org.geneweaver.query.ui.GraphAttributeEditingSupport 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.GraphAttribute;
import org.geneweaver.query.dao.GraphNode;
import org.geneweaver.query.dao.MappedParameter;
class GraphAttributeEditingSupport extends EditingSupport {
private final TableViewer viewer;
private final CellEditor editor;
private InputMapPage page;
public GraphAttributeEditingSupport(InputMapPage page, TableViewer viewer) {
super(viewer);
this.viewer = viewer;
this.page = page;
this.editor = new ComboBoxCellEditor(viewer.getTable(), GraphAttribute.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;
GraphAttribute sel = p.getAttribute();
if (sel==null) return 0;
return GraphAttribute.indexOf(sel);
}
@Override
protected void setValue(Object element, Object userInputValue) {
MappedParameter p = (MappedParameter) element;
GraphAttribute att = GraphAttribute.get((Integer)userInputValue);
p.setAttribute(att);
viewer.update(element, null);
page.validate(true);
}
}