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