Search in sources :

Example 26 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager 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 27 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project dbeaver by dbeaver.

the class ERDEditorPart method configureGraphicalViewer.

@Override
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    this.getGraphicalViewer().getControl().setBackground(UIUtils.getColorRegistry().get(ERDConstants.COLOR_ERD_DIAGRAM_BACKGROUND));
    GraphicalViewer graphicalViewer = getGraphicalViewer();
    /*
        MenuManager manager = new MenuManager(getClass().getName(), getClass().getName());
        manager.setRemoveAllWhenShown(true);
        getEditorSite().registerContextMenu(getClass().getName() + ".EditorContext", manager, graphicalViewer, true); //$NON-NLS-1$
*/
    IPreferenceStore store = ERDActivator.getDefault().getPreferenceStore();
    graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, store.getBoolean(ERDConstants.PREF_GRID_ENABLED));
    graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, store.getBoolean(ERDConstants.PREF_GRID_ENABLED));
    graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_SPACING, new Dimension(store.getInt(ERDConstants.PREF_GRID_WIDTH), store.getInt(ERDConstants.PREF_GRID_HEIGHT)));
    // initialize actions
    createActions();
    // Setup zoom manager
    ZoomManager zoomManager = rootPart.getZoomManager();
    List<String> zoomLevels = new ArrayList<>(3);
    zoomLevels.add(ZoomManager.FIT_ALL);
    zoomLevels.add(ZoomManager.FIT_WIDTH);
    zoomLevels.add(ZoomManager.FIT_HEIGHT);
    zoomManager.setZoomLevelContributions(zoomLevels);
    zoomManager.setZoomLevels(new double[] { .1, .25, .5, .75, 1.0, 1.5, 2.0, 2.5, 3, 4 });
    IAction zoomIn = new ZoomInAction(zoomManager);
    IAction zoomOut = new ZoomOutAction(zoomManager);
    addAction(zoomIn);
    addAction(zoomOut);
    graphicalViewer.addSelectionChangedListener(event -> {
        String status;
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        if (selection.isEmpty()) {
            status = "";
        } else if (selection.size() == 1) {
            status = CommonUtils.toString(selection.getFirstElement());
        } else {
            status = String.valueOf(selection.size()) + " objects";
        }
        progressControl.setInfo(status);
        updateActions(editPartActionIDs);
    });
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager) Dimension(org.eclipse.draw2d.geometry.Dimension) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 28 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project knime-core by knime.

the class WorkflowEditor method setZoomfactor.

private void setZoomfactor(final double z) {
    ZoomManager zoomManager = this.getZoomManager();
    zoomManager.setZoom(z);
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager)

Example 29 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project knime-core by knime.

the class WorkflowEditorDropTargetListener method getInsertLocation.

/**
 * Computes the location of the new node and also determines if some node should be moved.
 *
 * A successor node is selected for the move action if the distance between this node and the successor is
 * smaller than the {@link WorkflowEditorDropTargetListener#MINIMUM_NODE_DISTANCE} and if they overlap vertically.
 *
 * @return point where the new node should be inserted and sets
 *         {@link WorkflowEditorDropTargetListener#m_distanceToMoveTarget}
 */
private Point getInsertLocation() {
    ZoomManager zoomManager = (ZoomManager) getViewer().getProperty(ZoomManager.class.toString());
    double zoom = zoomManager.getZoom();
    int adjustedMinimumNodeDistance = (int) (MINIMUM_NODE_DISTANCE * zoom);
    double adjustedMinimumNodeDistanceBeforeInsertion = MINIMUM_NODE_DISTANCE_BEFORE_INSERTION * zoom;
    Point dropLocation = getDropLocation();
    Point insertLocation = dropLocation;
    int[] sourceBounds = null;
    int[] targetBounds = null;
    int sourceAnnotationHeight = 0;
    int targetAnnotationHeight = 0;
    EditPart source = m_edge.getSource().getParent();
    EditPart target = m_edge.getTarget().getParent();
    NodeContainerEditPart nextNode = null;
    if (source instanceof WorkflowInPortBarEditPart && target instanceof NodeContainerEditPart) {
        // metanode start --> first node in metanode
        WorkflowInPortBarEditPart sourceBar = ((WorkflowInPortBarEditPart) source);
        NodeContainerEditPart targetNode = (NodeContainerEditPart) target;
        Rectangle bounds = sourceBar.getFigure().getBounds();
        org.eclipse.swt.graphics.Point p = getViewer().getControl().toControl(bounds.x, bounds.y);
        sourceBounds = new int[] { p.x, p.y, bounds.width, bounds.height };
        targetBounds = targetNode.getNodeContainer().getUIInformation().getBounds();
        targetAnnotationHeight = targetNode.getNodeAnnotationEditPart().getModel().getHeight();
        nextNode = targetNode;
    } else if (source instanceof NodeContainerEditPart && target instanceof WorkflowOutPortBarEditPart) {
        // last node in metanode --> metanode end
        NodeContainerEditPart sourceNode = (NodeContainerEditPart) source;
        WorkflowOutPortBarEditPart targetBar = (WorkflowOutPortBarEditPart) target;
        sourceBounds = sourceNode.getNodeContainer().getUIInformation().getBounds();
        Rectangle bounds = targetBar.getFigure().getBounds();
        targetBounds = new int[] { bounds.x, bounds.y, bounds.width, bounds.height };
        sourceAnnotationHeight = sourceNode.getNodeAnnotationEditPart().getModel().getHeight();
    } else if (source instanceof WorkflowInPortBarEditPart && target instanceof WorkflowOutPortBarEditPart) {
        // metanode start --> metanode end
        WorkflowInPortBarEditPart sourceBar = (WorkflowInPortBarEditPart) source;
        WorkflowOutPortBarEditPart targetBar = (WorkflowOutPortBarEditPart) target;
        sourceBounds = sourceBar.getNodeContainer().getUIInformation().getBounds();
        targetBounds = targetBar.getNodeContainer().getUIInformation().getBounds();
    } else if (source instanceof NodeContainerEditPart && target instanceof NodeContainerEditPart) {
        // node --> node
        NodeContainerEditPart sourceNode = (NodeContainerEditPart) source;
        NodeContainerEditPart targetNode = (NodeContainerEditPart) target;
        sourceBounds = sourceNode.getNodeContainer().getUIInformation().getBounds();
        targetBounds = targetNode.getNodeContainer().getUIInformation().getBounds();
        sourceAnnotationHeight = sourceNode.getNodeAnnotationEditPart().getModel().getHeight();
        targetAnnotationHeight = targetNode.getNodeAnnotationEditPart().getModel().getHeight();
        nextNode = targetNode;
    }
    if (sourceBounds != null && targetBounds != null) {
        sourceBounds = recomputeBounds(sourceBounds);
        targetBounds = recomputeBounds(targetBounds);
        if (0 <= targetBounds[0] - sourceBounds[0] && targetBounds[0] - sourceBounds[0] >= adjustedMinimumNodeDistanceBeforeInsertion) {
            m_distanceToMoveTarget = 0;
        } else {
            m_distanceToMoveTarget = adjustedMinimumNodeDistance + (sourceBounds[0] + adjustedMinimumNodeDistance - targetBounds[0]);
            m_distanceToMoveTarget = (int) (m_distanceToMoveTarget / zoom);
        }
        insertLocation = new Point(getXLocation(dropLocation.x, sourceBounds[0], zoom), getYLocation(dropLocation.y, sourceBounds[1], targetBounds[1], zoom));
        if (WorkflowEditor.getActiveEditorSnapToGrid()) {
            insertLocation = WorkflowEditor.getActiveEditorClosestGridLocation(insertLocation);
        }
        getViewer().getSelectionManager().deselectAll();
        if (nextNode != null && selectSuccessor(sourceBounds[0], targetBounds[0], sourceBounds[1], sourceBounds[1] + sourceBounds[3] + sourceAnnotationHeight, targetBounds[1], targetBounds[1] + targetBounds[3] + targetAnnotationHeight, zoom)) {
            selectNodes(nextNode, zoom);
        }
    }
    return insertLocation;
}
Also used : WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager)

Example 30 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project knime-core by knime.

the class AddAnnotationCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    // adapt location to the viewport location and the zoom factor
    // this seems to be a workaround for a bug in the framework
    ZoomManager zoomManager = (ZoomManager) m_viewer.getProperty(ZoomManager.class.toString());
    // adjust the location according to the viewport position
    // seems to be a workaround for a bug in the framework
    // (should imediately deliver the correct view position and not
    // the position of the viewport)
    PrecisionPoint location = new PrecisionPoint(m_location.x, m_location.y);
    WorkflowEditor.adaptZoom(zoomManager, location, true);
    m_anno = new WorkflowAnnotation();
    AnnotationData data = new AnnotationData();
    // it is a workflow annotation
    data.setBgColor(INITIAL_FLOWANNO_COLOR);
    data.setDimension((int) location.preciseX, (int) location.preciseY, DEFAULT_WIDTH, DEFAULT_HEIGHT);
    data.setBorderSize(AnnotationEditPart.getAnnotationDefaultBorderSizePrefValue());
    data.setBorderColor(INITAL_FLOWBORDER_COLOR);
    data.setText(INITIAL_FLOWANNO_TEXT);
    data.setStyleRanges(new AnnotationData.StyleRange[0]);
    m_anno.copyFrom(data, true);
    WorkflowManager hostWFM = getHostWFM();
    hostWFM.addWorkflowAnnotation(m_anno);
    m_viewer.deselectAll();
    // select the new ones....
    if (m_viewer.getRootEditPart().getContents() != null && m_viewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
        ((WorkflowRootEditPart) m_viewer.getRootEditPart().getContents()).setFutureAnnotationSelection(Collections.singleton(m_anno));
    }
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager) AnnotationData(org.knime.core.node.workflow.AnnotationData) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) WorkflowAnnotation(org.knime.core.node.workflow.WorkflowAnnotation)

Aggregations

ZoomManager (org.eclipse.gef.editparts.ZoomManager)46 Point (org.eclipse.draw2d.geometry.Point)14 ArrayList (java.util.ArrayList)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 Dimension (org.eclipse.draw2d.geometry.Dimension)4 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)4 ZoomInAction (org.eclipse.gef.ui.actions.ZoomInAction)4 ZoomOutAction (org.eclipse.gef.ui.actions.ZoomOutAction)4 Iterator (java.util.Iterator)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 GraphicalViewer (org.eclipse.gef.GraphicalViewer)3 IAction (org.eclipse.jface.action.IAction)3 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)2 Bendpoint (org.eclipse.draw2d.Bendpoint)2 FigureCanvas (org.eclipse.draw2d.FigureCanvas)2 Viewport (org.eclipse.draw2d.Viewport)2 KeyHandler (org.eclipse.gef.KeyHandler)2