diff --git a/org.fortiss.tooling.kernel/trunk/icons/add.png b/org.fortiss.tooling.kernel/trunk/icons/add.png new file mode 100644 index 0000000000000000000000000000000000000000..2917b87e4ba0ec558c0314afd05546b58f27a3ba Binary files /dev/null and b/org.fortiss.tooling.kernel/trunk/icons/add.png differ diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CompositorService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CompositorService.java index 3e0cc1375f8cf5b98ad528af3f02751f873180ed..1ed068ac8da50677042af647872832f7741705b3 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CompositorService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/CompositorService.java @@ -17,7 +17,21 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.internal; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.conqat.ide.commons.ui.extension.ExtensionPointUtils; +import org.conqat.ide.commons.ui.logging.LoggingUtils; +import org.conqat.lib.commons.reflect.ReflectionUtils; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.ToolingKernelActivator; +import org.fortiss.tooling.kernel.interfaces.ICompositionContext; +import org.fortiss.tooling.kernel.interfaces.ICompositor; import org.fortiss.tooling.kernel.services.ICompositorService; +import org.osgi.framework.Bundle; /** * This class implements the {@link ICompositorService} interface. @@ -29,4 +43,85 @@ import org.fortiss.tooling.kernel.services.ICompositorService; */ public class CompositorService implements ICompositorService { + /** The compositor extension point ID. */ + private static final String EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelElementCompositor"; + + /** The compositor configuration element name. */ + private static final String CONFIGURATION_ELEMENT_NAME = "modelElementCompositor"; + + /** Stores the compositors for each model element class. */ + private Map<Class<?>, List<ICompositor<EObject>>> compositorMap; + + /** Constructor. */ + public CompositorService() { + setupCompositorMap(); + } + + /** Initializes the compositor map from plugin extensions. */ + @SuppressWarnings({ "unchecked" }) + private void setupCompositorMap() { + compositorMap = new HashMap<Class<?>, List<ICompositor<EObject>>>(); + for (IConfigurationElement ce : ExtensionPointUtils + .getConfigurationElements(EXTENSION_POINT_NAME, + CONFIGURATION_ELEMENT_NAME)) { + Bundle bundle = ExtensionPointUtils.getBundle(ce); + try { + Class<?> modelElementClass = ExtensionPointUtils.loadClass( + ce.getAttribute("modelElementClass"), bundle); + Class<?> compositorClass = ExtensionPointUtils.loadClass( + ce.getAttribute("compositor"), bundle); + ICompositor<EObject> compositor = (ICompositor<EObject>) compositorClass + .getConstructor().newInstance(); + addCompositor(modelElementClass, compositor); + } catch (Exception ex) { + LoggingUtils.error(ToolingKernelActivator.getDefault(), + ex.getMessage(), ex); + } + } + } + + /** Adds the given compositor to the map. */ + private void addCompositor(Class<?> modelElementClass, + ICompositor<EObject> compositor) { + List<ICompositor<EObject>> list = compositorMap.get(modelElementClass); + if (list == null) { + list = new LinkedList<ICompositor<EObject>>(); + compositorMap.put(modelElementClass, list); + } + list.add(compositor); + } + + /** {@inheritDoc} */ + @Override + public boolean canCompose(EObject container, EObject element, + ICompositionContext context) { + return findWorkingCompositor(container, element, context) != null; + } + + /** {@inheritDoc} */ + @Override + public boolean compose(EObject container, EObject element, + ICompositionContext context) { + return findWorkingCompositor(container, element, context).compose( + container, element, context); + } + + /** + * Returns the first {@link ICompositor} which can compose the given element + * (or <code>null</code>). + */ + private ICompositor<EObject> findWorkingCompositor(EObject container, + EObject contained, ICompositionContext context) { + final List<ICompositor<EObject>> list = ReflectionUtils + .performNearestClassLookup(container.getClass(), compositorMap); + if (list == null) { + return null; + } + for (ICompositor<EObject> compositor : list) { + if (compositor.canCompose(container, contained, context)) { + return compositor; + } + } + return null; + } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ModelElementService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ModelElementService.java index 98253d161a96e293d70fa33575a0273c2169181e..220873fe83c6040840e5971facbd47223f62955c 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ModelElementService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ModelElementService.java @@ -41,10 +41,10 @@ import org.osgi.framework.Bundle; public class ModelElementService implements IModelElementService { /** The model element handler extension point ID. */ - private static final String HANDLER_EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelElementHandler"; + private static final String EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelElementHandler"; /** The model element handler configuration element name. */ - private static final String HANDLER_CONFIGURATION_ELEMENT_NAME = "modelElementHandler"; + private static final String CONFIGURATION_ELEMENT_NAME = "modelElementHandler"; /** Stores the model element handler for each model element class. */ private Map<Class<?>, IModelElementHandler<EObject>> handlerMap; @@ -59,8 +59,8 @@ public class ModelElementService implements IModelElementService { private void setupHandlerMap() { handlerMap = new HashMap<Class<?>, IModelElementHandler<EObject>>(); for (IConfigurationElement ce : ExtensionPointUtils - .getConfigurationElements(HANDLER_EXTENSION_POINT_NAME, - HANDLER_CONFIGURATION_ELEMENT_NAME)) { + .getConfigurationElements(EXTENSION_POINT_NAME, + CONFIGURATION_ELEMENT_NAME)) { Bundle bundle = ExtensionPointUtils.getBundle(ce); try { Class<?> modelElementClass = ExtensionPointUtils.loadClass( diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/PrototypeService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/PrototypeService.java index ac2698536fd89abc8f6b4e56cb355b5de5af9d07..229d85e28fcb5ca793233258f22e6656ee50886e 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/PrototypeService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/PrototypeService.java @@ -40,13 +40,13 @@ import org.osgi.framework.Bundle; */ public class PrototypeService implements IPrototypeService { - /** The model element handler extension point ID. */ - private static final String HANDLER_EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelPrototypeProvider"; + /** The prototype provider extension point ID. */ + private static final String EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelPrototypeProvider"; - /** The model element handler configuration element name. */ - private static final String HANDLER_CONFIGURATION_ELEMENT_NAME = "modelPrototypeProvider"; + /** The prototype provider configuration element name. */ + private static final String CONFIGURATION_ELEMENT_NAME = "modelPrototypeProvider"; - /** Stores the registered prototypes. */ + /** Stores the registered prototype providers. */ private final List<IPrototypeProvider> prototypeList = new ArrayList<IPrototypeProvider>(); /** Constructor. */ @@ -57,8 +57,8 @@ public class PrototypeService implements IPrototypeService { /** Initializes the prototype list from plugin extensions. */ private void setupPrototypes() { for (IConfigurationElement ce : ExtensionPointUtils - .getConfigurationElements(HANDLER_EXTENSION_POINT_NAME, - HANDLER_CONFIGURATION_ELEMENT_NAME)) { + .getConfigurationElements(EXTENSION_POINT_NAME, + CONFIGURATION_ELEMENT_NAME)) { Bundle bundle = ExtensionPointUtils.getBundle(ce); try { Class<?> handlerClass = ExtensionPointUtils.loadClass( diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/handler/EMFStoreECPProjectModelElementHandler.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/handler/EMFStoreECPProjectModelElementHandler.java index fadff9e3d67da38eb83d39756f17f6aa61a85033..ad3c2307afd0b7f7a9d0ac77519351acbab15b6a 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/handler/EMFStoreECPProjectModelElementHandler.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/handler/EMFStoreECPProjectModelElementHandler.java @@ -68,12 +68,12 @@ public final class EMFStoreECPProjectModelElementHandler extends /** {@inheritDoc} */ @Override public List<EObject> getSubnodes(EMFStoreECPProject element) { - List<EObject> projectRootElements = new ArrayList<EObject>(); - for (EObject pContent : element.eContents()) { - if (pContent instanceof IProjectRootElement) { - projectRootElements.add(pContent); + List<EObject> list = new ArrayList<EObject>(); + for (EObject node : element.getAllModelElements()) { + if (node instanceof IProjectRootElement) { + list.add(node); } } - return projectRootElements; + return list; } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java index ede4e074dd9d6e76c01d050bcfe889819ece8632..362ba00a372adcfafba61a20ea90b6bde0bbf926 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorViewPart.java @@ -177,17 +177,22 @@ public final class NavigatorViewPart extends ViewPart implements .getSelectionService().addSelectionListener(this); getSite().setSelectionProvider(viewer); - if (viewer.getTree().getItems().length > 0) { - setActiveECPProject(viewer.getTree().getItem(0).getData()); - viewer.getTree().select(viewer.getTree().getItem(0)); - } + // FIXME: whats that good for? + // if (viewer.getTree().getItems().length > 0) { + // setActiveECPProject(viewer.getTree().getItem(0).getData()); + // viewer.getTree().select(viewer.getTree().getItem(0)); + // } } /** Creates the context menu. */ private void createContextMenu() { menuManager = new MenuManager(); - menuManager.add(new NewMenu()); + MenuManager newMenuManager = new MenuManager("New ...", + ToolingKernelActivator.getImageDescriptor("icons/add.png"), + NewMenu.MENU_ID); + newMenuManager.add(new NewMenu()); + menuManager.add(newMenuManager); Separator repositorySection = new Separator("repository"); repositorySection.setVisible(true); @@ -226,7 +231,8 @@ public final class NavigatorViewPart extends ViewPart implements IStructuredSelection selection = (IStructuredSelection) event .getSelection(); Object obj = selection.getFirstElement(); - setActiveECPProject(obj); + // FIXME: Whats that good for? + // setActiveECPProject(obj); } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java index 82bf83e199bf0c8d001033ce4b4683c5fdb69ca7..22f92967904b17931e9d3b60922dbb809532c2e2 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java @@ -26,6 +26,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.CompoundContributionItem; import org.fortiss.tooling.kernel.interfaces.IPrototypeProvider; import org.fortiss.tooling.kernel.internal.util.EObjectSelectionUtils; +import org.fortiss.tooling.kernel.services.ICompositorService; import org.fortiss.tooling.kernel.services.IModelElementService; import org.fortiss.tooling.kernel.services.IPrototypeService; import org.fortiss.tooling.kernel.services.IPrototypeService.Prototype; @@ -33,13 +34,16 @@ import org.fortiss.tooling.kernel.services.IPrototypeService.Prototype; /** * The contributor for the dynamic new menu based on composition. * - * @author hummelb + * @author hoelzlf * @author $Author$ * @version $Rev$ * @levd.rating YELLOW Hash: 3CE4433D450E33D6DDFDC4FB9A97FB2E */ public class NewMenu extends CompoundContributionItem { + /** The menu id. */ + public static final String MENU_ID = "org.fortiss.tooling.kernel.newmenu"; + /** List of available actions. */ private final List<AddPrototypeAction> actions = new ArrayList<AddPrototypeAction>(); @@ -62,9 +66,9 @@ public class NewMenu extends CompoundContributionItem { EObject selectedObject = EObjectSelectionUtils .getFirstElement(selection); - final List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); + List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); if (selectedObject != null) { - for (final AddPrototypeAction apa : actions) { + for (AddPrototypeAction apa : actions) { if (apa.prepare(selectedObject)) { contributionItems.add(new ActionContributionItem(apa)); } @@ -85,7 +89,7 @@ public class NewMenu extends CompoundContributionItem { /** Constructor. */ public AddPrototypeAction(Prototype prototype) { - super("New " + prototype.getName(), IModelElementService.INSTANCE + super(prototype.getName(), IModelElementService.INSTANCE .getModelElementHandler(prototype.getPrototype()) .getIconImageDescriptor()); this.prototype = prototype; @@ -94,23 +98,10 @@ public class NewMenu extends CompoundContributionItem { /** {@inheritDoc} */ @Override public void run() { - final EObject newObject = prototype.getPrototypeCopy(); - - // TODO (FH): implement composition - // final ModelContext context = ModelContextManager.getInstance() - // .getContext(container); - // context.runAsCommand(new Runnable() { - // @Override - // public void run() { - // final boolean composed = CompositionManager.getInstance() - // .compose(container, newObject, null); - // if (composed - // && !EditorBindingManager.getInstance() - // .getEditorBindings(newObject).isEmpty()) { - // context.openInEditor(newObject); - // } - // } - // }); + EObject newObject = prototype.getPrototypeCopy(); + if (ICompositorService.INSTANCE.compose(container, newObject, null)) { + // TODO (FH): open editor + } } /** @@ -119,10 +110,8 @@ public class NewMenu extends CompoundContributionItem { */ public boolean prepare(EObject container) { this.container = container; - return false; - // TODO (FH): use composition service - // CompositionManager.getInstance().canCompose(container, - // prototype.getPrototypeObject(), null); + return ICompositorService.INSTANCE.canCompose(container, + prototype.getPrototype(), null); } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/ICompositorService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/ICompositorService.java index 8048dfb7a0b7fbca97ba5e104ba7ee551e73e153..043999d331df1189d2a9a87e1f8d7427afe87e32 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/ICompositorService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/ICompositorService.java @@ -17,6 +17,8 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.services; +import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.interfaces.ICompositionContext; import org.fortiss.tooling.kernel.internal.CompositorService; /** @@ -33,5 +35,17 @@ public interface ICompositorService { /** Returns the singleton instance of the service. */ public static final ICompositorService INSTANCE = new CompositorService(); - // TODO (FH): define + /** + * Determines if there is a compositor that allows the composition of the + * container and the prototype {@link EObject}. + */ + boolean canCompose(EObject container, EObject element, + ICompositionContext context); + + /** + * Composes the container and the element. Since this operation may be + * canceled by the user, it returns a boolean value. + */ + boolean compose(EObject container, EObject element, + ICompositionContext context); }