Search in sources :

Example 1 with PropertySetDialog

use of org.talend.designer.xmlmap.ui.dialog.PropertySetDialog 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)

Aggregations

EditPart (org.eclipse.gef.EditPart)1 Command (org.eclipse.gef.commands.Command)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)1 MetadataTable (org.talend.core.model.metadata.MetadataTable)1 IProcess (org.talend.core.model.process.IProcess)1 IProcess2 (org.talend.core.model.process.IProcess2)1 OutputTreeNode (org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode)1 OutputXmlTree (org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree)1 InputXmlTreeEditPart (org.talend.designer.xmlmap.parts.InputXmlTreeEditPart)1 XmlMapDataEditPart (org.talend.designer.xmlmap.parts.XmlMapDataEditPart)1 PropertySetDialog (org.talend.designer.xmlmap.ui.dialog.PropertySetDialog)1