Skip to content
Snippets Groups Projects
Commit c1a147c9 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

intermediary check-in

parent f8eac3ec
No related branches found
No related tags found
No related merge requests found
Showing
with 152 additions and 48 deletions
org.fortiss.tooling.kernel/trunk/icons/add.png

307 B

......@@ -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;
}
}
......@@ -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(
......
......@@ -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(
......
......@@ -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;
}
}
......@@ -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);
}
}
......
......@@ -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);
}
}
......
......@@ -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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment