use of org.eclipse.swt.widgets.TreeItem 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.eclipse.swt.widgets.TreeItem in project tdi-studio-se by Talend.
the class JSONToJsonPathLinker method getTreeItem.
@Override
protected TreeItem getTreeItem(Tree tree, Object dataOfTreeItem, Object dataOfTableItem) {
String path = null;
if (dataOfTableItem instanceof SchemaTarget) {
SchemaTarget target = (SchemaTarget) dataOfTableItem;
path = target.getRelativeXPathQuery();
} else if (dataOfTableItem instanceof JSONXPathLoopDescriptor) {
JSONXPathLoopDescriptor target = (JSONXPathLoopDescriptor) dataOfTableItem;
path = target.getAbsoluteXPathQuery();
if (target.getConnection().isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(target.getConnection(), target.getConnection().getContextName());
path = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, path));
}
}
if (path == null) {
return super.getTreeItem(tree, dataOfTreeItem, dataOfTableItem);
}
boolean expressionIsAbsolute = false;
if (path.trim().startsWith(getRootSeperator())) {
expressionIsAbsolute = true;
}
//$NON-NLS-1$
String fullPath = "";
if (!expressionIsAbsolute) {
if (0 < loopXpathNodes.size()) {
fullPath = loopXpathNodes.get(0) + getFieldSeperator();
}
fullPath = fullPath + path;
} else {
fullPath = path;
}
TreeItem treeItem = treePopulator.getTreeItem(fullPath);
if (treeItem != null) {
return treeItem;
} else {
return super.getTreeItem(tree, dataOfTreeItem, dataOfTableItem);
}
}
use of org.eclipse.swt.widgets.TreeItem in project tdi-studio-se by Talend.
the class JSONFileSchema2TreeLinker method createLinks.
public void createLinks() {
removeAllLinks();
getBackgroundRefresher().refreshBackground();
ProgressDialog progressDialog = new ProgressDialog(getSource().getShell(), 1000) {
private IProgressMonitor monitorWrap;
@Override
public void run(IProgressMonitor monitor) {
TreeItem root = jsonViewer.getTree().getItem(0);
// if (getManager().getFoxComponent().istFileOutputMSXML()) {
// List<FOXTreeNode> treeData = getManager().getTreeData(getManager().getCurrentSchema());
// if (treeData != null && treeData.size() > 0) {
// FOXTreeNode rootTreeData = treeData.get(0);
// for (TreeItem item : xmlViewer.getTree().getItems()) {
// if (rootTreeData == item.getData()) {
// root = item;
// break;
// }
// }
// }
// }
List<TreeItem> allItems = TreeUtils.collectAllItems(root);
monitorWrap = new EventLoopProgressMonitor(monitor);
String taskName = "Loop links creation ...";
int totalWork = allItems.size();
//$NON-NLS-1$
monitorWrap.beginTask(taskName, totalWork);
for (int i = 0; i < totalWork; i++) {
if (monitorWrap.isCanceled()) {
return;
}
TreeItem treeItem = allItems.get(i);
FOXTreeNode node = (FOXTreeNode) treeItem.getData();
if (node.getColumn() == null) {
//$NON-NLS-1$
continue;
}
createLoopLinks(node.getColumn().getLabel(), treeItem, monitorWrap, i == totalWork - 1);
monitorWrap.worked(1);
}
monitorWrap.done();
}
};
try {
progressDialog.executeProcess();
} catch (InvocationTargetException e) {
e.printStackTrace();
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.eclipse.swt.widgets.TreeItem in project tdi-studio-se by Talend.
the class StatLogsAndImplicitcontextTreeViewPage method createStatTree.
private void createStatTree(Composite composite) {
//$NON-NLS-1$
Group g = widgetFactory.createGroup(composite, Messages.getString("StatsAndLogsComposite.StatsLogsSettings"));
GridData gd = new GridData(GridData.FILL_BOTH);
g.setLayoutData(gd);
g.setLayout(new FillLayout());
statViewer = new CheckboxRepositoryTreeViewer(g, SWT.MULTI | SWT.V_SCROLL);
statContentProvider = new AllJobContentProvider(repositoryView);
statViewer.setContentProvider(statContentProvider);
statViewer.setLabelProvider(new RepositoryLabelProvider(repositoryView));
statViewer.setSorter(repositoryView.getViewer().getSorter());
IViewSite viewSite = repositoryView.getViewSite();
statViewer.setInput(viewSite);
// This only tree listener aim is to change open/close icons on folders :
statViewer.addTreeListener(new ITreeViewerListener() {
@Override
public void treeCollapsed(TreeExpansionEvent event) {
RepositoryNode node = (RepositoryNode) event.getElement();
if (node.getType().equals(ENodeType.SIMPLE_FOLDER)) {
TreeItem item = getObject(statViewer.getTree(), event.getElement());
if (item != null) {
item.setImage(ImageProvider.getImage(ECoreImage.FOLDER_CLOSE_ICON));
}
}
}
@Override
public void treeExpanded(TreeExpansionEvent event) {
RepositoryNode node = (RepositoryNode) event.getElement();
if (node.getType().equals(ENodeType.SIMPLE_FOLDER)) {
TreeItem item = getObject(statViewer.getTree(), event.getElement());
if (item != null) {
item.setImage(ImageProvider.getImage(ECoreImage.FOLDER_OPEN_ICON));
}
}
}
});
statViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
RepositoryNode node = (RepositoryNode) event.getElement();
List<RepositoryNode> objects = new ArrayList<RepositoryNode>();
processItems(objects, node);
if (event.getChecked()) {
statAddedObjects.addAll(objects);
statRemovedObjects.removeAll(objects);
statCheckedObjects.addAll(objects);
} else {
statAddedObjects.removeAll(objects);
statRemovedObjects.addAll(objects);
statCheckedObjects.removeAll(objects);
}
// set checked
statViewer.setCheckedElements(statCheckedObjects.toArray());
// viewer.refresh();
}
});
RepositoryNode[] nodes = statContentProvider.getContents();
List<RepositoryNode> objects = new ArrayList<RepositoryNode>();
if (nodes != null) {
for (RepositoryNode n : nodes) {
processItems(objects, n);
for (RepositoryNode node : objects) {
if (isStatUseProjectSetting(node)) {
if (!statCheckedObjects.contains(node)) {
statCheckedObjects.add(node);
}
}
}
}
}
statViewer.setCheckedElements(statCheckedObjects.toArray());
if (nodes != null) {
statViewer.setExpandedElements(nodes);
}
}
use of org.eclipse.swt.widgets.TreeItem 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();
}
Aggregations