Search in sources :

Example 1 with CommandStackForComposite

use of org.talend.commons.ui.command.CommandStackForComposite in project tdi-studio-se by Talend.

the class JSONFileStep2Form method addGroupSchemaTarget.

private void addGroupSchemaTarget(final Composite mainComposite, final int width, final int height) {
    // Group Schema Viewer
    schemaTargetGroup = Form.createGroup(mainComposite, 1, "Target Schema", height);
    // to correct graphic bug under Linux-GTK when the wizard is opened the first time
    if (WindowSystem.isGTK() && firstTimeWizardOpened.equals(Boolean.TRUE)) {
        schemaTargetGroup.addListener(SWT.Paint, new Listener() {

            @Override
            public void handleEvent(Event event) {
                Point offsetPoint = event.display.map(linker.getBgDrawableComposite(), schemaTargetGroup, new Point(0, 0));
                linker.setOffset(offsetPoint);
                linker.drawBackground(event.gc);
            }
        });
    }
    // ///////////////////////////////////////////
    schemaTargetGroup.setBackgroundMode(SWT.INHERIT_FORCE);
    CommandStackForComposite commandStack = new CommandStackForComposite(schemaTargetGroup);
    loopModel = new JSONExtractorLoopModel("Path loop expression");
    loopTableEditorView = new ExtractionLoopWithJSONXPathEditorView(loopModel, schemaTargetGroup);
    loopTableEditorView.getExtendedTableViewer().setCommandStack(commandStack);
    GridData data2 = new GridData(GridData.FILL_HORIZONTAL);
    data2.heightHint = 90;
    final Composite loopTableEditorComposite = loopTableEditorView.getMainComposite();
    loopTableEditorComposite.setLayoutData(data2);
    loopTableEditorComposite.setBackground(null);
    // to correct graphic bug under Linux-GTK when the wizard is opened the first time
    if (WindowSystem.isGTK() && firstTimeWizardOpened.equals(Boolean.TRUE)) {
        loopTableEditorComposite.addListener(SWT.Paint, new Listener() {

            @Override
            public void handleEvent(Event event) {
                Point offsetPoint = event.display.map(linker.getBgDrawableComposite(), loopTableEditorComposite, new Point(0, 0));
                linker.setOffset(offsetPoint);
                linker.drawBackground(event.gc);
            }
        });
    }
    // ///////////////////////////////////////////
    // Messages.getString("FileStep3.metadataDescription")
    fieldsModel = new JSONExtractorFieldModel("Fields to extract");
    fieldsTableEditorView = new ExtractionFieldsWithJSONXPathEditorView(fieldsModel, schemaTargetGroup);
    fieldsTableEditorView.getExtendedTableViewer().setCommandStack(commandStack);
    final Composite fieldTableEditorComposite = fieldsTableEditorView.getMainComposite();
    data2 = new GridData(GridData.FILL_BOTH);
    data2.heightHint = 180;
    fieldTableEditorComposite.setLayoutData(data2);
    fieldTableEditorComposite.setBackground(null);
    // to correct graphic bug under Linux-GTK when the wizard is opened the first time
    if (WindowSystem.isGTK() && firstTimeWizardOpened.equals(Boolean.TRUE)) {
        fieldTableEditorComposite.addListener(SWT.Paint, new Listener() {

            @Override
            public void handleEvent(Event event) {
                Point offsetPoint = event.display.map(linker.getBgDrawableComposite(), fieldTableEditorComposite, new Point(0, 0));
                linker.setOffset(offsetPoint);
                linker.drawBackground(event.gc);
            }
        });
    }
// ///////////////////////////////////////////
}
Also used : CommandStackForComposite(org.talend.commons.ui.command.CommandStackForComposite) JSONExtractorFieldModel(org.talend.repository.json.ui.wizards.extraction.JSONExtractorFieldModel) IModifiedBeanListener(org.talend.commons.ui.swt.tableviewer.IModifiedBeanListener) IPreviewHandlerListener(org.talend.metadata.managment.ui.preview.IPreviewHandlerListener) IListenableListListener(org.talend.commons.utils.data.list.IListenableListListener) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) CommandStackForComposite(org.talend.commons.ui.command.CommandStackForComposite) ExtractionLoopWithJSONXPathEditorView(org.talend.repository.json.ui.wizards.extraction.ExtractionLoopWithJSONXPathEditorView) GridData(org.eclipse.swt.layout.GridData) ListenableListEvent(org.talend.commons.utils.data.list.ListenableListEvent) Event(org.eclipse.swt.widgets.Event) ModifiedBeanEvent(org.talend.commons.ui.swt.tableviewer.ModifiedBeanEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ExtractionFieldsWithJSONXPathEditorView(org.talend.repository.json.ui.wizards.extraction.ExtractionFieldsWithJSONXPathEditorView) Point(org.eclipse.swt.graphics.Point) JSONExtractorLoopModel(org.talend.repository.json.ui.wizards.extraction.JSONExtractorLoopModel)

Example 2 with CommandStackForComposite

use of org.talend.commons.ui.command.CommandStackForComposite in project tdi-studio-se by Talend.

the class JSONFileStep2Form method resetStatusIfNecessary.

/**
     * see bug 0004206: bug on the loop limit case in JSONfile source metadata defining
     */
private void resetStatusIfNecessary() {
    String curJSONPath = getConnection().getJSONFilePath();
    //$NON-NLS-1$
    String oraginalPath = "";
    if (jsonFilePath != null && curJSONPath != null) {
        // change JSON file
        if (isContextMode()) {
            ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
            oraginalPath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, curJSONPath));
        }
        if ((!jsonFilePath.equals(curJSONPath) && !jsonFilePath.equals(oraginalPath)) || !this.wizard.getReadbyMode().equals(currentReadbyMode)) {
            currentReadbyMode = this.wizard.getReadbyMode();
            // clear command stack
            CommandStackForComposite commandStack = new CommandStackForComposite(schemaTargetGroup);
            loopTableEditorView.getExtendedTableViewer().setCommandStack(commandStack);
            fieldsTableEditorView.getExtendedTableViewer().setCommandStack(commandStack);
            getConnection().getSchema().remove(jsonXPathLoopDescriptor);
            jsonXPathLoopDescriptor = JsonFactory.eINSTANCE.createJSONXPathLoopDescriptor();
            getConnection().getSchema().add(jsonXPathLoopDescriptor);
            loopModel.setJSONXPathLoopDescriptor(jsonXPathLoopDescriptor);
            XmlArray.setLimitToDefault();
            jsonXPathLoopDescriptor.setLimitBoucle(XmlArray.getRowLimit());
            fieldsModel.setJSONXPathLoopDescriptor(jsonXPathLoopDescriptor.getSchemaTargets());
            fieldsTableEditorView.getTableViewerCreator().layout();
            initTreePopulator();
            prepareJsonLinker();
            // reset linker
            linker.init(treePopulator);
            loopTableEditorView.setLinker(linker);
            fieldsTableEditorView.setLinker(linker);
            jsonFilePreview.removePreviewContent();
        }
    }
    if (isContextMode()) {
        jsonFilePath = oraginalPath;
    } else {
        jsonFilePath = curJSONPath;
    }
}
Also used : CommandStackForComposite(org.talend.commons.ui.command.CommandStackForComposite) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType)

Example 3 with CommandStackForComposite

use of org.talend.commons.ui.command.CommandStackForComposite 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

CommandStackForComposite (org.talend.commons.ui.command.CommandStackForComposite)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 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 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1 IModifiedBeanListener (org.talend.commons.ui.swt.tableviewer.IModifiedBeanListener)1 ModifiedBeanEvent (org.talend.commons.ui.swt.tableviewer.ModifiedBeanEvent)1 IListenableListListener (org.talend.commons.utils.data.list.IListenableListListener)1 ListenableListEvent (org.talend.commons.utils.data.list.ListenableListEvent)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 MetadataDialog (org.talend.core.ui.metadata.dialog.MetadataDialog)1 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)1 SchemasKeyData (org.talend.designer.filemultischemas.data.SchemasKeyData)1