diff options
author | Lars Vogel | 2013-10-17 18:25:36 +0000 |
---|---|---|
committer | Lars Vogel | 2013-10-21 08:10:06 +0000 |
commit | 258f3de49e8bfc6cb09a907ac2138b111c03c485 (patch) | |
tree | 893140af5cf2947010021dbd488b04e4c0992ed0 | |
parent | d4467f6804860df70d29b6335c0516b8eea11390 (diff) | |
download | org.eclipse.e4.tools-258f3de49e8bfc6cb09a907ac2138b111c03c485.tar.gz org.eclipse.e4.tools-258f3de49e8bfc6cb09a907ac2138b111c03c485.tar.xz org.eclipse.e4.tools-258f3de49e8bfc6cb09a907ac2138b111c03c485.zip |
Bug 419723 - Update ModelProcessor class to uses services
Change-Id: I49c3e63500921c4bc3f84dd9058532e993b90681
Signed-off-by: Lars Vogel <Lars.Vogel@gmail.com>
-rw-r--r-- | bundles/org.eclipse.e4.tools.emf.liveeditor/src/org/eclipse/e4/tools/emf/liveeditor/ModelProcessor.java | 114 |
1 files changed, 60 insertions, 54 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.liveeditor/src/org/eclipse/e4/tools/emf/liveeditor/ModelProcessor.java b/bundles/org.eclipse.e4.tools.emf.liveeditor/src/org/eclipse/e4/tools/emf/liveeditor/ModelProcessor.java index 3ddbbad5..f28fd13e 100644 --- a/bundles/org.eclipse.e4.tools.emf.liveeditor/src/org/eclipse/e4/tools/emf/liveeditor/ModelProcessor.java +++ b/bundles/org.eclipse.e4.tools.emf.liveeditor/src/org/eclipse/e4/tools/emf/liveeditor/ModelProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 BestSolution.at and others. + * Copyright (c) 2010 - 2013 BestSolution.at 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 @@ -7,6 +7,7 @@ * * Contributors: * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + * Lars Vogel <lars.vogel@gmail.com> - Bug 419723 ******************************************************************************/ package org.eclipse.e4.tools.emf.liveeditor; @@ -14,84 +15,89 @@ import java.util.List; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.ui.model.application.MApplication; -import org.eclipse.e4.ui.model.application.MApplicationElement; import org.eclipse.e4.ui.model.application.commands.MCommand; -import org.eclipse.e4.ui.model.application.commands.MCommandsFactory; 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.descriptor.basic.MPartDescriptor; +import org.eclipse.e4.ui.workbench.modeling.EModelService; -@SuppressWarnings("restriction") public class ModelProcessor { - + @Execute - public void process(MApplication application) { - MCommand command = findElementInstance(application.getCommands(), "e4.tooling.livemodel"); - - - if( command == null ) { - command = MCommandsFactory.INSTANCE.createCommand(); + public void process(MApplication application, EModelService modelService) { + System.out.println("ModelProcessor EModelService"); + List<MCommand> commands = modelService.findElements(application, + "e4.tooling.livemodel", MCommand.class, null); + + MCommand command = null; + + if (commands.size() == 0) { + command = modelService.createModelElement(MCommand.class); command.setElementId("e4.tooling.livemodel"); command.setCommandName("Show running app model"); command.setDescription("Show the running application model"); - application.getCommands().add(command); + application.getCommands().add(command); + } else { + command = commands.get(0); } - - MHandler handler = findElementInstance(application.getHandlers(), "e4.tooling.livemodel.handler"); - - if( handler == null ) { - handler = MCommandsFactory.INSTANCE.createHandler(); + + List<MHandler> handlers = modelService.findElements(application, + "e4.tooling.livemodel.handler", MHandler.class, null); + + MHandler handler = null; + + if (handlers.size() == 0) { + handler = modelService.createModelElement(MHandler.class); handler.setElementId("e4.tooling.livemodel.handler"); handler.setContributionURI("bundleclass://org.eclipse.e4.tools.emf.liveeditor/org.eclipse.e4.tools.emf.liveeditor.OpenLiveDialogHandler"); - handler.setCommand(command); - application.getHandlers().add(handler); + application.getHandlers().add(handler); } else { - handler.setCommand(command); + handler = handlers.get(0); } + handler.setCommand(command); - MKeyBinding binding = null; - - if( application.getBindingTables().size() > 0 ) { - binding = findElementInstance(application.getBindingTables().get(0).getBindings(), "e4.tooling.livemodel.binding"); - } - - if( binding == null ) { - binding = MCommandsFactory.INSTANCE.createKeyBinding(); - binding.setElementId("e4.tooling.livemodel.binding"); - binding.setKeySequence("ALT+SHIFT+F9"); - binding.setCommand(command); - if( application.getBindingTables().size() > 0 ) { - application.getBindingTables().get(0).getBindings().add(binding); - } - } else { + + if (application.getBindingTables().size() > 0) { + List<MKeyBinding> keyBindings = modelService.findElements( + application, "e4.tooling.livemodel.binding", + MKeyBinding.class, null); + + if (keyBindings.size() == 0) { + binding = modelService.createModelElement(MKeyBinding.class); + binding.setElementId("e4.tooling.livemodel.binding"); + binding.setKeySequence("ALT+SHIFT+F9"); + if (application.getBindingTables().size() > 0) { + application.getBindingTables().get(0).getBindings() + .add(binding); + } + } else { + binding = keyBindings.get(0); + } binding.setCommand(command); } - - MPartDescriptor descriptor = findElementInstance(application.getDescriptors(), "org.eclipse.e4.tools.emf.liveeditor.view"); - if( descriptor == null ) { - descriptor = org.eclipse.e4.ui.model.application.descriptor.basic.MBasicFactory.INSTANCE.createPartDescriptor(); + MPartDescriptor descriptor = null; + List<MPartDescriptor> descriptors = modelService.findElements( + application, "org.eclipse.e4.tools.emf.liveeditor.view", + MPartDescriptor.class, null); + + if (descriptors.size() == 0) { + descriptor = modelService.createModelElement(MPartDescriptor.class); descriptor.setCategory("org.eclipse.e4.secondaryDataStack"); descriptor.setElementId("org.eclipse.e4.tools.emf.liveeditor.view"); descriptor.getTags().add("View"); descriptor.getTags().add("categoryTag:General"); - + descriptor.setLabel("Live Application Model"); - descriptor.setContributionURI("bundleclass://org.eclipse.e4.tools.emf.liveeditor/org.eclipse.e4.tools.emf.liveeditor.LivePartDelegator"); - descriptor.setContributorURI("bundleclass://org.eclipse.e4.tools.emf.liveeditor"); - descriptor.setIconURI("platform:/plugin/org.eclipse.e4.tools.emf.liveeditor/icons/full/obj16/application_lightning.png"); - application.getDescriptors().add(descriptor); + descriptor + .setContributionURI("bundleclass://org.eclipse.e4.tools.emf.liveeditor/org.eclipse.e4.tools.emf.liveeditor.LivePartDelegator"); + descriptor + .setContributorURI("bundleclass://org.eclipse.e4.tools.emf.liveeditor"); + descriptor + .setIconURI("platform:/plugin/org.eclipse.e4.tools.emf.liveeditor/icons/full/obj16/application_lightning.png"); + application.getDescriptors().add(descriptor); } } - - private <O> O findElementInstance(List<? extends MApplicationElement> l, String id) { - for( MApplicationElement e : l ) { - if( id.equals(e.getElementId()) ) { - return (O) e; - } - } - - return null; - } + } |