Search in sources :

Example 31 with EditPart

use of org.eclipse.gef.EditPart in project tdi-studio-se by Talend.

the class FindAssignmentAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
protected void doRun() {
    RepositoryNode repositoryNode = (RepositoryNode) getFirstSelectedObject();
    IEditorPart activeEditor = getActiveEditor();
    // remove frames draw last time
    for (BusinessItemShapeFigure shapFigure : repaintedFigures) {
        shapFigure.setDrawFrame(false);
        shapFigure.revalidate();
        shapFigure.repaint();
    }
    if (activeEditor instanceof BusinessDiagramEditor) {
        BusinessDiagramEditor businessDiagramEditor = (BusinessDiagramEditor) activeEditor;
        Diagram diagram = (Diagram) businessDiagramEditor.getDiagramEditPart().getModel();
        BusinessProcess businessProcess = (BusinessProcess) diagram.getElement();
        // PTODO mhelleboid use OCL or using a visitor
        List list = new ArrayList();
        for (Iterator iter = businessProcess.getBusinessItems().iterator(); iter.hasNext(); ) {
            BusinessItem businessItem = (BusinessItem) iter.next();
            for (Iterator iterator = businessItem.getAssignments().iterator(); iterator.hasNext(); ) {
                BusinessAssignment businessAssignment = (BusinessAssignment) iterator.next();
                TalendItem talendItem = businessAssignment.getTalendItem();
                IRepositoryViewObject obj = repositoryNode.getObject();
                if (talendItem.getId().equals(repositoryNode.getId())) {
                    list.add(businessItem);
                } else if (talendItem instanceof SQLPattern || talendItem instanceof Routine || talendItem instanceof TableMetadata || talendItem instanceof Query || talendItem instanceof SapFunctionMetadata) {
                    if (talendItem.getLabel().equals(repositoryNode.getProperties(EProperties.LABEL))) {
                        list.add(businessItem);
                    }
                }
            }
        }
        IDiagramGraphicalViewer diagramGraphicalViewer = businessDiagramEditor.getDiagramGraphicalViewer();
        List editParts = new ArrayList();
        for (Iterator iter = list.iterator(); iter.hasNext(); ) {
            BusinessItem businessItem = (BusinessItem) iter.next();
            editParts.addAll(diagramGraphicalViewer.findEditPartsForElement(EMFCoreUtil.getProxyID(businessItem), BaseBusinessItemRelationShipEditPart.class));
            editParts.addAll(diagramGraphicalViewer.findEditPartsForElement(EMFCoreUtil.getProxyID(businessItem), BusinessItemShapeEditPart.class));
        }
        diagramGraphicalViewer.deselectAll();
        // add a frame when use findAassignment
        for (Iterator iter = editParts.iterator(); iter.hasNext(); ) {
            EditPart editPart = (EditPart) iter.next();
            if (editPart instanceof BusinessItemShapeEditPart) {
                BusinessItemShapeEditPart shapEditPart = (BusinessItemShapeEditPart) editPart;
                IFigure figure = shapEditPart.getFigure();
                for (Object child : figure.getChildren()) {
                    if (child instanceof BusinessItemShapeFigure) {
                        BusinessItemShapeFigure shapFigure = (BusinessItemShapeFigure) child;
                        shapFigure.setDrawFrame(true);
                        shapFigure.revalidate();
                        shapFigure.repaint();
                        repaintedFigures.add(shapFigure);
                    }
                }
            }
            diagramGraphicalViewer.getSelectionManager().appendSelection(editPart);
        }
        ZoomManager zoomManager = (ZoomManager) businessDiagramEditor.getAdapter(ZoomManager.class);
        zoomFitSelection(zoomManager, editParts, businessDiagramEditor.getDiagramEditPart(), true);
    }
}
Also used : IDiagramGraphicalViewer(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer) SapFunctionMetadata(org.talend.designer.business.model.business.SapFunctionMetadata) BusinessDiagramEditor(org.talend.designer.business.model.business.diagram.part.BusinessDiagramEditor) BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) Query(org.talend.designer.business.model.business.Query) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) TalendItem(org.talend.designer.business.model.business.TalendItem) IFigure(org.eclipse.draw2d.IFigure) TableMetadata(org.talend.designer.business.model.business.TableMetadata) SQLPattern(org.talend.designer.business.model.business.SQLPattern) 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) IEditorPart(org.eclipse.ui.IEditorPart) Routine(org.talend.designer.business.model.business.Routine) RepositoryNode(org.talend.repository.model.RepositoryNode) BaseBusinessItemRelationShipEditPart(org.talend.designer.business.diagram.custom.edit.parts.BaseBusinessItemRelationShipEditPart) Diagram(org.eclipse.gmf.runtime.notation.Diagram) BusinessItemShapeEditPart(org.talend.designer.business.diagram.custom.edit.parts.BusinessItemShapeEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) BusinessItemShapeFigure(org.talend.designer.business.diagram.custom.figures.BusinessItemShapeFigure) BusinessItem(org.talend.designer.business.model.business.BusinessItem) BusinessProcess(org.talend.designer.business.model.business.BusinessProcess)

Example 32 with EditPart

use of org.eclipse.gef.EditPart in project tdi-studio-se by Talend.

the class BusinessProcessCanonicalEditPolicy method createConnections.

/**
     * @generated
     */
private Collection createConnections(Collection linkDescriptors) {
    if (linkDescriptors.isEmpty()) {
        return Collections.EMPTY_LIST;
    }
    List adapters = new LinkedList();
    for (Iterator linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator.hasNext(); ) {
        final LinkDescriptor nextLinkDescriptor = (LinkDescriptor) linkDescriptorsIterator.next();
        EditPart sourceEditPart = getEditPartFor(nextLinkDescriptor.getSource());
        EditPart targetEditPart = getEditPartFor(nextLinkDescriptor.getDestination());
        if (sourceEditPart == null || targetEditPart == null) {
            continue;
        }
        CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(nextLinkDescriptor.getSemanticAdapter(), null, ViewUtil.APPEND, false, ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint());
        CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor);
        ccr.setType(RequestConstants.REQ_CONNECTION_START);
        ccr.setSourceEditPart(sourceEditPart);
        sourceEditPart.getCommand(ccr);
        ccr.setTargetEditPart(targetEditPart);
        ccr.setType(RequestConstants.REQ_CONNECTION_END);
        Command cmd = targetEditPart.getCommand(ccr);
        if (cmd != null && cmd.canExecute()) {
            executeCommand(cmd);
            IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject();
            if (viewAdapter != null) {
                adapters.add(viewAdapter);
            }
        }
    }
    return adapters;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) DeferredLayoutCommand(org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand) Command(org.eclipse.gef.commands.Command) CreateConnectionViewRequest(org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest) Iterator(java.util.Iterator) DatabaseBusinessItemEditPart(org.talend.designer.business.model.business.diagram.edit.parts.DatabaseBusinessItemEditPart) TerminalBusinessItemEditPart(org.talend.designer.business.model.business.diagram.edit.parts.TerminalBusinessItemEditPart) ActionBusinessItemEditPart(org.talend.designer.business.model.business.diagram.edit.parts.ActionBusinessItemEditPart) DirectionalBusinessItemRelationshipEditPart(org.talend.designer.business.model.business.diagram.edit.parts.DirectionalBusinessItemRelationshipEditPart) ListBusinessItemEditPart(org.talend.designer.business.model.business.diagram.edit.parts.ListBusinessItemEditPart) DataBusinessItemEditPart(org.talend.designer.business.model.business.diagram.edit.parts.DataBusinessItemEditPart) BusinessItemRelationshipEditPart(org.talend.designer.business.model.business.diagram.edit.parts.BusinessItemRelationshipEditPart) GearBusinessItemEditPart(org.talend.designer.business.model.business.diagram.edit.parts.GearBusinessItemEditPart) InputBusinessItemEditPart(org.talend.designer.business.model.business.diagram.edit.parts.InputBusinessItemEditPart) ActorBusinessItemEditPart(org.talend.designer.business.model.business.diagram.edit.parts.ActorBusinessItemEditPart) DocumentBusinessItemEditPart(org.talend.designer.business.model.business.diagram.edit.parts.DocumentBusinessItemEditPart) EllipseBusinessItemEditPart(org.talend.designer.business.model.business.diagram.edit.parts.EllipseBusinessItemEditPart) BusinessProcessEditPart(org.talend.designer.business.model.business.diagram.edit.parts.BusinessProcessEditPart) BidirectionalBusinessItemRelationshipEditPart(org.talend.designer.business.model.business.diagram.edit.parts.BidirectionalBusinessItemRelationshipEditPart) DecisionBusinessItemEditPart(org.talend.designer.business.model.business.diagram.edit.parts.DecisionBusinessItemEditPart) EditPart(org.eclipse.gef.EditPart) IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 33 with EditPart

use of org.eclipse.gef.EditPart 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 34 with EditPart

use of org.eclipse.gef.EditPart in project cubrid-manager by CUBRID.

the class DeleteAction method buildDeleteCommands.

public Command buildDeleteCommands(List<EditPart> parts) {
    if (parts == null || parts.size() == 0) {
        return null;
    }
    GroupRequest delRequest = new GroupRequest(RequestConstants.REQ_DELETE);
    delRequest.setEditParts(parts);
    CompoundCommand compCommands = new CompoundCommand(RequestConstants.REQ_DELETE);
    for (EditPart part : parts) {
        Command cmd = part.getCommand(delRequest);
        if (cmd != null) {
            compCommands.add(cmd);
        }
    }
    return compCommands;
}
Also used : CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) GroupRequest(org.eclipse.gef.requests.GroupRequest) EditPart(org.eclipse.gef.EditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 35 with EditPart

use of org.eclipse.gef.EditPart in project cubrid-manager by CUBRID.

the class GefViewerKeyHandler method keyPressed.

/**
	 * @see org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler.keyPressed
	 * @param event KeyEvent
	 * @return true or false.
	 */
public boolean keyPressed(KeyEvent event) {
    GraphicalEditPart editPart = getFocusEditPart();
    if (editPart instanceof HANodePart) {
        if (moveHANodesByKey(event)) {
            return true;
        }
        if (deleteHANodeByKey(event)) {
            return true;
        }
    }
    if (editPart instanceof DashboardPart && event.keyCode == SWT.F5) {
        DashboardPart dp = (DashboardPart) editPart;
        dp.refresh();
        List<?> childEditPart = dp.getChildren();
        for (Object child : childEditPart) {
            ((EditPart) child).refresh();
        }
    }
    return super.keyPressed(event);
}
Also used : DashboardPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.DashboardPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) HANodePart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.HANodePart)

Aggregations

EditPart (org.eclipse.gef.EditPart)291 List (java.util.List)58 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)55 ArrayList (java.util.ArrayList)51 Command (org.eclipse.gef.commands.Command)32 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)27 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)27 Point (org.eclipse.draw2d.geometry.Point)26 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)26 Test (org.junit.Test)26 EmptyEditPart (com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart)21 ConnectionEditPart (org.eclipse.gef.ConnectionEditPart)21 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)20 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)19 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)19 Iterator (java.util.Iterator)18 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)18 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)16 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)14 DiagramConnectionEditPart (com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart)13