Search in sources :

Example 21 with TableViewerCreator

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreator in project tdi-studio-se by Talend.

the class SearchZoneMapper method getSelectedKeyAtSelectedTableItem.

public Integer getSelectedKeyAtSelectedTableItem(Map<Integer, Map<Integer, ITableEntry>> searchMaps) {
    Integer selectKey = 0;
    TableViewerCreator tableViewerCreator = null;
    if (uiManager.getCurrentSelectedInputTableView() != null) {
        tableViewerCreator = uiManager.getCurrentSelectedInputTableView().getTableViewerCreatorForColumns();
        if (tableViewerCreator != null && tableViewerCreator.getTableViewer() != null) {
            ISelection selection = tableViewerCreator.getTableViewer().getSelection();
            if (selection == null || selection.isEmpty()) {
                if (uiManager.getCurrentSelectedOutputTableView() != null) {
                    tableViewerCreator = uiManager.getCurrentSelectedOutputTableView().getTableViewerCreatorForColumns();
                    if (tableViewerCreator != null && tableViewerCreator.getTableViewer() != null) {
                        selection = tableViewerCreator.getTableViewer().getSelection();
                        if (selection == null || selection.isEmpty()) {
                            if (uiManager.getCurrentSelectedVarsTableView() != null) {
                                tableViewerCreator = uiManager.getCurrentSelectedVarsTableView().getTableViewerCreatorForColumns();
                            }
                        }
                    }
                } else if (uiManager.getCurrentSelectedVarsTableView() != null) {
                    tableViewerCreator = uiManager.getCurrentSelectedVarsTableView().getTableViewerCreatorForColumns();
                }
            }
        }
    } else if (uiManager.getCurrentSelectedVarsTableView() != null) {
        tableViewerCreator = uiManager.getCurrentSelectedVarsTableView().getTableViewerCreatorForColumns();
    } else if (uiManager.getCurrentSelectedOutputTableView() != null) {
        tableViewerCreator = uiManager.getCurrentSelectedOutputTableView().getTableViewerCreatorForColumns();
    }
    if (tableViewerCreator != null && tableViewerCreator.getTableViewer() != null) {
        ISelection selection = tableViewerCreator.getTableViewer().getSelection();
        if (selection != null && !selection.isEmpty()) {
            List<ITableEntry> list = uiManager.extractSelectedTableEntries(selection);
            if (list != null && !list.isEmpty()) {
                ITableEntry tableEntry = list.get(0);
                if (tableEntry != null) {
                    Iterator iter = searchMaps.entrySet().iterator();
                    while (iter.hasNext()) {
                        Map.Entry entry = (Map.Entry) iter.next();
                        Map<Integer, ITableEntry> map = (Map<Integer, ITableEntry>) entry.getValue();
                        if (map.containsValue(tableEntry)) {
                            Iterator it = map.entrySet().iterator();
                            while (it.hasNext()) {
                                Map.Entry e = (Map.Entry) it.next();
                                if (e.getValue() != null && e.getValue() instanceof ITableEntry) {
                                    ITableEntry tableEntryTemp = (ITableEntry) e.getValue();
                                    if (tableEntry.equals(tableEntryTemp)) {
                                        tableViewerCreator.getTableViewer().getTable().deselectAll();
                                        return (Integer) entry.getKey();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return selectKey;
}
Also used : ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) ITableEntry(org.talend.designer.abstractmap.model.tableentry.ITableEntry) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with TableViewerCreator

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreator in project tdi-studio-se by Talend.

the class TableController method refresh.

@Override
public void refresh(IElementParameter param, boolean check) {
    TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
    if (tableViewerCreator == null || tableViewerCreator.getTable() == null || tableViewerCreator.getTable().isDisposed()) {
        return;
    }
    updateContextList(param);
    Object value = param.getValue();
    if (value instanceof List) {
        // updateTableValues(param);
        // (bug 5365)
        checkAndSetDefaultValue(param);
        if (tableViewerCreator != null) {
            if (!tableViewerCreator.getInputList().equals(value)) {
                tableViewerCreator.init((List) value);
            }
            tableViewerCreator.getTableViewer().refresh();
        }
    }
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 23 with TableViewerCreator

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreator in project tdi-studio-se by Talend.

the class TableController method updateContextList.

private void updateContextList(IElementParameter param) {
    List<String> contextParameterNamesList = new ArrayList<String>();
    IElementParameter processTypeParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
    if (processTypeParam == null) {
        processTypeParam = elem.getElementParameterFromField(EParameterFieldType.ROUTE_INPUT_PROCESS_TYPE);
        if (processTypeParam == null) {
            return;
        }
    }
    boolean haveContextParamList = false;
    for (Object valueParam : param.getListItemsValue()) {
        if (valueParam instanceof IElementParameter) {
            IElementParameter vParam = (IElementParameter) valueParam;
            if (vParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
                haveContextParamList = true;
                break;
            }
        }
    }
    if (!haveContextParamList) {
        return;
    }
    IElementParameter jobElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
    IElementParameter jobVersionParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_VERSION.getName());
    IElementParameter contextElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_CONTEXT.getName());
    // get context list
    String processId = (String) jobElemParam.getValue();
    String contextName = (String) contextElemParam.getValue();
    if (contextName == null) {
        contextName = new String();
    }
    if (processId == null || contextName == null) {
        revertToolBarButtonState(false);
        return;
    }
    IElementParameter useDynamic = elem.getElementParameter("USE_DYNAMIC_JOB");
    if (useDynamic != null && Boolean.valueOf(String.valueOf(useDynamic.getValue()))) {
        String[] split = processId.split(";");
        processId = split[0];
    }
    ProcessItem processItem = ItemCacheManager.getProcessItem(processId, (String) jobVersionParam.getValue());
    String[] contextParameterNames = null;
    if (processItem != null) {
        // achen modify to fix bug 0006107
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        // process = new Process(processItem.getProperty());
        // process.loadXmlFile();
        IContextManager contextManager = service.getProcessContextFromItem(processItem);
        if (contextManager != null) {
            IContext context = contextManager.getContext(contextName);
            for (IContextParameter contextParam : context.getContextParameterList()) {
                contextParameterNamesList.add(contextParam.getName());
            }
        }
        contextParameterNames = contextParameterNamesList.toArray(new String[0]);
    }
    if (contextParameterNames == null || contextParameterNames.length == 0) {
        contextParameterNamesList.clear();
        // we rerebuild the list here from what was saved in the job before
        for (HashMap<String, Object> values : (List<HashMap<String, Object>>) param.getValue()) {
            //$NON-NLS-1$
            String name = (String) values.get("PARAM_NAME_COLUMN");
            contextParameterNamesList.add(name);
        }
        contextParameterNames = contextParameterNamesList.toArray(new String[0]);
    }
    // update table values
    TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
    Object[] itemsValue = param.getListItemsValue();
    if (tableViewerCreator != null) {
        List colList = tableViewerCreator.getColumns();
        for (int j = 0; j < itemsValue.length; j++) {
            if ((j + 1) >= colList.size()) {
                break;
            }
            if (itemsValue[j] instanceof IElementParameter) {
                IElementParameter tmpParam = (IElementParameter) itemsValue[j];
                if (tmpParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
                    tmpParam.setListItemsDisplayCodeName(contextParameterNames);
                    tmpParam.setListItemsDisplayName(contextParameterNames);
                    tmpParam.setListItemsValue(contextParameterNames);
                    // TDI-35251 won't set default, if not fount, keep error
                    // if (contextParameterNames.length > 0) {
                    // tmpParam.setDefaultClosedListValue(contextParameterNames[0]);
                    // } else {
                    //$NON-NLS-1$
                    tmpParam.setDefaultClosedListValue("");
                    // }
                    // j + 1 because first column is masked
                    TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) colList.get(j + 1);
                    CCombo combo = (CCombo) column.getCellEditor().getControl();
                    String[] oldItems = combo.getItems();
                    combo.setItems(contextParameterNames);
                    List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
                    String[] items = param.getListItemsDisplayCodeName();
                    for (int currentIndex = 0; currentIndex < paramValues.size(); currentIndex++) {
                        Map<String, Object> currentLine = paramValues.get(currentIndex);
                        Object o = currentLine.get(items[j]);
                        if (o instanceof Integer) {
                            Integer nb = (Integer) o;
                            if ((nb >= oldItems.length) || (nb == -1)) {
                                currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
                            } else {
                                currentLine.put(items[j], oldItems[nb]);
                            }
                        } else {
                            if (o instanceof String) {
                                Integer nb = new Integer(tmpParam.getIndexOfItemFromList((String) o));
                                if (nb == -1 && !"".equals(tmpParam.getDefaultClosedListValue())) {
                                    currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // (bug 3740)
    boolean checked = contextParameterNames != null && contextParameterNames.length > 0;
    revertToolBarButtonState(checked);
}
Also used : IContext(org.talend.core.model.process.IContext) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) ArrayList(java.util.ArrayList) IContextParameter(org.talend.core.model.process.IContextParameter) Point(org.eclipse.swt.graphics.Point) CCombo(org.eclipse.swt.custom.CCombo) ProcessItem(org.talend.core.model.properties.ProcessItem) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IContextManager(org.talend.core.model.process.IContextManager) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with TableViewerCreator

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreator in project tdi-studio-se by Talend.

the class TableController method updateColumnList.

private void updateColumnList(IElementParameter param) {
    if (elem instanceof Node) {
        ColumnListController.updateColumnList((Node) elem, null);
    } else if (elem instanceof Connection) {
        ColumnListController.updateColumnList(((Connection) elem).getSource(), null);
    }
    TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
    Object[] itemsValue = param.getListItemsValue();
    if (tableViewerCreator != null) {
        List colList = tableViewerCreator.getColumns();
        for (int j = 0; j < itemsValue.length; j++) {
            if (itemsValue[j] instanceof IElementParameter) {
                IElementParameter tmpParam = (IElementParameter) itemsValue[j];
                if (tmpParam.getFieldType() == EParameterFieldType.COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.PREV_COLUMN_LIST || tmpParam.getFieldType() == EParameterFieldType.LOOKUP_COLUMN_LIST) {
                    if ((j + 1) >= colList.size()) {
                        break;
                    }
                    TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) colList.get(j + 1);
                    CellEditor cellEditor = column.getCellEditor();
                    String[] oldItems = null;
                    if (cellEditor instanceof ComboBoxCellEditor) {
                        CCombo combo = (CCombo) cellEditor.getControl();
                        oldItems = combo.getItems();
                        combo.setItems(tmpParam.getListItemsDisplayName());
                    }
                    List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
                    String[] items = param.getListItemsDisplayCodeName();
                    for (int currentIndex = 0; currentIndex < paramValues.size(); currentIndex++) {
                        Map<String, Object> currentLine = paramValues.get(currentIndex);
                        Object o = currentLine.get(items[j]);
                        if (o instanceof Integer) {
                            Integer nb = (Integer) o;
                            if ((nb >= oldItems.length) || (nb == -1)) {
                                nb = new Integer(tmpParam.getIndexOfItemFromList((String) tmpParam.getDefaultClosedListValue()));
                                currentLine.put(items[j], nb);
                            } else {
                                nb = new Integer(tmpParam.getIndexOfItemFromList(oldItems[nb]));
                                currentLine.put(items[j], nb);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) CellEditor(org.eclipse.jface.viewers.CellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Node(org.talend.designer.core.ui.editor.nodes.Node) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Point(org.eclipse.swt.graphics.Point) CCombo(org.eclipse.swt.custom.CCombo) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with TableViewerCreator

use of org.talend.commons.ui.swt.tableviewer.TableViewerCreator in project tdi-studio-se by Talend.

the class TableController method updateComponentList.

private void updateComponentList(IElementParameter param) {
    // update table values
    TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
    Object[] itemsValue = param.getListItemsValue();
    if (tableViewerCreator != null) {
        List colList = tableViewerCreator.getColumns();
        for (int j = 0; j < itemsValue.length; j++) {
            if ((j + 1) >= colList.size()) {
                break;
            }
            if (itemsValue[j] instanceof IElementParameter) {
                IElementParameter tmpParam = (IElementParameter) itemsValue[j];
                if (tmpParam.getFieldType() == EParameterFieldType.COMPONENT_LIST) {
                    String[] contextParameterNames = null;
                    ComponentListController.updateComponentList(elem, tmpParam);
                    contextParameterNames = tmpParam.getListItemsDisplayName();
                    tmpParam.setListItemsDisplayCodeName(contextParameterNames);
                    // tmpParam.setListItemsValue(contextParameterNames);
                    if (contextParameterNames.length > 0) {
                        tmpParam.setDefaultClosedListValue(contextParameterNames[0]);
                    } else {
                        //$NON-NLS-1$
                        tmpParam.setDefaultClosedListValue("");
                    }
                    // j + 1 because first column is masked
                    TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) colList.get(j + 1);
                    CCombo combo = (CCombo) column.getCellEditor().getControl();
                    String[] oldItems = combo.getItems();
                    combo.setItems(contextParameterNames);
                    List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
                    String[] items = param.getListItemsDisplayCodeName();
                    for (int currentIndex = 0; currentIndex < paramValues.size(); currentIndex++) {
                        Map<String, Object> currentLine = paramValues.get(currentIndex);
                        Object o = currentLine.get(items[j]);
                        if (o instanceof Integer) {
                            Integer nb = (Integer) o;
                            if ((nb >= oldItems.length) || (nb == -1)) {
                                nb = new Integer(tmpParam.getIndexOfItemFromList((String) tmpParam.getDefaultClosedListValue()));
                                currentLine.put(items[j], nb);
                            } else {
                                nb = new Integer(tmpParam.getIndexOfItemFromList(oldItems[nb]));
                                currentLine.put(items[j], nb);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) Point(org.eclipse.swt.graphics.Point) CCombo(org.eclipse.swt.custom.CCombo) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TableViewerCreator (org.talend.commons.ui.swt.tableviewer.TableViewerCreator)36 ArrayList (java.util.ArrayList)14 List (java.util.List)14 Point (org.eclipse.swt.graphics.Point)14 TableViewerCreatorColumnNotModifiable (org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable)11 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 CCombo (org.eclipse.swt.custom.CCombo)8 IElementParameter (org.talend.core.model.process.IElementParameter)8 DataMapTableView (org.talend.designer.mapper.ui.visualmap.table.DataMapTableView)8 MetadataTableEditorView (org.talend.core.ui.metadata.editor.MetadataTableEditorView)6 IColumnEntry (org.talend.designer.abstractmap.model.tableentry.IColumnEntry)6 TableViewer (org.eclipse.jface.viewers.TableViewer)4 DisposeEvent (org.eclipse.swt.events.DisposeEvent)4 DisposeListener (org.eclipse.swt.events.DisposeListener)4 ILineSelectionListener (org.talend.commons.ui.runtime.swt.tableviewer.selection.ILineSelectionListener)4 LineSelectionEvent (org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent)4 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)4 IDataMapTable (org.talend.designer.abstractmap.model.table.IDataMapTable)4