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 |
} |