Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-04-17 19:15:12 +0000
committerMichael Valenta2007-04-17 19:15:12 +0000
commitd50e1110e05fbb27b91a92ce94b08aca46914641 (patch)
tree7fcd3664865487b7ffa277cc93f4a1b52e39cf14
parentef8d6160070ed63da6e3888518ac9538f18ccd8a (diff)
downloadeclipse.platform.team-d50e1110e05fbb27b91a92ce94b08aca46914641.tar.gz
eclipse.platform.team-d50e1110e05fbb27b91a92ce94b08aca46914641.tar.xz
eclipse.platform.team-d50e1110e05fbb27b91a92ce94b08aca46914641.zip
Bug 181260 [Viewers] Compare viewers should bind command for Show Line Numbers
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java17
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java25
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java79
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java20
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java17
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java25
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java79
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java20
8 files changed, 188 insertions, 94 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
index 92a65a16a..d9d52bcb1 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
@@ -11,7 +11,6 @@
package org.eclipse.compare.contentmergeviewer;
-import java.util.ArrayList;
import java.util.ResourceBundle;
import org.eclipse.compare.*;
@@ -29,8 +28,6 @@ import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
-import org.eclipse.ui.handlers.IHandlerService;
-import org.eclipse.ui.services.IServiceLocator;
/**
* An abstract compare and merge viewer with two side-by-side content areas
@@ -264,7 +261,7 @@ public abstract class ContentMergeViewer extends ContentViewer
MergeViewerAction fLeftSaveAction;
MergeViewerAction fRightSaveAction;
- private IHandlerService fHandlerService;
+ private CompareHandlerService fHandlerService;
// SWT widgets
/* package */ Composite fComposite;
@@ -283,8 +280,6 @@ public abstract class ContentMergeViewer extends ContentViewer
private Cursor fVSashCursor;
private Cursor fHVSashCursor;
- private java.util.List fActivations = new ArrayList();
-
private ILabelProviderListener labelChangeListener = new ILabelProviderListener() {
public void labelProviderChanged(LabelProviderChangedEvent event) {
Object[] elements = event.getElements();
@@ -773,8 +768,7 @@ public abstract class ContentMergeViewer extends ContentViewer
createControls(fComposite);
- IServiceLocator locator = getCompareConfiguration().getContainer().getServiceLocator();
- fHandlerService= locator != null ? (IHandlerService)locator.getService(IHandlerService.class) : null;
+ fHandlerService= CompareHandlerService.createFor(getCompareConfiguration().getContainer(), fComposite.getShell());
initializeToolbars(parent);
@@ -802,7 +796,7 @@ public abstract class ContentMergeViewer extends ContentViewer
};
Utilities.initAction(fCopyLeftToRightAction, getResourceBundle(), "action.CopyLeftToRight."); //$NON-NLS-1$
tbm.appendToGroup("merge", fCopyLeftToRightAction); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, fCopyLeftToRightAction, "org.eclipse.compare.copyAllLeftToRight", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(fCopyLeftToRightAction, "org.eclipse.compare.copyAllLeftToRight"); //$NON-NLS-1$
}
if (cc.isLeftEditable()) {
@@ -814,7 +808,7 @@ public abstract class ContentMergeViewer extends ContentViewer
};
Utilities.initAction(fCopyRightToLeftAction, getResourceBundle(), "action.CopyRightToLeft."); //$NON-NLS-1$
tbm.appendToGroup("merge", fCopyRightToLeftAction); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, fCopyRightToLeftAction, "org.eclipse.compare.copyAllRightToLeft", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(fCopyRightToLeftAction, "org.eclipse.compare.copyAllRightToLeft"); //$NON-NLS-1$
}
Action a= new ChangePropertyAction(fBundle, getCompareConfiguration(), "action.EnableAncestor.", ICompareUIConstants.PROP_ANCESTOR_VISIBLE); //$NON-NLS-1$
@@ -900,8 +894,7 @@ public abstract class ContentMergeViewer extends ContentViewer
*/
protected void handleDispose(DisposeEvent event) {
- Utilities.deregisterActions(fHandlerService, fActivations);
- fHandlerService= null;
+ fHandlerService.dispose();
Object input= getInput();
if (input instanceof ICompareInput) {
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 6f7551953..b59994a29 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -52,9 +52,7 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
import org.eclipse.ui.actions.ActionFactory;
-import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.progress.IProgressService;
-import org.eclipse.ui.services.IServiceLocator;
import org.eclipse.ui.texteditor.*;
import com.ibm.icu.text.MessageFormat;
@@ -240,8 +238,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
private ActionContributionItem fCopyDiffLeftToRightItem;
private ActionContributionItem fCopyDiffRightToLeftItem;
- private IHandlerService fHandlerService;
- private List fActivations = new ArrayList();
+ private CompareHandlerService fHandlerService;
private boolean fSynchronizedScrolling= true;
private boolean fShowMoreInfo= false;
@@ -1709,8 +1706,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
*/
protected void handleDispose(DisposeEvent event) {
- Utilities.deregisterActions(fHandlerService, fActivations);
- fHandlerService= null;
+ fHandlerService.dispose();
Object input= getInput();
removeFromDocumentManager(ANCESTOR_CONTRIBUTOR, input);
@@ -3776,8 +3772,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
*/
protected void createToolItems(ToolBarManager tbm) {
- IServiceLocator locator = getCompareConfiguration().getContainer().getServiceLocator();
- fHandlerService= locator != null ? (IHandlerService)locator.getService(IHandlerService.class) : null;
+ fHandlerService= CompareHandlerService.createFor(getCompareConfiguration().getContainer(), fLeft.getControl().getShell());
final String ignoreAncestorActionKey= "action.IgnoreAncestor."; //$NON-NLS-1$
Action ignoreAncestorAction= new Action() {
@@ -3834,7 +3829,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
Utilities.initAction(a, getResourceBundle(), "action.NextChange."); //$NON-NLS-1$
fNextChange= new ActionContributionItem(a);
tbm.appendToGroup("navigation", fNextChange); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, a, "org.eclipse.compare.selectNextChange", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(a, "org.eclipse.compare.selectNextChange"); //$NON-NLS-1$
a= new Action() {
public void run() {
@@ -3846,7 +3841,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
Utilities.initAction(a, getResourceBundle(), "action.PrevChange."); //$NON-NLS-1$
fPreviousChange= new ActionContributionItem(a);
tbm.appendToGroup("navigation", fPreviousChange); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, a, "org.eclipse.compare.selectPreviousChange", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(a, "org.eclipse.compare.selectPreviousChange"); //$NON-NLS-1$
CompareConfiguration cc= getCompareConfiguration();
@@ -3860,7 +3855,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
fCopyDiffLeftToRightItem= new ActionContributionItem(a);
fCopyDiffLeftToRightItem.setVisible(true);
tbm.appendToGroup("merge", fCopyDiffLeftToRightItem); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, a, "org.eclipse.compare.copyLeftToRight", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(a, "org.eclipse.compare.copyLeftToRight"); //$NON-NLS-1$
}
if (cc.isLeftEditable()) {
@@ -3873,18 +3868,18 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
fCopyDiffRightToLeftItem= new ActionContributionItem(a);
fCopyDiffRightToLeftItem.setVisible(true);
tbm.appendToGroup("merge", fCopyDiffRightToLeftItem); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, a, "org.eclipse.compare.copyRightToLeft", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(a, "org.eclipse.compare.copyRightToLeft"); //$NON-NLS-1$
}
showWhitespaceAction = new ShowWhitespaceAction(new MergeSourceViewer[] {
fLeft, fRight, fAncestor
});
- Utilities.registerAction(fHandlerService, showWhitespaceAction, ITextEditorActionDefinitionIds.SHOW_WHITESPACE_CHARACTERS, fActivations);
+ fHandlerService.registerAction(showWhitespaceAction, ITextEditorActionDefinitionIds.SHOW_WHITESPACE_CHARACTERS);
toggleLineNumbersAction = new TextEditorPropertyAction(CompareMessages.TextMergeViewer_16, new MergeSourceViewer[] {
fLeft, fRight, fAncestor
}, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER);
- Utilities.registerAction(fHandlerService, toggleLineNumbersAction, ITextEditorActionDefinitionIds.LINENUMBER_TOGGLE, fActivations);
+ fHandlerService.registerAction(toggleLineNumbersAction, ITextEditorActionDefinitionIds.LINENUMBER_TOGGLE);
IAction findAction = new Action() {
public void run() {
@@ -3895,7 +3890,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
}
};
- Utilities.registerAction(fHandlerService, findAction, IWorkbenchActionDefinitionIds.FIND_REPLACE, fActivations);
+ fHandlerService.registerAction(findAction, IWorkbenchActionDefinitionIds.FIND_REPLACE);
}
/* (non-Javadoc)
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java
new file mode 100644
index 000000000..e219d18d2
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.compare.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.compare.ICompareContainer;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.ActiveShellExpression;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.IHandlerActivation;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.services.IServiceLocator;
+
+public class CompareHandlerService {
+
+ private final List fActivations = new ArrayList();
+ private IHandlerService fHandlerService;
+ private final Expression fExpression;
+
+ public static CompareHandlerService createFor(ICompareContainer container, Shell shell) {
+ IServiceLocator serviceLocator = container.getServiceLocator();
+ if (serviceLocator != null) {
+ IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
+ if (service != null)
+ return new CompareHandlerService(service, null);
+ }
+ if (container.getWorkbenchPart() == null && shell != null) {
+ // We're in a dialog so we can use an active shell expression
+ IHandlerService service = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
+ if (service != null) {
+ Expression e = new ActiveShellExpression(shell);
+ return new CompareHandlerService(service, e);
+ }
+ }
+ return new CompareHandlerService(null, null);
+ }
+
+ private CompareHandlerService(IHandlerService handlerService,
+ Expression expression) {
+ fHandlerService = handlerService;
+ fExpression = expression;
+ }
+
+ public void registerAction(IAction action, String commandId) {
+ if (fHandlerService == null)
+ return;
+ action.setActionDefinitionId(commandId);
+ IHandlerActivation activation;
+ if (fExpression == null) {
+ activation = fHandlerService.activateHandler(commandId, new ActionHandler(action));
+ } else {
+ activation = fHandlerService.activateHandler(commandId, new ActionHandler(action), fExpression);
+ }
+ if (activation != null) {
+ fActivations .add(activation);
+ }
+ }
+
+ public void dispose() {
+ if (fHandlerService == null)
+ return;
+ fHandlerService.deactivateHandlers(fActivations);
+ fActivations.clear();
+ fHandlerService = null;
+ }
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
index 8ae8e30f2..26d0e7e4a 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
@@ -24,7 +24,6 @@ import org.eclipse.core.resources.mapping.*;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.IDocument;
@@ -34,8 +33,6 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
-import org.eclipse.ui.handlers.IHandlerActivation;
-import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
import org.eclipse.ui.texteditor.IDocumentProvider;
@@ -48,23 +45,6 @@ public class Utilities {
private static final IPath ICONS_PATH= new Path("$nl$/icons/full/"); //$NON-NLS-1$
- public static void registerAction(IHandlerService hs, IAction a, String id, List activations) {
- if (hs != null) {
- a.setActionDefinitionId(id);
- IHandlerActivation activation = hs.activateHandler(id, new ActionHandler(a));
- if (activation != null) {
- activations .add(activation);
- }
- }
- }
-
- public static void deregisterActions(IHandlerService handlerService, List activations) {
- if (handlerService != null) {
- handlerService.deactivateHandlers(activations);
- activations.clear();
- }
- }
-
public static IWorkbenchPartSite findSite(Control c) {
while (c != null && !c.isDisposed()) {
Object data= c.getData();
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
index 92a65a16a..d9d52bcb1 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/ContentMergeViewer.java
@@ -11,7 +11,6 @@
package org.eclipse.compare.contentmergeviewer;
-import java.util.ArrayList;
import java.util.ResourceBundle;
import org.eclipse.compare.*;
@@ -29,8 +28,6 @@ import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
-import org.eclipse.ui.handlers.IHandlerService;
-import org.eclipse.ui.services.IServiceLocator;
/**
* An abstract compare and merge viewer with two side-by-side content areas
@@ -264,7 +261,7 @@ public abstract class ContentMergeViewer extends ContentViewer
MergeViewerAction fLeftSaveAction;
MergeViewerAction fRightSaveAction;
- private IHandlerService fHandlerService;
+ private CompareHandlerService fHandlerService;
// SWT widgets
/* package */ Composite fComposite;
@@ -283,8 +280,6 @@ public abstract class ContentMergeViewer extends ContentViewer
private Cursor fVSashCursor;
private Cursor fHVSashCursor;
- private java.util.List fActivations = new ArrayList();
-
private ILabelProviderListener labelChangeListener = new ILabelProviderListener() {
public void labelProviderChanged(LabelProviderChangedEvent event) {
Object[] elements = event.getElements();
@@ -773,8 +768,7 @@ public abstract class ContentMergeViewer extends ContentViewer
createControls(fComposite);
- IServiceLocator locator = getCompareConfiguration().getContainer().getServiceLocator();
- fHandlerService= locator != null ? (IHandlerService)locator.getService(IHandlerService.class) : null;
+ fHandlerService= CompareHandlerService.createFor(getCompareConfiguration().getContainer(), fComposite.getShell());
initializeToolbars(parent);
@@ -802,7 +796,7 @@ public abstract class ContentMergeViewer extends ContentViewer
};
Utilities.initAction(fCopyLeftToRightAction, getResourceBundle(), "action.CopyLeftToRight."); //$NON-NLS-1$
tbm.appendToGroup("merge", fCopyLeftToRightAction); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, fCopyLeftToRightAction, "org.eclipse.compare.copyAllLeftToRight", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(fCopyLeftToRightAction, "org.eclipse.compare.copyAllLeftToRight"); //$NON-NLS-1$
}
if (cc.isLeftEditable()) {
@@ -814,7 +808,7 @@ public abstract class ContentMergeViewer extends ContentViewer
};
Utilities.initAction(fCopyRightToLeftAction, getResourceBundle(), "action.CopyRightToLeft."); //$NON-NLS-1$
tbm.appendToGroup("merge", fCopyRightToLeftAction); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, fCopyRightToLeftAction, "org.eclipse.compare.copyAllRightToLeft", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(fCopyRightToLeftAction, "org.eclipse.compare.copyAllRightToLeft"); //$NON-NLS-1$
}
Action a= new ChangePropertyAction(fBundle, getCompareConfiguration(), "action.EnableAncestor.", ICompareUIConstants.PROP_ANCESTOR_VISIBLE); //$NON-NLS-1$
@@ -900,8 +894,7 @@ public abstract class ContentMergeViewer extends ContentViewer
*/
protected void handleDispose(DisposeEvent event) {
- Utilities.deregisterActions(fHandlerService, fActivations);
- fHandlerService= null;
+ fHandlerService.dispose();
Object input= getInput();
if (input instanceof ICompareInput) {
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 6f7551953..b59994a29 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -52,9 +52,7 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
import org.eclipse.ui.actions.ActionFactory;
-import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.progress.IProgressService;
-import org.eclipse.ui.services.IServiceLocator;
import org.eclipse.ui.texteditor.*;
import com.ibm.icu.text.MessageFormat;
@@ -240,8 +238,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
private ActionContributionItem fCopyDiffLeftToRightItem;
private ActionContributionItem fCopyDiffRightToLeftItem;
- private IHandlerService fHandlerService;
- private List fActivations = new ArrayList();
+ private CompareHandlerService fHandlerService;
private boolean fSynchronizedScrolling= true;
private boolean fShowMoreInfo= false;
@@ -1709,8 +1706,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
*/
protected void handleDispose(DisposeEvent event) {
- Utilities.deregisterActions(fHandlerService, fActivations);
- fHandlerService= null;
+ fHandlerService.dispose();
Object input= getInput();
removeFromDocumentManager(ANCESTOR_CONTRIBUTOR, input);
@@ -3776,8 +3772,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
*/
protected void createToolItems(ToolBarManager tbm) {
- IServiceLocator locator = getCompareConfiguration().getContainer().getServiceLocator();
- fHandlerService= locator != null ? (IHandlerService)locator.getService(IHandlerService.class) : null;
+ fHandlerService= CompareHandlerService.createFor(getCompareConfiguration().getContainer(), fLeft.getControl().getShell());
final String ignoreAncestorActionKey= "action.IgnoreAncestor."; //$NON-NLS-1$
Action ignoreAncestorAction= new Action() {
@@ -3834,7 +3829,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
Utilities.initAction(a, getResourceBundle(), "action.NextChange."); //$NON-NLS-1$
fNextChange= new ActionContributionItem(a);
tbm.appendToGroup("navigation", fNextChange); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, a, "org.eclipse.compare.selectNextChange", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(a, "org.eclipse.compare.selectNextChange"); //$NON-NLS-1$
a= new Action() {
public void run() {
@@ -3846,7 +3841,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
Utilities.initAction(a, getResourceBundle(), "action.PrevChange."); //$NON-NLS-1$
fPreviousChange= new ActionContributionItem(a);
tbm.appendToGroup("navigation", fPreviousChange); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, a, "org.eclipse.compare.selectPreviousChange", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(a, "org.eclipse.compare.selectPreviousChange"); //$NON-NLS-1$
CompareConfiguration cc= getCompareConfiguration();
@@ -3860,7 +3855,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
fCopyDiffLeftToRightItem= new ActionContributionItem(a);
fCopyDiffLeftToRightItem.setVisible(true);
tbm.appendToGroup("merge", fCopyDiffLeftToRightItem); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, a, "org.eclipse.compare.copyLeftToRight", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(a, "org.eclipse.compare.copyLeftToRight"); //$NON-NLS-1$
}
if (cc.isLeftEditable()) {
@@ -3873,18 +3868,18 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
fCopyDiffRightToLeftItem= new ActionContributionItem(a);
fCopyDiffRightToLeftItem.setVisible(true);
tbm.appendToGroup("merge", fCopyDiffRightToLeftItem); //$NON-NLS-1$
- Utilities.registerAction(fHandlerService, a, "org.eclipse.compare.copyRightToLeft", fActivations); //$NON-NLS-1$
+ fHandlerService.registerAction(a, "org.eclipse.compare.copyRightToLeft"); //$NON-NLS-1$
}
showWhitespaceAction = new ShowWhitespaceAction(new MergeSourceViewer[] {
fLeft, fRight, fAncestor
});
- Utilities.registerAction(fHandlerService, showWhitespaceAction, ITextEditorActionDefinitionIds.SHOW_WHITESPACE_CHARACTERS, fActivations);
+ fHandlerService.registerAction(showWhitespaceAction, ITextEditorActionDefinitionIds.SHOW_WHITESPACE_CHARACTERS);
toggleLineNumbersAction = new TextEditorPropertyAction(CompareMessages.TextMergeViewer_16, new MergeSourceViewer[] {
fLeft, fRight, fAncestor
}, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER);
- Utilities.registerAction(fHandlerService, toggleLineNumbersAction, ITextEditorActionDefinitionIds.LINENUMBER_TOGGLE, fActivations);
+ fHandlerService.registerAction(toggleLineNumbersAction, ITextEditorActionDefinitionIds.LINENUMBER_TOGGLE);
IAction findAction = new Action() {
public void run() {
@@ -3895,7 +3890,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
}
};
- Utilities.registerAction(fHandlerService, findAction, IWorkbenchActionDefinitionIds.FIND_REPLACE, fActivations);
+ fHandlerService.registerAction(findAction, IWorkbenchActionDefinitionIds.FIND_REPLACE);
}
/* (non-Javadoc)
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java
new file mode 100644
index 000000000..e219d18d2
--- /dev/null
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareHandlerService.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.compare.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.compare.ICompareContainer;
+import org.eclipse.core.expressions.Expression;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.commands.ActionHandler;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.ActiveShellExpression;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.IHandlerActivation;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.services.IServiceLocator;
+
+public class CompareHandlerService {
+
+ private final List fActivations = new ArrayList();
+ private IHandlerService fHandlerService;
+ private final Expression fExpression;
+
+ public static CompareHandlerService createFor(ICompareContainer container, Shell shell) {
+ IServiceLocator serviceLocator = container.getServiceLocator();
+ if (serviceLocator != null) {
+ IHandlerService service = (IHandlerService)serviceLocator.getService(IHandlerService.class);
+ if (service != null)
+ return new CompareHandlerService(service, null);
+ }
+ if (container.getWorkbenchPart() == null && shell != null) {
+ // We're in a dialog so we can use an active shell expression
+ IHandlerService service = (IHandlerService)PlatformUI.getWorkbench().getService(IHandlerService.class);
+ if (service != null) {
+ Expression e = new ActiveShellExpression(shell);
+ return new CompareHandlerService(service, e);
+ }
+ }
+ return new CompareHandlerService(null, null);
+ }
+
+ private CompareHandlerService(IHandlerService handlerService,
+ Expression expression) {
+ fHandlerService = handlerService;
+ fExpression = expression;
+ }
+
+ public void registerAction(IAction action, String commandId) {
+ if (fHandlerService == null)
+ return;
+ action.setActionDefinitionId(commandId);
+ IHandlerActivation activation;
+ if (fExpression == null) {
+ activation = fHandlerService.activateHandler(commandId, new ActionHandler(action));
+ } else {
+ activation = fHandlerService.activateHandler(commandId, new ActionHandler(action), fExpression);
+ }
+ if (activation != null) {
+ fActivations .add(activation);
+ }
+ }
+
+ public void dispose() {
+ if (fHandlerService == null)
+ return;
+ fHandlerService.deactivateHandlers(fActivations);
+ fActivations.clear();
+ fHandlerService = null;
+ }
+}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
index 8ae8e30f2..26d0e7e4a 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
@@ -24,7 +24,6 @@ import org.eclipse.core.resources.mapping.*;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.IDocument;
@@ -34,8 +33,6 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
-import org.eclipse.ui.handlers.IHandlerActivation;
-import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
import org.eclipse.ui.texteditor.IDocumentProvider;
@@ -48,23 +45,6 @@ public class Utilities {
private static final IPath ICONS_PATH= new Path("$nl$/icons/full/"); //$NON-NLS-1$
- public static void registerAction(IHandlerService hs, IAction a, String id, List activations) {
- if (hs != null) {
- a.setActionDefinitionId(id);
- IHandlerActivation activation = hs.activateHandler(id, new ActionHandler(a));
- if (activation != null) {
- activations .add(activation);
- }
- }
- }
-
- public static void deregisterActions(IHandlerService handlerService, List activations) {
- if (handlerService != null) {
- handlerService.deactivateHandlers(activations);
- activations.clear();
- }
- }
-
public static IWorkbenchPartSite findSite(Control c) {
while (c != null && !c.isDisposed()) {
Object data= c.getData();

Back to the top