| package org.eclipse.uml2.diagram.component.edit.parts; |
| |
| import org.eclipse.draw2d.BorderLayout; |
| import org.eclipse.draw2d.IFigure; |
| import org.eclipse.draw2d.Label; |
| import org.eclipse.draw2d.LayoutManager; |
| import org.eclipse.draw2d.PositionConstants; |
| import org.eclipse.draw2d.RectangleFigure; |
| import org.eclipse.draw2d.StackLayout; |
| import org.eclipse.draw2d.ToolbarLayout; |
| import org.eclipse.draw2d.geometry.Dimension; |
| import org.eclipse.gef.EditPart; |
| import org.eclipse.gef.EditPolicy; |
| import org.eclipse.gef.GraphicalEditPart; |
| import org.eclipse.gef.Request; |
| import org.eclipse.gef.commands.Command; |
| import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
| import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
| import org.eclipse.gef.requests.CreateRequest; |
| import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart; |
| import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; |
| import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
| import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; |
| import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy; |
| import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; |
| import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
| import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator; |
| import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; |
| 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.uml2.diagram.common.editparts.PrimaryShapeEditPart; |
| import org.eclipse.uml2.diagram.component.edit.policies.ComponentCanonicalEditPolicy; |
| import org.eclipse.uml2.diagram.component.edit.policies.ComponentItemSemanticEditPolicy; |
| import org.eclipse.uml2.diagram.component.part.UMLVisualIDRegistry; |
| |
| /** |
| * @generated |
| */ |
| public class ComponentEditPart extends AbstractBorderedShapeEditPart implements PrimaryShapeEditPart { |
| |
| /** |
| * @generated |
| */ |
| public static final int VISUAL_ID = 2001; |
| |
| /** |
| * @generated |
| */ |
| protected IFigure contentPane; |
| |
| /** |
| * @generated |
| */ |
| protected IFigure primaryShape; |
| |
| /** |
| * @generated |
| */ |
| public ComponentEditPart(View view) { |
| super(view); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected void createDefaultEditPolicies() { |
| installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy()); |
| super.createDefaultEditPolicies(); |
| installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ComponentItemSemanticEditPolicy()); |
| installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy()); |
| installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new ComponentCanonicalEditPolicy()); |
| installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
| // 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() { |
| LayoutEditPolicy lep = new LayoutEditPolicy() { |
| |
| protected EditPolicy createChildEditPolicy(EditPart child) { |
| if (child instanceof IBorderItemEditPart) { |
| return new BorderItemSelectionEditPolicy(); |
| } |
| EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
| if (result == null) { |
| result = new NonResizableEditPolicy(); |
| } |
| return result; |
| } |
| |
| protected Command getMoveChildrenCommand(Request request) { |
| return null; |
| } |
| |
| protected Command getCreateCommand(CreateRequest request) { |
| return null; |
| } |
| }; |
| return lep; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected IFigure createNodeShape() { |
| ComponentFigure figure = new ComponentFigure(); |
| return primaryShape = figure; |
| } |
| |
| /** |
| * @generated |
| */ |
| public ComponentFigure getPrimaryShape() { |
| return (ComponentFigure) primaryShape; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected boolean addFixedChild(EditPart childEditPart) { |
| if (childEditPart instanceof ComponentName2EditPart) { |
| ((ComponentName2EditPart) childEditPart).setLabel(getPrimaryShape().getFigureComponentFigure_name()); |
| return true; |
| } |
| if (childEditPart instanceof ComponentContentsEditPart) { |
| IFigure pane = getPrimaryShape().getFigureComponentFigure_Body(); |
| setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way |
| pane.add(((ComponentContentsEditPart) childEditPart).getFigure()); |
| return true; |
| } |
| if (childEditPart instanceof PortEditPart) { |
| BorderItemLocator locator = new BorderItemLocator(getMainFigure(), PositionConstants.NONE); |
| getBorderedFigure().getBorderItemContainer().add(((PortEditPart) childEditPart).getFigure(), locator); |
| return true; |
| } |
| return false; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected boolean removeFixedChild(EditPart childEditPart) { |
| |
| if (childEditPart instanceof ComponentContentsEditPart) { |
| IFigure pane = getPrimaryShape().getFigureComponentFigure_Body(); |
| pane.remove(((ComponentContentsEditPart) childEditPart).getFigure()); |
| return true; |
| } |
| if (childEditPart instanceof PortEditPart) { |
| getBorderedFigure().getBorderItemContainer().remove(((PortEditPart) 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 ComponentContentsEditPart) { |
| return getPrimaryShape().getFigureComponentFigure_Body(); |
| } |
| if (editPart instanceof PortEditPart) { |
| return getBorderedFigure().getBorderItemContainer(); |
| } |
| return super.getContentPaneFor(editPart); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected NodeFigure createNodePlate() { |
| DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode().DPtoLP(100), getMapMode().DPtoLP(40)); |
| return result; |
| } |
| |
| /** |
| * 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 createMainFigure() { |
| 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(getMapMode().DPtoLP(5)); |
| nodeShape.setLayoutManager(layout); |
| } |
| return nodeShape; // use nodeShape itself as contentPane |
| } |
| |
| /** |
| * @generated |
| */ |
| public IFigure getContentPane() { |
| if (contentPane != null) { |
| return contentPane; |
| } |
| return super.getContentPane(); |
| } |
| |
| /** |
| * @generated |
| */ |
| public EditPart getPrimaryChildEditPart() { |
| return getChildBySemanticHint(UMLVisualIDRegistry.getType(ComponentName2EditPart.VISUAL_ID)); |
| } |
| |
| /** |
| * @generated |
| */ |
| public class ComponentFigure extends RectangleFigure { |
| |
| /** |
| * @generated |
| */ |
| private Label fFigureComponentFigure_name; |
| |
| /** |
| * @generated |
| */ |
| private RectangleFigure fFigureComponentFigure_Body; |
| |
| /** |
| * @generated |
| */ |
| public ComponentFigure() { |
| |
| BorderLayout layoutThis = new BorderLayout(); |
| this.setLayoutManager(layoutThis); |
| |
| this.setFill(false); |
| this.setOutline(false); |
| createContents(); |
| } |
| |
| /** |
| * @generated |
| */ |
| private void createContents() { |
| |
| RectangleFigure componentFigure_LabelsContainer0 = new RectangleFigure(); |
| componentFigure_LabelsContainer0.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), getMapMode().DPtoLP(35))); |
| |
| this.add(componentFigure_LabelsContainer0, BorderLayout.TOP); |
| |
| ToolbarLayout layoutComponentFigure_LabelsContainer0 = new ToolbarLayout(); |
| layoutComponentFigure_LabelsContainer0.setStretchMinorAxis(true); |
| layoutComponentFigure_LabelsContainer0.setMinorAlignment(ToolbarLayout.ALIGN_CENTER); |
| |
| layoutComponentFigure_LabelsContainer0.setSpacing(0); |
| layoutComponentFigure_LabelsContainer0.setVertical(true); |
| |
| componentFigure_LabelsContainer0.setLayoutManager(layoutComponentFigure_LabelsContainer0); |
| |
| Label componentFigure_fixed_component1 = new Label(); |
| componentFigure_fixed_component1.setText("\u00ABcomponent\u00BB"); |
| |
| componentFigure_LabelsContainer0.add(componentFigure_fixed_component1); |
| |
| fFigureComponentFigure_name = new Label(); |
| fFigureComponentFigure_name.setText(""); |
| |
| componentFigure_LabelsContainer0.add(fFigureComponentFigure_name); |
| |
| fFigureComponentFigure_Body = new RectangleFigure(); |
| fFigureComponentFigure_Body.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), getMapMode().DPtoLP(55))); |
| |
| this.add(fFigureComponentFigure_Body, BorderLayout.CENTER); |
| |
| } |
| |
| /** |
| * @generated |
| */ |
| public Label getFigureComponentFigure_name() { |
| return fFigureComponentFigure_name; |
| } |
| |
| /** |
| * @generated |
| */ |
| public RectangleFigure getFigureComponentFigure_Body() { |
| return fFigureComponentFigure_Body; |
| } |
| |
| /** |
| * @generated |
| */ |
| private boolean myUseLocalCoordinates = false; |
| |
| /** |
| * @generated |
| */ |
| protected boolean useLocalCoordinates() { |
| return myUseLocalCoordinates; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
| myUseLocalCoordinates = useLocalCoordinates; |
| } |
| |
| } |
| |
| /** |
| * @generated |
| */ |
| protected void reorderChild(EditPart child, int index) { |
| // Save the constraint of the child so that it does not |
| // get lost during the remove and re-add. |
| IFigure childFigure = ((GraphicalEditPart) child).getFigure(); |
| LayoutManager layout = getContentPaneFor((IGraphicalEditPart) child).getLayoutManager(); |
| Object constraint = null; |
| if (layout != null) { |
| constraint = layout.getConstraint(childFigure); |
| } |
| super.reorderChild(child, index); |
| setLayoutConstraint(child, childFigure, constraint); |
| } |
| |
| } |