package org.eclipse.uml2.diagram.profile.edit.parts;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.ScalablePolygonShape;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ConstrainedToolbarLayoutEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.swt.graphics.Color;
import org.eclipse.uml2.diagram.common.async.AsyncDiagramComponentEditPolicy;
import org.eclipse.uml2.diagram.common.editparts.PrimaryShapeEditPart;
import org.eclipse.uml2.diagram.common.editpolicies.CreationEditPolicyWithCustomReparent;
import org.eclipse.uml2.diagram.common.editpolicies.DoNothingEditPolicy;
import org.eclipse.uml2.diagram.common.editpolicies.UnmovableUnselectableShapeEditPolicy;
import org.eclipse.uml2.diagram.profile.edit.policies.Profile3ItemSemanticEditPolicy;
import org.eclipse.uml2.diagram.profile.edit.policies.UMLTextSelectionEditPolicy;
import org.eclipse.uml2.diagram.profile.part.UMLVisualIDRegistry;
import org.eclipse.uml2.diagram.profile.providers.UMLElementTypes;
/**
* @generated
*/
public class Profile3EditPart extends ShapeNodeEditPart implements PrimaryShapeEditPart {
/**
* @generated
*/
public static final int VISUAL_ID = 2007;
/**
* @generated
*/
protected IFigure contentPane;
/**
* @generated
*/
protected IFigure primaryShape;
/**
* @generated
*/
public Profile3EditPart(View view) {
super(view);
}
/**
* @generated
*/
protected void createDefaultEditPolicies() {
installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicyWithCustomReparent(UMLVisualIDRegistry.TYPED_ADAPTER));
super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Profile3ItemSemanticEditPolicy());
installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
installEditPolicy(EditPolicy.COMPONENT_ROLE, new AsyncDiagramComponentEditPolicy());
installEditPolicy("ConnectionHandlesPolicy", new DoNothingEditPolicy()); //$NON-NLS-1$
// XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies
// removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE);
}
/**
* @generated
*/
protected LayoutEditPolicy createLayoutEditPolicy() {
ConstrainedToolbarLayoutEditPolicy lep = new ConstrainedToolbarLayoutEditPolicy() {
protected EditPolicy createChildEditPolicy(EditPart child) {
if (child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE) == null) {
if (child instanceof ITextAwareEditPart) {
return new UMLTextSelectionEditPolicy();
}
}
return super.createChildEditPolicy(child);
}
};
return lep;
}
/**
* @generated
*/
protected IFigure createNodeShape() {
return primaryShape = new SecondaryProfileFigure();
}
/**
* @generated
*/
public SecondaryProfileFigure getPrimaryShape() {
return (SecondaryProfileFigure) primaryShape;
}
/**
* @generated
*/
protected boolean addFixedChild(EditPart childEditPart) {
if (childEditPart instanceof ProfileName2EditPart) {
((ProfileName2EditPart) childEditPart).setLabel(getPrimaryShape().getFigureSecondaryProfile_NameLabel());
return true;
}
if (childEditPart instanceof ProfileProfileLabelsEditPart) {
IFigure pane = getPrimaryShape().getFigureSecondaryProfile_Imports();
setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
pane.add(((ProfileProfileLabelsEditPart) childEditPart).getFigure());
return true;
}
return false;
}
/**
* @generated
*/
protected boolean removeFixedChild(EditPart childEditPart) {
if (childEditPart instanceof ProfileProfileLabelsEditPart) {
IFigure pane = getPrimaryShape().getFigureSecondaryProfile_Imports();
pane.remove(((ProfileProfileLabelsEditPart) childEditPart).getFigure());
return true;
}
return false;
}
/**
* @generated
*/
protected void addChildVisual(EditPart childEditPart, int index) {
if (addFixedChild(childEditPart)) {
return;
}
super.addChildVisual(childEditPart, -1);
}
/**
* @generated
*/
protected void removeChildVisual(EditPart childEditPart) {
if (removeFixedChild(childEditPart)) {
return;
}
super.removeChildVisual(childEditPart);
}
/**
* @generated
*/
protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
if (editPart instanceof ProfileProfileLabelsEditPart) {
return getPrimaryShape().getFigureSecondaryProfile_Imports();
}
return getContentPane();
}
/**
* @generated
*/
protected NodeFigure createNodePlate() {
DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(100, 60);
return result;
}
/**
* @generated
*/
public EditPolicy getPrimaryDragEditPolicy() {
return new UnmovableUnselectableShapeEditPolicy();
}
/**
* Creates figure for this edit part.
*
* Body of this method does not depend on settings in generation model
* so you may safely remove <i>generated</i> tag and modify it.
*
* @generated
*/
protected NodeFigure createNodeFigure() {
NodeFigure figure = createNodePlate();
figure.setLayoutManager(new StackLayout());
IFigure shape = createNodeShape();
figure.add(shape);
contentPane = setupContentPane(shape);
return figure;
}
/**
* Default implementation treats passed figure as content pane.
* Respects layout one may have set for generated figure.
* @param nodeShape instance of generated figure class
* @generated
*/
protected IFigure setupContentPane(IFigure nodeShape) {
if (nodeShape.getLayoutManager() == null) {
ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
layout.setSpacing(5);
nodeShape.setLayoutManager(layout);
}
return nodeShape; // use nodeShape itself as contentPane
}
/**
* @generated
*/
public IFigure getContentPane() {
if (contentPane != null) {
return contentPane;
}
return super.getContentPane();
}
/**
* @generated
*/
protected void setForegroundColor(Color color) {
if (primaryShape != null) {
primaryShape.setForegroundColor(color);
}
}
/**
* @generated
*/
protected void setBackgroundColor(Color color) {
if (primaryShape != null) {
primaryShape.setBackgroundColor(color);
}
}
/**
* @generated
*/
protected void setLineWidth(int width) {
if (primaryShape instanceof Shape) {
((Shape) primaryShape).setLineWidth(width);
}
}
/**
* @generated
*/
protected void setLineType(int style) {
if (primaryShape instanceof Shape) {
((Shape) primaryShape).setLineStyle(style);
}
}
/**
* @generated
*/
public EditPart getPrimaryChildEditPart() {
return getChildBySemanticHint(UMLVisualIDRegistry.getType(ProfileName2EditPart.VISUAL_ID));
}
/**
* @generated
*/
public List<IElementType> getMARelTypesOnTarget() {
ArrayList<IElementType> types = new ArrayList<IElementType>(2);
types.add(UMLElementTypes.ConstraintConstrainedElement_4003);
types.add(UMLElementTypes.CommentAnnotatedElement_4004);
return types;
}
/**
* @generated
*/
public List<IElementType> getMATypesForSource(IElementType relationshipType) {
LinkedList<IElementType> types = new LinkedList<IElementType>();
if (relationshipType == UMLElementTypes.ConstraintConstrainedElement_4003) {
types.add(UMLElementTypes.Constraint_2008);
} else if (relationshipType == UMLElementTypes.CommentAnnotatedElement_4004) {
types.add(UMLElementTypes.Comment_2009);
}
return types;
}
/**
* @generated
*/
public EditPart getTargetEditPart(Request request) {
if (request instanceof CreateViewAndElementRequest) {
CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter();
IElementType type = (IElementType) adapter.getAdapter(IElementType.class);
if (type == UMLElementTypes.ElementImport_3009) {
return getChildBySemanticHint(UMLVisualIDRegistry.getType(ProfileProfileLabelsEditPart.VISUAL_ID));
}
}
return super.getTargetEditPart(request);
}
/**
* @generated
*/
protected void handleNotificationEvent(Notification event) {
if (event.getNotifier() == getModel() && EcorePackage.eINSTANCE.getEModelElement_EAnnotations().equals(event.getFeature())) {
handleMajorSemanticChange();
} else {
super.handleNotificationEvent(event);
}
}
/**
* @generated
*/
public class SecondaryProfileFigure extends ScalablePolygonShape {
/**
* @generated
*/
private Label fFigureSecondaryProfile_ProfileLabel;
/**
* @generated
*/
private Label fFigureSecondaryProfile_NameLabel;
/**
* @generated
*/
private RectangleFigure fFigureSecondaryProfile_Imports;
/**
* @generated
*/
public SecondaryProfileFigure() {
ToolbarLayout layoutThis = new ToolbarLayout();
layoutThis.setStretchMinorAxis(true);
layoutThis.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
layoutThis.setSpacing(0);
layoutThis.setVertical(true);
this.setLayoutManager(layoutThis);
this.addPoint(new Point(getMapMode().DPtoLP(0), getMapMode().DPtoLP(0)));
this.addPoint(new Point(getMapMode().DPtoLP(0), getMapMode().DPtoLP(40)));
this.addPoint(new Point(getMapMode().DPtoLP(35), getMapMode().DPtoLP(40)));
this.addPoint(new Point(getMapMode().DPtoLP(40), getMapMode().DPtoLP(35)));
this.addPoint(new Point(getMapMode().DPtoLP(40), getMapMode().DPtoLP(0)));
this.setFill(true);
this.setLineWidth(1);
this.setBorder(new MarginBorder(getMapMode().DPtoLP(5), getMapMode().DPtoLP(5), getMapMode().DPtoLP(13), getMapMode().DPtoLP(10)));
createContents();
}
/**
* @generated
*/
private void createContents() {
fFigureSecondaryProfile_ProfileLabel = new Label();
fFigureSecondaryProfile_ProfileLabel.setText("\u00ABprofile\u00BB");
this.add(fFigureSecondaryProfile_ProfileLabel);
fFigureSecondaryProfile_NameLabel = new Label();
fFigureSecondaryProfile_NameLabel.setText("");
this.add(fFigureSecondaryProfile_NameLabel);
fFigureSecondaryProfile_Imports = new RectangleFigure();
fFigureSecondaryProfile_Imports.setOutline(false);
fFigureSecondaryProfile_Imports.setLineWidth(1);
this.add(fFigureSecondaryProfile_Imports);
}
/**
* @generated
*/
public Label getFigureSecondaryProfile_ProfileLabel() {
return fFigureSecondaryProfile_ProfileLabel;
}
/**
* @generated
*/
public Label getFigureSecondaryProfile_NameLabel() {
return fFigureSecondaryProfile_NameLabel;
}
/**
* @generated
*/
public RectangleFigure getFigureSecondaryProfile_Imports() {
return fFigureSecondaryProfile_Imports;
}
}
}