Search in sources :

Example 31 with IGraphicalEditPart

use of org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart in project statecharts by Yakindu.

the class EditPartUtils method findEditPartForSemanticElement.

@SuppressWarnings("unchecked")
public static IGraphicalEditPart findEditPartForSemanticElement(EditPart editPart, EObject semanticElement) {
    if (semanticElement == null) {
        return null;
    }
    if (editPart instanceof IGraphicalEditPart) {
        EObject resolveSemanticElement = ((IGraphicalEditPart) editPart).resolveSemanticElement();
        if (resolveSemanticElement != null && EcoreUtil.getURI(resolveSemanticElement).equals(EcoreUtil.getURI(semanticElement))) {
            return (IGraphicalEditPart) editPart;
        }
    }
    for (Object child : editPart.getChildren()) {
        IGraphicalEditPart recursiveEditPart = findEditPartForSemanticElement((EditPart) child, semanticElement);
        if (recursiveEditPart != null) {
            return recursiveEditPart;
        }
    }
    if (editPart instanceof NodeEditPart) {
        List<Connection> connections = new ArrayList<Connection>();
        connections.addAll(((NodeEditPart) editPart).getSourceConnections());
        connections.addAll(((NodeEditPart) editPart).getTargetConnections());
        for (Object connection : connections) {
            EObject resolveSemanticElement = ((IGraphicalEditPart) connection).resolveSemanticElement();
            if (EcoreUtil.equals(resolveSemanticElement, semanticElement)) {
                return (IGraphicalEditPart) connection;
            }
        }
    }
    return null;
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) NodeEditPart(org.eclipse.gef.NodeEditPart) EObject(org.eclipse.emf.ecore.EObject) Connection(org.eclipse.draw2d.Connection) ArrayList(java.util.ArrayList) EObject(org.eclipse.emf.ecore.EObject)

Example 32 with IGraphicalEditPart

use of org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart in project statecharts by Yakindu.

the class ExtractSubdiagramRefactoring method getActualBounds.

protected Rectangle getActualBounds(Node child) {
    IEditorPart lastActiveEditor = ActiveEditorTracker.getLastActiveEditor();
    if (lastActiveEditor instanceof StatechartDiagramEditor) {
        IDiagramGraphicalViewer viewer = ((StatechartDiagramEditor) lastActiveEditor).getDiagramGraphicalViewer();
        IGraphicalEditPart editPart = (IGraphicalEditPart) viewer.getEditPartRegistry().get(child);
        return editPart.getFigure().getBounds();
    }
    return Rectangle.SINGLETON;
}
Also used : IDiagramGraphicalViewer(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer) IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) IEditorPart(org.eclipse.ui.IEditorPart) StatechartDiagramEditor(org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor)

Example 33 with IGraphicalEditPart

use of org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart in project statecharts by Yakindu.

the class InlineSubdiagramHandler method setPreferredSize.

private Object setPreferredSize(ExecutionEvent event) {
    IGraphicalEditPart editPart = (IGraphicalEditPart) getFirstElement(HandlerUtil.getCurrentSelection(event));
    Command cmd = editPart.getCommand(new SetPreferredSizeRequest(editPart));
    AbstractRefactoring.executeCommand(new CommandProxy(cmd), editPart.resolveSemanticElement().eResource());
    return null;
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) CommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy) Command(org.eclipse.gef.commands.Command) SetPreferredSizeRequest(org.yakindu.sct.ui.editor.policies.SetPreferredSizeRequest)

Example 34 with IGraphicalEditPart

use of org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart in project statecharts by Yakindu.

the class CompartmentLayoutEditPolicy method getCreateCommand.

@SuppressWarnings("unchecked")
@Override
protected Command getCreateCommand(CreateRequest request) {
    if (request instanceof CreateViewAndElementRequest) {
        TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
        CompositeTransactionalCommand cc = new CompositeTransactionalCommand(editingDomain, DiagramUIMessages.AddCommand_Label);
        Iterator<?> descriptors = ((CreateViewRequest) request).getViewDescriptors().iterator();
        while (descriptors.hasNext()) {
            CreateViewRequest.ViewDescriptor descriptor = (CreateViewRequest.ViewDescriptor) descriptors.next();
            int feedBackIndex = getFeedbackIndexFor(request);
            // obtain CreateElementRequest and add initial region feedback
            // index to request map. This index is needed to add the
            // semantic element at the correct listIndex
            CreateElementRequest createElementRequest = (CreateElementRequest) ((CreateViewAndElementRequest) request).getViewAndElementDescriptor().getCreateElementRequestAdapter().getAdapter(CreateElementRequest.class);
            if (createElementRequest != null) {
                createElementRequest.getParameters().put(RequestParameterKeys.RegionFeedbackIndex, feedBackIndex);
            }
            CreateCommand createCommand = new CompartmentChildCreateCommand(editingDomain, descriptor, (View) (getHost().getModel()), feedBackIndex);
            cc.compose(createCommand);
        }
        return new ICommandProxy(cc.reduce());
    }
    return null;
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) CompartmentChildCreateCommand(org.yakindu.base.gmf.runtime.commands.CompartmentChildCreateCommand) ICommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy) CompartmentChildCreateCommand(org.yakindu.base.gmf.runtime.commands.CompartmentChildCreateCommand) CreateCommand(org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand) CreateElementRequest(org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest) CreateViewAndElementRequest(org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest) CreateViewRequest(org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) CompositeTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand)

Example 35 with IGraphicalEditPart

use of org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart in project statecharts by Yakindu.

the class CompartmentLayoutEditPolicy method createAddCommand.

@Override
protected Command createAddCommand(EditPart child, EditPart after) {
    int index = getHost().getChildren().indexOf(after);
    TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
    AddCommand command = new CompartmentAddCommand(editingDomain, new EObjectAdapter((View) getHost().getModel()), new EObjectAdapter((View) child.getModel()), index);
    return new ICommandProxy(command);
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) ICommandProxy(org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) EObjectAdapter(org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter) View(org.eclipse.gmf.runtime.notation.View) AddCommand(org.eclipse.gmf.runtime.diagram.core.commands.AddCommand)

Aggregations

IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)43 ArrayList (java.util.ArrayList)10 EObject (org.eclipse.emf.ecore.EObject)10 View (org.eclipse.gmf.runtime.notation.View)10 List (java.util.List)8 Point (org.eclipse.draw2d.geometry.Point)8 Rectangle (org.eclipse.draw2d.geometry.Rectangle)7 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)7 ICommandProxy (org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy)7 IFigure (org.eclipse.draw2d.IFigure)6 BusinessItemShapeEditPart (org.talend.designer.business.diagram.custom.edit.parts.BusinessItemShapeEditPart)5 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)4 Command (org.eclipse.gef.commands.Command)4 CompositeTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand)3 EObjectAdapter (org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter)3 IElementType (org.eclipse.gmf.runtime.emf.type.core.IElementType)3 Iterator (java.util.Iterator)2 Connection (org.eclipse.draw2d.Connection)2 RoundedRectangle (org.eclipse.draw2d.RoundedRectangle)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2