org.geneweaver.query.ui.GraphNodeEditingSupport Maven / Gradle / Ivy
package org.geneweaver.query.ui;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.geneweaver.query.dao.GraphNode;
import org.geneweaver.query.dao.MappedParameter;
class GraphNodeEditingSupport extends EditingSupport {
private final TableViewer viewer;
private final CellEditor editor;
private InputMapPage page;
public GraphNodeEditingSupport(InputMapPage page, TableViewer viewer) {
super(viewer);
this.viewer = viewer;
this.page = page;
this.editor = new ComboBoxCellEditor(viewer.getTable(), GraphNode.names(), SWT.READ_ONLY);
((CCombo)editor.getControl()).addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
viewer.applyEditorValue();
viewer.cancelEditing();
}
});
}
@Override
protected CellEditor getCellEditor(Object element) {
return editor;
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected Object getValue(Object element) {
MappedParameter p = (MappedParameter) element;
if (p==null) return null;
GraphNode sel = p.getNode();
if (sel==null) return 0;
return GraphNode.indexOf(sel);
}
@Override
protected void setValue(Object element, Object userInputValue) {
MappedParameter p = (MappedParameter) element;
GraphNode node = GraphNode.get((Integer)userInputValue);
p.setNode(node);
viewer.update(element, null);
page.validate(true);
}
}