Search in sources :

Example 1 with ChangeCommitPropertiesCommand

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

the class SVNHistoryPage method getSetCommitPropertiesAction.

private IAction getSetCommitPropertiesAction() {
    // set Action (context menu)
    if (setCommitPropertiesAction == null) {
        setCommitPropertiesAction = new // $NON-NLS-1$
        Action(// $NON-NLS-1$
        Policy.bind("HistoryView.setCommitProperties")) {

            public void run() {
                try {
                    final ISelection selection = getSelection();
                    if (!(selection instanceof IStructuredSelection))
                        return;
                    final ILogEntry ourSelection = getLogEntry((IStructuredSelection) selection);
                    // Failing that, try the resource originally selected by the user if
                    // from the Team menu
                    // TODO: Search all paths from currentSelection and find the
                    // shortest path and
                    // get the resources for that instance (in order to get the 'best'
                    // "bugtraq" properties)
                    final ProjectProperties projectProperties = (resource != null) ? ProjectProperties.getProjectProperties(resource) : (ourSelection.getRemoteResource() != null) ? ProjectProperties.getProjectProperties(ourSelection.getRemoteResource()) : ProjectProperties.getProjectProperties(// will return null!
                    remoteResource);
                    final ISVNResource svnResource = ourSelection.getRemoteResource() != null ? ourSelection.getRemoteResource() : ourSelection.getResource();
                    SetCommitPropertiesDialog dialog = new SetCommitPropertiesDialog(getSite().getShell(), ourSelection.getRevision(), resource, projectProperties);
                    // Set previous text - the text to edit
                    dialog.setOldAuthor(ourSelection.getAuthor());
                    dialog.setOldComment(ourSelection.getComment());
                    boolean doCommit = (dialog.open() == Window.OK);
                    if (doCommit) {
                        final String author;
                        final String commitComment;
                        if (ourSelection.getAuthor().equals(dialog.getAuthor()))
                            author = null;
                        else
                            author = dialog.getAuthor();
                        if (ourSelection.getComment().equals(dialog.getComment()))
                            commitComment = null;
                        else
                            commitComment = dialog.getComment();
                        final ChangeCommitPropertiesCommand command = new ChangeCommitPropertiesCommand(svnResource.getRepository(), ourSelection.getRevision(), commitComment, author);
                        PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {

                            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                                try {
                                    command.run(monitor);
                                } catch (SVNException e) {
                                    throw new InvocationTargetException(e);
                                } finally {
                                    if (ourSelection instanceof LogEntry) {
                                        LogEntry logEntry = (LogEntry) ourSelection;
                                        if (command.isLogMessageChanged())
                                            logEntry.setComment(commitComment);
                                        if (command.isAuthorChanged())
                                            logEntry.setAuthor(author);
                                    }
                                    getSite().getShell().getDisplay().asyncExec(new Runnable() {

                                        public void run() {
                                            tableHistoryViewer.refresh();
                                            tableHistoryViewer.setSelection(selection, true);
                                        }
                                    });
                                }
                            }
                        });
                    }
                } catch (InvocationTargetException e) {
                    SVNUIPlugin.openError(getSite().getShell(), null, null, e, SVNUIPlugin.LOG_NONTEAM_EXCEPTIONS);
                } catch (InterruptedException e) {
                // Do nothing
                } catch (SVNException e) {
                    // TODO Auto-generated catch block
                    SVNUIPlugin.openError(getSite().getShell(), null, null, e, SVNUIPlugin.LOG_TEAM_EXCEPTIONS);
                }
            }

            // we don't allow multiple selection
            public boolean isEnabled() {
                ISelection selection = getSelection();
                return selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1;
            }
        };
    }
    return setCommitPropertiesAction;
}
Also used : ILogEntry(org.tigris.subversion.subclipse.core.history.ILogEntry) ISVNResource(org.tigris.subversion.subclipse.core.ISVNResource) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ProjectProperties(org.tigris.subversion.subclipse.ui.settings.ProjectProperties) SVNException(org.tigris.subversion.subclipse.core.SVNException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ChangeCommitPropertiesCommand(org.tigris.subversion.subclipse.core.commands.ChangeCommitPropertiesCommand) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) SetCommitPropertiesDialog(org.tigris.subversion.subclipse.ui.dialogs.SetCommitPropertiesDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ISelection(org.eclipse.jface.viewers.ISelection) ILogEntry(org.tigris.subversion.subclipse.core.history.ILogEntry) LogEntry(org.tigris.subversion.subclipse.core.history.LogEntry)

Example 2 with ChangeCommitPropertiesCommand

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

the class SetCommitPropertiesAction method run.

public void run() {
    try {
        IResource resource = ((RevisionGraphEditorInput) editor.getEditorInput()).getResource();
        ISVNRemoteResource remoteResource = ((RevisionGraphEditorInput) editor.getEditorInput()).getRemoteResource();
        ISVNInfo info = ((RevisionGraphEditorInput) editor.getEditorInput()).getInfo();
        final ProjectProperties projectProperties = (resource != null) ? ProjectProperties.getProjectProperties(resource) : ProjectProperties.getProjectProperties(remoteResource);
        SVNRevision.Number revision = new SVNRevision.Number(node.getRevision());
        SetCommitPropertiesDialog dialog = new SetCommitPropertiesDialog(Display.getDefault().getActiveShell(), revision, resource, projectProperties);
        dialog.setOldAuthor(node.getAuthor());
        dialog.setOldComment(node.getMessage());
        if (dialog.open() == SetCommitPropertiesDialog.OK) {
            final String author;
            final String commitComment;
            if (node.getAuthor().equals(dialog.getAuthor()))
                author = null;
            else
                author = dialog.getAuthor();
            if (node.getMessage().equals(dialog.getComment()))
                commitComment = null;
            else
                commitComment = dialog.getComment();
            ISVNRepositoryLocation repository = SVNProviderPlugin.getPlugin().getRepository(info.getRepository().toString());
            final ChangeCommitPropertiesCommand command = new ChangeCommitPropertiesCommand(repository, revision, commitComment, author);
            PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor) throws InvocationTargetException {
                    try {
                        command.run(monitor);
                    } catch (SVNException e) {
                        throw new InvocationTargetException(e);
                    } finally {
                        if (command.isAuthorChanged())
                            node.setAuthor(author);
                        if (command.isLogMessageChanged())
                            node.setMessage(commitComment);
                        if (command.isAuthorChanged() || command.isLogMessageChanged()) {
                            nodeFigure.setToolTip(new NodeTooltipFigure(node));
                        }
                    }
                }
            });
        }
    } catch (Exception e) {
        SVNUIPlugin.openError(Display.getDefault().getActiveShell(), null, null, e, SVNUIPlugin.LOG_TEAM_EXCEPTIONS);
    }
}
Also used : NodeTooltipFigure(org.tigris.subversion.subclipse.graph.editors.NodeTooltipFigure) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) ProjectProperties(org.tigris.subversion.subclipse.ui.settings.ProjectProperties) SVNException(org.tigris.subversion.subclipse.core.SVNException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SVNException(org.tigris.subversion.subclipse.core.SVNException) ChangeCommitPropertiesCommand(org.tigris.subversion.subclipse.core.commands.ChangeCommitPropertiesCommand) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) SetCommitPropertiesDialog(org.tigris.subversion.subclipse.ui.dialogs.SetCommitPropertiesDialog) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RevisionGraphEditorInput(org.tigris.subversion.subclipse.graph.editors.RevisionGraphEditorInput) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) IResource(org.eclipse.core.resources.IResource)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 SVNException (org.tigris.subversion.subclipse.core.SVNException)2 ChangeCommitPropertiesCommand (org.tigris.subversion.subclipse.core.commands.ChangeCommitPropertiesCommand)2 SetCommitPropertiesDialog (org.tigris.subversion.subclipse.ui.dialogs.SetCommitPropertiesDialog)2 ProjectProperties (org.tigris.subversion.subclipse.ui.settings.ProjectProperties)2 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)1 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)1 ISVNResource (org.tigris.subversion.subclipse.core.ISVNResource)1 ILogEntry (org.tigris.subversion.subclipse.core.history.ILogEntry)1 LogEntry (org.tigris.subversion.subclipse.core.history.LogEntry)1 NodeTooltipFigure (org.tigris.subversion.subclipse.graph.editors.NodeTooltipFigure)1 RevisionGraphEditorInput (org.tigris.subversion.subclipse.graph.editors.RevisionGraphEditorInput)1 ISVNInfo (org.tigris.subversion.svnclientadapter.ISVNInfo)1 SVNRevision (org.tigris.subversion.svnclientadapter.SVNRevision)1