Java Examples for org.eclipse.graphiti.services.IPeCreateService
The following java examples will help you to understand the usage of org.eclipse.graphiti.services.IPeCreateService. These source code samples are taken from different open source projects.
Example 1
| Project: gmp.graphiti-master File: CompartmentPattern.java View source code |
@Override
public PictogramElement add(IAddContext context) {
Object mainBusinessObject = context.getNewObject();
ContainerShape parentContainerShape = context.getTargetContainer();
// CONTAINER SHAPE WITH ROUNDED RECTANGLE
final IPeCreateService peCreateService = Graphiti.getPeCreateService();
IGaCreateService gaCreateService = Graphiti.getGaCreateService();
IGaService gaService = Graphiti.getGaService();
ContainerShape containerShape = peCreateService.createContainerShape(parentContainerShape, true);
getFeatureProvider().getDirectEditingInfo().setMainPictogramElement(containerShape);
// check whether valid size is available, e.g. if called from the create
// feature
int width = context.getWidth() <= 0 ? 100 : context.getWidth();
int height = context.getHeight() <= 0 ? 120 : context.getHeight();
{
// create and set graphics algorithm
RoundedRectangle roundedRectangle = gaCreateService.createRoundedRectangle(containerShape, getConfiguration().getCornerWidth(), getConfiguration().getCornerHeight());
roundedRectangle.setForeground(manageColor(getConfiguration().getForegroundColor()));
roundedRectangle.setBackground(manageColor(getConfiguration().getBackgroundColor()));
roundedRectangle.setLineWidth(getConfiguration().getLineWidth());
roundedRectangle.setTransparency(getConfiguration().getTransparency());
Graphiti.getGaService().setLocationAndSize(roundedRectangle, context.getX(), context.getY(), width, height);
// create link and wire it
link(containerShape, mainBusinessObject);
}
// HEADER SHAPE
{
// create shape for text
Shape shape = peCreateService.createShape(containerShape, false);
Text text;
if (getConfiguration().isHeaderImageVisible()) {
Rectangle rectangle = gaCreateService.createRectangle(shape);
rectangle.setFilled(false);
rectangle.setLineVisible(false);
gaCreateService.createImage(rectangle, IPlatformImageConstants.IMG_EDIT_EXPANDALL);
text = gaCreateService.createText(rectangle);
text.setForeground(manageColor(getConfiguration().getTextColor()));
text.setHorizontalAlignment(Orientation.ALIGNMENT_LEFT);
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
text.setFont(gaService.manageDefaultFont(getDiagram(), false, true));
} else // just a text data mapping
{
text = gaCreateService.createText(shape);
text.setForeground(manageColor(getConfiguration().getTextColor()));
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
text.setFont(gaService.manageDefaultFont(getDiagram(), false, true));
}
IDirectEditingInfo dei = getFeatureProvider().getDirectEditingInfo();
dei.setPictogramElement(shape);
dei.setGraphicsAlgorithm(text);
// create link and wire it
ILinkCreationInfo linkCreationInfo = getHeaderMapping().getLinkCreationInfo(mainBusinessObject);
String linkProperty = linkCreationInfo.getProperty();
if (linkProperty != null) {
getLinkService().setLinkProperty(shape, linkProperty);
}
link(shape, linkCreationInfo.getBusinessObjects());
}
{
for (int compartmentIndex = 0; compartmentIndex < getCompartmentCount(); compartmentIndex++) {
// create a line shape above each compartment
// SHAPE WITH LINE
{
// create shape for line
Shape shape = peCreateService.createShape(containerShape, false);
// create and set graphics algorithm
Polyline polyline = gaCreateService.createPolyline(shape, new int[] { 0, 0, 0, 0 });
polyline.setForeground(manageColor(getConfiguration().getForegroundColor()));
polyline.setLineWidth(getConfiguration().getLineWidth());
}
ContainerShape compartmentContainerShape = peCreateService.createContainerShape(containerShape, false);
Rectangle compartmentRectangle = gaCreateService.createRectangle(compartmentContainerShape);
compartmentRectangle.setFilled(false);
compartmentRectangle.setLineVisible(false);
// createLink(compartmentContainerShape, mainBusinessObject);
}
}
peCreateService.createChopboxAnchor(containerShape);
updatePictogramElement(containerShape);
return containerShape;
}Example 2
| Project: Permet-master File: AddTransitionFeature.java View source code |
@Override
public PictogramElement add(IAddContext context) {
IAddConnectionContext addConContext = (IAddConnectionContext) context;
Transition transition = (Transition) context.getNewObject();
IPeCreateService peCreateService = Graphiti.getPeCreateService();
Connection connection = peCreateService.createFreeFormConnection(getDiagram());
connection.setStart(addConContext.getSourceAnchor());
connection.setEnd(addConContext.getTargetAnchor());
IGaService gaService = Graphiti.getGaService();
Polyline polyline = gaService.createPolyline(connection);
polyline.setLineWidth(1);
polyline.setForeground(manageColor(IColorConstant.BLACK));
addArrow(connection);
addLabel(connection, transition);
link(connection, transition);
return connection;
}Example 3
| Project: jenkow-plugin-master File: AddTaskFeature.java View source code |
@Override
public PictogramElement add(IAddContext context) {
final Task addedTask = (Task) context.getNewObject();
final ContainerShape parent = context.getTargetContainer();
// CONTAINER SHAPE WITH ROUNDED RECTANGLE
final IPeCreateService peCreateService = Graphiti.getPeCreateService();
final ContainerShape containerShape = peCreateService.createContainerShape(parent, true);
final IGaService gaService = Graphiti.getGaService();
DiagramBaseShape baseShape = DiagramBaseShape.ACTIVITY;
if (ExtensionUtil.isCustomServiceTask(addedTask)) {
final ServiceTask serviceTask = (ServiceTask) addedTask;
final List<CustomServiceTask> customServiceTasks = ExtensionUtil.getCustomServiceTasks(ActivitiUiUtil.getProjectFromDiagram(getDiagram()));
CustomServiceTask targetTask = null;
for (final CustomServiceTask customServiceTask : customServiceTasks) {
if (customServiceTask.getId().equals(serviceTask.getExtensionId())) {
targetTask = customServiceTask;
break;
}
}
if (!DiagramBaseShape.ACTIVITY.equals(targetTask.getDiagramBaseShape())) {
baseShape = targetTask.getDiagramBaseShape();
}
}
int width = 0;
int height = 0;
GraphicsAlgorithm algorithm = null;
switch(baseShape) {
case ACTIVITY:
// check whether the context has a size (e.g. from a create feature)
// otherwise define a default size for the shape
width = context.getWidth() <= 0 ? 105 : context.getWidth();
height = context.getHeight() <= 0 ? 55 : context.getHeight();
// need to access it later
RoundedRectangle roundedRectangle;
{
// create invisible outer rectangle expanded by
// the width needed for the anchor
final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
gaService.setLocationAndSize(invisibleRectangle, context.getX(), context.getY(), width, height);
// create and set visible rectangle inside invisible rectangle
roundedRectangle = gaService.createRoundedRectangle(invisibleRectangle, 20, 20);
algorithm = roundedRectangle;
roundedRectangle.setParentGraphicsAlgorithm(invisibleRectangle);
roundedRectangle.setStyle(StyleUtil.getStyleForTask(getDiagram()));
gaService.setLocationAndSize(roundedRectangle, 0, 0, width, height);
// create link and wire it
link(containerShape, addedTask);
}
break;
case GATEWAY:
// check whether the context has a size (e.g. from a create feature)
// otherwise define a default size for the shape
width = context.getWidth() <= 0 ? 60 : context.getWidth();
height = context.getHeight() <= 0 ? 60 : context.getHeight();
Polygon polygon;
{
int xy[] = new int[] { 0, 30, 30, 0, 60, 30, 30, 60, 0, 30 };
final Polygon invisiblePolygon = gaService.createPolygon(containerShape, xy);
invisiblePolygon.setFilled(false);
invisiblePolygon.setLineVisible(false);
gaService.setLocationAndSize(invisiblePolygon, context.getX(), context.getY(), width, height);
// create and set visible circle inside invisible circle
polygon = gaService.createPolygon(invisiblePolygon, xy);
algorithm = polygon;
polygon.setParentGraphicsAlgorithm(invisiblePolygon);
polygon.setStyle(StyleUtil.getStyleForTask(getDiagram()));
gaService.setLocationAndSize(polygon, 0, 0, width, height);
// create link and wire it
link(containerShape, addedTask);
}
break;
case EVENT:
// check whether the context has a size (e.g. from a create feature)
// otherwise define a default size for the shape
width = context.getWidth() <= 0 ? 55 : context.getWidth();
height = context.getHeight() <= 0 ? 55 : context.getHeight();
Ellipse circle;
{
final Ellipse invisibleCircle = gaService.createEllipse(containerShape);
invisibleCircle.setFilled(false);
invisibleCircle.setLineVisible(false);
gaService.setLocationAndSize(invisibleCircle, context.getX(), context.getY(), width, height);
// create and set visible circle inside invisible circle
circle = gaService.createEllipse(invisibleCircle);
circle.setParentGraphicsAlgorithm(invisibleCircle);
circle.setStyle(StyleUtil.getStyleForTask(getDiagram()));
gaService.setLocationAndSize(circle, 0, 0, width, height);
// create link and wire it
link(containerShape, addedTask);
}
break;
}
// SHAPE WITH TEXT
{
// create shape for text
final Shape shape = peCreateService.createShape(containerShape, false);
// create and set text graphics algorithm
final MultiText text = gaService.createDefaultMultiText(getDiagram(), shape, addedTask.getName());
text.setStyle(StyleUtil.getStyleForTask(getDiagram()));
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
if (OSUtil.getOperatingSystem() == OSEnum.Mac) {
text.setFont(gaService.manageFont(getDiagram(), text.getFont().getName(), 11));
}
switch(baseShape) {
case ACTIVITY:
gaService.setLocationAndSize(text, 0, 20, width, height - 25);
break;
case GATEWAY:
gaService.setLocationAndSize(text, 0, height + 5, width, 40);
break;
case EVENT:
gaService.setLocationAndSize(text, 0, height + 5, width, 40);
break;
}
// create link and wire it
link(shape, addedTask);
// provide information to support direct-editing directly
// after object creation (must be activated additionally)
final IDirectEditingInfo directEditingInfo = getFeatureProvider().getDirectEditingInfo();
// set container shape for direct editing after object creation
directEditingInfo.setMainPictogramElement(containerShape);
// set shape and graphics algorithm where the editor for
// direct editing shall be opened after object creation
directEditingInfo.setPictogramElement(shape);
directEditingInfo.setGraphicsAlgorithm(text);
}
{
final Shape shape = peCreateService.createShape(containerShape, false);
final Image image = gaService.createImage(shape, getIcon(addedTask));
switch(baseShape) {
case ACTIVITY:
gaService.setLocationAndSize(image, 5, 5, IMAGE_SIZE, IMAGE_SIZE);
break;
case GATEWAY:
gaService.setLocationAndSize(image, (width - IMAGE_SIZE) / 2, (height - IMAGE_SIZE) / 2, IMAGE_SIZE, IMAGE_SIZE);
break;
case EVENT:
gaService.setLocationAndSize(image, (width - IMAGE_SIZE) / 2, (height - IMAGE_SIZE) / 2, IMAGE_SIZE, IMAGE_SIZE);
break;
}
}
// add a chopbox anchor to the shape
peCreateService.createChopboxAnchor(containerShape);
// create an additional box relative anchor at middle-right
final BoxRelativeAnchor boxAnchor = peCreateService.createBoxRelativeAnchor(containerShape);
boxAnchor.setRelativeWidth(1.0);
boxAnchor.setRelativeHeight(0.51);
boxAnchor.setReferencedGraphicsAlgorithm(algorithm);
final Ellipse ellipse = ActivitiUiUtil.createInvisibleEllipse(boxAnchor, gaService);
gaService.setLocationAndSize(ellipse, 0, 0, 0, 0);
layoutPictogramElement(containerShape);
return containerShape;
}Example 4
| Project: cdo-master File: AcoreBasicAddElementFeature.java View source code |
public PictogramElement add(IAddContext context) {
ABasicClass addedClass = (ABasicClass) context.getNewObject();
Diagram targetDiagram = (Diagram) context.getTargetContainer();
// CONTAINER SHAPE WITH ROUNDED RECTANGLE
IPeCreateService peCreateService = Graphiti.getPeCreateService();
// define a default size for the shape
int width = 100;
int height = 50;
IGaService gaService = Graphiti.getGaService();
addToResourceIfNeeded(addedClass);
ContainerShape containerShape = createContainerShape(context, addedClass, targetDiagram, peCreateService, width, height, gaService);
return containerShape;
}Example 5
| Project: Security-Service-Validation-and-Verification-master File: AddSecurityFlowFeature.java View source code |
@SuppressWarnings("unchecked")
public PictogramElement add(IAddContext context) {
IAddConnectionContext addConContext = (IAddConnectionContext) context;
SecurityFlow addedSecurityFlow = (SecurityFlow) context.getNewObject();
Anchor sourceAnchor = null;
Anchor targetAnchor = null;
if (addConContext.getSourceAnchor() == null) {
EList<Shape> shapeList = getDiagram().getChildren();
for (Shape shape : shapeList) {
FlowNode flowNode = (FlowNode) getBusinessObjectForPictogramElement(shape.getGraphicsAlgorithm().getPictogramElement());
if (flowNode == null || flowNode.getId() == null || addedSecurityFlow.getSourceRefNode() == null || addedSecurityFlow.getTargetRefNode() == null)
continue;
if (flowNode.getId().equals(addedSecurityFlow.getSourceRefNode().getId())) {
EList<Anchor> anchorList = ((ContainerShape) shape).getAnchors();
for (Anchor anchor : anchorList) {
if (anchor instanceof ChopboxAnchor) {
sourceAnchor = anchor;
break;
}
}
}
if (flowNode.getId().equals(addedSecurityFlow.getTargetRefNode().getId())) {
EList<Anchor> anchorList = ((ContainerShape) shape).getAnchors();
for (Anchor anchor : anchorList) {
if (anchor instanceof ChopboxAnchor) {
targetAnchor = anchor;
break;
}
}
}
}
} else {
sourceAnchor = addConContext.getSourceAnchor();
targetAnchor = addConContext.getTargetAnchor();
}
if (sourceAnchor == null || targetAnchor == null) {
return null;
}
boolean inSubProcess = false;
Object parentObject = null;
ContainerShape parentShape = null;
if (sourceAnchor.eContainer() instanceof ContainerShape) {
parentShape = (ContainerShape) sourceAnchor.eContainer().eContainer();
parentObject = getBusinessObjectForPictogramElement(parentShape.getGraphicsAlgorithm().getPictogramElement());
if (parentObject != null && parentObject instanceof SubProcess == false) {
parentShape = (ContainerShape) targetAnchor.eContainer().eContainer();
parentObject = getBusinessObjectForPictogramElement(parentShape.getGraphicsAlgorithm().getPictogramElement());
}
}
if (parentObject != null && parentObject instanceof SubProcess) {
inSubProcess = true;
}
IPeCreateService peCreateService = Graphiti.getPeCreateService();
// CONNECTION WITH POLYLINE
FreeFormConnection connection = peCreateService.createFreeFormConnection(getDiagram());
connection.setStart(sourceAnchor);
connection.setEnd(targetAnchor);
sourceAnchor.getOutgoingConnections().add(connection);
targetAnchor.getIncomingConnections().add(connection);
GraphicsAlgorithm sourceGraphics = getPictogramElement(addedSecurityFlow.getSourceRefNode()).getGraphicsAlgorithm();
GraphicsAlgorithm targetGraphics = getPictogramElement(addedSecurityFlow.getTargetRefNode()).getGraphicsAlgorithm();
List<GraphicInfo> bendpointList = null;
if (addConContext.getProperty("org.activiti.designer.bendpoints") != null) {
bendpointList = (List<GraphicInfo>) addConContext.getProperty("org.activiti.designer.bendpoints");
}
if (bendpointList != null && bendpointList.size() >= 0) {
for (GraphicInfo graphicInfo : bendpointList) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
if (inSubProcess == true) {
bendPoint.setX(parentShape.getGraphicsAlgorithm().getX() + graphicInfo.x);
bendPoint.setY(parentShape.getGraphicsAlgorithm().getY() + graphicInfo.y);
} else {
bendPoint.setX(graphicInfo.x);
bendPoint.setY(graphicInfo.y);
}
connection.getBendpoints().add(bendPoint);
}
} else {
/*if (addedSequenceFlow.getSourceRef() instanceof Gateway && addedSequenceFlow.getTargetRef() instanceof Gateway == false) {
if (((sourceGraphics.getY() + 10) < targetGraphics.getY()
|| (sourceGraphics.getY() - 10) > targetGraphics.getY()) &&
(sourceGraphics.getX() + (sourceGraphics.getWidth() / 2)) < targetGraphics.getX()) {
boolean subProcessWithBendPoint = false;
if(addedSequenceFlow.getTargetRef() instanceof SubProcess) {
int middleSub = targetGraphics.getY() + (targetGraphics.getHeight() / 2);
if((sourceGraphics.getY() + 20) < middleSub || (sourceGraphics.getY() - 20) > middleSub) {
subProcessWithBendPoint = true;
}
}
if(addedSequenceFlow.getTargetRef() instanceof SubProcess == false || subProcessWithBendPoint == true) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
if(inSubProcess == true) {
bendPoint.setX(parentShape.getGraphicsAlgorithm().getX() + sourceGraphics.getX() + 20);
bendPoint.setY(parentShape.getGraphicsAlgorithm().getY() + targetGraphics.getY() + (targetGraphics.getHeight() / 2));
} else {
bendPoint.setX(sourceGraphics.getX() + 20);
bendPoint.setY(targetGraphics.getY() + (targetGraphics.getHeight() / 2));
}
connection.getBendpoints().add(bendPoint);
}
}
} else if (addedSequenceFlow.getTargetRef() instanceof Gateway) {
if (((sourceGraphics.getY() + 10) < targetGraphics.getY()
|| (sourceGraphics.getY() - 10) > targetGraphics.getY()) &&
(sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX()) {
boolean subProcessWithBendPoint = false;
if(addedSequenceFlow.getSourceRef() instanceof SubProcess) {
int middleSub = sourceGraphics.getY() + (sourceGraphics.getHeight() / 2);
if((middleSub + 20) < targetGraphics.getY() || (middleSub - 20) > targetGraphics.getY()) {
subProcessWithBendPoint = true;
}
}
if(addedSequenceFlow.getSourceRef() instanceof SubProcess == false || subProcessWithBendPoint == true) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
if(inSubProcess == true) {
bendPoint.setX(parentShape.getGraphicsAlgorithm().getX() + targetGraphics.getX() + 20);
bendPoint.setY(parentShape.getGraphicsAlgorithm().getY() + sourceGraphics.getY() + (sourceGraphics.getHeight() / 2));
} else {
bendPoint.setX(targetGraphics.getX() + 20);
bendPoint.setY(sourceGraphics.getY() + (sourceGraphics.getHeight() / 2));
}
connection.getBendpoints().add(bendPoint);
}
}
} else if (addedSequenceFlow.getTargetRef() instanceof EndEvent) {
int middleSource = sourceGraphics.getY() + (sourceGraphics.getHeight() / 2);
int middleTarget = targetGraphics.getY() + (targetGraphics.getHeight() / 2);
if (((middleSource + 10) < middleTarget &&
(sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX()) ||
((middleSource - 10) > middleTarget &&
(sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX())) {
Point bendPoint = StylesFactory.eINSTANCE.createPoint();
if(inSubProcess == true) {
bendPoint.setX(parentShape.getGraphicsAlgorithm().getX() + targetGraphics.getX() + (targetGraphics.getWidth() / 2));
bendPoint.setY(parentShape.getGraphicsAlgorithm().getY() + sourceGraphics.getY() + (sourceGraphics.getHeight() / 2));
} else {
bendPoint.setX(targetGraphics.getX() + (targetGraphics.getWidth() / 2));
bendPoint.setY(sourceGraphics.getY() + (sourceGraphics.getHeight() / 2));
}
connection.getBendpoints().add(bendPoint);
}
}*/
}
IGaService gaService = Graphiti.getGaService();
Polyline polyline = gaService.createPolyline(connection);
polyline.setLineStyle(LineStyle.SOLID);
polyline.setForeground(Graphiti.getGaService().manageColor(getDiagram(), IColorConstant.LIGHT_BLUE));
// create link and wire it
link(connection, addedSecurityFlow);
// add dynamic text decorator for the reference name
ConnectionDecorator textDecorator = peCreateService.createConnectionDecorator(connection, true, 0.5, true);
Text text = gaService.createDefaultText(getDiagram(), textDecorator);
text.setStyle(StyleUtil.getStyleForTask((getDiagram())));
gaService.setLocation(text, 10, 0);
// set reference name in the text decorator
SecurityFlow securityFlow = (SecurityFlow) context.getNewObject();
text.setValue(securityFlow.getName());
// add static graphical decorators (composition and navigable)
ConnectionDecorator cd = peCreateService.createConnectionDecorator(connection, false, 1.0, true);
createArrow(cd);
return connection;
}Example 6
| Project: CertWare-master File: ObjectAddFeature.java View source code |
public PictogramElement add(IAddContext context) {
final net.certware.sacm.SACM.Evidence.Object addedObject = (Object) context.getNewObject();
final ContainerShape parent = context.getTargetContainer();
// container shape with circle
final IPeCreateService peCreateService = Graphiti.getPeCreateService();
final ContainerShape containerShape = peCreateService.createContainerShape(parent, true);
// use existing size or default
final int width = context.getWidth() <= 35 ? 35 : context.getWidth();
final int height = context.getHeight() <= 50 ? 50 : context.getHeight();
final IGaService gaService = Graphiti.getGaService();
@SuppressWarnings("unused") Ellipse circle;
{
final Ellipse objectCircle = gaService.createEllipse(containerShape);
//invisibleCircle.setFilled(false);
//invisibleCircle.setLineVisible(false);
gaService.setLocationAndSize(objectCircle, context.getX(), context.getY(), width, height);
objectCircle.setLineWidth(2);
objectCircle.setLineVisible(true);
objectCircle.setFilled(true);
objectCircle.setLineStyle(LineStyle.DASHDOT);
objectCircle.setForeground(manageColor(IColorConstant.BLACK));
objectCircle.setBackground(manageColor(IColorConstant.DARK_ORANGE));
// create and set visible circle inside invisible circle
//circle = gaService.createEllipse(objectCircle);
//circle.setParentGraphicsAlgorithm(objectCircle);
// TODO circle.setStyle(StyleUtil.getStyleForEvent(getDiagram()));
//if (addedArgumentation instanceof EndEvent == true) {
// circle.setLineWidth(3);
//}
//gaService.setLocationAndSize(circle, 0, 0, width, height);
//gaService.setLocationAndSize(circle, 0, 0, width, height);
link(containerShape, addedObject);
}
peCreateService.createChopboxAnchor(containerShape);
/*
if ( !(addedArgumentation instanceof EndEvent)) {
// create an additional box relative anchor at middle-right
final BoxRelativeAnchor boxAnchor = peCreateService.createBoxRelativeAnchor(containerShape);
boxAnchor.setRelativeWidth(1.0);
boxAnchor.setRelativeHeight(0.51);
boxAnchor.setReferencedGraphicsAlgorithm(circle);
final Ellipse ellipse = ActivitiUiUtil.createInvisibleEllipse(boxAnchor, gaService);
gaService.setLocationAndSize(ellipse, 0, 0, 0, 0);
}
*/
/*
if (addedEvent instanceof StartEvent && ((StartEvent) addedEvent).getEventDefinitions().size() > 0) {
StartEvent startEvent = (StartEvent) addedEvent;
final Shape shape = peCreateService.createShape(containerShape, false);
Image image = null;
if (startEvent.getEventDefinitions().get(0) instanceof TimerEventDefinition) {
image = gaService.createImage(shape, PluginImage.IMG_BOUNDARY_TIMER.getImageKey());
} else if (startEvent.getEventDefinitions().get(0) instanceof MessageEventDefinition){
image = gaService.createImage(shape, PluginImage.IMG_STARTEVENT_MESSAGE.getImageKey());
} else
image = gaService.createImage(shape, PluginImage.IMG_BOUNDARY_ERROR.getImageKey());
image.setWidth(IMAGE_SIZE);
image.setHeight(IMAGE_SIZE);
gaService.setLocationAndSize(image, (width - IMAGE_SIZE) / 2, (height - IMAGE_SIZE) / 2, IMAGE_SIZE, IMAGE_SIZE);
}
*/
layoutPictogramElement(containerShape);
return containerShape;
}Example 7
| Project: BPMN2-Editor-for-Eclipse-master File: AddParticipantFeature.java View source code |
@Override
public PictogramElement add(IAddContext context) {
Participant p = (Participant) context.getNewObject();
IGaService gaService = Graphiti.getGaService();
IPeService peService = Graphiti.getPeService();
Diagram targetDiagram = (Diagram) context.getTargetContainer();
IPeCreateService peCreateService = Graphiti.getPeCreateService();
ContainerShape containerShape = peCreateService.createContainerShape(targetDiagram, true);
int width = context.getWidth() > 0 ? context.getWidth() : 600;
int height = context.getHeight() > 0 ? context.getHeight() : 100;
Rectangle rect = gaService.createRectangle(containerShape);
StyleUtil.applyBGStyle(rect, this);
gaService.setLocationAndSize(rect, context.getX(), context.getY(), width, height);
Shape lineShape = peCreateService.createShape(containerShape, false);
Polyline line = gaService.createPolyline(lineShape, new int[] { 15, 0, 15, height });
line.setForeground(manageColor(StyleUtil.CLASS_FOREGROUND));
Shape textShape = peCreateService.createShape(containerShape, false);
Text text = gaService.createText(textShape, p.getName());
text.setStyle(StyleUtil.getStyleForText(getDiagram()));
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setAngle(-90);
gaService.setLocationAndSize(text, 0, 0, 15, height);
peService.setPropertyValue(containerShape, MULTIPLICITY, Boolean.toString(false));
createDIShape(containerShape, p);
link(textShape, p);
peCreateService.createChopboxAnchor(containerShape);
AnchorUtil.addFixedPointAnchors(containerShape, rect);
updatePictogramElement(containerShape);
layoutPictogramElement(containerShape);
return containerShape;
}Example 8
| Project: Disco-Build-System-master File: FileGroupPattern.java View source code |
/*-------------------------------------------------------------------------------------*/
/**
* Add a new pictogram, representing a UIFileGroup, onto a Graphiti Diagram.
*
* @param targetDiagram The Diagram to add the pictogram to.
* @param addedFileGroup The UIFileGroup to add a pictogram for.
* @param x The X location within the Diagram.
* @param y The Y location within the Diagram.
* @return The ContainerShape representing the FileGroup pictogram.
*/
private PictogramElement renderPictogram(Diagram targetDiagram, UIFileGroup addedFileGroup, int x, int y) {
IFileGroupMgr fileGroupMgr = buildStore.getFileGroupMgr();
int fileGroupId = addedFileGroup.getId();
int fileGroupType = fileGroupMgr.getGroupType(fileGroupId);
/*
* How many boxes will be shown? This helps us distinguish between file groups
* containing a single file, versus multiple files. With multiple files, we
* draw a second page that appears behind the front page.
*/
int groupSize = fileGroupMgr.getGroupSize(addedFileGroup.getId());
if (groupSize <= 0) {
return null;
/* an empty file group (or an errored file group) shouldn't be shown */
}
/*
* We can show a limited number of file names in the pictogram. If more than our
* maximum, display the last name as "...". For merge file groups, we don't show file
* names underneath the pictogram.
*/
int fileNamesToShow;
if (fileGroupType == IFileGroupMgr.MERGE_GROUP) {
fileNamesToShow = 0;
} else {
fileNamesToShow = (groupSize <= MAX_LABELS_TO_SHOW) ? groupSize : MAX_LABELS_TO_SHOW;
}
/* create a container that holds the pictogram */
IPeCreateService peCreateService = Graphiti.getPeCreateService();
IGaService gaService = Graphiti.getGaService();
ContainerShape containerShape = peCreateService.createContainerShape(targetDiagram, true);
/*
* Create an invisible outer rectangle. The smaller polygons and labels will be placed
* inside this. The width is always twice that of the polygon, to allow for long file
* names to be shown underneath the polygons. The height is carefully selected to allow
* for enough labels, as well as for the possible "second page" polygon.
*/
Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
gaService.setLocationAndSize(invisibleRectangle, x, y, 2 * FILE_GROUP_WIDTH, FILE_GROUP_HEIGHT + ((groupSize < 2) ? 0 : FILE_GROUP_OVERLAP) + ((fileNamesToShow + 1) * (LABEL_FONT_SIZE + LABEL_FONT_GAP)));
/*
* Create the visible file icon within the outer shape. First, consider whether
* a second page (with no corner bend) should be shown in the background.
*/
if (groupSize > 1) {
Polygon box = gaService.createPolygon(invisibleRectangle, coordsPage2);
box.setForeground(manageColor(LINE_COLOUR));
box.setBackground(manageColor(FILL_COLOUR));
box.setLineWidth(2);
}
/* now the front page, with the corner bent */
Polygon box = gaService.createPolygon(invisibleRectangle, coordsPage1);
box.setForeground(manageColor(LINE_COLOUR));
box.setBackground(manageColor(FILL_COLOUR));
box.setLineWidth(2);
Polygon boxCorner = gaService.createPolygon(invisibleRectangle, coordsCorner);
boxCorner.setForeground(manageColor(LINE_COLOUR));
boxCorner.setBackground(manageColor(FILL_CORNER_COLOUR));
boxCorner.setLineWidth(2);
/*
* For source/generated groups, display the file group's content (or at least part
* of it) under the file box. We can only show a limited number of file names. If
* there are too many to show, the last label must be "...".
*/
if (fileGroupType != IFileGroupMgr.MERGE_GROUP) {
for (int i = 0; i != fileNamesToShow; i++) {
String value;
if ((i == (MAX_LABELS_TO_SHOW - 1)) && (groupSize > MAX_LABELS_TO_SHOW)) {
value = "...";
} else {
/* fetch this particular file's base name */
int pathId = fileGroupMgr.getPathId(fileGroupId, i);
if (pathId < 0) {
value = "";
} else {
value = fileMgr.getBaseName(pathId);
}
}
/* draw the label underneath the main "page" polygon */
Text fileNames = gaService.createText(getDiagram(), invisibleRectangle, value, LABEL_FONT, LABEL_FONT_SIZE);
fileNames.setFilled(false);
fileNames.setForeground(manageColor(TEXT_FOREGROUND));
fileNames.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
gaService.setLocationAndSize(fileNames, 0, FILE_GROUP_HEIGHT + ((1 + i) * (LABEL_FONT_SIZE + LABEL_FONT_GAP)), FILE_GROUP_WIDTH * 2, (LABEL_FONT_SIZE + LABEL_FONT_GAP));
}
} else /*
* For merge groups, we draw three extra lines inside the file group box as
* an indication to the user that it's a merge group.
*/
{
for (int i = 0; i < coordsMergeLines.length; i++) {
Polyline mergeLine = gaService.createPolyline(invisibleRectangle, coordsMergeLines[i]);
mergeLine.setForeground(manageColor(LINE_COLOUR));
mergeLine.setBackground(manageColor(FILL_COLOUR));
mergeLine.setLineWidth(1);
}
}
/*
* Add anchors that reside to the immediate left/right of the file group box.
* There are for drawing connection arrows.
* UIFileActionConnection.INPUT_TO_ACTION (0) - right anchor
* UIFileActionConnection.OUTPUT_FROM_ACTION (1) - left anchor
*/
FixPointAnchor rightAnchor = peCreateService.createFixPointAnchor(containerShape);
rightAnchor.setLocation(gaService.createPoint(OFF_X + FILE_GROUP_WIDTH + (FILE_GROUP_OVERLAP * 2), FILE_GROUP_HEIGHT / 2));
gaService.createInvisibleRectangle(rightAnchor);
FixPointAnchor leftAnchor = peCreateService.createFixPointAnchor(containerShape);
leftAnchor.setLocation(gaService.createPoint(OFF_X, FILE_GROUP_HEIGHT / 2));
gaService.createInvisibleRectangle(leftAnchor);
/* create a link between the shape and the business object, and display it. */
link(containerShape, addedFileGroup);
layoutPictogramElement(containerShape);
return containerShape;
}Example 9
| Project: org.eclipse.etrice-master File: TrPointSupport.java View source code |
@Override
public PictogramElement add(IAddContext context) {
TrPoint tp = (TrPoint) context.getNewObject();
ContainerShape parentShape = context.getTargetContainer();
Object bo = getBusinessObjectForPictogramElement(parentShape);
boolean inherited = isInherited(tp, bo, parentShape);
boolean subtp = (bo instanceof State);
int margin = subtp ? StateSupport.MARGIN : StateGraphSupport.MARGIN;
int size = subtp ? ITEM_SIZE_SMALL : ITEM_SIZE;
// CONTAINER SHAPE WITH RECTANGLE
IPeCreateService peCreateService = Graphiti.getPeCreateService();
ContainerShape containerShape = peCreateService.createContainerShape(parentShape, true);
Graphiti.getPeService().setPropertyValue(containerShape, Constants.TYPE_KEY, Constants.TRP_TYPE);
String kind = getItemKind(tp);
Graphiti.getPeService().setPropertyValue(containerShape, PROP_KIND, kind);
// the context point is the midpoint relative to the invisible rectangle
int x = context.getX();
int y = context.getY();
int width = parentShape.getGraphicsAlgorithm().getWidth();
int height = parentShape.getGraphicsAlgorithm().getHeight();
{
int dx = (x <= width / 2) ? x : width - x;
int dy = (y <= height / 2) ? y : height - y;
if (dx > dy) {
// keep x, project y
if (y <= height / 2)
y = margin;
else
y = height - margin;
if (x < margin)
x = margin;
else if (x > width - margin)
x = width - margin;
} else {
// keep y, project x
if (x <= width / 2)
x = margin;
else
x = width - margin;
if (y < margin)
y = margin;
else if (y > height - margin)
y = height - margin;
}
// finally we subtract the midpoint to get coordinates of the upper left corner
x -= margin;
y -= margin;
}
Color dark = manageColor(inherited ? INHERITED_COLOR : DARK_COLOR);
IGaService gaService = Graphiti.getGaService();
{
final Rectangle invisibleRectangle = gaService.createInvisibleRectangle(containerShape);
gaService.setLocationAndSize(invisibleRectangle, x, y, 2 * margin, 2 * margin);
createFigure(tp, subtp, containerShape, invisibleRectangle, dark, manageColor(BRIGHT_COLOR));
// create link and wire it
link(containerShape, tp);
}
{
Shape labelShape = peCreateService.createShape(containerShape, false);
Text label = gaService.createDefaultText(labelShape, tp.getName());
label.setForeground(dark);
label.setBackground(dark);
label.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
label.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
gaService.setLocationAndSize(label, 0, 3 * margin / 2, 2 * margin, margin / 2);
adjustLabel(label, x, y, width, margin, size);
}
if (!subtp)
createParentTP(tp, containerShape, parentShape);
// call the layout feature
layoutPictogramElement(containerShape);
return containerShape;
}Example 10
| Project: spray-master File: AddShapeFeature.java View source code |
public StringConcatenation mainFile(final Container container, final String className) {
StringConcatenation _builder = new StringConcatenation();
String _constainerClass = GeneratorUtil.constainerClass(container);
String containerType = _constainerClass;
_builder.newLineIfNotEmpty();
StringConcatenation _header = this.header(this);
_builder.append(_header, "");
_builder.newLineIfNotEmpty();
_builder.append("package ");
String _feature_package = GeneratorUtil.feature_package();
_builder.append(_feature_package, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import ");
MetaClass _represents = container.getRepresents();
String _javaInterfaceName = this.naming.getJavaInterfaceName(_represents);
_builder.append(_javaInterfaceName, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("import org.eclipse.graphiti.features.IFeatureProvider;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.features.context.IAddContext;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.features.context.IContext;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.mm.algorithms.Text;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.mm.algorithms.Polyline;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.mm.algorithms.styles.Orientation;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.mm.pictograms.ContainerShape;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.mm.pictograms.Diagram;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.mm.pictograms.PictogramElement;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.mm.pictograms.Shape;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.services.Graphiti;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.services.IGaService;");
_builder.newLine();
_builder.append("import org.eclipse.graphiti.services.IPeCreateService;");
_builder.newLine();
_builder.append("import ");
String _util_package = GeneratorUtil.util_package();
_builder.append(_util_package, "");
_builder.append(".ISprayContainer;");
_builder.newLineIfNotEmpty();
_builder.append("import ");
String _util_package_1 = GeneratorUtil.util_package();
_builder.append(_util_package_1, "");
_builder.append(".");
_builder.append(containerType, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("import ");
String _util_package_2 = GeneratorUtil.util_package();
_builder.append(_util_package_2, "");
_builder.append(".SprayContainerService;");
_builder.newLineIfNotEmpty();
_builder.append("// MARKER_IMPORT");
_builder.newLine();
_builder.newLine();
_builder.append("public class ");
_builder.append(className, "");
_builder.append(" extends AbstractAddShapeFeature {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append(" ");
_builder.append("protected final static String typeOrAliasName = \"");
MetaClass _represents_1 = container.getRepresents();
String _visibleName = GeneratorUtil.visibleName(_represents_1);
_builder.append(_visibleName, " ");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append(" ");
_builder.append("protected Diagram targetDiagram = null;");
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.append("protected ");
_builder.append(containerType, " ");
_builder.append(" container = null;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append(" ");
_builder.append("protected IGaService gaService = null;");
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.append("public ");
_builder.append(className, " ");
_builder.append("(IFeatureProvider fp) {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("super(fp);");
_builder.newLine();
_builder.append(" ");
_builder.append("container = new ");
_builder.append(containerType, " ");
_builder.append("();");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("gaService = Graphiti.getGaService();");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.append("public boolean canAdd(IAddContext context) {");
_builder.newLine();
_builder.append(" ");
_builder.append("final Object newObject = context.getNewObject();");
_builder.newLine();
_builder.append(" ");
_builder.append("if (newObject instanceof ");
MetaClass _represents_2 = container.getRepresents();
String _name = this.e1.getName(_represents_2);
_builder.append(_name, " ");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("// check if user wants to add to a diagram");
_builder.newLine();
_builder.append(" ");
_builder.append("if (context.getTargetContainer() instanceof Diagram) {");
_builder.newLine();
_builder.append(" ");
_builder.append("return true;");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("return false;");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.append("public PictogramElement add(IAddContext context) {");
_builder.newLine();
_builder.append(" ");
MetaClass _represents_3 = container.getRepresents();
String _name_1 = this.e1.getName(_represents_3);
_builder.append(_name_1, " ");
_builder.append(" addedModelElement = (");
MetaClass _represents_4 = container.getRepresents();
String _name_2 = this.e1.getName(_represents_4);
_builder.append(_name_2, " ");
_builder.append(") context.getNewObject();");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("targetDiagram = Graphiti.getPeService().getDiagramForShape(context.getTargetContainer());");
_builder.newLine();
_builder.append(" ");
_builder.append("IPeCreateService peCreateService = Graphiti.getPeCreateService();");
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.append("ContainerShape containerShape = container.createContainer(context, addedModelElement);");
_builder.newLine();
{
boolean _hasFillColor = this.e2.hasFillColor(container);
if (_hasFillColor) {
_builder.append(" ");
_builder.append("GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();");
_builder.newLine();
_builder.append(" ");
_builder.append("containerGa.setBackground(manageColor(");
String _fillColor = this.e2.fillColor(container);
_builder.append(_fillColor, " ");
_builder.append("));");
_builder.newLineIfNotEmpty();
}
}
_builder.append(" ");
_builder.append("ContainerShape textContainer = SprayContainerService.findTextShape(containerShape);");
_builder.newLine();
_builder.append(" ");
_builder.append("link(containerShape, addedModelElement);");
_builder.newLine();
_builder.newLine();
{
SprayElement[] _parts = container.getParts();
for (final SprayElement part : _parts) {
{
if ((part instanceof Line)) {
Line line = ((Line) part);
_builder.newLineIfNotEmpty();
_builder.append("// Part is Line");
_builder.newLine();
_builder.append("{");
_builder.newLine();
_builder.append(" ");
_builder.append("// create shape for line");
_builder.newLine();
_builder.append(" ");
_builder.append("Shape shape = peCreateService.createShape(textContainer, false);");
_builder.newLine();
_builder.append(" ");
_builder.append("// create and set graphics algorithm");
_builder.newLine();
_builder.append(" ");
_builder.append("Polyline polyline = gaService.createPolyline(shape, new int[] { 0, 0, 0, 0 });");
_builder.newLine();
_builder.append(" ");
_builder.append("polyline.setForeground(manageColor(");
String _lineColor = this.e2.lineColor(line);
_builder.append(_lineColor, " ");
_builder.append(" ));");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("polyline.setLineWidth(");
Layout _layout = line.getLayout();
int _lineWidth = _layout.getLineWidth();
_builder.append(_lineWidth, " ");
_builder.append(");");
_builder.newLineIfNotEmpty();
{
Layout _layout_1 = line.getLayout();
int _lineWidth_1 = _layout_1.getLineWidth();
boolean _operator_equals = ObjectExtensions.operator_equals(((Integer) _lineWidth_1), ((Integer) 0));
if (_operator_equals) {
_builder.append("polyline.setLineVisible(false);");
_builder.newLine();
}
}
_builder.append(" ");
_builder.append("gaService.setLocation(polyline, 0, 0);");
_builder.newLine();
_builder.append(" ");
_builder.append("Graphiti.getPeService().setPropertyValue(shape, ISprayContainer.CONCEPT_SHAPE_KEY, ISprayContainer.LINE);");
_builder.newLine();
_builder.append("}");
_builder.newLine();
} else {
if ((part instanceof Text)) {
Text text = ((Text) part);
_builder.newLineIfNotEmpty();
_builder.append("// Part is Text");
_builder.newLine();
_builder.append("{");
_builder.newLine();
_builder.append(" ");
_builder.append("String type = \"");
QualifiedName _fullyQualifiedName = this.e3.getFullyQualifiedName(text);
_builder.append(_fullyQualifiedName, " ");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("// create shape for text and set text graphics algorithm");
_builder.newLine();
_builder.append(" ");
_builder.append("Shape shape = peCreateService.createShape(textContainer, false);");
_builder.newLine();
_builder.append(" ");
_builder.append("Text text = gaService.createDefaultText(getDiagram(), shape);");
_builder.newLine();
_builder.append(" ");
_builder.append("text.setFont(gaService.manageFont(getDiagram(), text.getFont().getName(), 12));");
_builder.newLine();
_builder.append(" ");
_builder.append("text.setForeground(manageColor(");
String _lineColor_1 = this.e2.lineColor(text);
_builder.append(_lineColor_1, " ");
_builder.append("));");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);");
_builder.newLine();
_builder.append(" ");
_builder.append("text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);");
_builder.newLine();
{
Layout _layout_2 = text.getLayout();
boolean _isBold = _layout_2.isBold();
if (_isBold) {
_builder.append("text.getFont().setBold(true);");
_builder.newLine();
}
}
{
Layout _layout_3 = text.getLayout();
boolean _isItalic = _layout_3.isItalic();
if (_isItalic) {
_builder.append("text.getFont().setItalic(true);");
_builder.newLine();
}
}
_builder.append(" ");
_builder.append("gaService.setLocationAndSize(text, 0, 0, 0, 0);");
_builder.newLine();
_builder.append(" ");
_builder.append("Graphiti.getPeService().setPropertyValue(shape, \"MODEL_TYPE\", type);");
_builder.newLine();
_builder.append(" ");
_builder.append("Graphiti.getPeService().setPropertyValue(shape, ISprayContainer.CONCEPT_SHAPE_KEY, ISprayContainer.TEXT);");
_builder.newLine();
_builder.append(" ");
_builder.append("// create link and wire it");
_builder.newLine();
_builder.append(" ");
_builder.append("link(shape, addedModelElement);");
_builder.newLine();
_builder.append("}");
_builder.newLine();
} else {
if ((part instanceof MetaReference)) {
final MetaReference metaRef = ((MetaReference) part);
_builder.newLineIfNotEmpty();
EReference _reference = metaRef.getReference();
final EReference eReference = _reference;
_builder.append(" ");
_builder.newLineIfNotEmpty();
_builder.append("// Part is reference list");
_builder.newLine();
_builder.append("{");
_builder.newLine();
_builder.append(" ");
_builder.append("// Create a dummy invisible line to have an ancjhor point for adding new elements to the list");
_builder.newLine();
_builder.append(" ");
_builder.append("Shape dummy = peCreateService.createShape(textContainer, false);");
_builder.newLine();
_builder.append(" ");
_builder.append("Graphiti.getPeService().setPropertyValue(dummy, \"MODEL_TYPE\", \"");
EClass _eReferenceType = eReference.getEReferenceType();
String _name_3 = _eReferenceType.getName();
_builder.append(_name_3, " ");
_builder.append("\");");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("Polyline p = gaService.createPolyline(dummy, new int[] { 0, 0, 0, 0 });");
_builder.newLine();
_builder.append(" ");
_builder.append("p.setForeground(manageColor(");
String _shortName = this.shortName(org.eclipse.graphiti.util.IColorConstant.class);
_builder.append(_shortName, " ");
_builder.append(".BLACK));");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("p.setLineWidth(0);");
_builder.newLine();
_builder.append(" ");
_builder.append("p.setLineVisible(false);");
_builder.newLine();
_builder.append(" ");
_builder.append("gaService.setLocation(p, 0, 0);");
_builder.newLine();
_builder.append(" ");
_builder.append("Graphiti.getPeService().setPropertyValue(dummy, ISprayContainer.CONCEPT_SHAPE_KEY, ISprayContainer.LINE);");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("for (");
EClass _eReferenceType_1 = eReference.getEReferenceType();
String _javaInterfaceName_1 = this.naming.getJavaInterfaceName(_eReferenceType_1);
String _shortName_1 = this.shortName(_javaInterfaceName_1);
_builder.append(_shortName_1, "");
_builder.append(" p : addedModelElement.get");
String _name_4 = eReference.getName();
String _firstUpper = StringExtensions.toFirstUpper(_name_4);
_builder.append(_firstUpper, "");
_builder.append("()) {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("Shape shape = peCreateService.createContainerShape(textContainer, true);");
_builder.newLine();
_builder.append(" ");
_builder.append("Graphiti.getPeService().setPropertyValue(shape, \"STATIC\", \"true\");");
_builder.newLine();
_builder.append(" ");
_builder.append("Graphiti.getPeService().setPropertyValue(shape, \"MODEL_TYPE\", \"");
EClass _eReferenceType_2 = eReference.getEReferenceType();
String _name_5 = _eReferenceType_2.getName();
_builder.append(_name_5, " ");
_builder.append("\");");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("Graphiti.getPeService().setPropertyValue(shape, ISprayContainer.CONCEPT_SHAPE_KEY, ISprayContainer.TEXT);");
_builder.newLine();
_builder.append(" ");
_builder.append("// create and set text graphics algorithm");
_builder.newLine();
_builder.append(" ");
_builder.append("Text text = gaService.createDefaultText(getDiagram(), shape, p.get");
String _labelPropertyName = this.e1.getLabelPropertyName(metaRef);
String _firstUpper_1 = StringExtensions.toFirstUpper(_labelPropertyName);
_builder.append(_firstUpper_1, " ");
_builder.append("());");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("// TODO should have a text color here, refer to representation of reference type");
_builder.newLine();
_builder.append(" ");
_builder.append("text.setForeground(manageColor(");
String _textColor = this.e2.textColor(container);
_builder.append(_textColor, " ");
_builder.append(")); ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("text.setHorizontalAlignment(Orientation.ALIGNMENT_LEFT);");
_builder.newLine();
_builder.append(" ");
_builder.append("text.setVerticalAlignment(Orientation.ALIGNMENT_TOP);");
_builder.newLine();
_builder.append(" ");
_builder.append("gaService.setLocationAndSize(text, 0, 0, 0, 0);");
_builder.newLine();
_builder.append(" ");
_builder.append("// create link and wire it");
_builder.newLine();
_builder.append(" ");
_builder.append("link(shape, p);");
_builder.newLine();
_builder.append("}");
_builder.newLine();
} else {
_builder.append("// TODO");
_builder.newLine();
_builder.append("System.out.println(\"Spray: unhandled Container child [");
Class<? extends Object> _class = part.getClass();
String _name_6 = _class.getName();
_builder.append(_name_6, "");
_builder.append("]\");");
_builder.newLineIfNotEmpty();
}
}
}
}
}
}
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("// add a chopbox anchor to the shape");
_builder.newLine();
_builder.append(" ");
_builder.append("peCreateService.createChopboxAnchor(containerShape);");
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.append("// call the update and layout features");
_builder.newLine();
_builder.append(" ");
_builder.append("updatePictogramElement(containerShape);");
_builder.newLine();
_builder.append(" ");
_builder.append("layoutPictogramElement(containerShape);");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("return containerShape;");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("@Override");
_builder.newLine();
_builder.append(" ");
_builder.append("public boolean hasDoneChanges() {");
_builder.newLine();
_builder.append(" ");
_builder.append("return false;");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.append("@Override");
_builder.newLine();
_builder.append(" ");
_builder.append("public boolean canUndo(IContext context) {");
_builder.newLine();
_builder.append(" ");
_builder.append("return false;");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}Example 11
| Project: orcc-master File: InstancePattern.java View source code |
@Override
public PictogramElement add(IAddContext context) {
final Diagram targetDiagram = (Diagram) context.getTargetContainer();
final IPeCreateService peCreateService = Graphiti.getPeCreateService();
final IGaService gaService = Graphiti.getGaService();
final Instance addedDomainObject = (Instance) context.getNewObject();
// Add the new Instance to the current Network
final Network network = (Network) getBusinessObjectForPictogramElement(getDiagram());
network.add(addedDomainObject);
// Create the container shape
final ContainerShape topLevelShape = peCreateService.createContainerShape(targetDiagram, true);
PropsUtil.setInstance(topLevelShape);
// Create the container graphic
final RoundedRectangle roundedRectangle = gaService.createPlainRoundedRectangle(topLevelShape, 5, 5);
roundedRectangle.setStyle(StyleUtil.basicInstanceShape(getDiagram()));
gaService.setLocationAndSize(roundedRectangle, context.getX(), context.getY(), TOTAL_MIN_WIDTH, TOTAL_MIN_HEIGHT);
// The text label for Instance name
final Text text = gaService.createPlainText(roundedRectangle);
PropsUtil.setIdentifier(text, LABEL_ID);
// Set properties on instance label
text.setStyle(StyleUtil.instanceText(getDiagram()));
gaService.setLocationAndSize(text, 0, 0, TOTAL_MIN_WIDTH, LABEL_HEIGHT);
if (addedDomainObject.getName() != null) {
text.setValue(addedDomainObject.getName());
}
// The line separator
final int[] xy = { 0, LABEL_HEIGHT, TOTAL_MIN_WIDTH, LABEL_HEIGHT };
final Polyline line = gaService.createPlainPolyline(roundedRectangle, xy);
PropsUtil.setIdentifier(line, SEP_ID);
line.setLineWidth(SEPARATOR);
// Configure direct editing
// 1- Get the IDirectEditingInfo object
final IDirectEditingInfo directEditingInfo = getFeatureProvider().getDirectEditingInfo();
// 2- These 2 members will be used to retrieve the pattern to call for
// direct editing
directEditingInfo.setPictogramElement(topLevelShape);
directEditingInfo.setGraphicsAlgorithm(text);
// 3- This PictogramElement is used to locate input on the diagram
directEditingInfo.setMainPictogramElement(topLevelShape);
// We link graphical representation and domain model object
link(topLevelShape, addedDomainObject);
if (addedDomainObject.getEntity() != null) {
updateRefinement(topLevelShape, addedDomainObject.getEntity());
}
return topLevelShape;
}Example 12
| Project: yang-ide-master File: YangModelUIUtil.java View source code |
public static Connection drawPictogramConnectionElement(IAddConnectionContext context, IFeatureProvider fp, String title) {
EObject addedEReference = (EObject) context.getNewObject();
IPeCreateService peCreateService = Graphiti.getPeCreateService();
Connection connection = peCreateService.createFreeFormConnection(fp.getDiagramTypeProvider().getDiagram());
connection.setStart(context.getSourceAnchor());
connection.setEnd(context.getTargetAnchor());
IGaService gaService = Graphiti.getGaService();
Polyline polyline = gaService.createPlainPolyline(connection);
polyline.setStyle(StyleUtil.getStyleForDomainObject(fp.getDiagramTypeProvider().getDiagram()));
// add dynamic text decorator for the reference name
ConnectionDecorator textDecorator = peCreateService.createConnectionDecorator(connection, false, 0.5, true);
Text text = gaService.createPlainText(textDecorator);
text.setStyle(StyleUtil.getStyleForTextDecorator(fp.getDiagramTypeProvider().getDiagram()));
gaService.setLocation(text, 10, 0);
// set reference name in the text decorator
text.setValue(title);
// add static graphical decorators (composition and inheritance)
if (YangModelUtil.checkType(YangModelUtil.MODEL_PACKAGE.getIdentity(), addedEReference)) {
createInheritanceConnectionArrow(connection, fp);
} else {
createConnectionArrow(connection, fp);
}
return connection;
}