KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > actions > ConfigureTagsFromRepoViewOnFolder


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.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.Iterator JavaDoc;
16
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.Path;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.operation.IRunnableWithProgress;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
24 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
25 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
26 import org.eclipse.team.internal.ccvs.ui.model.RemoteModule;
27 import org.eclipse.team.internal.ccvs.ui.tags.TagConfigurationDialog;
28 import org.eclipse.team.internal.ccvs.ui.tags.TagSource;
29 ;
30
31 /**
32  * DefineTagAction remembers a tag by name
33  */

34 public class ConfigureTagsFromRepoViewOnFolder extends CVSAction {
35     
36     /**
37      * Returns the selected remote folders
38      */

39     protected ICVSRemoteFolder[] getSelectedRemoteFolders() {
40         ArrayList JavaDoc resources = null;
41         IStructuredSelection selection = getSelection();
42         if (!selection.isEmpty()) {
43             resources = new ArrayList JavaDoc();
44             Iterator JavaDoc elements = selection.iterator();
45             while (elements.hasNext()) {
46                 Object JavaDoc next = elements.next();
47                 if (next instanceof RemoteModule) {
48                     next = ((RemoteModule)next).getCVSResource();
49                 }
50                 if (next instanceof ICVSRemoteFolder) {
51                     ICVSRemoteFolder folder = (ICVSRemoteFolder)next;
52                     if (folder.isDefinedModule()) {
53                         resources.add(next);
54                     } else if(new Path(null, ((ICVSRemoteFolder)next).getRepositoryRelativePath()).segmentCount()==1) {
55                         resources.add(next);
56                     }
57                 }
58             }
59         }
60         if (resources != null && !resources.isEmpty()) {
61             return (ICVSRemoteFolder[])resources.toArray(new ICVSRemoteFolder[resources.size()]);
62         }
63         return new ICVSRemoteFolder[0];
64     }
65
66     /*
67      * @see CVSAction@execute(IAction)
68      */

69     public void execute(IAction action) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
70         run(new IRunnableWithProgress() {
71             public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
72                 final ICVSRemoteFolder[] roots = getSelectedRemoteFolders();
73                 final Shell shell = getShell();
74                 shell.getDisplay().syncExec(new Runnable JavaDoc() {
75                     public void run() {
76                         ICVSFolder[] cvsFolders = new ICVSFolder[roots.length];
77                         for (int i = 0; i < roots.length; i++) {
78                             cvsFolders[i] = roots[i];
79                         }
80                         TagConfigurationDialog d = new TagConfigurationDialog(shell, TagSource.create(cvsFolders));
81                         d.open();
82                     }
83                 });
84             }
85         }, false /* cancelable */, PROGRESS_BUSYCURSOR);
86     }
87
88     /*
89      * @see TeamAction#isEnabled()
90      */

91     public boolean isEnabled() {
92         ICVSRemoteFolder[] roots = getSelectedRemoteFolders();
93         if (roots.length != 1) return false;
94         return true;
95     }
96     /**
97      * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
98      */

99     protected String JavaDoc getErrorTitle() {
100         return CVSUIMessages.ConfigureTagsFromRepoViewConfigure_Tag_Error_1;
101     }
102
103 }
104
Popular Tags