Search in sources :

Example 1 with LockResourcesCommand

use of org.tigris.subversion.subclipse.core.commands.LockResourcesCommand in project subclipse by subclipse.

the class SVNFileModificationValidator method validateEdit.

public IStatus validateEdit(IFile[] files, Object context) {
    String comment = "";
    boolean stealLock = false;
    // reduce the array to just read only files
    ReadOnlyFiles readOnlyFiles = processFileArray(files);
    if (readOnlyFiles.size() == 0)
        return Status.OK_STATUS;
    // of the read-only files, get array of ones which are versioned
    IFile[] managedFiles = readOnlyFiles.getManaged();
    if (managedFiles.length > 0) {
        // Prompt user to lock files
        if (context != null) {
            ISVNFileModificationValidatorPrompt svnFileModificationValidatorPrompt = SVNProviderPlugin.getPlugin().getSvnFileModificationValidatorPrompt();
            if (svnFileModificationValidatorPrompt != null) {
                if (!svnFileModificationValidatorPrompt.prompt(managedFiles, context))
                    return Status.CANCEL_STATUS;
                comment = svnFileModificationValidatorPrompt.getComment();
                stealLock = svnFileModificationValidatorPrompt.isStealLock();
            }
        }
        // Run the svn lock command
        RepositoryProvider provider = RepositoryProvider.getProvider(managedFiles[0].getProject());
        if ((provider != null) && (provider instanceof SVNTeamProvider)) {
            SVNTeamProvider svnTeamProvider = (SVNTeamProvider) provider;
            LockResourcesCommand command = new LockResourcesCommand(svnTeamProvider.getSVNWorkspaceRoot(), managedFiles, stealLock, comment, false);
            try {
                command.run(new NullProgressMonitor());
            } catch (SVNException e) {
                SVNProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
                return Status.CANCEL_STATUS;
            }
        }
    }
    // Process any unmanaged but read-only files.  For
    // those we need to prompt the user to flip the read only bit
    IFile[] unManagedFiles = readOnlyFiles.getUnManaged();
    if (unManagedFiles.length > 0) {
        synchronized (this) {
            if (uiValidator == null)
                uiValidator = loadUIValidator();
        }
        if (uiValidator != null) {
            return uiValidator.validateEdit(unManagedFiles, context);
        }
        // There was no plugged in validator so fail gracefully
        return getStatus(unManagedFiles);
    }
    return Status.OK_STATUS;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) IFile(org.eclipse.core.resources.IFile) LockResourcesCommand(org.tigris.subversion.subclipse.core.commands.LockResourcesCommand) SVNException(org.tigris.subversion.subclipse.core.SVNException) RepositoryProvider(org.eclipse.team.core.RepositoryProvider)

Example 2 with LockResourcesCommand

use of org.tigris.subversion.subclipse.core.commands.LockResourcesCommand in project subclipse by subclipse.

the class LockAction method execute.

protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    if (action != null && !action.isEnabled()) {
        action.setEnabled(true);
    } else {
        if (getSelectedResources() != null && getSelectedResources().length > 0) {
            final IResource[] resources = getSelectedResources();
            SvnWizardLockPage lockPage = new SvnWizardLockPage(resources);
            SvnWizard wizard = new SvnWizard(lockPage);
            SvnWizardDialog dialog = new SvnWizardDialog(getShell(), wizard);
            wizard.setParentDialog(dialog);
            if (dialog.open() == SvnWizardDialog.OK) {
                final String comment = lockPage.getComment();
                final boolean stealLock = lockPage.isStealLock();
                run(new WorkspaceModifyOperation() {

                    protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
                        try {
                            Hashtable table = getProviderMapping(getSelectedResources());
                            Set keySet = table.keySet();
                            Iterator iterator = keySet.iterator();
                            while (iterator.hasNext()) {
                                SVNTeamProvider provider = (SVNTeamProvider) iterator.next();
                                LockResourcesCommand command = new LockResourcesCommand(provider.getSVNWorkspaceRoot(), resources, stealLock, comment);
                                command.run(Policy.subMonitorFor(monitor, 1000));
                            }
                        } catch (TeamException e) {
                            throw new InvocationTargetException(e);
                        } finally {
                            monitor.done();
                        }
                    }
                }, true, /* cancelable */
                PROGRESS_DIALOG);
            }
        }
    }
}
Also used : Set(java.util.Set) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) Hashtable(java.util.Hashtable) SvnWizardDialog(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardDialog) SvnWizard(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizard) SvnWizardLockPage(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardLockPage) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) CoreException(org.eclipse.core.runtime.CoreException) LockResourcesCommand(org.tigris.subversion.subclipse.core.commands.LockResourcesCommand) Iterator(java.util.Iterator) IResource(org.eclipse.core.resources.IResource)

Aggregations

SVNTeamProvider (org.tigris.subversion.subclipse.core.SVNTeamProvider)2 LockResourcesCommand (org.tigris.subversion.subclipse.core.commands.LockResourcesCommand)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 RepositoryProvider (org.eclipse.team.core.RepositoryProvider)1 TeamException (org.eclipse.team.core.TeamException)1 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)1 SVNException (org.tigris.subversion.subclipse.core.SVNException)1 SvnWizard (org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizard)1 SvnWizardDialog (org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardDialog)1 SvnWizardLockPage (org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardLockPage)1