use of org.talend.designer.dbmap.model.tableentry.TableEntryLocation in project tdi-studio-se by Talend.
the class DbMapComponent method renameMetadataColumnName.
@Override
protected void renameMetadataColumnName(String conectionName, String oldColumnName, String newColumnName) {
if (conectionName == null || oldColumnName == null || newColumnName == null) {
throw new NullPointerException();
}
if (externalData != null) {
// rename metadata column name
List<ExternalDbMapTable> tables = new ArrayList<ExternalDbMapTable>(externalData.getInputTables());
tables.addAll(externalData.getOutputTables());
ExternalDbMapTable tableFound = null;
for (ExternalDbMapTable table : tables) {
if (table.getName().equals(conectionName)) {
List<ExternalDbMapEntry> metadataTableEntries = table.getMetadataTableEntries();
for (ExternalDbMapEntry entry : metadataTableEntries) {
if (entry.getName().equals(oldColumnName)) {
entry.setName(newColumnName);
tableFound = table;
break;
}
}
break;
}
}
// it is necessary to update expressions only if renamed column come from input table
if (tableFound != null && externalData.getInputTables().indexOf(tableFound) != -1) {
TableEntryLocation oldLocation = new TableEntryLocation(conectionName, oldColumnName);
TableEntryLocation newLocation = new TableEntryLocation(conectionName, newColumnName);
replaceLocationsInAllExpressions(oldLocation, newLocation, false);
}
}
}
use of org.talend.designer.dbmap.model.tableentry.TableEntryLocation in project tdi-studio-se by Talend.
the class ExpressionProposalProvider method getProposals.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int)
*/
public IContentProposal[] getProposals(String contents, int position) {
List<IContentProposal> proposals = new ArrayList<IContentProposal>();
TableEntryLocation sourceEntryLocation = new TableEntryLocation();
// Proposals based on process context
for (IDataMapTable table : this.tables) {
// proposals.add(new TableContentProposal(table, this.currentLanguage));
List<IColumnEntry> dataMapTableEntries = table.getColumnEntries();
for (IColumnEntry entrySource : dataMapTableEntries) {
sourceEntryLocation.tableName = entrySource.getParentName();
sourceEntryLocation.columnName = entrySource.getName();
if (mapperManager.getUiManager().checkSourceLocationIsValid(entrySource, currentModifiedEntry)) {
proposals.add(new EntryContentProposal(entrySource, this.currentLanguage));
}
}
}
for (IContentProposalProvider contentProposalProvider : otherContentProposalProviders) {
proposals.addAll(Arrays.asList(contentProposalProvider.getProposals(contents, position)));
}
IContentProposal[] res = new IContentProposal[proposals.size()];
res = proposals.toArray(res);
return res;
}
use of org.talend.designer.dbmap.model.tableentry.TableEntryLocation in project tdi-studio-se by Talend.
the class CompleteDropTargetListener 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(draggableTable, cursorPosition);
IDbLanguage currentLanguage = getMapperManager().getCurrentLanguage();
DataMapTableView dataMapTableViewTarget = getMapperManager().retrieveDataMapTableView(draggableTable);
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();
draggableTable.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 atLeastOneEntryInserted = false;
boolean insertionEntryMode = analyzer.isInsertionEntryMode();
boolean mapEachSourceToNextTargets = analyzer.isMapOneToOneMode();
TableViewerCreator tableViewerCreatorTarget = null;
if (targetTableIsFiltersTable) {
if (analyzer.targetTableIsWhereFiltersTable()) {
tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForWhereFilters();
} else {
tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForOtherFilters();
}
} else {
tableViewerCreatorTarget = dataMapTableViewTarget.getTableViewerCreatorForColumns();
}
// 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) {
modifyExistingEntry(uiManager, analyzer, currentLanguage, currentEntryTarget, columnIndicesToSelect, tableViewerCreatorTarget, lastEntryTarget, tableEntrySource, zoneSourceEntry);
} 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.OUTPUTS) {
insertNewInOutEntryFromInputEntry(sourceEntriesOfEntriesBeingAdded, metadataColumnsBeingAdded, // metadataEditorEvent,
tableEntrySource, metadataColumnDragged, columnName);
atLeastOneEntryInserted = true;
} 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);
}
}
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);
uiManager.unselectAllOutputMetaDataEntries();
uiManager.unselectAllInputMetaDataEntries();
uiManager.parseAllExpressionsForAllTables();
getMapperManager().getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
getUiManager().refreshSqlExpression();
uiManager.selectLinks(dataMapTableViewTarget, selectedEntries, targetTableIsFiltersTable, true);
tableViewerCreatorTarget.getTable().setFocus();
uiManager.setDragging(false);
}
use of org.talend.designer.dbmap.model.tableentry.TableEntryLocation in project tdi-studio-se by Talend.
the class UIManager method modifySelectionChangedListener.
private void modifySelectionChangedListener(final Zone currentZone, final MetadataTableEditorView metadataTableEditorViewFinal, final TableViewerCreator metadataTVCreator, final MetadataTableEditor metadataTableEditor, final DataMapTableView dataMapTableView, DataMapTableView previousSelectedTableView) {
final TableViewer tableViewer = dataMapTableView.getTableViewerCreatorForColumns().getTableViewer();
IModifiedBeanListener<IMetadataColumn> modifiedBeanListener = new IModifiedBeanListener<IMetadataColumn>() {
@Override
public void handleEvent(ModifiedBeanEvent<IMetadataColumn> event) {
if (AbstractMetadataTableEditorView.ID_COLUMN_NAME.equals(event.column.getId()) && !event.previousValue.equals(event.newValue)) {
IMetadataColumn modifiedObject = event.bean;
if (modifiedObject != null) {
TableEntryLocation tableEntryLocation = new TableEntryLocation(dataMapTableView.getDataMapTable().getName(), (String) event.previousValue);
final ITableEntry dataMapTableEntry = mapperManager.retrieveTableEntry(tableEntryLocation);
processColumnNameChanged((String) event.previousValue, (String) event.newValue, dataMapTableView, dataMapTableEntry, false);
}
// dataMapTableViewer.refresh(event.bean, true);
tableViewer.refresh(true);
mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
} else if (AbstractMetadataTableEditorView.ID_COLUMN_KEY.equals(event.column.getId())) {
tableViewer.refresh(true);
IColumnEntry entry = dataMapTableView.getDataMapTable().getColumnEntries().get(event.index);
parseExpression(entry.getExpression(), entry, false, false, false);
} else if (AbstractMetadataTableEditorView.ID_COLUMN_TYPE.equals(event.column.getId()) || AbstractMetadataTableEditorView.ID_COLUMN_NULLABLE.equals(event.column.getId())) {
mapperManager.getProblemsManager().checkProblemsForAllEntriesOfAllTables(true);
}
}
};
ILineSelectionListener metadataEditorViewerSelectionChangedListener = new ILineSelectionListener() {
@Override
public void handle(LineSelectionEvent e) {
if (metadataTableEditorViewFinal.getTableViewerCreator() == e.source) {
if (metadataTableEditorViewFinal.getExtendedTableViewer().isExecuteSelectionEvent()) {
mapperManager.getUiManager().selectLinkedTableEntries(metadataTableEditor.getMetadataTable(), metadataTVCreator.getTable().getSelectionIndices());
}
} else {
// if (dataMapTableView.getExtendedTableViewerForColumns().isExecuteSelectionEvent()) {
// int[] selectionIndices =
// dataMapTableView.getTableViewerCreatorForColumns().getTable().getSelectionIndices();
// mapperManager.getUiManager().selectLinkedMetadataEditorEntries(dataMapTableView,
// selectionIndices);
// }
}
}
};
// ISelectionChangedListener previousSelectionChangedListener = null;
ILineSelectionListener previousSelectionChangedListener = null;
IModifiedBeanListener<IMetadataColumn> previousModifiedBeanListener = null;
if (currentZone == Zone.INPUTS) {
previousSelectionChangedListener = inputsSelectionChangedListener;
previousModifiedBeanListener = inputModifiedBeanListener;
} else if (currentZone == Zone.OUTPUTS) {
previousSelectionChangedListener = outputsSelectionChangedListener;
previousModifiedBeanListener = outputModifiedBeanListener;
}
if (previousSelectionChangedListener != null) {
// metadataTVCreator.removeSelectionChangedListener(previousSelectionChangedListener);
metadataTVCreator.getSelectionHelper().removeAfterSelectionListener(previousSelectionChangedListener);
if (previousSelectedTableView != null) {
previousSelectedTableView.getTableViewerCreatorForColumns().getSelectionHelper().removeAfterSelectionListener(previousSelectionChangedListener);
}
}
if (previousModifiedBeanListener != null) {
metadataTableEditor.removeModifiedBeanListener(previousModifiedBeanListener);
}
if (currentZone == Zone.INPUTS) {
inputsSelectionChangedListener = metadataEditorViewerSelectionChangedListener;
inputModifiedBeanListener = modifiedBeanListener;
} else if (currentZone == Zone.OUTPUTS) {
outputsSelectionChangedListener = metadataEditorViewerSelectionChangedListener;
outputModifiedBeanListener = modifiedBeanListener;
}
// metadataTVCreator.addSelectionChangedListener(metadataEditorViewerSelectionChangedListener);
metadataTVCreator.getSelectionHelper().addAfterSelectionListener(metadataEditorViewerSelectionChangedListener);
dataMapTableView.getTableViewerCreatorForColumns().getSelectionHelper().addAfterSelectionListener(metadataEditorViewerSelectionChangedListener);
metadataTableEditor.addModifiedBeanListener(modifiedBeanListener);
if (this.commonMetadataDisposeListener == null) {
this.commonMetadataDisposeListener = new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
if (inputsSelectionChangedListener != null) {
getMetadataEditorView(Zone.INPUTS).getTableViewerCreator().getSelectionHelper().removeAfterSelectionListener(inputsSelectionChangedListener);
}
if (outputsSelectionChangedListener != null) {
getMetadataEditorView(Zone.OUTPUTS).getTableViewerCreator().getSelectionHelper().removeAfterSelectionListener(outputsSelectionChangedListener);
}
if (inputModifiedBeanListener != null) {
MetadataTableEditor metadataTableEditor = getMetadataEditorView(Zone.INPUTS).getMetadataTableEditor();
if (metadataTableEditor != null) {
metadataTableEditor.removeModifiedBeanListener(inputModifiedBeanListener);
}
}
if (outputModifiedBeanListener != null) {
MetadataTableEditor metadataTableEditor = getMetadataEditorView(Zone.OUTPUTS).getMetadataTableEditor();
if (metadataTableEditor != null) {
metadataTableEditor.removeModifiedBeanListener(outputModifiedBeanListener);
}
}
}
};
metadataTVCreator.getTable().addDisposeListener(this.commonMetadataDisposeListener);
}
}
use of org.talend.designer.dbmap.model.tableentry.TableEntryLocation in project tdi-studio-se by Talend.
the class UIManager method parseExpression.
/**
*
*
* @param expression
* @param currentModifiedITableEntry
* @param linkMustHaveSelectedState
* @param checkInputKeyAutomatically TODO
* @param inputExpressionAppliedOrCanceled TODO
* @param newSelectedDataMapTableView
* @return true if a link has been added or removed, false else
*/
public ParseExpressionResult parseExpression(String expression, ITableEntry currentModifiedITableEntry, boolean linkMustHaveSelectedState, boolean checkInputKeyAutomatically, boolean inputExpressionAppliedOrCanceled) {
DataMapTableView dataMapTableView = mapperManager.retrieveDataMapTableView(currentModifiedITableEntry);
boolean linkHasBeenAdded = false;
boolean linkHasBeenRemoved = false;
DataMapExpressionParser dataMapExpressionParser = new DataMapExpressionParser(mapperManager.getCurrentLanguage());
TableEntryLocation[] tableEntriesLocationsSources = dataMapExpressionParser.parseTableEntryLocations(expression);
Set<TableEntryLocation> alreadyProcessed = new HashSet<TableEntryLocation>();
Set<ITableEntry> sourcesForTarget = mapperManager.getSourcesForTarget(currentModifiedITableEntry);
Set<ITableEntry> sourcesForTargetToDelete = new HashSet<ITableEntry>(sourcesForTarget);
boolean isInputEntry = currentModifiedITableEntry instanceof InputColumnTableEntry;
for (TableEntryLocation tableEntriesLocationsSource : tableEntriesLocationsSources) {
TableEntryLocation location = tableEntriesLocationsSource;
if (!alreadyProcessed.contains(location) && checkSourceLocationIsValid(location, currentModifiedITableEntry)) {
ITableEntry sourceTableEntry = mapperManager.retrieveTableEntry(location);
sourcesForTargetToDelete.remove(sourceTableEntry);
if (sourceTableEntry != null && !sourcesForTarget.contains(sourceTableEntry)) {
DataMapTableView sourceDataMapTableView = mapperManager.retrieveDataMapTableView(sourceTableEntry);
IMapperLink link = new Link(new PointLinkDescriptor(sourceTableEntry, sourceDataMapTableView.getZone()), new PointLinkDescriptor(currentModifiedITableEntry, dataMapTableView.getZone()), mapperManager);
link.setState(linkMustHaveSelectedState ? LinkState.SELECTED : LinkState.UNSELECTED);
mapperManager.addLink(link);
linkHasBeenAdded = true;
}
alreadyProcessed.add(location);
}
}
Set<IMapperLink> targets = mapperManager.getGraphicalLinksFromTarget(currentModifiedITableEntry);
Set<IMapperLink> linksFromTarget = new HashSet<IMapperLink>(targets);
for (IMapperLink link : linksFromTarget) {
if (sourcesForTargetToDelete.contains(link.getPointLinkDescriptor1().getTableEntry())) {
mapperManager.removeLink(link, link.getPointLinkDescriptor2().getTableEntry());
linkHasBeenRemoved = true;
}
}
mapperManager.orderLinks();
return new ParseExpressionResult(linkHasBeenAdded, linkHasBeenRemoved);
}
Aggregations