Search in sources :

Example 1 with ExtendedTableMoveCommand

use of org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTableMoveCommand 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)

Aggregations

List (java.util.List)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Table (org.eclipse.swt.widgets.Table)1 ToolItem (org.eclipse.swt.widgets.ToolItem)1 ILineSelectionListener (org.talend.commons.ui.runtime.swt.tableviewer.selection.ILineSelectionListener)1 LineSelectionEvent (org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent)1 ExtendedTableMoveCommand (org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTableMoveCommand)1 AbstractExtendedTableViewer (org.talend.commons.ui.swt.extended.table.AbstractExtendedTableViewer)1 TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)1 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)1 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)1 ILanguage (org.talend.designer.mapper.language.ILanguage)1 VarsTable (org.talend.designer.mapper.model.table.VarsTable)1