KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > wizards > ExportProjectSetMainPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  * Patrick Dempsey <pd@bandxi.com> - Bug 177813 Export Team Project Set does not updateEnablement() when switching bewteen Project and Working sets
11  *******************************************************************************/

12 package org.eclipse.team.internal.ui.wizards;
13
14 import java.util.*;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.resources.*;
18 import org.eclipse.core.resources.mapping.ResourceMapping;
19 import org.eclipse.core.runtime.IAdaptable;
20 import org.eclipse.jface.dialogs.Dialog;
21 import org.eclipse.jface.dialogs.IDialogConstants;
22 import org.eclipse.jface.resource.ImageDescriptor;
23 import org.eclipse.jface.util.IPropertyChangeListener;
24 import org.eclipse.jface.util.PropertyChangeEvent;
25 import org.eclipse.jface.viewers.*;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.custom.SashForm;
28 import org.eclipse.swt.events.SelectionAdapter;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.graphics.Color;
31 import org.eclipse.swt.layout.*;
32 import org.eclipse.swt.widgets.*;
33 import org.eclipse.team.core.RepositoryProvider;
34 import org.eclipse.team.internal.ui.*;
35 import org.eclipse.ui.*;
36 import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
37 import org.eclipse.ui.ide.ResourceUtil;
38 import org.eclipse.ui.model.WorkbenchLabelProvider;
39 import org.eclipse.ui.part.Page;
40 import org.eclipse.ui.part.PageBook;
41
42 public class ExportProjectSetMainPage extends TeamWizardPage {
43     
44     PageBook book;
45     ProjectPage projectPage;
46     WorkingSetPage workingSetPage;
47     
48     IExportProjectSetPage selectedPage;
49     
50     Button exportWorkingSets;
51     
52     ArrayList passedInSelectedProjects = new ArrayList();
53     
54     class ProjectContentProvider implements ITreePathContentProvider{
55
56         public Object JavaDoc[] getChildren(TreePath parentPath) {
57             Object JavaDoc obj = parentPath.getLastSegment();
58             if (obj instanceof IWorkingSet){
59                 return ((IWorkingSet)obj).getElements();
60             }
61             return null;
62         }
63
64         public TreePath[] getParents(Object JavaDoc element) {
65             if (element instanceof IProject){
66                 ArrayList treePaths = new ArrayList();
67                 IWorkingSet[] workingSets = TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager().getWorkingSets();
68                 for (int i = 0; i < workingSets.length; i++) {
69                     IAdaptable[] elements = workingSets[i].getElements();
70                     for (int j = 0; j < elements.length; j++) {
71                         if (elements[j].equals(element)){
72                             treePaths.add(workingSets[i]);
73                             break;
74                         }
75                     }
76                 }
77                 return (TreePath[]) treePaths.toArray(new TreePath[treePaths.size()]);
78             }
79             return null;
80         }
81
82         public boolean hasChildren(TreePath path) {
83             Object JavaDoc obj = path.getLastSegment();
84             if (obj instanceof IWorkingSet)
85                 return true;
86             
87             return false;
88         }
89
90         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
91             if (inputElement instanceof IWorkspaceRoot) {
92                 IWorkspaceRoot root = (IWorkspaceRoot) inputElement;
93                 List JavaDoc projectList = new ArrayList();
94                 IProject[] workspaceProjects = root.getProjects();
95                 for (int i = 0; i < workspaceProjects.length; i++) {
96                     if (isProjectExportable(workspaceProjects[i])) {
97                         projectList.add(workspaceProjects[i]);
98                     }
99                 }
100                 return projectList.toArray(new IProject[projectList.size()]);
101             } else if (inputElement instanceof IWorkingSetManager){
102                 IWorkingSetManager manager = (IWorkingSetManager) inputElement;
103                 IWorkingSet[] allSets = manager.getAllWorkingSets();
104                 ArrayList resourceSets = new ArrayList();
105                 for (int i = 0; i < allSets.length; i++)
106                     if (isWorkingSetSupported(allSets[i]))
107                         resourceSets.add(allSets[i]);
108                 
109                 return resourceSets.toArray(new IWorkingSet[resourceSets.size()]);
110             } else if (inputElement instanceof IAdaptable){
111                 IProject[] tempProjects = getProjectsForObject(inputElement);
112                 if (tempProjects != null)
113                     return tempProjects;
114             }
115             else if (inputElement instanceof IAdaptable[]){
116                 IAdaptable[] tempAdaptable = (IAdaptable[]) inputElement;
117                 return getProjectsForAdaptables(tempAdaptable);
118             } else if (inputElement instanceof HashSet){
119                 Set tempList = new HashSet();
120                 HashSet inputElementSet = (HashSet) inputElement;
121                 for (Iterator iterator = inputElementSet.iterator(); iterator.hasNext();) {
122                     IProject[] projects = getProjectsForObject(iterator.next());
123                     if (projects != null)
124                         tempList.addAll(Arrays.asList(projects));
125                 }
126                 
127                 return (IProject[]) tempList.toArray(new IProject[tempList.size()]);
128             }
129             
130             return null;
131         }
132
133         public void dispose() {
134             
135         }
136
137         public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
138             
139         }
140     
141     };
142     
143     private class ExportProjectSetLabelProvider extends WorkbenchLabelProvider {
144
145         public Color getForeground(Object JavaDoc element) {
146             if (element instanceof IProject
147                     && !isProjectExportable((IProject) element)) {
148                 return Display.getCurrent().getSystemColor(
149                         SWT.COLOR_WIDGET_NORMAL_SHADOW);
150             }
151             return super.getForeground(element);
152         }
153     }
154     
155     private IProject[] getProjectsForObject(Object JavaDoc object) {
156         ResourceMapping resourceMapping = Utils.getResourceMapping(object);
157         if (resourceMapping != null) {
158             return resourceMapping.getProjects();
159         } else {
160             IResource resource = Utils.getResource(object);
161             if (resource != null && resource.getType() != IResource.ROOT)
162                 return new IProject[] { resource.getProject() };
163         }
164         return null;
165     }
166     
167     private IProject[] getProjectsForAdaptables(IAdaptable[] adaptable) {
168         Set projectSet = new HashSet();
169         for (int i = 0; i < adaptable.length; i++) {
170             IProject[] projects = getProjectsForObject(adaptable[i]);
171             if (projects != null)
172                 projectSet.addAll(Arrays.asList(projects));
173         }
174         if (!projectSet.isEmpty())
175             return (IProject[]) projectSet.toArray(new IProject[0]);
176
177         return null;
178     }
179     
180     private static boolean isWorkingSetSupported(IWorkingSet workingSet) {
181         if (!workingSet.isEmpty() && !workingSet.isAggregateWorkingSet()) {
182             IAdaptable[] elements = workingSet.getElements();
183             for (int i = 0; i < elements.length; i++) {
184                 IResource resource = ResourceUtil.getResource(elements[i]);
185                 if (resource != null)
186                     // support a working set if it contains at least one resource
187
return true;
188             }
189         }
190         return false;
191     }
192     
193     private boolean isProjectExportable(IProject project) {
194         return RepositoryProvider.getProvider(project) != null;
195     }
196     
197     public ExportProjectSetMainPage(String JavaDoc pageName, String JavaDoc title, ImageDescriptor titleImage) {
198         super(pageName, title, titleImage);
199         setDescription(TeamUIMessages.ExportProjectSetMainPage_description);
200     }
201
202     /*
203      * @see IDialogPage#createControl(Composite)
204      */

205     public void createControl(Composite parent) {
206         Composite c = SWTUtils.createHVFillComposite(parent, 0);
207         
208         //Add the export working set section
209
exportWorkingSets(c);
210         
211         book = new PageBook(c, SWT.NONE);
212         book.setLayoutData(SWTUtils.createHVFillGridData());
213         // set F1 help
214
PlatformUI.getWorkbench().getHelpSystem().setHelp(book, IHelpContextIds.EXPORT_PROJECT_SET_PAGE);
215         
216         workingSetPage = new WorkingSetPage();
217         workingSetPage.createControl(book);
218         
219         projectPage = new ProjectPage();
220         //pass in any selected
221
projectPage.getSelectedProjects().addAll(passedInSelectedProjects);
222         projectPage.getReferenceCountProjects().addAll(passedInSelectedProjects);
223         
224         projectPage.createControl(book);
225
226         setControl(c);
227         book.showPage(projectPage.getControl());
228         
229         selectedPage = projectPage;
230         
231         Dialog.applyDialogFont(parent);
232     }
233
234     private void exportWorkingSets(Composite composite) {
235         exportWorkingSets = new Button(composite, SWT.CHECK | SWT.LEFT);
236         exportWorkingSets.setText(TeamUIMessages.ExportProjectSetMainPage_ExportWorkingSets);
237     
238         exportWorkingSets.setSelection(false);
239         exportWorkingSets.addSelectionListener(new SelectionAdapter() {
240             public void widgetSelected(SelectionEvent e) {
241                 if (((Button) e.widget).getSelection()){
242                     book.showPage(workingSetPage.getControl());
243                     selectedPage = workingSetPage;
244                     workingSetPage.refresh();
245                     workingSetPage.updateEnablement();
246                 }
247                 else{
248                     book.showPage(projectPage.getControl());
249                     selectedPage = projectPage;
250                     projectPage.updateEnablement();
251                 }
252             }
253         });
254     }
255     
256     public IWorkingSet[] getSelectedWorkingSets(){
257         return (IWorkingSet[]) selectedPage.getWorkingSet().toArray(new IWorkingSet[selectedPage.getWorkingSet().size()]);
258     }
259     
260     public IProject[] getSelectedProjects() {
261         return (IProject[]) selectedPage.getSelectedProjects().toArray(new IProject[selectedPage.getSelectedProjects().size()]);
262     }
263
264     public void setSelectedProjects(IProject[] selectedProjects) {
265         passedInSelectedProjects.addAll(Arrays.asList(selectedProjects));
266     }
267     
268     private interface IExportProjectSetPage{
269         HashSet getSelectedProjects();
270         ArrayList getReferenceCountProjects();
271         ArrayList getWorkingSet();
272     }
273     
274     private class ProjectPage extends Page implements IExportProjectSetPage {
275         private Composite projectComposite;
276
277         private CheckboxTableViewer tableViewer;
278         private Table table;
279         
280         HashSet selectedProjects = new HashSet();
281         ArrayList referenceCountProjects = new ArrayList();
282         ArrayList selectedWorkingSet = new ArrayList();
283
284         public void createControl(Composite parent) {
285             
286             projectComposite = SWTUtils.createHVFillComposite(parent, 1);
287             initializeDialogUnits(projectComposite);
288             
289             //Adds the project table
290
addProjectSection(projectComposite);
291             initializeProjects();
292             updateEnablement();
293         }
294
295         public Control getControl() {
296             return projectComposite;
297         }
298
299         public void setFocus() {
300             projectComposite.setFocus();
301         }
302         
303         private void addProjectSection(Composite composite) {
304             
305             createLabel(composite, TeamUIMessages.ExportProjectSetMainPage_Select_the_projects_to_include_in_the_project_set__2);
306
307             table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
308             tableViewer = new CheckboxTableViewer(table);
309             table.setLayout(new TableLayout());
310             GridData data = new GridData(GridData.FILL_BOTH);
311             data.heightHint = 300;
312             table.setLayoutData(data);
313             tableViewer.setContentProvider(new ProjectContentProvider());
314             tableViewer.setLabelProvider(new WorkbenchLabelProvider());
315             tableViewer.addCheckStateListener(new ICheckStateListener() {
316                 public void checkStateChanged(CheckStateChangedEvent event) {
317                     Object JavaDoc temp = event.getElement();
318                     if (temp instanceof IProject){
319                         IProject project = (IProject) event.getElement();
320                         if (event.getChecked()) {
321                             selectedProjects.add(project);
322                             referenceCountProjects.add(project);
323                         } else {
324                             selectedProjects.remove(project);
325                             referenceCountProjects.remove(project);
326                         }
327                     } else if (temp instanceof IWorkingSet){
328                         IWorkingSet workingSet = (IWorkingSet) temp;
329                         if (event.getChecked()){
330                             IAdaptable[] elements = workingSet.getElements();
331                             for (int i = 0; i < elements.length; i++) {
332                                 selectedProjects.add(elements[i]);
333                             }
334                         } else {
335                             IAdaptable[] elements = workingSet.getElements();
336                             for (int i = 0; i < elements.length; i++) {
337                                 selectedProjects.remove(elements[i]);
338                             }
339                         }
340                     }
341                     updateEnablement();
342                 }
343             });
344
345             Composite buttonComposite = new Composite(composite, SWT.NONE);
346             GridLayout layout = new GridLayout();
347             layout.numColumns = 2;
348             layout.marginWidth = 0;
349             buttonComposite.setLayout(layout);
350             data = new GridData(SWT.FILL, SWT.FILL, true, false);
351             buttonComposite.setLayoutData(data);
352
353             Button selectAll = new Button(buttonComposite, SWT.PUSH);
354             data = new GridData();
355             data.verticalAlignment = GridData.BEGINNING;
356             data.horizontalAlignment = GridData.END;
357             int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
358             data.widthHint = Math.max(widthHint, selectAll.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
359             selectAll.setLayoutData(data);
360             selectAll.setText(TeamUIMessages.ExportProjectSetMainPage_SelectAll);
361             selectAll.addListener(SWT.Selection, new Listener() {
362                 public void handleEvent(Event event) {
363                     tableViewer.setAllChecked(true);
364                     selectedProjects.removeAll(selectedProjects);
365                     Object JavaDoc[] checked = tableViewer.getCheckedElements();
366                     for (int i = 0; i < checked.length; i++) {
367                         selectedProjects.add(checked[i]);
368                     }
369                     updateEnablement();
370                 }
371             });
372
373             Button deselectAll = new Button(buttonComposite, SWT.PUSH);
374             data = new GridData();
375             data.verticalAlignment = GridData.BEGINNING;
376             data.horizontalAlignment = GridData.END;
377             widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
378             data.widthHint = Math.max(widthHint, deselectAll.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
379             deselectAll.setLayoutData(data);
380             deselectAll.setText(TeamUIMessages.ExportProjectSetMainPage_DeselectAll);
381             deselectAll.addListener(SWT.Selection, new Listener() {
382                 public void handleEvent(Event event) {
383                     tableViewer.setAllChecked(false);
384                     selectedProjects.removeAll(selectedProjects);
385                     updateEnablement();
386                 }
387             });
388         }
389         
390         private void initializeProjects() {
391             tableViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
392         
393             // Check any necessary projects
394
if (selectedProjects != null) {
395                 tableViewer.setCheckedElements(selectedProjects.toArray(new IProject[selectedProjects.size()]));
396             }
397         }
398         
399         private void updateEnablement() {
400             boolean complete;
401             
402             complete = (selectedProjects.size() != 0);
403             
404             if (complete) {
405                 setMessage(null);
406             }
407             setPageComplete(complete);
408         }
409
410         public ArrayList getReferenceCountProjects() {
411             return referenceCountProjects;
412         }
413
414         public HashSet getSelectedProjects() {
415             return selectedProjects;
416         }
417
418         public ArrayList getWorkingSet() {
419             return selectedWorkingSet;
420         }
421
422     }
423
424     private class WorkingSetPage extends Page implements IExportProjectSetPage {
425
426         private Composite projectComposite;
427         private Table wsTable;
428         private CheckboxTableViewer wsTableViewer;
429         
430         private Table table;
431         private TableViewer tableViewer;
432         
433
434         HashSet selectedProjects = new HashSet();
435         ArrayList referenceCountProjects = new ArrayList();
436         ArrayList selectedWorkingSet = new ArrayList();
437         
438         public void createControl(Composite parent) {
439            
440             projectComposite = SWTUtils.createHVFillComposite(parent, 1);
441             initializeDialogUnits(projectComposite);
442
443             Label label = createLabel (projectComposite, TeamUIMessages.ExportProjectSetMainPage_SelectButton);
444             GridData grid = (GridData) label.getLayoutData();
445             label.setData(grid);
446             
447             SashForm form = new SashForm(projectComposite, SWT.HORIZONTAL);
448             form.setLayout(new FillLayout());
449             GridData data = new GridData(GridData.FILL_BOTH);
450             form.setLayoutData(data);
451
452             // Adds the working set table
453
addWorkingSetSection(form);
454
455             addProjectSection(form);
456
457             form.setWeights(new int[] { 75, 25 });
458
459             addButtons(projectComposite);
460             updateEnablement();
461         }
462         
463         private void addProjectSection(Composite composite) {
464                 
465                 table = new Table(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
466                 tableViewer = new TableViewer(table);
467                 table.setLayout(new TableLayout());
468                 GridData data = new GridData(GridData.FILL_BOTH);
469                 data.heightHint = 300;
470                 table.setLayoutData(data);
471                 tableViewer.setContentProvider(new ProjectContentProvider());
472                 tableViewer.setLabelProvider(new ExportProjectSetLabelProvider());
473             }
474         
475         private void addWorkingSetSection(Composite projectComposite) {
476
477             wsTable = new Table(projectComposite, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
478             wsTableViewer = new CheckboxTableViewer(wsTable);
479             wsTable.setLayout(new TableLayout());
480             GridData data = new GridData(GridData.FILL_BOTH);
481             data.heightHint = 300;
482             wsTable.setLayoutData(data);
483             wsTableViewer.setContentProvider(new ProjectContentProvider());
484             wsTableViewer.setLabelProvider(new WorkbenchLabelProvider());
485             wsTableViewer.addCheckStateListener(new ICheckStateListener() {
486                 public void checkStateChanged(CheckStateChangedEvent event) {
487                     Object JavaDoc temp = event.getElement();
488                     if (temp instanceof IWorkingSet){
489                         IWorkingSet workingSet = (IWorkingSet) temp;
490                         if (event.getChecked()){
491                             workingSetAdded(workingSet);
492                             //Add the selected project to the table viewer
493
tableViewer.setInput(selectedProjects);
494                         } else {
495                             workingSetRemoved(workingSet);
496                             //Add the selected project to the table viewer
497
tableViewer.setInput(selectedProjects);
498                         }
499                     }
500                     updateEnablement();
501                 }
502             });
503
504             wsTableViewer.setInput(TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager());
505         }
506
507         private void addButtons(Composite projectComposite){
508         
509             Composite buttonComposite = new Composite(projectComposite, SWT.NONE);
510             GridLayout layout = new GridLayout();
511             layout.numColumns = 3;
512             layout.marginWidth = 0;
513             buttonComposite.setLayout(layout);
514             GridData data = new GridData(SWT.FILL, SWT.FILL, false, false);
515             buttonComposite.setLayoutData(data);
516              
517             Button selectAll = new Button(buttonComposite, SWT.PUSH);
518             data = new GridData();
519             data.verticalAlignment = GridData.FILL;
520             data.horizontalAlignment = GridData.FILL;
521             int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
522             data.widthHint = Math.max(widthHint, selectAll.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
523             selectAll.setLayoutData(data);
524             selectAll.setText(TeamUIMessages.ExportProjectSetMainPage_SelectAll);
525             selectAll.addListener(SWT.Selection, new Listener() {
526                 public void handleEvent(Event event) {
527                     wsTableViewer.setAllChecked(true);
528                     
529                     selectedProjects.removeAll(selectedProjects);
530                     selectedWorkingSet.removeAll(selectedWorkingSet);
531                     Object JavaDoc[] checked = wsTableViewer.getCheckedElements();
532                     for (int i = 0; i < checked.length; i++) {
533                         selectedWorkingSet.add(checked[i]);
534                         if (checked[i] instanceof IWorkingSet){
535                             IWorkingSet ws = (IWorkingSet) checked[i];
536                             IAdaptable[] elements = ws.getElements();
537                             addProjects(elements);
538                         }
539                         tableViewer.setInput(selectedProjects);
540                     }
541                     updateEnablement();
542                 }
543             });
544
545             Button deselectAll = new Button(buttonComposite, SWT.PUSH);
546             data = new GridData();
547             data.verticalAlignment = GridData.FILL;
548             data.horizontalAlignment = GridData.FILL;
549             widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
550             data.widthHint = Math.max(widthHint, deselectAll.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
551             deselectAll.setLayoutData(data);
552             deselectAll.setText(TeamUIMessages.ExportProjectSetMainPage_DeselectAll);
553             deselectAll.addListener(SWT.Selection, new Listener() {
554                 public void handleEvent(Event event) {
555                     wsTableViewer.setAllChecked(false);
556                     selectedWorkingSet.removeAll(selectedWorkingSet);
557                     selectedProjects.removeAll(selectedProjects);
558                     referenceCountProjects.removeAll(referenceCountProjects);
559                     tableViewer.setInput(selectedProjects);
560                     updateEnablement();
561                 }
562             });
563             
564             Button newWorkingSet = new Button(buttonComposite, SWT.PUSH);
565             data = new GridData();
566             data.verticalAlignment = GridData.FILL;
567             data.horizontalAlignment = GridData.FILL;
568             widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
569             data.widthHint = Math.max(widthHint, deselectAll.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
570             newWorkingSet.setLayoutData(data);
571             newWorkingSet.setText(TeamUIMessages.ExportProjectSetMainPage_EditButton);
572             newWorkingSet.addListener(SWT.Selection, new Listener() {
573                 public void handleEvent(Event event) {
574                     final IWorkingSetManager workingSetManager = TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager();
575                     IWorkingSetSelectionDialog wsWizard = workingSetManager.createWorkingSetSelectionDialog(getShell(), false);
576                     if (wsWizard != null) {
577                         IPropertyChangeListener propListener = null;
578                         try {
579                             //add event listener
580
propListener = new IPropertyChangeListener() {
581                                 public void propertyChange(PropertyChangeEvent event) {
582                                     
583                                 }};
584                                 
585                             workingSetManager.addPropertyChangeListener(propListener);
586                             wsWizard.open();
587                             //recalculate working sets
588
selectedWorkingSet.removeAll(selectedWorkingSet);
589                             referenceCountProjects.removeAll(selectedProjects);
590                             selectedProjects.removeAll(selectedProjects);
591                             wsTableViewer.setInput(workingSetManager);
592                             Object JavaDoc[] checked = wsTableViewer.getCheckedElements();
593                             for (int i = 0; i < checked.length; i++) {
594                                 selectedWorkingSet.add(checked[i]);
595                                 if (checked[i] instanceof IWorkingSet) {
596                                     IWorkingSet ws = (IWorkingSet) checked[i];
597                                     IAdaptable[] elements = ws.getElements();
598                                     addProjects(elements);
599                                 }
600                             }
601                         
602                             wsTableViewer.setInput(workingSetManager);
603                             tableViewer.setInput(selectedProjects);
604                         } finally {
605                             if (propListener != null)
606                                 workingSetManager.removePropertyChangeListener(propListener);
607                         }
608                     }
609                 }
610             });
611         }
612         
613         public Control getControl() {
614             return projectComposite;
615         }
616
617         public void setFocus() {
618             projectComposite.setFocus();
619         }
620
621         public void refresh(){
622             wsTableViewer.setInput(TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager());
623         }
624         
625         private void updateEnablement() {
626             boolean complete = ((selectedProjects.size() != 0) && (selectedWorkingSet.size() != 0));
627             
628             // check if there is at least one exportable project selected
629
if (complete) {
630                 complete = false;
631                 for (Iterator iterator = selectedProjects.iterator(); iterator
632                         .hasNext();) {
633                     IProject selectedProject = (IProject) iterator.next();
634                     if (isProjectExportable(selectedProject)) {
635                         complete = true;
636                         break;
637                     }
638                 }
639             }
640             
641             if (complete) {
642                 setMessage(null);
643             }
644             setPageComplete(complete);
645         }
646
647         public ArrayList getReferenceCountProjects() {
648             return referenceCountProjects;
649         }
650
651         public HashSet getSelectedProjects() {
652             return selectedProjects;
653         }
654
655         public ArrayList getWorkingSet() {
656         return selectedWorkingSet;
657         }
658
659         private void workingSetAdded(IWorkingSet workingSet) {
660             IAdaptable[] elements = workingSet.getElements();
661             selectedWorkingSet.add(workingSet);
662             addProjects(elements);
663         }
664
665         private void workingSetRemoved(IWorkingSet workingSet) {
666             IAdaptable[] elements = workingSet.getElements();
667             selectedWorkingSet.remove(workingSet);
668             
669             Set tempSet = new HashSet();
670             for (int i = 0; i < elements.length; i++) {
671                 IProject[] projects = getProjectsForObject(elements[i]);
672                 if (projects != null)
673                     tempSet.addAll(Arrays.asList(projects));
674             }
675             
676             if (!tempSet.isEmpty()) {
677                 selectedProjects.removeAll(tempSet);
678                 for (Iterator iterator = tempSet.iterator(); iterator.hasNext();) {
679                     Object JavaDoc element = (Object JavaDoc) iterator.next();
680                     referenceCountProjects.remove(element);
681                 }
682                 selectedProjects.addAll(referenceCountProjects);
683             }
684         }
685         
686         private void addProjects(IAdaptable[] elements) {
687             Set tempSet = new HashSet();
688             for (int j = 0; j < elements.length; j++) {
689                 IProject[] projects = getProjectsForObject(elements[j]);
690                 if (projects != null)
691                     tempSet.addAll(Arrays.asList(projects));
692             }
693
694             selectedProjects.addAll(tempSet);
695             referenceCountProjects.addAll(tempSet);
696         }
697     }
698 }
699
Popular Tags