Skip to content
Snippets Groups Projects
Commit db703c75 authored by Andrei Serban Vlad's avatar Andrei Serban Vlad
Browse files

refs 1882
parent e7840443
No related branches found
No related tags found
No related merge requests found
Showing
with 216 additions and 13 deletions
......@@ -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);
......
/*--------------------------------------------------------------------------+
$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);
}
/*--------------------------------------------------------------------------+
$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;
}
}
......@@ -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();
}
......@@ -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);
}
}
}
}
}
......
......@@ -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);
}
});
}
/**
......
......@@ -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();
......
......@@ -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);
}
}
}
}
......
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