ModelingAssistant Popup for ShapeCompartments [message #988197] |
Wed, 28 November 2012 18:28 |
Daniel König 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!
[Updated on: Thu, 29 November 2012 13:43] Report message to a moderator
|
|
|
|
|
Re: ModelingAssistant Popup for ShapeCompartments [message #989089 is a reply to message #988197] |
Tue, 04 December 2012 15:20 |
Daniel König Messages: 24 Registered: November 2012 |
Junior Member |
|
|
It worked
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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02101 seconds