use of org.talend.commons.ui.swt.drawing.link.IStyleLink in project tdi-studio-se by Talend.
the class Schema2XMLLinker method updateLinksStyleAndControlsSelection.
@SuppressWarnings("unchecked")
public void updateLinksStyleAndControlsSelection(Control currentControl) {
// 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 (TreeItem tableItem : selection) {
selectedItems.add(tableItem.getData());
}
} else {
TableItem[] selection = getSource().getSelection();
for (TableItem treeItem : selection) {
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() == xmlViewer.getTree() || otherExtremity.getGraphicalObject() == xmlViewer.getTree()) {
styleLink = getSelectedLoopStyleLink();
} else {
if (currentItemIsSelected) {
styleLink = getSelectedStyleLink();
if (isTarget) {
itemsToSelect.put(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 = tableItemsToSelect.toArray(new TableItem[0]);
table.setSelection(tableItems);
}
} else {
xmlViewer.getTree().deselectAll();
}
}
getLinksManager().sortLinks(getDrawingLinksComparator());
}
use of org.talend.commons.ui.swt.drawing.link.IStyleLink in project tdi-studio-se by Talend.
the class JSONToXPathLinker method updateLinksStyleAndControlsSelection.
@Override
@SuppressWarnings("unchecked")
public void updateLinksStyleAndControlsSelection(Control currentControl, Boolean flag) {
boolean selectedControlIsTable = false;
if (currentControl instanceof Table) {
selectedControlIsTable = true;
} else if (currentControl instanceof Tree) {
selectedControlIsTable = false;
} else {
throw new IllegalArgumentException("This type of currentControl is unsupported");
}
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 (TableItem tableItem : selection) {
selectedItems.add(tableItem.getData());
}
} else {
TreeItem[] selection = getTree().getSelection();
for (TreeItem treeItem : selection) {
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 (extremity.getGraphicalObject() == loopTableEditorView.getTableViewerCreator().getTable() || otherExtremity.getGraphicalObject() == loopTableEditorView.getTableViewerCreator().getTable()) {
styleLink = getSelectedLoopStyleLink();
} else {
if (currentItemIsSelected) {
styleLink = getSelectedStyleLink();
if (selectedControlIsTable) {
itemsToSelect.put(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 (selectedControlIsTable) {
TreeItem[] treeItems = (TreeItem[]) itemsToSelect.keySet().toArray(new TreeItem[0]);
if (treeItems.length > 0) {
if (!treeItems[0].isDisposed()) {
(getTree()).setSelection(treeItems);
}
}
} 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();
}
if (flag) {
getLinksManager().sortLinks(getDrawingLinksComparator());
getBackgroundRefresher().refreshBackground();
}
}
use of org.talend.commons.ui.swt.drawing.link.IStyleLink 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.talend.commons.ui.swt.drawing.link.IStyleLink in project tdi-studio-se by Talend.
the class StyleLinkFactory method getSelectedZoneToOtherZoneStyle.
private IStyleLink getSelectedZoneToOtherZoneStyle(Color foregroundColor) {
StyleLink style = new StyleLink();
setCommonsStyleProperties(style);
style.setDrawableLink(getZoneToZoneLink(style));
ExtremityEastArrow eastArrowSource = new ExtremityEastArrow(style);
style.setExtremity1(eastArrowSource);
ExtremityEastArrow eastArrowTarget = new ExtremityEastArrow(style);
eastArrowTarget.setXOffset(-eastArrowTarget.getSize().x);
style.setExtremity2(eastArrowTarget);
style.setForegroundColor(foregroundColor);
return style;
}
use of org.talend.commons.ui.swt.drawing.link.IStyleLink in project tdi-studio-se by Talend.
the class Link method draw.
public void draw(GC gc, Rectangle boundsOfDrawing) {
StyleLinkFactory drawableLinkFactory = mapperManager.getUiManager().getStyleLinkFactory();
IStyleLink styleLink = drawableLinkFactory.getStyleLink(this);
IDrawableLink drawableLink = styleLink.getDrawableLink();
if (drawableLink == null) {
throw new NullPointerException();
}
IMapZone zone1 = pointLinkDescriptor1.getZone();
IMapZone zone2 = pointLinkDescriptor2.getZone();
int yOffsetPoint1 = uiManager.getVerticalScrolledOffsetBar((Zone) zone1);
int yOffsetPoint2 = uiManager.getVerticalScrolledOffsetBar((Zone) zone2);
boolean leftSidePosition = ((zone1 == Zone.INPUTS || zone1 == Zone.OUTPUTS) && zone1 == zone2);
int point1xForTraceLink = point1.x + (leftSidePosition ? 0 : widthTable1 - 4);
int point2xForTraceLink = point2.x + (leftSidePosition ? 0 : 0);
int point1yOffset = point1.y + yOffsetPoint1;
int point2yOffset = point2.y + yOffsetPoint2;
drawableLink.setPoint1(new Point(point1xForTraceLink, point1yOffset));
drawableLink.setPoint2(new Point(point2xForTraceLink, point2yOffset));
drawableLink.setBoundsOfCalculate(boundsOfDrawing);
Rectangle boundsOfSolidLine = new Rectangle(boundsOfDrawing.x, boundsOfDrawing.y, boundsOfDrawing.width, boundsOfDrawing.height);
boundsOfSolidLine.y = boundsOfDrawing.y + MapperUI.OFFSET_VISIBLES_POINTS;
boundsOfSolidLine.height = boundsOfDrawing.height - 2 * MapperUI.OFFSET_VISIBLES_POINTS;
drawableLink.getStyle().apply(gc);
if (!boundsOfSolidLine.contains(new Point(point1xForTraceLink, point1yOffset)) || !boundsOfSolidLine.contains(new Point(point2xForTraceLink, point2yOffset))) {
// gc.setLineDash(new int[] { 1, spaceBetweenPoints, 1 });
gc.setLineStyle(SWT.LINE_DOT);
// gc.setLineStyle(SWT.LINE_CUSTOM);
// System.out.println("SWT.LINE_DOT");
} else {
gc.setLineStyle(SWT.LINE_SOLID);
// System.out.println("SWT.LINE_SOLID");
}
if (this.level != null) {
drawableLink.setConnectorWidth(this.level * 5);
}
drawableLink.draw(gc);
}
Aggregations