use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.
the class HL7Tree2SchemaLinker method updateLinksStyleAndControlsSelection.
// private void getSelectedRelativeStyleLink() {
// StyleLink selectedStyleLink = new StyleLink();
// selectedStyleLink.setDrawableLink(new BezierHorizontalLink(selectedStyleLink));
// selectedStyleLink.setForegroundColor(selectedRelativeLinkColor);
// selectedStyleLink.setLineWidth(2);
// int xOffset = WindowSystem.isGTK() ? 2 : -2;
// int yOffset = WindowSystem.isGTK() ? -1 : 0;
// selectedStyleLink.setExtremity2(new ExtremityEastArrow(selectedStyleLink, -ExtremityEastArrow.WIDTH_ARROW +
// xOffset,
// yOffset));
// setSelectedStyleLink(selectedStyleLink);
// }
public void updateLinksStyleAndControlsSelection(Control currentControl, Boolean flag) {
boolean selectedControlIsTable = false;
if (currentControl instanceof Table) {
selectedControlIsTable = true;
} else if (currentControl instanceof Tree) {
selectedControlIsTable = false;
} else {
//$NON-NLS-1$
throw new IllegalArgumentException(Messages.getString("XmlToXPathLinker.illegalArgumentException"));
}
HashSet selectedItems = new HashSet();
Map itemsToSelect = new HashMap();
if (selectedControlIsTable) {
// for (Table table : getTables()) {
// if (table != currentControl) {
// table.deselectAll();
// if (isFieldsTable(table)) {
// fieldsTableEditorView.getExtendedToolbar().updateEnabledStateOfButtons();
// }
// }
// }
TableItem[] selection = ((Table) currentControl).getSelection();
for (int i = 0; i < selection.length; i++) {
TableItem tableItem = selection[i];
selectedItems.add(tableItem.getData());
}
} else {
TreeItem[] selection = getTree().getSelection();
for (int i = 0; i < selection.length; i++) {
TreeItem treeItem = selection[i];
selectedItems.add(treeItem.getData());
}
}
List<LinkDescriptor<TreeItem, Object, Table, Object>> links = linksManager.getLinks();
for (LinkDescriptor<TreeItem, Object, Table, Object> link : links) {
IStyleLink styleLink = null;
IExtremityLink extremity = null;
IExtremityLink otherExtremity = null;
if (selectedControlIsTable) {
extremity = link.getExtremity2();
otherExtremity = link.getExtremity1();
} else {
extremity = link.getExtremity1();
otherExtremity = link.getExtremity2();
}
boolean currentItemIsSelected = selectedItems.contains(extremity.getDataItem());
// }
if (styleLink == null) {
styleLink = createStandardLink(new Color(getBgDrawableComposite().getDisplay(), 255, 102, 102));
}
link.setStyleLink(styleLink);
}
if (selectedControlIsTable) {
(getTree()).setSelection((TreeItem[]) itemsToSelect.keySet().toArray(new TreeItem[0]));
} else {
Set<Table> set = itemsToSelect.keySet();
if (set.size() > 0) {
for (Table table : set) {
ArrayList<TableItem> tableItemsToSelect = (ArrayList<TableItem>) itemsToSelect.get(table);
table.deselectAll();
TableItem[] tableItems = tableItemsToSelect.toArray(new TableItem[0]);
table.setSelection(tableItems);
}
} else {
// loopTableEditorView.getTable().deselectAll();
// fieldsTableEditorView.getTable().deselectAll();
}
// fieldsTableEditorView.getExtendedToolbar().updateEnabledStateOfButtons();
}
getLinksManager().sortLinks(getDrawingLinksComparator());
getBackgroundRefresher().refreshBackground();
}
use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.
the class UIManager method getTableEntryPosition.
/**
* DOC amaumont Comment method "getTableEntryPosition".
*
* @param manager TODO
* @param tableEntry
* @param forceRecalculate TODO
* @return
*/
public Point getTableEntryPosition(ITableEntry tableEntry, boolean forceRecalculate) {
DataMapTableView dataMapTableView = mapperManager.retrieveDataMapTableView(tableEntry);
int entriesSize = 0;
int minHeight = dataMapTableView.getTableViewerCreatorForColumns().getTable().getHeaderHeight() + dataMapTableView.getTableViewerCreatorForColumns().getTable().getItemHeight();
TableItem[] tableItems = new TableItem[0];
if (tableEntry instanceof InputColumnTableEntry || tableEntry instanceof OutputColumnTableEntry) {
tableItems = dataMapTableView.getTableViewerCreatorForColumns().getTable().getItems();
AbstractInOutTable abstractInOutTable = (AbstractInOutTable) dataMapTableView.getDataMapTable();
if (dataMapTableView.getZone() == Zone.OUTPUTS) {
OutputTable outputTable = (OutputTable) abstractInOutTable;
List<IColumnEntry> oldOuputEntries = outputTable.getDataMapTableEntries();
entriesSize = oldOuputEntries.size();
}
if (dataMapTableView.getZone() == Zone.INPUTS) {
InputTable inputTable = (InputTable) abstractInOutTable;
List<IColumnEntry> oldOuputEntries = inputTable.getDataMapTableEntries();
entriesSize = oldOuputEntries.size();
}
}
Rectangle tableViewBounds = dataMapTableView.getBounds();
Point pointFromTableViewOrigin = null;
Display display = dataMapTableView.getDisplay();
Point returnedPoint = new Point(0, 0);
TableEntryProperties tableEntryProperties = null;
int itemIndex = 0;
if (tableEntry instanceof IColumnEntry || tableEntry instanceof FilterTableEntry || tableEntry instanceof GlobalMapEntry) {
tableEntryProperties = mapperManager.getTableEntryProperties(tableEntry);
returnedPoint = tableEntryProperties.position;
if (forceRecalculate || returnedPoint == null) {
int y;
TableItem tableItem = mapperManager.retrieveTableItem(tableEntry);
boolean isOutputEntry = tableEntry instanceof OutputColumnTableEntry;
boolean isIntputEntry = tableEntry instanceof InputColumnTableEntry;
boolean checked = false;
for (int i = 0; i < tableItems.length; i++) {
if (tableItems[i].getData() == tableEntry) {
itemIndex = i;
break;
}
}
boolean allIsNull = false;
if (tableItem == null && (isIntputEntry || isOutputEntry)) {
if (tableItems.length > 0) {
tableItem = tableItems[0];
checked = true;
} else {
allIsNull = true;
}
}
if (!allIsNull) {
Table table = tableItem.getParent();
// FIX for issue 1225 ("1" parameter added)
Rectangle boundsTableItem = tableItem.getBounds(1);
y = boundsTableItem.y + table.getItemHeight() / 2 + dataMapTableView.getBorderWidth();
if (isOutputEntry || isIntputEntry) {
if (entriesSize != tableItems.length) {
y = boundsTableItem.y + table.getItemHeight() / 2 + dataMapTableView.getBorderWidth();
}
}
if (checked) {
y = boundsTableItem.y + dataMapTableView.getBorderWidth();
checked = false;
}
int x = 0;
if (y < 0) {
y = 0;
}
Point point = new Point(x, y);
pointFromTableViewOrigin = display.map(tableItem.getParent(), dataMapTableView, point);
} else {
Text columnFilterText = dataMapTableView.getColumnNameFilterText();
Point point = new Point(-dataMapTableView.getBorderWidth() - 19, minHeight);
pointFromTableViewOrigin = display.map(columnFilterText, dataMapTableView, point);
}
}
} else if (tableEntry instanceof ExpressionFilterEntry) {
StyledText expressionFilterText = dataMapTableView.getExpressionFilterText();
// dataMapTableView.getex
Point point = new Point(-dataMapTableView.getBorderWidth() - 19, 16);
pointFromTableViewOrigin = display.map(expressionFilterText, dataMapTableView, point);
} else {
//$NON-NLS-1$
throw new IllegalStateException("Case not found");
}
if (pointFromTableViewOrigin.y > tableViewBounds.height - TableEntriesManager.HEIGHT_REACTION) {
pointFromTableViewOrigin.y = tableViewBounds.height - TableEntriesManager.HEIGHT_REACTION;
}
returnedPoint = convertPointToReferenceOrigin(getReferenceComposite(), pointFromTableViewOrigin, dataMapTableView);
if (tableEntryProperties != null) {
tableEntryProperties.position = returnedPoint;
}
return returnedPoint;
}
use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.
the class UIManager method selectLinks.
/**
* Highlight links and linked cells which have are referenced by the selected items.
*
* @param dataMapTableView
* @param forceResetHighlightLinksForOtherTables TODO
* @param selectAllTableLinks TODO
* @param selectedMetadataTableEntries, source or targets entries which must be highlighted, can be null to select
* all links of a same DataMapTableView
*/
@SuppressWarnings("unchecked")
public void selectLinks(DataMapTableView dataMapTableView, List<ITableEntry> selectedTableEntries, boolean forceResetHighlightLinksForOtherTables, boolean selectAllTableLinks) {
if (!selectAllTableLinks && selectedTableEntries == null || selectedTableEntries != null && selectedTableEntries.size() == 0) {
return;
}
UIManager uiManager = mapperManager.getUiManager();
TableViewerCreator<ITableEntry> currentTableViewer = null;
boolean isFilterTableSelected = false;
boolean isGlobalMapTableSelected = false;
if (!selectAllTableLinks) {
ITableEntry firstEntry = selectedTableEntries.get(0);
if (firstEntry.isTableEntry()) {
if (firstEntry instanceof FilterTableEntry) {
isFilterTableSelected = true;
currentTableViewer = dataMapTableView.getTableViewerCreatorForFilters();
} else if (firstEntry instanceof GlobalMapEntry) {
isGlobalMapTableSelected = true;
currentTableViewer = dataMapTableView.getTableViewerCreatorForGlobalMap();
} else {
currentTableViewer = dataMapTableView.getTableViewerCreatorForColumns();
}
}
}
// Color selectedColor = dataMapTableView.getDisplay().getSystemColor(SWT.COLOR_YELLOW);
Color unselectedColor = dataMapTableView.getDisplay().getSystemColor(SWT.COLOR_WHITE);
Zone currentZone = dataMapTableView.getZone();
Set<ITableEntry> hashSelectedMetadataTableEntries = new HashSet<ITableEntry>();
if (selectAllTableLinks) {
if (currentZone == Zone.INPUTS || currentZone == Zone.OUTPUTS) {
hashSelectedMetadataTableEntries.add(((AbstractInOutTable) dataMapTableView.getDataMapTable()).getExpressionFilter());
}
hashSelectedMetadataTableEntries.addAll(dataMapTableView.getTableViewerCreatorForColumns().getInputList());
if (currentZone == Zone.INPUTS) {
hashSelectedMetadataTableEntries.addAll(dataMapTableView.getTableViewerCreatorForGlobalMap().getInputList());
}
if (currentZone == Zone.OUTPUTS) {
hashSelectedMetadataTableEntries.addAll(dataMapTableView.getTableViewerCreatorForFilters().getInputList());
}
} else {
hashSelectedMetadataTableEntries.addAll(selectedTableEntries);
}
// ////////////////////////////////////////////////////////////////////////
// Unselect all links and tableEntries if Ctrl or Shift keys are not pressed or if zone different of last
// selection
boolean zoneHasChanged = (previousSelectedZone == Zone.INPUTS || previousSelectedZone == Zone.VARS) && currentZone == Zone.OUTPUTS || (currentZone == Zone.INPUTS || currentZone == Zone.VARS) && previousSelectedZone == Zone.OUTPUTS;
boolean tableTypeHasChanged = previousSelectedTableIsConstraint != isFilterTableSelected && currentZone == Zone.OUTPUTS || previousSelectedTableIsGlobalMap != isGlobalMapTableSelected && currentZone == Zone.INPUTS;
boolean resetHighlightObjectsForOtherTables = !uiManager.isDragging() && (!uiManager.isCtrlPressed() && !uiManager.isShiftPressed() || zoneHasChanged);
if (resetHighlightObjectsForOtherTables || forceResetHighlightLinksForOtherTables) {
for (IMapperLink link : mapperManager.getLinks()) {
if (!hashSelectedMetadataTableEntries.contains(link.getPointLinkDescriptor1().getTableEntry()) && !hashSelectedMetadataTableEntries.contains(link.getPointLinkDescriptor2().getTableEntry())) {
link.setState(LinkState.UNSELECTED);
ITableEntry sourceITableEntry = link.getPointLinkDescriptor1().getTableEntry();
TableItem tableItem = mapperManager.retrieveTableItem(sourceITableEntry);
if (tableItem != null) {
tableItem.setBackground(unselectedColor);
}
ITableEntry targetITableEntry = link.getPointLinkDescriptor2().getTableEntry();
if (tableItem != null) {
tableItem = mapperManager.retrieveTableItem(targetITableEntry);
}
if (tableItem != null) {
tableItem.setBackground(unselectedColor);
}
}
}
if (currentZone == Zone.INPUTS || currentZone == Zone.VARS) {
unselectAllOutputMetaDataEntries();
} else if (currentZone == Zone.OUTPUTS) {
unselectAllInputMetaDataEntries();
}
Collection<DataMapTableView> tablesToDeselectEntries = mapperManager.getTablesView();
for (DataMapTableView viewToDeselectEntries : tablesToDeselectEntries) {
if (viewToDeselectEntries != dataMapTableView) {
viewToDeselectEntries.unselectAllEntries();
} else if (viewToDeselectEntries == dataMapTableView && tableTypeHasChanged) {
if (isFilterTableSelected) {
viewToDeselectEntries.unselectAllColumnEntries();
viewToDeselectEntries.unselectAllGlobalMapEntries();
} else if (isGlobalMapTableSelected) {
viewToDeselectEntries.unselectAllColumnEntries();
viewToDeselectEntries.unselectAllConstraintEntries();
} else {
viewToDeselectEntries.unselectAllGlobalMapEntries();
viewToDeselectEntries.unselectAllConstraintEntries();
}
}
}
}
// ////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////
// Select or unselect links and tableEntries
List<ITableEntry> allEntriesOfCurrentTableView = new ArrayList<ITableEntry>();
if (currentZone == Zone.INPUTS || currentZone == Zone.OUTPUTS) {
allEntriesOfCurrentTableView.add(((AbstractInOutTable) dataMapTableView.getDataMapTable()).getExpressionFilter());
}
if (selectAllTableLinks || currentTableViewer != null) {
allEntriesOfCurrentTableView.addAll(dataMapTableView.getTableViewerCreatorForColumns().getInputList());
if (selectAllTableLinks && currentZone == Zone.OUTPUTS) {
allEntriesOfCurrentTableView.addAll(dataMapTableView.getTableViewerCreatorForFilters().getInputList());
}
// if (selectAllTableLinks && currentZone == Zone.INPUTS) {
if (currentZone == Zone.INPUTS) {
allEntriesOfCurrentTableView.addAll(dataMapTableView.getTableViewerCreatorForGlobalMap().getInputList());
}
}
int lstSize = allEntriesOfCurrentTableView.size();
Set<IMapperLink> linksAlreadySelected = new HashSet<IMapperLink>();
for (int i = 0; i < lstSize; i++) {
ITableEntry entry = allEntriesOfCurrentTableView.get(i);
Set<IMapperLink> linksFromSource = mapperManager.getGraphicalLinksFromSource(entry);
Set<IMapperLink> linksFromTarget = mapperManager.getGraphicalLinksFromTarget(entry);
LinkState linkState = null;
if (hashSelectedMetadataTableEntries.contains(entry)) {
linkState = LinkState.SELECTED;
} else {
linkState = LinkState.UNSELECTED;
}
for (IMapperLink link : linksFromSource) {
ITableEntry targetITableEntry = link.getPointLinkDescriptor2().getTableEntry();
if (linkState == LinkState.SELECTED || !linksAlreadySelected.contains(link) && linkState == LinkState.UNSELECTED) {
link.setState(linkState);
if (linkState == LinkState.SELECTED) {
linksAlreadySelected.add(link);
}
}
EntryState entryState = (link.getState() == LinkState.SELECTED ? EntryState.HIGHLIGHT : EntryState.NONE);
setEntryState(mapperManager, entryState, targetITableEntry);
}
for (IMapperLink link : linksFromTarget) {
ITableEntry sourceITableEntry = link.getPointLinkDescriptor1().getTableEntry();
if (linkState == LinkState.SELECTED || !linksAlreadySelected.contains(link) && linkState == LinkState.UNSELECTED) {
link.setState(linkState);
if (linkState == LinkState.SELECTED) {
linksAlreadySelected.add(link);
}
}
EntryState entryState = (link.getState() == LinkState.SELECTED ? EntryState.HIGHLIGHT : EntryState.NONE);
setEntryState(mapperManager, entryState, sourceITableEntry);
}
}
// ////////////////////////////////////////////////////////////////////////
// order links to place selected links at last position (last drawn)
mapperManager.orderLinks();
uiManager.refreshBackground(false, false);
previousSelectedZone = dataMapTableView.getZone();
previousSelectedTableIsConstraint = isFilterTableSelected;
previousSelectedTableIsGlobalMap = isGlobalMapTableSelected;
}
use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.
the class TableEntriesManager method retrieveTableItem.
TableItem retrieveTableItem(ITableEntry dataMapTableEntry) {
DataMapTableView dataMapTableView = this.mapperManager.retrieveAbstractDataMapTableView(dataMapTableEntry.getParent());
TableItem[] tableItems = new TableItem[0];
if (dataMapTableEntry instanceof IColumnEntry) {
tableItems = dataMapTableView.getTableViewerCreatorForColumns().getTable().getItems();
} else if (dataMapTableEntry instanceof FilterTableEntry) {
tableItems = dataMapTableView.getTableViewerCreatorForFilters().getTable().getItems();
} else if (dataMapTableEntry instanceof GlobalMapEntry) {
tableItems = dataMapTableView.getTableViewerCreatorForGlobalMap().getTable().getItems();
} else if (dataMapTableEntry instanceof ExpressionFilterEntry) {
return null;
} else {
//$NON-NLS-1$
throw new IllegalArgumentException(Messages.getString("TableEntriesManager.exceptionMessage.caseNotFound"));
}
TableItem tableItem = null;
for (int i = 0; i < tableItems.length; i++) {
if (tableItems[i].getData() == dataMapTableEntry) {
tableItem = tableItems[i];
break;
}
}
getTableEntryProperties(dataMapTableEntry).setTableItem(tableItem);
return tableItem;
}
use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.
the class TabFolderEditors method addListenersToOutputButtons.
/**
* DOC amaumont Comment method "addListenersToInputButtons".
*/
private void addListenersToOutputButtons() {
MetadataToolbarEditorView toolBar = outputMetaEditor.getToolBar();
outputToolBarButtons = toolBar.getButtons();
beforeCommandListenerForOutputButtons = new IExtendedButtonListener() {
@Override
public void handleEvent(ExtendedButtonEvent event) {
// TableViewerCreator tableViewerCreator =
// mapperManager.getUiManager().getCurrentSelectedOutputTableView()
// .getTableViewerCreatorForColumns();
// if (tableViewerCreator != null) {
// tableViewerCreator.applyActivatedCellEditor();
// }
}
};
for (ExtendedPushButton extendedPushButton : outputToolBarButtons) {
extendedPushButton.addListener(beforeCommandListenerForOutputButtons, true);
if (extendedPushButton instanceof RemovePushButton) {
removeButton = (RemovePushButtonForExtendedTable) extendedPushButton;
}
}
if (removeButton != null) {
final TableViewerCreator tableViewerCreator = removeButton.getExtendedTableViewer().getTableViewerCreator();
tableViewerCreator.getSelectionHelper().addAfterSelectionListener(new ILineSelectionListener() {
@Override
public void handle(LineSelectionEvent e) {
for (TableItem item : tableViewerCreator.getTable().getSelection()) {
if (item.getData() instanceof MetadataColumn) {
MetadataColumn column = (MetadataColumn) item.getData();
removeButton.getButton().setEnabled(!column.isCustom());
break;
}
}
}
});
}
this.addDisposeListener(new DisposeListener() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
*/
@Override
public void widgetDisposed(DisposeEvent e) {
for (ExtendedPushButton extendedPushButton : outputToolBarButtons) {
extendedPushButton.removeListener(beforeCommandListenerForOutputButtons, true);
}
}
});
}
Aggregations