use of org.talend.commons.ui.swt.drawing.link.IExtremityLink in project tdi-studio-se by Talend.
the class JSONFileSchema2TreeLinker method updateLinksStyleAndControlsSelection.
public void updateLinksStyleAndControlsSelection(Control currentControl, boolean lastOne) {
// super.updateLinksStyleAndControlsSelection(currentControl);
boolean isTarget = false;
if (getSource() != currentControl) {
isTarget = true;
} else {
isTarget = false;
}
HashSet selectedItems = new HashSet();
Map itemsToSelect = new HashMap();
if (isTarget) {
getTarget().deselectAll();
TreeItem[] selection = getTarget().getSelection();
for (int i = 0; i < selection.length; i++) {
TreeItem tableItem = selection[i];
selectedItems.add(tableItem.getData());
}
} else {
TableItem[] selection = getSource().getSelection();
for (int i = 0; i < selection.length; i++) {
TableItem treeItem = selection[i];
selectedItems.add(treeItem.getData());
}
}
List<LinkDescriptor<Item, Object, Tree, Object>> links = linksManager.getLinks();
for (LinkDescriptor<Item, Object, Tree, Object> link : links) {
IStyleLink styleLink = null;
IExtremityLink extremity = null;
IExtremityLink otherExtremity = null;
if (isTarget) {
extremity = link.getExtremity2();
otherExtremity = link.getExtremity1();
} else {
extremity = link.getExtremity1();
otherExtremity = link.getExtremity2();
}
boolean currentItemIsSelected = selectedItems.contains(extremity.getDataItem());
if (extremity.getGraphicalObject() == jsonViewer.getTree() || otherExtremity.getGraphicalObject() == jsonViewer.getTree()) {
styleLink = getSelectedLoopStyleLink();
} else {
if (currentItemIsSelected) {
styleLink = getSelectedStyleLink();
if (isTarget) {
itemsToSelect.put((TableItem) otherExtremity.getGraphicalObject(), null);
} else {
Table currentTable = (Table) otherExtremity.getGraphicalObject();
List<TableItem> tableItemsToSelect = (List<TableItem>) itemsToSelect.get(currentTable);
if (tableItemsToSelect == null) {
tableItemsToSelect = new ArrayList<TableItem>();
itemsToSelect.put(currentTable, tableItemsToSelect);
}
TableItem tableItem = TableUtils.getTableItem(currentTable, otherExtremity.getDataItem());
tableItemsToSelect.add(tableItem);
}
} else {
styleLink = getUnselectedStyleLink();
}
}
if (styleLink == null) {
styleLink = getDefaultStyleLink();
}
link.setStyleLink(styleLink);
}
if (isTarget) {
(getSource()).setSelection((TableItem[]) itemsToSelect.keySet().toArray(new TableItem[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 = (TableItem[]) tableItemsToSelect.toArray(new TableItem[0]);
table.setSelection(tableItems);
}
} else {
jsonViewer.getTree().deselectAll();
}
}
getLinksManager().sortLinks(getDrawingLinksComparator());
// for bug 9279
if (lastOne) {
getBackgroundRefresher().refreshBackground();
}
}
Aggregations