Search in sources :

Example 1 with TalendScalableFreeformRootEditPart

use of org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart in project tdi-studio-se by Talend.

the class ProcessPart method getAdapter.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getAdapter(java.lang.Class)
     */
@Override
public Object getAdapter(final Class adapter) {
    if (adapter.equals(RepositoryNode.class)) {
        if (node == null) {
            RootEditPart rootEditPart = getRoot();
            if (rootEditPart instanceof TalendScalableFreeformRootEditPart) {
                TalendScalableFreeformRootEditPart rootEditPart2 = (TalendScalableFreeformRootEditPart) rootEditPart;
                IEditorInput editorInput = rootEditPart2.getEditorInput();
                if (editorInput instanceof ProcessEditorInput) {
                    ProcessEditorInput processEditorInput = (ProcessEditorInput) editorInput;
                    node = processEditorInput.getRepositoryNode();
                }
            }
        }
        return node;
    }
    if (adapter == SnapToHelper.class) {
        List<Object> snapStrategies = new ArrayList<Object>();
        Boolean val = (Boolean) getViewer().getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY);
        val = (Boolean) getViewer().getProperty(NodeSnapToGeometry.PROPERTY_SNAP_ENABLED);
        if (val != null && val.booleanValue()) {
            snapStrategies.add(new NodeSnapToGeometry(this));
        }
        val = (Boolean) getViewer().getProperty(SnapToGrid.PROPERTY_GRID_ENABLED);
        if (val != null && val.booleanValue()) {
            snapStrategies.add(new SnapToGrid(this));
        }
        if (snapStrategies.size() == 0) {
            return null;
        }
        if (snapStrategies.size() == 1) {
            return snapStrategies.get(0);
        }
        SnapToHelper[] ss = new SnapToHelper[snapStrategies.size()];
        for (int i = 0; i < snapStrategies.size(); i++) {
            ss[i] = (SnapToHelper) snapStrategies.get(i);
        }
        return new CompoundSnapToHelper(ss);
    }
    return super.getAdapter(adapter);
}
Also used : SnapToHelper(org.eclipse.gef.SnapToHelper) CompoundSnapToHelper(org.eclipse.gef.CompoundSnapToHelper) ArrayList(java.util.ArrayList) ProcessEditorInput(org.talend.designer.core.ui.editor.ProcessEditorInput) SnapToGrid(org.eclipse.gef.SnapToGrid) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) CompoundSnapToHelper(org.eclipse.gef.CompoundSnapToHelper) IEditorInput(org.eclipse.ui.IEditorInput) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) RootEditPart(org.eclipse.gef.RootEditPart)

Example 2 with TalendScalableFreeformRootEditPart

use of org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart in project tdi-studio-se by Talend.

the class MultiPageEditorContributor method setActivePage.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.part.MultiPageEditorActionBarContributor#setActivePage(org.eclipse.ui.IEditorPart)
     */
@Override
public void setActivePage(final IEditorPart activeEditor) {
    if ((activeEditorPart == activeEditor) || (activeEditor == null)) {
        return;
    }
    activeEditorPart = activeEditor;
    if (activeEditor instanceof TalendEditor) {
        RootEditPart editPart = ((TalendEditor) activeEditor).getViewer().getRootEditPart();
        if (editPart != null && editPart instanceof TalendScalableFreeformRootEditPart) {
            ZoomManager manager = ((TalendScalableFreeformRootEditPart) ((TalendEditor) activeEditor).getViewer().getRootEditPart()).getZoomManager();
            item.setZoomManager(manager);
        }
    } else {
        item.setZoomManager(null);
    }
    IActionBars actionBars = getActionBars();
    if (actionBars != null) {
        actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), getAction(activeEditor, ActionFactory.DELETE.getId()));
        actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), getAction(activeEditor, ActionFactory.UNDO.getId()));
        actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), getAction(activeEditor, ActionFactory.REDO.getId()));
        actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), getAction(activeEditor, ActionFactory.CUT.getId()));
        actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), getAction(activeEditor, ActionFactory.COPY.getId()));
        actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), getAction(activeEditor, ActionFactory.PASTE.getId()));
        actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), getAction(activeEditor, ActionFactory.SELECT_ALL.getId()));
        actionBars.setGlobalActionHandler(ToggleSubjobsAction.ID, getAction(activeEditor, ToggleSubjobsAction.ID));
        // see bug 0003656: Actions in the main menu "View" are always disabled.
        activateActionsInViewMenu(activeEditor, actionBars, VIEW_MENU_ACTIONS_ID);
        // MOD mzhao bug 8710
        if (showAndRunProcessAction != null) {
            actionBars.setGlobalActionHandler(showAndRunProcessAction.getActionDefinitionId(), showAndRunProcessAction);
        }
        actionBars.updateActionBars();
    }
}
Also used : TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) TalendEditor(org.talend.designer.core.ui.editor.TalendEditor) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) IActionBars(org.eclipse.ui.IActionBars) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) RootEditPart(org.eclipse.gef.RootEditPart)

Example 3 with TalendScalableFreeformRootEditPart

use of org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart in project tdi-studio-se by Talend.

the class NodeResizableEditPolicy method getResizeCommand.

@Override
protected Command getResizeCommand(ChangeBoundsRequest request) {
    Object parent = getHost().getParent().getModel();
    if (!(parent instanceof NodeContainer)) {
        return null;
    }
    Node node = (Node) getHost().getModel();
    if (node.isReadOnly()) {
        return null;
    }
    TalendScalableFreeformRootEditPart rootEditPart = (TalendScalableFreeformRootEditPart) getHost().getRoot();
    double scale = 1 / rootEditPart.getZoomManager().getZoom();
    return new ResizeNodeCommand(node, new Dimension(node.getSize().width + request.getSizeDelta().getScaled(scale).width, node.getSize().height + request.getSizeDelta().getScaled(scale).height));
}
Also used : TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) ResizeNodeCommand(org.talend.designer.core.ui.editor.cmd.ResizeNodeCommand) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 4 with TalendScalableFreeformRootEditPart

use of org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart in project tdi-studio-se by Talend.

the class ComponentChooseDialog method dragOver.

@Override
public void dragOver(DropTargetEvent event) {
    // multi-drag for job,context, sqlPattern.
    IStructuredSelection selection = getSelection();
    if (selection.size() > 1) {
        boolean allowed = true;
        Item temItem = null;
        Iterator iter = selection.iterator();
        while (iter.hasNext()) {
            Object next = iter.next();
            if (next instanceof RepositoryNode) {
                RepositoryNode sourceNode = (RepositoryNode) next;
                IRepositoryViewObject object = sourceNode.getObject();
                if (object != null) {
                    Item selectItem = object.getProperty().getItem();
                    if (temItem == null) {
                        temItem = selectItem;
                        continue;
                    }
                    if (selectItem instanceof ProcessItem && !(temItem instanceof ProcessItem)) {
                        allowed = false;
                    } else if (selectItem instanceof ContextItem && !(temItem instanceof ContextItem)) {
                        allowed = false;
                    } else if (selectItem instanceof SQLPatternItem && !(temItem instanceof SQLPatternItem)) {
                        allowed = false;
                    }
                }
            }
        }
        if (!allowed) {
            event.detail = DND.DROP_NONE;
        }
    } else {
        CreateRequest req = ((CreateRequest) getTargetRequest());
        Object o = null;
        try {
            o = req.getNewObject();
        } catch (Exception e) {
            return;
        }
        if (!(o instanceof Node)) {
            return;
        }
        RootEditPart rep = editor.getViewer().getRootEditPart().getRoot();
        Point viewOriginalPosition = new Point();
        if (rep instanceof ScalableFreeformRootEditPart) {
            ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
            Viewport viewport = (Viewport) root.getFigure();
            viewOriginalPosition = viewport.getViewLocation();
        }
        org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event.x + viewOriginalPosition.x, event.y + viewOriginalPosition.y);
        Canvas canvas = (Canvas) editor.getViewer().getControl();
        swtLocation = canvas.toControl(swtLocation);
        // System.out.println("topLeft:" + topLeftpoint + " / event:" + swtLocation);
        org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
        double zoom = 1.0;
        if (editor.getViewer().getRootEditPart() instanceof TalendScalableFreeformRootEditPart) {
            ZoomManager zoomManager = ((TalendScalableFreeformRootEditPart) editor.getViewer().getRootEditPart()).getZoomManager();
            zoom = zoomManager.getZoom();
        }
        List<ConnectionPart> connectionParts = CreateComponentOnLinkHelper.getConnectionParts(editor.getProcessPart(), draw2dPosition, (Node) o);
        double minDistance = 1000000000;
        for (ConnectionPart part : connectionParts) {
            if (part.getFigure() instanceof PolylineConnection) {
                PolylineConnection connection = (PolylineConnection) part.getFigure();
                double distance = CreateComponentOnLinkHelper.getDistanceOrthogonal(draw2dPosition.x, draw2dPosition.y, connection, zoom);
                if (distance < minDistance) {
                    selectedConnectionPart = part;
                    minDistance = Math.min(distance, minDistance);
                }
            }
        }
        if (selectedConnectionPart != null && minDistance < 15) {
            for (Object child : editor.getProcessPart().getChildren()) {
                if (child instanceof SubjobContainerPart) {
                    CreateComponentOnLinkHelper.unselectAllConnections((SubjobContainerPart) child);
                }
            }
            CreateComponentOnLinkHelper.selectConnection(selectedConnectionPart);
        } else {
            if (selectedConnectionPart != null) {
                CreateComponentOnLinkHelper.unselectConnection(selectedConnectionPart);
            }
            selectedConnectionPart = null;
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) CreateRequest(org.eclipse.gef.requests.CreateRequest) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) RulesItem(org.talend.core.model.properties.RulesItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) FileItem(org.talend.core.model.properties.FileItem) Iterator(java.util.Iterator) Point(org.eclipse.draw2d.geometry.Point) Canvas(org.eclipse.swt.widgets.Canvas) Viewport(org.eclipse.draw2d.Viewport) Point(org.eclipse.draw2d.geometry.Point) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) PersistenceException(org.talend.commons.exception.PersistenceException) PolylineConnection(org.eclipse.draw2d.PolylineConnection) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) AnimatableZoomManager(org.talend.commons.ui.gmf.draw2d.AnimatableZoomManager) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart)

Example 5 with TalendScalableFreeformRootEditPart

use of org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart in project tdi-studio-se by Talend.

the class NoteResizableEditPolicy method getResizeCommand.

@Override
protected Command getResizeCommand(ChangeBoundsRequest request) {
    Object parent = getHost().getParent().getModel();
    if (!(parent instanceof Process)) {
        return null;
    }
    Note note = (Note) getHost().getModel();
    if (note.isReadOnly()) {
        return null;
    }
    TalendScalableFreeformRootEditPart rootEditPart = (TalendScalableFreeformRootEditPart) getHost().getRoot();
    double scale = 1 / rootEditPart.getZoomManager().getZoom();
    return new ResizeNoteCommand(note, new Dimension(note.getSize().width + request.getSizeDelta().getScaled(scale).width, note.getSize().height + request.getSizeDelta().getScaled(scale).height));
}
Also used : TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) ResizeNoteCommand(org.talend.designer.core.ui.editor.cmd.ResizeNoteCommand) Process(org.talend.designer.core.ui.editor.process.Process) Dimension(org.eclipse.draw2d.geometry.Dimension) PrecisionDimension(org.eclipse.draw2d.geometry.PrecisionDimension)

Aggregations

TalendScalableFreeformRootEditPart (org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart)5 RootEditPart (org.eclipse.gef.RootEditPart)3 Dimension (org.eclipse.draw2d.geometry.Dimension)2 ZoomManager (org.eclipse.gef.editparts.ZoomManager)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 PolylineConnection (org.eclipse.draw2d.PolylineConnection)1 Viewport (org.eclipse.draw2d.Viewport)1 Point (org.eclipse.draw2d.geometry.Point)1 PrecisionDimension (org.eclipse.draw2d.geometry.PrecisionDimension)1 CompoundSnapToHelper (org.eclipse.gef.CompoundSnapToHelper)1 SnapToGrid (org.eclipse.gef.SnapToGrid)1 SnapToHelper (org.eclipse.gef.SnapToHelper)1 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)1 CreateRequest (org.eclipse.gef.requests.CreateRequest)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Canvas (org.eclipse.swt.widgets.Canvas)1 IActionBars (org.eclipse.ui.IActionBars)1 IEditorInput (org.eclipse.ui.IEditorInput)1