1 11 package org.eclipse.team.internal.ccvs.ui.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 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 34 public class ConfigureTagsFromRepoViewOnFolder extends CVSAction { 35 36 39 protected ICVSRemoteFolder[] getSelectedRemoteFolders() { 40 ArrayList resources = null; 41 IStructuredSelection selection = getSelection(); 42 if (!selection.isEmpty()) { 43 resources = new ArrayList (); 44 Iterator elements = selection.iterator(); 45 while (elements.hasNext()) { 46 Object 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 69 public void execute(IAction action) throws InvocationTargetException , InterruptedException { 70 run(new IRunnableWithProgress() { 71 public void run(IProgressMonitor monitor) throws InvocationTargetException { 72 final ICVSRemoteFolder[] roots = getSelectedRemoteFolders(); 73 final Shell shell = getShell(); 74 shell.getDisplay().syncExec(new Runnable () { 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 , PROGRESS_BUSYCURSOR); 86 } 87 88 91 public boolean isEnabled() { 92 ICVSRemoteFolder[] roots = getSelectedRemoteFolders(); 93 if (roots.length != 1) return false; 94 return true; 95 } 96 99 protected String getErrorTitle() { 100 return CVSUIMessages.ConfigureTagsFromRepoViewConfigure_Tag_Error_1; 101 } 102 103 } 104 | Popular Tags |