/* * (c) 2011 - 2013 University of Mannheim: Software Engineering Group */ package de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts; import java.util.ArrayList; import java.util.HashSet; import org.eclipse.draw2d.Border; import org.eclipse.draw2d.GridData; import org.eclipse.draw2d.GridLayout; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.RectangleFigure; import org.eclipse.draw2d.Shape; import org.eclipse.draw2d.StackLayout; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; 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.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; 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.requests.RequestConstants; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.ocl.ParserException; import org.eclipse.ocl.ecore.Constraint; import org.eclipse.ocl.expressions.OCLExpression; import org.eclipse.ocl.helper.OCLHelper; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.widgets.Display; import de.itemis.gmf.runtime.layout.ResizableFlowLayout; /** * @generated */ public class ModelEditPart extends ShapeNodeEditPart { /** * @generated */ public static final int VISUAL_ID = 3059; /** * @generated */ protected IFigure contentPane; /** * @generated */ protected IFigure primaryShape; /** * @generated */ public ModelEditPart(View view) { super(view); } /** * @generated */ protected void createDefaultEditPolicies() { installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy()); super.createDefaultEditPolicies(); installEditPolicy( EditPolicyRoles.SEMANTIC_ROLE, new de.uni_mannheim.informatik.swt.models.plm.diagram.edit.policies.ModelItemSemanticEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy()); installEditPolicy( EditPolicyRoles.CANONICAL_ROLE, new de.uni_mannheim.informatik.swt.models.plm.diagram.edit.policies.ModelCanonicalEditPolicy()); 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); removeEditPolicy(EditPolicyRoles.POPUPBAR_ROLE); installEditPolicy( EditPolicyRoles.POPUPBAR_ROLE, new de.uni_mannheim.informatik.swt.models.plm.diagram.custom.popupbartools.editpolicy.PLMModelElementPopupBarEditPolicy()); } /** * @generated */ protected LayoutEditPolicy createLayoutEditPolicy() { org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy lep = new org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy() { protected EditPolicy createChildEditPolicy(EditPart child) { 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() { return primaryShape = new ModelFigure(); } /** * @generated */ public ModelFigure getPrimaryShape() { return (ModelFigure) primaryShape; } /** * @generated */ protected boolean addFixedChild(EditPart childEditPart) { if (childEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.ModelNameEditPart) { ((de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.ModelNameEditPart) childEditPart) .setLabel(getPrimaryShape() .getFigureOntologyLevelNameFigure()); return true; } if (childEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.WrappingLabel2EditPart) { ((de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.WrappingLabel2EditPart) childEditPart) .setLabel(getPrimaryShape() .getFigureOntologyLevelAVSFigure()); return true; } if (childEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.ModelDomainElementsCompartmentEditPart) { IFigure pane = getPrimaryShape().getFigureDomainElementsContainer(); setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way pane.add(((de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.ModelDomainElementsCompartmentEditPart) childEditPart) .getFigure()); return true; } return false; } /** * @generated */ protected boolean removeFixedChild(EditPart childEditPart) { if (childEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.ModelNameEditPart) { return true; } if (childEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.WrappingLabel2EditPart) { return true; } if (childEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.ModelDomainElementsCompartmentEditPart) { IFigure pane = getPrimaryShape().getFigureDomainElementsContainer(); pane.remove(((de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.ModelDomainElementsCompartmentEditPart) 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 de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.ModelDomainElementsCompartmentEditPart) { return getPrimaryShape().getFigureDomainElementsContainer(); } return getContentPane(); } /** * @generated */ protected NodeFigure createNodePlate() { DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 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 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(de.uni_mannheim.informatik.swt.models.plm.diagram.part.PLMVisualIDRegistry .getType(de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.ModelNameEditPart.VISUAL_ID)); } /** * @generated */ @Override protected void handleNotificationEvent(Notification notification) { super.handleNotificationEvent(notification); if (notification.getNotifier() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.Model && ((EStructuralFeature) notification.getFeature()).getName() .equals("content")) { if (notification.getNewValue() != null) { de.uni_mannheim.informatik.swt.models.plm.PLM.Model m = (de.uni_mannheim.informatik.swt.models.plm.PLM.Model) notification .getNotifier(); if (notification.getNewValue() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.Clabject) { de.uni_mannheim.informatik.swt.models.plm.PLM.Clabject c = (de.uni_mannheim.informatik.swt.models.plm.PLM.Clabject) notification .getNewValue(); de.uni_mannheim.informatik.swt.models.plm.PLM.Ontology ont = (de.uni_mannheim.informatik.swt.models.plm.PLM.Ontology) m .eContainer(); c.setLevel(ont.getContent().indexOf(m)); } } } if (notification.getNotifier() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.Model && ((EStructuralFeature) notification.getFeature()).getName() .equals("expressed")) { IGraphicalEditPart parent = (IGraphicalEditPart) getParent(); de.uni_mannheim.informatik.swt.models.plm.PLM.Element self = (de.uni_mannheim.informatik.swt.models.plm.PLM.Element) resolveSemanticElement(); //Check is visible if (parent.resolveSemanticElement() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.Context) { de.uni_mannheim.informatik.swt.models.plm.PLM.Context container = (de.uni_mannheim.informatik.swt.models.plm.PLM.Context) parent .resolveSemanticElement(); if ((container.getOrigin().equalsIgnoreCase("computed") && self .isExpressed()) || (container.getOrigin().equalsIgnoreCase("expressed") && !self .isExpressed())) { getNotationView().setVisible(false); } } else { getNotationView().setVisible(true); } } else if (notification.getNotifier() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.Model && ((EStructuralFeature) notification.getFeature()).getName() .equals("LMLVisualizersShown")) { de.uni_mannheim.informatik.swt.models.plm.PLM.Context container = (de.uni_mannheim.informatik.swt.models.plm.PLM.Context) notification .getNotifier(); de.uni_mannheim.informatik.swt.models.plm.PLM.LMLVisualizer[] LMLVisualizers = new de.uni_mannheim.informatik.swt.models.plm.PLM.LMLVisualizer[] {}; //find all LMLVisualizers in the model org.eclipse.ocl.ecore.OCL ocl = org.eclipse.ocl.ecore.OCL .newInstance(); OCLHelper<EClassifier, ?, ?, Constraint> helper = ocl .createOCLHelper(); helper.setContext(de.uni_mannheim.informatik.swt.models.plm.PLM.PLMPackage.Literals.MODEL); try { OCLExpression<EClassifier> q = helper .createQuery("self.content->collect(c | c.LMLVisualizer)"); LMLVisualizers = ((ArrayList<de.uni_mannheim.informatik.swt.models.plm.PLM.LMLVisualizer>) ocl .evaluate(resolveSemanticElement(), q)) .toArray(new de.uni_mannheim.informatik.swt.models.plm.PLM.LMLVisualizer[] {}); } catch (ParserException e) { e.printStackTrace(); } //find the notational elements for the LMLVisualizers for (de.uni_mannheim.informatik.swt.models.plm.PLM.LMLVisualizer r : LMLVisualizers) { TreeIterator<EObject> iter = (getNotationView().eAllContents()); while (iter.hasNext()) { EObject obj = iter.next(); if (obj instanceof Node) { Node n = (Node) obj; if (n.getElement() == r) { if (container.getVisualizersShown() .equalsIgnoreCase("none")) n.setVisible(false); else n.setVisible(true); break; } } } } performRequest(new Request(RequestConstants.REQ_REFRESH)); } else if (notification.getNotifier() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.Model && ((EStructuralFeature) notification.getFeature()).getName() .equals("origin")) { de.uni_mannheim.informatik.swt.models.plm.PLM.Element[] elements = new de.uni_mannheim.informatik.swt.models.plm.PLM.Element[] {}; de.uni_mannheim.informatik.swt.models.plm.PLM.Context container = (de.uni_mannheim.informatik.swt.models.plm.PLM.Context) resolveSemanticElement(); //find all LMLVisualizers in the model org.eclipse.ocl.ecore.OCL ocl = org.eclipse.ocl.ecore.OCL .newInstance(); OCLHelper<EClassifier, ?, ?, Constraint> helper = ocl .createOCLHelper(); helper.setContext(de.uni_mannheim.informatik.swt.models.plm.PLM.PLMPackage.Literals.MODEL); try { OCLExpression<EClassifier> q = helper .createQuery("self.content"); elements = ((HashSet<de.uni_mannheim.informatik.swt.models.plm.PLM.Element>) ocl .evaluate(resolveSemanticElement(), q)) .toArray(new de.uni_mannheim.informatik.swt.models.plm.PLM.Element[] {}); } catch (ParserException e) { e.printStackTrace(); } //find the notational elements for the LMLVisualizers for (de.uni_mannheim.informatik.swt.models.plm.PLM.Element e : elements) { TreeIterator<EObject> iter = (getNotationView().eAllContents()); while (iter.hasNext()) { EObject obj = iter.next(); if (obj instanceof Node) { Node s = (Node) obj; if (s.getElement() == e) { if (container.getOrigin().equalsIgnoreCase( "expressed") && e.isExpressed() || container.getOrigin().equalsIgnoreCase( "computed") && !e.isExpressed() || container.getOrigin().equalsIgnoreCase( "all")) s.setVisible(true); else s.setVisible(false); break; } } } } performRequest(new Request(RequestConstants.REQ_REFRESH)); } else if (notification.getNotifier() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.Model && ((EStructuralFeature) notification.getFeature()).getName() .equals("completness")) { de.uni_mannheim.informatik.swt.models.plm.PLM.Clabject[] clabjects = new de.uni_mannheim.informatik.swt.models.plm.PLM.Clabject[] {}; de.uni_mannheim.informatik.swt.models.plm.PLM.Model model = (de.uni_mannheim.informatik.swt.models.plm.PLM.Model) resolveSemanticElement(); //find all LMLVisualizers in the model org.eclipse.ocl.ecore.OCL ocl = org.eclipse.ocl.ecore.OCL .newInstance(); OCLHelper<EClassifier, ?, ?, Constraint> helper = ocl .createOCLHelper(); helper.setContext(de.uni_mannheim.informatik.swt.models.plm.PLM.PLMPackage.Literals.MODEL); try { OCLExpression<EClassifier> q = helper .createQuery("self.content->select(c | c.oclIsKindOf(Clabject))"); clabjects = ((HashSet<de.uni_mannheim.informatik.swt.models.plm.PLM.Clabject>) ocl .evaluate(resolveSemanticElement(), q)) .toArray(new de.uni_mannheim.informatik.swt.models.plm.PLM.Clabject[] {}); } catch (ParserException e) { e.printStackTrace(); } //find the notational elements for the LMLVisualizers for (de.uni_mannheim.informatik.swt.models.plm.PLM.Clabject c : clabjects) { TreeIterator<EObject> iter = (getNotationView().eAllContents()); while (iter.hasNext()) { EObject obj = iter.next(); if (obj instanceof Node) { Node s = (Node) obj; if (s.getElement() == c) { if (model.getCompletness().equalsIgnoreCase( "NoElision") && c.isElided()) s.setVisible(false); else s.setVisible(true); break; } } } } performRequest(new Request(RequestConstants.REQ_REFRESH)); } } /** * @generated */ public class ModelFigure extends RectangleFigure { /** * @generated */ private WrappingLabel fFigureOntologyLevelNameFigure; /** * @generated */ private WrappingLabel fFigureOntologyLevelAVSFigure; /** * @generated */ private RectangleFigure fFigureDomainElementsContainer; /** * @generated */ public ModelFigure() { ResizableFlowLayout layoutThis = new ResizableFlowLayout(); this.setLayoutManager(layoutThis); this.setFill(false); this.setOutline(false); this.setLineWidth(0); this.setBorder(createBorder0()); createContents(); } /** * @generated */ private void createContents() { RectangleFigure nameRectangle0 = new RectangleFigure(); nameRectangle0.setFill(false); nameRectangle0.setOutline(false); nameRectangle0.setMaximumSize(new Dimension(getMapMode().DPtoLP(0), getMapMode().DPtoLP(25))); this.add(nameRectangle0); GridLayout layoutNameRectangle0 = new GridLayout(); layoutNameRectangle0.numColumns = 2; layoutNameRectangle0.makeColumnsEqualWidth = false; layoutNameRectangle0.horizontalSpacing = 0; layoutNameRectangle0.verticalSpacing = 0; layoutNameRectangle0.marginWidth = 0; layoutNameRectangle0.marginHeight = 3; nameRectangle0.setLayoutManager(layoutNameRectangle0); fFigureOntologyLevelNameFigure = new WrappingLabel(); fFigureOntologyLevelNameFigure.setText(""); fFigureOntologyLevelNameFigure .setFont(FFIGUREONTOLOGYLEVELNAMEFIGURE_FONT); fFigureOntologyLevelNameFigure.setMaximumSize(new Dimension( getMapMode().DPtoLP(0), getMapMode().DPtoLP(20))); GridData constraintFFigureOntologyLevelNameFigure = new GridData(); constraintFFigureOntologyLevelNameFigure.verticalAlignment = GridData.CENTER; constraintFFigureOntologyLevelNameFigure.horizontalAlignment = GridData.BEGINNING; constraintFFigureOntologyLevelNameFigure.horizontalIndent = 0; constraintFFigureOntologyLevelNameFigure.horizontalSpan = 1; constraintFFigureOntologyLevelNameFigure.verticalSpan = 1; constraintFFigureOntologyLevelNameFigure.grabExcessHorizontalSpace = false; constraintFFigureOntologyLevelNameFigure.grabExcessVerticalSpace = false; nameRectangle0.add(fFigureOntologyLevelNameFigure, constraintFFigureOntologyLevelNameFigure); fFigureOntologyLevelAVSFigure = new WrappingLabel(); fFigureOntologyLevelAVSFigure.setText(""); fFigureOntologyLevelAVSFigure .setFont(FFIGUREONTOLOGYLEVELAVSFIGURE_FONT); fFigureOntologyLevelAVSFigure.setMaximumSize(new Dimension( getMapMode().DPtoLP(0), getMapMode().DPtoLP(20))); GridData constraintFFigureOntologyLevelAVSFigure = new GridData(); constraintFFigureOntologyLevelAVSFigure.verticalAlignment = GridData.CENTER; constraintFFigureOntologyLevelAVSFigure.horizontalAlignment = GridData.BEGINNING; constraintFFigureOntologyLevelAVSFigure.horizontalIndent = 0; constraintFFigureOntologyLevelAVSFigure.horizontalSpan = 1; constraintFFigureOntologyLevelAVSFigure.verticalSpan = 1; constraintFFigureOntologyLevelAVSFigure.grabExcessHorizontalSpace = true; constraintFFigureOntologyLevelAVSFigure.grabExcessVerticalSpace = true; nameRectangle0.add(fFigureOntologyLevelAVSFigure, constraintFFigureOntologyLevelAVSFigure); fFigureDomainElementsContainer = new RectangleFigure(); fFigureDomainElementsContainer.setFill(false); fFigureDomainElementsContainer.setOutline(false); this.add(fFigureDomainElementsContainer); } /** * @generated */ private Border createBorder0() { de.uni_mannheim.informatik.swt.models.plm.diagram.custom.borders.CustomBorder result = new de.uni_mannheim.informatik.swt.models.plm.diagram.custom.borders.CustomBorder(); result.setBottom(true); return result; } /** * @generated */ public WrappingLabel getFigureOntologyLevelNameFigure() { return fFigureOntologyLevelNameFigure; } /** * @generated */ public WrappingLabel getFigureOntologyLevelAVSFigure() { return fFigureOntologyLevelAVSFigure; } /** * @generated */ public RectangleFigure getFigureDomainElementsContainer() { return fFigureDomainElementsContainer; } } /** * @generated */ static final Font FFIGUREONTOLOGYLEVELNAMEFIGURE_FONT = new Font( Display.getCurrent(), Display.getDefault().getSystemFont() .getFontData()[0].getName(), 10, SWT.NORMAL); /** * @generated */ static final Font FFIGUREONTOLOGYLEVELAVSFIGURE_FONT = new Font( Display.getCurrent(), Display.getDefault().getSystemFont() .getFontData()[0].getName(), 8, SWT.NORMAL); //Gives the option to diplay a Connection/Generalization/Specialization as black rectangle }