Made InstructionTable a bit easier to use
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / tables / mi / BooleanEditingSupport.java
index fa7a918..8cdaae2 100644 (file)
@@ -1,19 +1,21 @@
 package net.mograsim.plugin.tables.mi;
 
 import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
 import org.eclipse.jface.viewers.EditingSupport;
 import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
 
 import net.mograsim.logic.core.types.Bit;
 import net.mograsim.machine.mi.MicroInstruction;
 import net.mograsim.machine.mi.MicroInstructionDefinition;
 import net.mograsim.machine.mi.parameters.BooleanClassification;
 import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
+import net.mograsim.machine.mi.parameters.Mnemonic;
 
 public class BooleanEditingSupport extends EditingSupport
 {
-       private final CheckboxCellEditor editor;
+       private final ComboBoxCellEditor editor;
        private final BooleanClassification boolClass;
        private final TableViewer viewer;
        private final int index;
@@ -23,7 +25,10 @@ public class BooleanEditingSupport extends EditingSupport
                super(viewer);
                this.viewer = viewer;
                this.boolClass = (BooleanClassification) definition.getParameterClassification(index);
-               editor = new CheckboxCellEditor(viewer.getTable());
+               editor = new ComboBoxCellEditor(viewer.getTable(), boolClass.getStringValues(), SWT.READ_ONLY);
+               editor.setActivationStyle(
+                               ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_PROGRAMMATIC_ACTIVATION
+                                               | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION);
                this.index = index;
        }
 
@@ -43,7 +48,8 @@ public class BooleanEditingSupport extends EditingSupport
        protected Object getValue(Object element)
        {
                InstructionTableRow row = (InstructionTableRow) element;
-               return row.data.getCell(row.address).getParameter(index).getValue().getMSBit(0).equals(Bit.ONE);
+               // true is 0 because the true value comes first in the combo box
+               return row.data.getCell(row.address).getParameter(index).getValue().getMSBit(0).equals(Bit.ONE) ? 0 : 1;
        }
 
        @Override
@@ -51,7 +57,11 @@ public class BooleanEditingSupport extends EditingSupport
        {
                InstructionTableRow row = (InstructionTableRow) element;
                MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters();
-               params[index] = boolClass.get((Boolean) value);
+               // true is 0 because the true value comes first in the combo box
+               Mnemonic newParam = boolClass.get(value.equals(0) ? true : false);
+               if (newParam.equals(params[index]))
+                       return;
+               params[index] = newParam;
                row.data.setCell(row.address, MicroInstruction.create(params));
                viewer.update(element, null);
        }