Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 237211
Collapse All | Expand All

(-)plugin.xml (+14 lines)
Lines 1803-1806 Link Here
1803
            target="org.eclipse.php.core.phpsource">
1803
            target="org.eclipse.php.core.phpsource">
1804
        </highlighting>
1804
        </highlighting>
1805
    </extension>     
1805
    </extension>     
1806
           
1807
	<extension point="org.eclipse.ui.preferencePages">
1808
		<page category="org.eclipse.php.ui.preferences.PHPBasePreferencePage"
1809
			class="org.eclipse.dltk.ui.preferences.BuildpathVariablesPreferencePage"
1810
			id="org.eclipse.dltk.ui.preferences.BuildpathVariablesPreferencePage"
1811
			name="Buildpath Variables">
1812
			<keywordReference id="org.eclipse.php.ui.buildpathVariables" />
1813
		</page>
1814
	</extension>
1815
	
1816
	<extension point="org.eclipse.ui.keywords">
1817
		<keyword id="org.eclipse.php.ui.buildpathVariables" label="Buildpath Variables">
1818
		</keyword>
1819
	</extension>
1806
</plugin>
1820
</plugin>
(-)src/org/eclipse/php/internal/ui/preferences/includepath/PHPBuildpathDialogAccess.java (+22 lines)
Lines 230-233 Link Here
230
		return Path.fromOSString(res).makeAbsolute();
230
		return Path.fromOSString(res).makeAbsolute();
231
	}
231
	}
232
232
233
	/**
234
	 * Shows the UI for selecting new variable classpath entries. See {@link IClasspathEntry#CPE_VARIABLE} for
235
	 * details about variable classpath entries.
236
	 * The dialog returns an array of the selected variable entries or <code>null</code> if the dialog has
237
	 * been canceled. The dialog does not apply any changes.
238
	 *
239
	 * @param shell The parent shell for the dialog.
240
	 * @param existingPaths An array of paths that are already on the classpath and therefore should not be
241
	 * selected again.
242
	 * @return Returns an non empty array of the selected variable entries or <code>null</code> if the dialog has
243
	 * been canceled.
244
	 */
245
	public static IPath[] chooseVariableEntries(Shell shell, IEnvironment environment) {
246
//		if (existingPaths == null) {
247
//			throw new IllegalArgumentException();
248
//		}
249
		NewVariableEntryDialog dialog= new NewVariableEntryDialog(shell,environment);
250
		if (dialog.open() == Window.OK) {
251
			return dialog.getResult();
252
		}
253
		return null;
254
	}
233
}
255
}
(-)src/org/eclipse/php/internal/ui/preferences/includepath/PHPLibrariesWorkbookPage.java (-7 / +29 lines)
Lines 22-27 Link Here
22
import org.eclipse.dltk.compiler.util.Util;
22
import org.eclipse.dltk.compiler.util.Util;
23
import org.eclipse.dltk.core.*;
23
import org.eclipse.dltk.core.*;
24
import org.eclipse.dltk.core.environment.EnvironmentManager;
24
import org.eclipse.dltk.core.environment.EnvironmentManager;
25
import org.eclipse.dltk.core.environment.EnvironmentPathUtils;
25
import org.eclipse.dltk.core.environment.IEnvironment;
26
import org.eclipse.dltk.core.environment.IEnvironment;
26
import org.eclipse.dltk.internal.ui.actions.WorkbenchRunnableAdapter;
27
import org.eclipse.dltk.internal.ui.actions.WorkbenchRunnableAdapter;
27
import org.eclipse.dltk.internal.ui.wizards.BuildpathDialogAccess;
28
import org.eclipse.dltk.internal.ui.wizards.BuildpathDialogAccess;
Lines 53-59 Link Here
53
	private final int IDX_ADDZIP = 0;
54
	private final int IDX_ADDZIP = 0;
54
	private final int IDX_ADDEXT = 1;
55
	private final int IDX_ADDEXT = 1;
55
	private final int IDX_ADDLIB = 2;
56
	private final int IDX_ADDLIB = 2;
56
	// private final int IDX_ADDFOL = 3;
57
	 private final int IDX_ADDFOL = 4;
57
	private final int IDX_ADDEXTFOL = 3;
58
	private final int IDX_ADDEXTFOL = 3;
58
	private final int IDX_EDIT = 5;
59
	private final int IDX_EDIT = 5;
59
	private final int IDX_REMOVE = 6;
60
	private final int IDX_REMOVE = 6;
Lines 86-92 Link Here
86
				NewWizardMessages.LibrariesWorkbookPage_libraries_addlibrary_button,
87
				NewWizardMessages.LibrariesWorkbookPage_libraries_addlibrary_button,
87
				// NewWizardMessages.LibrariesWorkbookPage_libraries_add_source_folder_button,
88
				// NewWizardMessages.LibrariesWorkbookPage_libraries_add_source_folder_button,
88
				NewWizardMessages.LibrariesWorkbookPage_libraries_add_external_source_folder_button,
89
				NewWizardMessages.LibrariesWorkbookPage_libraries_add_external_source_folder_button,
89
				/* */null,
90
//				/* */null,
91
				"Add Variables...",
90
				NewWizardMessages.LibrariesWorkbookPage_libraries_edit_button,
92
				NewWizardMessages.LibrariesWorkbookPage_libraries_edit_button,
91
				NewWizardMessages.LibrariesWorkbookPage_libraries_remove_button,
93
				NewWizardMessages.LibrariesWorkbookPage_libraries_remove_button,
92
				/* */null,
94
				/* */null,
Lines 95-101 Link Here
95
				NewWizardMessages.LibrariesWorkbookPage_libraries_addlibrary_button,
97
				NewWizardMessages.LibrariesWorkbookPage_libraries_addlibrary_button,
96
				// NewWizardMessages.LibrariesWorkbookPage_libraries_add_source_folder_button,
98
				// NewWizardMessages.LibrariesWorkbookPage_libraries_add_source_folder_button,
97
				NewWizardMessages.LibrariesWorkbookPage_libraries_add_external_source_folder_button,
99
				NewWizardMessages.LibrariesWorkbookPage_libraries_add_external_source_folder_button,
98
				/* */null,
100
//				/* */null,
101
				"Add Variables...",
99
				NewWizardMessages.LibrariesWorkbookPage_libraries_edit_button,
102
				NewWizardMessages.LibrariesWorkbookPage_libraries_edit_button,
100
				NewWizardMessages.LibrariesWorkbookPage_libraries_remove_button };
103
				NewWizardMessages.LibrariesWorkbookPage_libraries_remove_button };
101
		String[] buttonLabels;
104
		String[] buttonLabels;
Lines 250-258 Link Here
250
		case IDX_ADDEXTFOL: /* add folder */
253
		case IDX_ADDEXTFOL: /* add folder */
251
			libentries = opensExtSourceFolderDialog(null, environment);
254
			libentries = opensExtSourceFolderDialog(null, environment);
252
			break;
255
			break;
253
		// case IDX_ADDFOL: /* add folder */
256
		 case IDX_ADDFOL: /* add variables */
254
		// libentries = opensSourceFolderDialog(null);
257
		 libentries = addVariablesDialog(null, environment);
255
		// break;
258
		 break;
256
		case IDX_EDIT: /* edit */
259
		case IDX_EDIT: /* edit */
257
			editEntry();
260
			editEntry();
258
			return;
261
			return;
Lines 286-291 Link Here
286
		}
289
		}
287
	}
290
	}
288
291
292
	private BPListElement[] addVariablesDialog(BPListElement existing, IEnvironment environment) {
293
		if (existing == null) {
294
			IPath[] selected = PHPBuildpathDialogAccess
295
					.chooseVariableEntries(getShell(), environment);
296
			if (selected != null) {
297
				ArrayList res = new ArrayList();
298
				for (int i = 0; i < selected.length; i++) {
299
					IPath path = EnvironmentPathUtils.getFullPath(environment, DLTKCore.getBuildpathVariable(selected[i].toString()));
300
					res.add(new BPListElement(fCurrJProject,
301
							IBuildpathEntry.BPE_LIBRARY, path, null,
302
							true));
303
				}
304
				return (BPListElement[]) res.toArray(new BPListElement[res
305
						.size()]);
306
			}
307
		}
308
		return null;
309
	}
310
289
	public void addElement(BPListElement element) {
311
	public void addElement(BPListElement element) {
290
		fLibrariesList.addElement(element);
312
		fLibrariesList.addElement(element);
291
		fLibrariesList.postSetSelection(new StructuredSelection(element));
313
		fLibrariesList.postSetSelection(new StructuredSelection(element));
Lines 589-595 Link Here
589
			fLibrariesList.enableButton(IDX_REPLACE + IDX_ADD,
611
			fLibrariesList.enableButton(IDX_REPLACE + IDX_ADD,
590
					getSelectedProjectFragment() != null);
612
					getSelectedProjectFragment() != null);
591
		}
613
		}
592
		// fLibrariesList.enableButton(IDX_ADDFOL+IDX_ADD, noAttributes);
614
		 fLibrariesList.enableButton(IDX_ADDFOL+IDX_ADD, noAttributes);
593
		fLibrariesList.enableButton(IDX_ADDLIB + IDX_ADD, noAttributes);
615
		fLibrariesList.enableButton(IDX_ADDLIB + IDX_ADD, noAttributes);
594
	}
616
	}
595
617
(-)src/org/eclipse/php/internal/ui/preferences/includepath/NewVariableEntryDialog.java (+379 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.php.internal.ui.preferences.includepath;
12
13
import java.io.File;
14
import java.util.*;
15
16
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Path;
19
import org.eclipse.dltk.core.DLTKCore;
20
import org.eclipse.dltk.core.IScriptProject;
21
import org.eclipse.dltk.core.environment.EnvironmentManager;
22
import org.eclipse.dltk.core.environment.IEnvironment;
23
import org.eclipse.dltk.internal.ui.wizards.NewWizardMessages;
24
import org.eclipse.dltk.internal.ui.wizards.buildpath.BPVariableElement;
25
import org.eclipse.dltk.internal.ui.wizards.buildpath.BPVariableElementLabelProvider;
26
import org.eclipse.dltk.ui.preferences.BuildpathVariablesPreferencePage;
27
import org.eclipse.jface.dialogs.Dialog;
28
import org.eclipse.jface.dialogs.IDialogConstants;
29
import org.eclipse.jface.dialogs.IDialogSettings;
30
import org.eclipse.jface.dialogs.StatusDialog;
31
import org.eclipse.jface.resource.JFaceResources;
32
import org.eclipse.jface.viewers.StructuredSelection;
33
import org.eclipse.jface.viewers.Viewer;
34
import org.eclipse.jface.viewers.ViewerComparator;
35
import org.eclipse.jface.window.Window;
36
import org.eclipse.php.internal.ui.PHPUiPlugin;
37
import org.eclipse.php.internal.ui.util.Messages;
38
import org.eclipse.php.internal.ui.util.StatusInfo;
39
import org.eclipse.php.internal.ui.wizards.fields.*;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.custom.CLabel;
42
import org.eclipse.swt.layout.GridData;
43
import org.eclipse.swt.layout.GridLayout;
44
import org.eclipse.swt.widgets.Button;
45
import org.eclipse.swt.widgets.Composite;
46
import org.eclipse.swt.widgets.Control;
47
import org.eclipse.swt.widgets.Shell;
48
import org.eclipse.ui.PlatformUI;
49
import org.eclipse.ui.dialogs.PreferencesUtil;
50
import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds;
51
import org.eclipse.wst.jsdt.internal.ui.wizards.buildpaths.JARFileSelectionDialog;
52
53
public class NewVariableEntryDialog extends StatusDialog {
54
55
	private class VariablesAdapter implements IDialogFieldListener,
56
			IListAdapter {
57
58
		// -------- IListAdapter --------
59
60
		public void customButtonPressed(ListDialogField field, int index) {
61
			switch (index) {
62
			case IDX_EXTEND: /* extend */
63
				extendButtonPressed();
64
				break;
65
			}
66
		}
67
68
		public void selectionChanged(ListDialogField field) {
69
			doSelectionChanged();
70
		}
71
72
		public void doubleClicked(ListDialogField field) {
73
			doDoubleClick();
74
		}
75
76
		// ---------- IDialogFieldListener --------
77
78
		public void dialogFieldChanged(DialogField field) {
79
			if (field == fConfigButton) {
80
				configButtonPressed();
81
			}
82
83
		}
84
85
	}
86
87
	private final int IDX_EXTEND = 0;
88
89
	private ListDialogField fVariablesList;
90
	private boolean fCanExtend;
91
	private boolean fIsValidSelection;
92
93
	private IPath[] fResultPaths;
94
95
	private SelectionButtonDialogField fConfigButton;
96
97
	private CLabel fWarning;
98
	IEnvironment environment;
99
100
	public NewVariableEntryDialog(Shell parent, IEnvironment environment) {
101
		super(parent);
102
		setTitle(NewWizardMessages.NewVariableEntryDialog_title);
103
		this.environment = environment;
104
		updateStatus(new StatusInfo(IStatus.ERROR, "")); //$NON-NLS-1$
105
106
		String[] buttonLabels = new String[] { NewWizardMessages.NewVariableEntryDialog_vars_extend, };
107
108
		VariablesAdapter adapter = new VariablesAdapter();
109
110
		BPVariableElementLabelProvider labelProvider = new BPVariableElementLabelProvider(
111
				false);
112
113
		fVariablesList = new ListDialogField(adapter, buttonLabels,
114
				labelProvider);
115
		fVariablesList.setDialogFieldListener(adapter);
116
		fVariablesList
117
				.setLabelText(NewWizardMessages.NewVariableEntryDialog_vars_label);
118
119
		fVariablesList.enableButton(IDX_EXTEND, false);
120
121
		// fVariablesList.setViewerComparator(new ViewerComparator() {
122
		// public int compare(Viewer viewer, Object e1, Object e2) {
123
		// if (e1 instanceof BPVariableElement && e2 instanceof
124
		// BPVariableElement) {
125
		// return getComparator().compare(((BPVariableElement)e1).getName(),
126
		// ((BPVariableElement)e2).getName());
127
		// }
128
		// return super.compare(viewer, e1, e2);
129
		// }
130
		// });
131
132
		fConfigButton = new SelectionButtonDialogField(SWT.PUSH);
133
		fConfigButton
134
				.setLabelText(NewWizardMessages.NewVariableEntryDialog_configbutton_label);
135
		fConfigButton.setDialogFieldListener(adapter);
136
137
		initializeElements();
138
139
		fCanExtend = false;
140
		fIsValidSelection = false;
141
		fResultPaths = null;
142
143
		fVariablesList.selectFirstElement();
144
	}
145
146
	/*
147
	 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
148
	 * 
149
	 * @since 3.4
150
	 */
151
	protected boolean isResizable() {
152
		return true;
153
	}
154
155
	private void initializeElements() {
156
		String[] entries = DLTKCore.getBuildpathVariableNames();
157
		ArrayList elements = new ArrayList(entries.length);
158
		for (int i = 0; i < entries.length; i++) {
159
			String name = entries[i];
160
			IPath entryPath = DLTKCore.getBuildpathVariable(name);
161
			if (entryPath != null) {
162
				elements.add(new BPVariableElement(name, entryPath));
163
			}
164
		}
165
166
		fVariablesList.setElements(elements);
167
	}
168
169
	/*
170
	 * (non-Javadoc)
171
	 * 
172
	 * @see Window#configureShell(Shell)
173
	 */
174
	protected void configureShell(Shell shell) {
175
		super.configureShell(shell);
176
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
177
				IJavaHelpContextIds.NEW_VARIABLE_ENTRY_DIALOG);
178
	}
179
180
	/*
181
	 * (non-Javadoc)
182
	 * 
183
	 * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
184
	 */
185
	protected IDialogSettings getDialogBoundsSettings() {
186
		return PHPUiPlugin.getDefault().getDialogSettings()/*
187
															 * getDialogSettingsSection(
188
															 * getClass
189
															 * ().getName())
190
															 */;
191
	}
192
193
	/*
194
	 * (non-Javadoc)
195
	 * 
196
	 * @see
197
	 * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
198
	 * .Composite)
199
	 */
200
	protected Control createDialogArea(Composite parent) {
201
		initializeDialogUnits(parent);
202
203
		Composite composite = (Composite) super.createDialogArea(parent);
204
		GridLayout layout = (GridLayout) composite.getLayout();
205
		layout.numColumns = 2;
206
207
		fVariablesList.doFillIntoGrid(composite, 3);
208
209
		LayoutUtil.setHorizontalSpan(fVariablesList.getLabelControl(null), 2);
210
211
		GridData listData = (GridData) fVariablesList.getListControl(null)
212
				.getLayoutData();
213
		listData.grabExcessHorizontalSpace = true;
214
		listData.heightHint = convertHeightInCharsToPixels(10);
215
		listData.widthHint = convertWidthInCharsToPixels(70);
216
217
		fWarning = new CLabel(composite, SWT.NONE);
218
		fWarning.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,
219
				fVariablesList.getNumberOfControls() - 1, 1));
220
221
		Composite lowerComposite = new Composite(composite, SWT.NONE);
222
		lowerComposite.setLayoutData(new GridData(
223
				GridData.HORIZONTAL_ALIGN_FILL));
224
225
		layout = new GridLayout();
226
		layout.marginHeight = 0;
227
		layout.marginWidth = 0;
228
		lowerComposite.setLayout(layout);
229
230
		fConfigButton.doFillIntoGrid(lowerComposite, 1);
231
232
		applyDialogFont(composite);
233
		return composite;
234
	}
235
236
	public IPath[] getResult() {
237
		return fResultPaths;
238
	}
239
240
	/*
241
	 * @see IDoubleClickListener#doubleClick(DoubleClickEvent)
242
	 */
243
	private void doDoubleClick() {
244
		if (fIsValidSelection) {
245
			okPressed();
246
		} else if (fCanExtend) {
247
			extendButtonPressed();
248
		}
249
	}
250
251
	private void doSelectionChanged() {
252
		boolean isValidSelection = true;
253
		boolean canExtend = false;
254
		StatusInfo status = new StatusInfo();
255
256
		List selected = fVariablesList.getSelectedElements();
257
		int nSelected = selected.size();
258
259
		if (nSelected > 0) {
260
			fResultPaths = new Path[nSelected];
261
			for (int i = 0; i < nSelected; i++) {
262
				BPVariableElement curr = (BPVariableElement) selected.get(i);
263
				fResultPaths[i] = new Path(curr.getName());
264
				File file = curr.getPath().toFile();
265
				if (!file.exists()) {
266
					status
267
							.setError(NewWizardMessages.NewVariableEntryDialog_info_notexists);
268
					isValidSelection = false;
269
					break;
270
				}
271
				if (file.isDirectory()) {
272
					canExtend = true;
273
				}
274
			}
275
		} else {
276
			isValidSelection = false;
277
			status
278
					.setInfo(NewWizardMessages.NewVariableEntryDialog_info_noselection);
279
		}
280
		if (isValidSelection && nSelected > 1) {
281
			String str = Messages.format(
282
					NewWizardMessages.NewVariableEntryDialog_info_selected,
283
					String.valueOf(nSelected));
284
			status.setInfo(str);
285
		}
286
		fCanExtend = nSelected == 1 && canExtend;
287
		fVariablesList.enableButton(0, fCanExtend);
288
289
		updateStatus(status);
290
		fIsValidSelection = isValidSelection;
291
		Button okButton = getButton(IDialogConstants.OK_ID);
292
		if (okButton != null && !okButton.isDisposed()) {
293
			okButton.setEnabled(isValidSelection);
294
		}
295
		updateDeprecationWarning();
296
	}
297
298
	private void updateDeprecationWarning() {
299
		// TODO
300
		// if (fWarning == null || fWarning.isDisposed())
301
		// return;
302
		//
303
		// for (Iterator iter= fVariablesList.getSelectedElements().iterator();
304
		// iter.hasNext();) {
305
		// BPVariableElement element= (BPVariableElement) iter.next();
306
		// String deprecationMessage= element.getDeprecationMessage();
307
		// if (deprecationMessage != null) {
308
		// fWarning.setText(deprecationMessage);
309
		// fWarning.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
310
		// return;
311
		// }
312
		// }
313
		// fWarning.setText(null);
314
		// fWarning.setImage(null);
315
	}
316
317
	private IPath[] chooseExtensions(BPVariableElement elem) {
318
		File file = elem.getPath().toFile();
319
		IPath[] selected = PHPBuildpathDialogAccess
320
				.chooseExternalArchiveEntries(getShell(), environment);
321
		// JARFileSelectionDialog dialog= new JARFileSelectionDialog(getShell(),
322
		// true, true, true);
323
		// dialog.setTitle(NewWizardMessages.NewVariableEntryDialog_ExtensionDialog_title);
324
		// dialog.setMessage(Messages.format(NewWizardMessages.NewVariableEntryDialog_ExtensionDialog_description,
325
		// elem.getName()));
326
		// dialog.setInput(file);
327
		// if (dialog.open() == Window.OK) {
328
		// Object[] selected= dialog.getResult();
329
		IPath[] paths = new IPath[selected.length];
330
		for (int i = 0; i < selected.length; i++) {
331
			IPath filePath = Path.fromOSString(((File) selected[i]).getPath());
332
			IPath resPath = new Path(elem.getName());
333
			for (int k = elem.getPath().segmentCount(); k < filePath
334
					.segmentCount(); k++) {
335
				resPath = resPath.append(filePath.segment(k));
336
			}
337
			paths[i] = resPath;
338
		}
339
		return paths;
340
		// }
341
		// return null;
342
	}
343
344
	protected final void extendButtonPressed() {
345
		List selected = fVariablesList.getSelectedElements();
346
		if (selected.size() == 1) {
347
			IPath[] extendedPaths = chooseExtensions((BPVariableElement) selected
348
					.get(0));
349
			if (extendedPaths != null) {
350
				fResultPaths = extendedPaths;
351
				super.buttonPressed(IDialogConstants.OK_ID);
352
			}
353
		}
354
	}
355
356
	protected final void configButtonPressed() {
357
		String id = BuildpathVariablesPreferencePage.ID;
358
		Map options = new HashMap();
359
		List selected = fVariablesList.getSelectedElements();
360
		if (!selected.isEmpty()) {
361
			String varName = ((BPVariableElement) selected.get(0)).getName();
362
			options.put(BuildpathVariablesPreferencePage.DATA_SELECT_VARIABLE,
363
					varName);
364
		}
365
		PreferencesUtil.createPreferenceDialogOn(getShell(), id,
366
				new String[] { id }, options).open();
367
368
		List oldElements = fVariablesList.getElements();
369
		initializeElements();
370
		List newElements = fVariablesList.getElements();
371
		newElements.removeAll(oldElements);
372
		if (!newElements.isEmpty()) {
373
			fVariablesList.selectElements(new StructuredSelection(newElements));
374
		} else if (fVariablesList.getSelectedElements().isEmpty()) {
375
			fVariablesList.selectFirstElement();
376
		}
377
	}
378
379
}

Return to bug 237211