blob: 8adc13bc4731f740042153a6e5abe04b417e10ba [file] [log] [blame]
/*
 * Copyright (c) 2007, 2010 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:
* Artem Tikhomirov (Borland) - initial API and implementation
*/
import xpt.GlobalVarOperations;
import xpt.StreamOperations;
import xpt.StringOperations;
modeltype gmfgraph uses "http://www.eclipse.org/gmf/2006/GraphicalDefinition";
library Util;
property bordersInUse : Sequence(gmfgraph::CustomBorder) = Sequence { };
helper addBorder(border : gmfgraph::CustomBorder) : OclVoid {
bordersInUse := bordersInUse->including(border);
return null
}
helper clearBorders() : OclVoid {
bordersInUse := Sequence { };
return null
}
helper getBordersInUse() : Sequence(gmfgraph::CustomBorder) {
return bordersInUse;
}
helper compilationUnitName(figure : gmfgraph::FigureDescriptor) : String {
return figure.name.firstToUpper()
}
helper hasSourceDecoration(figure : gmfgraph::PolylineConnection) : Boolean {
return null <> figure.sourceDecoration
}
helper requiredBundles(referencedBundles : Sequence(String)) : Sequence(String) {
return (if isFullRuntime() then Sequence { 'org.eclipse.core.runtime', 'org.eclipse.draw2d', 'org.eclipse.gmf.runtime.draw2d.ui' }->union(referencedBundles)->asOrderedSet()->asSequence()->asOrderedSet()->asSequence() else Sequence { 'org.eclipse.core.runtime', 'org.eclipse.draw2d' }->union(referencedBundles)->asOrderedSet()->asSequence()->asOrderedSet()->asSequence() endif)
}
helper additionalStaticFields() : String {
return if xpandGetStreamNames()->includes('staticFields') then xpandGetStreamContents('staticFields') else '' endif
}
helper hasTargetDecoration(figure : gmfgraph::PolylineConnection) : Boolean {
return null <> figure.targetDecoration
}
helper isFullRuntime() : Boolean {
return (if internalCheckRuntimeToken() <> null then internalCheckRuntimeToken().toLower() = 'full' else true endif)
}
helper internalCheckRuntimeToken() : String {
return xpandGetStringGlobalVar('runtimeToken')
}
helper needsField(figure : gmfgraph::RealFigure) : Boolean {
return figure.descriptor <> null and figure.descriptor.accessors.figure->includes(figure)
}
helper figureVariableName(figure : gmfgraph::RealFigure, count : Integer) : String {
return (if needsField(figure) then figure.figureFieldName() else (if figure.name <> null and figure.name.trim().size() > 0 then figure.name.xpandToFirstLower() + count.repr() else figure.variableNameStem() + count.repr() endif) endif)
}
helper gmfgraph::FigureRef::nameStem() : String {
return self.figure.variableNameStem()
}
helper gmfgraph::Figure::nameStem() : String {
return self.variableNameStem()
}
helper gmfgraph::Figure::variableNameStem() : String {
return 'fig'
}
helper gmfgraph::RealFigure::variableNameStem() : String {
return 'fig'
}
helper gmfgraph::Shape::variableNameStem() : String {
return 'shape'
}
helper gmfgraph::Rectangle::variableNameStem() : String {
return 'rect'
}
helper gmfgraph::RoundedRectangle::variableNameStem() : String {
return 'rrect'
}
helper gmfgraph::Ellipse::variableNameStem() : String {
return 'elli'
}
helper gmfgraph::Polyline::variableNameStem() : String {
return 'polyline'
}
helper gmfgraph::Label::variableNameStem() : String {
return 'l'
}
helper gmfgraph::DecorationFigure::variableNameStem() : String {
return 'dec'
}
helper gmfgraph::ConnectionFigure::variableNameStem() : String {
return 'conn'
}
helper gmfgraph::RealFigure::figureFieldName() : String {
return figureFieldName(self.descriptor.accessors->select(a | self = a.figure)->asSequence())
}
helper figureFieldName(aaa : Sequence(gmfgraph::ChildAccess)) : String {
return aaa->collect(x | x.figureFieldName())->first()
}
helper gmfgraph::ChildAccess::figureFieldName() : String {
return 'f' + (if self.accessor.startsWith('get') and self.accessor.size() > 3 then self.accessor.substringAfter('get') else self.accessor endif)
}
helper borderLayoutConstant(layoutData : gmfgraph::BorderLayoutData) : String {
return switch { case (layoutData.alignment = gmfgraph::Alignment::BEGINNING) (if layoutData.vertical then 'TOP' else 'LEFT' endif); case (layoutData.alignment = gmfgraph::Alignment::END) (if layoutData.vertical then 'BOTTOM' else 'RIGHT' endif); else 'CENTER'; }
}
helper allCustomAccessors(fd : gmfgraph::FigureDescriptor) : Sequence(gmfgraph::FigureAccessor) {
return filterCustom(Sequence { fd.actualFigure }).customChildren
}
helper filterCustom(figures : Sequence(gmfgraph::Figure)) : Sequence(gmfgraph::CustomFigure) {
return (if figures->isEmpty() then Sequence { } else (figures)[gmfgraph::CustomFigure]->union(filterCustom((figures)[gmfgraph::RealFigure].children))->asOrderedSet()->asSequence() endif)->collect(it | it)->asSequence()
}
helper svgPropertyType(p : gmfgraph::SVGProperty) : String {
return switch { case (p.type = gmfgraph::SVGPropertyType::COLOR) 'org.eclipse.swt.graphics.Color'; case (p.type = gmfgraph::SVGPropertyType::FLOAT) 'float'; else 'String'; }
}