KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > tags > TagConfigurationDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui.tags;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import java.util.*;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.Path;
19 import org.eclipse.jface.dialogs.*;
20 import org.eclipse.jface.dialogs.Dialog;
21 import org.eclipse.jface.operation.IRunnableWithProgress;
22 import org.eclipse.jface.viewers.*;
23 import org.eclipse.jface.window.Window;
24 import org.eclipse.osgi.util.NLS;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.*;
27 import org.eclipse.swt.graphics.Point;
28 import org.eclipse.swt.graphics.Rectangle;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.*;
32 import org.eclipse.team.core.TeamException;
33 import org.eclipse.team.internal.ccvs.core.*;
34 import org.eclipse.team.internal.ccvs.ui.*;
35 import org.eclipse.team.internal.ccvs.ui.Policy;
36 import org.eclipse.team.internal.ccvs.ui.model.RemoteContentProvider;
37 import org.eclipse.team.internal.ccvs.ui.repo.NewDateTagAction;
38 import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
39 import org.eclipse.team.internal.ccvs.ui.tags.TagSourceWorkbenchAdapter.ProjectElementComparator;
40 import org.eclipse.ui.PlatformUI;
41 import org.eclipse.ui.model.WorkbenchContentProvider;
42 import org.eclipse.ui.model.WorkbenchLabelProvider;
43
44 /**
45  * Allows configuration of the CVS tags that are shown within the workbench.
46  */

47 public class TagConfigurationDialog extends TrayDialog {
48     
49     // show the resource contained within the roots
50
private TreeViewer cvsResourceTree;
51     
52     // shows the tags found on the selected resources
53
private CheckboxTableViewer cvsTagTree;
54     
55     // shows the defined tags for the given root
56
private TreeViewer cvsDefinedTagsTree;
57     
58     // remember the root element in the defined tags tree
59
private TagSourceWorkbenchAdapter cvsDefinedTagsRootElement;
60     
61     // list of auto-refresh files
62
private org.eclipse.swt.widgets.List autoRefreshFileList;
63     
64     // enable selecting auto-refresh files
65
private boolean allowSettingAutoRefreshFiles = true;
66     
67     // preference keys
68
private final String JavaDoc ALLOWREFRESH_WIDTH_KEY = "AllowRefreshWidth"; //$NON-NLS-1$
69
private final String JavaDoc ALLOWREFRESH_HEIGHT_KEY = "AllowRefreshHeight"; //$NON-NLS-1$
70
private final String JavaDoc NOREFRESH_WIDTH_KEY = "NoRefreshWidth"; //$NON-NLS-1$
71
private final String JavaDoc NOREFRESH_HEIGHT_KEY = "NoRefreshHeight"; //$NON-NLS-1$
72

73     // buttons
74
private Button addSelectedTagsButton;
75     private Button addSelectedFilesButton;
76     private Button removeFileButton;
77     private Button removeTagButton;
78     
79     // dialogs settings that are persistent between workbench sessions
80
private IDialogSettings settings;
81
82     private final TagSource tagSource;
83
84     private final TagSourceWrapper wrappedTagSource;
85     
86     class FileComparator extends ViewerComparator {
87         public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
88             boolean oneIsFile = e1 instanceof CVSFileElement;
89             boolean twoIsFile = e2 instanceof CVSFileElement;
90             if (oneIsFile != twoIsFile) {
91                 return oneIsFile ? 1 : -1;
92             }
93             return super.compare(viewer, e1, e2);
94         }
95     }
96     
97     /*
98      * Create a tag source that cahces the added and removed tags
99      * so that the changes can be propogated to the repository
100      * manager when OK is pressed
101      */

102     class TagSourceWrapper extends TagSource {
103
104         private final TagSource tagSource;
105         private final List JavaDoc branches = new ArrayList();
106         private final List JavaDoc versions = new ArrayList();
107         private final List JavaDoc dates = new ArrayList();
108
109         public TagSourceWrapper(TagSource tagSource) {
110             this.tagSource = tagSource;
111             branches.addAll(Arrays.asList(tagSource.getTags(CVSTag.BRANCH)));
112             versions.addAll(Arrays.asList(tagSource.getTags(CVSTag.VERSION)));
113             dates.addAll(Arrays.asList(tagSource.getTags(CVSTag.DATE)));
114         }
115         
116         /* (non-Javadoc)
117          * @see org.eclipse.team.internal.ccvs.ui.merge.TagSource#getTags(int)
118          */

119         public CVSTag[] getTags(int type) {
120             if (type == CVSTag.HEAD || type == BASE) {
121                 return super.getTags(type);
122             }
123             List JavaDoc list = getTagList(type);
124             if (list != null)
125                 return (CVSTag[]) list.toArray(new CVSTag[list.size()]);
126             return tagSource.getTags(type);
127         }
128
129         private List JavaDoc getTagList(int type) {
130             switch (type) {
131             case CVSTag.VERSION:
132                 return versions;
133             case CVSTag.BRANCH:
134                 return branches;
135             case CVSTag.DATE:
136                 return dates;
137         }
138             return null;
139         }
140         
141         /* (non-Javadoc)
142          * @see org.eclipse.team.internal.ccvs.ui.merge.TagSource#refresh(org.eclipse.core.runtime.IProgressMonitor)
143          */

144         public CVSTag[] refresh(boolean bestEffort, IProgressMonitor monitor) throws TeamException {
145             // The wrapper is never refreshed
146
return new CVSTag[0];
147         }
148
149         /* (non-Javadoc)
150          * @see org.eclipse.team.internal.ccvs.ui.merge.TagSource#getLocation()
151          */

152         public ICVSRepositoryLocation getLocation() {
153             return tagSource.getLocation();
154         }
155
156         /* (non-Javadoc)
157          * @see org.eclipse.team.internal.ccvs.ui.merge.TagSource#getShortDescription()
158          */

159         public String JavaDoc getShortDescription() {
160             return tagSource.getShortDescription();
161         }
162
163         public void remove(CVSTag[] tags) {
164             for (int i = 0; i < tags.length; i++) {
165                 CVSTag tag = tags[i];
166                 List JavaDoc list = getTagList(tag.getType());
167                 if (list != null)
168                     list.remove(tag);
169             }
170         }
171
172         public void add(CVSTag[] tags) {
173             for (int i = 0; i < tags.length; i++) {
174                 CVSTag tag = tags[i];
175                 List JavaDoc list = getTagList(tag.getType());
176                 if (list != null)
177                     list.add(tag);
178             }
179         }
180
181         public void removeAll() {
182             versions.clear();
183             branches.clear();
184             dates.clear();
185         }
186
187         /**
188          * Remember the state that has been accumulated
189          * @param monitor
190          * @throws CVSException
191          */

192         public void commit(IProgressMonitor monitor) throws CVSException {
193             tagSource.commit(getTags(new int[] { CVSTag.VERSION, CVSTag.BRANCH, CVSTag.DATE }), true /* replace */, monitor);
194         }
195
196         /* (non-Javadoc)
197          * @see org.eclipse.team.internal.ccvs.ui.merge.TagSource#commit(org.eclipse.team.internal.ccvs.core.CVSTag[], boolean, org.eclipse.core.runtime.IProgressMonitor)
198          */

199         public void commit(CVSTag[] tags, boolean replace, IProgressMonitor monitor) throws CVSException {
200             // Not invoked
201
}
202
203         /* (non-Javadoc)
204          * @see org.eclipse.team.internal.ccvs.ui.tags.TagSource#getCVSResources()
205          */

206         public ICVSResource[] getCVSResources() {
207             return tagSource.getCVSResources();
208         }
209     }
210     
211     public TagConfigurationDialog(Shell shell, TagSource tagSource) {
212         super(shell);
213         this.tagSource = tagSource;
214         wrappedTagSource = new TagSourceWrapper(tagSource);
215         setShellStyle(SWT.CLOSE|SWT.RESIZE|SWT.APPLICATION_MODAL);
216         allowSettingAutoRefreshFiles = getSingleFolder(tagSource, false) != null;
217         IDialogSettings workbenchSettings = CVSUIPlugin.getPlugin().getDialogSettings();
218         this.settings = workbenchSettings.getSection("TagConfigurationDialog");//$NON-NLS-1$
219
if (settings == null) {
220             this.settings = workbenchSettings.addNewSection("TagConfigurationDialog");//$NON-NLS-1$
221
}
222     }
223
224     /**
225      * @see Window#configureShell(Shell)
226      */

227     protected void configureShell(Shell newShell) {
228         super.configureShell(newShell);
229         newShell.setText(NLS.bind(CVSUIMessages.TagConfigurationDialog_1, new String JavaDoc[] { tagSource.getShortDescription() }));
230     }
231
232     /**
233      * @see Dialog#createDialogArea(Composite)
234      */

235     protected Control createDialogArea(Composite parent) {
236         Composite shell = new Composite(parent, SWT.NONE);
237         GridData data = new GridData (GridData.FILL_BOTH);
238         shell.setLayoutData(data);
239         GridLayout gridLayout = new GridLayout();
240         gridLayout.numColumns = 2;
241         gridLayout.makeColumnsEqualWidth = true;
242         gridLayout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
243         gridLayout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
244         shell.setLayout (gridLayout);
245         
246         Composite comp = new Composite(shell, SWT.NULL);
247         gridLayout = new GridLayout();
248         gridLayout.numColumns = 1;
249         gridLayout.marginWidth = 0;
250         gridLayout.marginHeight = 0;
251         comp.setLayout(gridLayout);
252         comp.setLayoutData(new GridData(GridData.FILL_BOTH));
253         
254         Label cvsResourceTreeLabel = new Label(comp, SWT.NONE);
255         cvsResourceTreeLabel.setText(CVSUIMessages.TagConfigurationDialog_5);
256         data = new GridData();
257         data.horizontalSpan = 1;
258         cvsResourceTreeLabel.setLayoutData(data);
259     
260         Tree tree = new Tree(comp, SWT.BORDER | SWT.MULTI);
261         cvsResourceTree = new TreeViewer (tree);
262         cvsResourceTree.setContentProvider(new RemoteContentProvider());
263         cvsResourceTree.setLabelProvider(new WorkbenchLabelProvider());
264         data = new GridData (GridData.FILL_BOTH);
265         data.heightHint = 150;
266         data.horizontalSpan = 1;
267         cvsResourceTree.getTree().setLayoutData(data);
268         cvsResourceTree.setComparator(new FileComparator());
269         cvsResourceTree.setInput(TagSourceResourceAdapter.getViewerInput(tagSource));
270         cvsResourceTree.addSelectionChangedListener(new ISelectionChangedListener() {
271             public void selectionChanged(SelectionChangedEvent event) {
272                 updateShownTags();
273                 updateEnablements();
274             }
275         });
276
277         comp = new Composite(shell, SWT.NULL);
278         gridLayout = new GridLayout();
279         gridLayout.numColumns = 1;
280         gridLayout.marginWidth = 0;
281         gridLayout.marginHeight = 0;
282         comp.setLayout(gridLayout);
283         comp.setLayoutData(new GridData(GridData.FILL_BOTH));
284     
285         Label cvsTagTreeLabel = new Label(comp, SWT.NONE);
286         cvsTagTreeLabel.setText(CVSUIMessages.TagConfigurationDialog_6);
287         data = new GridData();
288         data.horizontalSpan = 1;
289         cvsTagTreeLabel.setLayoutData(data);
290         
291         final Table table = new Table(comp, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);
292         data = new GridData(GridData.FILL_BOTH);
293         data.heightHint = 150;
294         data.horizontalSpan = 1;
295         table.setLayoutData(data);
296         cvsTagTree = new CheckboxTableViewer(table);
297         cvsTagTree.setContentProvider(new WorkbenchContentProvider());
298         cvsTagTree.setLabelProvider(new WorkbenchLabelProvider());
299         cvsTagTree.addSelectionChangedListener(new ISelectionChangedListener() {
300             public void selectionChanged(SelectionChangedEvent event) {
301                 updateEnablements();
302             }
303         });
304         
305         Composite selectComp = new Composite(comp, SWT.NONE);
306         GridLayout selectLayout = new GridLayout(2, true);
307         selectLayout.marginHeight = selectLayout.marginWidth = 0;
308         selectComp.setLayout(selectLayout);
309         selectComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
310         Button selectAllButton = new Button(selectComp, SWT.PUSH);
311         selectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
312         selectAllButton.setText(CVSUIMessages.ReleaseCommentDialog_selectAll);
313         selectAllButton.addSelectionListener(new SelectionAdapter() {
314             public void widgetSelected(SelectionEvent e) {
315                 int nItems = table.getItemCount();
316                 for (int j=0; j<nItems; j++)
317                     table.getItem(j).setChecked(true);
318             }
319         });
320         Button deselectAllButton = new Button(selectComp, SWT.PUSH);
321         deselectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
322         deselectAllButton.setText(CVSUIMessages.ReleaseCommentDialog_deselectAll);
323         deselectAllButton.addSelectionListener(new SelectionAdapter() {
324             public void widgetSelected(SelectionEvent e) {
325                 int nItems = table.getItemCount();
326                 for (int j=0; j<nItems; j++)
327                     table.getItem(j).setChecked(false);
328             }
329         });
330         
331         cvsTagTree.setComparator(new ViewerComparator() {
332             public int compare(Viewer viewer, Object JavaDoc e1, Object JavaDoc e2) {
333                 if (!(e1 instanceof TagElement) || !(e2 instanceof TagElement)) return super.compare(viewer, e1, e2);
334                 CVSTag tag1 = ((TagElement)e1).getTag();
335                 CVSTag tag2 = ((TagElement)e2).getTag();
336                 int type1 = tag1.getType();
337                 int type2 = tag2.getType();
338                 if (type1 != type2) {
339                     return type1 - type2;
340                 }
341                 // Sort in reverse order so larger numbered versions are at the top
342
return -tag1.compareTo(tag2);
343             }
344         });
345         
346         Composite rememberedTags = new Composite(shell, SWT.NONE);
347         data = new GridData (GridData.FILL_BOTH);
348         data.horizontalSpan = 2;
349         rememberedTags.setLayoutData(data);
350         gridLayout = new GridLayout();
351         gridLayout.numColumns = 2;
352         gridLayout.marginHeight = 0;
353         gridLayout.marginWidth = 0;
354         rememberedTags.setLayout (gridLayout);
355     
356         Label rememberedTagsLabel = new Label (rememberedTags, SWT.NONE);
357         rememberedTagsLabel.setText (CVSUIMessages.TagConfigurationDialog_7);
358         data = new GridData ();
359         data.horizontalSpan = 2;
360         rememberedTagsLabel.setLayoutData (data);
361         
362         tree = new Tree(rememberedTags, SWT.BORDER | SWT.MULTI);
363         cvsDefinedTagsTree = new TreeViewer (tree);
364         cvsDefinedTagsTree.setContentProvider(new WorkbenchContentProvider());
365         cvsDefinedTagsTree.setLabelProvider(new WorkbenchLabelProvider());
366         data = new GridData (GridData.FILL_BOTH);
367         data.heightHint = 100;
368         data.horizontalAlignment = GridData.FILL;
369         data.grabExcessHorizontalSpace = true;
370         cvsDefinedTagsTree.getTree().setLayoutData(data);
371         cvsDefinedTagsRootElement = new TagSourceWorkbenchAdapter(wrappedTagSource, TagSourceWorkbenchAdapter.INCLUDE_BRANCHES | TagSourceWorkbenchAdapter.INCLUDE_VERSIONS |TagSourceWorkbenchAdapter.INCLUDE_DATES);
372         cvsDefinedTagsTree.setInput(cvsDefinedTagsRootElement);
373         cvsDefinedTagsTree.addSelectionChangedListener(new ISelectionChangedListener() {
374             public void selectionChanged(SelectionChangedEvent event) {
375                 updateEnablements();
376             }
377         });
378         cvsDefinedTagsTree.setComparator(new ProjectElementComparator());
379     
380         Composite buttonComposite = new Composite(rememberedTags, SWT.NONE);
381         data = new GridData ();
382         data.verticalAlignment = GridData.BEGINNING;
383         buttonComposite.setLayoutData(data);
384         gridLayout = new GridLayout();
385         gridLayout.marginHeight = 0;
386         gridLayout.marginWidth = 0;
387         buttonComposite.setLayout (gridLayout);
388         
389         addSelectedTagsButton = new Button (buttonComposite, SWT.PUSH);
390         addSelectedTagsButton.setText (CVSUIMessages.TagConfigurationDialog_8);
391         data = getStandardButtonData(addSelectedTagsButton);
392         data.horizontalAlignment = GridData.FILL;
393         addSelectedTagsButton.setLayoutData(data);
394         addSelectedTagsButton.addListener(SWT.Selection, new Listener() {
395                 public void handleEvent(Event event) {
396                     rememberCheckedTags();
397                     updateShownTags();
398                     updateEnablements();
399                 }
400             });
401         Button addDatesButton = new Button(buttonComposite, SWT.PUSH);
402         addDatesButton.setText(CVSUIMessages.TagConfigurationDialog_0);
403         data = getStandardButtonData(addDatesButton);
404         data.horizontalAlignment = GridData.FILL;
405         addDatesButton.setLayoutData(data);
406         addDatesButton.addListener(SWT.Selection, new Listener(){
407             public void handleEvent(Event event){
408                 CVSTag dateTag = NewDateTagAction.getDateTag(getShell(), tagSource.getLocation());
409                 addDateTagsSelected(dateTag);
410                 updateShownTags();
411                 updateEnablements();
412             }
413         });
414         removeTagButton = new Button (buttonComposite, SWT.PUSH);
415         removeTagButton.setText (CVSUIMessages.TagConfigurationDialog_9);
416         data = getStandardButtonData(removeTagButton);
417         data.horizontalAlignment = GridData.FILL;
418         removeTagButton.setLayoutData(data);
419         removeTagButton.addListener(SWT.Selection, new Listener() {
420                 public void handleEvent(Event event) {
421                     deleteSelected();
422                     updateShownTags();
423                     updateEnablements();
424                 }
425             });
426             
427         Button removeAllTags = new Button (buttonComposite, SWT.PUSH);
428         removeAllTags.setText (CVSUIMessages.TagConfigurationDialog_10);
429         data = getStandardButtonData(removeAllTags);
430         data.horizontalAlignment = GridData.FILL;
431         removeAllTags.setLayoutData(data);
432         removeAllTags.addListener(SWT.Selection, new Listener() {
433                 public void handleEvent(Event event) {
434                     removeAllKnownTags();
435                     updateShownTags();
436                     updateEnablements();
437                 }
438             });
439         
440         if(allowSettingAutoRefreshFiles) {
441             Label explanation = new Label(rememberedTags, SWT.WRAP);
442             explanation.setText(CVSUIMessages.TagConfigurationDialog_11);
443             data = new GridData ();
444             data.horizontalSpan = 2;
445             //data.widthHint = 300;
446
explanation.setLayoutData(data);
447             
448             autoRefreshFileList = new org.eclipse.swt.widgets.List(rememberedTags, SWT.BORDER | SWT.MULTI);
449             data = new GridData ();
450             data.heightHint = 45;
451             data.horizontalAlignment = GridData.FILL;
452             data.grabExcessHorizontalSpace = true;
453             autoRefreshFileList.setLayoutData(data);
454             try {
455                 autoRefreshFileList.setItems(CVSUIPlugin.getPlugin().getRepositoryManager().getAutoRefreshFiles(getSingleFolder(tagSource, false)));
456             } catch (CVSException e) {
457                 autoRefreshFileList.setItems(new String JavaDoc[0]);
458                 CVSUIPlugin.log(e);
459             }
460             autoRefreshFileList.addSelectionListener(new SelectionListener() {
461                 public void widgetSelected(SelectionEvent e) {
462                     updateEnablements();
463                 }
464                 public void widgetDefaultSelected(SelectionEvent e) {
465                     updateEnablements();
466                 }
467             });
468     
469             Composite buttonComposite2 = new Composite(rememberedTags, SWT.NONE);
470             data = new GridData ();
471             data.verticalAlignment = GridData.BEGINNING;
472             buttonComposite2.setLayoutData(data);
473             gridLayout = new GridLayout();
474             gridLayout.marginHeight = 0;
475             gridLayout.marginWidth = 0;
476             buttonComposite2.setLayout (gridLayout);
477     
478             addSelectedFilesButton = new Button (buttonComposite2, SWT.PUSH);
479             addSelectedFilesButton.setText (CVSUIMessages.TagConfigurationDialog_12);
480             data = getStandardButtonData(addSelectedFilesButton);
481             data.horizontalAlignment = GridData.FILL;
482             addSelectedFilesButton.setLayoutData(data);
483             addSelectedFilesButton.addListener(SWT.Selection, new Listener() {
484                     public void handleEvent(Event event) {
485                         addSelectionToAutoRefreshList();
486                     }
487                 });
488                 
489             removeFileButton = new Button (buttonComposite2, SWT.PUSH);
490             removeFileButton.setText (CVSUIMessages.TagConfigurationDialog_13);
491             data = getStandardButtonData(removeFileButton);
492             data.horizontalAlignment = GridData.FILL;
493             removeFileButton.setLayoutData(data);
494             removeFileButton.addListener(SWT.Selection, new Listener() {
495                     public void handleEvent(Event event) {
496                         String JavaDoc[] selected = autoRefreshFileList.getSelection();
497                         for (int i = 0; i < selected.length; i++) {
498                             autoRefreshFileList.remove(selected[i]);
499                             autoRefreshFileList.setFocus();
500                         }
501                     }
502                 });
503             PlatformUI.getWorkbench().getHelpSystem().setHelp(autoRefreshFileList, IHelpContextIds.TAG_CONFIGURATION_REFRESHLIST);
504         }
505             
506         Label seperator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
507         data = new GridData (GridData.FILL_BOTH);
508         data.horizontalSpan = 2;
509         seperator.setLayoutData(data);
510     
511         PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IHelpContextIds.TAG_CONFIGURATION_OVERVIEW);
512     
513         updateEnablements();
514         Dialog.applyDialogFont(parent);
515         return shell;
516     }
517
518     private void updateShownTags() {
519         final CVSFileElement[] filesSelection = getSelectedFiles();
520         final Set tags = new HashSet();
521         if(filesSelection.length!=0) {
522             try {
523                 CVSUIPlugin.runWithProgress(getShell(), true /*cancelable*/, new IRunnableWithProgress() {
524                     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
525                         monitor.beginTask(CVSUIMessages.TagConfigurationDialog_22, filesSelection.length);
526                         try {
527                             for (int i = 0; i < filesSelection.length; i++) {
528                                 ICVSFile file = filesSelection[i].getCVSFile();
529                                 tags.addAll(Arrays.asList(getTagsFor(file, Policy.subMonitorFor(monitor, 1))));
530                             }
531                         } catch (TeamException e) {
532                             // ignore the exception
533
} finally {
534                             monitor.done();
535                         }
536                     }
537                 });
538             } catch (InterruptedException JavaDoc e) {
539                 // operation cancelled
540
} catch (InvocationTargetException JavaDoc e) {
541                 // can't happen since we're ignoring all possible exceptions
542
}
543             cvsTagTree.getTable().removeAll();
544             for (Iterator it = tags.iterator(); it.hasNext();) {
545                 CVSTag tag = (CVSTag) it.next();
546                 List JavaDoc knownTags = new ArrayList();
547                 knownTags.addAll(Arrays.asList(wrappedTagSource.getTags(new int[] { CVSTag.VERSION, CVSTag.BRANCH, CVSTag.DATE })));
548                 if(!knownTags.contains(tag)) {
549                     TagElement tagElem = new TagElement(tag);
550                     cvsTagTree.add(tagElem);
551                     cvsTagTree.setChecked(tagElem, true);
552                 }
553             }
554         }
555     }
556     
557     private CVSFileElement[] getSelectedFiles() {
558         IStructuredSelection selection = (IStructuredSelection)cvsResourceTree.getSelection();
559         if (!selection.isEmpty()) {
560             final List JavaDoc filesSelection = new ArrayList();
561             Iterator it = selection.iterator();
562             while(it.hasNext()) {
563                 Object JavaDoc o = it.next();
564                 if(o instanceof CVSFileElement) {
565                     filesSelection.add(o);
566                 }
567             }
568             return (CVSFileElement[]) filesSelection.toArray(new CVSFileElement[filesSelection.size()]);
569         }
570         return new CVSFileElement[0];
571     }
572     
573     private void addSelectionToAutoRefreshList() {
574         IStructuredSelection selection = (IStructuredSelection)cvsResourceTree.getSelection();
575         if (!selection.isEmpty()) {
576             final List JavaDoc filesSelection = new ArrayList();
577             Iterator it = selection.iterator();
578             while(it.hasNext()) {
579                 Object JavaDoc o = it.next();
580                 if(o instanceof CVSFileElement) {
581                     filesSelection.add(o);
582                 }
583             }
584             if(!filesSelection.isEmpty()) {
585                 for (it = filesSelection.iterator(); it.hasNext();) {
586                     try {
587                         ICVSFile file = ((CVSFileElement)it.next()).getCVSFile();
588                         ICVSFolder fileParent = file.getParent();
589                         String JavaDoc filePath = new Path(null, fileParent.getFolderSyncInfo().getRepository())
590                             .append(file.getRelativePath(fileParent)).toString();
591                         if(autoRefreshFileList.indexOf(filePath)==-1) {
592                             autoRefreshFileList.add(filePath);
593                         }
594                     } catch(CVSException e) {
595                         CVSUIPlugin.openError(getShell(), null, null, e);
596                     }
597                 }
598             }
599         }
600     }
601     
602     private CVSTag[] getTagsFor(ICVSFile file, IProgressMonitor monitor) throws TeamException {
603         return SingleFileTagSource.fetchTagsFor(file, monitor);
604     }
605     
606     private void rememberCheckedTags() {
607         Object JavaDoc[] checked = cvsTagTree.getCheckedElements();
608         List JavaDoc tagsToAdd = new ArrayList();
609         for (int i = 0; i < checked.length; i++) {
610             CVSTag tag = ((TagElement)checked[i]).getTag();
611             tagsToAdd.add(tag);
612         }
613         if (!tagsToAdd.isEmpty()) {
614             wrappedTagSource.add((CVSTag[]) tagsToAdd.toArray(new CVSTag[tagsToAdd.size()]));
615             cvsDefinedTagsTree.refresh();
616         }
617     }
618     
619     private void deleteSelected() {
620         IStructuredSelection selection = (IStructuredSelection)cvsDefinedTagsTree.getSelection();
621         List JavaDoc tagsToRemove = new ArrayList();
622         if (!selection.isEmpty()) {
623             Iterator it = selection.iterator();
624             while(it.hasNext()) {
625                 Object JavaDoc o = it.next();
626                 if(o instanceof TagElement) {
627                     CVSTag tag = ((TagElement)o).getTag();
628                     tagsToRemove.add(tag);
629                 }
630             }
631         }
632         if (!tagsToRemove.isEmpty()) {
633             wrappedTagSource.remove((CVSTag[]) tagsToRemove.toArray(new CVSTag[tagsToRemove.size()]));
634             cvsDefinedTagsTree.refresh();
635             cvsDefinedTagsTree.getTree().setFocus();
636         }
637     }
638     private void addDateTagsSelected(CVSTag tag){
639         if(tag == null) return;
640         List JavaDoc knownTags = new ArrayList();
641         knownTags.addAll(Arrays.asList(wrappedTagSource.getTags(CVSTag.DATE)));
642         if(!knownTags.contains( tag)){
643             wrappedTagSource.add(new CVSTag[] { tag });
644             cvsDefinedTagsTree.refresh();
645             cvsDefinedTagsTree.getTree().setFocus();
646         }
647     }
648     private boolean isTagSelectedInKnownTagTree() {
649         IStructuredSelection selection = (IStructuredSelection)cvsDefinedTagsTree.getSelection();
650         if (!selection.isEmpty()) {
651             Iterator it = selection.iterator();
652             while(it.hasNext()) {
653                 Object JavaDoc o = it.next();
654                 if(o instanceof TagElement) {
655                     return true;
656                 }
657             }
658         }
659         return false;
660     }
661
662     private void removeAllKnownTags() {
663         wrappedTagSource.removeAll();
664         cvsDefinedTagsTree.refresh();
665     }
666     
667     private void updateEnablements() {
668         // add checked tags
669
Object JavaDoc[] checked = cvsTagTree.getCheckedElements();
670         addSelectedTagsButton.setEnabled(checked.length!=0?true:false);
671         
672         // Remove known tags
673
removeTagButton.setEnabled(isTagSelectedInKnownTagTree()?true:false);
674         
675         if(allowSettingAutoRefreshFiles) {
676             // add selected files
677
addSelectedFilesButton.setEnabled(getSelectedFiles().length!=0?true:false);
678             
679             // remove auto refresh files
680
removeFileButton.setEnabled(autoRefreshFileList.getSelection().length!=0?true:false);
681         }
682     }
683     
684     /**
685      * @see Dialog#okPressed()
686      */

687     protected void okPressed() {
688         try {
689             // save auto refresh file names
690
if(allowSettingAutoRefreshFiles) {
691                 RepositoryManager manager = CVSUIPlugin.getPlugin().getRepositoryManager();
692                 manager.setAutoRefreshFiles(getSingleFolder(tagSource, false), autoRefreshFileList.getItems());
693             }
694             
695             wrappedTagSource.commit(null);
696             
697             super.okPressed();
698         } catch (CVSException e) {
699             CVSUIPlugin.openError(getShell(), null, null, e);
700         }
701     }
702      
703     protected ICVSFolder getSingleFolder(TagSource tagSource, boolean bestEffort) {
704         if (!bestEffort && tagSource instanceof MultiFolderTagSource)
705             return null;
706         if (tagSource instanceof SingleFolderTagSource)
707             return ((SingleFolderTagSource)tagSource).getFolder();
708         return null;
709     }
710
711     /**
712      * @see Window#getInitialSize()
713      */

714     protected Point getInitialSize() {
715         int width, height;
716         if(allowSettingAutoRefreshFiles) {
717             try {
718                 height = settings.getInt(ALLOWREFRESH_HEIGHT_KEY);
719                 width = settings.getInt(ALLOWREFRESH_WIDTH_KEY);
720             } catch(NumberFormatException JavaDoc e) {
721                 return super.getInitialSize();
722             }
723         } else {
724             try {
725                 height = settings.getInt(NOREFRESH_HEIGHT_KEY);
726                 width = settings.getInt(NOREFRESH_WIDTH_KEY);
727             } catch(NumberFormatException JavaDoc e) {
728                 return super.getInitialSize();
729             }
730         }
731         return new Point(width, height);
732     }
733     
734     /**
735      * @see Dialog#cancelPressed()
736      */

737     protected void cancelPressed() {
738         super.cancelPressed();
739     }
740     
741     private GridData getStandardButtonData(Button button) {
742         GridData data = new GridData();
743         data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
744         //don't crop labels with large font
745
//int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
746
//data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
747
return data;
748     }
749
750     /**
751      * @see Window#close()
752      */

753     public boolean close() {
754         // Close the tray so we only remember the size without the tray
755
if (getTray() != null)
756             closeTray();
757         Rectangle bounds = getShell().getBounds();
758         if(allowSettingAutoRefreshFiles) {
759             settings.put(ALLOWREFRESH_HEIGHT_KEY, bounds.height);
760             settings.put(ALLOWREFRESH_WIDTH_KEY, bounds.width);
761         } else {
762             settings.put(NOREFRESH_HEIGHT_KEY, bounds.height);
763             settings.put(NOREFRESH_WIDTH_KEY, bounds.width);
764         }
765         return super.close();
766     }
767 }
768
Popular Tags