Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.e4.tools.spy/src/org/eclipse/e4/tools/spy/SpyProcessor.java')
-rw-r--r--bundles/org.eclipse.e4.tools.spy/src/org/eclipse/e4/tools/spy/SpyProcessor.java152
1 files changed, 68 insertions, 84 deletions
diff --git a/bundles/org.eclipse.e4.tools.spy/src/org/eclipse/e4/tools/spy/SpyProcessor.java b/bundles/org.eclipse.e4.tools.spy/src/org/eclipse/e4/tools/spy/SpyProcessor.java
index 5cb402f5..854c37b8 100644
--- a/bundles/org.eclipse.e4.tools.spy/src/org/eclipse/e4/tools/spy/SpyProcessor.java
+++ b/bundles/org.eclipse.e4.tools.spy/src/org/eclipse/e4/tools/spy/SpyProcessor.java
@@ -29,8 +29,6 @@ import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.commands.MBindingContext;
import org.eclipse.e4.ui.model.application.commands.MBindingTable;
import org.eclipse.e4.ui.model.application.commands.MCommand;
-import org.eclipse.e4.ui.model.application.commands.MCommandParameter;
-import org.eclipse.e4.ui.model.application.commands.MHandler;
import org.eclipse.e4.ui.model.application.commands.MKeyBinding;
import org.eclipse.e4.ui.model.application.commands.MParameter;
import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor;
@@ -47,7 +45,6 @@ public class SpyProcessor {
public static final String SPY_COMMAND = "org.eclipse.e4.tools.spy.command";
public static final String SPY_COMMAND_PARAM = "org.eclipse.e4.tools.spy.command.partID";
- private static final String SPY_HANDLER = "org.eclipse.e4.tools.spy.handler";
private static final String E4_SPIES_BINDING_TABLE = "org.eclipse.e4.tools.spy.bindings";
MApplication application;
@@ -63,16 +60,11 @@ public class SpyProcessor {
@Execute
public void process(IExtensionRegistry extRegistry) {
- // This processor will read all spy extensions and automatically create
- // the command, handler and binding
- // to open this spy in the dedicated spy window.
+ // This processor will read all spy extensions and automatically fill
+ // the dynamics contents where spies are used
- // First of all, it creates the spyCommand having one parameter (Id of
- // the part to display) and default handler for this command.
-
-
-
- MCommand command = getOrCreateSpyCommand();
+ MCommand command = getSpyCommand();
+ MBindingTable bindingTable = getBindingTable();
for (IConfigurationElement e : extRegistry.getConfigurationElementsFor("org.eclipse.e4.tools.spy.spyPart")) {
String partName = e.getAttribute("name");
@@ -87,7 +79,7 @@ public class SpyProcessor {
// Bind the command with the binding, and add the view ID as
// parameter.
// The part class name will be the ID of the part descriptor
- bindSpyKeyBinding(shortCut, command, partID);
+ bindSpyKeyBinding(bindingTable, shortCut, command, partID);
// Add the descriptor in application
addSpyPartDescriptor(partID, partName, iconPath, partClass, desc);
@@ -103,8 +95,9 @@ public class SpyProcessor {
}
- public MCommand getOrCreateSpyCommand() {
- // DO NOT USE findElement on ModelService (it searches only in
+ public MCommand getSpyCommand() {
+
+ // Warning : DO NOT USE findElement on ModelService (it searches only in
// MUIElements)
for (MCommand cmd : application.getCommands()) {
if (SPY_COMMAND.equals(cmd.getElementId())) {
@@ -113,60 +106,80 @@ public class SpyProcessor {
}
}
- MCommand command = modelService.createModelElement(MCommand.class);
- command.setElementId(SPY_COMMAND);
- command.setCommandName("Open a spy");
- String contributorURI = "platform:/plugin/" + FrameworkUtil.getBundle(getClass()).getSymbolicName();
- command.setContributorURI(contributorURI);
- command.setDescription("Open a spy in the E4 spy window");
-
- // Parameter (will be the ID of the part descriptor (ie, the full
- // qualified class name))
- // It will be received in the Handler and send by keybinding
- MCommandParameter cp = modelService.createModelElement(MCommandParameter.class);
- cp.setElementId(SPY_COMMAND_PARAM);
- cp.setName("viewPart");
- cp.setContributorURI(contributorURI);
- command.getParameters().add(cp);
-
- application.getCommands().add(command);
-
- // Create the default handler for this command
- // (will receive the parameter)
- for (MHandler hdl : application.getHandlers()) {
- if (SPY_HANDLER.equals(hdl.getElementId())) {
- // Do nothing if handler exists, return the command
- return command;
+ log.error("The Spy command (with ID : " + SPY_COMMAND
+ + " cannot be found (It should be provided by org.elipse.e4.tools/fragmenE4.xmi");
+
+ return null;
+ }
+
+
+
+ /**
+ * Helper method to get or create the binding table for all spies (where
+ * spies will add their key binding). Bind this table with the
+ * org.eclipse.ui.contexts.dialogAndWindow binding context which should be
+ * present (create it if not)
+ *
+ * This method will probably move to the common spy plugin providing common
+ * spy stuff (see bug #428903)
+ *
+ * @param keySequence
+ * @param cmd
+ * @param paramViewId
+ */
+ public void bindSpyKeyBinding(MBindingTable spyBindingTable, String keySequence, MCommand cmd, String paramViewId) {
+ // This method must :
+ // search for a binding table having the binding context 'dialog and
+ // window'
+ // If none found, create it and also the binding context
+ // Then can add the KeyBinding if not already added
+
+
+ // Search for the key binding if already present
+ for (MKeyBinding kb : spyBindingTable.getBindings())
+ if (keySequence.equals(kb.getKeySequence())) {
+ // A binding with this key sequence is already present. Check if
+ // command is the same
+ if (kb.getCommand().getElementId().equals(cmd.getElementId()))
+ return;
+ else {
+ // Must log an error : key binding already exists in this
+ // table but with another command
+ System.out.println("WARNING : Cannot bind the command '" + cmd.getElementId()
+ + "' to the keySequence : " + keySequence + " because the command "
+ + kb.getCommand().getElementId() + " is already bound !");
+ return;
+ }
}
- }
- // Create the handler for this command.
- MHandler handler = modelService.createModelElement(MHandler.class);
- handler.setElementId(SPY_HANDLER);
- handler.setContributionURI("bundleclass://org.eclipse.e4.tools.spy/org.eclipse.e4.tools.spy.SpyHandler");
- handler.setContributorURI("platform:/plugin/org.eclipse.e4.tools.spy");
- application.getHandlers().add(handler);
+ // Key binding is not yet in table... can add it now.
+ MKeyBinding binding = modelService.createModelElement(MKeyBinding.class);
+ binding.setElementId(paramViewId + ".binding");
+ binding.setContributorURI(cmd.getContributorURI());
+ binding.setKeySequence(keySequence);
- handler.setCommand(command);
+ MParameter p = modelService.createModelElement(MParameter.class);
+ p.setName(SPY_COMMAND_PARAM);
+ p.setValue(paramViewId);
+ binding.getParameters().add(p);
- return command;
+ spyBindingTable.getBindings().add(binding);
+ binding.setCommand(cmd);
}
/**
- * Helper method to get or create the binding table for all spies (where spies
- * will add their key binding). Bind this table with the
+ * Helper method to get or create the binding table for all spies (where
+ * spies will add their key binding). Bind this table with the
* org.eclipse.ui.contexts.dialogAndWindow binding context which should be
* present (create it if not)
*
- * This method will probably move to the common spy plugin providing common spy
- * stuff (see bug #428903)
*
* @param keySequence
* @param cmd
* @param paramViewId
*/
- public void bindSpyKeyBinding(String keySequence, MCommand cmd, String paramViewId) {
+ private MBindingTable getBindingTable() {
// This method must :
// search for a binding table having the binding context 'dialog and
// window'
@@ -210,36 +223,7 @@ public class SpyProcessor {
}
- // Search for the key binding if already present
- for (MKeyBinding kb : spyBindingTable.getBindings())
- if (keySequence.equals(kb.getKeySequence())) {
- // A binding with this key sequence is already present. Check if
- // command is the same
- if (kb.getCommand().getElementId().equals(cmd.getElementId()))
- return;
- else {
- // Must log an error : key binding already exists in this
- // table but with another command
- System.out.println("WARNING : Cannot bind the command '" + cmd.getElementId()
- + "' to the keySequence : " + keySequence + " because the command "
- + kb.getCommand().getElementId() + " is already bound !");
- return;
- }
- }
-
- // Key binding is not yet in table... can add it now.
- MKeyBinding binding = modelService.createModelElement(MKeyBinding.class);
- binding.setElementId(cmd.getElementId() + ".binding");
- binding.setContributorURI(cmd.getContributorURI());
- binding.setKeySequence(keySequence);
-
- MParameter p = modelService.createModelElement(MParameter.class);
- p.setName(SPY_COMMAND_PARAM);
- p.setValue(paramViewId);
- binding.getParameters().add(p);
-
- spyBindingTable.getBindings().add(binding);
- binding.setCommand(cmd);
+ return spyBindingTable;
}
@@ -274,7 +258,7 @@ public class SpyProcessor {
@AboutToShow
public void fillE4SpyMenu(List<MMenuElement> items) {
- MCommand command = getOrCreateSpyCommand();
+ MCommand command = getSpyCommand();
for (MPartDescriptor mp : application.getDescriptors()) {
if (mp.getTags().contains(SPY_TAG)) {
MHandledMenuItem hi = modelService.createModelElement(MHandledMenuItem.class);

Back to the top