Search in sources :

Example 1 with PaletteEditPart

use of org.eclipse.gef.ui.palette.editparts.PaletteEditPart in project tesb-studio-se by Talend.

the class CamelEditorDropTargetListener method checkSelectionSource.

/**
     * Routelet and context types are validated
     * 
     * @return true if validated
     */
private boolean checkSelectionSource() {
    isContextSource = false;
    selectSourceList.clear();
    boolean isRouteletSource = false;
    LocalSelectionTransfer transfer = (LocalSelectionTransfer) getTransfer();
    IStructuredSelection selection = (IStructuredSelection) transfer.getSelection();
    Iterator iterator = selection.iterator();
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof RepositoryNode) {
            RepositoryNode sourceNode = (RepositoryNode) obj;
            if (sourceNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.PROCESS_ROUTELET) {
                selectSourceList.add(obj);
                isRouteletSource = true;
            }
            Item item = sourceNode.getObject().getProperty().getItem();
            if (item instanceof ContextItem) {
                selectSourceList.add(obj);
                isContextSource = true;
            }
        } else if (obj instanceof PaletteEditPart) {
            selectSourceList.add(obj);
            Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
            if (newObject != null && newObject instanceof INode) {
                if (((INode) newObject).getComponent().getComponentType() == EComponentType.JOBLET) {
                    selectSourceList.add(newObject);
                    isRouteletSource = true;
                }
            }
        }
    }
    if (selectSourceList.size() == 0) {
        return false;
    }
    if (isRouteletSource) {
        List<String> routeletList = new ArrayList<String>();
        for (INode node : editor.getProcess().getGraphicalNodes()) {
            if (node.getComponent().getComponentType() == EComponentType.JOBLET) {
                routeletList.add(node.getComponent().getName());
            }
        }
        boolean isDuplicateRoutelet = false;
        String duplicatesName = "";
        for (Object object : selectSourceList) {
            if (object instanceof RepositoryNode) {
                RepositoryNode sourceNode = (RepositoryNode) object;
                if (sourceNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.PROCESS_ROUTELET) {
                    if (routeletList.contains(sourceNode.getProperties(EProperties.LABEL))) {
                        isDuplicateRoutelet = true;
                        //$NON-NLS-1$
                        duplicatesName += " ," + sourceNode.getProperties(EProperties.LABEL);
                    }
                }
            } else if (object instanceof INode) {
                INode node = (INode) object;
                if (node.getComponent().getComponentType() == EComponentType.JOBLET) {
                    if (routeletList.contains(node.getComponent().getName())) {
                        isDuplicateRoutelet = true;
                        //$NON-NLS-1$                            
                        duplicatesName += " ," + node.getComponent().getName();
                    }
                }
            }
        }
        if (isDuplicateRoutelet) {
            //$NON-NLS-1$
            MessageDialog.openInformation(//$NON-NLS-1$
            editor.getEditorSite().getShell(), //$NON-NLS-1$
            "Adding Routelet", //$NON-NLS-1$
            "Do not allow duplicate Routelets\nRoutelet \"" + duplicatesName.substring(2) + "\" already exist.");
            return false;
        }
    }
    return true;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) PaletteEditPart(org.eclipse.gef.ui.palette.editparts.PaletteEditPart) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) Iterator(java.util.Iterator) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer)

Example 2 with PaletteEditPart

use of org.eclipse.gef.ui.palette.editparts.PaletteEditPart 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)

Aggregations

PaletteEditPart (org.eclipse.gef.ui.palette.editparts.PaletteEditPart)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Command (org.eclipse.gef.commands.Command)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 CreateRequest (org.eclipse.gef.requests.CreateRequest)1 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 INode (org.talend.core.model.process.INode)1 ContextItem (org.talend.core.model.properties.ContextItem)1 Item (org.talend.core.model.properties.Item)1 ProcessItem (org.talend.core.model.properties.ProcessItem)1 CreateNodeContainerCommand (org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand)1 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)1 NodeContainerPart (org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart)1 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)1 RepositoryNode (org.talend.repository.model.RepositoryNode)1