diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramEditorBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramEditorBase.java index 76d51e455b47c5c682c7c1db006b85e23ce4956f..e80bddeef6fb8df27d9005d8c85e52b9be3455bc 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramEditorBase.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramEditorBase.java @@ -27,6 +27,7 @@ import static org.eclipse.gef.editparts.ZoomManager.FIT_WIDTH; import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_ORIGIN_X; import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_ORIGIN_Y; import static org.fortiss.tooling.base.layout.DefaultLayoutConstants.DEFAULT_GRID_SIZE; +import static org.fortiss.tooling.kernel.ui.util.EObjectSelectionUtils.getEObjectElements; import static org.fortiss.tooling.kernel.ui.util.EObjectSelectionUtils.getFirstElement; import java.util.ArrayList; @@ -176,6 +177,15 @@ public class DiagramEditorBase<T extends EObject> extends GEFEditorBase<T> imple return null; } + /** {@inheritDoc} */ + @Override + public List<EObject> getSelectedModelElementList() { + if(getSite().getSelectionProvider() != null) { + return getEObjectElements(getSite().getSelectionProvider().getSelection()); + } + return null; + } + /** Creates the context menu. */ private void createContextMenu() { MenuManager menuManager = IContextMenuService.INSTANCE.createDefaultContextMenu(this); diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/IContextMenuMultiSelectionContributor.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/IContextMenuMultiSelectionContributor.java new file mode 100644 index 0000000000000000000000000000000000000000..a37666b37852d03a8ad7347a85908e093285e2ae --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/IContextMenuMultiSelectionContributor.java @@ -0,0 +1,43 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| Copyright 2014 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.ui.extension; + +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.action.IContributionItem; +import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider; + +/** + * + * @author Andreiasw1 + * @author $Author: hoelzl $ + * @version $Rev: 18709 $ + * @ConQAT.Rating RED Hash: + */ +public interface IContextMenuMultiSelectionContributor extends IContextMenuContributor { + /** + * Returns the contributed items, i.e., actions or menus in the context of + * the given provider and the given selected model element. The selection + * may be null, but is always equal to + * {@link ContextMenuContextProvider#getSelectedModelElement()}. + */ + + List<IContributionItem> getContributedItems(List<EObject> selection, + ContextMenuContextProvider contextProvider); +} diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/MultiEObjectActionBase.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/MultiEObjectActionBase.java new file mode 100644 index 0000000000000000000000000000000000000000..1cc25cd3e0f03b47f0b94d8be5f12fa1b7446fe5 --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/MultiEObjectActionBase.java @@ -0,0 +1,94 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| Copyright 2014 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.ui.extension.base; + +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.resource.ImageDescriptor; + +/** + * support for multi object selection + * + * @author Andreiasw1 + * @author $Author: hoelzl $ + * @version $Rev: 18709 $ + * @ConQAT.Rating RED Hash: + */ +public abstract class MultiEObjectActionBase<T extends List<? extends EObject>> extends Action { + + /** Stores the target element. */ + private T target; + + /** Constructor. */ + public MultiEObjectActionBase(String text, ImageDescriptor image) { + super(text, image); + } + + /** Constructor. */ + public MultiEObjectActionBase(T target, String text, ImageDescriptor image) { + this(text, image); + refresh(target); + } + + /** Constructor. */ + public MultiEObjectActionBase(T target, String text) { + this(target, text, null); + } + + /** Sets the target object. */ + public void setTarget(T target) { + this.target = target; + } + + /** Returns the current target. */ + public T getTarget() { + return target; + } + + /** Refreshes the enabled state for the current action target. */ + public final void refresh() { + if(getTarget() == null || getTarget().isEmpty()) { + setEnabled(false); + return; + } + setEnabled(computeEnabled()); + } + + /** + * Refreshes the action's target and enabled state. + * + * @see #setTarget(List) + * @see #refresh() + */ + public final void refresh(T element) { + setTarget(element); + refresh(); + } + + /** + * Computes the enabled state of the action for the current target, which is + * not <code>null</code> when this method is called. The default + * implementation returns <code>true</code>. + */ + protected boolean computeEnabled() { + return true; + } + +} diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/data/ContextMenuContextProvider.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/data/ContextMenuContextProvider.java index 860ac01b2a0d6306766dbb5c296d0c0961c40690..32b915b03ef2dfef13c45db6f39082f42c75c340 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/data/ContextMenuContextProvider.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/data/ContextMenuContextProvider.java @@ -17,6 +17,8 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.ui.extension.data; +import java.util.List; + import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor; import org.fortiss.tooling.kernel.ui.internal.ContextMenuService; @@ -42,4 +44,9 @@ public interface ContextMenuContextProvider { * creation or update. */ EObject getSelectedModelElement(); + + /** + * Returns a list containing the selected Eobjects + */ + List<EObject> getSelectedModelElementList(); } diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ContextMenuService.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ContextMenuService.java index f106ed5c44ca9b58eb878d1fb09ccc87f28cdf08..9249f3dba83909b91da8d1f8b7b3fc43d3f327a9 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ContextMenuService.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/ContextMenuService.java @@ -30,6 +30,7 @@ import org.eclipse.jface.action.Separator; import org.eclipse.ui.IWorkbenchActionConstants; import org.fortiss.tooling.kernel.ToolingKernelActivator; import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor; +import org.fortiss.tooling.kernel.ui.extension.IContextMenuMultiSelectionContributor; import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider; import org.fortiss.tooling.kernel.ui.service.IActionService; import org.fortiss.tooling.kernel.ui.service.IContextMenuService; @@ -85,9 +86,11 @@ public class ContextMenuService implements IContextMenuService { Class<?> handlerClass = ExtensionPointUtils.loadClass( ce.getAttribute(HANDLER_CLASS_ATTRIBUTE_NAME), bundle); + IContextMenuContributor provider = (IContextMenuContributor)handlerClass.getConstructor().newInstance(); providerList.add(provider); + } catch(Exception ex) { LoggingUtils.error(ToolingKernelActivator.getDefault(), ex.getMessage(), ex); } @@ -127,18 +130,44 @@ public class ContextMenuService implements IContextMenuService { /** Adds registered contributions to the given menu. */ private void addContributions(IMenuManager menu, ContextMenuContextProvider contextProvider) { - EObject selection = contextProvider.getSelectedModelElement(); - for(IContextMenuContributor contributor : providerList) { - String menuSectionID = contributor.getMenuSectionID(); - if(menuSectionID == null) { - menuSectionID = IWorkbenchActionConstants.MB_ADDITIONS; - } - List<IContributionItem> l = contributor.getContributedItems(selection, contextProvider); - if(l == null) { - continue; + + List<EObject> selection = contextProvider.getSelectedModelElementList(); + if(selection == null) { + // do nothing + } else if(selection.size() == 1) { + EObject selectionElem = contextProvider.getSelectedModelElement(); + for(IContextMenuContributor contributor : providerList) { + String menuSectionID = contributor.getMenuSectionID(); + if(menuSectionID == null) { + menuSectionID = IWorkbenchActionConstants.MB_ADDITIONS; + } + List<IContributionItem> l = + contributor.getContributedItems(selectionElem, contextProvider); + if(l == null) { + continue; + } + for(IContributionItem item : l) { + menu.appendToGroup(menuSectionID, item); + } } - for(IContributionItem item : l) { - menu.appendToGroup(menuSectionID, item); + } else if(selection.size() > 1) { + for(IContextMenuContributor contributor : providerList) { + if(contributor instanceof IContextMenuMultiSelectionContributor) { + IContextMenuMultiSelectionContributor multicontributor = + (IContextMenuMultiSelectionContributor)contributor; + String menuSectionID = contributor.getMenuSectionID(); + if(menuSectionID == null) { + menuSectionID = IWorkbenchActionConstants.MB_ADDITIONS; + } + List<IContributionItem> l = + multicontributor.getContributedItems(selection, contextProvider); + if(l == null) { + continue; + } + for(IContributionItem item : l) { + menu.appendToGroup(menuSectionID, item); + } + } } } } diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java index 048c1e6e43d75b7ed9986185c03a2e15f9886ae3..573127b2d327e44c6dc241734feb61c63305d8e3 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/editor/ExtendableMultiPageEditor.java @@ -256,7 +256,13 @@ public class ExtendableMultiPageEditor extends MultiPageEditorPart implements /** {@inheritDoc} */ @Override public void commandStackChanged(EventObject event) { - firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY); + getEditorSite().getWorkbenchWindow().getShell().getDisplay().syncExec(new Runnable() { + /** {@inheritDoc} */ + @Override + public void run() { + firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY); + } + }); } /** diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java index e3c45f0ebf629087ebb204bc0300678a11f9a698..6db6fb9bd7d91ba34e9f3a4ddab45422e24237c9 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorViewPart.java @@ -17,6 +17,8 @@ $Id$ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.kernel.ui.internal.views; +import java.util.List; + import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -346,6 +348,13 @@ public final class NavigatorViewPart extends ViewPart implements ISelectionListe .getSelection()); } + /** {@inheritDoc} */ + @Override + public List<EObject> getSelectedModelElementList() { + return EObjectSelectionUtils.getEObjectElements(getSite().getSelectionProvider() + .getSelection()); + } + /** Returns whether expert view is active. */ public boolean isExpertViewActive() { return ((NavigatorTreeContentProvider)viewer.getContentProvider()).isExpertViewActive(); diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/EObjectSelectionUtils.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/EObjectSelectionUtils.java index 08887dd585ae559e794dceefb70f36d0635296ac..2895aa2b881af9d3eb72868037aab0017bfe2697 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/EObjectSelectionUtils.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/EObjectSelectionUtils.java @@ -118,11 +118,16 @@ public final class EObjectSelectionUtils { */ public static List<EObject> getEObjectElements(ISelection selection) { List<EObject> result = new ArrayList<EObject>(); - if(selection instanceof StructuredSelection) { + if(selection instanceof StructuredSelection && !selection.isEmpty()) { for(Object o : ((StructuredSelection)selection).toList()) { EObject eo = EObjectOfObject(o); if(eo != null) { result.add(eo); + } else if(o instanceof IAdaptable) { + EObject eo2 = (EObject)((IAdaptable)o).getAdapter(EObject.class); + if(eo2 != null) { + result.add(eo2); + } } } }