Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Merks2015-11-20 13:00:13 +0000
committerLars Vogel2015-12-01 15:46:56 +0000
commit7d084641490d9ab423494a832bc2da6cd2012614 (patch)
tree37e34875bb115882272806c5cda0ef9e58886bfe
parentba180dcb153ebd5da8f1610ad4fc7176aa443ecd (diff)
downloadeclipse.platform.ui-7d084641490d9ab423494a832bc2da6cd2012614.tar.gz
eclipse.platform.ui-7d084641490d9ab423494a832bc2da6cd2012614.tar.xz
eclipse.platform.ui-7d084641490d9ab423494a832bc2da6cd2012614.zip
Bug 482680 Support mapped lookup of command by element ID
To support the fast lookup of commands in the application, we provide a new method to access commands directly via ID. Looping over the commands has been identified as performance problem during startup. Change-Id: I2373a6d877e7b9d71ae7a9d974ad80e4a9944349 Signed-off-by: Ed Merks <ed.merks@gmail.com>
-rw-r--r--bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/application/MApplication.java8
-rw-r--r--bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/application/impl/ApplicationImpl.java32
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java8
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java8
4 files changed, 40 insertions, 16 deletions
diff --git a/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/application/MApplication.java b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/application/MApplication.java
index 9b411607785..d8f714eec29 100644
--- a/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/application/MApplication.java
+++ b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/application/MApplication.java
@@ -86,6 +86,14 @@ public interface MApplication extends MElementContainer<MWindow>, MContext, MHan
List<MCommand> getCommands();
/**
+ * Returns the model element for the command identified via the elementId or
+ * null if the element cannot be found
+ *
+ * @since 1.2
+ */
+ MCommand getCommand(String elementId);
+
+ /**
* Returns the value of the '<em><b>Addons</b></em>' containment reference list.
* The list contents are of type {@link org.eclipse.e4.ui.model.application.MAddon}.
* <!-- begin-user-doc -->
diff --git a/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/application/impl/ApplicationImpl.java b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/application/impl/ApplicationImpl.java
index 44ea5da5faa..08e40870077 100644
--- a/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/application/impl/ApplicationImpl.java
+++ b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/application/impl/ApplicationImpl.java
@@ -11,6 +11,7 @@
package org.eclipse.e4.ui.model.application.impl;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.e4.core.contexts.IEclipseContext;
@@ -256,6 +257,8 @@ public class ApplicationImpl extends ElementContainerImpl<MWindow> implements MA
*/
protected EList<MDialog> dialogs;
+ protected Map<String, MCommand> elementIdToCommandMap;
+
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
@@ -456,15 +459,40 @@ public class ApplicationImpl extends ElementContainerImpl<MWindow> implements MA
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
- * @generated
+ * @generated NOT
*/
public List<MCommand> getCommands() {
if (commands == null) {
- commands = new EObjectContainmentEList<MCommand>(MCommand.class, this, ApplicationPackageImpl.APPLICATION__COMMANDS);
+ commands = new EObjectContainmentEList<MCommand>(MCommand.class, this,
+ ApplicationPackageImpl.APPLICATION__COMMANDS) {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void didChange() {
+ elementIdToCommandMap = null;
+ super.didChange();
+ }
+ };
}
return commands;
}
+ public MCommand getCommand(String elementId) {
+ if (elementIdToCommandMap == null) {
+ Map<String, MCommand> result = new HashMap<String, MCommand>();
+ for (MCommand command : getCommands()) {
+ MCommand otherCommand = result.put(command.getElementId(), command);
+ if (otherCommand != null) {
+ result.put(command.getElementId(), otherCommand);
+ }
+ }
+
+ elementIdToCommandMap = result;
+ }
+ return elementIdToCommandMap.get(elementId);
+ }
+
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java
index ce0f3db69c8..c6ab0604d9c 100644
--- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java
+++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java
@@ -406,13 +406,7 @@ public final class ContributionsAnalyzer {
}
public static MCommand getCommandById(MApplication app, String cmdId) {
- final List<MCommand> cmds = app.getCommands();
- for (MCommand cmd : cmds) {
- if (cmdId.equals(cmd.getElementId())) {
- return cmd;
- }
- }
- return null;
+ return app.getCommand(cmdId);
}
static class Key {
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java
index b42aff49d88..d01320601c2 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java
@@ -595,13 +595,7 @@ public final class BindingService implements IBindingService {
ParameterizedCommand parmCmd = binding.getParameterizedCommand();
String id = parmCmd.getId();
- MCommand cmd = null;
- for (MCommand appCommand : application.getCommands()) {
- if (id.equals(appCommand.getElementId())) {
- cmd = appCommand;
- break;
- }
- }
+ MCommand cmd = application.getCommand(id);
if (cmd == null) {
return null;
}

Back to the top