Search in sources :

Example 11 with SchemaTarget

use of org.talend.repository.model.json.SchemaTarget in project tdi-studio-se by Talend.

the class ExtractionFieldsWithJSONXPathEditorView method initToolBar.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.commons.ui.swt.advanced.dataeditor.AbstractDataTableEditorView#initToolBar()
     */
@Override
protected ExtendedToolbarView initToolBar() {
    return new ExtendedToolbarView(getMainComposite(), SWT.NONE, getExtendedTableViewer()) {

        @Override
        protected AddPushButtonForExtendedTable createAddPushButton() {
            return new AddPushButtonForExtendedTable(this.toolbar, getExtendedTableViewer()) {

                @Override
                protected Object getObjectToAdd() {
                    UniqueStringGenerator<SchemaTarget> generator = new UniqueStringGenerator<SchemaTarget>("column", getModel().getBeansList()) {

                        @Override
                        protected String getBeanString(SchemaTarget bean) {
                            // TODO Auto-generated method stub
                            return bean.getRelativeXPathQuery();
                        }
                    };
                    SchemaTarget tarhe = getModel().createNewSchemaTarget();
                    tarhe.setRelativeXPathQuery(generator.getUniqueString());
                    tarhe.setTagName(generator.getUniqueString());
                    return tarhe;
                }
            };
        }

        /*
             * (non-Javadoc)
             * 
             * @see org.talend.core.ui.extended.ExtendedToolbarView#createPastePushButton()
             */
        @Override
        protected PastePushButton createPastePushButton() {
            return new PastePushButtonForExtendedTable(toolbar, extendedTableViewer) {

                @Override
                protected Command getCommandToExecute(ExtendedTableModel extendedTableModel, Integer indexWhereInsert) {
                    return new ExtendedTablePasteCommand(extendedTableModel, indexWhereInsert) {

                        @Override
                        public List createPastableBeansList(ExtendedTableModel extendedTableModel, List copiedObjectsList) {
                            ArrayList list = new ArrayList();
                            JSONExtractorFieldModel fieldsModel = (JSONExtractorFieldModel) extendedTableModel;
                            for (Object current : copiedObjectsList) {
                                if (current instanceof SchemaTarget) {
                                    SchemaTarget original = (SchemaTarget) current;
                                    SchemaTarget copy = fieldsModel.createNewSchemaTarget();
                                    copy.setRelativeXPathQuery(original.getRelativeXPathQuery());
                                    copy.setTagName(original.getTagName());
                                    list.add(copy);
                                }
                            }
                            return list;
                        }
                    };
                }
            };
        }
    };
}
Also used : AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) ExtendedTablePasteCommand(org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTablePasteCommand) ArrayList(java.util.ArrayList) PastePushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButtonForExtendedTable) SchemaTarget(org.talend.repository.model.json.SchemaTarget) UniqueStringGenerator(org.talend.commons.utils.data.list.UniqueStringGenerator) ArrayList(java.util.ArrayList) List(java.util.List) ExtendedTableModel(org.talend.commons.ui.swt.extended.table.ExtendedTableModel) ExtendedToolbarView(org.talend.commons.ui.swt.advanced.dataeditor.ExtendedToolbarView)

Example 12 with SchemaTarget

use of org.talend.repository.model.json.SchemaTarget in project tdi-studio-se by Talend.

the class ExtractionFieldsWithJSONXPathEditorView method createColumns.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.commons.ui.swt.advanced.macrotable.AbstractExtendedTableViewer#createColumns(org.talend.commons.ui
     * .swt.tableviewer.TableViewerCreator, org.eclipse.swt.widgets.Table)
     */
@Override
protected void createColumns(TableViewerCreator<SchemaTarget> tableViewerCreator, final Table table) {
    CellEditorValueAdapter intValueAdapter = new CellEditorValueAdapter() {

        @Override
        public Object getOriginalTypedValue(final CellEditor cellEditor, Object value) {
            try {
                return new Integer(value.toString());
            } catch (Exception ex) {
                return null;
            }
        }

        @Override
        public Object getCellEditorTypedValue(final CellEditor cellEditor, Object value) {
            if (value != null) {
                return String.valueOf(value);
            }
            //$NON-NLS-1$
            return "";
        }
    };
    // //////////////////////////////////////////////////////////////////////////////////////
    // column for mouse selection
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    //$NON-NLS-1$
    column.setTitle("");
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    column.setWidth(15);
    // //////////////////////////////////////////////////////////////////////////////////////
    // X Path Query
    column = new TableViewerCreatorColumn(tableViewerCreator);
    xPathColumn = column;
    //$NON-NLS-1$
    column.setTitle("Relative or absolute path expression");
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<SchemaTarget, String>() {

        @Override
        public String get(SchemaTarget bean) {
            return bean.getRelativeXPathQuery();
        }

        @Override
        public void set(SchemaTarget bean, String value) {
            bean.setRelativeXPathQuery(value);
        }
    });
    xPathCellEditor = new TextCellEditorWithProposal(tableViewerCreator.getTable(), SWT.NONE, column);
    column.setCellEditor(xPathCellEditor);
    xPathCellEditor.addListener(new DialogErrorForCellEditorListener(xPathCellEditor, column) {

        @Override
        public void newValidValueTyped(int itemIndex, Object previousValue, Object newValue, CELL_EDITOR_STATE state) {
            if (state == CELL_EDITOR_STATE.EDITING) {
                linker.onXPathValueChanged(table, newValue.toString(), itemIndex);
            }
        }

        @Override
        public String validateValue(String newValue, int beanPosition) {
            String currentLoopXPath = linker.getCurrentLoopXPath();
            String value = null;
            if (newValue.trim().length() == 0) {
                return null;
            } else if (newValue.trim().startsWith(linker.getRootSeperator())) {
                value = newValue;
            } else {
                value = currentLoopXPath + linker.getFieldSeperator() + newValue;
            }
            return linker.validateXPathExpression(value);
        }
    });
    column.setModifiable(true);
    column.setWeight(30);
    column.setMinimumWidth(50);
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    // //////////////////////////////////////////////////////////////////////////////////////
    // //////////////////////////////////////////////////////////////////////////////////////
    // Tag Name
    column = new TableViewerCreatorColumn(tableViewerCreator);
    //$NON-NLS-1$
    column.setTitle("Column Name");
    column.setBeanPropertyAccessors(new IBeanPropertyAccessors<SchemaTarget, String>() {

        @Override
        public String get(SchemaTarget bean) {
            return bean.getTagName();
        }

        @Override
        public void set(SchemaTarget bean, String value) {
            bean.setTagName(value);
        }
    });
    column.setModifiable(true);
    column.setWeight(10);
    column.setMinimumWidth(50);
    // column.setCellEditor(new TextCellEditor(table));
    //$NON-NLS-1$
    column.setDefaultInternalValue("");
    final TextCellEditorWithProposal tagNameCellEditor = createTagNameEditor(tableViewerCreator, column);
    column.setCellEditor(tagNameCellEditor);
}
Also used : TextCellEditorWithProposal(org.talend.commons.ui.swt.proposal.TextCellEditorWithProposal) CELL_EDITOR_STATE(org.talend.commons.ui.swt.tableviewer.TableViewerCreator.CELL_EDITOR_STATE) CellEditor(org.eclipse.jface.viewers.CellEditor) DialogErrorForCellEditorListener(org.talend.commons.ui.swt.tableviewer.celleditor.DialogErrorForCellEditorListener) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) SchemaTarget(org.talend.repository.model.json.SchemaTarget) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)

Example 13 with SchemaTarget

use of org.talend.repository.model.json.SchemaTarget in project tdi-studio-se by Talend.

the class JSONToXPathLinker method handleListenableListAfterTableViewerRefreshedEvent.

public void handleListenableListAfterTableViewerRefreshedEvent(final ListenableListEvent<SchemaTarget> event) {
    if (event.type == ListenableListEvent.TYPE.ADDED) {
        ProgressDialog progressDialog = new ProgressDialog(getTree().getShell(), 1000) {

            private IProgressMonitor monitorWrap;

            @Override
            public void run(IProgressMonitor monitor) {
                monitorWrap = new EventLoopProgressMonitor(monitor);
                List<SchemaTarget> addedObjects = new ArrayList<SchemaTarget>(event.addedObjects);
                JSONToXPathLinker.this.createFieldsLinkWithProgressMonitor(monitorWrap, addedObjects.size(), addedObjects, event.index, addedObjects.size());
                monitorWrap.done();
            }
        };
        try {
            progressDialog.executeProcess();
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
        // Nothing to do
        }
        getBackgroundRefresher().refreshBackground();
    } else if (event.type == ListenableListEvent.TYPE.SWAPED) {
        getBackgroundRefresher().refreshBackground();
    } else if (event.type == TYPE.REMOVED) {
        getBackgroundRefresher().refreshBackground();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) SchemaTarget(org.talend.repository.model.json.SchemaTarget) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 14 with SchemaTarget

use of org.talend.repository.model.json.SchemaTarget in project tdi-studio-se by Talend.

the class JSONToXPathLinker method parseAllFieldsXPathExpressions.

public void parseAllFieldsXPathExpressions() {
    List<SchemaTarget> beansList = fieldsTableEditorView.getExtendedTableModel().getBeansList();
    int lstSize = beansList.size();
    for (int i = 0; i < lstSize; i++) {
        SchemaTarget schemaTarget = beansList.get(i);
        onXPathValueChanged(fieldsTableEditorView.getTable(), schemaTarget.getRelativeXPathQuery(), i);
    }
}
Also used : SchemaTarget(org.talend.repository.model.json.SchemaTarget)

Aggregations

SchemaTarget (org.talend.repository.model.json.SchemaTarget)14 ArrayList (java.util.ArrayList)5 JSONXPathLoopDescriptor (org.talend.repository.model.json.JSONXPathLoopDescriptor)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 List (java.util.List)2 EList (org.eclipse.emf.common.util.EList)2 TableItem (org.eclipse.swt.widgets.TableItem)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 EventLoopProgressMonitor (org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor)2 ProgressDialog (org.talend.commons.ui.swt.dialogs.ProgressDialog)2 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)2 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1