Search in sources :

Example 11 with Canvas

use of org.eclipse.swt.widgets.Canvas in project cubrid-manager by CUBRID.

the class ERDThumbnailViewPart method drawThumbnail.

/**
	 * Draw the thumbnail
	 * 
	 * @param rootEditPart
	 */
private void drawThumbnail(ScalableFreeformRootEditPart rootEditPart) {
    canvas = new Canvas(container, SWT.None);
    canvas.setLayout(new FillLayout());
    canvas.setBackground(ResourceManager.getColor(SWT.COLOR_WHITE));
    liSystem = new LightweightSystem(canvas);
    thumbnail = new ScrollableThumbnail((Viewport) rootEditPart.getFigure());
    thumbnail.setViewport((Viewport) rootEditPart.getFigure());
    thumbnail.setSource(rootEditPart.getLayer(LayerConstants.SCALABLE_LAYERS));
    liSystem.setContents(thumbnail);
    container.layout();
}
Also used : Canvas(org.eclipse.swt.widgets.Canvas) Viewport(org.eclipse.draw2d.Viewport) LightweightSystem(org.eclipse.draw2d.LightweightSystem) FillLayout(org.eclipse.swt.layout.FillLayout) ScrollableThumbnail(org.eclipse.draw2d.parts.ScrollableThumbnail)

Example 12 with Canvas

use of org.eclipse.swt.widgets.Canvas 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 13 with Canvas

use of org.eclipse.swt.widgets.Canvas in project tesb-studio-se by Talend.

the class CamelEditorDropTargetListener method createNewComponent.

public void createNewComponent(DropTargetEvent event1) {
    boolean quickCreateInput = event1.detail == DND.DROP_LINK;
    boolean quickCreateOutput = event1.detail == DND.DROP_COPY;
    List<TempStore> list = new ArrayList<TempStore>();
    List<IComponent> components = new ArrayList<IComponent>();
    for (Object obj : selectSourceList) {
        if (obj instanceof RepositoryNode) {
            RepositoryNode sourceNode = (RepositoryNode) obj;
            ERepositoryObjectType type = sourceNode.getObjectType();
            Item item = sourceNode.getObject().getProperty().getItem();
            TempStore store = new TempStore();
            store.seletetedNode = sourceNode;
            getAppropriateComponent(item, quickCreateInput, quickCreateOutput, store, type);
            if (store.component != null) {
                list.add(store);
            } else {
                MessageDialog.openInformation(editor.getEditorSite().getShell(), //$NON-NLS-1$
                Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.title"), //$NON-NLS-1$
                Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.content"));
                return;
            }
        }
        org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event1.x, event1.y);
        Canvas canvas = (Canvas) editor.getViewer().getControl();
        /*
             * translate to Canvas coordinate
             */
        swtLocation = canvas.toControl(swtLocation);
        /*
             * translate to Viewport coordinate with zoom
             */
        org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
        /*
             * calcule the view port position. Take into acounte the scroll position
             */
        ProcessPart part = (ProcessPart) editor.getViewer().getRootEditPart().getRoot().getChildren().get(0);
        IFigure targetFigure = part.getFigure();
        translateAbsolateToRelative(targetFigure, draw2dPosition);
        // creates every node
        for (TempStore store : list) {
            RepositoryNode selectedNode = store.seletetedNode;
            IComponent element = store.component;
            if (!components.contains(element)) {
                components.add(element);
            }
            Node node = new Node(element);
            IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
            if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
                String LabelValue = null;
                if (CorePlugin.getDefault().getDesignerCoreService().getPreferenceStore(TalendDesignerPrefConstants.DEFAULT_LABEL).equals(node.getPropertyValue(EParameterName.LABEL.getName()))) {
                    // dnd a default
                    LabelValue = selectedNode.getObject().getLabel();
                }
                if (LabelValue != null) {
                    node.setPropertyValue(EParameterName.LABEL.getName(), LabelValue);
                }
            }
            NodeContainer nc = ((Process) node.getProcess()).loadNodeContainer(node, false);
            // create the node on the design sheet
            execCommandStack(new CreateNodeContainerCommand((Process) editor.getProcess(), nc, draw2dPosition));
            // initialize the propertiesView
            CompoundCommand cc = new CompoundCommand();
            createRefreshingPropertiesCommand(cc, selectedNode, node);
            execCommandStack(cc);
            draw2dPosition = draw2dPosition.getCopy();
            draw2dPosition.x += TalendEditor.GRID_SIZE;
            draw2dPosition.y += TalendEditor.GRID_SIZE;
            node.checkNode();
        }
    }
}
Also used : IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) ArrayList(java.util.ArrayList) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) Process(org.talend.designer.core.ui.editor.process.Process) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IFigure(org.eclipse.draw2d.IFigure) Canvas(org.eclipse.swt.widgets.Canvas) RepositoryNode(org.talend.repository.model.RepositoryNode) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

Canvas (org.eclipse.swt.widgets.Canvas)13 PaintEvent (org.eclipse.swt.events.PaintEvent)5 PaintListener (org.eclipse.swt.events.PaintListener)5 Point (org.eclipse.draw2d.geometry.Point)4 Node (org.talend.designer.core.ui.editor.nodes.Node)4 ArrayList (java.util.ArrayList)3 Viewport (org.eclipse.draw2d.Viewport)3 MouseEvent (org.eclipse.swt.events.MouseEvent)3 Point (org.eclipse.swt.graphics.Point)3 Iterator (java.util.Iterator)2 List (java.util.List)2 IFigure (org.eclipse.draw2d.IFigure)2 LightweightSystem (org.eclipse.draw2d.LightweightSystem)2 ScrollableThumbnail (org.eclipse.draw2d.parts.ScrollableThumbnail)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 CreationFactory (org.eclipse.gef.requests.CreationFactory)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 FillLayout (org.eclipse.swt.layout.FillLayout)2