use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.
the class JSONToXPathLinker method createLinks.
/**
* DOC amaumont Comment method "createLinks".
*/
public void createLinks() {
removeAllLinks();
getBackgroundRefresher().refreshBackground();
ProgressDialog progressDialog = new ProgressDialog(getTree().getShell(), 1000) {
private IProgressMonitor monitorWrap;
@Override
public void run(IProgressMonitor monitor) {
TableItem[] loopTableItems = loopTableEditorView.getTable().getItems();
TableItem[] fieldsTableItems = fieldsTableEditorView.getTable().getItems();
monitorWrap = new EventLoopProgressMonitor(monitor);
String taskName = "Loop links creation ...";
int totalWork = loopTableItems.length + fieldsTableItems.length;
monitorWrap.beginTask(taskName, totalWork);
List<JSONXPathLoopDescriptor> xpathLoopDescriptorList = loopTableEditorView.getModel().getBeansList();
for (int i = 0; i < loopTableItems.length; i++) {
if (monitorWrap.isCanceled()) {
return;
}
TableItem tableItem = loopTableItems[i];
JSONXPathLoopDescriptor xpathLoopDescriptor = xpathLoopDescriptorList.get(i);
String originalValue = xpathLoopDescriptor.getAbsoluteXPathQuery();
if (xpathLoopDescriptor.getConnection() != null) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(xpathLoopDescriptor.getConnection(), xpathLoopDescriptor.getConnection().getContextName());
if (contextType != null) {
originalValue = ConnectionContextHelper.getOriginalValue(contextType, xpathLoopDescriptor.getAbsoluteXPathQuery());
originalValue = TalendQuoteUtils.removeQuotes(originalValue);
}
}
if (originalValue != null) {
createLoopLinks(originalValue, tableItem, monitorWrap);
}
monitorWrap.worked(1);
}
List<SchemaTarget> schemaTargetList = fieldsTableEditorView.getModel().getBeansList();
createFieldsLinkWithProgressMonitor(monitorWrap, schemaTargetList.size() + loopTableItems.length, schemaTargetList, 0, fieldsTableItems.length);
monitorWrap.done();
}
};
try {
progressDialog.executeProcess();
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
// Nothing to do
}
}
use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.
the class JSONFileSchema2TreeLinker method addLink.
private LinkDescriptor<Item, Object, Tree, Object> addLink(Item tableItem, Object dataItem1, Tree tree, Object dataItem2, boolean lastOne) {
LinkDescriptor<Item, Object, Tree, Object> link = new LinkDescriptor<Item, Object, Tree, Object>(new ItemExtremityDescriptor(tableItem, dataItem1), new ExtremityLink<Tree, Object>(tree, dataItem2));
link.setStyleLink(getUnselectedStyleLink());
getLinksManager().addLink(link);
updateLinksStyleAndControlsSelection(tree, lastOne);
return link;
}
use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.
the class JSONToXPathLinker method onXPathValueChanged.
/**
* DOC amaumont Comment method "onXPathValueChanged".
*
* @param table
* @param newValue
* @param itemIndex
*/
public void onXPathValueChanged(Table table, String newValue, int itemIndex) {
if (isLoopTable(table)) {
nodeRetriever.setCurrentLoopXPath(newValue);
}
TableItem tableItem = table.getItem(itemIndex);
linksManager.removeLinksFromDataItem2(tableItem.getData());
if (isLoopTable(table)) {
createLinks();
} else {
createFieldLinks(newValue, tableItem, null, null);
}
getBackgroundRefresher().refreshBackground();
}
use of org.eclipse.swt.widgets.TableItem 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.TableItem in project tdi-studio-se by Talend.
the class CompleteDropTargetListener method getItemIndexFromPosition.
/**
*
* DOC amaumont Comment method "getItemIndexFromPosition".
*
* @param cursorPosition
* @return
*/
private Integer getItemIndexFromPosition(Point cursorPosition) {
TableItem[] tableItems = draggableTable.getItems();
Point point = new Point(cursorPosition.x, cursorPosition.y);
TableItem tableItemBehindCursor = getTableItemFromPosition(point);
if (tableItemBehindCursor != null) {
for (int i = 0; i < tableItems.length; i++) {
if (tableItems[i] == tableItemBehindCursor) {
return i;
}
}
}
return null;
}
Aggregations