Search in sources :

Example 61 with Command

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

the class AbstractSchemaController method createButtonCommand.

@Override
protected Command createButtonCommand(Button button) {
    // see 0003766: Problems with the read only mode of the properties on repository mode.
    if (checkForRepositoryShema(button)) {
        return null;
    }
    Button inputButton = button;
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    if (inputButton.getData(NAME).equals(SCHEMA)) {
        // this map wil hold the all input connection for the tUnite component
        Map<INode, Map<IMetadataTable, Boolean>> inputInfos = new HashMap<INode, Map<IMetadataTable, Boolean>>();
        INode node;
        if (elem instanceof Node) {
            node = (INode) elem;
        } else {
            // else instanceof Connection
            node = ((IConnection) elem).getSource();
        }
        IMetadataTable inputMetadata = null, inputMetaCopy = null;
        Connection inputConec = null;
        String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        IElementParameter param = node.getElementParameter(propertyName);
        IElementParameter connectionParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
        String connectionName = null;
        if (connectionParam != null) {
            connectionName = (String) connectionParam.getValue();
        }
        Object obj = button.getData(FORCE_READ_ONLY);
        boolean forceReadOnly = false;
        if (obj != null) {
            forceReadOnly = (Boolean) obj;
        }
        boolean inputReadOnly = false, outputReadOnly = false, inputReadOnlyNode = false, inputReadOnlyParam = false;
        for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
            if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE) || connec.getLineStyle().equals(EConnectionType.FLOW_MERGE) || connec.getLineStyle() == EConnectionType.FLOW_REF)) {
                if (connectionName != null && !connec.getName().equals(connectionName)) {
                    continue;
                }
                inputMetadata = connec.getMetadataTable();
                inputMetaCopy = inputMetadata.clone();
                inputConec = connec;
                if (connec.getSource().isReadOnly()) {
                    inputReadOnlyNode = true;
                } else {
                    for (IElementParameter curParam : connec.getSource().getElementParameters()) {
                        if (curParam.getFieldType() == EParameterFieldType.SCHEMA_TYPE || curParam.getFieldType() == EParameterFieldType.SCHEMA_REFERENCE) {
                            if (curParam.isReadOnly()) {
                                inputReadOnlyParam = true;
                            }
                        }
                    }
                }
                // check if the inputMetadata is readonly
                if (inputMetadata != null) {
                    for (IMetadataColumn column : inputMetadata.getListColumns(true)) {
                        IMetadataColumn columnCopied = inputMetaCopy.getColumn(column.getLabel());
                        columnCopied.setCustom(column.isCustom());
                        columnCopied.setReadOnly(column.isReadOnly());
                    }
                    inputMetaCopy.setReadOnly(inputMetadata.isReadOnly());
                    inputReadOnly = prepareReadOnlyTable(inputMetaCopy, inputReadOnlyParam, inputReadOnlyNode);
                }
                // store the value for Dialog
                Map<IMetadataTable, Boolean> oneInput = new HashMap<IMetadataTable, Boolean>();
                oneInput.put(inputMetaCopy, inputReadOnly);
                inputInfos.put(connec.getSource(), oneInput);
            }
        }
        if (connectionParam != null && inputMetadata == null) {
            //$NON-NLS-1$
            MessageDialog.openError(//$NON-NLS-1$
            button.getShell(), //$NON-NLS-1$
            Messages.getString("AbstractSchemaController.inputNotSet"), //$NON-NLS-1$
            Messages.getString("AbstractSchemaController.connectionNotAvaliable"));
            return null;
        }
        IMetadataTable originaleMetadataTable = getMetadataTableFromXml(node);
        // check if the outputMetadata is readonly
        IMetadataTable originaleOutputTable = node.getMetadataFromConnector(param.getContext());
        // when several schema_type button ,need get the right one which is opening
        //$NON-NLS-1$
        IElementParameter schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
        // need setRepository here
        if (!param.getContext().equals(schemaParam.getContext())) {
            //$NON-NLS-1$
            schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
        }
        if (schemaParam != null && EmfComponent.REPOSITORY.equals(schemaParam.getValue())) {
            if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
                ((MetadataTable) originaleOutputTable).setRepository(true);
            }
        } else if (schemaParam != null && EmfComponent.BUILTIN.equals(schemaParam.getValue())) {
            if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
                ((MetadataTable) originaleOutputTable).setRepository(false);
            }
        }
        if ("tUniservBTGeneric".equals(node.getComponent().getName())) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            originaleOutputTable = node.getMetadataTable("OUTPUT_SCHEMA");
        }
        IMetadataTable outputMetaCopy = originaleOutputTable.clone(true);
        for (IMetadataColumn column : originaleOutputTable.getListColumns(true)) {
            IMetadataColumn columnCopied = outputMetaCopy.getColumn(column.getLabel());
            columnCopied.setCustom(column.isCustom());
            columnCopied.setReadOnly(column.isReadOnly());
            if (//$NON-NLS-1$ //$NON-NLS-2$
            ("tLogCatcher".equals(node.getComponent().getName()) || "tStatCatcher".equals(node.getComponent().getName())) && !outputMetaCopy.sameMetadataAs(originaleMetadataTable, IMetadataColumn.OPTIONS_NONE)) {
                columnCopied.setReadOnly(false);
            }
        }
        outputMetaCopy.setReadOnly(originaleOutputTable.isReadOnly() || param.isReadOnly(node.getElementParametersWithChildrens()));
        if (//$NON-NLS-1$ //$NON-NLS-2$
        ("tLogCatcher".equals(node.getComponent().getName()) || "tStatCatcher".equals(node.getComponent().getName())) && !outputMetaCopy.sameMetadataAs(originaleMetadataTable, IMetadataColumn.OPTIONS_NONE)) {
            outputMetaCopy.setReadOnly(false);
        }
        //$NON-NLS-1$
        IElementParameter schemaTypeParam = param.getChildParameters().get("SCHEMA_TYPE");
        List<IElementParameterDefaultValue> defaultValues = schemaTypeParam.getDefaultValues();
        for (IElementParameterDefaultValue elementParameterDefaultValue : defaultValues) {
            if (elementParameterDefaultValue.getDefaultValue() instanceof MetadataTable) {
                MetadataTable table = (MetadataTable) elementParameterDefaultValue.getDefaultValue();
                outputMetaCopy.setReadOnlyColumnPosition(table.getReadOnlyColumnPosition());
                break;
            }
        }
        outputMetaCopy.sortCustomColumns();
        if (!forceReadOnly) {
            outputReadOnly = prepareReadOnlyTable(outputMetaCopy, param.isReadOnly(), node.isReadOnly());
        } else {
            outputReadOnly = true;
        }
        // create the MetadataDialog
        MetadataDialog metaDialog = null;
        if (inputMetadata != null) {
            if (inputInfos != null && inputInfos.size() > 1 && connectionName == null) {
                MetadataDialogForMerge metaDialogForMerge = new MetadataDialogForMerge(composite.getShell(), inputInfos, outputMetaCopy, node, getCommandStack());
                //$NON-NLS-1$
                metaDialogForMerge.setText(Messages.getString("AbstractSchemaController.schemaOf") + node.getLabel());
                metaDialogForMerge.setInputReadOnly(inputReadOnly);
                metaDialogForMerge.setOutputReadOnly(outputReadOnly);
                if (metaDialogForMerge.open() == MetadataDialogForMerge.OK) {
                    // inputMetaCopy = metaDialog.getInputMetaData();
                    outputMetaCopy = metaDialogForMerge.getOutputMetaData();
                    // check if the metadata is modified
                    boolean modified = false;
                    if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
                        modified = true;
                    } else {
                        if (inputMetadata != null) {
                            // Notice: the Map inputInfos maybe is modified by the dialog.
                            Set<INode> inputNodes = inputInfos.keySet();
                            for (INode inputNode : inputNodes) {
                                Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
                                inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
                                if (!inputMetaCopy.sameMetadataAs(inputNode.getMetadataList().get(0), IMetadataColumn.OPTIONS_NONE)) {
                                    modified = true;
                                }
                            }
                        }
                    }
                    // create the changeMetadataCommand
                    if (modified) {
                        if (switchParam != null) {
                            switchParam.setValue(Boolean.FALSE);
                        }
                        Command changeMetadataCommand = null;
                        // only output, no input
                        if (inputInfos.isEmpty()) {
                            changeMetadataCommand = new ChangeMetadataCommand(node, param, null, null, null, originaleOutputTable, outputMetaCopy);
                        } else {
                            Set<INode> inputNodes = inputInfos.keySet();
                            int count = 0;
                            for (INode inputNode : inputNodes) {
                                Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
                                inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
                                if (count == 0) {
                                    changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy);
                                } else {
                                    changeMetadataCommand = changeMetadataCommand.chain(new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy));
                                }
                                count++;
                            }
                        }
                        return changeMetadataCommand;
                    }
                }
            } else {
                INode inputNode = (inputConec.getSource());
                if (inputMetaCopy.getAttachedConnector() == null) {
                    INodeConnector mainConnector;
                    if (inputNode.isELTComponent()) {
                        mainConnector = inputNode.getConnectorFromType(EConnectionType.TABLE);
                    } else {
                        mainConnector = inputNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
                    }
                    inputMetaCopy.setAttachedConnector(mainConnector.getName());
                }
                metaDialog = new MetadataDialog(composite.getShell(), inputMetaCopy, inputNode, outputMetaCopy, node, getCommandStack());
            }
        } else {
            metaDialog = new MetadataDialog(composite.getShell(), outputMetaCopy, node, getCommandStack());
        }
        if (metaDialog != null) {
            //$NON-NLS-1$
            metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", node.getLabel()));
            metaDialog.setInputReadOnly(inputReadOnly);
            metaDialog.setOutputReadOnly(outputReadOnly);
            setMetadataTableOriginalNameList(inputMetadata, inputMetaCopy);
            setMetadataTableOriginalNameList(originaleOutputTable, outputMetaCopy);
            if (metaDialog.open() == MetadataDialog.OK) {
                inputMetaCopy = metaDialog.getInputMetaData();
                outputMetaCopy = metaDialog.getOutputMetaData();
                boolean modified = false;
                if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
                    modified = true;
                } else {
                    if (inputMetadata != null) {
                        if (!inputMetaCopy.sameMetadataAs(inputMetadata, IMetadataColumn.OPTIONS_NONE)) {
                            modified = true;
                        }
                    }
                }
                if (modified) {
                    if (switchParam != null) {
                        switchParam.setValue(Boolean.FALSE);
                    }
                    INode inputNode = null;
                    if (inputConec != null) {
                        inputNode = inputConec.getSource();
                    }
                    ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
                    return changeMetadataCommand;
                }
            }
        }
    } else if (inputButton.getData(NAME).equals(RETRIEVE_SCHEMA)) {
        Node node = (Node) elem;
        // String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        final Command cmd = RetrieveSchemaHelper.retrieveSchemasCommand(node);
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        return cmd;
    } else if (inputButton.getData(NAME).equals(RESET_COLUMNS)) {
        Node node = (Node) elem;
        String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        IElementParameter param = node.getElementParameter(propertyName);
        final Command cmd = SynchronizeSchemaHelper.createCommand(node, param);
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        return cmd;
    } else if (button.getData(NAME).equals(REPOSITORY_CHOICE)) {
        String paramName = (String) button.getData(PARAMETER_NAME);
        IElementParameter schemaParam = elem.getElementParameter(paramName);
        ERepositoryObjectType type = ERepositoryObjectType.METADATA_CON_TABLE;
        String filter = schemaParam.getFilter();
        if (elem instanceof Node) {
            Node sapNode = (Node) elem;
            if (sapNode.getComponent().getName().startsWith("tESB")) {
                //$NON-NLS-1$
                filter = ERepositoryObjectType.SERVICESOPERATION.getType();
            }
        }
        RepositoryReviewDialog dialog = new RepositoryReviewDialog(button.getShell(), type, filter);
        if (dialog.open() == RepositoryReviewDialog.OK) {
            RepositoryNode node = dialog.getResult();
            while (node.getObject().getProperty().getItem() == null || (!(node.getObject().getProperty().getItem() instanceof ConnectionItem))) {
                node = node.getParent();
            }
            IRepositoryViewObject object = dialog.getResult().getObject();
            Property property = object.getProperty();
            String id = property.getId();
            // The name is Table Name.
            String name = object.getLabel();
            org.talend.core.model.metadata.builder.connection.MetadataTable table = null;
            if (property.getItem() instanceof SAPConnectionItem && object instanceof MetadataTableRepositoryObject) {
                MetadataTableRepositoryObject metadataObject = (MetadataTableRepositoryObject) object;
                table = (org.talend.core.model.metadata.builder.connection.MetadataTable) metadataObject.getModelElement();
                if (table.eContainer() instanceof SAPFunctionUnit) {
                    SAPFunctionUnit function = (SAPFunctionUnit) table.eContainer();
                    String tableType = table.getTableType() == null ? MetadataSchemaType.OUTPUT.name() : table.getTableType();
                    //$NON-NLS-1$ //$NON-NLS-2$
                    name = function.getLabel() + "/" + tableType + "/" + name;
                }
            }
            if (name != null) {
                if (elem instanceof Node) {
                    Node nodeElement = (Node) elem;
                    //$NON-NLS-1$
                    String value = id + " - " + name;
                    IMetadataTable repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(value);
                    if (nodeElement.getComponent().getName().equals("tSQLTemplateMerge")) {
                        //$NON-NLS-1$
                        if (paramName.equals("SCHEMA")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            paramName = "SOURCE_TABLE";
                            Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            executeCommand(dbSelectorCommand);
                            Text labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            //$NON-NLS-1$
                            paramName = "SCHEMA:REPOSITORY_SCHEMA_TYPE";
                            dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
                            executeCommand(dbSelectorCommand);
                            labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(name));
                            //$NON-NLS-1$
                            paramName = "SCHEMA";
                        } else if (paramName.equals("SCHEMA_TARGET")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            paramName = "TARGET_TABLE";
                            Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            executeCommand(dbSelectorCommand);
                            Text labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            //$NON-NLS-1$
                            paramName = "SCHEMA_TARGET:REPOSITORY_SCHEMA_TYPE";
                            dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
                            executeCommand(dbSelectorCommand);
                            labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(name));
                            //$NON-NLS-1$
                            paramName = "SCHEMA_TARGET";
                        }
                    } else if (nodeElement.getComponent().getName().startsWith("tSQLTemplate")) {
                        //$NON-NLS-1$
                        if (paramName.equals("SCHEMA")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            paramName = "TABLE_NAME";
                            Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            executeCommand(dbSelectorCommand);
                            Text labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            //$NON-NLS-1$
                            paramName = "SCHEMA:REPOSITORY_SCHEMA_TYPE";
                            dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
                            executeCommand(dbSelectorCommand);
                            labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(name));
                            //$NON-NLS-1$
                            paramName = "SCHEMA";
                        } else if (paramName.equals("SCHEMA_TARGET")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            paramName = "TABLE_NAME_TARGET";
                            Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            executeCommand(dbSelectorCommand);
                            Text labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            //$NON-NLS-1$
                            paramName = "SCHEMA_TARGET:REPOSITORY_SCHEMA_TYPE";
                            dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
                            executeCommand(dbSelectorCommand);
                            labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(name));
                            //$NON-NLS-1$
                            paramName = "SCHEMA_TARGET";
                        }
                    } else if (nodeElement.getComponent().getName().startsWith("tSalesforce")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        paramName = paramName + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                        Command selectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(value));
                        executeCommand(selectorCommand);
                    } else {
                        Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                        executeCommand(dbSelectorCommand);
                        Text labelText = (Text) hashCurControls.get(paramName);
                        if (labelText != null) {
                            labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                        }
                    }
                }
            }
            //$NON-NLS-1$
            String value = id + " - " + name;
            //$NON-NLS-1$
            String fullParamName = paramName + ":" + getRepositoryChoiceParamName();
            org.talend.core.model.metadata.builder.connection.Connection connection = null;
            if (elem instanceof Node) {
                IMetadataTable repositoryMetadata = null;
                if (table != null && table instanceof SAPBWTable) {
                    repositoryMetadata = ConvertionHelper.convert(table);
                } else {
                    repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(value);
                    connection = MetadataToolHelper.getConnectionFromRepository(value);
                }
                // For SAP see bug 5423
                String functionId = node.getParent().getId();
                if (//$NON-NLS-1$//$NON-NLS-2$
                ((Node) elem).getUniqueName().startsWith("tSAP") && !((Node) elem).getUniqueName().startsWith("tSAPHana") && functionId != "-1") {
                    //$NON-NLS-1$
                    Node sapNode = (Node) elem;
                    repositoryMetadata = getMetadataFromRepository(id, functionId, name);
                    String functionName = node.getParent().getObject().getLabel();
                    for (IElementParameter param : sapNode.getElementParameters()) {
                        SAPParametersUtils.retrieveSAPParams(elem, connection, param, functionName);
                    }
                }
                // For validation rule.
                boolean isValRulesLost = false;
                IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
                if (currentValRuleObj != null) {
                    List<IRepositoryViewObject> valRuleObjs = ValidationRulesUtil.getRelatedValidationRuleObjs(value);
                    if (!ValidationRulesUtil.isCurrentValRuleObjInList(valRuleObjs, currentValRuleObj)) {
                        if (!MessageDialog.openConfirm(button.getShell(), //$NON-NLS-1$
                        Messages.getString("AbstractSchemaController.validationrule.title.confirm"), Messages.getString("AbstractSchemaController.validationrule.selectMetadataMsg"))) {
                            //$NON-NLS-1$
                            return null;
                        } else {
                            isValRulesLost = true;
                        }
                    }
                }
                if (repositoryMetadata == null) {
                    repositoryMetadata = new MetadataTable();
                }
                if (switchParam != null) {
                    switchParam.setValue(Boolean.FALSE);
                }
                CompoundCommand cc = new CompoundCommand();
                RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, null, null, table);
                changeMetadataCommand.setConnection(connection);
                cc.add(changeMetadataCommand);
                if (isValRulesLost) {
                    ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
                }
                return cc;
            }
        }
    } else if (button.getData(NAME).equals(COPY_CHILD_COLUMNS)) {
        String paramName = (String) button.getData(PARAMETER_NAME);
        IElementParameter param = elem.getElementParameter(paramName);
        IElementParameter processParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
        IElementParameter processIdParam = processParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
        String id = (String) processIdParam.getValue();
        Item item = ItemCacheManager.getProcessItem(id);
        Node node = (Node) elem;
        copySchemaFromChildJob(node, item);
        // pop up the schema dialog
        MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), node.getMetadataList().get(0), node, getCommandStack());
        //$NON-NLS-1$
        metaDialog.setText(Messages.getString("AbstractSchemaController.schemaOf") + node.getLabel());
        if (metaDialog.open() == MetadataDialog.OK) {
            IMetadataTable outputMetaData = metaDialog.getOutputMetaData();
            return new ChangeMetadataCommand(node, param, null, outputMetaData);
        }
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) INodeConnector(org.talend.core.model.process.INodeConnector) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Button(org.eclipse.swt.widgets.Button) IElementParameterDefaultValue(org.talend.core.model.process.IElementParameterDefaultValue) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) MetadataDialog(org.talend.core.ui.metadata.dialog.MetadataDialog) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) SAPBWTable(org.talend.core.model.metadata.builder.connection.SAPBWTable) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Text(org.eclipse.swt.widgets.Text) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryReviewDialog(org.talend.repository.ui.dialog.RepositoryReviewDialog) Point(org.eclipse.swt.graphics.Point) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Map(java.util.Map) HashMap(java.util.HashMap) MetadataDialogForMerge(org.talend.core.ui.metadata.dialog.MetadataDialogForMerge)

Example 62 with Command

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

the class CheckController method createCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
     */
private Command createCommand(SelectionEvent event) {
    Control ctrl = (Control) event.getSource();
    String paramName = (String) ctrl.getData(PARAMETER_NAME);
    // only for checkbox, other buttons must be checked
    // before
    Command cmd = null;
    Boolean value = new Boolean(((Button) ctrl).getSelection());
    // Empty EParameterName.PROCESS_TYPE_PROCESS parameter if the select job is a M/R job(TDI-25914).
    if (value && paramName.equals(EParameterName.USE_DYNAMIC_JOB.getName())) {
        if (elem instanceof Node) {
            String processParamName = EParameterName.PROCESS_TYPE_PROCESS.getName();
            IElementParameter processParameter = elem.getElementParameter(processParamName);
            if (processParameter != null) {
                String processId = String.valueOf(processParameter.getValue());
                IRepositoryNode repNode = null;
                if (StringUtils.isNotEmpty(processId)) {
                    repNode = RepositorySeekerManager.getInstance().searchRepoViewNode(processId);
                }
                if (repNode != null && ERepositoryObjectType.PROCESS_MR != null && ERepositoryObjectType.PROCESS_MR.equals(repNode.getObjectType())) {
                    //$NON-NLS-1$
                    cmd = new PropertyChangeCommand(elem, processParamName, "");
                    executeCommand(cmd);
                }
            }
        }
    }
    if (paramName.equals(EParameterName.ACTIVATE.getName())) {
        if (elem instanceof Node) {
            List<Node> nodeList = new ArrayList<Node>();
            nodeList.add((Node) elem);
            List<Connection> connList = new ArrayList<Connection>();
            cmd = new ChangeActivateStatusElementCommand(value, nodeList, connList);
        } else if (elem instanceof Connection) {
            List<Node> nodeList = new ArrayList<Node>();
            List<Connection> connList = new ArrayList<Connection>();
            connList.add((Connection) elem);
            cmd = new ChangeActivateStatusElementCommand(value, nodeList, connList);
        }
    } else {
        cmd = new PropertyChangeCommand(elem, paramName, value);
    }
    return cmd;
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ArrayList(java.util.ArrayList) Connection(org.talend.designer.core.ui.editor.connections.Connection) Control(org.eclipse.swt.widgets.Control) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) ChangeActivateStatusElementCommand(org.talend.designer.core.ui.editor.cmd.ChangeActivateStatusElementCommand) IElementParameter(org.talend.core.model.process.IElementParameter) ChangeActivateStatusElementCommand(org.talend.designer.core.ui.editor.cmd.ChangeActivateStatusElementCommand) ArrayList(java.util.ArrayList) List(java.util.List)

Example 63 with Command

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

the class ValidationRulesUtil method getRemoveValidationRuleCommands.

public static List<Command> getRemoveValidationRuleCommands(IElement elem) {
    List<Command> commands = new ArrayList<Command>();
    commands.add(new PropertyChangeCommand(elem, EParameterName.VALIDATION_RULES.getName(), false));
    commands.add(new //$NON-NLS-1$
    ChangeValuesFromRepository(//$NON-NLS-1$
    elem, //$NON-NLS-1$
    null, //$NON-NLS-1$
    "VALIDATION_RULE_TYPE:VALIDATION_RULE_TYPE", EmfComponent.BUILTIN));
    //$NON-NLS-1$
    commands.add(new PropertyChangeCommand(elem, EParameterName.REPOSITORY_VALIDATION_RULE_TYPE.getName(), ""));
    return commands;
}
Also used : PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) ConnectionDeleteCommand(org.talend.designer.core.ui.editor.cmd.ConnectionDeleteCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) ArrayList(java.util.ArrayList)

Example 64 with Command

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

the class DbTableController method openDbTableSelectorJob.

/**
     * qzhang Comment method "openDbTableSelectorJob".
     * 
     * @param openListTable
     */
private void openDbTableSelectorJob(final Button openListTable) {
    Job job = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    Messages.getString("DbTableController.openSelectionDialog")) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            //$NON-NLS-1$
            monitor.beginTask(Messages.getString("DbTableController.waitingForOpen"), IProgressMonitor.UNKNOWN);
            DatabaseConnection existConnection = getExistConnection();
            if (existConnection == null) {
                if (connParameters == null) {
                    initConnectionParameters();
                }
                existConnection = TracesConnectionUtils.createConnection(connParameters);
            }
            final DatabaseConnection con = existConnection;
            IMetadataConnection iMetadataConnection = null;
            final IMetadataConnection[] iMetadata = new IMetadataConnection[1];
            boolean isStatus = false;
            if (existConnection != null) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        IMetadataConnection convert = ConvertionHelper.convert(con);
                        iMetadata[0] = convert;
                    }
                });
                iMetadataConnection = iMetadata[0];
                // Added by Marvin Wang for bug TDI-24288.
                if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(con.getDatabaseType())) {
                    if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equalsIgnoreCase(con.getDbVersionString())) {
                        try {
                            HiveConnectionManager.getInstance().checkConnection(iMetadataConnection);
                            isStatus = true;
                        } catch (ClassNotFoundException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        } catch (InstantiationException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        } catch (IllegalAccessException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        } catch (SQLException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        }
                    }
                } else {
                    isStatus = checkConnection(iMetadataConnection);
                }
            }
            String type = null;
            if (iMetadataConnection != null) {
                type = iMetadataConnection.getDbType();
            }
            final String dbType = type;
            if (!monitor.isCanceled()) {
                try {
                    if (isStatus) {
                        // Added by Marvin Wang for bug TDI-24288.
                        if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(con.getDatabaseType())) {
                            if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equalsIgnoreCase(con.getDbVersionString())) {
                                JavaSqlFactory.doHivePreSetup((DatabaseConnection) iMetadataConnection.getCurrentConnection());
                                returnTablesFormConnection = ExtractMetaDataFromDataBase.fetchAllTablesForHiveEmbeddedModel(iMetadataConnection);
                                JavaSqlFactory.doHiveConfigurationClear();
                            }
                        } else {
                            returnTablesFormConnection = ExtractMetaDataFromDataBase.returnTablesFormConnection(iMetadataConnection);
                        }
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                final DbTableSelectorObject object = new DbTableSelectorObject();
                                DbTableSelectorObject connO = new DbTableSelectorObject();
                                if (dbType != null && dbType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName())) {
                                    connO.setLabel(connParameters.getLocalServiceName());
                                } else if ("".equals(connParameters.getDbName())) {
                                    //$NON-NLS-1$
                                    connO.setLabel(connParameters.getDatasource());
                                } else {
                                    connO.setLabel(connParameters.getDbName());
                                }
                                // ...
                                if (connO.getLabel() == null || connO.getLabel().equals("")) {
                                    //$NON-NLS-1$
                                    if (elem instanceof INode) {
                                        connO.setLabel(elem.getElementName());
                                    } else {
                                        connO.setLabel("tJDBCConnection");
                                    }
                                }
                                connO.setType(ObjectType.DB);
                                if (monitor.isCanceled()) {
                                    monitor.done();
                                    return;
                                }
                                for (String string : returnTablesFormConnection) {
                                    DbTableSelectorObject tableO = new DbTableSelectorObject();
                                    tableO.setLabel(string);
                                    tableO.setType(ObjectType.TABLE);
                                    connO.addChildren(tableO);
                                }
                                object.addChildren(connO);
                                String propertyName = (String) openListTable.getData(PARAMETER_NAME);
                                DbTableSelectorDialog selectorDialog = new DbTableSelectorDialog(composite.getShell(), object);
                                if (selectorDialog.open() == DbTableSelectorDialog.OK) {
                                    String name = selectorDialog.getSelectName();
                                    if (name != null) {
                                        Command dbSelectorCommand = new PropertyChangeCommand(elem, propertyName, TalendTextUtils.addQuotes(name));
                                        executeCommand(dbSelectorCommand);
                                        Text labelText = (Text) hashCurControls.get(propertyName);
                                        labelText.setText(TalendTextUtils.addQuotes(name));
                                    }
                                }
                            }
                        });
                    } else {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                //$NON-NLS-1$
                                String pid = "org.talend.sqlbuilder";
                                //$NON-NLS-1$
                                String mainMsg = "Database connection is failed. ";
                                ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
                                if (dialog.getCodeOfButton() == Window.OK) {
                                    openParamemerDialog(openListTable, part.getProcess().getContextManager());
                                }
                            }
                        });
                    }
                } catch (SQLException e) {
                    // Added by Marvin Wang for bug TDI-24288.
                    JavaSqlFactory.doHiveConfigurationClear();
                    ExceptionHandler.process(e);
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialog.openError(openListTable.getShell(), //$NON-NLS-1$
                            Messages.getString("DbTableController.dialog.title"), //$NON-NLS-1$
                            Messages.getString("DbTableController.dialog.contents.fetchTableFailed"));
                        }
                    });
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    if (part != null) {
        IWorkbenchSiteProgressService siteps = (IWorkbenchSiteProgressService) part.getSite().getAdapter(IWorkbenchSiteProgressService.class);
        siteps.showInDialog(composite.getShell(), job);
    } else {
        PlatformUI.getWorkbench().getProgressService().showInDialog(composite.getShell(), job);
    }
    job.setUser(true);
    job.schedule();
}
Also used : ErrorDialogWithDetailAreaAndContinueButton(org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton) INode(org.talend.core.model.process.INode) SQLException(java.sql.SQLException) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Text(org.eclipse.swt.widgets.Text) DbTableSelectorDialog(org.talend.core.ui.metadata.dialog.DbTableSelectorDialog) DbTableSelectorObject(org.talend.core.ui.metadata.dialog.DbTableSelectorObject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Job(org.eclipse.core.runtime.jobs.Job)

Example 65 with Command

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

the class DataBusinessItemNameEditPart method createDefaultEditPolicies.

/**
     * @generated
     */
protected void createDefaultEditPolicies() {
    super.createDefaultEditPolicies();
    installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
    installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicy() {

        protected List createSelectionHandles() {
            List handles = new ArrayList();
            NonResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), handles);
            return handles;
        }

        public Command getCommand(Request request) {
            return null;
        }

        public boolean understandsRequest(Request request) {
            return false;
        }
    });
}
Also used : LabelDirectEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy) Command(org.eclipse.gef.commands.Command) ArrayList(java.util.ArrayList) Request(org.eclipse.gef.Request) DirectEditRequest(org.eclipse.gef.requests.DirectEditRequest) List(java.util.List) ArrayList(java.util.ArrayList) NonResizableEditPolicy(org.eclipse.gef.editpolicies.NonResizableEditPolicy) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)

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