From f8eac3ec34ae4f5ae1e9a445eade6716dbceded9 Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Wed, 16 Feb 2011 09:58:26 +0000 Subject: [PATCH] added new menu and prototype service --- .../kernel/base/ModelElementHandlerBase.java | 9 +- .../kernel/base/PrototypeProviderBase.java | 1 + .../interfaces/IModelElementHandler.java | 6 +- .../kernel/interfaces/IPrototypeProvider.java | 37 +---- .../kernel/internal/ModelElementService.java | 1 - .../kernel/internal/PrototypeService.java | 49 +++++++ ...EMFStoreECPProjectModelElementHandler.java | 2 +- .../navigator/NavigatorTreeLabelProvider.java | 2 +- .../internal/navigator/NavigatorViewPart.java | 108 ++++++++++++++- .../kernel/internal/navigator/NewMenu.java | 130 ++++++++++++++++++ .../internal/util/EObjectSelectionUtils.java | 47 +++++++ .../kernel/services/IPrototypeService.java | 42 +++++- 12 files changed, 385 insertions(+), 49 deletions(-) create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/util/EObjectSelectionUtils.java diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/ModelElementHandlerBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/ModelElementHandlerBase.java index ee42b3b60..607c3601f 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/ModelElementHandlerBase.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/ModelElementHandlerBase.java @@ -48,9 +48,9 @@ public abstract class ModelElementHandlerBase<T extends EObject> implements /** {@inheritDoc} */ @Override - public final Image getIcon(T element) { + public final Image getIcon() { if (iconImage == null) { - ImageDescriptor descr = getImageDescriptor(); + ImageDescriptor descr = getIconImageDescriptor(); if (descr != null) { iconImage = descr.createImage(); } @@ -58,8 +58,9 @@ public abstract class ModelElementHandlerBase<T extends EObject> implements return iconImage; } - /** Returns image descriptor to be used as icon image. */ - protected ImageDescriptor getImageDescriptor() { + /** {@inheritDoc} */ + @Override + public ImageDescriptor getIconImageDescriptor() { return ToolingKernelActivator.getImageDescriptor("icons/unknown.png"); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/PrototypeProviderBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/PrototypeProviderBase.java index 391694c0b..37f5ee47e 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/PrototypeProviderBase.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/PrototypeProviderBase.java @@ -23,6 +23,7 @@ import java.util.List; import org.conqat.lib.commons.collections.CollectionUtils; import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.kernel.interfaces.IPrototypeProvider; +import org.fortiss.tooling.kernel.services.IPrototypeService.Prototype; /** * Base implementation for {@link IPrototypeProvider}s. diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IModelElementHandler.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IModelElementHandler.java index b752acde1..9f498869e 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IModelElementHandler.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IModelElementHandler.java @@ -20,6 +20,7 @@ package org.fortiss.tooling.kernel.interfaces; import java.util.List; import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; /** @@ -40,7 +41,10 @@ public interface IModelElementHandler<T extends EObject> { String getDescription(T element); /** Returns the icon of the model element. */ - Image getIcon(T element); + Image getIcon(); + + /** Returns image descriptor to be used as icon image. */ + public ImageDescriptor getIconImageDescriptor(); /** Returns all children acting as nodes. */ List<EObject> getSubnodes(T element); diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IPrototypeProvider.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IPrototypeProvider.java index 6ad219b6b..de6ab99f7 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IPrototypeProvider.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IPrototypeProvider.java @@ -20,7 +20,7 @@ package org.fortiss.tooling.kernel.interfaces; import java.util.List; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; +import org.fortiss.tooling.kernel.services.IPrototypeService.Prototype; /** * An {@link IPrototypeProvider} offers preconfigured {@link EObject}s to be @@ -35,39 +35,4 @@ public interface IPrototypeProvider { /** Returns the prototypes provided by this provider. */ List<Prototype> getPrototypes(); - - /** - * Prototypes consist of a generic description and preconfigured - * {@link EObject}. - */ - public static final class Prototype { - /** The generic prototype name. */ - private final String name; - /** the preconfigure {@link EObject}. */ - private final EObject prototype; - - /** Constructor. */ - public Prototype(String name, EObject prototype) { - this.name = name; - this.prototype = prototype; - } - - /** Returns the name. */ - public String getName() { - return name; - } - - /** Returns the prototype instance (NOT a copy!). */ - public EObject getPrototype() { - return prototype; - } - - /** - * Returns a copy of the prototype. This method is potentially - * expensive. - */ - public EObject getPrototypeCopy() { - return EcoreUtil.copy(prototype); - } - } } 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 dc0ff60be..98253d161 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 @@ -75,7 +75,6 @@ public class ModelElementService implements IModelElementService { ex.getMessage(), ex); } } - } /** {@inheritDoc} */ 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 6cd03d430..ac2698536 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 @@ -17,7 +17,18 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.internal; +import java.util.ArrayList; +import java.util.List; + +import org.conqat.ide.commons.ui.extension.ExtensionPointUtils; +import org.conqat.ide.commons.ui.logging.LoggingUtils; +import org.conqat.lib.commons.collections.CollectionUtils; +import org.conqat.lib.commons.collections.UnmodifiableList; +import org.eclipse.core.runtime.IConfigurationElement; +import org.fortiss.tooling.kernel.ToolingKernelActivator; +import org.fortiss.tooling.kernel.interfaces.IPrototypeProvider; import org.fortiss.tooling.kernel.services.IPrototypeService; +import org.osgi.framework.Bundle; /** * This class implements the {@link IPrototypeService} interface. @@ -29,4 +40,42 @@ import org.fortiss.tooling.kernel.services.IPrototypeService; */ 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 model element handler configuration element name. */ + private static final String HANDLER_CONFIGURATION_ELEMENT_NAME = "modelPrototypeProvider"; + + /** Stores the registered prototypes. */ + private final List<IPrototypeProvider> prototypeList = new ArrayList<IPrototypeProvider>(); + + /** Constructor. */ + public PrototypeService() { + setupPrototypes(); + } + + /** Initializes the prototype list from plugin extensions. */ + private void setupPrototypes() { + for (IConfigurationElement ce : ExtensionPointUtils + .getConfigurationElements(HANDLER_EXTENSION_POINT_NAME, + HANDLER_CONFIGURATION_ELEMENT_NAME)) { + Bundle bundle = ExtensionPointUtils.getBundle(ce); + try { + Class<?> handlerClass = ExtensionPointUtils.loadClass( + ce.getAttribute("provider"), bundle); + IPrototypeProvider provider = (IPrototypeProvider) handlerClass + .getConstructor().newInstance(); + prototypeList.add(provider); + } catch (Exception ex) { + LoggingUtils.error(ToolingKernelActivator.getDefault(), + ex.getMessage(), ex); + } + } + } + + /** {@inheritDoc} */ + @Override + public UnmodifiableList<IPrototypeProvider> getPrototypeProviders() { + return CollectionUtils.asUnmodifiable(prototypeList); + } } 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 f0fdeb9a4..fadff9e3d 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 @@ -61,7 +61,7 @@ public final class EMFStoreECPProjectModelElementHandler extends /** {@inheritDoc} */ @Override - protected ImageDescriptor getImageDescriptor() { + public ImageDescriptor getIconImageDescriptor() { return ToolingKernelActivator.getImageDescriptor("icons/project.png"); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorTreeLabelProvider.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorTreeLabelProvider.java index 04ddff01a..5e25afe7d 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorTreeLabelProvider.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NavigatorTreeLabelProvider.java @@ -42,7 +42,7 @@ public final class NavigatorTreeLabelProvider extends BaseLabelProvider IModelElementHandler<EObject> handler = IModelElementService.INSTANCE .getModelElementHandler((EObject) element); if (handler != null) { - return handler.getIcon((EObject) element); + return handler.getIcon(); } } return null; 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 8eb9ee1c0..ede4e074d 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 @@ -24,9 +24,23 @@ import org.eclipse.core.runtime.Status; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.DecoratingLabelProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IDecoratorManager; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.progress.UIJob; import org.fortiss.tooling.kernel.ToolingKernelActivator; @@ -45,7 +59,8 @@ import org.unicase.ecp.model.workSpaceModel.WorkSpaceModelPackage; * @version $Rev$ * @levd.rating RED Rev: */ -public final class NavigatorViewPart extends ViewPart { +public final class NavigatorViewPart extends ViewPart implements + ISelectionListener, ISelectionChangedListener { /** Stores the TreeViewer. */ private TreeViewer viewer; @@ -59,6 +74,9 @@ public final class NavigatorViewPart extends ViewPart { /** Stores the project listener. */ private ECPProjectListener projectListener; + /** Stores the menu manager. */ + private MenuManager menuManager; + /** Constructor. */ public NavigatorViewPart() { try { @@ -144,18 +162,100 @@ public final class NavigatorViewPart extends ViewPart { viewer = new TreeViewer(parent, SWT.MULTI); if (workspace != null) { - // TODO (FH): DecoratorManager - viewer.setLabelProvider(new NavigatorTreeLabelProvider()); + IDecoratorManager decoratorManager = PlatformUI.getWorkbench() + .getDecoratorManager(); + viewer.setLabelProvider(new DecoratingLabelProvider( + new NavigatorTreeLabelProvider(), decoratorManager + .getLabelDecorator())); viewer.setContentProvider(new NavigatorTreeContentProvider()); viewer.setInput(workspace); } - // TODO (FH): SelectionProvider + createContextMenu(); + + PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .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)); + } } + /** Creates the context menu. */ + private void createContextMenu() { + menuManager = new MenuManager(); + + menuManager.add(new NewMenu()); + + Separator repositorySection = new Separator("repository"); + repositorySection.setVisible(true); + menuManager.add(repositorySection); + + Separator additions = new Separator( + IWorkbenchActionConstants.MB_ADDITIONS); + additions.setVisible(true); + menuManager.add(additions); + + getSite().registerContextMenu(menuManager, viewer); + + Control control = viewer.getControl(); + Menu menu = menuManager.createContextMenu(control); + control.setMenu(menu); + } + + /** Creates the actions. */ + /** {@inheritDoc} */ @Override public void setFocus() { viewer.getControl().setFocus(); } + + /** {@inheritDoc} */ + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + // TODO (FH): implement link with editor feature here + } + + /** {@inheritDoc} */ + @Override + public void selectionChanged(SelectionChangedEvent event) { + if (event.getSelection() instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) event + .getSelection(); + Object obj = selection.getFirstElement(); + setActiveECPProject(obj); + } + } + + /** Sets the active ECPProject element. */ + private void setActiveECPProject(Object obj) { + if (obj instanceof EObject) { + try { + ECPWorkspaceManager.getInstance().getWorkSpace() + .setActiveModelelement((EObject) obj); + } catch (NoWorkspaceException e) { + LoggingUtils.error(ToolingKernelActivator.getDefault(), + e.getMessage(), e); + } + } + + } + + /** {@inheritDoc} */ + @Override + public void dispose() { + PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getSelectionService().removeSelectionListener(this); + getSite().setSelectionProvider(null); + + workspace.eAdapters().remove(workspaceListener); + for (ECPProject project : workspace.getProjects()) { + project.removeECPProjectListener(projectListener); + } + + super.dispose(); + } } 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 new file mode 100644 index 000000000..82bf83e19 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/NewMenu.java @@ -0,0 +1,130 @@ +/*-----------------------------------------------------------------------+ + | edu.tum.cs.ccts.model.base + | | + $Id$ + | | + | Copyright (c) 2004-2008 Technische Universitaet Muenchen | + | | + | Technische Universitaet Muenchen ######### ########## | + | Institut fuer Informatik - Lehrstuhl IV ## ## ## ## ## | + | Prof. Dr. Manfred Broy ## ## ## ## ## | + | Boltzmannstr. 3 ## ## ## ## ## | + | 85748 Garching bei Muenchen ## ## ## ## ## | + | Germany ## ###### ## ## | + +-----------------------------------------------------------------------*/ +package org.fortiss.tooling.kernel.internal.navigator; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.viewers.ISelection; +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.IModelElementService; +import org.fortiss.tooling.kernel.services.IPrototypeService; +import org.fortiss.tooling.kernel.services.IPrototypeService.Prototype; + +/** + * The contributor for the dynamic new menu based on composition. + * + * @author hummelb + * @author $Author$ + * @version $Rev$ + * @levd.rating YELLOW Hash: 3CE4433D450E33D6DDFDC4FB9A97FB2E + */ +public class NewMenu extends CompoundContributionItem { + + /** List of available actions. */ + private final List<AddPrototypeAction> actions = new ArrayList<AddPrototypeAction>(); + + /** Constructor. */ + public NewMenu() { + for (IPrototypeProvider provider : IPrototypeService.INSTANCE + .getPrototypeProviders()) { + for (Prototype prototype : provider.getPrototypes()) { + actions.add(new AddPrototypeAction(prototype)); + } + } + } + + /** {@inheritDoc} */ + @Override + protected IContributionItem[] getContributionItems() { + ISelection selection = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getSelectionService() + .getSelection(); + EObject selectedObject = EObjectSelectionUtils + .getFirstElement(selection); + + final List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); + if (selectedObject != null) { + for (final AddPrototypeAction apa : actions) { + if (apa.prepare(selectedObject)) { + contributionItems.add(new ActionContributionItem(apa)); + } + } + } + return contributionItems + .toArray(new IContributionItem[contributionItems.size()]); + } + + /** Action for creating a new prototype. */ + private static class AddPrototypeAction extends Action { + + /** The prototype. */ + private final Prototype prototype; + + /** The container. */ + private EObject container; + + /** Constructor. */ + public AddPrototypeAction(Prototype prototype) { + super("New " + prototype.getName(), IModelElementService.INSTANCE + .getModelElementHandler(prototype.getPrototype()) + .getIconImageDescriptor()); + this.prototype = prototype; + } + + /** {@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); + // } + // } + // }); + } + + /** + * Stores the given container and returns whether the underlying + * prototype can be added to it. + */ + public boolean prepare(EObject container) { + this.container = container; + return false; + // TODO (FH): use composition service + // CompositionManager.getInstance().canCompose(container, + // prototype.getPrototypeObject(), null); + } + + } + +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/util/EObjectSelectionUtils.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/util/EObjectSelectionUtils.java new file mode 100644 index 000000000..f740a87b1 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/util/EObjectSelectionUtils.java @@ -0,0 +1,47 @@ +/*--------------------------------------------------------------------------+ +$Id$ +| | +| Copyright 2011 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.kernel.internal.util; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; + +/** + * Utility methods for {@link EObject} selections. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public final class EObjectSelectionUtils { + + /** + * Returns the first selected EObject or <code>null</code> if no EObject is + * selected. + */ + public static EObject getFirstElement(ISelection selection) { + if (selection instanceof IStructuredSelection && !selection.isEmpty()) { + if (((IStructuredSelection) selection).getFirstElement() instanceof EObject) { + return (EObject) ((IStructuredSelection) selection) + .getFirstElement(); + } + } + return null; + } +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPrototypeService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPrototypeService.java index 005450ca5..8ab4ec757 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPrototypeService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IPrototypeService.java @@ -17,6 +17,10 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.services; +import org.conqat.lib.commons.collections.UnmodifiableList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.fortiss.tooling.kernel.interfaces.IPrototypeProvider; import org.fortiss.tooling.kernel.internal.PrototypeService; /** @@ -33,5 +37,41 @@ public interface IPrototypeService { /** Returns the singleton instance of the service. */ public static final IPrototypeService INSTANCE = new PrototypeService(); - // TODO (FH): define + /** Returns the list of all registered prototype providers. */ + UnmodifiableList<IPrototypeProvider> getPrototypeProviders(); + + /** + * Prototypes consist of a generic description and preconfigured + * {@link EObject}. + */ + public static final class Prototype { + /** The generic prototype name. */ + private final String name; + /** the preconfigure {@link EObject}. */ + private final EObject prototype; + + /** Constructor. */ + public Prototype(String name, EObject prototype) { + this.name = name; + this.prototype = prototype; + } + + /** Returns the name. */ + public String getName() { + return name; + } + + /** Returns the prototype instance (NOT a copy!). */ + public EObject getPrototype() { + return prototype; + } + + /** + * Returns a copy of the prototype. This method is potentially + * expensive. + */ + public EObject getPrototypeCopy() { + return EcoreUtil.copy(prototype); + } + } } -- GitLab