### Eclipse Workspace Patch 1.0 #P org.eclipse.team.cvs.ui Index: src/org/eclipse/team/internal/ccvs/ui/mappings/AbstractCommitAction.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/AbstractCommitAction.java,v retrieving revision 1.2 diff -u -r1.2 AbstractCommitAction.java --- src/org/eclipse/team/internal/ccvs/ui/mappings/AbstractCommitAction.java 3 Jan 2007 21:16:29 -0000 1.2 +++ src/org/eclipse/team/internal/ccvs/ui/mappings/AbstractCommitAction.java 15 Feb 2007 13:43:39 -0000 @@ -28,12 +28,72 @@ import org.eclipse.team.internal.ccvs.core.CVSException; import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; import org.eclipse.team.internal.ccvs.ui.wizards.CommitWizard; +import org.eclipse.team.internal.ccvs.ui.wizards.CommitWizard.AddAndCommitOperation; +import org.eclipse.team.internal.core.subscribers.ChangeSet; +import org.eclipse.team.internal.ui.Policy; import org.eclipse.team.internal.ui.Utils; import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; import org.eclipse.ui.PlatformUI; public abstract class AbstractCommitAction extends CVSModelProviderAction { + private class ChangeSetCommitOperation implements IRunnableWithProgress { + private final Object[] changeSets; + + private ChangeSetCommitOperation(Object[] changeSets) { + this.changeSets = changeSets; + } + + public void run(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + monitor.beginTask(null, changeSets.length * 100); + for (int i = 0; i < changeSets.length; i++) { + ChangeSet changeSet = (ChangeSet) changeSets[i]; + IResource[] setResources = changeSet.getResources(); + IResource[] toAddArray = null; + + try { + toAddArray = findToAddResources(setResources); + } catch (CVSException e) { + Utils.handleError(getConfiguration().getSite().getShell(), + e, null, null); + return; + } + + String comment = getComment(changeSet); + + + AddAndCommitOperation op = new AddAndCommitOperation( + getConfiguration().getSite().getPart(), setResources, + toAddArray, comment); + op.run(Policy.subMonitorFor(monitor, 100)); + } + } + + private IResource[] findToAddResources(IResource[] setResources) + throws CVSException { + List toAdd = new ArrayList(); + for (int j = 0; j < setResources.length; j++) { + if (!CommitWizard.isAdded(setResources[j])) { + toAdd.add(setResources[j]); + } + } + IResource[] toAddArray = new IResource[toAdd.size()]; + for (int j = 0; j < toAdd.size(); j++) { + toAddArray[j] = (IResource) toAdd.get(j); + } + return toAddArray; + } + + private String getComment(ChangeSet changeSet) { + String comment = changeSet.getComment(); + if (comment == null) { + comment = changeSet.getName(); + } + return comment; + } + } + public AbstractCommitAction(ISynchronizePageConfiguration configuration) { super(configuration); } @@ -42,33 +102,84 @@ * @see org.eclipse.jface.action.Action#run() */ public void execute() { - final List resources = new ArrayList(); final IStructuredSelection selection = getActualSelection(); + + /* check only ChangeSets are selected (see bug 111164)*/ + boolean onlyChangeSets = true; + final Object [] selectionAsArray = selection.toArray(); + for(int i = 0; i < selectionAsArray.length; i++){ + if( ! (selectionAsArray[i] instanceof ChangeSet) ){ + onlyChangeSets = false; + } + } + + if(onlyChangeSets){ + commitChangeSets(selectionAsArray); // skip commit wizard + } else { + commitResources(selection); //classic commit wizard path + } + } + + /** + * This function prepares data for Commit Wizard and displays it. + * @param selection selection with resources that should be commited + */ + private void commitResources(final IStructuredSelection selection) { + final List resources = new ArrayList(); try { - PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - try { - ResourceTraversal[] traversals = getCommitTraversals(selection, monitor); - resources.add(getOutgoingChanges(getSynchronizationContext().getDiffTree(), traversals, monitor)); - } catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - }); + PlatformUI.getWorkbench().getProgressService().busyCursorWhile( + new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) + throws InvocationTargetException, + InterruptedException { + try { + ResourceTraversal[] traversals = getCommitTraversals( + selection, monitor); + resources.add(getOutgoingChanges( + getSynchronizationContext() + .getDiffTree(), traversals, + monitor)); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } + } + }); } catch (InvocationTargetException e) { - Utils.handleError(getConfiguration().getSite().getShell(), e, null, null); + Utils.handleError(getConfiguration().getSite().getShell(), e, null, + null); } catch (InterruptedException e) { // Ignore } - if (!resources.isEmpty() && ((IResource[])resources.get(0)).length > 0) { - Shell shell= getConfiguration().getSite().getShell(); - try { - CommitWizard.run(getConfiguration().getSite().getPart(), shell, ((IResource[])resources.get(0))); - } catch (CVSException e) { - CVSUIPlugin.log(e); - } + if (!resources.isEmpty() && ((IResource[]) resources.get(0)).length > 0) { + Shell shell = getConfiguration().getSite().getShell(); + try { + CommitWizard.run(getConfiguration().getSite().getPart(), shell, + ((IResource[]) resources.get(0))); + } catch (CVSException e) { + CVSUIPlugin.log(e); + } + } + } + + /** + * If only changeSets are selected, we can skip commit wizard, and perform + * commits. Comment have been provided to changeSets before (while creating + * them). + * + * @param changeSets changeSets to commit + */ + private void commitChangeSets(final Object[] changeSets) { + try { + PlatformUI.getWorkbench().getProgressService().busyCursorWhile( + new ChangeSetCommitOperation(changeSets)); + } catch (InvocationTargetException e) { + Utils.handleError(getConfiguration().getSite().getShell(), e, null, + null); + } catch (InterruptedException e) { + // Ignore } } + protected IStructuredSelection getActualSelection() { return getStructuredSelection(); Index: src/org/eclipse/team/internal/ccvs/ui/wizards/CommitWizard.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/CommitWizard.java,v retrieving revision 1.33 diff -u -r1.33 CommitWizard.java --- src/org/eclipse/team/internal/ccvs/ui/wizards/CommitWizard.java 27 Nov 2006 15:39:59 -0000 1.33 +++ src/org/eclipse/team/internal/ccvs/ui/wizards/CommitWizard.java 15 Feb 2007 13:43:39 -0000 @@ -447,7 +447,7 @@ return files; } - private static boolean isAdded(IResource resource) throws CVSException { + public static boolean isAdded(IResource resource) throws CVSException { final ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource); if (cvsResource.isFolder()) { return ((ICVSFolder)cvsResource).isCVSFolder();