Search in sources :

Example 1 with DiagramEditPart

use of org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart in project tdi-studio-se by Talend.

the class BusinessDiagramEditor method refresh.

public void refresh() {
    DiagramEditPart diagramEditPart = this.getDiagramEditPart();
    List list = diagramEditPart.getChildren();
    for (Object o : list) {
        if (o instanceof BusinessItemShapeEditPart) {
            BusinessItemShapeEditPart element = (BusinessItemShapeEditPart) o;
            element.refresh();
        }
    }
}
Also used : DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) BusinessItemShapeEditPart(org.talend.designer.business.diagram.custom.edit.parts.BusinessItemShapeEditPart) List(java.util.List) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 2 with DiagramEditPart

use of org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart in project tdi-studio-se by Talend.

the class ClipboardActionHandler method getCommand.

@Override
public ICommand getCommand(IGlobalActionContext cntxt) {
    IWorkbenchPart part = cntxt.getActivePart();
    if (!(part instanceof IDiagramWorkbenchPart)) {
        return null;
    }
    IDiagramWorkbenchPart workbenchPart = (IDiagramWorkbenchPart) part;
    DiagramEditPart diagramEditPart = workbenchPart.getDiagramEditPart();
    ICommand command = null;
    String actionId = cntxt.getActionId();
    if (actionId.equals(GlobalActionId.COPY)) {
        command = getCopyCommand(cntxt, workbenchPart, false);
        transfer(cntxt.getSelection());
        isCut = false;
        older = workbenchPart;
        orginalCopyFrom = workbenchPart;
        clonedSourceProcessItemsList = new ArrayList<BusinessItem>(((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement()).getBusinessItems());
    } else if (actionId.equals(GlobalActionId.CUT) && cntxt.getSelection() != null) {
        saveCut(cntxt.getSelection());
        command = getCutCommand(cntxt, workbenchPart);
        transfer(cntxt.getSelection());
        isCut = true;
        older = workbenchPart;
        clonedSourceProcessItemsList = new ArrayList<BusinessItem>(((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement()).getBusinessItems());
    } else if (actionId.equals(GlobalActionId.SAVE)) {
        if (workbenchPart instanceof IEditorPart) {
            IEditorPart editorPart = (IEditorPart) workbenchPart;
            if (editorPart.isDirty()) {
                IWorkbenchPage page = editorPart.getSite().getPage();
                page.saveEditor(editorPart, false);
            }
        }
    }
    if (actionId.equals(GlobalActionId.PASTE)) {
        // diagramPart.getDiagramGraphicalViewer().setSelection(new
        // StructuredSelection(diagramPart.getDiagramEditPart()));
        PasteViewRequest pasteReq = createPasteViewRequest();
        CommandStack cs = workbenchPart.getDiagramEditDomain().getDiagramCommandStack();
        IStructuredSelection selection = (IStructuredSelection) cntxt.getSelection();
        if (!(selection.getFirstElement() instanceof BusinessProcessEditPart)) {
            selection = new StructuredSelection(workbenchPart.getDiagramEditPart());
        }
        Object[] objects = selection.toArray();
        Collection returnValues = null;
        if (objects.length == 1) {
            Command paste = ((EditPart) objects[0]).getCommand(pasteReq);
            if (paste != null) {
                cs.execute(paste);
                workbenchPart.getDiagramEditPart().getFigure().invalidate();
                workbenchPart.getDiagramEditPart().getFigure().validate();
                returnValues = DiagramCommandStack.getReturnValues(paste);
            // selectAddedObject(diagramPart.getDiagramGraphicalViewer(), returnValues);
            }
        }
        Object elements = TemplateTransfer.getInstance().getObject();
        if (elements instanceof List) {
            List<BusinessItem> list = (List<BusinessItem>) elements;
            boolean inEditors = false;
            if (older != workbenchPart) {
                inEditors = true;
            } else if (!this.isCut && orginalCopyFrom != workbenchPart) {
                // bug 16065 fixed, by xtan. to resolve the copy(A)/parse(B)/parse(B)/parse(B)... problem.
                inEditors = true;
            }
            // always keep the last one as the current selection.
            older = workbenchPart;
            GmfPastCommand pastBusiness = new GmfPastCommand((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement(), list, diagramEditPart, this.cutItemIds, this.isCut | inEditors);
            pastBusiness.setClonedSourceProcessItemsList(clonedSourceProcessItemsList);
            try {
                pastBusiness.execute(null, null);
            } catch (ExecutionException e) {
                ExceptionHandler.process(e);
            }
        }
        if (returnValues != null) {
            selectAddedObject(workbenchPart.getDiagramGraphicalViewer(), returnValues);
        }
        return null;
    }
    return command;
}
Also used : PasteViewRequest(org.eclipse.gmf.runtime.diagram.ui.requests.PasteViewRequest) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) BusinessProcessEditPart(org.talend.designer.business.model.business.diagram.edit.parts.BusinessProcessEditPart) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(org.eclipse.core.commands.ExecutionException) GmfPastCommand(org.talend.designer.business.diagram.custom.commands.GmfPastCommand) DiagramCommandStack(org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack) CommandStack(org.eclipse.gef.commands.CommandStack) IDiagramWorkbenchPart(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) BusinessProcessEditPart(org.talend.designer.business.model.business.diagram.edit.parts.BusinessProcessEditPart) EditPart(org.eclipse.gef.EditPart) IEditorPart(org.eclipse.ui.IEditorPart) Diagram(org.eclipse.gmf.runtime.notation.Diagram) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) ICommand(org.eclipse.gmf.runtime.common.core.command.ICommand) GmfPastCommand(org.talend.designer.business.diagram.custom.commands.GmfPastCommand) Command(org.eclipse.gef.commands.Command) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) BusinessItem(org.talend.designer.business.model.business.BusinessItem) BusinessProcess(org.talend.designer.business.model.business.BusinessProcess)

Example 3 with DiagramEditPart

use of org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart in project tdi-studio-se by Talend.

the class FindAssignmentAction method zoomFitSelection.

// PTODO mhelleboid bug for org.eclipse.gmf.runtime.diagram.ui.internal.actions.ZoomContributionItem
private void zoomFitSelection(ZoomManager zoomManager, List editParts, DiagramEditPart diagramEditPart, boolean zoomOutOnly) {
    Rectangle rectangle = null;
    for (Iterator iter = editParts.iterator(); iter.hasNext(); ) {
        EditPart editPart = (EditPart) iter.next();
        IFigure f = ((GraphicalEditPart) editPart).getFigure();
        rectangle = rectangle == null ? f.getBounds().getCopy() : rectangle.getUnion(f.getBounds());
    }
    // IF nothing to Zoom...
    if (rectangle == null) {
        // do nothing
        return;
    }
    // Translate the region into pixels
    MapModeUtil.getMapMode(diagramEditPart.getFigure()).LPtoDP(rectangle);
    Viewport viewport = zoomManager.getViewport();
    float xratio = viewport.getHorizontalRangeModel().getExtent() / (float) rectangle.width;
    float yratio = viewport.getVerticalRangeModel().getExtent() / (float) rectangle.height;
    double zoom = 1.0;
    zoom = (yratio < xratio) ? Math.floor(yratio * 100) : Math.floor(xratio * 100);
    if (zoomOutOnly && zoom >= 100) {
        // we should always continue in order to set the viewport
        // location
        zoom = 100;
    }
    // apply thresholds
    zoom = Math.min((int) (zoomManager.getMaxZoom() * 100), Math.max((int) (zoomManager.getMinZoom() * 100), zoom));
    int viewX = Math.round(rectangle.getTopLeft().x * (float) zoom / 100.0f);
    int viewY = Math.round(rectangle.getTopLeft().y * (float) zoom / 100.0f);
    zoomManager.setZoom(zoom / 100);
    viewport.setHorizontalLocation(viewX);
    viewport.setVerticalLocation(viewY);
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Iterator(java.util.Iterator) BusinessItemShapeEditPart(org.talend.designer.business.diagram.custom.edit.parts.BusinessItemShapeEditPart) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) BaseBusinessItemRelationShipEditPart(org.talend.designer.business.diagram.custom.edit.parts.BaseBusinessItemRelationShipEditPart) Viewport(org.eclipse.draw2d.Viewport) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IFigure(org.eclipse.draw2d.IFigure)

Example 4 with DiagramEditPart

use of org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart in project tdi-studio-se by Talend.

the class BusinessDiagramEditor method selectionChanged.

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    super.selectionChanged(part, selection);
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    JobSettingsView view = (JobSettingsView) page.findView(JobSettingsView.ID);
    getDiagramEditorInput().getItem().getProperty().eAdapters().remove(dirtyListener);
    if (view == null) {
        return;
    }
    if (!(selection instanceof IStructuredSelection)) {
        return;
    }
    Object firstElement = ((IStructuredSelection) selection).getFirstElement();
    if (!(selection instanceof IStructuredSelection)) {
        return;
    } else if (firstElement instanceof RepositoryNode) {
        return;
    }
    // for Find Assignment
    if (((IStructuredSelection) selection).size() > 0) {
        DiagramEditPart diagramEditPart = getDiagramEditPart();
        if (diagramEditPart instanceof BusinessProcessEditPart) {
            BusinessProcessEditPart processPart = (BusinessProcessEditPart) diagramEditPart;
            for (Object object : processPart.getChildren()) {
                if (object instanceof BusinessItemShapeEditPart) {
                    BusinessItemShapeEditPart shapEditPart = (BusinessItemShapeEditPart) object;
                    IFigure figure = shapEditPart.getFigure();
                    for (Object child : figure.getChildren()) {
                        if (child instanceof BusinessItemShapeFigure) {
                            BusinessItemShapeFigure shapFigure = (BusinessItemShapeFigure) child;
                            Border border = shapFigure.getBorder();
                            if (border != null) {
                                shapFigure.setDrawFrame(false);
                                shapFigure.revalidate();
                                shapFigure.repaint();
                            }
                        }
                    }
                }
            }
        }
    }
    // to refresh the jobsettings view
    if (((IStructuredSelection) selection).size() > 1) {
        view.cleanDisplay();
    } else {
        if (firstElement instanceof BusinessItemShapeEditPart || firstElement instanceof BaseBusinessItemRelationShipEditPart || firstElement instanceof NoteEditPart || firstElement instanceof NoteAttachmentEditPart) {
            view.refresh(false, firstElement);
        } else if (firstElement instanceof BusinessProcessEditPart || firstElement instanceof CompartmentEditPart) {
            view.refresh(true, this);
        }
    }
    getDiagramEditorInput().getItem().getProperty().eAdapters().add(dirtyListener);
}
Also used : JobSettingsView(org.talend.designer.core.ui.views.jobsettings.JobSettingsView) CompartmentEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart) NoteEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.NoteEditPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) BaseBusinessItemRelationShipEditPart(org.talend.designer.business.diagram.custom.edit.parts.BaseBusinessItemRelationShipEditPart) BusinessProcessEditPart(org.talend.designer.business.model.business.diagram.edit.parts.BusinessProcessEditPart) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) NoteAttachmentEditPart(org.eclipse.gmf.runtime.diagram.ui.internal.editparts.NoteAttachmentEditPart) BusinessItemShapeEditPart(org.talend.designer.business.diagram.custom.edit.parts.BusinessItemShapeEditPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Border(org.eclipse.draw2d.Border) BusinessItemShapeFigure(org.talend.designer.business.diagram.custom.figures.BusinessItemShapeFigure) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

DiagramEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart)4 BusinessItemShapeEditPart (org.talend.designer.business.diagram.custom.edit.parts.BusinessItemShapeEditPart)3 List (java.util.List)2 IFigure (org.eclipse.draw2d.IFigure)2 EditPart (org.eclipse.gef.EditPart)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 BaseBusinessItemRelationShipEditPart (org.talend.designer.business.diagram.custom.edit.parts.BaseBusinessItemRelationShipEditPart)2 BusinessProcessEditPart (org.talend.designer.business.model.business.diagram.edit.parts.BusinessProcessEditPart)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 Border (org.eclipse.draw2d.Border)1 Viewport (org.eclipse.draw2d.Viewport)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 EObject (org.eclipse.emf.ecore.EObject)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 Command (org.eclipse.gef.commands.Command)1