Search in sources :

Example 16 with SchemasKeyData

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

the class MultiSchemasUI method checkKeyValue.

private boolean checkKeyValue(String oldValue, String newValue) {
    String errorMsg = null;
    boolean canModify = true;
    if (!Pattern.matches(SCHEMA_NAME_PATTERN, newValue)) {
        errorMsg = "'" + newValue + "' is invalid value.";
    } else {
        final Object input = schemaTreeViewer.getInput();
        if (input instanceof SchemasKeyData) {
            List<String> list = new ArrayList<String>();
            final List<SchemasKeyData> children = ((SchemasKeyData) input).getChildren();
            for (SchemasKeyData schema : children) {
                final String name = schema.getUniqueRecord();
                if (!name.equals(oldValue)) {
                    list.add(name.toUpperCase());
                }
            }
            if (newValue != null && list.contains(newValue.toUpperCase())) {
                errorMsg = "'" + newValue + "' already exist.";
            }
        }
    }
    if (errorMsg != null) {
        MessageDialog.openError(schemaTreeViewer.getTree().getShell(), "Invalid value", errorMsg);
        canModify = false;
    }
    return canModify;
}
Also used : ArrayList(java.util.ArrayList) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData)

Example 17 with SchemasKeyData

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

the class UIManager method enableMovedRecord.

public boolean enableMovedRecord(TreeViewer schemaTreeViewer, boolean left) {
    if (schemaTreeViewer == null) {
        return false;
    }
    ISelection selection = schemaTreeViewer.getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (structuredSelection.size() == 1) {
            Object element = structuredSelection.getFirstElement();
            if (element instanceof SchemasKeyData) {
                SchemasKeyData data = (SchemasKeyData) element;
                SchemasKeyData parent = data.getParent();
                int index = parent.getChildren().indexOf(data);
                if (left) {
                    SchemasKeyData grandfather = parent.getParent();
                    if (grandfather == null) {
                        // in root.
                        return false;
                    }
                    if (index != parent.getChildren().size() - 1) {
                        // not the end of children.
                        return false;
                    }
                } else {
                    if (index == 0) {
                        // in first of children.
                        return false;
                    }
                }
                return true;
            }
        }
    }
    return false;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData)

Example 18 with SchemasKeyData

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

the class MultiSchemasUI method addFieldListeners.

private void addFieldListeners() {
    fileField.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            getConnection().setFilePath(fileField.getText());
            previewBtn.setEnabled(checkFieldsValue());
            clearPreview();
            refreshPreview();
        }
    });
    rowSeparatorText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            getConnection().setRowSeparatorValue(rowSeparatorText.getText());
            previewBtn.setEnabled(checkFieldsValue());
            clearPreview();
        }
    });
    fieldSeparatorText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            getConnection().setFieldSeparatorValue(fieldSeparatorText.getText());
            previewBtn.setEnabled(checkFieldsValue());
            clearPreview();
        }
    });
    useMultiSaparators.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            boolean selected = useMultiSaparators.getSelection();
            fieldSeparatorCombo.setEnabled(!selected);
            fieldSeparatorText.setEditable(!selected);
            multiSeparatorsText.setEditable(selected);
            keyValuesText.setEditable(selected);
            keyIndexText.setEditable(selected);
            escapeCharCombo.setEnabled(selected);
            textEnclosureCombo.setEnabled(selected);
            csvRadio.setSelection(selected);
            delimitedRadio.setSelection(!selected);
            delimitedRadio.setEnabled(!selected);
            if (selected) {
                getConnection().setFieldSeparatorValue(multiSeparatorsText.getText());
                multiSchemaManager.setSelectedColumnIndex(Integer.parseInt(keyIndexText.getText()));
            } else {
                getConnection().setFieldSeparatorValue(fieldSeparatorText.getText());
            }
            clearPreview();
            previewBtn.setEnabled(checkFieldsValue());
            if (previewBtn.isEnabled()) {
                refreshPreview();
            }
        }
    });
    schemaTreeViewer.getTree().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
        }
    });
    schemaTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            removeRow.setEnabled(true);
            editSchema.setEnabled(true);
            if (isReadOnly()) {
                leftBtn.setEnabled(false);
                rightBtn.setEnabled(false);
            } else {
                leftBtn.setEnabled(getUIManager().enableMovedRecord(schemaTreeViewer, true));
                rightBtn.setEnabled(getUIManager().enableMovedRecord(schemaTreeViewer, false));
            }
            IStructuredSelection selection = (IStructuredSelection) schemaTreeViewer.getSelection();
            Object element = selection.getFirstElement();
            if (element != null && (element instanceof SchemasKeyData) && ((SchemasKeyData) element).getTagLevel() > 0) {
                cardText.setText(((SchemasKeyData) element).getCard());
                cardText.setEnabled(true);
            } else {
                //$NON-NLS-1$
                cardText.setText("");
                cardText.setEnabled(false);
            }
        }
    });
    schemaTreeViewer.getTree().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
        //
        }

        @Override
        public void keyReleased(KeyEvent e) {
        //
        }
    });
    schemaTreeViewer.addTreeListener(new ITreeViewerListener() {

        public void treeCollapsed(TreeExpansionEvent event) {
        // getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
        }

        public void treeExpanded(TreeExpansionEvent event) {
        // getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
        }
    });
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) KeyEvent(org.eclipse.swt.events.KeyEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent)

Example 19 with SchemasKeyData

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

the class MultiSchemasManager method createSchemasTree.

/**
     * 
     * cLi Comment method "createSchemasTree".
     * 
     * @param csvArray
     * @return tree of data.
     */
public SchemasKeyData createSchemasTree(CSVArrayAndSeparator csvArrayBean, int selectColumnIndex) {
    if (csvArrayBean == null) {
        return null;
    }
    // final int columnIndex = 2;
    //$NON-NLS-1$
    final SchemasKeyData rootSchemasKeyData = new SchemasKeyData("");
    List<String[]> rows = csvArrayBean.getCsvArray().getRows();
    for (int i = 0; i < rows.size(); i++) {
        // if (line.length < columnIndex) { // must contain 2 columns
        // continue;
        // }
        String[] line = rows.get(i);
        final String key = precessString(line[selectColumnIndex]);
        if (key == null) {
            continue;
        }
        String newKey = key + csvArrayBean.getSeparators().get(i);
        //
        SchemasKeyData schemaData = findSchemasKeyData(rootSchemasKeyData, newKey);
        if (schemaData == null) {
            schemaData = new SchemasKeyData(key);
            // TDI-6803
            String separator = csvArrayBean.getSeparators().get(i);
            if (separator != null && separator.equals("\\")) {
                schemaData.setSeparator("\\\\");
            } else {
                schemaData.setSeparator(separator);
            }
            schemaData.setUniqueRecord(generateUniqueRecordName(null, rootSchemasKeyData));
            rootSchemasKeyData.addChild(schemaData);
        }
        //
        MultiSchemaRowData rowData = createRowData(line, selectColumnIndex);
        if (rowData != null) {
            schemaData.addRowsData(rowData);
        }
    }
    for (SchemasKeyData schemaData : rootSchemasKeyData.getChildren()) {
        createPropertiesColumns(schemaData);
    }
    return rootSchemasKeyData;
}
Also used : MultiSchemaRowData(org.talend.designer.filemultischemas.data.MultiSchemaRowData) SchemasKeyData(org.talend.designer.filemultischemas.data.SchemasKeyData)

Example 20 with SchemasKeyData

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

the class UIManager method refreshSchemasDetailView.

public void refreshSchemasDetailView(TreeViewer schemaTreeViewer, TreeViewer schemaDetailsViewer, boolean model) {
    if (schemaTreeViewer == null || schemaTreeViewer.getTree().isDisposed() || schemaDetailsViewer == null || schemaDetailsViewer.getTree().isDisposed()) {
        return;
    }
    IStructuredSelection selection = (IStructuredSelection) schemaTreeViewer.getSelection();
    Object element = selection.getFirstElement();
    if (element == null || !(element instanceof SchemasKeyData)) {
        return;
    }
    final Tree tree = schemaDetailsViewer.getTree();
    tree.setRedraw(false);
    SchemasKeyData schemasData = (SchemasKeyData) element;
    final List<MultiMetadataColumn> metadataColumns = schemasData.getMetadataColumnsInModel();
    if (model) {
        schemaDetailsViewer.setInput(metadataColumns);
        //
        tree.setRedraw(true);
        // type
        final TreeColumn typeColumn = tree.getColumns()[EPropertyName.indexOf(EPropertyName.TYPE)];
        typeColumn.pack();
    } else {
        final int colSize = metadataColumns.size();
        if (colSize > 0) {
            //
            List<String> columnProperties = new ArrayList<String>();
            // first column
            columnProperties.add(new Integer(-1).toString());
            final int columnNum = tree.getColumnCount() - 1;
            for (int i = 0; i < colSize; i++) {
                TreeColumn dataColumn = null;
                if (i < columnNum) {
                    // existed column, only update data.
                    dataColumn = tree.getColumns()[i + 1];
                } else {
                    // create new column
                    dataColumn = new TreeColumn(tree, SWT.NONE);
                    dataColumn.setWidth(100);
                }
                // MultiSchemasMetadataColumn metadataColumn = metadataColumns.get(i);
                // dataColumn.setText(metadataColumn.getLabel());
                // dataColumn.setData(metadataColumn);
                columnProperties.add(new Integer(i).toString());
            }
            schemaDetailsViewer.setColumnProperties(columnProperties.toArray(new String[0]));
            schemaDetailsViewer.setInput(schemasData);
        } else {
            schemaDetailsViewer.setInput(null);
        }
        //
        tree.setRedraw(true);
        updateColumns(tree, colSize);
    }
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) ArrayList(java.util.ArrayList) Tree(org.eclipse.swt.widgets.Tree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) 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