Search in sources :

Example 56 with TableItem

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
    }
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) TableItem(org.eclipse.swt.widgets.TableItem) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) SchemaTarget(org.talend.repository.model.json.SchemaTarget) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 57 with TableItem

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;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) TreeItem(org.eclipse.swt.widgets.TreeItem) Item(org.eclipse.swt.widgets.Item) ItemExtremityDescriptor(org.talend.commons.ui.swt.drawing.link.ItemExtremityDescriptor) Tree(org.eclipse.swt.widgets.Tree) LinkDescriptor(org.talend.commons.ui.swt.drawing.link.LinkDescriptor)

Example 58 with TableItem

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();
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem)

Example 59 with TableItem

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();
    }
}
Also used : Table(org.eclipse.swt.widgets.Table) HashMap(java.util.HashMap) TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) IExtremityLink(org.talend.commons.ui.swt.drawing.link.IExtremityLink) IStyleLink(org.talend.commons.ui.swt.drawing.link.IStyleLink) Tree(org.eclipse.swt.widgets.Tree) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkDescriptor(org.talend.commons.ui.swt.drawing.link.LinkDescriptor) HashSet(java.util.HashSet)

Example 60 with TableItem

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;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Aggregations

TableItem (org.eclipse.swt.widgets.TableItem)475 Point (org.eclipse.swt.graphics.Point)136 Table (org.eclipse.swt.widgets.Table)125 TableColumn (org.eclipse.swt.widgets.TableColumn)79 SelectionEvent (org.eclipse.swt.events.SelectionEvent)73 GridData (org.eclipse.swt.layout.GridData)70 GridLayout (org.eclipse.swt.layout.GridLayout)61 Composite (org.eclipse.swt.widgets.Composite)56 ArrayList (java.util.ArrayList)55 Image (org.eclipse.swt.graphics.Image)55 Button (org.eclipse.swt.widgets.Button)53 Rectangle (org.eclipse.swt.graphics.Rectangle)52 Label (org.eclipse.swt.widgets.Label)51 Shell (org.eclipse.swt.widgets.Shell)49 Color (org.eclipse.swt.graphics.Color)48 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)43 Text (org.eclipse.swt.widgets.Text)42 FillLayout (org.eclipse.swt.layout.FillLayout)40 Test (org.junit.Test)39 SelectionListener (org.eclipse.swt.events.SelectionListener)36