Search in sources :

Example 1 with AddRowDialog

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

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 CommandStackForComposite (org.talend.commons.ui.command.CommandStackForComposite)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 MetadataDialog (org.talend.core.ui.metadata.dialog.MetadataDialog)1 SchemasKeyData (org.talend.designer.filemultischemas.data.SchemasKeyData)1 AddRowDialog (org.talend.designer.filemultischemas.ui.dialog.AddRowDialog)1