1 11 package org.eclipse.team.internal.ccvs.ui.repo; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.action.IAction; 17 import org.eclipse.jface.dialogs.IInputValidator; 18 import org.eclipse.jface.dialogs.InputDialog; 19 import org.eclipse.jface.operation.IRunnableWithProgress; 20 import org.eclipse.jface.window.Window; 21 import org.eclipse.swt.widgets.Shell; 22 import org.eclipse.team.internal.ccvs.core.*; 23 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 24 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 25 import org.eclipse.team.internal.ccvs.ui.actions.CVSAction; 26 27 30 public class AddToBranchAction extends CVSAction { 31 32 IInputValidator validator = new IInputValidator() { 33 public String isValid(String newText) { 34 IStatus status = CVSTag.validateTagName(newText); 35 if (status.isOK()) return null; 36 return status.getMessage(); 37 } 38 }; 39 40 43 protected void execute(IAction action) throws InvocationTargetException , InterruptedException { 44 run(new IRunnableWithProgress() { 45 public void run(IProgressMonitor monitor) throws InvocationTargetException { 46 final ICVSRemoteFolder folder = getSelectedRootFolder(); 47 if (folder == null) return; 48 Shell shell = getShell(); 49 final CVSException[] exception = new CVSException[] { null }; 50 shell.getDisplay().syncExec(new Runnable () { 51 public void run() { 52 InputDialog dialog = new InputDialog(getShell(), CVSUIMessages.AddToBranchAction_enterTag, CVSUIMessages.AddToBranchAction_enterTagLong, null, validator); if (dialog.open() == Window.OK) { 54 CVSTag tag = new CVSTag(dialog.getValue(), CVSTag.BRANCH); 55 try { 56 CVSUIPlugin.getPlugin().getRepositoryManager().addTags(folder, new CVSTag[] {tag}); 57 } catch (CVSException e) { 58 exception[0] = e; 59 } 60 } 61 } 62 }); 63 if (exception[0] != null) 64 throw new InvocationTargetException (exception[0]); 65 } 66 }, false, PROGRESS_BUSYCURSOR); 67 } 68 69 72 public boolean isEnabled() { 73 return getSelectedRootFolder() != null; 74 } 75 76 protected ICVSRemoteFolder getSelectedRootFolder() { 77 ICVSRemoteFolder[] folders = getSelectedRemoteFolders(); 78 ICVSRemoteFolder selectedFolder = null; 79 for (int i = 0; i < folders.length; i++) { 80 ICVSRemoteFolder folder = folders[i]; 81 if (folder.isDefinedModule() || new Path(null, folder.getRepositoryRelativePath()).segmentCount()==1) { 82 if (selectedFolder != null) return null; 84 selectedFolder = folder; 85 } 86 } 87 return selectedFolder; 88 } 89 } 90 | Popular Tags |