Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » ModelingAssistant Popup for ShapeCompartments
ModelingAssistant Popup for ShapeCompartments [message #988197] Wed, 28 November 2012 18:28 Go to next message
Daniel König is currently offline Daniel KönigFriend
Messages: 24
Registered: November 2012
Junior Member
Hello!

I had to change my compartments to ShapeCompartments (ListLayout = false).
Since I changed this I do not get the ModelingAssistant Popup anymore.

The EditPolicy should be installed by default:

org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeCompartmentEditPart:
	protected void createDefaultEditPolicies() {
		super.createDefaultEditPolicies();
		installEditPolicy(EditPolicyRoles.CREATION_ROLE,
			new CreationEditPolicy());
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new XYLayoutEditPolicy());
		installEditPolicy(EditPolicy.CONTAINER_ROLE, new ContainerEditPolicy());
		// TODO: this edit policy get overriden by code at the end of this
		// function
		// may be this breaks some use cases; it needs to be checked
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE,
			new DiagramLinkDragDropEditPolicy());
		installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE,
			new ContainerNodeEditPolicy());
		// Install an edit policy for snap
		installEditPolicy(EditPolicyRoles.SNAP_FEEDBACK_ROLE,
			new SnapFeedbackPolicy());
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE,
			new ShapeCompartmentDropEditPolicy());
		installEditPolicy(EditPolicyRoles.POPUPBAR_ROLE,
			new PopupBarEditPolicy());
	}




ComponentStateCompartmentEditPart extends ShapeCompartmentEditPart:
	protected void createDefaultEditPolicies() {
		super.createDefaultEditPolicies();
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ComponentComponentStateCompartmentItemSemanticEditPolicy());
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicyWithCustomReparent(
				MachineVisualIDRegistry.TYPED_INSTANCE));
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new ComponentComponentStateCompartmentCanonicalEditPolicy());
	}


The ModelingAssistantProvider should also be fine:
	public List getTypesForPopupBar(IAdaptable host) {
		IGraphicalEditPart editPart = (IGraphicalEditPart) host.getAdapter(IGraphicalEditPart.class);
		if (editPart instanceof ModelEditPart) {
			ArrayList<IElementType> types = new ArrayList<IElementType>(1);
			types.add(MachineElementTypes.Machine_2001);
			return types;
		}
		if (editPart instanceof MachineEditPart) {
			ArrayList<IElementType> types = new ArrayList<IElementType>(1);
			types.add(MachineElementTypes.Component_3001);
			return types;
		}
		if (editPart instanceof ComponentStateCompartmentEditPart) {
			ArrayList<IElementType> types = new ArrayList<IElementType>(1);
			types.add(MachineElementTypes.State_3002);
			return types;
		}
		if (editPart instanceof StateComponentValueCompartmentEditPart) {
			ArrayList<IElementType> types = new ArrayList<IElementType>(1);
			types.add(MachineElementTypes.StateValue_3004);
			return types;
		}
		return Collections.EMPTY_LIST;
	}



Is there any way I can get the ModelingAssistant back for my ShapeCompartment?
I recognized in the ModelingAssistantProvider that the EditPart for ListCompartments is the Node itself (for example "MachineEditPart"). If it's a ShapeCompartment, the CompartmentEditPart is used ("ComponentStateCompartmentEditPart" resp. "StateComponentValueCompartmentEditPart").

Manually changing to the Node which contains the Compartment did not have any effect.


I hope someone can help me.
Thank you! Smile

[Updated on: Thu, 29 November 2012 13:43]

Report message to a moderator

Re: ModelingAssistant Popup for ShapeCompartments [message #988265 is a reply to message #988197] Thu, 29 November 2012 08:27 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 702
Registered: November 2009
Senior Member
Hi,

I had the following problem too and found a workaround which is not the nicest. At first you need to install your own PopUpBarEditPolicy into the container editpart. An example for such an edit policy can be found here http://code.google.com/a/eclipselabs.org/p/melanie/source/browse/de.uni_mannheim.informatik.swt.models.plm.diagram/custom-src/de/uni_mannheim/informatik/swt/models/plm/diagram/custom/popupbartools/editpolicy/PLMModelElementPopupBarEditPolicy.java . Next I added a tool which selects the entry from the palette and lets you decide where to add the model element http://code.google.com/a/eclipselabs.org/p/melanie/source/browse/de.uni_mannheim.informatik.swt.models.plm.diagram/custom-src/de/uni_mannheim/informatik/swt/models/plm/diagram/custom/popupbartools/InstantiatatePopupBarTool.java. You can install the edit policy by using the following template http://code.google.com/a/eclipselabs.org/p/melanie/source/browse/de.uni_mannheim.informatik.swt.models.gmf/templates/aspects/impl/diagram/editparts/CompartmentEditPart.xpt or http://code.google.com/a/eclipselabs.org/p/melanie/source/browse/de.uni_mannheim.informatik.swt.models.gmf/templates/aspects/impl/diagram/editparts/NodeEditPart.xpt .Information on how to work with templates is found here http://www.bonitasoft.org/blog/eclipse/customize-your-gmf-editor-by-customizing-templates/ .

Ralph
Re: ModelingAssistant Popup for ShapeCompartments [message #988347 is a reply to message #988265] Thu, 29 November 2012 14:11 Go to previous messageGo to next message
Daniel König is currently offline Daniel KönigFriend
Messages: 24
Registered: November 2012
Junior Member
I'll try your solution.

Thank you very much!
I'm quite new to GMF and some Use-Cases are very special Wink
Re: ModelingAssistant Popup for ShapeCompartments [message #989089 is a reply to message #988197] Tue, 04 December 2012 15:20 Go to previous messageGo to next message
Daniel König is currently offline Daniel KönigFriend
Messages: 24
Registered: November 2012
Junior Member
It worked Smile
Here is a very simple solution to add a modeling assistant to your ShapeCompartment.

MachinePopupBarEditPolicy = zyxPopupBarEditPolicy:
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.PopupBarEditPolicy;

public class MachinePopupBarEditPolicy extends PopupBarEditPolicy {
	
	@Override
	protected void fillPopupBarDescriptors() {
		super.fillPopupBarDescriptors();
		EObject hostElement = ((IGraphicalEditPart) getHost()).resolveSemanticElement();
		
		// Component -> State
		if (hostElement instanceof Component) {
			addPopupBarDescriptor(new MachinePopupBarTool(this, MachineElementTypes.State_3002, Messages.Zustand2CreationTool_title));			
		} 
		// State -> StateValue
		else if (hostElement instanceof State) {
			addPopupBarDescriptor(new MachinePopupBarTool(this, MachineElementTypes.StateValue_3004, Messages.Zustandswert3CreationTool_title));
		}
	}
	
	public void addPopupBarDescriptor(MachinePopupBarTool tool) {
		super.addPopupBarDescriptor(null, tool.getImage(), tool, tool.getDescription());
	}
	
	@Override
	protected boolean shouldShowDiagramAssistant() {
		return true;
	}
}


MachinePopupBarTool = xyzPopupBarTool:
import org.eclipse.gmf.runtime.diagram.ui.tools.PopupBarTool;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;

public class MachinePopupBarTool extends PopupBarTool {

	private Image image;
	private String description;
	
	public MachinePopupBarTool(MachinePopupBarEditPolicy policy, IElementType elementType, String description) {
		super(policy.getHost(), elementType);
		
		ImageDescriptor imageDescriptor = MachineElementTypes.getImageDescriptor(elementType);
		this.image = imageDescriptor.createImage();
		this.description = description;
	}
	
	public Image getImage() {
		return image;
	}
	
	public String getDescription() {
		return description;
	}
}



The images are all taken from the standard folder for your creation tools (which are in the palette).
You just have to choose the ElementType and a description string.
Re: ModelingAssistant Popup for ShapeCompartments [message #989093 is a reply to message #988197] Tue, 04 December 2012 15:24 Go to previous message
Daniel König is currently offline Daniel KönigFriend
Messages: 24
Registered: November 2012
Junior Member
To install the editpolicy I used the example from Ralph:
http://code.google.com/a/eclipselabs.org/p/melanie/source/browse/de.uni_mannheim.informatik.swt.models.gmf/templates/aspects/impl/diagram/editparts/CompartmentEditPart.xpt
Previous Topic:Editor not created?
Next Topic:Helper functions in OCL constraints
Goto Forum:
  


Current Time: Wed Apr 24 15:56:52 GMT 2024

Powered by FUDForum. Page generated in 0.02872 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top