org.eclipse.gmf.runtime.notation.DecorationNode Java Examples

The following examples show how to use org.eclipse.gmf.runtime.notation.DecorationNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addGateway(String id, final String name, final Point location, final Dimension size, final GatewayType gatewayType, final boolean displayLabel)
        throws ProcBuilderException {
    id = NamingUtils.convertToId(id);
    final IElementType type = resolveGatewayType(gatewayType);
    final Element createdElement = createShape(id, currentContainer, location, size, type);
    if (currentView != null && !currentView.getPersistedChildren().isEmpty()) {
        final Object decorator = currentView.getPersistedChildren().get(0);
        if (decorator instanceof DecorationNode) {
            commandStack.append(SetCommand.create(editingDomain, decorator, NotationPackage.Literals.VIEW__VISIBLE, displayLabel));
        }
    }
    commandStack.append(SetCommand.create(editingDomain, createdElement, ProcessPackage.eINSTANCE.getElement_Name(), name));

    currentStep = createdElement;
    currentElement = createdElement;

    steps.put(id, createdElement);
    execute();
}
 
Example #2
Source File: CrossflowViewProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
private Node createLabel(View owner, String hint) {
	DecorationNode rv = NotationFactory.eINSTANCE.createDecorationNode();
	rv.setType(hint);
	ViewUtil.insertChildView(owner, rv, ViewUtil.APPEND, true);
	return rv;
}
 
Example #3
Source File: FactoryUtils.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static Node createLabel(View owner, String hint) {
	DecorationNode nameLabel = NotationFactory.eINSTANCE.createDecorationNode();
	nameLabel.setType(hint);

	ShapeStyle style = NotationFactory.eINSTANCE.createShapeStyle();
	style.setFontColor(FigureUtilities.RGBToInteger(ColorConstants.black.getRGB()));
	nameLabel.getStyles().add(style);

	ViewUtil.insertChildView(owner, nameLabel, ViewUtil.APPEND, true);
	nameLabel.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
	return nameLabel;
}
 
Example #4
Source File: BPMNShapeFactory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public BPMNEdge createBPMNEdge(final String bpmnFlowId, EObject bonitaElement) {
    Edge bonitaEdge = modelExporter.getElementNotationEdge(bonitaElement);
    if (bonitaEdge != null) {
        final BPMNEdge edge = DiFactory.eINSTANCE.createBPMNEdge();
        edge.setBpmnElement(QName.valueOf(bpmnFlowId));
        edge.setId(modelExporter.getEObjectID(bonitaEdge));

        PolylineConnection conn = createConnectorFigure(bonitaEdge);
        PointList points = conn.getPoints();
        for (int i = 0; i < points.size(); i++) {
            final org.omg.spec.dd.dc.Point sourcePoint = DcFactory.eINSTANCE.createPoint();
            Point point = points.getPoint(i);
            sourcePoint.setX(point.x);
            sourcePoint.setY(point.y);
            edge.getWaypoint().add(sourcePoint);
        }

        if (bonitaElement instanceof SequenceFlow) {
            bonitaEdge.getPersistedChildren().stream()
                    .filter(DecorationNode.class::isInstance)
                    .findFirst()
                    .ifPresent(decorationNode -> attachEdgeLabel((DecorationNode) decorationNode, edge,
                            ((SequenceFlow) bonitaElement).getName(), bonitaEdge));
        }
        return edge;
    }
    return null;
}
 
Example #5
Source File: BPMNShapeFactory.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void attachEdgeLabel(final DecorationNode decorationNode, final BPMNEdge edge, String labelText,
        Edge bonitaEdge) {
    Font font = createFont(bonitaEdge);
    if (font != null) {
        final BPMNLabel label = DiFactory.eINSTANCE.createBPMNLabel();
        Location relativeLocation = (Location) decorationNode.getLayoutConstraint();

        Point offSet = new Point(relativeLocation.getX(), relativeLocation.getY());
        org.eclipse.gmf.runtime.notation.Bounds absoluteBounds = NotationFactory.eINSTANCE.createBounds();
        PointList pList = new PointList();
        edge.getWaypoint().stream().map(wayPoint -> new PrecisionPoint(wayPoint.getX(), wayPoint.getY()))
                .forEach(pList::addPoint);

        Point referencePoint = PointListUtilities.calculatePointRelativeToLine(pList, 0,
                LabelViewConstants.MIDDLE_LOCATION, true);
        Point location = LabelHelper.calculatePointRelativeToPointOnLine(pList, referencePoint, offSet);
        //Here we use some default constant values to avoid a dependency on a set Display
        //The output diemension values are sligthly the same between windows and linux
        Dimension dimension = new Dimension((int) (labelText.length() * 7.42), (int) (11 * 1.6));
        absoluteBounds.setWidth(dimension.width);
        absoluteBounds.setHeight(dimension.height);
        location.translate(-1 * dimension.width / 2, -1 * dimension.height / 2);

        absoluteBounds.setWidth(dimension.width);
        absoluteBounds.setHeight(dimension.height);
        absoluteBounds.setX(location.x);
        absoluteBounds.setY(location.y);
        final Bounds elementBounds = DcFactory.eINSTANCE.createBounds();
        elementBounds.setX(absoluteBounds.getX());
        elementBounds.setY(absoluteBounds.getY());
        elementBounds.setHeight(absoluteBounds.getHeight());
        elementBounds.setWidth(absoluteBounds.getWidth());
        edge.setBPMNLabel(label);
    }
}
 
Example #6
Source File: ProcessViewProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
private Node createLabel(View owner, String hint) {
	DecorationNode rv = NotationFactory.eINSTANCE.createDecorationNode();
	rv.setType(hint);
	ViewUtil.insertChildView(owner, rv, ViewUtil.APPEND, true);
	return rv;
}
 
Example #7
Source File: CustomProcessViewProvider.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private Node createLabel(final View owner, final String hint) {
    final DecorationNode rv = NotationFactory.eINSTANCE.createDecorationNode();
    rv.setType(hint);
    ViewUtil.insertChildView(owner, rv, ViewUtil.APPEND, true);
    return rv;
}
 
Example #8
Source File: CustomPasteCommand.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param progressMonitor
 * @param info
 * @param part
 * @param toCopy
 */
protected void copyOnePart(final IProgressMonitor progressMonitor, IGraphicalEditPart part, List<IGraphicalEditPart> toCopy) {
	if(part.resolveSemanticElement() instanceof Element){
		final Element toCopyElement = (Element) part.resolveSemanticElement();
		Element res = EcoreUtil.copy(toCopyElement);
		if (canHandlePaste(part, toCopy)) {
			final Container container = (Container) targetElement;

			AbstractProcess mainProc = ModelHelper.getMainProcess(container);
			AbstractProcess pool = ModelHelper.getParentProcess(container);
			List<Element> elems = ModelHelper.getAllItemsOfType(mainProc, ProcessPackage.eINSTANCE.getElement()) ;
			Iterator<Element> it = elems.iterator();
			boolean alreadyExists = false ;
			while(it.hasNext() && !alreadyExists){
				Element e = it.next() ;
				if(e.getName() != null && toCopyElement.getName() != null){
					if(e.getName().equals(toCopyElement.getName())){
						alreadyExists = true ;
					}
				}
			}
			if(alreadyExists){
				updateLabelandId(toCopyElement.getName(), res, elems);
			}

			removeConnections(res);
			copyReferencedDataTypes(toCopyElement, res, mainProc);
			copyActorsAndActorsMapping(toCopyElement, res, mainProc, pool);
			resetConnections(toCopyElement, res, container);

			View resView = copyView(retrieveTargetCompartment(selectedTargetEditPart).getNotationView(), part, res,toCopy);
			mapping.put(part.resolveSemanticElement(), resView);
			
			//Copy Boundary view
			if(res instanceof Activity){
				if(!((Activity) res).getBoundaryIntermediateEvents().isEmpty()){
					//remove bad boundary copies
					List<View> boundaryViewsToRemove = new ArrayList<View>();
					for(Object childView : resView.getChildren()){
						if(childView instanceof Shape){

							if(res.equals(((Shape) childView).getElement())){
								boundaryViewsToRemove.add((View) childView);
							}
						}
					}
					resView.getPersistedChildren().removeAll(boundaryViewsToRemove);

					for (IGraphicalEditPart boundaryPart : getBoundaries(toCopy)) {
						BoundaryEvent semanticBoundary = (BoundaryEvent)boundaryPart.resolveSemanticElement();
						EObject semanticParent = semanticBoundary.eContainer();
						View parentView = mapping.get(semanticParent);
						if(parentView != null){
							Activity newParent = (Activity)parentView.getElement();
							if(newParent.equals(res)){
								BoundaryEvent newBoundarySemantic = null;
								for (BoundaryEvent event : newParent.getBoundaryIntermediateEvents()) {
									if (event.getName().equals(semanticBoundary.getName())) {
										newBoundarySemantic = event;
									}
								}
								mapping.put(semanticBoundary, copyView(resView, boundaryPart, newBoundarySemantic, toCopy));
							}
						}
					}					
				}
			}
			AbstractProcess targetProcess = ModelHelper.getParentProcess(targetElement);
			AbstractProcess sourceProcess = ModelHelper.getParentProcess(res);
			if(targetProcess == null || !targetProcess.equals(sourceProcess)){
				ModelHelper.removedReferencedEObjects(res,targetElement);//REMOVE DANDLING REFS !
			}
		}

		final IGraphicalEditPart newEp = (IGraphicalEditPart) selectedTargetEditPart.findEditPart(selectedTargetEditPart, res);

		if (newEp != null) {
			/* Create Node related to form element */
			for (Object child : selectedTargetEditPart.getNotationView().getChildren()) {
				if (child instanceof DecorationNode && ((DecorationNode) child).getType().equals(String.valueOf(PoolPoolCompartmentEditPart.VISUAL_ID))
						|| ((DecorationNode) child).getType().equals(String.valueOf(LaneLaneCompartmentEditPart.VISUAL_ID))) {
					newEp.getNotationView().getPersistedChildren().add(child);
				}
			}

		}
	}
}
 
Example #9
Source File: BPMNShapeFactory.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void attachLabel(Node node, String labelText,
        final BPMNShape elementShape) {
    final Font font = createFont(node);
    if (font != null) {
        final BPMNLabel label = DiFactory.eINSTANCE.createBPMNLabel();
        final BPMNLabelStyle labelStyle = getLabelStyle(font);
        label.setId(EcoreUtil.generateUUID());
        label.setLabelStyle(QName.valueOf(labelStyle.getId()));
        node.getPersistedChildren().stream()
                .filter(DecorationNode.class::isInstance)
                .map(DecorationNode.class::cast)
                .findFirst()
                .ifPresent(labelNode -> {
                    Location offsetLocation = modelExporter.getLocation((Node) labelNode);
                    if (offsetLocation != null) {
                        org.eclipse.gmf.runtime.notation.Bounds absoluteBounds = NotationFactory.eINSTANCE
                                .createBounds();

                        //Here we use some default constant values to avoid a dependency on a set Display
                        //The output diemension values are sligthly the same between windows and linux
                        Dimension dimension = new Dimension((int) (labelText.length() * 7.42), (int) (11 * 1.6));
                        absoluteBounds.setWidth(dimension.width);
                        absoluteBounds.setHeight(dimension.height);

                        final Point location = toRectangle(elementShape.getBounds()).getBottom()
                                .getTranslated(new Point(offsetLocation.getX(), offsetLocation.getY()));
                        location.translate(-dimension.width / 2, 0);

                        absoluteBounds.setY(location.y);
                        absoluteBounds.setX(location.x);
                        final Bounds elementBounds = DcFactory.eINSTANCE.createBounds();
                        elementBounds.setX(absoluteBounds.getX());
                        elementBounds.setY(absoluteBounds.getY());
                        elementBounds.setHeight(absoluteBounds.getHeight());
                        elementBounds.setWidth(absoluteBounds.getWidth());
                        label.setBounds(elementBounds);
                        elementShape.setBPMNLabel(label);
                    }
                });
    }
}
 
Example #10
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private Node createLabel(final View owner, final String hint) {
    final DecorationNode rv = NotationFactory.eINSTANCE.createDecorationNode();
    rv.setType(hint);
    ViewUtil.insertChildView(owner, rv, ViewUtil.APPEND, true);
    return rv;
}