diff --git a/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF index 5bfccf320f993bc04b5eb58a4715e4f7837464b8..d7ee1fa82cb322c999a0115585ddcd61e1549a4f 100644 --- a/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.kernel/trunk/META-INF/MANIFEST.MF @@ -5,8 +5,9 @@ Bundle-SymbolicName: org.fortiss.tooling.kernel;singleton:=true Bundle-Version: 0.0.1.qualifier Bundle-Activator: org.fortiss.tooling.kernel.ToolingKernelActivator Bundle-Vendor: fortiss -Require-Bundle: org.eclipse.ui;visibility:=reexport, - org.eclipse.core.runtime;visibility:=reexport, +Require-Bundle: org.eclipse.core.runtime;visibility:=reexport, + org.eclipse.ui;visibility:=reexport, + org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100";visibility:=reexport, org.eclipse.emf.ecore;bundle-version="2.6.1";visibility:=reexport, org.conqat.ide.commons;bundle-version="2.7.0";visibility:=reexport, org.conqat.ide.commons.ui;bundle-version="2.7.0";visibility:=reexport, diff --git a/org.fortiss.tooling.kernel/trunk/plugin.xml b/org.fortiss.tooling.kernel/trunk/plugin.xml index 1187435ba168bfba74af4df904f3ccd4ba675355..e3605d576d076cea545612f2a4bc92928f9d430b 100644 --- a/org.fortiss.tooling.kernel/trunk/plugin.xml +++ b/org.fortiss.tooling.kernel/trunk/plugin.xml @@ -4,6 +4,7 @@ <extension-point id="modelElementHandler" name="Model Element Handler" schema="schema/modelElementHandler.exsd"/> <extension-point id="modelPrototypeProvider" name="Model Prototype Provider" schema="schema/modelPrototypeProvider.exsd"/> <extension-point id="modelElementCompositor" name="Model Element Compositor" schema="schema/modelElementCompositor.exsd"/> + <extension-point id="modelEditorBinding" name="Model Element Editor Bindings" schema="schema/modelEditorBinding.exsd"/> <extension point="org.eclipse.emf.ecore.generated_package"> <package diff --git a/org.fortiss.tooling.kernel/trunk/schema/modelEditorBinding.exsd b/org.fortiss.tooling.kernel/trunk/schema/modelEditorBinding.exsd new file mode 100644 index 0000000000000000000000000000000000000000..c30a887e6d9d4f23a488d4177999b8ca6439269e --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/schema/modelEditorBinding.exsd @@ -0,0 +1,112 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.fortiss.tooling.kernel" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appinfo> + <meta.schema plugin="org.fortiss.tooling.kernel" id="modelEditorBinding" name="Model Element Editor Bindings"/> + </appinfo> + <documentation> + Registers editors for specific model elements. + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appinfo> + <meta.element /> + </appinfo> + </annotation> + <complexType> + <sequence> + <element ref="modelEditorBinding" minOccurs="1" maxOccurs="unbounded"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute translatable="true"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="modelEditorBinding"> + <complexType> + <attribute name="modelElementClass" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute kind="java" basedOn=":org.eclipse.emf.ecore.EObject"/> + </appinfo> + </annotation> + </attribute> + <attribute name="binding" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute kind="java" basedOn=":org.fortiss.tooling.kernel.interfaces.IEditorBinding"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appinfo> + <meta.section type="since"/> + </appinfo> + <documentation> + [Enter the first release in which this extension point appears.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="examples"/> + </appinfo> + <documentation> + [Enter extension point usage example here.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="apiinfo"/> + </appinfo> + <documentation> + [Enter API information here.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="implementation"/> + </appinfo> + <documentation> + [Enter information about supplied implementation of this extension point.] + </documentation> + </annotation> + + +</schema> diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBindingBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBindingBase.java new file mode 100644 index 0000000000000000000000000000000000000000..478a5b23aa53b2d1243f27b28283dc2d8abaf38c --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBindingBase.java @@ -0,0 +1,39 @@ +/*--------------------------------------------------------------------------+ +$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.base; + +import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.interfaces.IEditorBinding; + +/** + * Abstract class for editor bindings. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public abstract class EditorBindingBase<T extends EObject> implements + IEditorBinding<EObject>, Comparable<IEditorBinding<EObject>> { + + /** {@inheritDoc} */ + @Override + public final int compareTo(IEditorBinding<EObject> eb) { + return eb.getPriority() - getPriority(); + } +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ICompositor.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ICompositor.java index 8eb8b1568fc7237d574a57992e1165260768d6ab..22bf53730aa62ca7eef6db548f29ab6c5fdb8b0a 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ICompositor.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/ICompositor.java @@ -28,7 +28,7 @@ import org.eclipse.emf.ecore.EObject; * @version $Rev$ * @levd.rating RED Rev: */ -public interface ICompositor<T extends EObject> { +public interface ICompositor<T extends EObject> extends IEObjectAware<T> { /** * Returns whether the given container may include the given contained * object. diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IEObjectAware.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IEObjectAware.java new file mode 100644 index 0000000000000000000000000000000000000000..377ae8dcd55bd2384c8d33d1646ba1230256edb9 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IEObjectAware.java @@ -0,0 +1,33 @@ +/*--------------------------------------------------------------------------+ +$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.interfaces; + +import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.internal.EObjectAwareService; + +/** + * Abstract interface for {@link EObjectAwareService} base implementation. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public interface IEObjectAware<T extends EObject> { + // nothing specific is need here +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IEditorBinding.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IEditorBinding.java new file mode 100644 index 0000000000000000000000000000000000000000..ad674efac5e4a31b8978518dbdad4577939e1c09 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IEditorBinding.java @@ -0,0 +1,42 @@ +/*--------------------------------------------------------------------------+ +$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.interfaces; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.ui.IEditorPart; + +/** + * Interface for editor bindings. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public interface IEditorBinding<T extends EObject> extends + IEObjectAware<EObject> { + + /** Returns the class of the editor registered by this binding. */ + Class<? extends IEditorPart> getEditorClass(); + + /** Returns the label of the editor. */ + String getLabel(); + + /** Returns the priority of the editor. Higher values have lower priority. */ + int getPriority(); +} 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 1ed068ac8da50677042af647872832f7741705b3..fa1c28494ab64618f226e7b09ee12484b855041b 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,21 +17,12 @@ $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. @@ -41,7 +32,8 @@ import org.osgi.framework.Bundle; * @version $Rev$ * @levd.rating RED Rev: */ -public class CompositorService implements ICompositorService { +public final class CompositorService extends + EObjectAwareService<ICompositor<EObject>> implements ICompositorService { /** The compositor extension point ID. */ private static final String EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelElementCompositor"; @@ -49,47 +41,8 @@ public class CompositorService implements ICompositorService { /** 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); - } + /** The compositor attribute name. */ + private static final String ATTRIBUTE_NAME = "compositor"; /** {@inheritDoc} */ @Override @@ -112,8 +65,8 @@ public class CompositorService implements ICompositorService { */ private ICompositor<EObject> findWorkingCompositor(EObject container, EObject contained, ICompositionContext context) { - final List<ICompositor<EObject>> list = ReflectionUtils - .performNearestClassLookup(container.getClass(), compositorMap); + List<ICompositor<EObject>> list = getRegisteredHandlers(container + .getClass()); if (list == null) { return null; } @@ -124,4 +77,22 @@ public class CompositorService implements ICompositorService { } return null; } + + /** {@inheritDoc} */ + @Override + protected String getExtensionPointName() { + return EXTENSION_POINT_NAME; + } + + /** {@inheritDoc} */ + @Override + protected String getConfigurationElementName() { + return CONFIGURATION_ELEMENT_NAME; + } + + /** {@inheritDoc} */ + @Override + protected String getHandlerClassAttribute() { + return ATTRIBUTE_NAME; + } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/EObjectAwareService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/EObjectAwareService.java new file mode 100644 index 0000000000000000000000000000000000000000..1f9b7e1792d255037844f74bdc58534c7fed42cc --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/EObjectAwareService.java @@ -0,0 +1,108 @@ +/*--------------------------------------------------------------------------+ +$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; + +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.IEObjectAware; +import org.osgi.framework.Bundle; + +/** + * Service base implementation, which supports handler registration with + * {@link EObject} relation. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public abstract class EObjectAwareService<T extends IEObjectAware<EObject>> { + + /** Stores the class to handler map. */ + protected final Map<Class<?>, List<T>> handlerMap = new HashMap<Class<?>, List<T>>(); + + /** Constructor. */ + public EObjectAwareService() { + setupHandlerMap(); + } + + /** Returns the list of registered handlers for the given class. */ + public List<T> getRegisteredHandlers(Class<?> modelElementClass) { + return ReflectionUtils.performNearestClassLookup(modelElementClass, + handlerMap); + } + + /** Initializes the handler map from plugin extensions. */ + @SuppressWarnings({ "unchecked" }) + private void setupHandlerMap() { + for (IConfigurationElement ce : ExtensionPointUtils + .getConfigurationElements(getExtensionPointName(), + getConfigurationElementName())) { + Bundle bundle = ExtensionPointUtils.getBundle(ce); + try { + Class<?> modelElementClass = ExtensionPointUtils.loadClass( + ce.getAttribute(getModelElementClassAttribute()), + bundle); + Class<?> handlerClass = ExtensionPointUtils.loadClass( + ce.getAttribute(getHandlerClassAttribute()), bundle); + T handler = (T) handlerClass.getConstructor().newInstance(); + addHandler(modelElementClass, handler); + } catch (Exception ex) { + LoggingUtils.error(ToolingKernelActivator.getDefault(), + ex.getMessage(), ex); + } + } + } + + /** Adds the given compositor to the map. */ + private void addHandler(Class<?> modelElementClass, T handler) { + List<T> list = handlerMap.get(modelElementClass); + if (list == null) { + list = new LinkedList<T>(); + handlerMap.put(modelElementClass, list); + } + list.add(handler); + } + + /** Returns the extension point name. */ + protected abstract String getExtensionPointName(); + + /** Returns the configuration element name. */ + protected abstract String getConfigurationElementName(); + + /** Returns the handler class attribute name. */ + protected abstract String getHandlerClassAttribute(); + + /** + * Returns the attribute name for the model element class. Sub-classes may + * override, but should first consider to use the default value + * <i>modelElementClass</i> in the extension point definition. + */ + protected String getModelElementClassAttribute() { + return "modelElementClass"; + } +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/EditorService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/EditorService.java index ef889a25a574aa7cd8456557ab333d1ae5528c99..34ed34c81add8b10ad3a61b5cdf1a61fa54d7e45 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/EditorService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/EditorService.java @@ -17,6 +17,12 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.internal; +import java.util.Collections; +import java.util.List; + +import org.conqat.lib.commons.collections.CollectionUtils; +import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.base.EditorBindingBase; import org.fortiss.tooling.kernel.services.IEditorService; /** @@ -27,6 +33,54 @@ import org.fortiss.tooling.kernel.services.IEditorService; * @version $Rev$ * @levd.rating RED Rev: */ -public class EditorService implements IEditorService { +public class EditorService extends + EObjectAwareService<EditorBindingBase<EObject>> implements + IEditorService { + + /** The compositor extension point ID. */ + private static final String EXTENSION_POINT_NAME = "org.fortiss.tooling.kernel.modelEditorBinding"; + + /** The compositor configuration element name. */ + private static final String CONFIGURATION_ELEMENT_NAME = "modelEditorBinding"; + + /** The compositor attribute name. */ + private static final String ATTRIBUTE_NAME = "binding"; + + /** Constructor. */ + public EditorService() { + super(); + // sort editor bindings by priority. + for (Class<?> clazz : handlerMap.keySet()) { + Collections.sort(handlerMap.get(clazz)); + } + } + + /** {@inheritDoc} */ + @Override + public List<EditorBindingBase<EObject>> getBindings(EObject element) { + List<EditorBindingBase<EObject>> bindings = getRegisteredHandlers(element + .getClass()); + if (bindings == null) { + bindings = CollectionUtils.emptyList(); + } + return bindings; + } + + /** {@inheritDoc} */ + @Override + protected String getExtensionPointName() { + return EXTENSION_POINT_NAME; + } + + /** {@inheritDoc} */ + @Override + protected String getConfigurationElementName() { + return CONFIGURATION_ELEMENT_NAME; + } + /** {@inheritDoc} */ + @Override + protected String getHandlerClassAttribute() { + return ATTRIBUTE_NAME; + } } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/editor/BindingEditor.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/editor/BindingEditor.java new file mode 100644 index 0000000000000000000000000000000000000000..94d140c1bc438cbf3b8b4322d37b93962a49595e --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/editor/BindingEditor.java @@ -0,0 +1,201 @@ +/*-----------------------------------------------------------------------+ + | 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.editor; + +import org.conqat.ide.commons.ui.logging.LoggingUtils; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.part.MultiPageEditorPart; +import org.eclipse.ui.views.properties.IPropertySheetPage; +import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; +import org.fortiss.tooling.kernel.ToolingKernelActivator; +import org.fortiss.tooling.kernel.base.EditorBindingBase; +import org.fortiss.tooling.kernel.interfaces.IHandler; +import org.fortiss.tooling.kernel.services.IEditorService; + +/** + * This editor is used for displaying multiple editors provided by editor + * bindings for a given model element. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating YELLOW Hash: 5BCA3453180427D26544F7CF84AFDB4B + */ +public class BindingEditor extends MultiPageEditorPart implements + ITabbedPropertySheetPageContributor { + + /** The editor's ID. */ + public static String ID = BindingEditor.class.getName(); + + // TODO (FH): change this + /** The tabbed property sheet contributor ID. */ + public static final String TABBED_PROPERTY_CONTRIBUTOR_ID = "edu.tum.cs.ccts.model.base.properties.Contributor"; + + /** + * The object shown in this editor. This is valid as soon as + * {@link #init(IEditorSite, IEditorInput)} has been called. + */ + protected EObject editedObject; + + /** The model element handler to be used with the {@link #editedObject}. */ + protected IHandler<EObject> handler; + + /** + * The adapter used for learning about changes in the {@link #editedObject}. + */ + private final Adapter editedObjectChangeAdapter = new AdapterImpl() { + + /** {@inheritDoc} */ + @Override + public void notifyChanged(Notification msg) { + editedObjectChanged(); + } + }; + + /** + * This is called whenever something about the currently edited object + * changes. This is used to update the part name and to close the editor if + * the object is removed. + */ + protected void editedObjectChanged() { + setPartName(handler.getName(editedObject)); + setContentDescription(handler.getDescription(editedObject)); + + if (editedObject.eContainer() == null) { + getSite().getPage().closeEditor(this, false); + } + } + + /** {@inheritDoc} */ + @Override + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + if (!(input instanceof ModelElementEditorInput)) { + throw new PartInitException( + "BindingEditor initialized with wrong editor input object."); + } + super.init(site, input); + + ModelElementEditorInput meInput = ((ModelElementEditorInput) input); + editedObject = meInput.getEditorInput(); + if (editedObject == null) { + throw new PartInitException("Missing model element!"); + } + + handler = meInput.getModelElementHandler(); + if (handler == null) { + throw new PartInitException("Missing model element handler!"); + } + + setPartName(handler.getName(editedObject)); + setContentDescription(handler.getDescription(editedObject)); + setTitleImage(handler.getIcon()); + + editedObject.eAdapters().add(editedObjectChangeAdapter); + } + + /** {@inheritDoc} */ + @Override + protected void createPages() { + int pageIndex = 0; + for (EditorBindingBase<EObject> editorBinding : IEditorService.INSTANCE + .getBindings(editedObject)) { + try { + IEditorPart editorPart = editorBinding.getEditorClass() + .newInstance(); + addPage(editorPart, getEditorInput()); + setPageText(pageIndex++, editorBinding.getLabel()); + } catch (Exception ex) { + LoggingUtils.error(ToolingKernelActivator.getDefault(), + "Editor instantiation failed.", ex); + } + } + } + + /** {@inheritDoc} */ + @Override + public void doSave(IProgressMonitor monitor) { + // Saving is handled automatically by emfStore + } + + /** {@inheritDoc} */ + @Override + public void doSaveAs() { + // Saving is handled automatically by emfStore + } + + /** {@inheritDoc} */ + @Override + public void dispose() { + editedObject.eAdapters().remove(editedObjectChangeAdapter); + super.dispose(); + } + + /** {@inheritDoc} */ + @Override + public boolean isDirty() { + // editors for emfStore objects are never dirty + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean isSaveAsAllowed() { + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean isSaveOnCloseNeeded() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public String getContributorId() { + return TABBED_PROPERTY_CONTRIBUTOR_ID; + } + + /** + * {@inheritDoc} + */ + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if (adapter == IPropertySheetPage.class) { + return new TabbedPropertySheetPage(this); + } + return super.getAdapter(adapter); + } + + /** + * TODO: COMMENT ME + */ + public void gotoMarker(IMarker marker) { + // TODO (FH): implement marker goto + } +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/editor/ModelElementEditorInput.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/editor/ModelElementEditorInput.java new file mode 100644 index 0000000000000000000000000000000000000000..b16b3efc42be2853c1e8385eb403218d0b1f8a0c --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/editor/ModelElementEditorInput.java @@ -0,0 +1,111 @@ +/*--------------------------------------------------------------------------+ +$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.editor; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IPersistableElement; +import org.fortiss.tooling.kernel.interfaces.IHandler; +import org.fortiss.tooling.kernel.services.IModelElementService; + +/** + * {@link IEditorInput} used when opening a {@link BindingEditor}. + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @levd.rating RED Rev: + */ +public final class ModelElementEditorInput implements IEditorInput { + + /** The editor input {@link EObject}. */ + private final EObject modelElement; + + /** Stores the model element handler. */ + private final IHandler<EObject> handler; + + /** Constructor. */ + public ModelElementEditorInput(EObject modelElement) { + this.modelElement = modelElement; + this.handler = IModelElementService.INSTANCE + .getModelElementHandler(modelElement); + } + + /** Returns the editor input {@link EObject}. */ + public EObject getEditorInput() { + return modelElement; + } + + /** Returns the model element handler. */ + public IHandler<EObject> getModelElementHandler() { + return handler; + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object obj) { + return obj instanceof ModelElementEditorInput + && ((ModelElementEditorInput) obj).getEditorInput().equals( + modelElement); + } + + /** {@inheritDoc} */ + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + return null; + } + + /** {@inheritDoc} */ + @Override + public boolean exists() { + return modelElement.eContainer() != null; + } + + /** {@inheritDoc} */ + @Override + public ImageDescriptor getImageDescriptor() { + // TODO (FH): add image support + return null; + } + + /** {@inheritDoc} */ + @Override + public String getName() { + return handler.getName(modelElement); + } + + /** {@inheritDoc} */ + @Override + public IPersistableElement getPersistable() { + return null; + } + + /** {@inheritDoc} */ + @Override + public String getToolTipText() { + return handler.getDescription(modelElement); + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + return super.hashCode(); + } +} diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IEditorService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IEditorService.java index 84097c756a3324282036e839a4f78fbe60acb887..d6d00d8b6aa1def2ee9b6afd98f4f54fe07d7606 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IEditorService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/IEditorService.java @@ -17,6 +17,10 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.services; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.base.EditorBindingBase; import org.fortiss.tooling.kernel.internal.EditorService; /** @@ -32,5 +36,6 @@ public interface IEditorService { /** Returns the singleton instance of the service. */ public static final IEditorService INSTANCE = new EditorService(); - // TODO (FH): define + /** Returns registered editor bindings for the given {@link EObject}. */ + List<EditorBindingBase<EObject>> getBindings(EObject element); }