| /******************************************************************************* |
| * Copyright (c) 2006 Borland Software Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Borland Software Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.gmf.examples.mindmap.diagram.edit.parts; |
| |
| import org.eclipse.draw2d.IFigure; |
| import org.eclipse.draw2d.StackLayout; |
| import org.eclipse.gef.EditPart; |
| import org.eclipse.gef.EditPolicy; |
| import org.eclipse.gmf.examples.mindmap.diagram.edit.policies.MindmapTextSelectionEditPolicy; |
| import org.eclipse.gmf.examples.mindmap.diagram.edit.policies.TopicCanonicalEditPolicy; |
| import org.eclipse.gmf.examples.mindmap.diagram.edit.policies.TopicGraphicalNodeEditPolicy; |
| import org.eclipse.gmf.examples.mindmap.diagram.edit.policies.TopicItemSemanticEditPolicy; |
| import org.eclipse.gmf.examples.mindmap.diagram.part.MindmapVisualIDRegistry; |
| 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.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; |
| |
| /** |
| * @generated |
| */ |
| public class TopicEditPart extends ShapeNodeEditPart { |
| |
| /** |
| * @generated |
| */ |
| public static final int VISUAL_ID = 1001; |
| |
| /** |
| * @generated |
| */ |
| protected IFigure contentPane; |
| |
| /** |
| * @generated |
| */ |
| protected IFigure primaryShape; |
| |
| /** |
| * @generated |
| */ |
| public TopicEditPart(View view) { |
| super(view); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected void createDefaultEditPolicies() { |
| super.createDefaultEditPolicies(); |
| installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new TopicItemSemanticEditPolicy()); |
| installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new TopicGraphicalNodeEditPolicy()); |
| installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new TopicCanonicalEditPolicy()); |
| installEditPolicy(EditPolicy.LAYOUT_ROLE, new ConstrainedToolbarLayoutEditPolicy() { |
| |
| protected EditPolicy createChildEditPolicy(EditPart child) { |
| if (child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE) == null) { |
| if (child instanceof ITextAwareEditPart) { |
| return new MindmapTextSelectionEditPolicy(); |
| } |
| } |
| return super.createChildEditPolicy(child); |
| } |
| }); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected IFigure createNodeShape() { |
| RoundedTopicFigure figure = new RoundedTopicFigure(); |
| return primaryShape = figure; |
| } |
| |
| /** |
| * @generated |
| */ |
| public RoundedTopicFigure getPrimaryShape() { |
| return (RoundedTopicFigure) primaryShape; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected boolean addFixedChild(EditPart childEditPart) { |
| if (childEditPart instanceof Topic_nameEditPart) { |
| ((Topic_nameEditPart) childEditPart).setLabel(getPrimaryShape().getFigureTopicNameFigure()); |
| return true; |
| } |
| return false; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected NodeFigure createNodePlate() { |
| return new DefaultSizeNodeFigure(getMapMode().DPtoLP(40), getMapMode().DPtoLP(40)); |
| } |
| |
| /** |
| * 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(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(MindmapVisualIDRegistry.getType(Topic_nameEditPart.VISUAL_ID)); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected void addChildVisual(EditPart childEditPart, int index) { |
| if (!addFixedChild(childEditPart)) { |
| super.addChildVisual(childEditPart, -1); |
| } |
| } |
| |
| /** |
| * @generated |
| */ |
| public class RoundedTopicFigure extends org.eclipse.draw2d.RoundedRectangle { |
| |
| /** |
| * @generated |
| */ |
| public RoundedTopicFigure() { |
| |
| this.setForegroundColor(new org.eclipse.swt.graphics.Color(null, 220, 220, 250)); |
| this.setCornerDimensions(new org.eclipse.draw2d.geometry.Dimension(20, 20)); |
| |
| createContents(); |
| } |
| |
| /** |
| * @generated |
| */ |
| private void createContents() { |
| org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig_0 = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel(); |
| fig_0.setText(""); |
| |
| setFigureTopicNameFigure(fig_0); |
| |
| Object layData0 = null; |
| |
| this.add(fig_0, layData0); |
| } |
| |
| /** |
| * @generated |
| */ |
| private org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fTopicNameFigure; |
| |
| /** |
| * @generated |
| */ |
| public org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel getFigureTopicNameFigure() { |
| return fTopicNameFigure; |
| } |
| |
| /** |
| * @generated |
| */ |
| private void setFigureTopicNameFigure(org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel fig) { |
| fTopicNameFigure = fig; |
| } |
| |
| /** |
| * @generated |
| */ |
| private boolean myUseLocalCoordinates = false; |
| |
| /** |
| * @generated |
| */ |
| protected boolean useLocalCoordinates() { |
| return myUseLocalCoordinates; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
| myUseLocalCoordinates = useLocalCoordinates; |
| } |
| |
| } |
| |
| } |