use of org.talend.designer.mapper.model.tableentry.TableEntryLocation in project tdi-studio-se by Talend.
the class CompleteDropTargetTableListener method drop.
// private void showInfos(DropTargetEvent event) {
// System.out.println(event);
// System.out.println("event.feedback=" + event.feedback);
// System.out.println("event.detail=" + event.detail);
// System.out.println("event.operations=" + event.operations);
//
// System.out.println("DND.DROP_DEFAULT=" + DND.DROP_DEFAULT);
// System.out.println("DND.DROP_COPY=" + DND.DROP_COPY);
// System.out.println("DND.DROP_MOVE=" + DND.DROP_MOVE);
// System.out.println("DND.DROP_LINK=" + DND.DROP_LINK);
// System.out.println("DND.DROP_TARGET_MOVE=" + DND.DROP_TARGET_MOVE);
// }
//
@Override
public void drop(DropTargetEvent event) {
super.drop(event);
retrieveInsertionIndicator().setVisible(false);
UIManager uiManager = getUiManager();
DraggedData draggedData = TableEntriesTransfer.getInstance().getDraggedData();
DropContextAnalyzer analyzer = analyzeDropTarget(event, draggedData);
// System.out.println("\n>>drop");
// System.out.println(event);
Point cursorPosition = new Point(event.x, event.y);
// int startInsertAtThisIndex = getItemIndexWhereInsertFromPosition(cursorPosition);
int startInsertAtThisIndex = TableUtils.getItemIndexWhereInsertFromPosition(draggableTargetControl, cursorPosition);
ILanguage currentLanguage = LanguageProvider.getCurrentLanguage();
DataMapTableView dataMapTableViewTarget = getMapperManager().retrieveDataMapTableView(draggableTargetControl);
Zone zoneTarget = dataMapTableViewTarget.getZone();
uiManager.selectDataMapTableView(dataMapTableViewTarget, true, false);
MetadataTableEditorView metadataEditorView = getUiManager().getMetadataEditorView(dataMapTableViewTarget.getZone());
List<TransferableEntry> transferableEntryList = draggedData.getTransferableEntryList();
int currentIndex = startInsertAtThisIndex;
uiManager.clearLastCreatedInOutColumnEntries();
draggableTargetControl.deselectAll();
ITableEntry currentEntryTarget = getEntryFromPosition(cursorPosition);
ArrayList<String> columnsBeingAdded = new ArrayList<String>();
ArrayList<Integer> columnIndicesToSelect = new ArrayList<Integer>();
ArrayList<ITableEntry> sourceEntriesOfEntriesBeingAdded = new ArrayList<ITableEntry>();
ArrayList<IMetadataColumn> metadataColumnsBeingAdded = new ArrayList<IMetadataColumn>();
boolean targetTableIsFiltersTable = analyzer.targetTableIsFiltersTable();
boolean targetTableIsGlobalMapTable = analyzer.targetTableIsGlobalMapTable();
boolean atLeastOneEntryInserted = false;
boolean insertionEntryMode = analyzer.isInsertionEntryMode();
boolean mapEachSourceToNextTargets = analyzer.isMapOneToOneMode();
TableViewerCreator tableViewerCreatorTarget = null;
if (!analyzer.targetIsExpressionFilterText()) {
if (targetTableIsFiltersTable) {
tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForFilters();
} else if (targetTableIsGlobalMapTable) {
tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForGlobalMap();
} else {
tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForColumns();
}
}
uiManager.applyActivatedCellEditors(tableViewerCreatorTarget);
// MapperDropCommand dropCommand = new MapperDropCommand();
// MetadataEditorEvent metadataEditorEvent = new MetadataEditorEvent(MetadataEditorEvent.TYPE.ADD);
ITableEntry lastEntryTarget = null;
for (TransferableEntry transferableEntry : transferableEntryList) {
ITableEntry tableEntrySource = transferableEntry.getTableEntrySource();
IMetadataColumn metadataColumnDragged = transferableEntry.getMetadataColumn();
Zone zoneSourceEntry = (Zone) transferableEntry.getZoneSourceEntry();
TableEntryLocation tableEntryLocationTarget = new TableEntryLocation(dataMapTableViewTarget.getDataMapTable().getName(), tableEntrySource.getName());
if (zoneSourceEntry == Zone.INPUTS && zoneTarget == Zone.INPUTS && tableEntrySource.getParentName().equals(tableEntryLocationTarget.tableName)) {
continue;
} else if (currentEntryTarget != null && !insertionEntryMode) {
// set the default operator.
if (currentEntryTarget instanceof InputColumnTableEntry) {
((InputColumnTableEntry) currentEntryTarget).setOperator(Operator.EQUALS.getLiteral());
}
boolean overwrite = (lastEntryTarget != currentEntryTarget && analyzer.isOverwriteExpression());
modifyExistingExpression(currentLanguage, currentEntryTarget, tableEntrySource, overwrite, zoneSourceEntry);
uiManager.parseExpression(currentEntryTarget.getExpression(), currentEntryTarget, false, true, true);
int indexOfEntry = tableViewerCreatorTarget.getInputList().indexOf(currentEntryTarget);
columnIndicesToSelect.add(indexOfEntry);
} else {
String columnName = transferableEntry.getTableEntrySource().getName();
tableEntryLocationTarget = getMapperManager().findUniqueLocation(tableEntryLocationTarget, dataMapTableViewTarget.getDataMapTable());
columnName = tableEntryLocationTarget.columnName;
if (currentEntryTarget == null && analyzer.isMapOneToOneMode()) {
currentIndex = tableViewerCreatorTarget.getInputList().size();
columnIndicesToSelect.add(currentIndex);
}
if (zoneSourceEntry == Zone.INPUTS && zoneTarget == Zone.VARS || zoneSourceEntry == Zone.VARS && zoneTarget == Zone.VARS) {
columnIndicesToSelect.add(currentIndex);
currentIndex = insertNewVarEntry(currentLanguage, dataMapTableViewTarget, currentIndex, tableEntrySource, columnName);
atLeastOneEntryInserted = true;
} else if (zoneSourceEntry == Zone.VARS && zoneTarget == Zone.OUTPUTS) {
insertNewOutputEntryFromVarEntry(sourceEntriesOfEntriesBeingAdded, metadataColumnsBeingAdded, // metadataEditorEvent,
tableEntrySource, columnName);
atLeastOneEntryInserted = true;
} else if (zoneSourceEntry == Zone.INPUTS && targetTableIsGlobalMapTable) {
insertNewGlobalMapEntryFromInputEntry(currentLanguage, dataMapTableViewTarget, currentIndex, tableEntrySource);
atLeastOneEntryInserted = true;
} else if (zoneSourceEntry == Zone.INPUTS && zoneTarget != Zone.VARS) {
insertNewInOutEntryFromInputEntry(sourceEntriesOfEntriesBeingAdded, metadataColumnsBeingAdded, // metadataEditorEvent,
tableEntrySource, metadataColumnDragged, columnName);
atLeastOneEntryInserted = true;
} else if (zoneSourceEntry == Zone.OUTPUTS && zoneTarget == Zone.VARS) {
// nothing
} else if (zoneSourceEntry == Zone.OUTPUTS && zoneTarget == Zone.OUTPUTS) {
insertOutpuEntryCopyToOtherOutput(sourceEntriesOfEntriesBeingAdded, metadataColumnsBeingAdded, // metadataEditorEvent,
tableEntrySource, metadataColumnDragged, columnName);
atLeastOneEntryInserted = true;
} else {
// throw new IllegalStateException("Drop case not found !");
}
columnsBeingAdded.add(columnName);
}
lastEntryTarget = currentEntryTarget;
if (mapEachSourceToNextTargets && currentEntryTarget != null) {
currentEntryTarget = getNextEntryTarget(currentEntryTarget, tableViewerCreatorTarget);
}
}
if (!atLeastOneEntryInserted) {
tableViewerCreatorTarget.getTableViewer().refresh();
} else {
updateExpressionsOfInsertedEntries(currentLanguage, metadataEditorView, currentIndex, sourceEntriesOfEntriesBeingAdded, targetTableIsFiltersTable, tableViewerCreatorTarget, // , metadataEditorEvent
metadataColumnsBeingAdded);
for (int i = currentIndex; i < currentIndex + sourceEntriesOfEntriesBeingAdded.size(); i++) {
columnIndicesToSelect.add(i);
}
}
if (zoneTarget == Zone.VARS) {
dataMapTableViewTarget.resizeAtExpandedSize();
}
if (targetTableIsGlobalMapTable) {
dataMapTableViewTarget.updateGridDataHeightForTableGlobalMap();
dataMapTableViewTarget.resizeAtExpandedSize();
}
uiManager.unselectAllEntriesOfAllTables();
uiManager.refreshBackground(true, false);
if (metadataEditorView != null && !targetTableIsFiltersTable) {
metadataEditorView.getTableViewerCreator().getTableViewer().refresh();
}
int[] selection = ArrayUtils.toPrimitive(columnIndicesToSelect.toArray(new Integer[0]));
tableViewerCreatorTarget.getSelectionHelper().setSelection(selection);
ISelection iselection = tableViewerCreatorTarget.getTableViewer().getSelection();
List<ITableEntry> selectedEntries = uiManager.extractSelectedTableEntries(iselection);
tableViewerCreatorTarget.getTable().deselectAll();
uiManager.unselectAllOutputMetaDataEntries();
uiManager.unselectAllInputMetaDataEntries();
uiManager.parseAllExpressionsForAllTables();
getMapperManager().getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
getMapperManager().getProblemsManager().checkLookupExpressionProblem();
uiManager.selectLinks(dataMapTableViewTarget, selectedEntries, true, false);
dataMapTableViewTarget.checkChangementsAfterEntryModifiedOrAdded(false);
tableViewerCreatorTarget.getTable().setFocus();
uiManager.setDragging(false);
}
use of org.talend.designer.mapper.model.tableentry.TableEntryLocation in project tdi-studio-se by Talend.
the class MapperComponent method replaceLocation.
public String replaceLocation(TableEntryLocation oldLocation, TableEntryLocation newLocation, String currentExpression, DataMapExpressionParser dataMapExpressionParser, boolean tableRenamed) {
if (currentExpression == null || currentExpression.trim().length() == 0) {
return null;
}
TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(currentExpression);
// loop on all locations of current expression
for (TableEntryLocation currentLocation : tableEntryLocations) {
if (tableRenamed && oldLocation.tableName.equals(currentLocation.tableName)) {
oldLocation.columnName = currentLocation.columnName;
newLocation.columnName = currentLocation.columnName;
}
if (currentLocation.equals(oldLocation)) {
currentExpression = dataMapExpressionParser.replaceLocation(currentExpression, currentLocation, newLocation);
}
}
// for (int i = 0; i < tableEntryLocations.length; i++) {
return currentExpression;
}
use of org.talend.designer.mapper.model.tableentry.TableEntryLocation in project tdi-studio-se by Talend.
the class PerlGenerationManager method tranformArraysExpressions.
/**
* DOC amaumont Comment method "tranformArraysExpressions".
*
* @param uniqueNameComponent
* @param outputExpression
* @param expressionParser
* @param possibleSources
* @return
*/
private String tranformArraysExpressions(boolean addArrayPointers, String uniqueNameComponent, String outputExpression, DataMapExpressionParser expressionParser, TableType[] possibleSources) {
expressionParser.setLocationPattern(getPerlLanguage().getLocationPattern());
TableEntryLocation[] allEntryLocations = expressionParser.parseTableEntryLocations(outputExpression);
// expressionParser.setLocationPattern("\\$\\s*(\\w+)\\s*\\[\\s*(\\$?\\w+)\\s*\\]");
TableEntryLocation[] validColumnEntryLocations = null;
HashSet<TableEntryLocation> sValidColumnEntryLocations = new HashSet<TableEntryLocation>();
if (!addArrayPointers) {
expressionParser.setLocationPattern(getPerlLanguage().getLocationPatternValidColumnName());
validColumnEntryLocations = expressionParser.parseTableEntryLocations(outputExpression);
for (int i = 0; i < validColumnEntryLocations.length; i++) {
sValidColumnEntryLocations.add(validColumnEntryLocations[i]);
}
}
ArrayList<TableEntryLocation> listCoupleForAddTablePrefix = new ArrayList<TableEntryLocation>();
ArrayList<TableEntryLocation> listCoupleForAddTablePrefixWithPrefixComponentName = new ArrayList<TableEntryLocation>();
boolean possibleSourceInputs = false;
boolean possibleSourceVars = false;
for (int i = 0; i < possibleSources.length; i++) {
TableType possibleSourceType = possibleSources[i];
if (possibleSourceType == TableType.INPUT) {
possibleSourceInputs = true;
}
if (possibleSourceType == TableType.VARS) {
possibleSourceVars = true;
}
}
for (TableEntryLocation location : allEntryLocations) {
if (possibleSourceInputs && isInputTable(location.tableName)) {
listCoupleForAddTablePrefix.add(location);
} else if (possibleSourceVars && isVarsTable(location.tableName)) {
listCoupleForAddTablePrefixWithPrefixComponentName.add(location);
}
}
String outputExpressionToWrite = outputExpression;
if (listCoupleForAddTablePrefix.size() > 0) {
if (addArrayPointers) {
outputExpressionToWrite = expressionParser.addRefArrayPointer(outputExpressionToWrite, listCoupleForAddTablePrefix.toArray(new TableEntryLocation[0]));
} else {
outputExpressionToWrite = expressionParser.addTablePrefixToColumnName(uniqueNameComponent, outputExpressionToWrite, listCoupleForAddTablePrefix.toArray(new TableEntryLocation[0]), false, sValidColumnEntryLocations);
}
}
if (listCoupleForAddTablePrefixWithPrefixComponentName.size() > 0) {
if (addArrayPointers) {
outputExpressionToWrite = expressionParser.addRefArrayPointer(outputExpressionToWrite, listCoupleForAddTablePrefixWithPrefixComponentName.toArray(new TableEntryLocation[0]));
} else {
outputExpressionToWrite = expressionParser.addTablePrefixToColumnName(uniqueNameComponent, outputExpressionToWrite, listCoupleForAddTablePrefixWithPrefixComponentName.toArray(new TableEntryLocation[0]), true, sValidColumnEntryLocations);
}
}
return outputExpressionToWrite;
}
use of org.talend.designer.mapper.model.tableentry.TableEntryLocation in project tdi-studio-se by Talend.
the class ExternalMapperTable method isSelfFilter.
public boolean isSelfFilter() {
DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(LanguageProvider.getCurrentLanguage());
TableEntryLocation[] tableEntryLocations = dataMapExpressionParser.parseTableEntryLocations(this.expressionFilter);
for (TableEntryLocation tableEntryLocation : tableEntryLocations) {
if (!this.name.equals(tableEntryLocation.tableName)) {
return false;
}
}
return true;
}
use of org.talend.designer.mapper.model.tableentry.TableEntryLocation in project tdi-studio-se by Talend.
the class MapperManager method findUniqueLocation.
public TableEntryLocation findUniqueLocation(final TableEntryLocation proposedLocation, IDataMapTable table) {
TableEntryLocation tableEntryLocation = new TableEntryLocation(proposedLocation);
int counter = 1;
boolean exists = true;
while (exists) {
boolean found = false;
if (table != null) {
for (IColumnEntry entry : table.getColumnEntries()) {
// TDI-26953: drag-and-drop column name should case-sensitive
if (entry.getName().equalsIgnoreCase(tableEntryLocation.columnName)) {
found = true;
break;
}
}
}
exists = found;
if (!exists) {
break;
}
//$NON-NLS-1$
tableEntryLocation.columnName = proposedLocation.columnName + "_" + counter++;
}
return tableEntryLocation;
}
Aggregations