Search in sources :

Example 1 with CreateRequest

use of org.eclipse.gef.requests.CreateRequest in project tesb-studio-se by Talend.

the class CamelEditorDropTargetListener method handleDrop.

@Override
protected void handleDrop() {
    if (!checkSelectionSource()) {
        return;
    }
    updateTargetRequest();
    updateTargetEditPart();
    if (selectSourceList.get(0) instanceof PaletteEditPart && getTargetRequest() instanceof CreateRequest) {
        if (getTargetEditPart() instanceof ProcessPart) {
            Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
            if (newObject != null) {
                Command command = getCommand();
                if (command != null) {
                    execCommandStack(command);
                }
            }
        }
        return;
    }
    if (isContextSource) {
        createContext();
    } else {
        if (!(getTargetEditPart() instanceof NodeContainerPart)) {
            try {
                createNewComponent(getCurrentEvent());
            } catch (OperationCanceledException e) {
                return;
            }
        }
    }
    // in case after drag/drop the editor is dirty but can not get focus
    if (editor.isDirty()) {
        editor.setFocus();
    }
    this.eraseTargetFeedback();
}
Also used : NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CreateRequest(org.eclipse.gef.requests.CreateRequest) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) PaletteEditPart(org.eclipse.gef.ui.palette.editparts.PaletteEditPart)

Example 2 with CreateRequest

use of org.eclipse.gef.requests.CreateRequest in project dbeaver by serge-rider.

the class NodeDropTargetListener method createTargetRequest.

@Override
protected Request createTargetRequest() {
    CreateRequest request = new CreateRequest();
    request.setFactory(new CreationFactory() {

        @Override
        public Object getNewObject() {
            Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
            if (objects == null) {
                return null;
            }
            return DiagramObjectCollector.generateEntityList(((DiagramPart) getViewer().getRootEditPart().getContents()).getDiagram(), objects);
        }

        @Override
        public Object getObjectType() {
            return RequestConstants.REQ_CREATE;
        }
    });
    request.setLocation(getDropLocation());
    return request;
}
Also used : CreateRequest(org.eclipse.gef.requests.CreateRequest) CreationFactory(org.eclipse.gef.requests.CreationFactory) Collection(java.util.Collection) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DiagramPart(org.jkiss.dbeaver.ext.erd.part.DiagramPart)

Example 3 with CreateRequest

use of org.eclipse.gef.requests.CreateRequest 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 4 with CreateRequest

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

the class ComponentChooseDialog method createTargetRequest.

@Override
protected Request createTargetRequest() {
    fromPalette = false;
    CreateRequest request = new CreateRequest();
    CreationFactory factory = getFactory(LocalSelectionTransfer.getTransfer().getSelection());
    if (factory != null) {
        fromPalette = true;
        request.setFactory(factory);
        return request;
    }
    return super.createTargetRequest();
}
Also used : CreateRequest(org.eclipse.gef.requests.CreateRequest) CreationFactory(org.eclipse.gef.requests.CreationFactory)

Example 5 with CreateRequest

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

the class ComponentChooseDialog method handleDrop.

// private void checkRequiredModules() {
// Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
// if (newObject instanceof Node) {
// IComponent component = ((Node) newObject).getComponent();
// Shell shell = Display.getCurrent().getActiveShell();
// ModulesInstallerUtil.installModules(new Shell(shell), component);
// }
// }
/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.dnd.TemplateTransferDropTargetListener#handleDrop()
     */
@Override
protected void handleDrop() {
    updateTargetRequest();
    updateTargetEditPart();
    // checkRequiredModules();
    if (fromPalette && getTargetRequest() instanceof CreateRequest) {
        if (selectedConnectionPart != null) {
            CreateRequest req = ((CreateRequest) getTargetRequest());
            Object o = req.getNewObject();
            Point location = req.getLocation();
            if (o instanceof Node) {
                createComponentOnLink((Node) o, location);
            }
            // checkRequiredModules();
            return;
        } else if (getTargetEditPart() instanceof ProcessPart) {
            // for palette dnd, feature 6457
            Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
            if (newObject != null) {
                Command command = getCommand();
                if (command != null) {
                    execCommandStack(command);
                }
            }
            // checkRequiredModules();
            return;
        } else if (getTargetEditPart() instanceof SubjobContainerPart) {
            // TDI-24985:for palette dnd.
            Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
            if (newObject != null) {
                Command command = getCommand();
                if (command != null) {
                    execCommandStack(command);
                }
            }
            return;
        } else if (getTargetEditPart() instanceof JobletContainerPart) {
            JobletContainerPart jobletPart = (JobletContainerPart) getTargetEditPart();
            if (isLock(jobletPart)) {
                Shell shell = Display.getCurrent().getActiveShell();
                ChooseJobletDialog dialog = new ChooseJobletDialog(new Shell(shell), getDropLocation());
                if (dialog.open() == dialog.OK) {
                    EditPart part = getTargetEditPart();
                    if (dialog.addToJoblet()) {
                        AbstractMultiPageTalendEditor openEditor = getJobletPart((JobletContainerPart) part);
                        part = openEditor.getDesignerEditor().getProcessPart();
                        // editor = openEditor.getTalendEditor();
                        setTargetEditPart(part);
                        Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
                        if (newObject != null) {
                            Command command = getCommand();
                            if (command != null) {
                                CommandStack commandStack = (CommandStack) openEditor.getAdapter(CommandStack.class);
                                if (commandStack != null) {
                                    commandStack.execute(command);
                                } else {
                                    command.execute();
                                }
                            }
                        }
                        // checkRequiredModules();
                        return;
                    } else {
                        part = getParentPart(part);
                        setTargetEditPart(part);
                        Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
                        if (newObject != null) {
                            Command command = getCommand();
                            if (command != null) {
                                execCommandStack(command);
                            }
                        }
                        // checkRequiredModules();
                        return;
                    }
                }
            }
        }
    }
    List<Object> sources = getSelectSource();
    if (containsContextSource(sources)) {
        createContext(sources);
    } else {
        if (!(getTargetEditPart() instanceof NodeContainerPart)) {
            try {
                createNewComponent(getCurrentEvent());
            } catch (OperationCanceledException e) {
                return;
            }
        } else {
            if (containsSQLPatternSource(sources)) {
                createSQLPattern(sources);
            } else {
                Object obj = getSelection().getFirstElement();
                createSchema(obj, getTargetEditPart());
                createQuery(obj, getTargetEditPart());
                createProperty(obj, getTargetEditPart());
                createChildJob(obj, getTargetEditPart());
                createValidationRule(obj, getTargetEditPart());
                if (obj instanceof IRepositoryNode) {
                    propaHadoopCfgChanges((IRepositoryNode) obj);
                }
                for (IExtendedNodeHandler hander : ExtendedNodeManager.getExtendedNodeHandler()) {
                    boolean updated = hander.updateComponent(obj, getTargetEditPart(), editor.getCommandStack());
                    if (updated) {
                        break;
                    }
                }
            }
        }
    }
    // in case after drag/drop the editor is dirty but can not get focus
    if (editor.isDirty()) {
        editor.setFocus();
    }
    this.eraseTargetFeedback();
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) IRepositoryNode(org.talend.repository.model.IRepositoryNode) 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) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) TalendScalableFreeformRootEditPart(org.talend.designer.core.ui.editor.TalendScalableFreeformRootEditPart) RootEditPart(org.eclipse.gef.RootEditPart) EditPart(org.eclipse.gef.EditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) PaletteEditPart(org.eclipse.gef.ui.palette.editparts.PaletteEditPart) JobletContainerPart(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainerPart) Point(org.eclipse.draw2d.geometry.Point) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) ChooseJobletDialog(org.talend.designer.core.ui.dialog.mergeorder.ChooseJobletDialog) IExtendedNodeHandler(org.talend.designer.core.IExtendedNodeHandler) Shell(org.eclipse.swt.widgets.Shell) ConnectionCreateCommand(org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand) RepositoryChangeMetadataForSAPCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForSAPCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) RepositoryChangeQueryCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeQueryCommand) ConnectionReconnectCommand(org.talend.designer.core.ui.editor.cmd.ConnectionReconnectCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) RepositoryChangeMetadataForEBCDICCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForEBCDICCommand) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) 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)

Aggregations

CreateRequest (org.eclipse.gef.requests.CreateRequest)5 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 Point (org.eclipse.draw2d.geometry.Point)2 RootEditPart (org.eclipse.gef.RootEditPart)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)2 CreationFactory (org.eclipse.gef.requests.CreationFactory)2 PaletteEditPart (org.eclipse.gef.ui.palette.editparts.PaletteEditPart)2 HL7FileNode (org.talend.core.model.metadata.builder.connection.HL7FileNode)2 XMLFileNode (org.talend.core.model.metadata.builder.connection.XMLFileNode)2 IExternalNode (org.talend.core.model.process.IExternalNode)2 INode (org.talend.core.model.process.INode)2 MapperExternalNode (org.talend.core.model.process.node.MapperExternalNode)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)2 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)2 QueryRepositoryObject (org.talend.core.repository.model.repositoryObject.QueryRepositoryObject)2 SAPFunctionRepositoryObject (org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject)2 SAPIDocRepositoryObject (org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject)2