1 package net.mograsim.plugin.tables.mi;
3 import org.eclipse.jface.viewers.CellEditor;
4 import org.eclipse.jface.viewers.ComboBoxCellEditor;
5 import org.eclipse.jface.viewers.EditingSupport;
6 import org.eclipse.jface.viewers.TableViewer;
7 import org.eclipse.swt.SWT;
9 import net.mograsim.logic.core.types.Bit;
10 import net.mograsim.machine.mi.MicroInstruction;
11 import net.mograsim.machine.mi.MicroInstructionDefinition;
12 import net.mograsim.machine.mi.parameters.BooleanClassification;
13 import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
14 import net.mograsim.machine.mi.parameters.Mnemonic;
16 public class BooleanEditingSupport extends EditingSupport
18 private final ComboBoxCellEditor editor;
19 private final BooleanClassification boolClass;
20 private final TableViewer viewer;
21 private final int index;
23 public BooleanEditingSupport(TableViewer viewer, MicroInstructionDefinition definition, int index)
27 this.boolClass = (BooleanClassification) definition.getParameterClassification(index);
28 editor = new ComboBoxCellEditor(viewer.getTable(), boolClass.getStringValues(), SWT.READ_ONLY);
29 editor.setActivationStyle(
30 ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_PROGRAMMATIC_ACTIVATION
31 | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION);
36 protected boolean canEdit(Object element)
42 protected CellEditor getCellEditor(Object element)
48 protected Object getValue(Object element)
50 InstructionTableRow row = (InstructionTableRow) element;
51 // true is 0 because the true value comes first in the combo box
52 return row.data.getCell(row.address).getParameter(index).getValue().getMSBit(0).equals(Bit.ONE) ? 0 : 1;
56 protected void setValue(Object element, Object value)
58 InstructionTableRow row = (InstructionTableRow) element;
59 MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters();
60 // true is 0 because the true value comes first in the combo box
61 Mnemonic newParam = boolClass.get(value.equals(0) ? true : false);
62 if (newParam.equals(params[index]))
64 params[index] = newParam;
65 row.data.setCell(row.address, MicroInstruction.create(params));
66 viewer.update(element, null);