1 11 package org.eclipse.team.internal.ccvs.ui.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.NullProgressMonitor; 17 import org.eclipse.jface.action.IAction; 18 import org.eclipse.jface.dialogs.IDialogConstants; 19 import org.eclipse.jface.dialogs.MessageDialogWithToggle; 20 import org.eclipse.jface.operation.IRunnableWithProgress; 21 import org.eclipse.jface.preference.IPreferenceStore; 22 import org.eclipse.jface.window.Window; 23 import org.eclipse.osgi.util.NLS; 24 import org.eclipse.team.internal.ccvs.core.CVSException; 25 import org.eclipse.team.internal.ccvs.core.CVSTag; 26 import org.eclipse.team.internal.ccvs.core.ICVSFolder; 27 import org.eclipse.team.internal.ccvs.core.ICVSResource; 28 import org.eclipse.team.internal.ccvs.ui.*; 29 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 30 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants; 31 import org.eclipse.team.internal.ccvs.ui.operations.ITagOperation; 32 import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager; 33 import org.eclipse.team.internal.ccvs.ui.tags.TagAsVersionDialog; 34 35 38 public abstract class TagAction extends WorkspaceTraversalAction { 39 40 private boolean wasCancelled = false; 42 43 46 public void execute(IAction action) throws InvocationTargetException , InterruptedException { 47 setWasCancelled(false); 48 49 final ITagOperation[] result = new ITagOperation[1]; 51 getShell().getDisplay().syncExec(new Runnable () { 52 public void run() { 53 result[0] = configureOperation(); 54 if (result[0] == null) { 55 return; 56 } 57 }}); 58 59 if (result[0] == null) { 60 setWasCancelled(true); 61 return; 62 } 63 64 result[0].run(); 65 } 66 67 protected boolean performPrompting(ITagOperation operation) { 68 return true; 69 } 70 71 76 protected ITagOperation configureOperation() { 77 IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore(); 78 ITagOperation operation = createTagOperation(); 79 if (operation.isEmpty()) { 80 return null; 81 } 82 if (!performPrompting(operation)) { 83 return null; 84 } 85 TagAsVersionDialog dialog = new TagAsVersionDialog(getShell(), 86 CVSUIMessages.TagAction_tagResources, 87 operation); 88 if (dialog.open() != Window.OK) return null; 89 90 if (dialog.shouldMoveTag() && store.getBoolean(ICVSUIConstants.PREF_CONFIRM_MOVE_TAG)) { 92 MessageDialogWithToggle confirmDialog = MessageDialogWithToggle.openYesNoQuestion(getShell(), 93 CVSUIMessages.TagAction_moveTagConfirmTitle, 94 NLS.bind(CVSUIMessages.TagAction_moveTagConfirmMessage, new String [] { dialog.getTagName() }), 95 null, 96 false, 97 null, 98 null); 99 100 if (confirmDialog.getReturnCode() == IDialogConstants.YES_ID) { 101 store.setValue(ICVSUIConstants.PREF_CONFIRM_MOVE_TAG, !confirmDialog.getToggleState()); 102 } else { 103 return null; 104 } 105 } 106 107 return dialog.getOperation(); 109 } 110 111 protected abstract ITagOperation createTagOperation(); 112 113 protected String getErrorTitle() { 114 return CVSUIMessages.TagAction_tagErrorTitle; 115 } 116 117 protected String getWarningTitle() { 118 return CVSUIMessages.TagAction_tagWarningTitle; 119 } 120 121 124 protected boolean isEnabledForAddedResources() { 125 return false; 126 } 127 128 public boolean wasCancelled() { 129 return wasCancelled; 130 } 131 132 public void setWasCancelled(boolean b) { 133 wasCancelled = b; 134 } 135 136 public static void broadcastTagChange(final ICVSResource[] resources, final CVSTag tag) throws InvocationTargetException , InterruptedException { 137 final RepositoryManager manager = CVSUIPlugin.getPlugin().getRepositoryManager(); 138 manager.run(new IRunnableWithProgress() { 139 public void run(IProgressMonitor monitor) { 140 try { 141 for (int i = 0; i < resources.length; i++) { 142 ICVSResource resource = resources[i]; 143 manager.addTags(getRootParent(resource), new CVSTag[] {tag}); 145 } 146 } catch (CVSException e) { 147 CVSUIPlugin.log(e); 148 } 149 } 150 private ICVSResource getRootParent(ICVSResource resource) throws CVSException { 151 if (!resource.isManaged()) return resource; 152 ICVSFolder parent = resource.getParent(); 153 if (parent == null) return resource; 154 if (parent.getName().length() == 0) return resource; 156 return getRootParent(parent); 157 } 158 }, new NullProgressMonitor()); 159 } 160 } 161 162 | Popular Tags |