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);
}
});
// /////////////////////////////////////////////////////////////////
}
Aggregations