Search in sources :

Example 1 with CommitOperation

use of org.tigris.subversion.subclipse.ui.operations.CommitOperation in project subclipse by subclipse.

the class CommitAction method execute.

/*
   * get non added resources and prompts for resources to be added
   * prompts for comments
   * add non added files
   * commit selected files
   * @see SVNAction#execute(IAction)
   */
public void execute(IAction action) throws InvocationTargetException, InterruptedException {
    statusMap = new HashMap();
    final IResource[] resources = getSelectedResources();
    final List resourcesToBeAdded = new ArrayList();
    final List resourcesToBeDeleted = new ArrayList();
    if (action != null && !action.isEnabled()) {
        action.setEnabled(true);
    } else {
        run(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                try {
                    // search for modified or added, non-ignored resources in the selection.
                    IResource[] modified = getChangeSetResources(getModifiedResources(resources, monitor));
                    // if no changes since last commit, do not show commit dialog.
                    if (modified.length == 0) {
                        MessageDialog.openInformation(getShell(), Policy.bind("CommitDialog.title"), // $NON-NLS-1$ //$NON-NLS-2$
                        Policy.bind("CommitDialog.noChanges"));
                        commit = false;
                    } else {
                        ProjectProperties projectProperties = ProjectProperties.getProjectProperties(modified[0]);
                        commit = confirmCommit(modified, projectProperties);
                    }
                    // resources that were selected.
                    if (commit) {
                        for (int i = 0; i < resourcesToCommit.length; i++) {
                            IResource resource = resourcesToCommit[i];
                            ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
                            if (svnResource.exists() && !svnResource.isManaged())
                                resourcesToBeAdded.add(resource);
                            if (svnResource.getStatus().isMissing())
                                resourcesToBeDeleted.add(resource);
                        }
                    }
                } catch (TeamException e) {
                    throw new InvocationTargetException(e);
                }
            }
        }, true, /* cancelable */
        PROGRESS_BUSYCURSOR);
        if (!commit) {
            // user canceled
            return;
        }
        CommitOperation commitOperation = new CommitOperation(getTargetPart(), resources, (IResource[]) resourcesToBeAdded.toArray(new IResource[resourcesToBeAdded.size()]), (IResource[]) resourcesToBeDeleted.toArray(new IResource[resourcesToBeDeleted.size()]), resourcesToCommit, commitComment, keepLocks);
        commitOperation.setCanRunAsJob(canRunAsJob);
        commitOperation.run();
    }
}
Also used : TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) HashMap(java.util.HashMap) CommitOperation(org.tigris.subversion.subclipse.ui.operations.CommitOperation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ProjectProperties(org.tigris.subversion.subclipse.ui.settings.ProjectProperties) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 2 with CommitOperation

use of org.tigris.subversion.subclipse.ui.operations.CommitOperation in project subclipse by subclipse.

the class CommitSynchronizeOperation method run.

/* (non-Javadoc)
   * @see org.eclipse.team.examples.filesystem.ui.FileSystemSynchronizeOperation#run(org.eclipse.team.examples.filesystem.FileSystemProvider, org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
   */
protected void run(SVNTeamProvider provider, SyncInfoSet set, IProgressMonitor monitor) {
    if (set.hasConflicts() || set.hasIncomingChanges()) {
        switch(promptForConflicts(getShell(), set)) {
            case 0:
                // Yes, commit non-conflicts
                set.removeConflictingNodes();
                set.removeIncomingNodes();
                break;
            case 1:
                // No, stop here
                return;
            default:
                return;
        }
    }
    if (confirmCommit(set)) {
        final IResource[][] resourcesToBeAdded = new IResource[][] { null };
        final IResource[][] resourcesToBeDeleted = new IResource[][] { null };
        List toBeAddedList = new ArrayList();
        List toBeDeletedList = new ArrayList();
        for (int i = 0; i < resourcesToCommit.length; i++) {
            IResource resource = resourcesToCommit[i];
            ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
            try {
                if (!svnResource.isManaged())
                    toBeAddedList.add(resource);
                if (svnResource.getStatus().isMissing())
                    toBeDeletedList.add(resource);
            } catch (SVNException e) {
                SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
            }
        }
        resourcesToBeAdded[0] = new IResource[toBeAddedList.size()];
        toBeAddedList.toArray(resourcesToBeAdded[0]);
        resourcesToBeDeleted[0] = new IResource[toBeDeletedList.size()];
        toBeDeletedList.toArray(resourcesToBeDeleted[0]);
        try {
            CommitOperation commit = new CommitOperation(getPart(), resourcesToCommit, resourcesToBeAdded[0], resourcesToBeDeleted[0], resourcesToCommit, commitComment, keepLocks);
            commit.run();
        } catch (InvocationTargetException e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
        } catch (InterruptedException e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
        }
    }
}
Also used : CommitOperation(org.tigris.subversion.subclipse.ui.operations.CommitOperation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IResource (org.eclipse.core.resources.IResource)2 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)2 CommitOperation (org.tigris.subversion.subclipse.ui.operations.CommitOperation)2 HashMap (java.util.HashMap)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 TeamException (org.eclipse.team.core.TeamException)1 SVNException (org.tigris.subversion.subclipse.core.SVNException)1 ProjectProperties (org.tigris.subversion.subclipse.ui.settings.ProjectProperties)1