Search in sources :

Example 91 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class XmlDropTargetListener method handleDrop.

@Override
protected void handleDrop() {
    final Object object = TemplateTransfer.getInstance().getObject();
    if (object == null || !(object instanceof TransferedObject)) {
        return;
    }
    updateTargetRequest();
    updateTargetEditPart();
    DropContextAnalyzer analyzer = new DropContextAnalyzer((TransferedObject) object, (AbstractGraphicalEditPart) getTargetEditPart(), getDropLocation());
    if (analyzer.isDropValid()) {
        NodeType selectedNodeType = NodeType.ELEMENT;
        DropType dropType = analyzer.getDropType();
        if (dropType == DropType.DROP_OUTPUT_DOC_CHILD && getTargetEditPart() instanceof OutputTreeNodeEditPart) {
            OutputTreeNode targetOutputNode = (OutputTreeNode) ((OutputTreeNodeEditPart) getTargetEditPart()).getModel();
            Shell shell = getViewer().getControl().getShell();
            // if allNamespace , create output as namespace , if allsubTree , create output subtree , no need prompt
            boolean needPrompt = false;
            boolean hasSubTree = false;
            for (Object o : ((TransferedObject) object).getToTransfer()) {
                if (o instanceof VarNodeEditPart) {
                    needPrompt = true;
                } else if (o instanceof TreeNodeEditPart) {
                    TreeNode treeNode = (TreeNode) ((TreeNodeEditPart) o).getModel();
                    if (NodeType.ATTRIBUT.equals(treeNode.getNodeType())) {
                        needPrompt = true;
                    }
                    if (NodeType.ELEMENT.equals(treeNode.getNodeType())) {
                        if (treeNode.getChildren().isEmpty()) {
                            needPrompt = true;
                        } else {
                            hasSubTree = true;
                        }
                    }
                }
            }
            if (needPrompt) {
                DragAndDrogDialog selectDialog = new DragAndDrogDialog(shell, !targetOutputNode.getChildren().isEmpty());
                int open = selectDialog.open();
                if (open == Window.OK) {
                    if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
                        selectedNodeType = NodeType.ELEMENT;
                    } else if (DragAndDrogDialog.CREATE_AS_ATTRIBUTE.equals(selectDialog.getSelectValue())) {
                        selectedNodeType = NodeType.ATTRIBUT;
                    } else if (DragAndDrogDialog.CREATE_AS_SUBELEMENT.equals(selectDialog.getSelectValue())) {
                        selectedNodeType = NodeType.NAME_SPACE;
                    } else if (DragAndDrogDialog.CREATE_AS_TEXT.equals(selectDialog.getSelectValue())) {
                        dropType = DropType.DROP_EXPRESSION;
                    }
                } else {
                    return;
                }
            }
            if (dropType != DropType.DROP_EXPRESSION) {
                if (!targetOutputNode.getIncomingConnections().isEmpty() && ((selectedNodeType != NodeType.ATTRIBUT && selectedNodeType != NodeType.NAME_SPACE) || hasSubTree)) {
                    boolean canContinue = MessageDialog.openConfirm(null, "Warning", "Do you want to disconnect the existing linker and then add an sub element for the selected element ?");
                    if (canContinue) {
                        MapperManager mapperManager = ((XmlMapGraphicViewer) getViewer()).getMapperManager();
                        if (mapperManager != null && mapperManager.getExternalData() != null) {
                            XmlMapUtil.detachNodeConnections(targetOutputNode, mapperManager.getExternalData(), false);
                        }
                    } else {
                        return;
                    }
                }
            }
        }
        NewNodeCreationFactory factory = new NewNodeCreationFactory(dropType, selectedNodeType);
        getCreateRequest().setFactory(factory);
    }
    if (getTargetEditPart() != null) {
        Command command = getCommand();
        if (command != null && command.canExecute()) {
            getViewer().getEditDomain().getCommandStack().execute(command);
        } else {
            getCurrentEvent().detail = DND.DROP_NONE;
        }
    } else {
        getCurrentEvent().detail = DND.DROP_NONE;
    }
    selectAddedObject();
}
Also used : VarNodeEditPart(org.talend.designer.xmlmap.parts.VarNodeEditPart) MapperManager(org.talend.designer.xmlmap.ui.tabs.MapperManager) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNodeEditPart(org.talend.designer.xmlmap.parts.TreeNodeEditPart) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) Point(org.eclipse.draw2d.geometry.Point) Shell(org.eclipse.swt.widgets.Shell) Command(org.eclipse.gef.commands.Command) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) NodeType(org.talend.designer.xmlmap.model.emf.xmlmap.NodeType) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) TransferedObject(org.talend.designer.gefabstractmap.dnd.TransferedObject) OutputTreeNodeEditPart(org.talend.designer.xmlmap.parts.OutputTreeNodeEditPart) XmlMapGraphicViewer(org.talend.designer.xmlmap.editor.XmlMapGraphicViewer)

Example 92 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class XmlMapInputZoneToolBar method changProperty.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.newabstractmap.figures.treetools.zone.InputZoneTooBar#changProperty()
     */
@Override
public void changProperty() {
    boolean dieOnError = mapperManger.isDieOnError();
    PropertySetDialog propertySet = new PropertySetDialog(null, dieOnError);
    if (propertySet.open() == Window.OK) {
        if (graphicViewer != null && propertySet.isValueChanged()) {
            final boolean newValue = !dieOnError;
            CommandStack commandStack = graphicViewer.getEditDomain().getCommandStack();
            commandStack.execute(new Command() {

                @Override
                public void execute() {
                    mapperManger.setDieOnError(newValue);
                    if (newValue) {
                        if (!externalData.getOutputTrees().isEmpty()) {
                            OutputXmlTree outputTree = externalData.getOutputTrees().get(0);
                            if (outputTree.isErrorReject()) {
                                // mapperComponent.getMetadataList().add(metadataTable);
                                externalData.getOutputTrees().remove(0);
                                mapperComponent.getProcess().removeUniqueConnectionName(outputTree.getName());
                                removeMetadataTableByName(outputTree.getName());
                                if (!externalData.getOutputTrees().isEmpty()) {
                                    int indexOf = externalPart.getModelChildren().indexOf(externalData.getOutputTrees().get(0));
                                    if (indexOf != -1) {
                                        graphicViewer.select((EditPart) externalPart.getChildren().get(indexOf));
                                    }
                                }
                            }
                        }
                    } else {
                        boolean hasRejectTable = false;
                        if (!externalData.getOutputTrees().isEmpty()) {
                            OutputXmlTree outputTree = externalData.getOutputTrees().get(0);
                            if (outputTree.isErrorReject()) {
                                hasRejectTable = true;
                            }
                        }
                        if (!hasRejectTable) {
                            String baseName = MapperManager.ERROR_REJECT;
                            IProcess process = mapperComponent.getProcess();
                            String tableName = baseName;
                            if (!process.checkValidConnectionName(baseName) && process instanceof IProcess2) {
                                final String uniqueName = ((IProcess2) process).generateUniqueConnectionName("row", baseName);
                                tableName = uniqueName;
                                ((IProcess2) process).addUniqueConnectionName(uniqueName);
                            } else if (process instanceof IProcess2) {
                                tableName = baseName;
                                ((IProcess2) process).addUniqueConnectionName(baseName);
                            }
                            OutputXmlTree outputXmlTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
                            outputXmlTree.setErrorReject(true);
                            outputXmlTree.setName(tableName);
                            externalData.getOutputTrees().add(0, outputXmlTree);
                            MetadataTable metadataTable = new MetadataTable();
                            metadataTable.setLabel(tableName);
                            metadataTable.setTableName(tableName);
                            MetadataColumn errorMessageCol = new MetadataColumn();
                            errorMessageCol.setLabel(MapperManager.ERROR_REJECT_MESSAGE);
                            errorMessageCol.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
                            errorMessageCol.setNullable(true);
                            errorMessageCol.setOriginalDbColumnName(MapperManager.ERROR_REJECT_MESSAGE);
                            errorMessageCol.setReadOnly(true);
                            errorMessageCol.setCustom(true);
                            metadataTable.getListColumns().add(errorMessageCol);
                            MetadataColumn errorStackTrace = new MetadataColumn();
                            errorStackTrace.setLabel(MapperManager.ERROR_REJECT_STACK_TRACE);
                            errorStackTrace.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
                            errorStackTrace.setNullable(true);
                            errorStackTrace.setOriginalDbColumnName(MapperManager.ERROR_REJECT_STACK_TRACE);
                            errorStackTrace.setReadOnly(true);
                            errorStackTrace.setCustom(true);
                            metadataTable.getListColumns().add(errorStackTrace);
                            mapperComponent.getMetadataList().add(metadataTable);
                            OutputTreeNode errorMessageNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                            errorMessageNode.setName(MapperManager.ERROR_REJECT_MESSAGE);
                            errorMessageNode.setType(errorMessageCol.getTalendType());
                            errorMessageNode.setNullable(true);
                            outputXmlTree.getNodes().add(errorMessageNode);
                            OutputTreeNode errorStackTraceNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
                            errorStackTraceNode.setName(MapperManager.ERROR_REJECT_STACK_TRACE);
                            errorStackTraceNode.setType(errorStackTrace.getTalendType());
                            errorStackTraceNode.setNullable(true);
                            outputXmlTree.getNodes().add(errorStackTraceNode);
                            int indexOf = externalPart.getModelChildren().indexOf(outputXmlTree);
                            if (indexOf != -1) {
                                graphicViewer.select((EditPart) externalPart.getChildren().get(indexOf));
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) PropertySetDialog(org.talend.designer.xmlmap.ui.dialog.PropertySetDialog) XmlMapDataEditPart(org.talend.designer.xmlmap.parts.XmlMapDataEditPart) InputXmlTreeEditPart(org.talend.designer.xmlmap.parts.InputXmlTreeEditPart) EditPart(org.eclipse.gef.EditPart) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) Command(org.eclipse.gef.commands.Command) IProcess2(org.talend.core.model.process.IProcess2) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) IProcess(org.talend.core.model.process.IProcess)

Example 93 with Command

use of org.eclipse.gef.commands.Command in project tesb-studio-se by Talend.

the class RestResponseSchemaController method createComboCommand.

@Override
public Command createComboCommand(SelectionEvent event) {
    //Change the body type according to selected return body type
    Command changePropertyCommand = super.createComboCommand(event);
    Object newReturnType = null;
    if (changePropertyCommand != null) {
        newReturnType = ((PropertyChangeCommand) changePropertyCommand).getNewValue();
    }
    if (newReturnType == null) {
        return null;
    }
    //get old metadata column
    List<IMetadataTable> metadataList = ((INode) elem).getMetadataList();
    IMetadataTable oldMetadataTable = null;
    if (metadataList != null && metadataList.size() > 0) {
        oldMetadataTable = metadataList.get(0);
    } else {
        metadataList = new ArrayList<IMetadataTable>();
        ((INode) elem).setMetadataList(metadataList);
    }
    //create new metadata column
    IMetadataTable newMetadataTable = oldMetadataTable == null ? new MetadataTable() : oldMetadataTable.clone();
    List<IMetadataColumn> listColumns = newMetadataTable.getListColumns();
    if (listColumns == null) {
        listColumns = new ArrayList<IMetadataColumn>();
        newMetadataTable.setListColumns(listColumns);
    }
    IMetadataColumn bodyColumn = listColumns.size() > 0 ? listColumns.get(0) : new MetadataColumn();
    bodyColumn.setId("body");
    bodyColumn.setTalendType(newReturnType.toString());
    listColumns.clear();
    listColumns.add(bodyColumn);
    metadataList.clear();
    metadataList.add(newMetadataTable);
    //construct change metadata command
    ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand((INode) elem, null, oldMetadataTable, newMetadataTable);
    //construct compound command by combining above 2 commands
    CompoundCommand compoundCommand = new CompoundCommand();
    compoundCommand.add(changePropertyCommand);
    compoundCommand.add(changeMetadataCommand);
    return compoundCommand;
}
Also used : INode(org.talend.core.model.process.INode) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)

Example 94 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class MapperUI method closeMapperDialog.

public void closeMapperDialog(int response) {
    mapperResponse = response;
    if (response == SWT.OK || response == SWT.APPLICATION_MODAL) {
        prepareClosing(response);
        mapperComponent.setExternalEmfData(copyOfMapData);
        if (response == SWT.APPLICATION_MODAL) {
            IExternalNode externalNode = mapperComponent;
            IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
            if (externalNode != null && (part instanceof AbstractMultiPageTalendEditor)) {
                INode node = externalNode.getOriginalNode();
                if (node != null && node instanceof Node) {
                    Command cmd = new ExternalNodeChangeCommand((Node) node, externalNode);
                    CommandStack cmdStack = (CommandStack) part.getAdapter(CommandStack.class);
                    cmdStack.execute(cmd);
                }
            }
        }
        IElementParameter elementParameter = mapperComponent.getElementParameter("DIE_ON_ERROR");
        if (elementParameter != null) {
            elementParameter.setValue(mapperManager.isDieOnError());
        }
    }
    if (response == SWT.OK) {
        closeWithoutPrompt = true;
    }
    if (response == SWT.OK || response == SWT.CANCEL) {
        mapperShell.close();
    }
}
Also used : ExternalNodeChangeCommand(org.talend.designer.core.ui.editor.cmd.ExternalNodeChangeCommand) CommandStack(org.eclipse.gef.commands.CommandStack) INode(org.talend.core.model.process.INode) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ExternalNodeChangeCommand(org.talend.designer.core.ui.editor.cmd.ExternalNodeChangeCommand) Command(org.eclipse.gef.commands.Command) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) Node(org.talend.designer.core.ui.editor.nodes.Node) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) IElementParameter(org.talend.core.model.process.IElementParameter) IExternalNode(org.talend.core.model.process.IExternalNode)

Example 95 with Command

use of org.eclipse.gef.commands.Command in project tdi-studio-se by Talend.

the class XmlDirectEditPolicy method getDirectEditCommand.

@Override
protected Command getDirectEditCommand(DirectEditRequest request) {
    Command command = null;
    CellEditor editor = request.getCellEditor();
    Object directEditFeature = request.getDirectEditFeature();
    if (directEditFeature instanceof DirectEditType) {
        DirectEditType type = (DirectEditType) directEditFeature;
        if (getHost().getModel() instanceof AbstractNode) {
            AbstractNode model = (AbstractNode) getHost().getModel();
            switch(type) {
                case EXPRESSION:
                case NODE_NAME:
                    command = new DirectEditCommand(getHost(), model, type, request.getCellEditor().getValue());
                    break;
                case VAR_NODE_TYPE:
                    if (editor instanceof ComboBoxCellEditor) {
                        ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
                        int selectIndex = (Integer) combo.getValue();
                        command = new DirectEditCommand(getHost(), model, type, combo.getItems()[selectIndex]);
                    }
                    break;
                case LOOKUP_MODEL:
                case MATCH_MODEL:
                case JOIN_MODEL:
                case PERSISTENT_MODEL:
                case OUTPUT_REJECT:
                case LOOK_UP_INNER_JOIN_REJECT:
                    if (editor instanceof ComboBoxCellEditor) {
                        ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
                        int selectIndex = (Integer) combo.getValue();
                        command = new TreeSettingDirectEditCommand(model, type, combo.getItems()[selectIndex]);
                    }
                    break;
                case EXPRESSION_FILTER:
                    if (editor instanceof TextCellEditor) {
                        command = new TreeSettingDirectEditCommand(model, type, request.getCellEditor().getValue());
                    }
                default:
                    break;
            }
        } else {
            switch(type) {
                case LOOKUP_MODEL:
                case MATCH_MODEL:
                case JOIN_MODEL:
                case PERSISTENT_MODEL:
                case OUTPUT_REJECT:
                case LOOK_UP_INNER_JOIN_REJECT:
                case ALL_IN_ONE:
                case ENABLE_EMPTY_ELEMENT:
                    if ((editor instanceof ComboBoxCellEditor)) {
                        ComboBoxCellEditor combo = (ComboBoxCellEditor) editor;
                        int selectIndex = (Integer) combo.getValue();
                        command = new TreeSettingDirectEditCommand(getHost().getModel(), type, combo.getItems()[selectIndex]);
                    }
                    break;
                case EXPRESSION_FILTER:
                    command = new TreeSettingDirectEditCommand(getHost().getModel(), type, request.getCellEditor().getValue());
            }
        }
    }
    return command;
}
Also used : DirectEditType(org.talend.designer.gefabstractmap.part.directedit.DirectEditType) DirectEditCommand(org.talend.designer.xmlmap.commands.DirectEditCommand) Command(org.eclipse.gef.commands.Command) TreeSettingDirectEditCommand(org.talend.designer.xmlmap.commands.TreeSettingDirectEditCommand) AbstractNode(org.talend.designer.xmlmap.model.emf.xmlmap.AbstractNode) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) DirectEditCommand(org.talend.designer.xmlmap.commands.DirectEditCommand) TreeSettingDirectEditCommand(org.talend.designer.xmlmap.commands.TreeSettingDirectEditCommand) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TreeSettingDirectEditCommand(org.talend.designer.xmlmap.commands.TreeSettingDirectEditCommand) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Aggregations

Command (org.eclipse.gef.commands.Command)100 ArrayList (java.util.ArrayList)38 List (java.util.List)35 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)35 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)28 IElementParameter (org.talend.core.model.process.IElementParameter)22 Node (org.talend.designer.core.ui.editor.nodes.Node)20 INode (org.talend.core.model.process.INode)17 EditPart (org.eclipse.gef.EditPart)15 CommandStack (org.eclipse.gef.commands.CommandStack)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)14 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)14 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)13 RepositoryNode (org.talend.repository.model.RepositoryNode)13 RepositoryChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand)12 Request (org.eclipse.gef.Request)11 NonResizableEditPolicy (org.eclipse.gef.editpolicies.NonResizableEditPolicy)11 DirectEditRequest (org.eclipse.gef.requests.DirectEditRequest)11 LabelDirectEditPolicy (org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy)11