View | Details | Raw Unified | Return to bug 37389 | Differences between
and this patch

Collapse All | Expand All

(-).project (-5 lines)
Lines 4-16 Link Here
4
	<comment></comment>
4
	<comment></comment>
5
	<projects>
5
	<projects>
6
		<project>org.eclipse.core.resources</project>
6
		<project>org.eclipse.core.resources</project>
7
		<project>org.eclipse.core.runtime.compatibility</project>
8
		<project>org.eclipse.help</project>
9
		<project>org.eclipse.jface</project>
7
		<project>org.eclipse.jface</project>
10
		<project>org.eclipse.ui</project>
11
		<project>org.eclipse.ui.views</project>
12
		<project>org.eclipse.ui.workbench</project>
8
		<project>org.eclipse.ui.workbench</project>
13
		<project>org.eclipse.update.core</project>
14
	</projects>
9
	</projects>
15
	<buildSpec>
10
	<buildSpec>
16
		<buildCommand>
11
		<buildCommand>
(-)plugin.properties (+1 lines)
Lines 85-90 Link Here
85
Views.IntroAdapter = Intro
85
Views.IntroAdapter = Intro
86
86
87
WorkingSets.resource = Resource
87
WorkingSets.resource = Resource
88
WorkingSets.project = Project
88
AddBookmark.label=Add Boo&kmark...
89
AddBookmark.label=Add Boo&kmark...
89
AddBookmark.tooltip=Add Bookmark...
90
AddBookmark.tooltip=Add Bookmark...
90
AddTask.label=Add &Task...
91
AddTask.label=Add &Task...
(-)plugin.xml (+14 lines)
Lines 214-219 Link Here
214
            class="org.eclipse.ui.internal.ide.dialogs.WelcomeEditorInputFactory"
214
            class="org.eclipse.ui.internal.ide.dialogs.WelcomeEditorInputFactory"
215
            id="org.eclipse.ui.internal.dialogs.WelcomeEditorInputFactory">
215
            id="org.eclipse.ui.internal.dialogs.WelcomeEditorInputFactory">
216
      </factory>
216
      </factory>
217
      <factory
218
            class="org.eclipse.ui.internal.ide.model.ProjectWorkingSetFactory"
219
            id="org.eclipse.ui.ide.ProjectWorkingSetFactory">
220
      </factory>
221
      <factory
222
            class="org.eclipse.ui.internal.ide.model.ProjectWorkingSetReferenceFactory"
223
            id="org.eclipse.ui.ide.ProjectWorkingSetReferenceFactory">
224
      </factory>
217
   </extension>
225
   </extension>
218
   <extension
226
   <extension
219
         point="org.eclipse.ui.workingSets">
227
         point="org.eclipse.ui.workingSets">
Lines 222-227 Link Here
222
            pageClass="org.eclipse.ui.internal.ide.dialogs.ResourceWorkingSetPage"
230
            pageClass="org.eclipse.ui.internal.ide.dialogs.ResourceWorkingSetPage"
223
            icon="icons/full/obj16/workset.gif"
231
            icon="icons/full/obj16/workset.gif"
224
            id="org.eclipse.ui.resourceWorkingSetPage">
232
            id="org.eclipse.ui.resourceWorkingSetPage">
233
      </workingSet>
234
      <workingSet
235
            name="%WorkingSets.project"
236
            pageClass="org.eclipse.ui.internal.ide.dialogs.ProjectWorkingSetPage"
237
            icon="icons/full/obj16/elements_obj.gif"
238
            id="org.eclipse.ui.ide.projectWorkingSetPage">
225
      </workingSet>
239
      </workingSet>
226
   </extension>
240
   </extension>
227
   <extension
241
   <extension
(-)src/org/eclipse/ui/internal/ide/IDEInternalWorkbenchImages.java (-1 / +3 lines)
Lines 129-134 Link Here
129
129
130
	public final static String IMG_VIEW_DEFAULTVIEW_MISC = "IMG_VIEW_DEFAULTVIEW_MISC"; //$NON-NLS-1$
130
	public final static String IMG_VIEW_DEFAULTVIEW_MISC = "IMG_VIEW_DEFAULTVIEW_MISC"; //$NON-NLS-1$
131
	
131
	
132
	public final static String IMG_OBJS_ELEMENT = "IMG_OBJ_ELEMENT"; //$NON-NLS-1$
133
	
132
	// dialog images
134
	// dialog images
133
	public final static String IMG_DLGBAN_SAVEAS_DLG = "IMG_DLGBAN_SAVEAS_DLG"; //$NON-NLS-1$
135
	public final static String IMG_DLGBAN_SAVEAS_DLG = "IMG_DLGBAN_SAVEAS_DLG"; //$NON-NLS-1$
134
136
Lines 172-178 Link Here
172
	public final static String IMG_OBJS_DND_STACK_MASK = "IMG_OBJS_DND_STACK_MASK"; //$NON-NLS-1$
174
	public final static String IMG_OBJS_DND_STACK_MASK = "IMG_OBJS_DND_STACK_MASK"; //$NON-NLS-1$
173
	public final static String IMG_OBJS_DND_OFFSCREEN_SOURCE = "IMG_OBJS_DND_OFFSCREEN_SOURCE"; //$NON-NLS-1$
175
	public final static String IMG_OBJS_DND_OFFSCREEN_SOURCE = "IMG_OBJS_DND_OFFSCREEN_SOURCE"; //$NON-NLS-1$
174
	public final static String IMG_OBJS_DND_OFFSCREEN_MASK = "IMG_OBJS_DND_OFFSCREEN_MASK"; //$NON-NLS-1$
176
	public final static String IMG_OBJS_DND_OFFSCREEN_MASK = "IMG_OBJS_DND_OFFSCREEN_MASK"; //$NON-NLS-1$
175
	
177
176
	/**
178
	/**
177
	 * Returns the image descriptor for the workbench image with the given
179
	 * Returns the image descriptor for the workbench image with the given
178
	 * symbolic name. Use this method to retrieve image descriptors for any
180
	 * symbolic name. Use this method to retrieve image descriptors for any
(-)src/org/eclipse/ui/internal/ide/messages.properties (-2 / +26 lines)
Lines 1498-1515 Link Here
1498
WorkingSetTypePage.typesLabel=&Working set type:
1498
WorkingSetTypePage.typesLabel=&Working set type:
1499
1499
1500
ResourceWorkingSetPage.title=Resource Working Set
1500
ResourceWorkingSetPage.title=Resource Working Set
1501
ResourceWorkingSetPage.description=Enter a working set name and select the working set resources.
1501
ResourceWorkingSetPage.description=Enter a working set name and select the working set projects or sub-sets.
1502
ResourceWorkingSetPage.message=&Working set name:
1502
ResourceWorkingSetPage.message=&Working set name:
1503
ResourceWorkingSetPage.label.tree=Working set &contents:
1503
ResourceWorkingSetPage.label.tree=Working set &contents:
1504
ResourceWorkingSetPage.warning.nameMustNotBeEmpty= The name must not be empty.
1504
ResourceWorkingSetPage.warning.nameMustNotBeEmpty= The name must not be empty.
1505
ResourceWorkingSetPage.warning.nameWhitespace= The name must not have leading or trailing whitespace.
1505
ResourceWorkingSetPage.warning.nameWhitespace= The name must not have leading or trailing whitespace.
1506
ResourceWorkingSetPage.warning.workingSetExists= A working set with the same name already exists.
1506
ResourceWorkingSetPage.warning.workingSetExists= A working set with the same name already exists.
1507
ResourceWorkingSetPage.warning.resourceMustBeChecked= At least one resource must be checked.
1507
ResourceWorkingSetPage.warning.resourceMustBeChecked= At least one project or sub-set must be checked.
1508
ResourceWorkingSetPage.error= Error
1508
ResourceWorkingSetPage.error= Error
1509
ResourceWorkingSetPage.error.updateCheckedState= Error during update of checked state
1509
ResourceWorkingSetPage.error.updateCheckedState= Error during update of checked state
1510
ResourceWorkingSetPage.projectClosedDialog.message= A closed project can not be modified
1510
ResourceWorkingSetPage.projectClosedDialog.message= A closed project can not be modified
1511
ResourceWorkingSetPage.projectClosedDialog.title= Working Set Change
1511
ResourceWorkingSetPage.projectClosedDialog.title= Working Set Change
1512
1512
1513
ProjectWorkingSetPage.title=Project Working Set
1514
ProjectWorkingSetPage.description=Enter a working set name and select the working set Projects.
1515
ProjectWorkingSetPage.message=&Working set name:
1516
ProjectWorkingSetPage.label.included=Working set &contents:
1517
ProjectWorkingSetPage.label.available=Availa&ble Projects:
1518
ProjectWorkingSetPage.warning.nameMustNotBeEmpty= The name must not be empty.
1519
ProjectWorkingSetPage.warning.nameWhitespace= The name must not have leading or trailing whitespace.
1520
ProjectWorkingSetPage.warning.workingSetExists= A working set with the same name already exists.
1521
ProjectWorkingSetPage.warning.projectMustBeIncluded= At least one Project must be included.
1522
ProjectWorkingSetPage.error= Error
1523
ProjectWorkingSetPage.error.updateCheckedState= Error during update of checked state
1524
ProjectWorkingSetPage.projectClosedDialog.message= A closed project can not be modified
1525
ProjectWorkingSetPage.projectClosedDialog.title= Working Set Change
1526
ProjectWorkingSetPage.button.Add=&Add -->
1527
ProjectWorkingSetPage.button.AllProjects= All &Projects --> 
1528
ProjectWorkingSetPage.button.Remove=<-- &Remove
1529
ProjectWorkingSetPage.button.RemoveAll=<-- Remo&ve All
1530
ProjectWorkingSetPage.button.Swap=<-- &Swap -->
1531
ProjectWorkingSetPage.formatted.count={0,number,integer} of {1,number,integer} selected
1532
1513
WorkingSetSelectionDialog.title= Select Working Set
1533
WorkingSetSelectionDialog.title= Select Working Set
1514
WorkingSetSelectionDialog.title.multiSelect= Select Working Sets
1534
WorkingSetSelectionDialog.title.multiSelect= Select Working Sets
1515
WorkingSetSelectionDialog.message= &Select a working set:
1535
WorkingSetSelectionDialog.message= &Select a working set:
Lines 1568-1572 Link Here
1568
DecorationScheduler.UpdatingTask=Updating
1588
DecorationScheduler.UpdatingTask=Updating
1569
DecorationScheduler.CalculatingTask=Calculating
1589
DecorationScheduler.CalculatingTask=Calculating
1570
DecorationScheduler.DecoratingSubtask=Decorating {0}
1590
DecorationScheduler.DecoratingSubtask=Decorating {0}
1591
<<<<<<< messages.properties
1592
ProjectWorkingSetPage.18={0,number,integer} of {1,number,integer} selected
1593
=======
1571
GlobalBuildAction.BuildRunningTitle=Build Is Running
1594
GlobalBuildAction.BuildRunningTitle=Build Is Running
1572
GlobalBuildAction.BuildRunningMessage=A build is currently running. Do you wish to cancel it?
1595
GlobalBuildAction.BuildRunningMessage=A build is currently running. Do you wish to cancel it?
1596
>>>>>>> 1.15
(-)src/org/eclipse/ui/internal/ide/dialogs/PixelConverter.java (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.dialogs;
12
/**
13
 * @version 	1.0
14
 * @author
15
 */
16
import org.eclipse.swt.graphics.FontMetrics;
17
import org.eclipse.swt.graphics.GC;
18
import org.eclipse.swt.widgets.Control;
19
20
import org.eclipse.jface.dialogs.Dialog;
21
22
public class PixelConverter {
23
	
24
	private FontMetrics fFontMetrics;
25
	
26
	public PixelConverter(Control control) {
27
		GC gc = new GC(control);
28
		gc.setFont(control.getFont());
29
		fFontMetrics= gc.getFontMetrics();
30
		gc.dispose();
31
	}
32
	
33
		
34
	/**
35
	 * @see DialogPage#convertHeightInCharsToPixels
36
	 */
37
	public int convertHeightInCharsToPixels(int chars) {
38
		return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
39
	}
40
41
	/**
42
	 * @see DialogPage#convertHorizontalDLUsToPixels
43
	 */
44
	public int convertHorizontalDLUsToPixels(int dlus) {
45
		return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus);
46
	}
47
48
	/**
49
	 * @see DialogPage#convertVerticalDLUsToPixels
50
	 */
51
	public int convertVerticalDLUsToPixels(int dlus) {
52
		return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus);
53
	}
54
	
55
	/**
56
	 * @see DialogPage#convertWidthInCharsToPixels
57
	 */
58
	public int convertWidthInCharsToPixels(int chars) {
59
		return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
60
	}	
61
62
}
63
(-)src/org/eclipse/ui/internal/ide/dialogs/ProjectWorkingSetPage.java (+652 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.internal.ide.dialogs;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.Iterator;
17
import java.util.List;
18
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IWorkspaceRoot;
21
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.jface.dialogs.Dialog;
23
import org.eclipse.jface.viewers.DoubleClickEvent;
24
import org.eclipse.jface.viewers.IDoubleClickListener;
25
import org.eclipse.jface.viewers.IStructuredSelection;
26
import org.eclipse.jface.viewers.LabelProvider;
27
import org.eclipse.jface.viewers.TableViewer;
28
import org.eclipse.jface.wizard.WizardPage;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.events.ModifyEvent;
31
import org.eclipse.swt.events.ModifyListener;
32
import org.eclipse.swt.events.SelectionAdapter;
33
import org.eclipse.swt.events.SelectionEvent;
34
import org.eclipse.swt.graphics.Font;
35
import org.eclipse.swt.graphics.Image;
36
import org.eclipse.swt.layout.GridData;
37
import org.eclipse.swt.layout.GridLayout;
38
import org.eclipse.swt.widgets.Button;
39
import org.eclipse.swt.widgets.Composite;
40
import org.eclipse.swt.widgets.Label;
41
import org.eclipse.swt.widgets.Table;
42
import org.eclipse.swt.widgets.TableItem;
43
import org.eclipse.swt.widgets.Text;
44
import org.eclipse.ui.ISharedImages;
45
import org.eclipse.ui.IWorkingSet;
46
import org.eclipse.ui.IWorkingSetManager;
47
import org.eclipse.ui.PlatformUI;
48
import org.eclipse.ui.dialogs.IWorkingSetPage;
49
import org.eclipse.ui.help.WorkbenchHelp;
50
import org.eclipse.ui.ide.IDE;
51
import org.eclipse.ui.internal.IHelpContextIds;
52
import org.eclipse.ui.internal.WorkbenchPlugin;
53
import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages;
54
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
55
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
56
import org.eclipse.ui.internal.ide.model.ProjectWorkingSet;
57
58
59
/**
60
 * ProjectWorkingSetPage provides an edit page for the New and Edit Working Set
61
 * Wizard for "Project" workings sets. These working sets are for top-level
62
 * projects and also allow nested definitions that include other existing
63
 * Project working sets.
64
 * <p>
65
 * This wizard can be included in the Eclipse UI by extending the
66
 * org.eclipse.ui.workingSets extension point, as shown in the following
67
 * example.
68
 * <pre>
69
 *  <extension
70
 *        point="org.eclipse.ui.workingSets">
71
 *     <workingSet
72
 *           name="%WorkingSets.project"
73
 *           pageClass="org.eclipse.ui.internal.ide.dialogs.ProjectWorkingSetPage"
74
 *           icon="icons/full/obj16/elements_obj.gif"
75
 *           id="org.eclipse.ui.ide.projectWorkingSetPage">
76
 *     </workingSet>
77
 *  </extension>
78
 * </pre>
79
 * 
80
 * @since 3.0
81
 */
82
public class ProjectWorkingSetPage extends WizardPage implements IWorkingSetPage {
83
	static final int LIST_WIDTH_HINT = 200;
84
	static final int LIST_HEIGHT_HINT = 250;
85
	
86
	private Text text;
87
	private Label countLabel;
88
	private TableViewer availableListViewer;
89
	private TableViewer inclusionListViewer;
90
	private ProjectWorkingSet workingSet;
91
	private IAdaptable[] availableList;
92
	private boolean firstCheck = true;
93
	
94
	
95
	/**
96
	 * Creates a new instance of the receiver.
97
	 */
98
	public ProjectWorkingSetPage() {
99
		super("projectWorkingSetPage", //$NON-NLS-1$ 
100
			IDEWorkbenchMessages.getString("ProjectWorkingSetPage.title"), //$NON-NLS-1$ 
101
			IDEInternalWorkbenchImages.getImageDescriptor(
102
				IDEInternalWorkbenchImages.IMG_WIZBAN_NEWPRJ_WIZ));
103
		setDescription(IDEWorkbenchMessages.getString("ProjectWorkingSetPage.description")); //$NON-NLS-1$
104
		workingSet = new ProjectWorkingSet("", new IProject[0]); //$NON-NLS-1$
105
	}
106
	
107
	/**
108
	 * Get available projects and project-sets from workspace.
109
	 */
110
	private IAdaptable[] getAvailableList() {
111
		List available = new ArrayList();
112
		List /* <IProject[]> */ projects = getWorkspaceProjects();
113
		List /* <IWorkingSet[]> */ sets = getWorkspaceProjectWorkingSets();
114
		available.addAll(sets);
115
		available.addAll(projects);
116
		IAdaptable[] target = new IAdaptable[available.size()];
117
		Iterator iter = available.iterator();
118
		int i = 0;
119
		while (iter.hasNext()) {
120
			target[i++] = (IAdaptable) iter.next();
121
		}
122
		return target;
123
	}
124
125
	/* (non-Javadoc)
126
	 * @see org.eclipse.ui.dialogs.IWorkingSetPage#finish()
127
	 */
128
	public void finish() {
129
		if (workingSet != null)
130
		workingSet.setElements(getElementsFromViewer(inclusionListViewer));
131
	}
132
133
	/* (non-Javadoc)
134
	 * @see org.eclipse.ui.dialogs.IWorkingSetPage#getSelection()
135
	 */
136
	public IWorkingSet getSelection() {
137
		return workingSet;
138
	}
139
140
	/* (non-Javadoc)
141
	 * @see org.eclipse.ui.dialogs.IWorkingSetPage#setSelection(org.eclipse.ui.IWorkingSet)
142
	 */
143
	public void setSelection(IWorkingSet workingSet) {
144
		if (workingSet == null) {
145
			throw new IllegalArgumentException("Working set must not be null"); //$NON-NLS-1$
146
		}
147
		this.workingSet = (ProjectWorkingSet) workingSet;
148
	}
149
150
	/*
151
	 *  (non-Javadoc)
152
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
153
	 */
154
	public void createControl(Composite parent) {
155
	
156
		Font font = parent.getFont();
157
		Composite composite= new Composite(parent, SWT.NULL);
158
		composite.setLayout(new GridLayout());
159
		composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
160
		setControl(composite);
161
		
162
		// TODO: fix help context
163
		WorkbenchHelp.setHelp(composite, IHelpContextIds.WORKING_SET_RESOURCE_PAGE);		
164
		Label label = new Label(composite, SWT.WRAP);
165
		label.setText(IDEWorkbenchMessages.getString("ProjectWorkingSetPage.message")); //$NON-NLS-1$
166
		GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
167
		label.setLayoutData(data);
168
		label.setFont(font);
169
		
170
		text = new Text(composite, SWT.SINGLE | SWT.BORDER);
171
		text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
172
		text.setFont(font);
173
		text.addModifyListener(
174
			new ModifyListener() {
175
				public void modifyText(ModifyEvent e) {
176
					validateInput();
177
				}
178
			}
179
		);
180
		text.setFocus();
181
		
182
		Composite container = new Composite(composite, SWT.NONE);
183
		GridLayout layout = new GridLayout();
184
		layout.numColumns = 3;
185
		layout.horizontalSpacing = 5;
186
		layout.verticalSpacing = 10;
187
		container.setLayout(layout);
188
		
189
		// left-side viewer
190
		Object[] components = createViewerList(container, IDEWorkbenchMessages.getString("ProjectWorkingSetPage.label.available")); //$NON-NLS-1$
191
		((Composite) components[0]).setLayoutData(new GridData(GridData.FILL_BOTH));
192
		availableListViewer = (TableViewer) components[1];
193
		// buttons
194
		createButtonArea(container);
195
		// right-side viewer
196
		components = createViewerList(container, IDEWorkbenchMessages.getString("ProjectWorkingSetPage.label.included")); //$NON-NLS-1$
197
		((Composite) components[0]).setLayoutData(new GridData(GridData.FILL_BOTH));
198
		inclusionListViewer = (TableViewer) components[1];
199
		
200
		addViewerListeners();
201
		
202
		setControl(composite);
203
		Dialog.applyDialogFont(composite);
204
205
		initializeSets();
206
		if (workingSet != null) {
207
			text.setText(workingSet.getName());
208
		}
209
		setPageComplete(false);
210
	}
211
	
212
	/*
213
	 * Add handlers for single and double click that add/remove projects from the table viewers
214
	 */
215
	private void addViewerListeners() {
216
		availableListViewer.addDoubleClickListener(new IDoubleClickListener() {
217
			public void doubleClick(DoubleClickEvent event) {
218
				handleAdd();
219
			}
220
		});
221
				
222
		inclusionListViewer.addDoubleClickListener(new IDoubleClickListener() {
223
			public void doubleClick(DoubleClickEvent event) {
224
				handleRemove();
225
			}
226
		});
227
	}
228
229
	
230
	/**
231
	 * Create a Project/Set list viewer and return both the new Composite and the inner
232
	 * TableViewer in the Object array. This is used to created both the left and right
233
	 * side selection tables.
234
	 * 
235
	 * @param parent should be the top-level control
236
	 * @param labelText a heading for the table viewer
237
	 */
238
	private Object[] createViewerList(Composite parent, String labelText) {
239
		Object[] result = new Object[2];
240
		Composite container = new Composite(parent, SWT.NONE);
241
		GridLayout layout = new GridLayout();
242
		layout.marginWidth = 0;
243
		layout.marginHeight = 0;
244
		container.setLayout(layout);
245
		container.setLayoutData(new GridData(GridData.FILL_BOTH));
246
247
		Label label = new Label(container, SWT.NONE);
248
		label.setText(labelText); //$NON-NLS-1$
249
250
		Table table = new Table(container, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
251
		GridData gd = new GridData(GridData.FILL_BOTH);
252
		gd.widthHint = LIST_WIDTH_HINT;
253
		gd.heightHint = LIST_HEIGHT_HINT;
254
		table.setLayoutData(gd);
255
256
		TableViewer viewer = new TableViewer(table);
257
		viewer.setLabelProvider(new DefaultLabelProvider());
258
		viewer.setContentProvider(new ContentProvider());
259
		viewer.setInput(getWorkingSetManager());
260
		viewer.setSorter(new ProjectWorkingSetSorter());
261
262
		result[0] = container;
263
		result[1] = viewer;
264
		return result;
265
	}
266
	
267
	/**
268
	 * Provide Content for the list of available Projects and ProjectWorkingSets
269
	 */
270
	private class ContentProvider extends SimpleListContentProvider {
271
		public Object[] getElements(Object element) {
272
			return new Object[0];
273
			//return (availableList == null) ? getAvailableList() : availableList;
274
		}
275
	}
276
277
	/**
278
	 * Label provider for Project, ProjectWorkingSet, and ProjectWorkingSetReference
279
	 */
280
	class DefaultLabelProvider extends LabelProvider {
281
		public Image getImage(Object element) {
282
			if (element instanceof IProject) {
283
				return PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
284
			} else if (element instanceof ProjectWorkingSetReference || element instanceof ProjectWorkingSet) {
285
				return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
286
			} else {
287
				return super.getImage(element);
288
			}
289
		}
290
		public String getText(Object element) {
291
			if (element instanceof IProject) {
292
				IProject project = (IProject) element;
293
				return project.getName();
294
			} else if (element instanceof ProjectWorkingSetReference) {
295
				ProjectWorkingSetReference reference = (ProjectWorkingSetReference) element;
296
				return reference.getName();
297
			} else if (element instanceof ProjectWorkingSet) {
298
				ProjectWorkingSet set = (ProjectWorkingSet) element;
299
				return set.getName();
300
			} else {
301
				return super.getText(element);
302
			}
303
		}
304
	}
305
306
	// center console buttons
307
	private Composite createButtonArea(Composite parent) {
308
		Composite comp = new Composite(parent, SWT.NONE);
309
		GridLayout layout = new GridLayout();
310
		layout.marginWidth = layout.marginHeight = 0;
311
		comp.setLayout(layout);
312
		comp.setLayoutData(new GridData(GridData.FILL_VERTICAL));
313
		
314
		Composite container = new Composite(comp, SWT.NONE);
315
		layout = new GridLayout();
316
		layout.marginWidth = 0;
317
		layout.marginHeight = 30;
318
		container.setLayout(layout);
319
		GridData gd = new GridData(GridData.FILL_BOTH);
320
		gd.widthHint = 100;
321
		container.setLayoutData(gd);
322
		
323
		// All Projects
324
		Button button = new Button(container, SWT.PUSH);
325
		button.setText(IDEWorkbenchMessages.getString("ProjectWorkingSetPage.button.AllProjects")); //$NON-NLS-1$
326
		button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
327
		button.addSelectionListener(new SelectionAdapter() {
328
			public void widgetSelected(SelectionEvent e) {
329
				handleAllProjects();
330
			}
331
		});
332
		SWTUtil.setButtonDimensionHint(button);
333
334
		// Add
335
		button = new Button(container, SWT.PUSH);
336
		button.setText(IDEWorkbenchMessages.getString("ProjectWorkingSetPage.button.Add")); //$NON-NLS-1$
337
		button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
338
		button.addSelectionListener(new SelectionAdapter() {
339
			public void widgetSelected(SelectionEvent e) {
340
				handleAdd();
341
			}
342
		});
343
		SWTUtil.setButtonDimensionHint(button);
344
		
345
		// Remove
346
		button = new Button(container, SWT.PUSH);
347
		button.setText(IDEWorkbenchMessages.getString("ProjectWorkingSetPage.button.Remove")); //$NON-NLS-1$
348
		button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
349
		button.addSelectionListener(new SelectionAdapter() {
350
			public void widgetSelected(SelectionEvent e) {
351
				handleRemove();
352
			}
353
		});
354
		SWTUtil.setButtonDimensionHint(button);
355
		
356
		// Remove All
357
		button = new Button(container, SWT.PUSH);
358
		button.setText(IDEWorkbenchMessages.getString("ProjectWorkingSetPage.button.RemoveAll")); //$NON-NLS-1$
359
		button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
360
		button.addSelectionListener(new SelectionAdapter() {
361
			public void widgetSelected(SelectionEvent e) {
362
				handleRemoveAll();
363
			}
364
		});
365
		SWTUtil.setButtonDimensionHint(button);
366
		
367
		button = new Button(container, SWT.PUSH);
368
		button.setText(IDEWorkbenchMessages.getString("ProjectWorkingSetPage.button.Swap")); //$NON-NLS-1$
369
		button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
370
		button.addSelectionListener(new SelectionAdapter() {
371
			public void widgetSelected(SelectionEvent e) {
372
				handleSwap();
373
			}
374
		});
375
		SWTUtil.setButtonDimensionHint(button);
376
		
377
		//new Label(container, SWT.NONE); // spacer
378
379
/* build path limits us from supporting this feature...		
380
		button = new Button(container, SWT.PUSH);
381
		button.setText("Shared Projects"); //$NON-NLS-1$
382
		button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
383
		button.addSelectionListener(new SelectionAdapter() {
384
			public void widgetSelected(SelectionEvent e) {
385
				handleShared();
386
			}
387
		});
388
		SWTUtil.setButtonDimensionHint(button);
389
*/		
390
		// "X of Y selected"
391
		countLabel = new Label(comp, SWT.NONE);
392
		countLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));		
393
		return container;
394
	}
395
	
396
	protected void pageChanged() {
397
		updateCount();
398
		validateInput(); // sets page complete if OK
399
	}
400
	
401
	/*
402
	 * extract items from a table viewer as IAdaptable(s)
403
	 */
404
	private static IAdaptable[] getElementsFromViewer(TableViewer viewer) {
405
		TableItem[] items = viewer.getTable().getItems();
406
		ArrayList result = new ArrayList();
407
		for (int i = 0; i < items.length; i++) {
408
			result.add(items[i].getData());
409
		}
410
		return (IAdaptable[]) result.toArray(new IAdaptable[result.size()]);
411
	}
412
	
413
	/*
414
	 * Update the "X of Y Selected" count indication text.
415
	 */
416
	private void updateCount() {
417
		countLabel.setText(
418
			java.text.MessageFormat.format(IDEWorkbenchMessages.getString("ProjectWorkingSetPage.formatted.count"), //$NON-NLS-1$
419
				new Object[] {
420
					new Integer(inclusionListViewer.getTable().getItemCount()),
421
					new Integer(availableList.length)}));
422
		countLabel.getParent().layout();
423
	}
424
	
425
	private void handleAdd() {
426
		IStructuredSelection ssel = (IStructuredSelection)availableListViewer.getSelection();
427
		if (ssel.size() > 0) {
428
			Table table = availableListViewer.getTable();
429
			int index = table.getSelectionIndices()[0];
430
			availableListViewer.remove(ssel.toArray());
431
			inclusionListViewer.add(ssel.toArray());
432
			table.setSelection(index < table.getItemCount() ? index : table.getItemCount() -1);
433
			pageChanged();
434
		}		
435
	}
436
437
	private void handleRemove() {
438
		IStructuredSelection ssel = (IStructuredSelection)inclusionListViewer.getSelection();
439
		if (ssel.size() > 0) {
440
			Table table = inclusionListViewer.getTable();
441
			int index = table.getSelectionIndices()[0];
442
			inclusionListViewer.remove(ssel.toArray());
443
			availableListViewer.add(ssel.toArray());
444
			table.setSelection(index < table.getItemCount() ? index : table.getItemCount() -1);
445
			pageChanged();
446
		}		
447
	}
448
	
449
	private void handleRemoveAll() {
450
		TableItem[] items = inclusionListViewer.getTable().getItems();
451
		
452
		ArrayList data = new ArrayList();
453
		for (int i = 0; i < items.length; i++) {
454
			data.add(items[i].getData());
455
		}
456
		if (data.size() > 0) {
457
			availableListViewer.add(data.toArray());
458
			inclusionListViewer.remove(data.toArray());
459
			pageChanged();
460
		}		
461
	}
462
	
463
	private void handleSwap() {
464
		TableItem[] aItems = availableListViewer.getTable().getItems();
465
		TableItem[] iItems = inclusionListViewer.getTable().getItems();
466
		
467
		ArrayList data = new ArrayList();
468
		for (int i = 0; i < iItems.length; i++) {
469
			data.add(iItems[i].getData());
470
		}
471
		if (data.size() > 0) {
472
			availableListViewer.add(data.toArray());
473
			inclusionListViewer.remove(data.toArray());
474
		}
475
		
476
		data.clear();
477
		for (int i = 0; i < aItems.length; i++) {
478
			data.add(aItems[i].getData());
479
		}
480
		if (data.size() > 0) {
481
			inclusionListViewer.add(data.toArray());
482
			availableListViewer.remove(data.toArray());
483
		}
484
		pageChanged();		
485
	}
486
	
487
	private void handleAllProjects() {
488
		handleRemoveAll();
489
		ArrayList result = new ArrayList();
490
		List /* <IProject[]> */ projects = getWorkspaceProjects();
491
		Iterator iter = projects.iterator();
492
		while (iter.hasNext()) {
493
			IProject project = (IProject) iter.next();
494
			if (project.isOpen()) {
495
				result.add(project);
496
			}
497
		}
498
		if (result.size() > 0) {
499
			inclusionListViewer.add(result.toArray());
500
			availableListViewer.remove(result.toArray());
501
		}
502
		pageChanged();		
503
	}
504
/*
505
 * Team is not on our build path, so we can't support this
506
 * feature from within this package.
507
 *
508
	private void handleShared() {
509
		handleRemoveAll(false);
510
		ArrayList result = new ArrayList();
511
		IProject[] projects = getWorkspaceProjects();
512
		for (int i = 0; i < projects.length; i++) {
513
			IProject project = projects[i];
514
			if (project.isOpen()
515
				&& RepositoryProvider.isShared(project)) {
516
				result.add(project);
517
			}
518
		}
519
		if (result.size() > 0) {
520
			inclusionListViewer.add(result.toArray());
521
			availableListViewer.remove(result.toArray());
522
		}
523
		pageChanged();		
524
	}*/
525
526
	/**
527
	 * Initialize the list of available projects and if we are editing an
528
	 * existing working set, then also initialize the selected project list.
529
	 * Primes the Table Viewers, so we have to have UI componenets before
530
	 * calling this method.
531
	 */
532
	private void initializeSets() {
533
		List available = Arrays.asList(getAvailableList());
534
		List elements = Arrays.asList(workingSet.getElements());
535
		if (elements.size() > 0) {
536
			inclusionListViewer.add(elements.toArray());
537
		}
538
		if (available.size() > 0) {
539
			// source is "available"-"elements"
540
			List source = new ArrayList();
541
			source.addAll(available);
542
			source.removeAll(elements);
543
544
			availableList = adaptableArrayOfList (source);
545
			availableListViewer.add(availableList);
546
		}
547
		updateCount();
548
	}
549
	
550
	/*
551
	 * Convert a list of adaptables to an array. Java compiler doesn't
552
	 * handle this very nicely.
553
	 */
554
	private IAdaptable[] adaptableArrayOfList (List list) {
555
		IAdaptable[] result = new IAdaptable[list.size()];
556
		Iterator iter = list.iterator();
557
		int i = 0;
558
		while (iter.hasNext()) {
559
			IAdaptable element = (IAdaptable) iter.next();
560
			result[i++] = element;
561
		}
562
		return result;
563
	}
564
	/**
565
	 * Validates the working set name and the set of Projects and ProjectWorkingSet references.
566
	 * Working sets may not reference themselves; this is enforced by filtering the new working
567
	 * set name out of the "available" list and also by disallowing a new working set to have a
568
	 * name that already exists.
569
	 */
570
	private void validateInput() {
571
		String errorMessage = null;	//$NON-NLS-1$
572
		String newText = text.getText();
573
574
		if (newText.equals(newText.trim()) == false) {
575
			errorMessage = IDEWorkbenchMessages.getString("ProjectWorkingSetPage.warning.nameWhitespace"); //$NON-NLS-1$
576
		} else if (firstCheck) {
577
			firstCheck = false;
578
			return;
579
		}
580
		if (newText.equals("")) { //$NON-NLS-1$
581
			errorMessage = IDEWorkbenchMessages.getString("ProjectWorkingSetPage.warning.nameMustNotBeEmpty"); //$NON-NLS-1$
582
		}
583
		if (errorMessage == null && (workingSet == null || newText.equals(workingSet.getName()) == false)) {
584
			IWorkingSet[] workingSets = PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSets();
585
			for (int i = 0; i < workingSets.length; i++) {
586
				if (newText.equals(workingSets[i].getName())) {
587
					errorMessage = IDEWorkbenchMessages.getString("ProjectWorkingSetPage.warning.workingSetExists"); //$NON-NLS-1$
588
				}
589
			}
590
		}
591
592
		// save working set name if we got this far
593
		if (errorMessage == null) {
594
			workingSet.setName(newText);
595
		}
596
		if (errorMessage == null && inclusionListViewer.getTable().getItemCount() == 0) {
597
			errorMessage = IDEWorkbenchMessages.getString("ProjectWorkingSetPage.warning.projectMustBeIncluded"); //$NON-NLS-1$
598
		}
599
		setErrorMessage(errorMessage);
600
		setPageComplete(errorMessage == null);
601
	}
602
	
603
	/*
604
	 *  (non-Javadoc)
605
	 * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
606
	 */
607
	public void setVisible(boolean visible) {
608
		super.setVisible(visible);
609
		setPageComplete(visible && inclusionListViewer.getTable().getItemCount() > 0);
610
	}
611
612
	/*
613
	 * get the list of projects from the workspace
614
	 */
615
	protected List /* <IProject[]> */ getWorkspaceProjects() {
616
		IProject[] projects = getWorkspaceRoot().getProjects();
617
		return Arrays.asList(projects);
618
	}
619
	
620
	/*
621
	 * Build a list of proxies to existing project working sets.
622
	 * If the current working set is already named, then it's own
623
	 * name will not appear in the list.
624
	 */
625
	protected List getWorkspaceProjectWorkingSets() {
626
		IWorkingSet[] sets = getWorkingSetManager().getWorkingSets();
627
		List list = new ArrayList();
628
		for (int i=0; i<sets.length; i++) {
629
			if (sets[i] instanceof ProjectWorkingSet) {
630
				ProjectWorkingSet set = (ProjectWorkingSet) sets[i];
631
				if (!set.getName().equals(workingSet.getName())) {
632
					list.add(new ProjectWorkingSetReference(set.getName()));
633
				}
634
			}
635
		}
636
		return list;
637
	}
638
	
639
	/*
640
	 * Get the Global WorkingSet manager from the workbench.
641
	 */
642
	protected IWorkingSetManager getWorkingSetManager() {
643
		return WorkbenchPlugin.getDefault().getWorkingSetManager();
644
	}
645
	
646
	/*
647
	 * Get the Workspace Root from our host Plugin
648
	 */
649
	protected IWorkspaceRoot getWorkspaceRoot() {
650
		return IDEWorkbenchPlugin.getPluginWorkspace().getRoot();
651
	}
652
}
(-)src/org/eclipse/ui/internal/ide/dialogs/ProjectWorkingSetReference.java (+148 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.dialogs;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.ui.IContainmentAdapter;
19
import org.eclipse.ui.IMemento;
20
import org.eclipse.ui.IPersistableElement;
21
import org.eclipse.ui.internal.IWorkbenchConstants;
22
import org.eclipse.ui.internal.WorkbenchPlugin;
23
import org.eclipse.ui.internal.ide.model.*;
24
25
/**
26
 * A ProjectWorkingSetReference represents a late-bindable reference
27
 * to a ProjectWorking set by storing and persisting just the name of
28
 * the working set and providing accessor methods to resolve the name
29
 * to an actual ProjectWorkingSet.
30
 * <p>
31
 * Performs late binding containment check and detects and avoids
32
 * circular references in working set references.
33
 * </p>
34
 * @since 3.0
35
 *
36
 */
37
public class ProjectWorkingSetReference
38
		implements
39
			IPersistableElement,
40
			IAdaptable,
41
			IContainmentAdapter {
42
	
43
	static final String FACTORY_ID = "org.eclipse.ui.ide.ProjectWorkingSetReferenceFactory"; //$NON-NLS-1$
44
	protected String name; // name of the referenced project working set
45
46
	/**
47
	 * Creates a new project working set reference from a memento.
48
	 * 
49
	 * @param name the name of the new working set. Should not have 
50
	 * 	leading or trailing whitespace.
51
	 * @param memento persistence memento containing the elements of  
52
	 * 	the working set.
53
	 */
54
	public ProjectWorkingSetReference(String name) {
55
		this.name = name;
56
	}
57
	
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.ui.IPersistableElement#getFactoryId()
60
	 */
61
	public String getFactoryId() {
62
		return FACTORY_ID;
63
	}
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.ui.IPersistableElement#saveState(org.eclipse.ui.IMemento)
66
	 */
67
	public void saveState(IMemento memento) {
68
		memento.putString(IWorkbenchConstants.TAG_NAME, name);
69
	}
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
72
	 */
73
	public Object getAdapter(Class adapter) {
74
		if (adapter == IContainmentAdapter.class || adapter == IPersistableElement.class) {
75
			return this;
76
		}
77
		return null;
78
	}
79
80
	/* (non-Javadoc)
81
	 * @see org.eclipse.ui.IContainmentAdapter#contains(java.lang.Object, java.lang.Object, int)
82
	 */
83
	public boolean contains(Object parentName, Object element, int flags) {
84
		// TODO instantiate the reference ProjectWorkingSet if it exists and
85
		// follow all references. The context is an array that holds the names of all
86
		// previsouly visited Working Sets so that we don't get stuck in a cycle.
87
		
88
		if (element == null) return false;
89
		
90
		// accumulation list of all sub-sets already checked
91
		List /* <String> */ visited  = new ArrayList();
92
		if (parentName != null)
93
			visited.add(parentName); // don't recurse back to parent
94
		
95
		return contains(visited, this, element);
96
	}
97
	
98
	/*
99
	 * Do all of the recursion by hand because we need to keep a "visited" list to avoid cycles.
100
	 */
101
	protected static boolean contains(List /* <String> */ visited, IAdaptable container, Object element) {
102
		if (container instanceof IProject && element instanceof IProject) {
103
			// for project element, just compare the full project name
104
			IProject wsProject = (IProject) container;
105
			IProject project = (IProject) element;
106
			return wsProject.getFullPath().equals(project.getFullPath());
107
		} else if (container instanceof ProjectWorkingSetReference){
108
			// get the real definition of ourself from the WorkingSetManager
109
			ProjectWorkingSetReference reference = (ProjectWorkingSetReference) container;
110
			ProjectWorkingSet self = (ProjectWorkingSet) WorkbenchPlugin.getDefault().getWorkingSetManager().getWorkingSet(reference.getName());
111
			if (self == null) return false;
112
			if (visited.contains(self.getName())) return false; // deja vous
113
			visited.add(self.getName()); // reminder to self...don't contemplate our own navel
114
			// test our sub elements for containment, passing our visited context to avoid cycles
115
			IAdaptable[] elements = self.getElements();
116
			for (int i=0; i < elements.length; i++) {
117
				IAdaptable adaptable = (IAdaptable) elements[i];
118
				if (contains(visited, adaptable, element)) {
119
					return true;
120
				}
121
			}
122
		}
123
		return false;
124
	}
125
	/**
126
	 * @return Returns the name.
127
	 */
128
	public String getName() {
129
		return name;
130
	}
131
	/**
132
	 * @param name The name to set.
133
	 */
134
	public void setName(String name) {
135
		this.name = name;
136
	}
137
	
138
	public String toString() {
139
		return getName();
140
	}
141
	/* (non-Javadoc)
142
	 * @see java.lang.Object#equals(java.lang.Object)
143
	 */
144
	public boolean equals(Object obj) {
145
		if (name == null) return super.equals(obj);
146
		else return name.equals(obj.toString());
147
	}
148
}
(-)src/org/eclipse/ui/internal/ide/dialogs/ProjectWorkingSetSorter.java (+43 lines)
Added Link Here
1
/******************************************************************************* 
2
 * Copyright (c) 2004 IBM Corporation and others. 
3
 * All rights reserved. This program and the accompanying materials! 
4
 * are made available under the terms of the Common Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/cpl-v10.html 
7
 * 
8
 * Contributors: 
9
 *      IBM Corporation - initial API and implementation
10
*************************************************************************/
11
package org.eclipse.ui.internal.ide.dialogs;
12
13
import java.text.Collator;
14
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.jface.viewers.ViewerSorter;
17
18
/**
19
 * Sort elements of type IProject and others. IProjects are sorted
20
 * as group first, and followed by others.
21
 */
22
public class ProjectWorkingSetSorter extends ViewerSorter {
23
	/**
24
	 * 
25
	 */
26
	public ProjectWorkingSetSorter() {
27
		super();
28
		// TODO Auto-generated constructor stub
29
	}
30
	/**
31
	 * @param collator
32
	 */
33
	public ProjectWorkingSetSorter(Collator collator) {
34
		super(collator);
35
		// TODO Auto-generated constructor stub
36
	}
37
	/* (non-Javadoc)
38
	 * @see org.eclipse.jface.viewers.ViewerSorter#category(java.lang.Object)
39
	 */
40
	public int category(Object element) {
41
		return (element instanceof IProject) ? 1 : 0;
42
	}
43
}
(-)src/org/eclipse/ui/internal/ide/dialogs/SWTUtil.java (+120 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.dialogs;
12
/**
13
 * @version 	1.0
14
 * @author
15
 */
16
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.dialogs.IDialogConstants;
18
import org.eclipse.jface.resource.JFaceResources;
19
import org.eclipse.jface.util.Assert;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.dnd.DragSource;
22
import org.eclipse.swt.dnd.DropTarget;
23
import org.eclipse.swt.graphics.Point;
24
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Caret;
27
import org.eclipse.swt.widgets.Control;
28
import org.eclipse.swt.widgets.Display;
29
import org.eclipse.swt.widgets.Menu;
30
import org.eclipse.swt.widgets.ScrollBar;
31
import org.eclipse.swt.widgets.Shell;
32
import org.eclipse.swt.widgets.Widget;
33
34
35
/**
36
 * Utility class to simplify access to some SWT resources. 
37
 */
38
public class SWTUtil {
39
40
	/**
41
	 * Returns the standard display to be used. The method first checks, if
42
	 * the thread calling this method has an associated disaply. If so, this
43
	 * display is returned. Otherwise the method returns the default display.
44
	 */
45
	public static Display getStandardDisplay() {
46
		Display display;
47
		display = Display.getCurrent();
48
		if (display == null)
49
			display = Display.getDefault();
50
		return display;
51
	}
52
53
	/**
54
	 * Returns the shell for the given widget. If the widget doesn't represent
55
	 * a SWT object that manage a shell, <code>null</code> is returned.
56
	 * 
57
	 * @return the shell for the given widget
58
	 */
59
	public static Shell getShell(Widget widget) {
60
		if (widget instanceof Control)
61
			return ((Control) widget).getShell();
62
		if (widget instanceof Caret)
63
			return ((Caret) widget).getParent().getShell();
64
		if (widget instanceof DragSource)
65
			return ((DragSource) widget).getControl().getShell();
66
		if (widget instanceof DropTarget)
67
			return ((DropTarget) widget).getControl().getShell();
68
		if (widget instanceof Menu)
69
			return ((Menu) widget).getParent().getShell();
70
		if (widget instanceof ScrollBar)
71
			return ((ScrollBar) widget).getParent().getShell();
72
73
		return null;
74
	}
75
76
	/**
77
	 * Returns a width hint for a button control.
78
	 */
79
	public static int getButtonWidthHint(Button button) {
80
		if (button.getFont().equals(JFaceResources.getDefaultFont()))
81
			button.setFont(JFaceResources.getDialogFont());
82
		PixelConverter converter= new PixelConverter(button);
83
		int widthHint= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
84
		return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
85
	}
86
87
	/**
88
	 * Returns a height hint for a button control.
89
	 */
90
	public static int getButtonHeigthHint(Button button) {
91
		if (button.getFont().equals(JFaceResources.getDefaultFont()))
92
			button.setFont(JFaceResources.getDialogFont());
93
		PixelConverter converter= new PixelConverter(button);
94
		return converter.convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
95
	}
96
97
	/**
98
	 * Sets width and height hint for the button control.
99
	 * <b>Note:</b> This is a NOP if the button's layout data is not
100
	 * an instance of <code>GridData</code>.
101
	 * 
102
	 * @param	the button for which to set the dimension hint
103
	 */
104
	public static void setButtonDimensionHint(Button button) {
105
		Assert.isNotNull(button);
106
		Object gd = button.getLayoutData();
107
		if (gd instanceof GridData) {
108
			((GridData) gd).heightHint = getButtonHeigthHint(button);
109
			((GridData) gd).widthHint = getButtonWidthHint(button);
110
		}
111
	}
112
113
	public static void setDialogSize(Dialog dialog, int width, int height) {
114
		Point computedSize =
115
			dialog.getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
116
		width = Math.max(computedSize.x, width);
117
		height = Math.max(computedSize.y, height);
118
		dialog.getShell().setSize(width, height);
119
	}
120
}
(-)src/org/eclipse/ui/internal/ide/model/ProjectWorkingSet.java (+153 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.model;
12
13
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.jface.resource.ImageDescriptor;
16
import org.eclipse.ui.IContainmentAdapter;
17
import org.eclipse.ui.IMemento;
18
import org.eclipse.ui.IPersistableElement;
19
import org.eclipse.ui.ISharedImages;
20
import org.eclipse.ui.IWorkingSet;
21
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.internal.WorkingSet;
23
import org.eclipse.ui.internal.ide.dialogs.ProjectWorkingSetReference;
24
25
/**
26
 * A ProjectWorkingSet is a WorkingSet that holds projects and nested sub-sets.
27
 * <p>
28
 * Each element of the ProjectWorkingSet implents the <code>IAdaptable</code>
29
 * interface as needed by <code>IWorkingSet</code>. In addition, ProjectWorkingSet
30
 * implements the <code>IContainmentAdapter</code> interface which allows it to
31
 * answer questions about elements contained by the working set. This is
32
 * what allows ProjectWorkingSet to hold projects nested within sub-sets without
33
 * exposing that structure to clients of the <code>IWorkingSet</code> interface.
34
 * </p><p>
35
 * The <code>contains</code> method is eventually called by the WorkingSetFilter
36
 * classes within the workbench to decide if this WorkingSet contains projects
37
 * that should be included or excluded by the filter.
38
 * </p><p>
39
 * A ProjectWorkingSet defines a working set as a set of Projects and ProjectWorkingSets.
40
 * Projects are the usual workspace projects. ProjectWorkingSets that are included in a
41
 * definition are proxied by a ProjectWorkingSetReference and all usage of the working
42
 * set is evaluated as lazily (late) as possible. The actual project working set that
43
 * is refered to is not instantiated until the working set is used via the
44
 * <code>contains</code> method. This allows the definition of referenced sub-sets to
45
 * change and result in changed run-time behavior of the parent working set.
46
 * </p><p>
47
 * ProjectWorkingSet(s) may contain references to other ProjectWorkingSet(s), which
48
 * makes it possible to have circular references between sets. The only restrictions
49
 * placed on defintions of ProjectWorkingSets is that they may not reference themselves.
50
 * Circular references are detected at evaluation time in the <code>contains</code>
51
 * method so that working sets are only tested once. It is important to allow these
52
 * cycles because the definer of a working set has not control over what other sets
53
 * may include her working sets. Also, because sets will be persisted, imported, and
54
 * exported, these evaluations must be done as late as possible. References to sets
55
 * that do not exist are quietly ignored at evaluation time. This ensures robust
56
 * operation in environments of large working groups with hundreds of projects,
57
 * tens of working sets, and frequent sharing/importing of working set definitions.
58
 * </p><p>
59
 * ProjectWorkingSet(s) and their proxies are persistable via the <code>IPersitableElement</code>
60
 * interface, which allows them to be saved as part of the existing WorkingSet
61
 * infrastructure (@see WorkingSetManager). They are re-created from their persisted
62
 * content via a <code>ProjectWorkingSetFactory</code> class that is registered in the
63
 * plugin XML specification under the extension point "org.eclipse.ui.elementFactories".
64
 * The <code>ProjectWorkingSetReference</code> also has a factory.
65
 */
66
public class ProjectWorkingSet extends WorkingSet implements IContainmentAdapter {
67
	static final String FACTORY_ID = "org.eclipse.ui.ide.ProjectWorkingSetFactory"; //$NON-NLS-1$
68
	
69
	/**
70
	 * Construct a ProjectWorkingSet from a previously persisted
71
	 * <code>IMemento</code>. This is meant to be called by an element
72
	 * factory that restores saved working set definitions.
73
	 * 
74
	 * @param name the name of the new working set. Should not have 
75
	 * 	leading or trailing whitespace.
76
	 * @param memento persistence memento containing the elements of  
77
	 * 	the working set.
78
	 */
79
	public ProjectWorkingSet(String name, IMemento memento) {
80
		super(name, memento);
81
	}
82
	
83
	/**
84
	 * Construct a ProjectWorkingSet from it's name and the memebers of its set.
85
	 * Set members implement the <code>IAdaptable</code> interface, and presently
86
	 * include <code>IProject</code> and <code>ProjectWorkingSetReference</code>.
87
	 * 
88
	 * @param name
89
	 * @param elements
90
	 */
91
	public ProjectWorkingSet(String name, IAdaptable[] elements) {
92
		super(name, elements);
93
	}
94
	/* (non-Javadoc)
95
	 * @see org.eclipse.ui.IWorkingSet#getId()
96
	 */
97
	public String getId() {
98
		return "org.eclipse.ui.ide.projectWorkingSetPage"; //$NON-NLS-1$
99
	}
100
	/* (non-Javadoc)
101
	 * @see org.eclipse.ui.IPersistableElement
102
	 */
103
	public String getFactoryId() {
104
		return FACTORY_ID;
105
	}
106
	/* (non-Javadoc)
107
	 * @see org.eclipse.ui.IWorkingSet#getImage()
108
	 */
109
	public ImageDescriptor getImage() {
110
		return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT);
111
	}
112
113
	/**
114
	 * Returns the receiver if the requested type is either IWorkingSet 
115
	 * or IPersistableElement or IContainmentAdapter. In the later case,
116
	 * we answer questions about sub-sets and projects contained within
117
	 * this working set.
118
	 * 
119
	 * @param adapter the requested type
120
	 * @return the receiver if the requested type is either IWorkingSet 
121
	 * 	or IPersistableElement or IContainmentAdapter.
122
	 */
123
	public Object getAdapter(Class adapter) {
124
		if (adapter == IContainmentAdapter.class || adapter == IWorkingSet.class || adapter == IPersistableElement.class) {
125
			return this;
126
		}
127
		return null;
128
	}
129
	
130
	/* (non-Javadoc)
131
	 * @see org.eclipse.ui.IContainmentAdapter#contains(java.lang.Object, java.lang.Object, int)
132
	 */
133
	public boolean contains(Object workingSetElement, Object element, int flags) {
134
		if (element == null) return false;
135
		if (workingSetElement == element) return true;
136
		if (workingSetElement instanceof IProject) {
137
			// for project element, just compare the full project name
138
			IProject wsProject = (IProject) workingSetElement;
139
			IProject project = (IProject) element;
140
			return wsProject.getFullPath().equals(project.getFullPath());
141
		} else if (workingSetElement instanceof ProjectWorkingSetReference) {
142
			// for workingset references, we ask the reference to answer the question
143
			// because it needs to provide cycle detection. Pass the name of the top-level
144
			// working set as a "context" so that the down-stream search can avoid cycling
145
			// back into the parent.
146
			ProjectWorkingSetReference reference = (ProjectWorkingSetReference) workingSetElement;
147
			return reference.contains(getName(), element, flags);
148
		} else {
149
			// workingSetElement wasn't a type we understand
150
			return false;
151
		}
152
	}
153
}
(-)src/org/eclipse/ui/internal/ide/model/ProjectWorkingSetFactory.java (+45 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.model;
12
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.ui.IElementFactory;
15
import org.eclipse.ui.IMemento;
16
import org.eclipse.ui.internal.IWorkbenchConstants;
17
18
/**
19
 * A ProjectWorkingSetFactory is used to recreate a persisted ProjectWorkingSet 
20
 * object.
21
 */
22
public class ProjectWorkingSetFactory implements IElementFactory {
23
24
	/* (non-Javadoc)
25
	 * @see org.eclipse.ui.IElementFactory
26
	 */
27
	public IAdaptable createElement(IMemento memento) {
28
		String workingSetName = memento.getString(IWorkbenchConstants.TAG_NAME);
29
		String workingSetEditPageId = memento.getString(IWorkbenchConstants.TAG_EDIT_PAGE_ID);
30
		
31
		if (workingSetName == null)
32
			return null;
33
34
		ProjectWorkingSet workingSet = new ProjectWorkingSet(workingSetName, memento);
35
		if (workingSetEditPageId != null) {
36
			workingSet.setId(workingSetEditPageId);
37
		}
38
		else {
39
			// working sets created with builds 20020418 and 20020419 will not
40
			// have an edit page id. fix this automatically.
41
			workingSet.setId("org.eclipse.ui.ide.projectWorkingSetPage"); //$NON-NLS-1$
42
		}
43
		return workingSet;
44
	}
45
}
(-)src/org/eclipse/ui/internal/ide/model/ProjectWorkingSetReferenceFactory.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.model;
12
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.ui.IElementFactory;
15
import org.eclipse.ui.IMemento;
16
import org.eclipse.ui.internal.IWorkbenchConstants;
17
import org.eclipse.ui.internal.ide.dialogs.ProjectWorkingSetReference;
18
19
/**
20
 * A ProjectWorkingSetReferenceFactory is used to recreate a persisted
21
 * ProjectWorkingSetReference object.
22
 */
23
public class ProjectWorkingSetReferenceFactory implements IElementFactory {
24
25
	/* (non-Javadoc)
26
	 * @see org.eclipse.ui.IElementFactory
27
	 */
28
	public IAdaptable createElement(IMemento memento) {
29
		String workingSetName = memento.getString(IWorkbenchConstants.TAG_NAME);
30
		
31
		if (workingSetName == null)
32
			return null;
33
34
		ProjectWorkingSetReference workingSet = new ProjectWorkingSetReference(workingSetName);
35
		return workingSet;
36
	}
37
}

Return to bug 37389