org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart Java Examples

The following examples show how to use org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart. 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
/**
 * It depends if source and target are correctly defined and already exists.
 *
 * @param srcId
 * @param trgtId
 * @param sourceNode
 * @param targetNode
 * @return
 */
private boolean canSequenceFlowBeCreated(final String srcId, final String trgtId,
        final ShapeNodeEditPart sourceNode, final ShapeNodeEditPart targetNode) {
    if (sourceNode == null) {
        return false;
    }

    if (targetNode == null) {
        return false;
    }

    final EObject sourceElement = steps.get(srcId);
    final EObject targetElement = steps.get(trgtId);
    if (sourceElement != null && targetElement != null) {
        if (!ModelHelper.getParentProcess(sourceElement).equals(ModelHelper.getParentProcess(targetElement))) {
            return false;//TODO HAPPENS WITH EMBEDDED SUBPROC AND NOT SUPPORTED YET IN BOS
        }
    }

    if (createdSequenceFlows.contains(new Pair<String, String>(srcId, trgtId))) {
        return false; //Already exists
    }

    return true;
}
 
Example #2
Source File: UpdateSizePoolSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private ShapeNodeEditPart findPoolEditPart(EditPart host) {
    EditPart result = host ;

    if(host instanceof SequenceFlowEditPart){
        result = ((AbstractConnectionEditPart) host).getSource();
    }

    if(host instanceof MessageFlowEditPart){
        result = ((AbstractConnectionEditPart) host).getSource();
    }

    /*first search for a CustomLaneEditPart*/
    while(!(result instanceof CustomPoolEditPart) && result != null){
        result = result.getParent() ;
    }

    if(result == null){
        return null ;
    }

    return (ShapeNodeEditPart) result;
}
 
Example #3
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public ProcBuilder(final IProgressMonitor progressMonitor) {
    monitor = progressMonitor;
    diagramResources = new HashMap<String, Resource>();
    commandStack = new CompoundCommand();
    dataByName = new HashMap<String, Data>();
    datatypes = new HashMap<String, EnumType>();
    participants = new HashMap<String, Actor>();
    editParts = new HashMap<String, ShapeNodeEditPart>();
    throwLinkEvents = new HashMap<ThrowLinkEvent, String>();
    catchLinkEvents = new HashMap<String, CatchLinkEvent>();
    steps = new HashMap<String, EObject>();
    processIds = new HashMap<AbstractProcess, String>();
    messageFlows = new ArrayList<MessageFlowData>();
    createdSequenceFlows = new ArrayList<Pair<String, String>>();
    processes = new HashMap<String, AbstractProcess>();
    lanes = new HashMap<String, Lane>();
    elementToReplaceName = new HashMap<Element, String>();
}
 
Example #4
Source File: GMFTools.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param parts
 * @return
 */
public static IGraphicalEditPart getFirstNodeShapeEditPart(List<IGraphicalEditPart> parts) {
    int i = 0;
    IGraphicalEditPart refNode = null;
    while (refNode == null) {
        if (parts.get(i) instanceof ShapeNodeEditPart) {
            refNode = parts.get(i);
        } else {
            i++;
        }
    }
    return refNode;
}
 
Example #5
Source File: CustomSubprocessEventCompartmentEditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected List<IGraphicalEditPart> getChildrenToMoveVerticaly(int xPosition, int yPosition,double zoom) {
    IGraphicalEditPart _container = (IGraphicalEditPart) getParent().getParent() ;
    // the children that will be moved around
    List<IGraphicalEditPart> bottomChildren = new ArrayList<IGraphicalEditPart>();

    if (_container != null && _container.resolveSemanticElement() instanceof Container) {
        List children  = null;
        if (_container.resolveSemanticElement() instanceof Container) {
            children = _container.getChildren();
        } else if (_container instanceof ShapeCompartmentEditPart) {
            children = ((ShapeCompartmentEditPart) _container).getChildren();
        }
        if (children == null) {
            throw new IllegalArgumentException("The part " + _container + " did not contain elements"); //$NON-NLS-1$ //$NON-NLS-2$
        }

        for (Object child : children) {
            if (child instanceof ShapeNodeEditPart && !child.equals(getParent())) {
                MultipleShapesHorizontalMoveTool.setBoundsForOverlapComputation((IGraphicalEditPart) child,SINGLETON) ;
                SINGLETON = SINGLETON.scale(zoom) ;
                ((DiagramEditPart) getViewer().getContents()).getFigure().translateToRelative(SINGLETON);
                if (SINGLETON.x + SINGLETON.width >= xPosition && SINGLETON.y > yPosition) {
                    bottomChildren.add((IGraphicalEditPart) child);
                }
            }
        }

    }
    return bottomChildren ;
}
 
Example #6
Source File: CustomSubprocessEventCompartmentEditPart.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected List<IGraphicalEditPart> getChildrenToMoveHorizontaly(int xPosition, int yPosition,double zoom){
    IGraphicalEditPart _container = (IGraphicalEditPart) getParent().getParent() ;
    // the children that will be moved around
    List<IGraphicalEditPart> rightChildren = new ArrayList<IGraphicalEditPart>();

    if (_container != null && _container.resolveSemanticElement() instanceof Container) {
        List children  = null;
        if (_container.resolveSemanticElement() instanceof Container) {
            children = _container.getChildren();
        } else if (_container instanceof ShapeCompartmentEditPart) {
            children = ((ShapeCompartmentEditPart) _container).getChildren();
        }
        if (children == null) {
            throw new IllegalArgumentException("The part " + _container + " did not contain elements"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        // now iterate over the compartment children
        // and take those that are on the right.
        for (Object child : children) {
            if (child instanceof ShapeNodeEditPart) {
                MultipleShapesHorizontalMoveTool.setBoundsForOverlapComputation((IGraphicalEditPart) child,SINGLETON) ;
                SINGLETON = SINGLETON.scale(zoom) ;
                ((DiagramEditPart) getViewer().getContents()).getFigure().translateToRelative(SINGLETON);
                if (SINGLETON.x > xPosition && SINGLETON.y < yPosition && SINGLETON.y + SINGLETON.height + 60  > yPosition) {
                    rightChildren.add((IGraphicalEditPart) child);
                }
            }
        }
    }
    return rightChildren;
}
 
Example #7
Source File: UpdateSizeLaneSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void showSelection() {
    if(!(((IGraphicalEditPart) getHost()).resolveSemanticElement() instanceof Lane)){
        return ;
    }

    laneEditPart = (ShapeNodeEditPart) getHost() ;

    if (sourceFigure == null) {
        sourceFigure = laneEditPart.getFigure();
        sourceFigure.addFigureListener(figureListener);
    }


    hideSelection();
    layer = getLayer(LayerConstants.HANDLE_LAYER);
    /*
     * need to flush in order to have the new correct size of the host
     * figure
     */
    //		poolEditPart.getViewer().flush();
    //FIXME
    final Rectangle ref = sourceFigure.getBounds().getCopy();
    FiguresHelper.translateToAbsolute(sourceFigure, ref);
    if (ref.x == 0 && ref.y == 0 && ref.height == 0 && ref.width == 0) {
        return;
    }

    if(zoomManager.getZoom() > GMFTools.MINIMAL_ZOOM_DISPLAY){
        showSelectionForAddBottom();
        showSelectionForRemoveBottom();
        showSelectionForAddRight(zoomManager.getZoom());
        showSelectionForRemoveRight(zoomManager.getZoom());
    }

}
 
Example #8
Source File: UpdateSizeLaneSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private ShapeNodeEditPart findLaneEditPart(final EditPart host) {
    EditPart result = host ;
    final EditPart tempEditPart = result;
    /*first search for a CustomLaneEditPart*/
    while(!(result instanceof CustomLaneEditPart) && result != null){
        result = result.getParent() ;
    }

    if(result == null){
        return null ;
    }

    return (ShapeNodeEditPart) result;
}
 
Example #9
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addEventSubprocess(String id, final String name, final Point location, final Dimension size, final boolean isCollapsed)
        throws ProcBuilderException {

    id = NamingUtils.convertToId(id);
    final Element createdElement = createShape(id, currentContainer, location, size, ProcessElementTypes.SubProcessEvent_3058, isCollapsed);

    final ShapeNodeEditPart nodeEditPart = (ShapeNodeEditPart) GMFTools.findEditPart(diagramPart, createdElement);
    final Node node = (Node) nodeEditPart.getNotationView();

    if (node != null) {
        DrawerStyle drawer = null;
        for (final Object child : node.getPersistedChildren()) {
            if (child instanceof DrawerStyle) {
                drawer = (DrawerStyle) child;
            }
        }
        if (drawer != null) {
            commandStack.append(SetCommand.create(editingDomain, drawer, NotationPackage.eINSTANCE.getDrawerStyle_Collapsed(), isCollapsed));
        }
    }

    commandStack.append(SetCommand.create(editingDomain, createdElement, ProcessPackage.eINSTANCE.getElement_Name(), name));

    currentContainer = createdElement;
    currentStep = createdElement;
    currentElement = createdElement;
    execute();
}
 
Example #10
Source File: ActivityDecoratorProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * getDecoratorTargetClassifier Utility method to determine if the
 * decoratorTarget is a supported type for this decorator and return the
 * associated EditPart element.
 * 
 * @param decoratorTarget
 *            IDecoratorTarget to check and return valid Classifier target.
 * @return node GraphicalEditPart if IDecoratorTarget can be supported, null
 *         otherwise.
 */
public static GraphicalEditPart getDecoratorTargetNode(IDecoratorTarget decoratorTarget) {
    if(decoratorTarget == null){
        return null;
    }
    ShapeNodeEditPart node = (ShapeNodeEditPart) decoratorTarget.getAdapter(ShapeNodeEditPart.class);
    if(node != null ){
        return node ;
    }

    return null;

}
 
Example #11
Source File: CustomPasteCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param toCopy
 * @return
 */
private List<IGraphicalEditPart> getNodes(List<IGraphicalEditPart> toCopy) {
	List<IGraphicalEditPart> res = new ArrayList<IGraphicalEditPart>();
	for (IGraphicalEditPart part : toCopy) {
		if (part instanceof ShapeNodeEditPart &&
				! (part instanceof BorderedBorderItemEditPart)) {
			res.add(part);
		}
	}
	return res;
}
 
Example #12
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private Element createShape(final String id, final EObject container, final Point location, final Dimension size, final IElementType type,
        final boolean isCollapsed) throws ProcBuilderException {

    diagramPart.refresh();
    final IGraphicalEditPart parentEditPart = GMFTools.findEditPart(diagramPart, container);
    final IGraphicalEditPart compartment = retrieveCompartmentEditPartFor(parentEditPart);
    if (compartment instanceof LaneLaneCompartmentEditPart) {
        int laneHeightOffset = 0;

        final PoolPoolCompartmentEditPart poolCompartment = (PoolPoolCompartmentEditPart) compartment.getParent().getParent();
        final int currentLaneIndex = ((Container) currentContainer.eContainer()).getElements().indexOf(currentContainer);
        if (currentLaneIndex > 0) {
            for (final Object object : poolCompartment.getChildren()) {
                if (object instanceof LaneEditPart) {
                    final EObject semanticElement = ((LaneEditPart) object).resolveSemanticElement();
                    final int laneIndex = ((Container) currentContainer.eContainer()).getElements().indexOf(semanticElement);
                    if (laneIndex < currentLaneIndex) {
                        laneHeightOffset = laneHeightOffset + ((LaneEditPart) object).getFigure().getSize().height;
                    }
                }
            }
        }
        if (laneHeightOffset != 0 && laneHeightOffset + 80 > location.y) {
            location.y = location.y + laneHeightOffset + 20;
        }
    }

    final PreferencesHint hint = diagramPart.getDiagramPreferencesHint();
    final PreferenceStore store = (PreferenceStore) hint.getPreferenceStore();
    store.setValue("isCollapsed", isCollapsed);

    final ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(new CreateElementRequestAdapter(new CreateElementRequest(type)),
            Node.class,
            ((IHintedType) type).getSemanticHint(), hint);
    final CreateViewAndElementRequest createRequest = createCreationRequest(location, size, viewDescriptor);

    if (container == null || !(container instanceof Element)) {
        throw new ProcBuilderException("Impossible to find the parent EditPart");
    }

    diagramPart.getDiagramEditDomain().getDiagramCommandStack().execute(compartment.getCommand(createRequest));
    compartment.refresh();

    final Node newNode = (Node) viewDescriptor.getAdapter(Node.class);
    if (newNode == null) {
        throw new ProcBuilderException("New element not created");
    }
    currentView = newNode;
    final Element createdElement = (Element) newNode.getElement();
    final ShapeNodeEditPart nodeEditPart = (ShapeNodeEditPart) GMFTools.findEditPart(diagramPart, createdElement);

    if (nodeEditPart == null) {
        throw new ProcBuilderException("New edit part not created");
    }

    editParts.put(id, nodeEditPart);

    return createdElement;
}
 
Example #13
Source File: MultipleShapesHorizontalMoveTool.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Moved to public so that it may be called programmatically
 * by an other tool.
 */
public boolean handleButtonDown(int button) {
	Object underMouse = getCurrentViewer().findObjectAt(getCurrentInput().getMouseLocation());
	if (!(underMouse instanceof IGraphicalEditPart)) {
		return true;
	}
	stateTransition(STATE_INITIAL, STATE_DRAG_IN_PROGRESS);
	_initialPosition = getCurrentPosition();
	_initPosNoZoom = getCurrentPositionZoomed();

	// calculate the initial selection
	// of shapes that should move
	_container = (IGraphicalEditPart) findPool(underMouse);

	// the children that will be moved around
	List<IGraphicalEditPart> rightChildren = new ArrayList<IGraphicalEditPart>();
	List<IGraphicalEditPart> subProcesses = new ArrayList<IGraphicalEditPart>();

	if (_container != null && _container.resolveSemanticElement() instanceof Container) {
		List children  = null;
		if (_container.resolveSemanticElement() instanceof Container) {
			children = _container.getChildren();
		} else if (_container instanceof ShapeCompartmentEditPart) {
			children = ((ShapeCompartmentEditPart) _container).getChildren();
		}
		if (children == null) {
			throw new IllegalArgumentException("The part " + _container + " did not contain elements"); //$NON-NLS-1$ //$NON-NLS-2$
		}
		// now iterate over the compartment children
		// and take those that are on the right.
		for (Object child : children) {
			if (child instanceof ShapeNodeEditPart) {
				setBoundsForOverlapComputation((IGraphicalEditPart) child,SINGLETON) ;
				((DiagramEditPart) getCurrentViewer().getContents())
				.getFigure().translateToRelative(SINGLETON);
				if (SINGLETON.x > _initPosNoZoom) {
					rightChildren.add((IGraphicalEditPart) child);
				} 
			}
		}
	}
	_movingShapes = rightChildren;
	_subProcesses = subProcesses;

	updateSourceRequest();
	showSourceFeedback();

	return true;
}
 
Example #14
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addSequenceFlow(final String name, final String sourceId, final String targetId, final boolean isDefault, final Point sourceAnchor,
        final Point targetAnchor, final PointList bendpoints) throws ProcBuilderException {
    final String srcId = NamingUtils.convertToId(sourceId);
    final String trgtId = NamingUtils.convertToId(targetId);
    final ShapeNodeEditPart sourceNode = editParts.get(srcId);
    final ShapeNodeEditPart targetNode = editParts.get(trgtId);

    if (!canSequenceFlowBeCreated(srcId, trgtId, sourceNode, targetNode)) {
        return;
    }

    final CreateConnectionViewAndElementRequest request = new CreateConnectionViewAndElementRequest(ProcessElementTypes.SequenceFlow_4001,
            ((IHintedType) ProcessElementTypes.SequenceFlow_4001).getSemanticHint(), diagramPart
                    .getDiagramPreferencesHint());
    final Command createSequenceFlowCommand = CreateConnectionViewAndElementRequest.getCreateCommand(request, sourceNode, targetNode);
    if(!createSequenceFlowCommand.canExecute()) {
       return;
    }
    createSequenceFlowCommand.execute();
    
    final ConnectionViewAndElementDescriptor newObject = (ConnectionViewAndElementDescriptor) request.getNewObject();
    final Edge edge = (Edge) newObject.getAdapter(Edge.class);
    final SequenceFlow createdElement = (SequenceFlow) newObject.getElementAdapter().getAdapter(EObject.class);
    if (createdElement == null) {
        throw new ProcBuilderException("Impossible to create SequenceFlow " + name);
    }

    if (bendpoints != null && bendpoints.size() > 1) {
        setBendPoints(bendpoints, newObject);
    }

    handleSequenceFlowAnchors(sourceAnchor, targetAnchor, newObject);
    if (name != null) {
        commandStack.append(SetCommand.create(editingDomain, createdElement, ProcessPackage.Literals.ELEMENT__NAME, name));
    }
    commandStack.append(SetCommand.create(editingDomain, createdElement, ProcessPackage.eINSTANCE.getSequenceFlow_IsDefault(), isDefault));
    if (edge != null) {
        commandStack.append(SetCommand.create(editingDomain, edge.getStyle(NotationPackage.eINSTANCE.getLineStyle()),
                NotationPackage.eINSTANCE.getLineStyle_LineColor(), FigureUtilities.colorToInteger(ColorConstants.lightGray)));
    }

    createdSequenceFlows.add(new Pair<String, String>(srcId, trgtId));
    currentElement = createdElement;
    currentView = edge;
    execute();
}
 
Example #15
Source File: UpdateSizePoolSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void showSelection() {
    if(!(((IGraphicalEditPart) getHost()).resolveSemanticElement() instanceof Pool)){
        return ;
    }
    if(getHost() instanceof ITextAwareEditPart || getHost() instanceof ShapeCompartmentEditPart) {
        return ;
    }

    poolEditPart = (ShapeNodeEditPart) getHost() ;

    haveLanes = false ;
    for(Object o : poolEditPart.getChildren()){
        if(o instanceof CustomPoolCompartmentEditPart){
            if(!((CustomPoolCompartmentEditPart)o).getPoolLanes().isEmpty()){
                haveLanes = true ;
                break ;
            }
        } 
    }


    if (sourceFigure == null) {
        sourceFigure = poolEditPart.getFigure();
        sourceFigure.addFigureListener(figureListener);
    }


    hideSelection();
    layer = getLayer(LayerConstants.HANDLE_LAYER);
    Rectangle ref = sourceFigure.getBounds();

    if (ref.x == 0 && ref.y == 0 && ref.height == 0 && ref.width == 0) {
        return;
    }


    if(zoomManager.getZoom() > GMFTools.MINIMAL_ZOOM_DISPLAY){

        showSelectionForAddRight(zoomManager.getZoom());
        showSelectionForRemoveRight(zoomManager.getZoom());

        if(!haveLanes){
            showSelectionForAddBottom(zoomManager.getZoom());
            showSelectionForRemoveBottom(zoomManager.getZoom());
        }
    }
}
 
Example #16
Source File: MultipleShapesVerticalMoveTool.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Moved to public so that it may be called programmatically
 * by an other tool.
 */
public boolean handleButtonDown(int button) {
	Object underMouse = getCurrentViewer().findObjectAt(getCurrentInput().getMouseLocation());
	if (!(underMouse instanceof IGraphicalEditPart)) {
		return true;
	}
	stateTransition(STATE_INITIAL, STATE_DRAG_IN_PROGRESS);
	_initialPosition = getCurrentPosition();
	_initPosNoZoom = getCurrentPositionZoomed();

	// calculate the initial selection
	// of shapes that should move
	_container = (IGraphicalEditPart) findPool(underMouse);

	// the children that will be moved around
	List<IGraphicalEditPart> bottomChildren = new ArrayList<IGraphicalEditPart>();
	List<IGraphicalEditPart> subProcesses = new ArrayList<IGraphicalEditPart>();

	if (_container != null && _container.resolveSemanticElement() instanceof Container) {
		List children  = null;
		if (_container.resolveSemanticElement() instanceof Container) {
			children = _container.getChildren();
		} else if (_container instanceof ShapeCompartmentEditPart) {
			children = ((ShapeCompartmentEditPart) _container).getChildren();
		}
		if (children == null) {
			throw new IllegalArgumentException("The part " + _container + " did not contain elements"); //$NON-NLS-1$ //$NON-NLS-2$
		}
		// now iterate over the compartment children
		// and take those that are on the right.
		for (Object child : children) {
			if (child instanceof ShapeNodeEditPart) {
				setBoundsForOverlapComputation((IGraphicalEditPart) child,SINGLETON) ;
				((DiagramEditPart) getCurrentViewer().getContents()).getFigure().translateToRelative(SINGLETON);
				if (SINGLETON.y > _initPosNoZoom) {
					bottomChildren.add((IGraphicalEditPart) child);
				} 
			}
		}
	}
	_movingShapes = bottomChildren;
	_subProcesses = subProcesses;

	updateSourceRequest();
	showSourceFeedback();

	return true;
}
 
Example #17
Source File: AbstractSwitchLaneSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 votes vote down vote up
protected abstract List<? extends ShapeNodeEditPart> getLanes();