Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2004-08-31 15:30:50 -0400
committerMichael Valenta2004-08-31 15:30:50 -0400
commit185e8bac643527725db03bad3809fac998766d35 (patch)
treec18420cc4522a1b323002b94b59d44acab8a741c
parentabce922cf54ea19c4322d257baceef11d7f7547a (diff)
downloadeclipse.platform.team-185e8bac643527725db03bad3809fac998766d35.tar.gz
eclipse.platform.team-185e8bac643527725db03bad3809fac998766d35.tar.xz
eclipse.platform.team-185e8bac643527725db03bad3809fac998766d35.zip
Bug 63848 [Annotate] CVS annotate should be done in the background
-rw-r--r--bundles/org.eclipse.team.cvs.ui/plugin.properties1
-rw-r--r--bundles/org.eclipse.team.cvs.ui/plugin.xml8
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java98
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPerspective.java2
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java4
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ICVSUIConstants.java6
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkInProgressPreferencePage.java122
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/ShowAnnotationAction.java198
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties19
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java248
10 files changed, 494 insertions, 212 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/plugin.properties b/bundles/org.eclipse.team.cvs.ui/plugin.properties
index b19175e08..7ef106a56 100644
--- a/bundles/org.eclipse.team.cvs.ui/plugin.properties
+++ b/bundles/org.eclipse.team.cvs.ui/plugin.properties
@@ -32,6 +32,7 @@ DecoratorPreferencePage.name=Label Decorations
ExtMethodPreferencePage.name=Ext Connection Method
WatchEditPreferencePage.name=Watch/Edit
ComparePreferencePage.name=Compare
+WorkInProgressPreferencePage.name=Work in Progress
newWizardCategoryName=CVS
newProjectCheckoutWizard=Checkout Projects from CVS
diff --git a/bundles/org.eclipse.team.cvs.ui/plugin.xml b/bundles/org.eclipse.team.cvs.ui/plugin.xml
index a725570a5..fbcba9ac4 100644
--- a/bundles/org.eclipse.team.cvs.ui/plugin.xml
+++ b/bundles/org.eclipse.team.cvs.ui/plugin.xml
@@ -716,6 +716,14 @@
id="org.eclipse.team.cvs.ui.PasswordManagementPreferencePage">
</page>
</extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ class="org.eclipse.team.internal.ccvs.ui.WorkInProgressPreferencePage"
+ category="org.eclipse.team.cvs.ui.CVSPreferences"
+ name="%WorkInProgressPreferencePage.name"
+ id="org.eclipse.team.cvs.ui.WorkInProgressPreferencePage"/>
+ </extension>
<!-- **************** Decorator ******************* -->
<extension
point="org.eclipse.ui.decorators">
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
index 2da698299..60821465c 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/AnnotateView.java
@@ -12,20 +12,41 @@ package org.eclipse.team.internal.ccvs.ui;
import java.io.IOException;
import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Iterator;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jface.text.*;
-import org.eclipse.jface.viewers.*;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.IPostSelectionProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.team.internal.ccvs.core.*;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.team.internal.ccvs.core.CVSAnnotateBlock;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
+import org.eclipse.team.internal.ccvs.core.ICVSResource;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
-import org.eclipse.ui.*;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IReusableEditor;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.registry.EditorDescriptor;
@@ -94,9 +115,9 @@ public class AnnotateView extends ViewPart implements ISelectionChangedListener
* @param cvsResource
* @param cvsAnnotateBlocks
* @param contents
- * @throws InvocationTargetException
+ * @throws PartInitException, CVSException
*/
- public void showAnnotations(ICVSResource cvsResource, Collection cvsAnnotateBlocks, InputStream contents) throws InvocationTargetException {
+ public void showAnnotations(ICVSResource cvsResource, Collection cvsAnnotateBlocks, InputStream contents) throws PartInitException, CVSException {
showAnnotations(cvsResource, cvsAnnotateBlocks, contents, true);
}
@@ -106,9 +127,9 @@ public class AnnotateView extends ViewPart implements ISelectionChangedListener
* @param cvsAnnotateBlocks
* @param contents
* @param useHistoryView
- * @throws InvocationTargetException
+ * @throws PartInitException, CVSException
*/
- public void showAnnotations(ICVSResource cvsResource, Collection cvsAnnotateBlocks, InputStream contents, boolean useHistoryView) throws InvocationTargetException {
+ public void showAnnotations(ICVSResource cvsResource, Collection cvsAnnotateBlocks, InputStream contents, boolean useHistoryView) throws PartInitException, CVSException {
// Disconnect from old annotation editor
disconnect();
@@ -158,14 +179,8 @@ public class AnnotateView extends ViewPart implements ISelectionChangedListener
// Get hook to the HistoryView
- try {
- historyView = (HistoryView) page.showView(HistoryView.VIEW_ID);
- historyView.showHistory((ICVSRemoteFile) CVSWorkspaceRoot.getRemoteResourceFor(cvsResource), false /* don't refetch */);
- } catch (PartInitException e) {
- throw new InvocationTargetException(e);
- } catch (CVSException e) {
- throw new InvocationTargetException(e);
- }
+ historyView = (HistoryView) page.showView(HistoryView.VIEW_ID);
+ historyView.showHistory((ICVSRemoteFile) CVSWorkspaceRoot.getRemoteResourceFor(cvsResource), false /* don't refetch */);
}
protected void disconnect() {
@@ -248,8 +263,10 @@ public class AnnotateView extends ViewPart implements ISelectionChangedListener
try {
contents.reset();
showAnnotations(cvsResource, cvsAnnotateBlocks, contents, false);
- } catch (InvocationTargetException e) {
+ } catch (CVSException e) {
return;
+ } catch (PartInitException e) {
+ return;
} catch (IOException e) {
return;
}
@@ -300,19 +317,15 @@ public class AnnotateView extends ViewPart implements ISelectionChangedListener
/**
* Try and open the correct registered editor type for the file.
- * @throws InvocationTargetException
+ * @throws CVSException, PartInitException
*/
- private IEditorPart openEditor() throws InvocationTargetException {
+ private IEditorPart openEditor() throws CVSException, PartInitException {
// Open the editor
IEditorPart part;
ICVSRemoteFile file;
IEditorRegistry registry;
- try {
- file = (ICVSRemoteFile) CVSWorkspaceRoot.getRemoteResourceFor(cvsResource);
- } catch (CVSException e1) {
- throw new InvocationTargetException(e1);
- }
+ file = (ICVSRemoteFile) CVSWorkspaceRoot.getRemoteResourceFor(cvsResource);
registry = CVSUIPlugin.getPlugin().getWorkbench().getEditorRegistry();
IEditorDescriptor descriptor = registry.getDefaultEditor(file.getName());
@@ -339,27 +352,20 @@ public class AnnotateView extends ViewPart implements ISelectionChangedListener
}
// Either reuse an existing editor or open a new editor of the correct type.
- try {
- try {
- if (editor != null && editor instanceof IReusableEditor && page.isPartVisible(editor) && editor.getSite().getId().equals(id)) {
- // We can reuse the editor
- ((IReusableEditor) editor).setInput(new RemoteAnnotationEditorInput(file, contents));
- part = editor;
- } else {
- // We can not reuse the editor so close the existing one and open a new one.
- if (editor != null) {
- page.closeEditor(editor, false);
- editor = null;
- }
- part = page.openEditor(new RemoteAnnotationEditorInput(file, contents), id);
- }
- } catch (PartInitException e) {
- throw e;
- }
- } catch (PartInitException e) {
- // Total failure.
- throw new InvocationTargetException(e);
+
+ if (editor != null && editor instanceof IReusableEditor && page.isPartVisible(editor) && editor.getSite().getId().equals(id)) {
+ // We can reuse the editor
+ ((IReusableEditor) editor).setInput(new RemoteAnnotationEditorInput(file, contents));
+ part = editor;
+ } else {
+ // We can not reuse the editor so close the existing one and open a new one.
+ if (editor != null) {
+ page.closeEditor(editor, false);
+ editor = null;
+ }
+ part = page.openEditor(new RemoteAnnotationEditorInput(file, contents), id);
}
+
// Hook Editor post selection listener.
ITextEditor editor = (ITextEditor) part;
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPerspective.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPerspective.java
index f0afa4e25..99ace83e2 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPerspective.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPerspective.java
@@ -16,6 +16,8 @@ import org.eclipse.team.ui.synchronize.ISynchronizeView;
import org.eclipse.ui.*;
public class CVSPerspective implements IPerspectiveFactory {
+
+ public final static String ID = "org.eclipse.team.cvs.ui.cvsPerspective"; //$NON-NLS-1$
/* (Non-javadoc)
* Method declared on IPerpsectiveFactory
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
index aa9badd17..896f26988 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
@@ -20,6 +20,7 @@ import org.eclipse.core.resources.IResourceStatus;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
@@ -618,6 +619,9 @@ public class CVSUIPlugin extends AbstractUIPlugin {
store.setDefault(ICVSUIConstants.PREF_PROMPT_ON_SAVING_IN_SYNC, true);
store.setDefault(ICVSUIConstants.PREF_SAVE_DIRTY_EDITORS, ICVSUIConstants.OPTION_PROMPT);
+ store.setDefault(ICVSUIConstants.PREF_DEFAULT_PERSPECTIVE_FOR_SHOW_ANNOTATIONS, CVSPerspective.ID);
+ store.setDefault(ICVSUIConstants.PREF_CHANGE_PERSPECTIVE_ON_SHOW_ANNOTATIONS, MessageDialogWithToggle.PROMPT);
+
// Set the watch/edit preferences defaults and values
store.setDefault(ICVSUIConstants.PREF_CHECKOUT_READ_ONLY, corePrefs.getDefaultBoolean(CVSProviderPlugin.READ_ONLY));
store.setDefault(ICVSUIConstants.PREF_EDIT_ACTION, ICVSUIConstants.PREF_EDIT_PROMPT_EDIT);
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ICVSUIConstants.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ICVSUIConstants.java
index ca032515c..713e42119 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ICVSUIConstants.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ICVSUIConstants.java
@@ -126,6 +126,10 @@ public interface ICVSUIConstants {
// Repositories view preferences
public final String PREF_GROUP_VERSIONS_BY_PROJECT = "pref_group_versions_by_project"; //$NON-NLS-1$
+ // Work in Progress preferences
+ public final String PREF_CHANGE_PERSPECTIVE_ON_SHOW_ANNOTATIONS= "pref_change_perspective_on_show_annotations"; //$NON-NLS-1$
+ public final String PREF_DEFAULT_PERSPECTIVE_FOR_SHOW_ANNOTATIONS= "pref_default_perspective_for_show_annotations"; //$NON-NLS-1$
+
// Wizard banners
public final String IMG_WIZBAN_SHARE = "wizban/newconnect_wizban.gif"; //$NON-NLS-1$
public final String IMG_WIZBAN_MERGE = "wizban/mergestream_wizban.gif"; //$NON-NLS-1$
@@ -155,5 +159,7 @@ public interface ICVSUIConstants {
public final int OPTION_NEVER = 1;
public final int OPTION_PROMPT = 2;
public final int OPTION_AUTOMATIC = 3;
+
+ public final String OPTION_NO_PERSPECTIVE= "none"; //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkInProgressPreferencePage.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkInProgressPreferencePage.java
index 6e850912e..b97a9bf55 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkInProgressPreferencePage.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/WorkInProgressPreferencePage.java
@@ -10,12 +10,44 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui;
+import java.text.Collator;
+import java.util.Arrays;
+import java.util.Comparator;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.RadioGroupFieldEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.team.internal.ui.preferences.ComboFieldEditor;
+import org.eclipse.ui.IPerspectiveDescriptor;
+import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.PlatformUI;
public class WorkInProgressPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ private static class PerspectiveDescriptorComparator implements Comparator {
+ /*
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(Object o1, Object o2) {
+ if (o1 instanceof IPerspectiveDescriptor && o2 instanceof IPerspectiveDescriptor) {
+ String id1= ((IPerspectiveDescriptor)o1).getLabel();
+ String id2= ((IPerspectiveDescriptor)o2).getLabel();
+ return Collator.getInstance().compare(id1, id2);
+ }
+ return 0;
+ }
+ }
+
+ private RadioGroupFieldEditor synchronizePerspectiveSwitch;
public WorkInProgressPreferencePage() {
super(GRID);
@@ -25,25 +57,91 @@ public class WorkInProgressPreferencePage extends FieldEditorPreferencePage impl
}
/* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
- */
- public void createControl(Composite parent) {
- super.createControl(parent);
- //WorkbenchHelp.setHelp(getControl(), IDebugHelpContextIds.CONSOLE_PREFERENCE_PAGE);
- }
-
- /* (non-Javadoc)
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
*/
- public void createFieldEditors() {
+ public void createFieldEditors() {
+
+ synchronizePerspectiveSwitch= new RadioGroupFieldEditor(
+ ICVSUIConstants.PREF_CHANGE_PERSPECTIVE_ON_SHOW_ANNOTATIONS,
+ Policy.bind("WorkInProgressPreferencePage.7"), //$NON-NLS-1$
+ 3,
+ new String[][] {
+ {Policy.bind("WorkInProgressPreferencePage.8"), MessageDialogWithToggle.ALWAYS}, //$NON-NLS-1$
+ {Policy.bind("WorkInProgressPreferencePage.2"), MessageDialogWithToggle.NEVER}, //$NON-NLS-1$
+ {Policy.bind("WorkInProgressPreferencePage.3"), MessageDialogWithToggle.PROMPT} //$NON-NLS-1$
+ },
+ getFieldEditorParent(), true);
+ addField(synchronizePerspectiveSwitch);
+
+ final Group perspectiveGroup = createGroup(
+ getFieldEditorParent(),
+ Policy.bind("WorkInProgressPreferencePage.4")); //$NON-NLS-1$
+
+ handleDeletedPerspectives();
+ final String[][] perspectiveNamesAndIds = getPerspectiveNamesAndIds();
+
+ ComboFieldEditor comboEditor= new ComboFieldEditor(
+ ICVSUIConstants.PREF_DEFAULT_PERSPECTIVE_FOR_SHOW_ANNOTATIONS,
+ Policy.bind("WorkInProgressPreferencePage.5"), //$NON-NLS-1$
+ perspectiveNamesAndIds,
+ perspectiveGroup);
+ addField(comboEditor);
+
+ Dialog.applyDialogFont(getFieldEditorParent());
+ updateLayout(perspectiveGroup);
+ getFieldEditorParent().layout(true);
+
}
/* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
*/
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
- */
public void init(IWorkbench workbench) {
}
+
+ private Group createGroup(Composite parent, String title) {
+ Group display = new Group(parent, SWT.NONE);
+ updateLayout(display);
+ GridData data = new GridData();
+ data.horizontalSpan = 2;
+ data.horizontalAlignment = GridData.FILL;
+ display.setLayoutData(data);
+ display.setText(title);
+ return display;
+ }
+
+ private void updateLayout(Composite composite) {
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginWidth = 5;
+ layout.marginHeight =5;
+ layout.horizontalSpacing = 5;
+ layout.verticalSpacing = 5;
+ composite.setLayout(layout);
+ }
+
+ private static void handleDeletedPerspectives() {
+ final IPreferenceStore store= CVSUIPlugin.getPlugin().getPreferenceStore();
+ final String id= store.getString(ICVSUIConstants.PREF_DEFAULT_PERSPECTIVE_FOR_SHOW_ANNOTATIONS);
+ if (PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(id) == null) {
+ store.putValue(ICVSUIConstants.PREF_DEFAULT_PERSPECTIVE_FOR_SHOW_ANNOTATIONS, ICVSUIConstants.OPTION_NO_PERSPECTIVE);
+ }
+ }
+
+ private String[][] getPerspectiveNamesAndIds() {
+
+ final IPerspectiveRegistry registry= PlatformUI.getWorkbench().getPerspectiveRegistry();
+ final IPerspectiveDescriptor[] perspectiveDescriptors= registry.getPerspectives();
+
+ Arrays.sort(perspectiveDescriptors, new PerspectiveDescriptorComparator());
+
+ final String[][] table = new String[perspectiveDescriptors.length + 1][2];
+ table[0][0] = Policy.bind("WorkInProgressPreferencePage.6"); //$NON-NLS-1$
+ table[0][1] = ICVSUIConstants.OPTION_NO_PERSPECTIVE;
+ for (int i = 0; i < perspectiveDescriptors.length; i++) {
+ table[i + 1][0] = perspectiveDescriptors[i].getLabel();
+ table[i + 1][1] = perspectiveDescriptors[i].getId();
+ }
+ return table;
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/ShowAnnotationAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/ShowAnnotationAction.java
index e8597368a..9f72e4402 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/ShowAnnotationAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/ShowAnnotationAction.java
@@ -10,32 +10,19 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.actions;
-import java.io.*;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IStorage;
-import org.eclipse.core.runtime.*;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.variants.IResourceVariant;
-import org.eclipse.team.internal.ccvs.core.*;
-import org.eclipse.team.internal.ccvs.core.client.*;
-import org.eclipse.team.internal.ccvs.core.client.listeners.AnnotateListener;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
+import org.eclipse.team.internal.ccvs.core.ICVSResource;
import org.eclipse.team.internal.ccvs.core.client.listeners.LogEntry;
-import org.eclipse.team.internal.ccvs.core.connection.CVSServerException;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
-import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
-import org.eclipse.team.internal.ccvs.core.util.KnownRepositories;
-import org.eclipse.team.internal.ccvs.ui.*;
-import org.eclipse.team.internal.ccvs.ui.AnnotateView;
import org.eclipse.team.internal.ccvs.ui.Policy;
-import org.eclipse.team.internal.core.TeamPlugin;
-import org.eclipse.ui.*;
+import org.eclipse.team.internal.ccvs.ui.operations.ShowAnnotationOperation;
public class ShowAnnotationAction extends WorkspaceAction {
@@ -43,140 +30,28 @@ public class ShowAnnotationAction extends WorkspaceAction {
* Action to open a CVS Annotate View
*/
public void execute(IAction action) throws InvocationTargetException, InterruptedException {
- // Get the selected resource.
- final ICVSResource cvsResource = getSingleSelectedCVSResource();
- execute(cvsResource);
+ final ICVSResource resource= getSingleSelectedCVSResource();
+ if (resource == null)
+ return;
+ execute(resource);
}
-
- public void execute(final ICVSResource cvsResource) throws InvocationTargetException, InterruptedException {
-
- final AnnotateListener listener = new AnnotateListener();
- if (cvsResource == null) {
- return;
- }
- // Get the selected revision
- final String revision;
- try {
- ResourceSyncInfo info = cvsResource.getSyncInfo();
- if (info == null) {
- handle(new CVSException(Policy.bind("ShowAnnotationAction.noSyncInfo", cvsResource.getName()))); //$NON-NLS-1$
- return;
- }
- revision = cvsResource.getSyncInfo().getRevision();
- } catch (CVSException e) {
- throw new InvocationTargetException(e);
- }
-
- // Run the CVS Annotate action with a progress monitor
- run(new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- monitor.beginTask(null, 100);
- fetchAnnotation(listener, cvsResource, revision, Policy.subMonitorFor(monitor, 80));
- try {
- if (hasCharset(cvsResource, listener.getContents())) {
- listener.setContents(getRemoteContents(cvsResource, Policy.subMonitorFor(monitor, 20)));
- }
- } catch (CoreException e) {
- // Log and continue, using the original fetched contents
- CVSUIPlugin.log(e);
- }
- monitor.done();
- }
- }, true, PROGRESS_DIALOG);
-
- if (listener.hasError()) {
- throw new InvocationTargetException(new CVSException(Policy.bind("ShowAnnotationAction.1", listener.getError()))); //$NON-NLS-1$
- }
-
- // Open the view
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if (window != null) {
- try {
- PlatformUI.getWorkbench().showPerspective("org.eclipse.team.cvs.ui.cvsPerspective", window); //$NON-NLS-1$
- } catch (WorkbenchException e1) {
- // If this does not work we will just open the view in the
- // curren perspective.
- }
- }
-
- try {
- AnnotateView view = AnnotateView.openInActivePerspective();
- view.showAnnotations(cvsResource, listener.getCvsAnnotateBlocks(), listener.getContents());
- } catch (PartInitException e1) {
- handle(e1);
- }
- }
-
- protected boolean hasCharset(ICVSResource cvsResource, InputStream contents) {
- try {
- return TeamPlugin.getCharset(cvsResource.getName(), contents) != null;
- } catch (IOException e) {
- // Assume that the contents do have a charset
- return true;
- }
- }
-
+
/**
- * Send the CVS annotate command
+ * Fetch the revision number of a CVS resource and perform a ShowAnnotationOperation
+ * in the background.
+ *
+ * @param cvsResource The CVS resource (must not be null)
*
- * @param listener
- * @param cvsResource
- * @param revision
- * @param monitor
* @throws InvocationTargetException
+ * @throws InterruptedException
*/
- private void fetchAnnotation(final AnnotateListener listener, final ICVSResource cvsResource, final String revision, IProgressMonitor monitor) throws InvocationTargetException {
-
- try {
- monitor = Policy.monitorFor(monitor);
- monitor.beginTask(null, 100);
- ICVSFolder folder = cvsResource.getParent();
- final FolderSyncInfo info = folder.getFolderSyncInfo();
- ICVSRepositoryLocation location = KnownRepositories.getInstance().getRepository(info.getRoot());
- Session session = new Session(location, folder, true /*
- * output to
- * console
- */);
- session.open(Policy.subMonitorFor(monitor, 10), false /* read-only */);
- try {
- Command.QuietOption quietness = CVSProviderPlugin.getPlugin().getQuietness();
- try {
- CVSProviderPlugin.getPlugin().setQuietness(Command.VERBOSE);
- final Command.LocalOption[] localOption;
- if (revision == null) {
- localOption = Command.NO_LOCAL_OPTIONS;
- } else {
- localOption = new Command.LocalOption[1];
- localOption[0] = Annotate.makeRevisionOption(revision);
- }
- IStatus status = Command.ANNOTATE.execute(session, Command.NO_GLOBAL_OPTIONS, localOption, new ICVSResource[]{cvsResource}, listener, Policy.subMonitorFor(monitor, 90));
- if (status.getCode() == CVSStatus.SERVER_ERROR) {
- throw new CVSServerException(status);
- }
- } finally {
- CVSProviderPlugin.getPlugin().setQuietness(quietness);
- monitor.done();
- }
- } finally {
- session.close();
- }
- } catch (CVSException e) {
- throw new InvocationTargetException(e);
- }
+ public void execute(final ICVSResource cvsResource) throws InvocationTargetException, InterruptedException {
+ final String revision= getRevision(cvsResource);
+ if (revision == null)
+ return;
+ new ShowAnnotationOperation(getTargetPart(), cvsResource, revision).run();
}
- private InputStream getRemoteContents(ICVSResource resource, IProgressMonitor monitor) throws CoreException {
- ICVSRemoteResource remote = CVSWorkspaceRoot.getRemoteResourceFor(resource);
- if (remote == null) {
- return new ByteArrayInputStream(new byte[0]);
- }
- IStorage storage = ((IResourceVariant)remote).getStorage(monitor);
- if (storage == null) {
- return new ByteArrayInputStream(new byte[0]);
- }
- return storage.getContents();
- }
-
/**
* Ony enabled for single resource selection
*/
@@ -184,7 +59,7 @@ public class ShowAnnotationAction extends WorkspaceAction {
ICVSResource resource = getSingleSelectedCVSResource();
return (resource != null && ! resource.isFolder() && resource.isManaged());
}
-
+
/**
* This action is called from one of a Resource Navigator a CVS Resource
* Navigator or a History Log Viewer. Return the selected resource as an
@@ -192,26 +67,47 @@ public class ShowAnnotationAction extends WorkspaceAction {
*
* @return ICVSResource
*/
- protected ICVSResource getSingleSelectedCVSResource() {
+ private ICVSResource getSingleSelectedCVSResource() {
// Selected from a CVS Resource Navigator
- ICVSResource[] cvsResources = getSelectedCVSResources();
+ final ICVSResource[] cvsResources = getSelectedCVSResources();
if (cvsResources.length == 1) {
return cvsResources[0];
}
// Selected from a History Viewer
- Object[] logEntries = getSelectedResources(LogEntry.class);
+ final Object[] logEntries = getSelectedResources(LogEntry.class);
if (logEntries.length == 1) {
- LogEntry aLogEntry = (LogEntry) logEntries[0];
- ICVSRemoteFile cvsRemoteFile = aLogEntry.getRemoteFile();
+ final LogEntry aLogEntry = (LogEntry) logEntries[0];
+ final ICVSRemoteFile cvsRemoteFile = aLogEntry.getRemoteFile();
return cvsRemoteFile;
}
// Selected from a Resource Navigator
- IResource[] resources = getSelectedResources();
+ final IResource[] resources = getSelectedResources();
if (resources.length == 1) {
return CVSWorkspaceRoot.getCVSResourceFor(resources[0]);
}
return null;
}
+
+
+ /**
+ * Get the revision for the CVS resource. Throws an InvocationTargetException
+ * if the revision could not be determined.
+ *
+ * @param cvsResource The CVS resource
+ * @return The revision of the resource.
+ * @throws InvocationTargetException
+ */
+ private String getRevision(ICVSResource cvsResource) throws InvocationTargetException {
+ final ResourceSyncInfo info;
+ try {
+ info= cvsResource.getSyncInfo();
+ if (info == null)
+ throw new CVSException(Policy.bind("ShowAnnotationAction.noSyncInfo", cvsResource.getName())); //$NON-NLS-1$
+ } catch (CVSException e) {
+ throw new InvocationTargetException(e);
+ }
+ return info.getRevision();
+ }
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
index dd75c35db..4f7566d4b 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
@@ -82,7 +82,13 @@ CVSAction.mixingTags=You are mixing tags within a project. Beware that synchroni
CVSAnnotateView.showFileAnnotation=CVS Annotate - {0}
CVSAnnotateView.viewInstructions=This view shows annotations for a file in CVS. Select a file and then choose \"Team->Show Annotation\" from the context menu.
+
ShowAnnotationAction.noSyncInfo=Cannot display annotation for {0} because it doesn't have a remote revision.
+ShowAnnotationOperation.taskName=Fetching annotations from repository
+ShowAnnotationOperation.0=Error opening perspective
+ShowAnnotationOperation.1=Confirm Perspective Switch
+ShowAnnotationOperation.2=The CVS Annotate View is associated with the {0} perspective. Do you want to switch to that perspective now?
+ShowAnnotationOperation.4=&Remember my decision
CVSCatchupReleaseViewer.commit=&Commit...
CVSCatchupReleaseViewer.update=&Update from Repository
@@ -1064,9 +1070,16 @@ CommitAction.jobName=CVS Commit
OverrideAndUpdateAction.jobName=Performing CVS Override and Update on {0} resources
WorkInProgressPreferencePage.0=CVS Work In Progress
WorkInProgressPreferencePage.1=Preferences for enabling features that are not complete:
-WorkInProgressPreferencePage.2=Enable background fetching of resources in the CVS Repositories view
-WorkInProgressPreferencePage.3=Enable operations to be run in the background (e.g. checkout, update, commit)
-WorkInProgressPreferencePage.4=Enable the CVS sync actions to open the new sync view
+WorkInProgressPreferencePage.7=Switch to the associated perspective after a show annotations operation is complete:
+WorkInProgressPreferencePage.8=Al&ways
+WorkInProgressPreferencePage.2=N&ever
+WorkInProgressPreferencePage.3=&Prompt
+WorkInProgressPreferencePage.4=Associated perspective for the show annotations operation:
+WorkInProgressPreferencePage.5=Pe&rspective:
+WorkInProgressPreferencePage.6=None
+
+
+
CheckoutProjectOperation.8=Checking out ''{0}'' into project ''{1}''
CheckoutProjectOperation.9=Checking out ''{0}'' into {1} projects
CheckoutProjectOperation.0=Checkout of remote folder {0} cancelled by user
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java
new file mode 100644
index 000000000..dd85c51f1
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/ShowAnnotationOperation.java
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.team.internal.ccvs.ui.operations;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.team.core.variants.IResourceVariant;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.internal.ccvs.core.CVSStatus;
+import org.eclipse.team.internal.ccvs.core.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource;
+import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
+import org.eclipse.team.internal.ccvs.core.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.client.Annotate;
+import org.eclipse.team.internal.ccvs.core.client.Command;
+import org.eclipse.team.internal.ccvs.core.client.Session;
+import org.eclipse.team.internal.ccvs.core.client.listeners.AnnotateListener;
+import org.eclipse.team.internal.ccvs.core.connection.CVSServerException;
+import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
+import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
+import org.eclipse.team.internal.ccvs.core.util.KnownRepositories;
+import org.eclipse.team.internal.ccvs.ui.AnnotateView;
+import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
+import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
+import org.eclipse.team.internal.ccvs.ui.Policy;
+import org.eclipse.team.internal.core.TeamPlugin;
+import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.ui.IPerspectiveDescriptor;
+import org.eclipse.ui.IPerspectiveRegistry;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.WorkbenchException;
+
+/**
+ * An operation to fetch the annotations for a file from the repository and
+ * display them in the annotations view.
+ */
+public class ShowAnnotationOperation extends CVSOperation {
+
+ final private ICVSResource fCVSResource;
+ final private String fRevision;
+
+ public ShowAnnotationOperation(IWorkbenchPart part, ICVSResource cvsResource, String revision) {
+ super(part);
+ fCVSResource= cvsResource;
+ fRevision= revision;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void execute(IProgressMonitor monitor) throws CVSException, InterruptedException {
+
+ monitor.beginTask(null, 100);
+
+ // Get the annotations from the repository.
+ final AnnotateListener listener= new AnnotateListener();
+ fetchAnnotation(listener, fCVSResource, fRevision, Policy.subMonitorFor(monitor, 80));
+ try {
+ if (hasCharset(fCVSResource, listener.getContents())) {
+ listener.setContents(getRemoteContents(fCVSResource, Policy.subMonitorFor(monitor, 20)));
+ }
+ } catch (CoreException e) {
+ // Log and continue, using the original fetched contents
+ CVSUIPlugin.log(e);
+ }
+
+ // Open the view and display it from the UI thread.
+ final Display display= getPart().getSite().getShell().getDisplay();
+ display.asyncExec(new Runnable() {
+ public void run() { showView(listener); }
+ });
+ monitor.done();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#getTaskName()
+ */
+ protected String getTaskName() {
+ return Policy.bind("ShowAnnotationOperation.taskName"); //$NON-NLS-1$
+ }
+
+ protected boolean hasCharset(ICVSResource cvsResource, InputStream contents) {
+ try {
+ return TeamPlugin.getCharset(cvsResource.getName(), contents) != null;
+ } catch (IOException e) {
+ // Assume that the contents do have a charset
+ return true;
+ }
+ }
+
+ /**
+ * Shows the view once the background operation is finished. This must be called
+ * from the UI thread.
+ *
+ * @param listener The listener with the results.
+ */
+ protected void showView(final AnnotateListener listener) {
+ final IWorkbench workbench= PlatformUI.getWorkbench();
+ final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+
+ final String defaultPerspectiveID= promptForPerspectiveSwitch();
+
+ if (defaultPerspectiveID != null) {
+ try {
+ workbench.showPerspective(defaultPerspectiveID, window);
+ } catch (WorkbenchException e) {
+ Utils.handleError(window.getShell(), e, Policy.bind("ShowAnnotationOperation.0"), e.getMessage()); //$NON-NLS-1$
+ }
+ }
+
+ try {
+ final AnnotateView view = AnnotateView.openInActivePerspective();
+ view.showAnnotations(fCVSResource, listener.getCvsAnnotateBlocks(), listener.getContents());
+ } catch (PartInitException e) {
+ CVSUIPlugin.log(e);
+ } catch (CVSException e) {
+ CVSUIPlugin.log(e);
+ }
+ }
+
+
+ private void fetchAnnotation(AnnotateListener listener, ICVSResource cvsResource, String revision, IProgressMonitor monitor) throws CVSException {
+
+ monitor = Policy.monitorFor(monitor);
+ monitor.beginTask(null, 100);
+
+ final ICVSFolder folder = cvsResource.getParent();
+ final FolderSyncInfo info = folder.getFolderSyncInfo();
+ final ICVSRepositoryLocation location = KnownRepositories.getInstance().getRepository(info.getRoot());
+
+ final Session session = new Session(location, folder, true /*output to console*/);
+ session.open(Policy.subMonitorFor(monitor, 10), false /* read-only */);
+ try {
+ final Command.QuietOption quietness = CVSProviderPlugin.getPlugin().getQuietness();
+ try {
+ CVSProviderPlugin.getPlugin().setQuietness(Command.VERBOSE);
+ final Command.LocalOption[] localOption;
+ if (revision == null) {
+ localOption = Command.NO_LOCAL_OPTIONS;
+ } else {
+ localOption = new Command.LocalOption[1];
+ localOption[0] = Annotate.makeRevisionOption(revision);
+ }
+ final IStatus status = Command.ANNOTATE.execute(session, Command.NO_GLOBAL_OPTIONS, localOption, new ICVSResource[]{cvsResource}, listener, Policy.subMonitorFor(monitor, 90));
+ if (status.getCode() == CVSStatus.SERVER_ERROR) {
+ throw new CVSServerException(status);
+ }
+ } finally {
+ CVSProviderPlugin.getPlugin().setQuietness(quietness);
+ monitor.done();
+ }
+ } finally {
+ session.close();
+ }
+ }
+
+ private InputStream getRemoteContents(ICVSResource resource, IProgressMonitor monitor) throws CoreException {
+
+ final ICVSRemoteResource remote = CVSWorkspaceRoot.getRemoteResourceFor(resource);
+ if (remote == null) {
+ return new ByteArrayInputStream(new byte[0]);
+ }
+ final IStorage storage = ((IResourceVariant)remote).getStorage(monitor);
+ if (storage == null) {
+ return new ByteArrayInputStream(new byte[0]);
+ }
+ return storage.getContents();
+ }
+
+ /**
+ * @return The ID of the perspective if the perspective needs to be changed,
+ * null otherwise.
+ */
+ private String promptForPerspectiveSwitch() {
+ // check whether we should ask the user.
+ final IPreferenceStore store = CVSUIPlugin.getPlugin().getPreferenceStore();
+ final String option = store.getString(ICVSUIConstants.PREF_CHANGE_PERSPECTIVE_ON_SHOW_ANNOTATIONS);
+ final String desiredID = store.getString(ICVSUIConstants.PREF_DEFAULT_PERSPECTIVE_FOR_SHOW_ANNOTATIONS);
+
+ if (option.equals(MessageDialogWithToggle.ALWAYS))
+ return desiredID; // no, always switch
+
+ if (option.equals(MessageDialogWithToggle.NEVER))
+ return null; // no, never switch
+
+ // Check whether the desired perspective is already active.
+ final IPerspectiveRegistry registry= PlatformUI.getWorkbench().getPerspectiveRegistry();
+ final IPerspectiveDescriptor desired = registry.findPerspectiveWithId(desiredID);
+ final IWorkbenchPage page = CVSUIPlugin.getActivePage();
+
+ if (page != null) {
+ final IPerspectiveDescriptor current = page.getPerspective();
+ if (current != null && current.getId().equals(desiredID)) {
+ return null; // it is active, so no prompt and no switch
+ }
+ }
+
+ if (desired != null) {
+
+ // Ask the user whether to switch
+ final MessageDialogWithToggle m = MessageDialogWithToggle.openYesNoQuestion(
+ Utils.getShell(null),
+ Policy.bind("ShowAnnotationOperation.1"), //$NON-NLS-1$
+ Policy.bind("ShowAnnotationOperation.2", desired.getLabel()), //$NON-NLS-1$
+ Policy.bind("ShowAnnotationOperation.4"), //$NON-NLS-1$
+ false /* toggle state */,
+ store,
+ ICVSUIConstants.PREF_CHANGE_PERSPECTIVE_ON_SHOW_ANNOTATIONS);
+
+ final int result = m.getReturnCode();
+ switch (result) {
+ // yes
+ case IDialogConstants.YES_ID:
+ case IDialogConstants.OK_ID :
+ return desiredID;
+ // no
+ case IDialogConstants.NO_ID :
+ return null;
+ }
+ }
+ return null;
+ }
+}

Back to the top