use of com.centurylink.jface.viewers.TreeComboCellEditor 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;
}
Aggregations