Search in sources :

Example 1 with SelectionModifier

use of com.centurylink.jface.viewers.TreeComboCellEditor.SelectionModifier in project mdw-designer by CenturyLinkCloud.

the class TableEditor method createTableViewer.

private TableViewer createTableViewer(Table table) {
    TableViewer lTableViewer = new TableViewer(table);
    lTableViewer.setUseHashlookup(true);
    lTableViewer.setColumnProperties(columnProps);
    if (!isReadOnly()) {
        CellEditor[] cellEditors = new CellEditor[columnSpecs.size()];
        for (int i = 0; i < columnSpecs.size(); i++) {
            ColumnSpec colSpec = columnSpecs.get(i);
            CellEditor cellEditor = null;
            if (!colSpec.hidden) {
                if (colSpec.type.equals(TYPE_TEXT)) {
                    if (colSpec.style != 0)
                        cellEditor = new TextCellEditor(table, colSpec.style);
                    else
                        cellEditor = new TextCellEditor(table);
                } else if (colSpec.type.equals(TYPE_CHECKBOX)) {
                    cellEditor = new CheckboxCellEditor(table);
                } else if (colSpec.type.equals(TYPE_COMBO)) {
                    int style = SWT.None;
                    if (colSpec.readOnly)
                        style = style | SWT.READ_ONLY;
                    cellEditor = new ComboBoxCellEditor(table, colSpec.options, style);
                    if (!colSpec.readOnly)
                        cellEditor.addListener(new EditableComboCellEditorListener((ComboBoxCellEditor) cellEditor, i));
                } else if (colSpec.type.equals(WorkflowAssetEditor.TYPE_ASSET)) {
                    int style = SWT.None;
                    if (colSpec.readOnly)
                        style = style | SWT.READ_ONLY;
                    cellEditor = new TreeComboCellEditor(table, style) {

                        @Override
                        protected void doSetValue(Object value) {
                            Object val = getValue();
                            if (val instanceof CTreeComboItem) {
                                CTreeComboItem selItem = (CTreeComboItem) getValue();
                                if (selItem != null) {
                                    super.doSetValue(selItem.getText());
                                    return;
                                }
                            }
                            if (value instanceof String) {
                                String strVal = (String) value;
                                if (strVal.indexOf('/') > -1) {
                                    super.doSetValue(strVal.substring(strVal.indexOf('/') + 1));
                                    return;
                                }
                            }
                            super.doSetValue(value);
                        }
                    };
                    ((TreeComboCellEditor) cellEditor).setSelectionModifier(new SelectionModifier() {

                        public String modify(CTreeComboItem selection) {
                            if (selection.getParentItem() != null) {
                                WorkflowPackage pkg = getProject().getPackage(selection.getParentItem().getText());
                                if (pkg == null || pkg.isDefaultPackage())
                                    return selection.getText();
                                else
                                    return pkg.getName() + "/" + selection.getText();
                            } else {
                                // ignore packages
                                return null;
                            }
                        }
                    });
                    // populate the treecombo
                    if (colSpec.source.equals(PROCESS)) {
                        List<WorkflowPackage> packages = getProject().getTopLevelUserVisiblePackages();
                        for (WorkflowPackage pkg : packages) {
                            CTreeComboItem packageItem = ((TreeComboCellEditor) cellEditor).addItem(pkg.getName());
                            packageItem.setText(pkg.getName());
                            packageItem.setImage(pkg.getIconImage());
                            for (WorkflowProcess process : pkg.getProcesses()) {
                                CTreeComboItem processItem = new CTreeComboItem(packageItem, SWT.NONE);
                                processItem.setText(process.getLabel());
                                processItem.setImage(process.getIconImage());
                            }
                        }
                    } else {
                        List<WorkflowAsset> assets = getProject().getAssetList(Arrays.asList(colSpec.assetTypes));
                        Map<String, CTreeComboItem> packageItems = new HashMap<>();
                        for (WorkflowAsset asset : assets) {
                            String pkgName = asset.getPackage().getName();
                            CTreeComboItem packageItem = packageItems.get(pkgName);
                            if (packageItem == null) {
                                packageItem = ((TreeComboCellEditor) cellEditor).addItem(pkgName);
                                packageItem.setImage(asset.getPackage().getIconImage());
                                packageItems.put(pkgName, packageItem);
                            }
                            CTreeComboItem assetItem = new CTreeComboItem(packageItem, SWT.NONE);
                            assetItem.setText(asset.getLabel());
                            assetItem.setImage(asset.getIconImage());
                        }
                    }
                }
                if (colSpec.listener != null && cellEditor != null)
                    cellEditor.addListener(colSpec.listener);
                cellEditors[i] = cellEditor;
            }
        }
        lTableViewer.setCellEditors(cellEditors);
        lTableViewer.setCellModifier(cellModifier);
    }
    return lTableViewer;
}
Also used : WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) TreeComboCellEditor(com.centurylink.jface.viewers.TreeComboCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) CTreeComboItem(com.centurylink.swt.widgets.CTreeComboItem) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) SelectionModifier(com.centurylink.jface.viewers.TreeComboCellEditor.SelectionModifier) WorkflowAsset(com.centurylink.mdw.plugin.designer.model.WorkflowAsset) TreeComboCellEditor(com.centurylink.jface.viewers.TreeComboCellEditor) List(java.util.List) ArrayList(java.util.ArrayList) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) WorkflowProcess(com.centurylink.mdw.plugin.designer.model.WorkflowProcess) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

TreeComboCellEditor (com.centurylink.jface.viewers.TreeComboCellEditor)1 SelectionModifier (com.centurylink.jface.viewers.TreeComboCellEditor.SelectionModifier)1 WorkflowAsset (com.centurylink.mdw.plugin.designer.model.WorkflowAsset)1 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)1 WorkflowProcess (com.centurylink.mdw.plugin.designer.model.WorkflowProcess)1 CTreeComboItem (com.centurylink.swt.widgets.CTreeComboItem)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CellEditor (org.eclipse.jface.viewers.CellEditor)1 CheckboxCellEditor (org.eclipse.jface.viewers.CheckboxCellEditor)1 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1