Search in sources :

Example 11 with SchemasKeyData

use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.

the class UIManager method moveRecord.

public void moveRecord(TreeViewer schemaTreeViewer, boolean left) {
    if (schemaTreeViewer == null) {
        return;
    }
    ISelection selection = schemaTreeViewer.getSelection();
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof SchemasKeyData) {
            SchemasKeyData data = (SchemasKeyData) element;
            SchemasKeyData parent = data.getParent();
            if (left) {
                SchemasKeyData grandfather = parent.getParent();
                if (grandfather != null) {
                    // not in root.
                    List<SchemasKeyData> children = grandfather.getChildren();
                    int index = -1;
                    for (int i = 0; i < children.size(); i++) {
                        if (children.get(i) == parent) {
                            index = i;
                            break;
                        }
                    }
                    if (index > -1) {
                        int index2 = index + 1;
                        if (index2 > children.size()) {
                            grandfather.addChild(data);
                        } else {
                            grandfather.addChild(index2, data);
                        }
                    }
                }
            } else {
                SchemasKeyData sibling = null;
                for (SchemasKeyData skd : parent.getChildren()) {
                    if (skd == data) {
                        break;
                    } else {
                        sibling = skd;
                    }
                }
                if (sibling != null) {
                    sibling.addChild(data);
                }
            }
            schemaTreeViewer.refresh();
        }
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData)

Example 12 with SchemasKeyData

use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.

the class MultiSchemasUI method addFieldsListenersGroupFileSettings.

private void addFieldsListenersGroupFileSettings() {
    // Event encodingCombo
    encodingCombo.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent e) {
            getConnection().setEncoding(encodingCombo.getText());
            checkFieldsValue();
        }
    });
    // Separator Combo (field and row)
    fieldSeparatorCombo.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent e) {
            // Label Custom of fieldSeparatorText
            fieldSeparatorManager();
        }
    });
    rowSeparatorCombo.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent e) {
            // Label Custom of rowSeparatorText
            rowSeparatorManager();
        }
    });
    // Separator Text (field and row)
    fieldSeparatorText.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent e) {
            getConnection().setFieldSeparatorValue(fieldSeparatorText.getText());
            checkFieldsValue();
        }
    });
    multiSeparatorsText.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent e) {
            getConnection().setFieldSeparatorValue(multiSeparatorsText.getText());
            previewBtn.setEnabled(checkFieldsValue());
        }
    });
    keyIndexText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.character > '9' || e.character < '0') {
                if (e.character != '\b' || e.keyCode == '') {
                    e.doit = false;
                }
            }
        }
    });
    keyIndexText.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent e) {
            boolean modify = false;
            if (keyIndexText.getText() == null || "".equals(keyIndexText.getText())) {
                multiSchemaManager.setSelectedColumnIndex(0);
                modify = true;
            } else {
                int index = 0;
                try {
                    index = Integer.parseInt(keyIndexText.getText());
                } catch (Exception ex) {
                    index = 0;
                    keyIndexText.setText(String.valueOf(index));
                }
                multiSchemaManager.setSelectedColumnIndex(index);
                modify = true;
            }
            if (modify) {
            // refreshPreview();
            }
            previewBtn.setEnabled(checkFieldsValue());
            if (previewBtn.isEnabled()) {
                refreshPreview();
            }
        }
    });
    keyValuesText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            previewBtn.setEnabled(checkFieldsValue());
        }
    });
    rowSeparatorText.addModifyListener(new ModifyListener() {

        public void modifyText(final ModifyEvent e) {
            getConnection().setRowSeparatorValue(rowSeparatorText.getText());
            checkFieldsValue();
        }
    });
    cardText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            IStructuredSelection selection = (IStructuredSelection) schemaTreeViewer.getSelection();
            Object element = selection.getFirstElement();
            if (element != null && (element instanceof SchemasKeyData)) {
                ((SchemasKeyData) element).setCard(cardText.getText());
            }
        }
    });
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 13 with SchemasKeyData

use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.

the class MultiSchemasUI method addButtonListeners.

protected void addButtonListeners() {
    // Event PreviewButton
    previewBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            refreshPreview();
        }
    });
    fetchBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            fetchCodes();
        }
    });
    leftBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            getUIManager().moveRecord(schemaTreeViewer, true);
            getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
        }
    });
    rightBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            getUIManager().moveRecord(schemaTreeViewer, false);
            getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
        }
    });
    addRow.addSelectionListener(new // hywang for 10263
    SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            SchemasKeyData root = (SchemasKeyData) schemaTreeViewer.getInput();
            AddRowDialog dialog = new AddRowDialog(MultiSchemasUI.this.getShell(), root);
            if (Window.OK == dialog.open()) {
                Object input = schemaTreeViewer.getInput();
                if (input instanceof SchemasKeyData) {
                    SchemasKeyData data = (SchemasKeyData) input;
                    List<SchemasKeyData> all = data.getChildren();
                    SchemasKeyData newData = new SchemasKeyData(dialog.getRecordValue());
                    newData.setSeparator(dialog.getSepValue());
                    newData.setUniqueRecord(dialog.getKeyValue());
                    final IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNode(getMultiSchemasComponent(), dialog.getKeyValue());
                    if (metadataTable != null) {
                        multiSchemaManager.createMultiSchemasColumns(newData, metadataTable.clone(true));
                    } else {
                        List<MultiMetadataColumn> colums = multiSchemaManager.createPropertiesColumns(newData);
                        newData.setMetadataColumns(colums);
                    }
                    all.add(newData);
                    data.addChild(newData);
                    newData.setParent(data);
                    schemaTreeViewer.refresh();
                    int len = schemaTreeViewer.getTree().getItems().length;
                    schemaTreeViewer.getTree().select(schemaTreeViewer.getTree().getItems()[len - 1]);
                }
                getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
            }
        }
    });
    removeRow.addSelectionListener(new // hywang for 10263
    SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean needRefresh = false;
            if (schemaTreeViewer == null) {
                return;
            }
            SchemasKeyData removeData = null;
            ISelection selection = schemaTreeViewer.getSelection();
            Object input = schemaTreeViewer.getInput();
            if (selection instanceof IStructuredSelection) {
                Object element = ((IStructuredSelection) selection).getFirstElement();
                if (element instanceof SchemasKeyData) {
                    removeData = (SchemasKeyData) element;
                }
            }
            if (input instanceof SchemasKeyData) {
                SchemasKeyData data = (SchemasKeyData) input;
                List<SchemasKeyData> all = data.getChildren();
                if (all.contains(removeData)) {
                    all.remove(removeData);
                    schemaTreeViewer.setInput(data);
                    needRefresh = true;
                }
                if (needRefresh) {
                    schemaTreeViewer.refresh();
                    int len = schemaTreeViewer.getTree().getItems().length;
                    if (len > 0) {
                        schemaTreeViewer.getTree().select(schemaTreeViewer.getTree().getItems()[len - 1]);
                    }
                    removeRow.setEnabled(!all.isEmpty());
                    editSchema.setEnabled(!all.isEmpty());
                    getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
                }
            }
        }
    });
    editSchema.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = schemaTreeViewer.getSelection();
            SchemasKeyData selectedData = null;
            if (selection instanceof IStructuredSelection) {
                Object element = ((IStructuredSelection) selection).getFirstElement();
                if (element instanceof SchemasKeyData) {
                    selectedData = (SchemasKeyData) element;
                    IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNode(getMultiSchemasComponent(), selectedData.getUniqueRecord());
                    if (metadataTable == null) {
                        metadataTable = new org.talend.core.model.metadata.MetadataTable();
                    }
                    metadataTable.getListColumns().clear();
                    SchemasKeyData keydata = (SchemasKeyData) schemaTreeViewer.getInput();
                    for (int i = 0; i < keydata.getChildren().size(); i++) {
                        if (selectedData.getUniqueRecord().equals(keydata.getChildren().get(i).getUniqueRecord())) {
                            metadataTable.getListColumns().addAll(keydata.getChildren().get(i).getMetadataColumns());
                            break;
                        }
                    }
                    MetadataDialog dialog = new MetadataDialog(MultiSchemasUI.this.getShell(), metadataTable, getMultiSchemasComponent(), new CommandStackForComposite(MultiSchemasUI.this.getShell()));
                    dialog.setText("Schema of " + selectedData.getUniqueRecord());
                    if (Window.OK == dialog.open()) {
                        metadataTable = dialog.getOutputMetaData();
                        if (!selectedData.getMetadataColumns().isEmpty()) {
                            selectedData.getMetadataColumns().clear();
                        }
                        multiSchemaManager.createMultiSchemasColumns(selectedData, metadataTable);
                        getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
                    }
                }
            }
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) CommandStackForComposite(org.talend.commons.ui.command.CommandStackForComposite) AddRowDialog(org.talend.designer.filemultischemas.ui.dialog.AddRowDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataDialog(org.talend.core.ui.metadata.dialog.MetadataDialog) ArrayList(java.util.ArrayList) List(java.util.List) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData)

Example 14 with SchemasKeyData

use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.

the class MultiSchemasManager method createSimpleDatas.

public void createSimpleDatas(SchemasKeyData rootData, List<Map<String, String>> schemasValues) {
    for (Map<String, String> line : schemasValues) {
        String code = line.get(IMultiSchemaConstant.RECORD);
        if (code != null) {
            // code = MultiSchemasManager.removeQuotes(code);
            code = TalendTextUtils.trimParameter(code);
            SchemasKeyData data = new SchemasKeyData(code);
            final String schemaName = line.get(IMultiSchemaConstant.SCHEMA);
            if (schemaName != null) {
                final IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNode(getMultiSchemasComponent(), schemaName);
                if (metadataTable != null) {
                    data.setUniqueRecord(schemaName);
                    createMultiSchemasColumns(data, metadataTable.clone(true));
                }
                rootData.addChild(data);
            }
            String text = line.get(IMultiSchemaConstant.KEY_COLUMN_INDEX);
            if (text == null) {
                //$NON-NLS-1$
                text = "";
            }
            final String keyColumnIndex = TalendTextUtils.removeQuotes(text);
            //$NON-NLS-1$
            String[] keys = keyColumnIndex.split(",");
            for (String name : keys) {
                try {
                    List<MultiMetadataColumn> metadataColumns = data.getMetadataColumns();
                    int index = Integer.parseInt(name);
                    for (int i = 0; i < metadataColumns.size(); i++) {
                        MultiMetadataColumn multiMetadataColumn = metadataColumns.get(i);
                        if (index == i) {
                            multiMetadataColumn.setKey(true);
                        } else {
                            multiMetadataColumn.setKey(false);
                        }
                    }
                } catch (NumberFormatException e) {
                //
                }
            }
            String card = line.get(IMultiSchemaConstant.CARDINALITY);
            if (card == null) {
                //$NON-NLS-1$
                card = TalendTextUtils.addQuotes("");
            }
            data.setCard(card);
            String keyIndex = line.get(IMultiSchemaConstant.FIELDDELIMITED);
            if (keyIndex == null) {
                //$NON-NLS-1$
                keyIndex = "";
            } else {
                keyIndex = TalendTextUtils.removeQuotes(keyIndex);
            }
            data.setSeparator(keyIndex);
        }
    }
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData) MultiMetadataColumn(org.talend.designer.filemultischemas.data.MultiMetadataColumn)

Example 15 with SchemasKeyData

use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.

the class MultiSchemasManager method retrieveRelativeParent.

private void retrieveRelativeParent(SchemasKeyData rootData, List<Map<String, String>> schemasValues) {
    for (Map<String, String> line : schemasValues) {
        String code = line.get(IMultiSchemaConstant.RECORD);
        if (code != null) {
            code = TalendTextUtils.removeQuotes(code);
            SchemasKeyData currentData = findKeyData(rootData, code);
            if (currentData != null) {
                String codeParent = line.get(IMultiSchemaConstant.PARENT_RECORD);
                if (codeParent != null) {
                    codeParent = TalendTextUtils.removeQuotes(codeParent);
                }
                if (codeParent == null || "".equals(codeParent.trim())) {
                    // root //$NON-NLS-1$
                    rootData.addChild(currentData);
                } else {
                    SchemasKeyData parentData = findKeyData(rootData, codeParent.trim());
                    if (parentData != null) {
                        parentData.addChild(currentData);
                        // set the added column, last column.
                        List<MultiMetadataColumn> metadataColumns = currentData.getMetadataColumns();
                        if (!metadataColumns.isEmpty()) {
                            MultiMetadataColumn multiMetadataColumn = metadataColumns.get(metadataColumns.size() - 1);
                            metadataColumns.remove(multiMetadataColumn);
                            currentData.setAddedColumn(multiMetadataColumn);
                        }
                    }
                }
            }
        }
    }
}
Also used : SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData) MultiMetadataColumn(org.talend.designer.filemultischemas.data.MultiMetadataColumn)

Aggregations

SchemasKeyData (org.talend.designer.filemultischemas.data.SchemasKeyData)21 MultiMetadataColumn (org.talend.designer.filemultischemas.data.MultiMetadataColumn)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 ArrayList (java.util.ArrayList)5 ISelection (org.eclipse.jface.viewers.ISelection)3 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 KeyAdapter (org.eclipse.swt.events.KeyAdapter)2 KeyEvent (org.eclipse.swt.events.KeyEvent)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Tree (org.eclipse.swt.widgets.Tree)2 TreeColumn (org.eclipse.swt.widgets.TreeColumn)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 CommandStackForComposite (org.talend.commons.ui.command.CommandStackForComposite)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1