1 11 package org.eclipse.team.internal.ccvs.ui.mappings; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.resources.mapping.ResourceTraversal; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.jface.operation.IRunnableWithProgress; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 import org.eclipse.swt.widgets.Shell; 24 import org.eclipse.team.core.diff.IDiff; 25 import org.eclipse.team.core.diff.IThreeWayDiff; 26 import org.eclipse.team.core.mapping.IResourceDiffTree; 27 import org.eclipse.team.core.mapping.provider.ResourceDiffTree; 28 import org.eclipse.team.internal.ccvs.core.CVSException; 29 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 30 import org.eclipse.team.internal.ccvs.ui.wizards.CommitWizard; 31 import org.eclipse.team.internal.ui.Utils; 32 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 33 import org.eclipse.ui.PlatformUI; 34 35 public abstract class AbstractCommitAction extends CVSModelProviderAction { 36 37 public AbstractCommitAction(ISynchronizePageConfiguration configuration) { 38 super(configuration); 39 } 40 41 44 public void execute() { 45 final List resources = new ArrayList (); 46 try { 47 final IStructuredSelection selection = getActualSelection(); 48 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { 49 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 50 try { 51 ResourceTraversal[] traversals = getCommitTraversals(selection, monitor); 52 resources.add(getOutgoingChanges(getSynchronizationContext().getDiffTree(), traversals, monitor)); 53 } catch (CoreException e) { 54 throw new InvocationTargetException (e); 55 } 56 } 57 }); 58 } catch (InvocationTargetException e) { 59 Utils.handleError(getConfiguration().getSite().getShell(), e, null, null); 60 } catch (InterruptedException e) { 61 } catch (CVSException e) { 63 Utils.handleError(getConfiguration().getSite().getShell(), e, null, null); 64 } 65 if (!resources.isEmpty() && ((IResource[])resources.get(0)).length > 0) { 66 Shell shell= getConfiguration().getSite().getShell(); 67 try { 68 CommitWizard.run(getConfiguration().getSite().getPart(), shell, ((IResource[])resources.get(0))); 69 } catch (CVSException e) { 70 CVSUIPlugin.log(e); 71 } 72 } 73 } 74 75 protected IStructuredSelection getActualSelection() throws CVSException { 76 return getStructuredSelection(); 77 } 78 79 protected abstract ResourceTraversal[] getCommitTraversals(IStructuredSelection selection, IProgressMonitor monitor) throws CoreException; 80 81 protected IResource[] getOutgoingChanges(final IResourceDiffTree tree, ResourceTraversal[] traversals, IProgressMonitor monitor) { 82 final List resources = new ArrayList (); 83 IDiff[] diffs = tree.getDiffs(traversals); 84 for (int i = 0; i < diffs.length; i++) { 85 IDiff diff = diffs[i]; 86 if (hasLocalChange(diff)) { 87 IResource resource = ResourceDiffTree.getResourceFor(diff); 88 if (resource != null) 89 resources.add(resource); 90 } 91 } 92 return (IResource[]) resources.toArray(new IResource[resources.size()]); 93 } 94 95 private boolean hasLocalChange(IDiff diff) { 96 if (diff instanceof IThreeWayDiff) { 97 IThreeWayDiff twd = (IThreeWayDiff) diff; 98 return twd.getDirection() == IThreeWayDiff.OUTGOING 99 || twd.getDirection() == IThreeWayDiff.CONFLICTING; 100 } 101 return false; 102 } 103 104 } 105 | Popular Tags |