1 11 package org.eclipse.team.internal.ccvs.ui.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.resources.mapping.*; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.jface.action.IAction; 19 import org.eclipse.jface.dialogs.IDialogConstants; 20 import org.eclipse.jface.dialogs.MessageDialogWithToggle; 21 import org.eclipse.jface.operation.IRunnableWithProgress; 22 import org.eclipse.jface.preference.IPreferenceStore; 23 import org.eclipse.swt.widgets.Shell; 24 import org.eclipse.team.core.mapping.provider.SynchronizationScopeManager; 25 import org.eclipse.team.internal.ccvs.core.mapping.CVSActiveChangeSetCollector; 26 import org.eclipse.team.internal.ccvs.ui.*; 27 import org.eclipse.team.internal.ccvs.ui.wizards.CommitWizard; 28 import org.eclipse.team.internal.ui.Utils; 29 import org.eclipse.ui.PlatformUI; 30 31 35 public class CommitAction extends WorkspaceTraversalAction { 36 37 private final class CommitScopeManager extends SynchronizationScopeManager { 38 private boolean includeChangeSets; 39 40 private CommitScopeManager(ResourceMapping[] mappings, ResourceMappingContext context, boolean models) { 41 super("", mappings, context, models); includeChangeSets = isIncludeChangeSets(getShell(), CVSUIMessages.CommitAction_2); 43 } 44 45 protected ResourceTraversal[] adjustInputTraversals(ResourceTraversal[] traversals) { 46 if (includeChangeSets) 47 return ((CVSActiveChangeSetCollector)CVSUIPlugin.getPlugin().getChangeSetManager()).adjustInputTraversals(traversals); 48 return super.adjustInputTraversals(traversals); 49 } 50 } 51 52 55 public void execute(IAction action) throws InvocationTargetException , InterruptedException { 56 final ResourceTraversal[][] traversals = new ResourceTraversal[][] { null }; 57 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { 58 public void run(IProgressMonitor monitor) 59 throws InvocationTargetException , InterruptedException { 60 try { 61 monitor.beginTask(CVSUIMessages.CommitAction_0, 100); 62 traversals[0] = getTraversals(Policy.subMonitorFor(monitor, 80)); 63 } catch (CoreException e) { 64 throw new InvocationTargetException (e); 65 } finally { 66 monitor.done(); 67 } 68 } 69 }); 70 run(new IRunnableWithProgress() { 71 public void run(IProgressMonitor monitor) 72 throws InvocationTargetException , InterruptedException { 73 try { 74 CommitWizard.run(getTargetPart(), getShell(), traversals[0]); 75 } catch (CoreException e) { 76 throw new InvocationTargetException (e); 77 } 78 } 79 }, false, PROGRESS_BUSYCURSOR); 80 } 81 82 85 protected String getErrorTitle() { 86 return CVSUIMessages.CommitAction_commitFailed; 87 } 88 89 92 protected boolean isEnabledForUnmanagedResources() { 93 return true; 94 } 95 96 99 protected boolean isEnabledForNonExistantResources() { 100 return true; 101 } 102 103 106 public String getId() { 107 return ICVSUIConstants.CMD_COMMIT; 108 } 109 110 protected SynchronizationScopeManager getScopeManager() { 111 return new CommitScopeManager(getCVSResourceMappings(), getResourceMappingContext(), true); 112 } 113 114 public static boolean isIncludeChangeSets(final Shell shell, final String message) { 115 if (CVSUIPlugin.getPlugin().getChangeSetManager().getSets().length == 0) 116 return false; 117 final IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore(); 118 final String option = store.getString(ICVSUIConstants.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT); 119 if (option.equals(MessageDialogWithToggle.ALWAYS)) 120 return true; 122 if (option.equals(MessageDialogWithToggle.NEVER)) 123 return false; 125 final int[] result = new int[] { 0 }; 127 Utils.syncExec(new Runnable () { 128 public void run() { 129 final MessageDialogWithToggle m = MessageDialogWithToggle.openYesNoQuestion( 130 shell, 131 CVSUIMessages.CommitAction_1, 132 message, 133 CVSUIMessages.ShowAnnotationOperation_4, 134 false , 135 store, 136 ICVSUIConstants.PREF_INCLUDE_CHANGE_SETS_IN_COMMIT); 137 138 result[0] = m.getReturnCode(); 139 } 140 }, shell); 141 142 switch (result[0]) { 143 case IDialogConstants.YES_ID: 145 case IDialogConstants.OK_ID : 146 return true; 147 case IDialogConstants.NO_ID : 149 return false; 150 } 151 return false; 152 } 153 } 154 | Popular Tags |