Search in sources :

Example 1 with VarsTable

use of org.talend.designer.mapper.model.table.VarsTable in project tdi-studio-se by Talend.

the class VarsDataMapTableView method createToolItems.

@Override
protected void createToolItems() {
    // /////////////////////////////////////////////////////////////////
    ToolItem addEntryItem = new ToolItem(toolBarActions, SWT.PUSH);
    addEntryItem.setEnabled(!getMapperManager().componentIsReadOnly());
    //$NON-NLS-1$
    addEntryItem.setToolTipText(Messages.getString("VarsDataMapTableView.entryItemTooltip.addVariable"));
    addEntryItem.setImage(org.talend.commons.ui.runtime.image.ImageProvider.getImage(org.talend.commons.ui.runtime.image.ImageProvider.getImageDesc(EImage.ADD_ICON)));
    addEntryItem.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            TableViewerCreator<IColumnEntry> tableViewerCreator = getExtendedTableViewerForColumns().getTableViewerCreator();
            tableViewerCreator.applyActivatedCellEditor();
            Table table = getExtendedTableViewerForColumns().getTable();
            int[] indices = table.getSelectionIndices();
            int indexInsert = table.getItemCount();
            if (indices.length > 0) {
                indexInsert = indices[indices.length - 1] + 1;
            }
            IDataMapTable dataMapTable = VarsDataMapTableView.this.getDataMapTable();
            String varName = null;
            if (dataMapTable instanceof VarsTable) {
                //$NON-NLS-1$
                varName = ((VarsTable) dataMapTable).findUniqueColumnName("var");
            } else {
                throw new UnsupportedOperationException(Messages.getString(//$NON-NLS-1$
                "VarsDataMapTableView.exceptionMessage.caseNotFound"));
            }
            ILanguage currentLanguage = LanguageProvider.getCurrentLanguage();
            String type = null;
            if (currentLanguage.getCodeLanguage() == ECodeLanguage.JAVA) {
                type = JavaTypesManager.STRING.getId();
            } else {
                // fix bug 0018996 ,when add a var row,there is no default type,this bug exsit for long time
                type = PerlTypesManager.STRING;
            }
            mapperManager.addNewVarEntry(VarsDataMapTableView.this, varName, indexInsert, type);
            tableViewerCreatorForColumns.getTableViewer().refresh();
            if (canBeResizedAtPreferedSize()) {
                VarsDataMapTableView.this.changeSize(VarsDataMapTableView.this.getPreferredSize(true, true, false), true, true);
                changeMinimizeState(false);
            }
            mapperManager.getUiManager().refreshBackground(true, false);
            table.setSelection(indexInsert);
            removeEntryItem.setEnabled(true);
            moveUpEntryItem.setEnabled(true);
            moveDownEntryItem.setEnabled(true);
        }
    });
    // /////////////////////////////////////////////////////////////////
    // /////////////////////////////////////////////////////////////////
    removeEntryItem = new ToolItem(toolBarActions, SWT.PUSH);
    removeEntryItem.setEnabled(false);
    removeEntryItem.setImage(org.talend.commons.ui.runtime.image.ImageProvider.getImage(org.talend.commons.ui.runtime.image.ImageProvider.getImageDesc(EImage.MINUS_ICON)));
    //$NON-NLS-1$
    removeEntryItem.setToolTipText(Messages.getString("VarsDataMapTableView.entryItemTooltip.removeVariable"));
    removeEntryItem.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewerCreatorForColumns.getTableViewer().getSelection();
            List<ITableEntry> selectedBeans = selection.toList();
            for (ITableEntry entry : selectedBeans) {
                mapperManager.removeTableEntry(entry);
            }
            if (selectedBeans.size() > 0) {
                tableViewerCreatorForColumns.getTableViewer().refresh();
                mapperManager.getUiManager().refreshBackground(true, false);
                if (canBeResizedAtPreferedSize()) {
                    resizeAtExpandedSize();
                }
            }
            removeEntryItem.setEnabled(false);
        }
    });
    // /////////////////////////////////////////////////////////////////
    // /////////////////////////////////////////////////////////////////
    moveUpEntryItem = new ToolItem(toolBarActions, SWT.PUSH);
    moveUpEntryItem.setEnabled(false);
    moveUpEntryItem.setImage(ImageProvider.getImage(EImage.UP_ICON));
    //$NON-NLS-1$
    moveUpEntryItem.setToolTipText(Messages.getString("VarsDataMapTableView.entryItemTooltip.moveUpVariable"));
    moveUpEntryItem.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            AbstractExtendedTableViewer viewer = getExtendedTableViewerForColumns();
            ExtendedTableMoveCommand moveCommand = new ExtendedTableMoveCommand(viewer.getExtendedTableModel(), true, viewer.getTableViewerCreator().getTable().getSelectionIndices());
            viewer.getTableViewerCreator().applyActivatedCellEditor();
            viewer.executeCommand(moveCommand);
        }
    });
    // /////////////////////////////////////////////////////////////////
    // /////////////////////////////////////////////////////////////////
    moveDownEntryItem = new ToolItem(toolBarActions, SWT.PUSH);
    moveDownEntryItem.setEnabled(false);
    moveDownEntryItem.setImage(ImageProvider.getImage(EImage.DOWN_ICON));
    //$NON-NLS-1$
    moveDownEntryItem.setToolTipText(Messages.getString("VarsDataMapTableView.entryItemTooltip.movedownVariable"));
    moveDownEntryItem.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            AbstractExtendedTableViewer viewer = getExtendedTableViewerForColumns();
            ExtendedTableMoveCommand moveCommand = new ExtendedTableMoveCommand(viewer.getExtendedTableModel(), false, viewer.getTableViewerCreator().getTable().getSelectionIndices());
            viewer.getTableViewerCreator().applyActivatedCellEditor();
            viewer.executeCommand(moveCommand);
        }
    });
// /////////////////////////////////////////////////////////////////
}
Also used : ExtendedTableMoveCommand(org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTableMoveCommand) VarsTable(org.talend.designer.mapper.model.table.VarsTable) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) Table(org.eclipse.swt.widgets.Table) VarsTable(org.talend.designer.mapper.model.table.VarsTable) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ILanguage(org.talend.designer.mapper.language.ILanguage) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LineSelectionEvent(org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent) AbstractExtendedTableViewer(org.talend.commons.ui.swt.extended.table.AbstractExtendedTableViewer) List(java.util.List) ToolItem(org.eclipse.swt.widgets.ToolItem) ILineSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.selection.ILineSelectionListener) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with VarsTable

use of org.talend.designer.mapper.model.table.VarsTable in project tdi-studio-se by Talend.

the class ExpressionProposalProvider method getVariables.

public List<Variable> getVariables() {
    List<Variable> variables = new ArrayList<Variable>();
    for (IDataMapTable table : this.tables) {
        List<IColumnEntry> dataMapTableEntries = table.getColumnEntries();
        for (IColumnEntry entrySource : dataMapTableEntries) {
            String variable = null;
            if (table instanceof VarsTable) {
                variable = entrySource.getExpression();
            } else {
                variable = LanguageProvider.getCurrentLanguage().getLocation(entrySource.getParentName(), entrySource.getName());
            }
            String talendType = null;
            boolean nullable = true;
            if (entrySource instanceof AbstractInOutTableEntry) {
                talendType = ((AbstractInOutTableEntry) entrySource).getMetadataColumn().getTalendType();
                nullable = ((AbstractInOutTableEntry) entrySource).getMetadataColumn().isNullable();
            } else if (entrySource instanceof VarTableEntry) {
                talendType = ((VarTableEntry) entrySource).getType();
                nullable = ((VarTableEntry) entrySource).isNullable();
            }
            if (talendType != null) {
                if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
                    boolean exist = false;
                    for (Variable v : variables) {
                        if (variable != null && v.getName() != null && v.getName().trim().equals(variable.trim())) {
                            exist = true;
                            break;
                        }
                    }
                    if (!exist) {
                        variables.add(new Variable(variable, JavaTypesManager.getDefaultValueFromJavaIdType(talendType, nullable).toString(), talendType, nullable));
                    }
                } else {
                    //$NON-NLS-1$
                    variables.add(new Variable(variable, "", talendType, nullable));
                }
            }
        }
    }
    return variables;
}
Also used : VarsTable(org.talend.designer.mapper.model.table.VarsTable) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) ArrayList(java.util.ArrayList) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) VarTableEntry(org.talend.designer.mapper.model.tableentry.VarTableEntry) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) AbstractInOutTableEntry(org.talend.designer.mapper.model.tableentry.AbstractInOutTableEntry)

Example 3 with VarsTable

use of org.talend.designer.mapper.model.table.VarsTable in project tdi-studio-se by Talend.

the class MapperUI method createVarsZoneWithTables.

private void createVarsZoneWithTables(MapperModel mapperModel, final Display display) {
    Control previousControl;
    // Feature TDI-26691 : Add search option
    SearchZone searchZone = new SearchZone(datasFlowViewSashForm, SWT.NONE, mapperManager);
    searchZone.createSearchZone();
    sc2 = new ScrolledComposite(searchZone, getBorder() | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData sc2GridData = new GridData(GridData.FILL_BOTH);
    sc2.setLayoutData(sc2GridData);
    varsTableZoneView = new VarsTableZoneView(sc2, getBorder(), mapperManager);
    sc2.setContent(varsTableZoneView);
    sc2.setBackgroundMode(SWT.INHERIT_DEFAULT);
    sc2.setExpandHorizontal(true);
    sc2.addControlListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        // System.out.println("sc2 controlMoved");
        }

        public void controlResized(ControlEvent e) {
            // System.out.println("sc2 controlResized");
            onSashResized(display);
        }
    });
    sc2MSListener = new MouseScrolledListener(mapperManager.getUiManager(), sc2);
    varsTableZoneView.initInsertionIndicator();
    // final Composite finalTablesZoneViewVars = tablesZoneViewVars;
    previousControl = null;
    for (VarsTable varsTable : mapperModel.getVarsDataMapTables()) {
        DataMapTableView dataMapTableView = new VarsDataMapTableView(varsTableZoneView, SWT.BORDER, varsTable, mapperManager);
        FormData formData = new FormData();
        formData.left = new FormAttachment(0, 0);
        formData.right = new FormAttachment(100, 0);
        formData.top = new FormAttachment(previousControl);
        dataMapTableView.setLayoutData(formData);
        previousControl = dataMapTableView;
        dataMapTableView.minimizeTable(varsTable.isMinimized());
        dataMapTableView.registerStyledExpressionEditor(getTabFolderEditors().getStyledTextHandler());
    // dataMapTableView.fillMinimumSize(false);
    }
    varsTableZoneView.setSize(varsTableZoneView.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc2MSListener.addMouseWheelListener(sc2);
}
Also used : FormData(org.eclipse.swt.layout.FormData) VarsTable(org.talend.designer.mapper.model.table.VarsTable) OutputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView) InputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView) VarsDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) MouseScrolledListener(org.talend.designer.abstractmap.ui.listener.MouseScrolledListener) SearchZone(org.talend.designer.mapper.ui.visualmap.zone.SearchZone) VarsDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView) Control(org.eclipse.swt.widgets.Control) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) VarsTableZoneView(org.talend.designer.mapper.ui.visualmap.zone.scrollable.VarsTableZoneView)

Example 4 with VarsTable

use of org.talend.designer.mapper.model.table.VarsTable in project tdi-studio-se by Talend.

the class ExternalDataConverter method prepareVarsTables.

private List<VarsTable> prepareVarsTables(ExternalMapperData externalData) {
    List<VarsTable> varsTablesList = new ArrayList<VarsTable>();
    if (externalData != null) {
        List<ExternalMapperTable> varsExternalTables = externalData.getVarsTables();
        for (ExternalMapperTable persistentTable : varsExternalTables) {
            VarsTable varsTable = new VarsTable(this.mapperManager, persistentTable.getName());
            varsTable.initFromExternalData(persistentTable);
            varsTablesList.add(varsTable);
        }
    }
    if (varsTablesList.size() == 0) {
        VarsTable varsTable = new VarsTable(this.mapperManager, VarsTable.PREFIX_VARS_TABLE_NAME);
        varsTable.setMinimized(true);
        varsTablesList.add(varsTable);
    }
    return varsTablesList;
}
Also used : VarsTable(org.talend.designer.mapper.model.table.VarsTable) ArrayList(java.util.ArrayList) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable)

Example 5 with VarsTable

use of org.talend.designer.mapper.model.table.VarsTable in project tdi-studio-se by Talend.

the class ExternalDataConverter method loadInExternalData.

private void loadInExternalData(Collection<? extends AbstractDataMapTable> tables) {
    for (IDataMapTable table : tables) {
        ExternalMapperTable externalMapperTable = new ExternalMapperTable();
        fillExternalTable(table, externalMapperTable);
        ArrayList<ExternalMapperTableEntry> perTableEntries = new ArrayList<ExternalMapperTableEntry>();
        boolean isVarTable = table instanceof VarsTable;
        boolean isInputTable = table instanceof InputTable;
        for (ITableEntry dataMapTableEntry : table.getColumnEntries()) {
            ExternalMapperTableEntry externalMapperTableEntry = new ExternalMapperTableEntry();
            externalMapperTableEntry.setExpression(dataMapTableEntry.getExpression());
            externalMapperTableEntry.setName(dataMapTableEntry.getName());
            if (isVarTable) {
                externalMapperTableEntry.setType(((VarTableEntry) dataMapTableEntry).getType());
                externalMapperTableEntry.setNullable(((VarTableEntry) dataMapTableEntry).isNullable());
            } else {
                externalMapperTableEntry.setType(((AbstractInOutTableEntry) dataMapTableEntry).getMetadataColumn().getTalendType());
                externalMapperTableEntry.setNullable(((AbstractInOutTableEntry) dataMapTableEntry).getMetadataColumn().isNullable());
            }
            if (isInputTable) {
                externalMapperTableEntry.setOperator(((InputColumnTableEntry) dataMapTableEntry).getOperator());
            }
            perTableEntries.add(externalMapperTableEntry);
        }
        externalMapperTable.setMetadataTableEntries(perTableEntries);
    }
}
Also used : InputTable(org.talend.designer.mapper.model.table.InputTable) VarsTable(org.talend.designer.mapper.model.table.VarsTable) ExternalMapperTableEntry(org.talend.designer.mapper.external.data.ExternalMapperTableEntry) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) ArrayList(java.util.ArrayList) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) AbstractInOutTableEntry(org.talend.designer.mapper.model.tableentry.AbstractInOutTableEntry)

Aggregations

VarsTable (org.talend.designer.mapper.model.table.VarsTable)8 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)4 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)4 InputTable (org.talend.designer.mapper.model.table.InputTable)4 ArrayList (java.util.ArrayList)3 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)2 ExternalMapperTable (org.talend.designer.mapper.external.data.ExternalMapperTable)2 OutputTable (org.talend.designer.mapper.model.table.OutputTable)2 AbstractInOutTableEntry (org.talend.designer.mapper.model.tableentry.AbstractInOutTableEntry)2 VarTableEntry (org.talend.designer.mapper.model.tableentry.VarTableEntry)2 DataMapTableView (org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)2 HashMap (java.util.HashMap)1 List (java.util.List)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 ControlListener (org.eclipse.swt.events.ControlListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1