Search in sources :

Example 21 with IGraphicalEditPart

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

the class AdjustIdentityAnchorCommand method computeNewAnchor.

private PrecisionPoint computeNewAnchor(PrecisionPoint currentAnchorPoint, EditPart editPart) {
    double scale = getScale(editPart);
    IFigure figure = ((IGraphicalEditPart) editPart).getFigure();
    Rectangle bounds = figure.getBounds();
    if (figure instanceof HandleBounds) {
        bounds = ((HandleBounds) figure).getHandleBounds();
    }
    Point currentRelativePoint = getAnchorRelativePoint(currentAnchorPoint, bounds);
    if (futureSize != null && delta != null) {
        // and delta are used instead of the request data.
        return new PrecisionPoint(((double) (currentRelativePoint.x - delta.x)) / futureSize.width, ((double) (currentRelativePoint.y - delta.y)) / futureSize.height);
    } else {
        double logicalWidthDelta = request.getSizeDelta().width / scale;
        double logicalHeightDelta = request.getSizeDelta().height / scale;
        int direction = request.getResizeDirection();
        double newRelativeX = computeNewXRelativeLocation(direction, currentRelativePoint, logicalWidthDelta);
        double newRelativeY = computeNewYRelativeLocation(direction, currentRelativePoint, logicalHeightDelta);
        return new PrecisionPoint(newRelativeX / (bounds.width() + logicalWidthDelta), newRelativeY / (bounds.height() + logicalHeightDelta));
    }
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) HandleBounds(org.eclipse.gef.handles.HandleBounds) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) IFigure(org.eclipse.draw2d.IFigure)

Example 22 with IGraphicalEditPart

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

the class CreationWizard method openDiagram.

protected boolean openDiagram(Resource diagram) throws PartInitException {
    String path = diagram.getURI().toPlatformString(true);
    IResource workspaceResource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path));
    if (workspaceResource instanceof IFile) {
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        StatechartDiagramEditor editor = (StatechartDiagramEditor) page.openEditor(new FileEditorInput((IFile) workspaceResource), getEditorID());
        if (editor != null) {
            List<EObject> allNotationElements = EcoreUtil2.eAllContentsAsList(diagram);
            for (EObject eObject : allNotationElements) {
                if (eObject instanceof View && ((View) eObject).getType().equals(SemanticHints.STATE_NAME)) {
                    IGraphicalEditPart editPart = EditPartUtils.findEditPartForSemanticElement(editor.getDiagramGraphicalViewer().getRootEditPart(), ((View) eObject).getElement());
                    editPart = editPart.getChildBySemanticHint(SemanticHints.STATE_NAME);
                    if (editPart != null) {
                        final DirectEditRequest request = new DirectEditRequest();
                        request.setDirectEditFeature(BasePackage.Literals.NAMED_ELEMENT__NAME);
                        editPart.performRequest(request);
                        break;
                    }
                }
            }
            return false;
        }
    }
    return false;
}
Also used : Path(org.eclipse.core.runtime.Path) IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) IFile(org.eclipse.core.resources.IFile) DirectEditRequest(org.eclipse.gef.requests.DirectEditRequest) FileEditorInput(org.eclipse.ui.part.FileEditorInput) EObject(org.eclipse.emf.ecore.EObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) StatechartDiagramEditor(org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor) View(org.eclipse.gmf.runtime.notation.View) IResource(org.eclipse.core.resources.IResource)

Example 23 with IGraphicalEditPart

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

the class SheetLabelProvider method getImage.

public Image getImage(Object element) {
    element = unwrap(element);
    if (element instanceof IGraphicalEditPart) {
        EObject semanticElement = ((IGraphicalEditPart) element).resolveSemanticElement();
        if (semanticElement == null) {
            // Default images
            View view = ((IGraphicalEditPart) element).getNotationView();
            String viewType = view.getType();
            if (ViewType.NOTE.equals(viewType)) {
                return SharedImages.get(SharedImages.IMG_NOTE);
            } else if (ViewType.TEXT.equals(viewType)) {
                return SharedImages.get(SharedImages.IMG_TEXT);
            }
        } else {
            // custom images
            IElementType elementType = ElementTypeRegistry.getInstance().getElementType(semanticElement);
            Image image = DiagramActivator.getDefault().getImageRegistry().get(elementType.getIconURL().toString());
            if (image == null) {
                ImageDescriptor desc = ImageDescriptor.createFromURL(elementType.getIconURL());
                DiagramActivator.getDefault().getImageRegistry().put(elementType.getIconURL().toString(), desc.createImage());
                return DiagramActivator.getDefault().getImageRegistry().get(elementType.getIconURL().toString());
            }
            return image;
        }
    }
    return null;
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) IElementType(org.eclipse.gmf.runtime.emf.type.core.IElementType) EObject(org.eclipse.emf.ecore.EObject) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image) View(org.eclipse.gmf.runtime.notation.View)

Example 24 with IGraphicalEditPart

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

the class SheetLabelProvider method getText.

public String getText(Object element) {
    element = unwrap(element);
    if (element instanceof IGraphicalEditPart) {
        EObject semanticElement = ((IGraphicalEditPart) element).resolveSemanticElement();
        if (semanticElement == null) {
            View view = ((IGraphicalEditPart) element).getNotationView();
            return view.getType();
        } else {
            IElementType elementType = ElementTypeRegistry.getInstance().getElementType(semanticElement);
            StringBuilder builder = new StringBuilder();
            builder.append(elementType.getDisplayName());
            if (semanticElement instanceof NamedElement && ((NamedElement) semanticElement).getName() != null) {
                builder.append(' ');
                builder.append(((NamedElement) semanticElement).getName());
            }
            return builder.toString();
        }
    }
    return null;
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) IElementType(org.eclipse.gmf.runtime.emf.type.core.IElementType) EObject(org.eclipse.emf.ecore.EObject) View(org.eclipse.gmf.runtime.notation.View) NamedElement(org.yakindu.base.base.NamedElement)

Example 25 with IGraphicalEditPart

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

the class StatechartMarkerNavigationProvider method doGotoMarker.

@Override
@SuppressWarnings("rawtypes")
protected void doGotoMarker(IMarker marker) {
    String elementId = marker.getAttribute(SCTMarkerType.SEMANTIC_ELEMENT_ID, null);
    if (elementId == null || !(getEditor() instanceof DiagramEditor)) {
        return;
    }
    DiagramEditor editor = (DiagramEditor) getEditor();
    EObject targetElement = (EObject) editor.getDiagram().eResource().getEObject(elementId);
    if (targetElement == null) {
        return;
    }
    View view = DiagramPartitioningUtil.findNotationView(targetElement);
    if (view == null) {
        return;
    }
    Diagram element = DiagramPartitioningUtil.getDiagramContaining(view.getElement());
    editor = (DiagramEditor) DiagramPartitioningUtil.openEditor(element);
    Map editPartRegistry = editor.getDiagramGraphicalViewer().getEditPartRegistry();
    EditPart targetEditPart = (EditPart) editPartRegistry.get(view);
    if (targetEditPart != null) {
        if (!targetEditPart.isSelectable())
            return;
        DiagramPartitioningUtil.selectElementsInDiagram(editor, Arrays.asList(new EditPart[] { targetEditPart }));
    }
    try {
        if (marker.isSubtypeOf(SCTMarkerType.SUPERTYPE)) {
            final DirectEditRequest request = new DirectEditRequest();
            request.setDirectEditFeature(getEditFeature(targetElement, marker));
            List<IGraphicalEditPart> allEditParts = getEditParts(editPartRegistry, EcoreUtil2.eAllContentsAsList(view));
            for (IGraphicalEditPart editPart : allEditParts) {
                if (editPart instanceof IXtextAwareEditPart || (editPart instanceof TextAwareLabelEditPart) && ((TextAwareLabelEditPart) editPart).getFeature().equals(request.getDirectEditFeature())) {
                    editPart.performRequest(request);
                    break;
                }
            }
        }
    } catch (CoreException e) {
        e.printStackTrace();
    }
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) DiagramEditor(org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor) TextAwareLabelEditPart(org.yakindu.base.gmf.runtime.editparts.TextAwareLabelEditPart) IXtextAwareEditPart(org.yakindu.base.xtext.utils.gmf.directedit.IXtextAwareEditPart) EditPart(org.eclipse.gef.EditPart) IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) View(org.eclipse.gmf.runtime.notation.View) Diagram(org.eclipse.gmf.runtime.notation.Diagram) CoreException(org.eclipse.core.runtime.CoreException) DirectEditRequest(org.eclipse.gef.requests.DirectEditRequest) TextAwareLabelEditPart(org.yakindu.base.gmf.runtime.editparts.TextAwareLabelEditPart) EObject(org.eclipse.emf.ecore.EObject) IXtextAwareEditPart(org.yakindu.base.xtext.utils.gmf.directedit.IXtextAwareEditPart) Map(java.util.Map)

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