Search in sources :

Example 51 with TableItem

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

Example 52 with TableItem

use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.

the class DropContextAnalyzer method dropVarsEntryIsValid.

private boolean dropVarsEntryIsValid(TableItem tableItemTarget) {
    Table table = tableItemTarget.getParent();
    TableItem[] tableItems = table.getItems();
    for (TableItem tableItem : tableItems) {
        if (tableItemTarget == tableItem) {
            break;
        }
        if (tableItemSource == tableItem) {
            return true;
        }
    }
    return false;
}
Also used : IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) Table(org.eclipse.swt.widgets.Table) InputTable(org.talend.designer.mapper.model.table.InputTable) OutputTable(org.talend.designer.mapper.model.table.OutputTable) TableItem(org.eclipse.swt.widgets.TableItem)

Example 53 with TableItem

use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.

the class DropContextAnalyzer method checkDropIsValid.

/**
     * DOC amaumont Comment method "checkDropHasValidTarget".
     */
private boolean checkDropIsValid() {
    isInputToInput = false;
    mapOneToOneAuthorized = true;
    if (targetIsExpressionFilterText() || (targetTableIsFiltersTable() || targetTableIsGlobalMapTable() || draggedData.getTransferableEntryList().size() <= 1)) {
        mapOneToOneAuthorized = false;
    }
    if (invalidKeyPressed) {
        return false;
    }
    /*
         * INPUT => INPUT
         */
    if (zoneSource == Zone.INPUTS && zoneTarget == Zone.INPUTS) {
        isInputToInput = true;
        mapOneToOneAuthorized = false;
        List<InputTable> inputTables = mapperManager.getInputTables();
        int indexTableSource = inputTables.indexOf(dataMapTableViewSource.getDataMapTable());
        int indexTableTarget = inputTables.indexOf(dataMapTableViewTarget.getDataMapTable());
        if (currentTableTarget != null) {
            if (indexTableSource >= indexTableTarget) {
                /*
                     * INPUT => INPUT && index of table source >= index of table target
                     */
                return false;
            } else {
                return true;
            }
        } else if (currentStyledTextTarget != null) {
            if (indexTableSource > indexTableTarget) {
                /*
                     * INPUT => INPUT && index of table source > index of table target
                     */
                return false;
            } else {
                return true;
            }
        } else {
            //$NON-NLS-1$
            throw new IllegalStateException(Messages.getString("DropContextAnalyzer.notFound"));
        }
    }
    /*
         * OUTPUT => OUTPUT
         */
    if (zoneSource == Zone.OUTPUTS && zoneTarget == Zone.OUTPUTS) {
        isOutputToOutput = true;
        mapOneToOneAuthorized = true;
        List<OutputTable> outputTables = mapperManager.getOutputTables();
        int indexSourceOutputTable = outputTables.indexOf(dataMapTableViewSource.getDataMapTable());
        int indexTargetOutputTable = outputTables.indexOf(dataMapTableViewTarget.getDataMapTable());
        if (indexSourceOutputTable == indexTargetOutputTable) {
            /*
                 * INPUT => INPUT && index of table source >= index of table target
                 */
            return false;
        } else {
            // OUTPUT => OUTPUT
            return checkZoonTarget();
        }
    }
    if (currentTableTarget != null) {
        TableItem tableItemTarget = getTableItemFromPosition(new Point(event.x, event.y));
        if (zoneSource == Zone.VARS && zoneTarget == Zone.VARS && tableItemTarget != null) {
            if (tableItemSource == tableItemTarget || !dropVarsEntryIsValid(tableItemTarget)) {
                /*
                     * VAR => VAR && (item source == item target || item target is invalid)
                     */
                return false;
            }
        }
    }
    if (zoneSource == Zone.VARS && zoneTarget == Zone.INPUTS || zoneSource == Zone.OUTPUTS && zoneTarget == Zone.INPUTS || zoneSource == Zone.OUTPUTS && zoneTarget == Zone.VARS) {
        /*
             * VAR => INPUT OUTPUT => OUTPUT OUTPUT => INPUT OUTPUT => VAR
             */
        return false;
    }
    return checkZoonTarget();
}
Also used : InputTable(org.talend.designer.mapper.model.table.InputTable) TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) OutputTable(org.talend.designer.mapper.model.table.OutputTable)

Example 54 with TableItem

use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.

the class DropContextAnalyzer method checkZoonTarget.

private boolean checkZoonTarget() {
    IDataMapTable dataMapTable = dataMapTableViewTarget.getDataMapTable();
    if (zoneTarget == Zone.OUTPUTS) {
        OutputTable outputTable = (OutputTable) dataMapTable;
        if (outputTable.isErrorRejectTable()) {
            if (currentTableTarget != null && event != null) {
                if (event.item instanceof TableItem) {
                    Object data = event.item.getData();
                    if (data instanceof OutputColumnTableEntry) {
                        String label = ((OutputColumnTableEntry) data).getName();
                        if (mapperManager.ERROR_REJECT_MESSAGE.equals(label) || mapperManager.ERROR_REJECT_STACK_TRACE.equals(label)) {
                            return false;
                        }
                    }
                }
            }
        }
        boolean useRepositoryMeta = (outputTable.isRepository()) || (outputTable.getId() != null && !"".equals(outputTable.getId()));
        // for join table if main table use repository metadata
        if (!useRepositoryMeta && outputTable.getIsJoinTableOf() != null && !"".equals(outputTable.getIsJoinTableOf())) {
            OutputTable mainTable = mapperManager.getOutputTableByName(outputTable.getIsJoinTableOf());
            if (mainTable != null) {
                useRepositoryMeta = mainTable.getId() != null && !"".equals(mainTable.getId());
            }
        }
        if (useRepositoryMeta && currentStyledTextTarget != null) {
            return true;
        }
        if (useRepositoryMeta && isCursorOverHeader || useRepositoryMeta && !isCursorOverExpressionCell) {
            return false;
        }
    }
    return true;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) OutputColumnTableEntry(org.talend.designer.mapper.model.tableentry.OutputColumnTableEntry) OutputTable(org.talend.designer.mapper.model.table.OutputTable)

Example 55 with TableItem

use of org.eclipse.swt.widgets.TableItem in project tdi-studio-se by Talend.

the class JSONToXPathLinker method createFieldsLinkWithProgressMonitor.

/**
     * DOC amaumont Comment method "createFieldsLinkWithProgressDialog".
     * 
     * @param monitorWrap
     * @param fieldsTableItems
     * @param totalWork
     * @param schemaTargetList
     */
private void createFieldsLinkWithProgressMonitor(IProgressMonitor monitorWrap, int totalWork, List<SchemaTarget> schemaTargetList, int startTableItem, int tableItemLength) {
    monitorWrap.beginTask("Fields links creation ...", totalWork);
    TableItem[] fieldsTableItems = fieldsTableEditorView.getTable().getItems();
    for (int i = startTableItem, indexShemaTarget = 0; i < startTableItem + tableItemLength; i++, indexShemaTarget++) {
        if (monitorWrap.isCanceled()) {
            for (int j = startTableItem + tableItemLength - 2; j >= 0; j--) {
                // fieldsTableEditorView.getTable().remove(j);
                fieldsTableEditorView.getTable().redraw();
                JSONExtractorFieldModel schemaModel = this.fieldsTableEditorView.getModel();
                schemaModel.remove(j);
            }
            return;
        }
        TableItem tableItem = fieldsTableItems[i];
        SchemaTarget schemaTarget = schemaTargetList.get(indexShemaTarget);
        String relativeXpathQuery = schemaTarget.getRelativeXPathQuery();
        createFieldLinks(relativeXpathQuery, tableItem, monitorWrap, schemaTarget);
        monitorWrap.worked(1);
    }
    getLinksManager().sortLinks(getDrawingLinksComparator());
    getBackgroundRefresher().refreshBackground();
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) SchemaTarget(org.talend.repository.model.json.SchemaTarget)

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