| /** |
| * Copyright (c) 2009, 2012 Borland Software Corporation & 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: |
| * Artem Tikhomirov (Borland) - initial API and implementation |
| * Guillaume Hillairet (Montages A.G.) |
| */ |
| import xpt.XpandFacade; |
| import Utils; |
| |
| modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings'); |
| modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel'); |
| modeltype GMFGRAPH uses gmfgraph('http://www.eclipse.org/gmf/2006/GraphicalDefinition'); |
| modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore'); |
| |
| library Viewmaps; |
| |
| -- |
| -- Canvas |
| -- |
| |
| mapping GMFGRAPH::Canvas::viewmap() : GMFGEN::Viewmap { |
| init { |
| result := object GMFGEN::FigureViewmap { |
| figureQualifiedClassName := 'org.eclipse.draw2d.FreeformLayer'; |
| }; |
| } |
| } |
| |
| -- |
| -- ChildReference |
| -- |
| |
| helper GMFMAP::ChildReference::viewmap(node: GMFMAP::NodeMapping) : GMFGEN::Viewmap = |
| if node.isPureLabelNode() then |
| node.labelMappings->first().diagramLabel.map viewmap() |
| else |
| node.diagramNode.map viewmap() |
| endif; |
| |
| -- |
| -- Node |
| -- |
| |
| helper GMFGRAPH::Node::viewmap(): GMFGEN::Viewmap { |
| var rs := self.figure.viewmap(); |
| |
| rs.layoutType := self.getLayoutType(); |
| rs.attributes += if self.hasResizeConstraints() then self.map resizeConstraints() endif; |
| rs.attributes += if self.hasDefaultSize() then self.map defaultSize() endif; |
| |
| return rs; |
| } |
| |
| query GMFGRAPH::Node::hasResizeConstraints(): Boolean = |
| not (self.resizeConstraint.oclIsUndefined() or (self.resizeConstraint = Direction::NSEW)); |
| |
| query GMFGRAPH::Node::hasDefaultSize(): Boolean { |
| var facet : DefaultSizeFacet := self.facets[DefaultSizeFacet]->first(); |
| var defaultSize := if facet.oclIsUndefined() then self.figure.actualFigure.preferredSize else facet.defaultSize endif; |
| |
| return not defaultSize.oclIsUndefined() |
| } |
| |
| mapping GMFGRAPH::Node::resizeConstraints(): GMFGEN::ResizeConstraints { |
| resizeHandles := self.resizeConstraint.repr().toInteger(); |
| } |
| |
| mapping GMFGRAPH::Node::defaultSize(): GMFGEN::DefaultSizeAttributes { |
| var facet : DefaultSizeFacet := self.facets[DefaultSizeFacet]->first(); |
| var defaultSize := if facet.oclIsUndefined() then self.figure.actualFigure.preferredSize else facet.defaultSize endif; |
| |
| if not defaultSize.oclIsUndefined() then { |
| height := defaultSize.dy; |
| width := defaultSize.dx; |
| } endif; |
| } |
| |
| query GMFGRAPH::Node::getLayoutType(): GMFGEN::ViewmapLayoutType { |
| var layout = ViewmapLayoutType::UNKNOWN; |
| if (self.figure.actualFigure.layout.oclIsUndefined()) then { |
| layout := GMFGEN::ViewmapLayoutType::UNKNOWN; |
| } else { |
| if self.figure.actualFigure.layout.oclIsKindOf(GMFGRAPH::FlowLayout) then { |
| var fl := self.figure.actualFigure.layout.oclAsType(GMFGRAPH::FlowLayout); |
| if fl.forceSingleLine then |
| layout := GMFGEN::ViewmapLayoutType::TOOLBAR_LAYOUT |
| else |
| layout := GMFGEN::ViewmapLayoutType::FLOW_LAYOUT |
| endif; |
| } else |
| if self.figure.actualFigure.layout.oclIsKindOf(GMFGRAPH::XYLayout) then |
| layout := GMFGEN::ViewmapLayoutType::XY_LAYOUT |
| endif |
| endif; |
| } endif; |
| return layout; |
| } |
| |
| -- |
| -- Compartment |
| -- |
| |
| helper GMFGRAPH::Compartment::viewmap() : GMFGEN::Viewmap { |
| if self.figure.oclIsUndefined() then |
| return object GMFGEN::FigureViewmap {} |
| endif; |
| -- FIXME check self.accessor, see InnerClassViewapProducer |
| if self.accessor.oclIsUndefined() then |
| return self.figure.viewmap() |
| endif; |
| return self.figure.viewmap(self.accessor); |
| } |
| |
| -- |
| -- Connection |
| -- |
| |
| helper GMFGRAPH::Connection::viewmap() : GMFGEN::Viewmap { |
| var rs : GMFGEN::Viewmap := null; |
| |
| if self.figure.oclIsUndefined() then |
| rs := object GMFGEN::FigureViewmap { |
| figureQualifiedClassName := "org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx"; |
| } |
| else |
| rs := self.figure.viewmap() |
| endif; |
| |
| return rs; |
| } |
| |
| -- |
| -- DiagramLabel |
| -- |
| |
| helper GMFGRAPH::DiagramLabel::viewmap(): GMFGEN::Viewmap { |
| var rs : GMFGEN::Viewmap := null; |
| |
| if self.figure.oclIsUndefined() then |
| rs := object GMFGEN::FigureViewmap { |
| figureQualifiedClassName := "org.eclipse.draw2d.Label" |
| } |
| else |
| if self.accessor.oclIsUndefined() then |
| rs := self.figure.viewmap() |
| else |
| -- for GenLinkLabel, need to specify alignment based on AlignmentFacet |
| -- besides, need to create LabelOffsetAttributes and optionally populate it from LabelOffsetFacet |
| rs := self.figure.viewmap(self.accessor) |
| endif |
| endif; |
| |
| return rs; |
| } |
| |
| helper DiagramLabel::labelOffSetAttributes(position: Integer): LabelOffsetAttributes = |
| object LabelOffsetAttributes { |
| var offsetFacet := self.findOffsetFacet(); |
| if not offsetFacet.oclIsUndefined() then { |
| x := offsetFacet.x; |
| y := offsetFacet.y; |
| } else { |
| y := (position + 1) * 20; |
| } endif; |
| }; |
| |
| -- |
| -- Figure |
| -- |
| |
| helper GMFGRAPH::FigureDescriptor::viewmap() : GMFGEN::Viewmap { |
| var rs: GMFGEN::Viewmap := null; |
| |
| if self.actualFigure.isBareInstance() then { |
| rs := object GMFGEN::FigureViewmap { |
| figureQualifiedClassName := self.actualFigure.xpand('Runtime::fqn', templates()); |
| } |
| } else { |
| rs := object GMFGEN::InnerClassViewmap { |
| classBody := self.xpand('top::Descriptor::Inner', templates()); |
| className := self.name.firstToUpper(); -- FIXME InnerClassViewmapProducer has validJavaIdentifier(capName()) |
| }; |
| } endif; |
| |
| rs.attributes := self.actualFigure.createStyleAttributes(); |
| |
| return rs; |
| } |
| |
| helper GMFGRAPH::Figure::createStyleAttributes() : GMFGEN::StyleAttributes { |
| var attributes: GMFGEN::StyleAttributes; |
| if not (self.font.oclIsUndefined() and self.foregroundColor.oclIsUndefined() and |
| self.backgroundColor.oclIsUndefined()) then { |
| attributes := object GMFGEN::StyleAttributes { |
| fixedFont := if (self.font.oclIsUndefined()) then false else true endif; |
| fixedForeground := if (self.foregroundColor.oclIsUndefined()) then false else true endif; |
| fixedBackground := if (self.backgroundColor.oclIsUndefined()) then false else true endif; |
| }; |
| } endif; |
| return attributes; |
| } |
| |
| helper GMFGRAPH::FigureDescriptor::viewmap(childAccess : GMFGRAPH::ChildAccess) : GMFGEN::Viewmap = |
| object GMFGEN::ParentAssignedViewmap { |
| getterName := childAccess.accessor; |
| figureQualifiedClassName := childAccess.figure.xpand('Runtime::fqn', templates()); |
| attributes := childAccess.figure.createStyleAttributes(); |
| }; |
| |
| query GMFGRAPH::Figure::isBareInstance() : Boolean = false; |
| |
| query GMFGRAPH::RealFigure::isBareInstance() : Boolean { |
| if self.children->notEmpty() then return false endif; |
| if self.oclIsKindOf(GMFGRAPH::Label) then { |
| if self.oclAsType(GMFGRAPH::Label).text <> null then return false endif; |
| } endif; |
| if self.oclIsKindOf(GMFGRAPH::Shape) then { |
| var sh : Shape := self.oclAsType(GMFGRAPH::Shape); |
| if sh.lineWidth <> 1 then return false endif; |
| if sh.lineKind <> LineKind::LINE_SOLID then return false endif; |
| if not sh.outline or not sh.fill or sh.xorFill or sh.xorOutline then return false endif; |
| } endif; |
| |
| if self.border <> null then return false endif; |
| if self.font <> null then return false endif; |
| if self.foregroundColor <> null then return false endif; |
| if self.backgroundColor <> null then return false endif; |
| if self.maximumSize <> null then return false endif; |
| if self.minimumSize <> null then return false endif; |
| if self.preferredSize <> null then return false endif; |
| if self.insets <> null then return false endif; |
| if self.location <> null then return false endif; |
| if self.size <> null then return false endif; |
| |
| if self.oclIsKindOf(GMFGRAPH::PolylineConnection) then { |
| if self.oclAsType(GMFGRAPH::PolylineConnection).sourceDecoration <> null then return false endif; |
| if self.oclAsType(GMFGRAPH::PolylineConnection).targetDecoration <> null then return false endif; |
| } endif; |
| |
| if self.oclIsKindOf(GMFGRAPH::SVGFigure) then { |
| if self.oclAsType(GMFGRAPH::SVGFigure).documentURI <> null then return false endif; |
| } endif; |
| return true; |
| } |
| |
| query DiagramElement::findOffsetFacet(): LabelOffsetFacet = |
| self.facets->selectOne(e | e.oclIsKindOf(LabelOffsetFacet)).oclAsType(LabelOffsetFacet); |
| |
| query DiagramElement::findIndex(): Integer { |
| var container := self.oclAsType(EObject).eContainer(); |
| if container.oclIsKindOf(LabelMapping) then { |
| var linkMapping := container.eContainer(); |
| |
| if linkMapping.oclIsKindOf(GMFMAP::LinkMapping) then { |
| return linkMapping.oclAsType(LinkMapping).labelMappings->indexOf(container.oclAsType(LabelMapping)) |
| } endif; |
| |
| } endif; |
| |
| return 0; |
| } |
| |
| -- |
| -- Templates |
| -- |
| |
| property templateRoots : Sequence(String) = Sequence {'platform:/plugin/org.eclipse.gmf.graphdef.codegen/templates/'}; |
| property mapModeTemplateRoots : String = 'platform:/plugin/org.eclipse.gmf.graphdef.codegen/templates/rt_mm/'; |
| property useMapMode : Boolean = false; |
| |
| helper setMapMode(mapMode: Boolean) { |
| this.useMapMode := mapMode; |
| return; |
| } |
| |
| query templates(): Sequence(String) = |
| if useMapMode then this.templateRoots->prepend(this.mapModeTemplateRoots) else this.templateRoots endif; |