diff --git a/org.fortiss.tooling.kernel/trunk/icons/library.png b/org.fortiss.tooling.kernel/trunk/icons/library.png new file mode 100644 index 0000000000000000000000000000000000000000..35a3b9b945078b8ff2ad510597c4a1ff7aec3faf Binary files /dev/null and b/org.fortiss.tooling.kernel/trunk/icons/library.png differ diff --git a/org.fortiss.tooling.kernel/trunk/icons/link_with_editor.gif b/org.fortiss.tooling.kernel/trunk/icons/link_with_editor.gif new file mode 100644 index 0000000000000000000000000000000000000000..870934b6934844102afd508e067750591ccc34c0 Binary files /dev/null and b/org.fortiss.tooling.kernel/trunk/icons/link_with_editor.gif differ diff --git a/org.fortiss.tooling.kernel/trunk/icons/tumlogo.png b/org.fortiss.tooling.kernel/trunk/icons/tumlogo.png new file mode 100644 index 0000000000000000000000000000000000000000..d3f3895395477c473ccbdebace1f639723aeb9b3 Binary files /dev/null and b/org.fortiss.tooling.kernel/trunk/icons/tumlogo.png differ diff --git a/org.fortiss.tooling.kernel/trunk/plugin.xml b/org.fortiss.tooling.kernel/trunk/plugin.xml index 02b98324e42cb873cbdcbf70399df26485337ee2..94c410998c84b93cde3e6975a7ff0810b93f1c82 100644 --- a/org.fortiss.tooling.kernel/trunk/plugin.xml +++ b/org.fortiss.tooling.kernel/trunk/plugin.xml @@ -26,13 +26,15 @@ point="org.eclipse.ui.views"> <view class="org.fortiss.tooling.kernel.internal.navigator.NavigatorViewPart" + icon="icons/tumlogo.png" id="org.fortiss.tooling.kernel.model.navigator" name="Model Navigator" restorable="true"> </view> <view class="org.fortiss.tooling.kernel.internal.views.LibraryView" - id="org.fortiss.tooling.kernel.internal.views" + icon="icons/library.png" + id="org.fortiss.tooling.kernel.model.element.library" name="Model Elements" restorable="true"> </view> diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EObjectAction.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EObjectActionBase.java similarity index 93% rename from org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EObjectAction.java rename to org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EObjectActionBase.java index 5c020c251ff55fb7e21af4f0d70d01c14e9205ea..26bb88a2ce26d675d16ff986b49bcb18edfe221e 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EObjectAction.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EObjectActionBase.java @@ -29,13 +29,13 @@ import org.eclipse.jface.resource.ImageDescriptor; * @version $Rev$ * @ConQAT.Rating RED Hash: C4F9557D8CC494C748E0C75BF07DC40C */ -public abstract class EObjectAction extends Action { +public abstract class EObjectActionBase extends Action { /** Stores the target {@link EObject}. */ private EObject target; /** Constructor. */ - public EObjectAction(String text, ImageDescriptor image) { + public EObjectActionBase(String text, ImageDescriptor image) { super(text, image); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java index a8618702e4d944b58558b75b74ff8f0bd3861f9b..6685e78df5c79ae41dc653338fc43b309a8c2ed4 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/base/EditorBase.java @@ -52,6 +52,22 @@ public abstract class EditorBase<T extends EObject> extends EditorPart { /** Databinding context used for model changes. */ protected final DataBindingContext dbc = new DataBindingContext(); + /** Returns the edited object. */ + public EObject getEditedObject() { + return editedObject; + } + + /** + * Returns the list of visible model element classes. This list is used to + * determine, which elements are to be included in the model element + * library. Sub-classes should override the default behavior, which returns + * the class of the {@link #editedObject}. + */ + @SuppressWarnings("unchecked") + public Class<? extends EObject>[] getVisibleEObjectTypes() { + return new Class[] { editedObject.getClass() }; + } + /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override @@ -63,7 +79,7 @@ public abstract class EditorBase<T extends EObject> extends EditorPart { } ModelElementEditorInput meInput = (ModelElementEditorInput) input; - editedObject = (T) meInput.getEditorInput(); + editedObject = (T) meInput.getModelElement(); if (editedObject == null) { throw new PartInitException("Missing model element!"); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/views/IBindingEditorPageChangeListener.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IBindingEditorPageChangeListener.java similarity index 87% rename from org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/views/IBindingEditorPageChangeListener.java rename to org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IBindingEditorPageChangeListener.java index 55d1e4ceeaa484d166004fd2ae5ba05b2654544a..fc145d11e27a55fedf64031f20c21961b415209c 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/views/IBindingEditorPageChangeListener.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/interfaces/IBindingEditorPageChangeListener.java @@ -15,11 +15,14 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ | See the License for the specific language governing permissions and | | limitations under the License. | +--------------------------------------------------------------------------*/ -package org.fortiss.tooling.kernel.internal.views; +package org.fortiss.tooling.kernel.interfaces; + +import org.fortiss.tooling.kernel.internal.editor.BindingEditor; /** + * Listener for page changes of the {@link BindingEditor}. * - * @author Eder + * @author hoelzl * @author $Author: hoelzl $ * @version $Rev: 18709 $ * @ConQAT.Rating RED Hash: F730F4FC380A1FD636CAE29BDBA5E643 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 58d25dce9c2b9c3775cee20fe23ce251d7c656ac..057671a31922bdf40dea19328a227b19ca5d6269 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 @@ -18,6 +18,7 @@ $Id$ package org.fortiss.tooling.kernel.interfaces; import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.kernel.services.IPrototypeService.Prototype; /** * Interface for compositors, i.e. classes which know how to compose @@ -43,4 +44,13 @@ public interface ICompositor<T extends EObject> extends IEObjectAware<T> { * might cancel the command. */ boolean compose(T container, EObject contained, ICompositionContext context); + + /** + * Returns whether this compositor is able to compose the given prototype. + * While {@link #canCompose(EObject, EObject, ICompositionContext)} + * considers a concrete composition between the container and contained + * element, this method returns this compositor's ability to accept the + * given prototype in general. + */ + boolean canComposePrototype(Prototype prototype); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java index 934d250d9c18786bab433ac35f0f4282972b8deb..d41a980791837d9dd89606bb8df339c77712fb8c 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/ActionService.java @@ -26,7 +26,7 @@ import org.eclipse.ui.ISharedImages; import org.eclipse.ui.IViewSite; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionFactory; -import org.fortiss.tooling.kernel.base.EObjectAction; +import org.fortiss.tooling.kernel.base.EObjectActionBase; import org.fortiss.tooling.kernel.model.IRemovable; import org.fortiss.tooling.kernel.services.IActionService; import org.fortiss.tooling.kernel.services.ICommandStackService; @@ -47,7 +47,7 @@ public class ActionService implements IActionService { public static final String GROUP_GLOBAL_DEFAULTS = "globalDefaults"; /** The global undo action. */ - public final EObjectAction globalUndoAction = new EObjectAction("Undo", + public final EObjectActionBase globalUndoAction = new EObjectActionBase("Undo", PlatformUI.getWorkbench().getSharedImages() .getImageDescriptor(ISharedImages.IMG_TOOL_UNDO)) { @@ -60,7 +60,7 @@ public class ActionService implements IActionService { }; /** The global redo action. */ - public final EObjectAction globalRedoAction = new EObjectAction("Redo", + public final EObjectActionBase globalRedoAction = new EObjectActionBase("Redo", PlatformUI.getWorkbench().getSharedImages() .getImageDescriptor(ISharedImages.IMG_TOOL_UNDO)) { @@ -73,7 +73,7 @@ public class ActionService implements IActionService { }; /** The global delete action. */ - public final EObjectAction globalDeleteAction = new EObjectAction("Delete", + public final EObjectActionBase globalDeleteAction = new EObjectActionBase("Delete", PlatformUI.getWorkbench().getSharedImages() .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)) { @Override 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 1c63b24ca2f3981a1d16377c58b1d25a4e519b24..84f834399f09635eaab46a8b15e76fcf0356adaa 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 @@ -24,6 +24,7 @@ import org.fortiss.tooling.kernel.base.EObjectAwareServiceBase; import org.fortiss.tooling.kernel.interfaces.ICompositionContext; import org.fortiss.tooling.kernel.interfaces.ICompositor; import org.fortiss.tooling.kernel.services.ICompositorService; +import org.fortiss.tooling.kernel.services.IPrototypeService.Prototype; /** * This class implements the {@link ICompositorService} interface. @@ -61,6 +62,22 @@ public final class CompositorService extends container, element, context); } + /** {@inheritDoc} */ + @Override + public boolean canComposePrototype(Class<? extends EObject> containerClass, + Prototype prototype) { + List<ICompositor<EObject>> list = getRegisteredHandlers(containerClass); + if (list == null) { + return false; + } + for (ICompositor<EObject> compositor : list) { + if (compositor.canComposePrototype(prototype)) { + return true; + } + } + return false; + } + /** * Returns the first {@link ICompositor} which can compose the given element * (or <code>null</code>). diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/NavigatorService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/NavigatorService.java index 6b0e615d6d224f1f24d9f2c93604540918868685..1a8e399f3b3ceb9ed5f6c160317217f056386d16 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/NavigatorService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/NavigatorService.java @@ -190,4 +190,10 @@ public class NavigatorService implements INavigatorService, return context.hashCode(); } } + + /** {@inheritDoc} */ + @Override + public void revealModelElement(EObject modelElement) { + navigatorViewPart.revealModelElement(modelElement); + } } 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 3908312da7c550dc413f097760af5dcab20060aa..c1f6434f1461f0237612839575f4aa8de73ea8fe 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 @@ -18,6 +18,7 @@ $Id$ package org.fortiss.tooling.kernel.internal; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import org.conqat.ide.commons.ui.extension.ExtensionPointUtils; @@ -25,8 +26,10 @@ 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.eclipse.emf.ecore.EObject; import org.fortiss.tooling.kernel.ToolingKernelActivator; import org.fortiss.tooling.kernel.interfaces.IPrototypeProvider; +import org.fortiss.tooling.kernel.services.ICompositorService; import org.fortiss.tooling.kernel.services.IPrototypeService; import org.osgi.framework.Bundle; @@ -88,4 +91,18 @@ public class PrototypeService implements IPrototypeService { } return CollectionUtils.asUnmodifiable(result); } + + /** {@inheritDoc} */ + @Override + public List<Prototype> getComposablePrototypes( + Class<? extends EObject> modelElementType) { + List<Prototype> result = new LinkedList<Prototype>(); + for (Prototype prototype : getAllPrototypes()) { + if (ICompositorService.INSTANCE.canComposePrototype( + modelElementType, prototype)) { + result.add(prototype); + } + } + return result; + } } 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 index 91ed7f0c3487c0a6b9deecae661ec0f53be2d2e9..9e1629188edaa38b982f934103798ab2c03a26b2 100644 --- 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 @@ -17,7 +17,10 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.internal.editor; +import java.util.Collection; + import org.conqat.ide.commons.ui.logging.LoggingUtils; +import org.conqat.lib.commons.collections.IdentityHashSet; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.common.notify.Adapter; @@ -33,6 +36,7 @@ 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.interfaces.IBindingEditorPageChangeListener; import org.fortiss.tooling.kernel.interfaces.IEditorBinding; import org.fortiss.tooling.kernel.interfaces.IHandler; import org.fortiss.tooling.kernel.services.IEditorService; @@ -74,6 +78,31 @@ public class BindingEditor extends MultiPageEditorPart implements } }; + /** Stores the binding editor listeners. */ + private final Collection<IBindingEditorPageChangeListener> bindingEditorListeners = new IdentityHashSet<IBindingEditorPageChangeListener>(); + + /** Adds a page change listener. */ + public void addBindingEditorListener( + IBindingEditorPageChangeListener listener) { + bindingEditorListeners.add(listener); + } + + /** Removes a page change listener. */ + public void removeBindingEditorListener( + IBindingEditorPageChangeListener listener) { + bindingEditorListeners.remove(listener); + } + + /** {@inheritDoc} */ + @Override + protected void pageChange(int newPageIndex) { + super.pageChange(newPageIndex); + + for (final IBindingEditorPageChangeListener listener : bindingEditorListeners) { + listener.pageChanged(); + } + } + /** * 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 @@ -88,6 +117,11 @@ public class BindingEditor extends MultiPageEditorPart implements } } + /** Returns the active editor. */ + public IEditorPart getActiveEditorPart() { + return getActiveEditor(); + } + /** {@inheritDoc} */ @Override public void init(IEditorSite site, IEditorInput input) @@ -99,7 +133,7 @@ public class BindingEditor extends MultiPageEditorPart implements super.init(site, input); ModelElementEditorInput meInput = ((ModelElementEditorInput) input); - editedObject = meInput.getEditorInput(); + editedObject = meInput.getModelElement(); if (editedObject == null) { throw new PartInitException("Missing model element!"); } 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 index 226ca953e369526c03738f7cd78e551ffc8a530f..8fedaab0e0a2443cca4f399357211cba6cd94e74 100644 --- 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 @@ -47,8 +47,8 @@ public final class ModelElementEditorInput implements IEditorInput { .getModelElementHandler(modelElement); } - /** Returns the editor input {@link EObject}. */ - public EObject getEditorInput() { + /** Returns the editor input's {@link EObject} model element. */ + public EObject getModelElement() { return modelElement; } @@ -61,7 +61,7 @@ public final class ModelElementEditorInput implements IEditorInput { @Override public boolean equals(Object obj) { return obj instanceof ModelElementEditorInput - && ((ModelElementEditorInput) obj).getEditorInput().equals( + && ((ModelElementEditorInput) obj).getModelElement().equals( modelElement); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/LinkWithEditorPartListener.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/LinkWithEditorPartListener.java new file mode 100644 index 0000000000000000000000000000000000000000..a8f604f473ef8304fc8c88c468569985dd9c5d88 --- /dev/null +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/navigator/LinkWithEditorPartListener.java @@ -0,0 +1,96 @@ +/*--------------------------------------------------------------------------+ +$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.navigator; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IPartListener2; +import org.eclipse.ui.IWorkbenchPartReference; +import org.fortiss.tooling.kernel.internal.editor.ModelElementEditorInput; +import org.fortiss.tooling.kernel.services.INavigatorService; + +/** + * + * @author hoelzlf + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating RED Rev: + */ +final class LinkWithEditorPartListener implements IPartListener2 { + + /** {@inheritDoc} */ + @Override + public void partActivated(IWorkbenchPartReference partRef) { + revealModelElementInNavigator(partRef); + } + + /** {@inheritDoc} */ + @Override + public void partInputChanged(IWorkbenchPartReference partRef) { + revealModelElementInNavigator(partRef); + } + + /** Calls {@link INavigatorService} to reveal the editor input element. */ + private void revealModelElementInNavigator(IWorkbenchPartReference partRef) { + if (partRef instanceof IEditorReference) { + IEditorPart editor = ((IEditorReference) partRef).getEditor(true); + if (editor.getEditorInput() instanceof ModelElementEditorInput) { + EObject editorInput = ((ModelElementEditorInput) editor + .getEditorInput()).getModelElement(); + INavigatorService.INSTANCE.revealModelElement(editorInput); + } + } + } + + /** {@inheritDoc} */ + @Override + public void partBroughtToTop(IWorkbenchPartReference partRef) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void partClosed(IWorkbenchPartReference partRef) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void partDeactivated(IWorkbenchPartReference partRef) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void partOpened(IWorkbenchPartReference partRef) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void partHidden(IWorkbenchPartReference partRef) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void partVisible(IWorkbenchPartReference partRef) { + // ignore + } +} 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 6c6536eaa5918a4386cee5b518eddf28153a4712..190668de2f1028cf8e3da64f09df4602db26428f 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,8 +24,11 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; import org.eclipse.jface.viewers.DecoratingLabelProvider; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IDoubleClickListener; @@ -33,11 +36,14 @@ 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.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Menu; import org.eclipse.ui.IDecoratorManager; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IPartListener2; import org.eclipse.ui.ISaveablePart; import org.eclipse.ui.ISaveablesSource; import org.eclipse.ui.ISelectionListener; @@ -50,8 +56,11 @@ import org.eclipse.ui.progress.UIJob; 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.interfaces.ICustomMenuContributor; import org.fortiss.tooling.kernel.internal.NavigatorService; +import org.fortiss.tooling.kernel.internal.editor.BindingEditor; +import org.fortiss.tooling.kernel.internal.editor.ModelElementEditorInput; import org.fortiss.tooling.kernel.services.IActionService; import org.fortiss.tooling.kernel.services.IContextMenuService; import org.fortiss.tooling.kernel.services.IEditorService; @@ -79,6 +88,18 @@ public final class NavigatorViewPart extends ViewPart implements /** Stores the menu manager. */ private MenuManager menuManager; + /** Stores the part listener for editor link support. */ + private IPartListener2 partListener; + + /** Stores the toggle action flag for editor linkage. */ + private boolean isLinkedWithEditor = false; + + /** Stores the toggle action for editor linkage. */ + private Action linkWithEditorAction = null; + + /** Dialog setting ID for the link with editor action flag. */ + private static final String LINK_WITH_EDITOR_FLAG = "navigatorSettingLinkWithEditor"; + /** Stores the UI update job. */ private final UIJob updateUI = new UIJob("Update Model Navigator") { @Override @@ -121,15 +142,60 @@ public final class NavigatorViewPart extends ViewPart implements viewer.addDoubleClickListener(this); IActionService.INSTANCE.registerGlobalActions(getViewSite()); + createLinkWithEditorAction(); PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getSelectionService().addSelectionListener(this); - // FIXME (FH): whats that good for? - // if (viewer.getTree().getItems().length > 0) { - // setActiveECPProject(viewer.getTree().getItem(0).getData()); - // viewer.getTree().select(viewer.getTree().getItem(0)); - // } + getSite().getPage().addPartListener(partListener); + } + + /** Creates the part listener and the view action. */ + private void createLinkWithEditorAction() { + partListener = new LinkWithEditorPartListener(); + + isLinkedWithEditor = ToolingKernelActivator.getDefault() + .getDialogSettings().getBoolean(LINK_WITH_EDITOR_FLAG); + if (isLinkedWithEditor) { + getSite().getPage().addPartListener(partListener); + } + + linkWithEditorAction = new Action("Link with editor", SWT.TOGGLE) { + + @Override + public void run() { + if (isLinkedWithEditor) { + isLinkedWithEditor = false; + getSite().getPage().removePartListener(partListener); + } else { + isLinkedWithEditor = true; + getSite().getPage().addPartListener(partListener); + IEditorPart editor = getSite().getPage().getActiveEditor(); + if (editor instanceof BindingEditor + && editor.getEditorInput() instanceof ModelElementEditorInput) { + revealModelElement(((ModelElementEditorInput) editor + .getEditorInput()).getModelElement()); + } + } + + ToolingKernelActivator.getDefault().getDialogSettings() + .put(LINK_WITH_EDITOR_FLAG, this.isChecked()); + } + + }; + + linkWithEditorAction.setImageDescriptor(ToolingKernelActivator + .getImageDescriptor("icons/link_with_editor.gif")); + linkWithEditorAction.setToolTipText("Link with editor"); + linkWithEditorAction.setChecked(ToolingKernelActivator.getDefault() + .getDialogSettings().getBoolean(LINK_WITH_EDITOR_FLAG)); + + IToolBarManager toolBarManager = getViewSite().getActionBars() + .getToolBarManager(); + Separator additionsSeperator = new Separator("additions"); + additionsSeperator.setVisible(true); + toolBarManager.add(additionsSeperator); + toolBarManager.insertAfter("additions", linkWithEditorAction); } /** Creates the context menu. */ @@ -143,14 +209,23 @@ public final class NavigatorViewPart extends ViewPart implements getSite().registerContextMenu(menuManager, viewer); } - /** Creates the actions. */ - /** {@inheritDoc} */ @Override public void setFocus() { viewer.getControl().setFocus(); } + /** Reveals the given model element in the navigator view. */ + public void revealModelElement(EObject modelElement) { + if (modelElement == null) { + return; + } + if (!viewer.getExpandedState(modelElement)) { + viewer.expandToLevel(modelElement, 2); + } + viewer.setSelection(new StructuredSelection(modelElement), true); + } + /** {@inheritDoc} */ @Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { @@ -174,6 +249,8 @@ public final class NavigatorViewPart extends ViewPart implements .getSelectionService().removeSelectionListener(this); getSite().setSelectionProvider(null); + getSite().getPage().removePartListener(partListener); + super.dispose(); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/views/LibraryView.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/views/LibraryView.java index d9ccff36d4d32c928309dea1887eab819be2d183..a1900d27399de6e4e1627a61a37a69db21912b5a 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/views/LibraryView.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/views/LibraryView.java @@ -17,6 +17,10 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.internal.views; +import java.util.Set; + +import org.conqat.lib.commons.collections.IdentityHashSet; +import org.eclipse.emf.ecore.EObject; import org.eclipse.gef.dnd.TemplateTransfer; import org.eclipse.jface.util.LocalSelectionTransfer; import org.eclipse.jface.viewers.ITreeContentProvider; @@ -27,25 +31,57 @@ import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IPartListener; +import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.dialogs.FilteredTree; import org.eclipse.ui.dialogs.PatternFilter; import org.eclipse.ui.part.ViewPart; +import org.fortiss.tooling.kernel.base.EditorBase; +import org.fortiss.tooling.kernel.interfaces.IBindingEditorPageChangeListener; +import org.fortiss.tooling.kernel.interfaces.IHandler; +import org.fortiss.tooling.kernel.internal.editor.BindingEditor; +import org.fortiss.tooling.kernel.services.IModelElementService; import org.fortiss.tooling.kernel.services.IPrototypeService; import org.fortiss.tooling.kernel.services.IPrototypeService.Prototype; /** + * {@link ViewPart} for the model element library view. * - * @author Eder + * @author eder * @author $Author: hoelzl $ * @version $Rev: 18709 $ * @ConQAT.Rating RED Hash: A43DAF31B100FF92B123EA6A31C86CBA */ public class LibraryView extends ViewPart { - TreeViewer viewer; + /** The viewer. */ + private TreeViewer viewer; + + /** Filter text field for the tree viewer. */ + private FilteredTree filteredTree; + + /** Current active {@link BindingEditor}. */ + private BindingEditor activeBindingEditor = null; + + /** Stores the editor activation listener. */ + private EditorActivationListener editorActivationListener = new EditorActivationListener(); - FilteredTree filteredTree; + /** The container object used. */ + private EObject containerObject = null; + + /** The prototypes supported by the current editor. */ + private Set<Prototype> supportedBaseClasses = new IdentityHashSet<Prototype>(); + + /** Listener for reacting to changes of the embedded editor. */ + private final IBindingEditorPageChangeListener bindingEditorPageChangeListener = new IBindingEditorPageChangeListener() { + @Override + public void pageChanged() { + updateEditorFilters(activeBindingEditor.getActiveEditorPart()); + } + }; /** {@inheritDoc} */ @Override @@ -57,46 +93,9 @@ public class LibraryView extends ViewPart { | SWT.V_SCROLL, patternFilter, false); viewer = filteredTree.getViewer(); - viewer.setContentProvider(new ITreeContentProvider() { - - @Override - public Object[] getChildren(Object parentElement) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Object getParent(Object element) { - return null; - } - - @Override - public boolean hasChildren(Object element) { - return false; - } - - @Override - public Object[] getElements(Object inputElement) { - if (inputElement instanceof Object[]) { - return (Object[]) inputElement; - } - return new Object[0]; - } - - @Override - public void dispose() { - // TODO Auto-generated method stub - - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, - Object newInput) { - // TODO Auto-generated method stub - - } - }); + viewer.setContentProvider(new LibraryTreeContentProvider()); viewer.setLabelProvider(new LibraryLabelProvider()); + viewer.addDragSupport(DND.DROP_COPY, new Transfer[] { TemplateTransfer.getInstance(), LocalSelectionTransfer.getTransfer() }, @@ -104,22 +103,47 @@ public class LibraryView extends ViewPart { viewer.setInput(IPrototypeService.INSTANCE.getAllPrototypes().toArray()); - viewer.addFilter(new ViewerFilter() { + viewer.addFilter(new LibraryViewerFilter()); - @Override - public boolean select(Viewer viewer, Object parentElement, - Object element) { + getViewSite().setSelectionProvider(viewer); + getSite().getWorkbenchWindow().getPartService() + .addPartListener(editorActivationListener); + } - /* - * if (element instanceof Prototype) { EObject prototypeObject = - * ((Prototype) element).getPrototype(); return true; } - */ - return true; - } + /** Switches to the given workbench editor part. */ + private void switchWorkbenchEditor(IEditorPart editor) { + if (activeBindingEditor != null) { + activeBindingEditor + .removeBindingEditorListener(bindingEditorPageChangeListener); + activeBindingEditor = null; + } - }); + if (editor instanceof BindingEditor) { + activeBindingEditor = (BindingEditor) editor; + activeBindingEditor + .addBindingEditorListener(bindingEditorPageChangeListener); + updateEditorFilters(activeBindingEditor.getActiveEditorPart()); + } else if (editor != null) { + updateEditorFilters(editor); + } + } - getViewSite().setSelectionProvider(viewer); + /** Updates the filters according to the given editor. */ + @SuppressWarnings("unchecked") + private void updateEditorFilters(IEditorPart editor) { + supportedBaseClasses.clear(); + if (editor instanceof EditorBase) { + EditorBase<? extends EObject> editorBase = (EditorBase<? extends EObject>) editor; + containerObject = editorBase.getEditedObject(); + for (Class<? extends EObject> clazz : editorBase + .getVisibleEObjectTypes()) { + supportedBaseClasses.addAll(IPrototypeService.INSTANCE + .getComposablePrototypes(clazz)); + } + } else { + containerObject = null; + } + viewer.refresh(); } /** {@inheritDoc} */ @@ -128,7 +152,7 @@ public class LibraryView extends ViewPart { viewer.getControl().setFocus(); } - /** The label provider used here-in. */ + /** The label provider used in the library view. */ private class LibraryLabelProvider extends LabelProvider { /** {@inheritDoc} */ @@ -142,13 +166,119 @@ public class LibraryView extends ViewPart { } - // TODO (JE): getImage - /* - * @Override public Image getImage(Object element) { if (element - * instanceof Prototype) { Prototype prototype = (Prototype) element; - * return ModelElementService.getInstance().getImage( - * prototype.getPrototypeObject()); } return super.getImage(element); } + /** {@inheritDoc} */ + @Override + public Image getImage(Object element) { + if (element instanceof Prototype) { + Prototype prototype = (Prototype) element; + // delegate to the model element handlers + if (element instanceof EObject) { + IHandler<EObject> handler = IModelElementService.INSTANCE + .getModelElementHandler(prototype.getPrototype()); + if (handler != null) { + return handler.getIcon(); + } + } + } + return super.getImage(element); + } + } + + /** The content provider used in the library view. */ + private class LibraryTreeContentProvider implements ITreeContentProvider { + + /** {@inheritDoc} */ + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof Object[]) { + return (Object[]) inputElement; + } + return new Object[0]; + } + + /** {@inheritDoc} */ + @Override + public void dispose() { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public Object[] getChildren(Object parentElement) { + return null; + } + + /** {@inheritDoc} */ + @Override + public Object getParent(Object element) { + return null; + } + + /** {@inheritDoc} */ + @Override + public boolean hasChildren(Object element) { + return false; + } + } + + /** The filter used in the library view. */ + private class LibraryViewerFilter extends ViewerFilter { + + /** {@inheritDoc} */ + @Override + public boolean select(Viewer viewer, Object parentElement, + Object element) { + if (containerObject == null || supportedBaseClasses.isEmpty()) { + return false; + } + return supportedBaseClasses.contains(element); + } + } + + /** If an editor in a different Project is opened the Model is reinitialized */ + private class EditorActivationListener implements IPartListener { + + /** + * Change the tree viewer content whenever workbench part changes. */ + @Override + public void partActivated(IWorkbenchPart workbenchPart) { + if (!(workbenchPart instanceof IEditorPart)) { + return; + } + + IEditorPart part = (IEditorPart) workbenchPart; + switchWorkbenchEditor(part); + } + + /** {@inheritDoc} */ + @Override + public void partBroughtToTop(IWorkbenchPart part) { + // to react on activated is enough + } + + /** {@inheritDoc} */ + @Override + public void partClosed(IWorkbenchPart part) { + // nothing to do + } + + /** {@inheritDoc} */ + @Override + public void partDeactivated(IWorkbenchPart part) { + // nothing to do + } + /** {@inheritDoc} */ + @Override + public void partOpened(IWorkbenchPart part) { + // nothing to do + } } } 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 8bddb993d24f01f03eae83bc04ea5b9c160dbeda..394690e5afa73d3d565a96f76bbbd9a86b2e8ff4 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 @@ -19,7 +19,9 @@ package org.fortiss.tooling.kernel.services; import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.kernel.interfaces.ICompositionContext; +import org.fortiss.tooling.kernel.interfaces.ICompositor; import org.fortiss.tooling.kernel.internal.CompositorService; +import org.fortiss.tooling.kernel.services.IPrototypeService.Prototype; /** * The compositor service provides registration and access to model element @@ -48,4 +50,14 @@ public interface ICompositorService { */ boolean compose(EObject container, EObject element, ICompositionContext context); + + /** + * Returns whether given prototype can be composed with containers of the + * given class. This method searches for an {@link ICompositor} that is able + * to handle the composition in general. + * + * @see ICompositor#canComposePrototype(org.fortiss.tooling.kernel.services.IPrototypeService.Prototype) + */ + boolean canComposePrototype(Class<? extends EObject> containerClass, + Prototype prototype); } diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/INavigatorService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/INavigatorService.java index 0b001a5a86c6a2766e0692bcaad5b5d2988cd190..1fa2b9edc7ea97035d3dd30e3a36932b7a1e6628 100644 --- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/INavigatorService.java +++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/services/INavigatorService.java @@ -17,6 +17,7 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.services; +import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.Saveable; import org.eclipse.ui.part.ViewPart; @@ -52,4 +53,7 @@ public interface INavigatorService { /** Returns the saveables of the current selection. */ Saveable[] getActiveSaveables(); + + /** Reveals the given model element. */ + void revealModelElement(EObject modelElement); } 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 2f9b421d758791735cc12db9ba59b36f3d3a50e0..3395969174fb8cb7cd7f917300bdafd3cc004124 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,8 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.services; +import java.util.List; + import org.conqat.lib.commons.collections.UnmodifiableList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; @@ -43,6 +45,13 @@ public interface IPrototypeService { /** Returns the list of all prototypes registered any provider. */ UnmodifiableList<Prototype> getAllPrototypes(); + /** + * Returns the list of all prototypes composable with the given model + * element class. + */ + List<Prototype> getComposablePrototypes( + Class<? extends EObject> modelElementType); + /** * Prototypes consist of a generic description and pre-configured * {@link EObject}.