Added View for micro instruction editor
[Mograsim.git] / net.mograsim.plugin.core / src / net / mograsim / plugin / tables / mi / IntegerEditingSupport.java
diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java
new file mode 100644 (file)
index 0000000..43d6041
--- /dev/null
@@ -0,0 +1,38 @@
+package net.mograsim.plugin.tables.mi;
+
+import java.math.BigInteger;
+
+import org.eclipse.jface.viewers.TableViewer;
+
+import net.mograsim.machine.mi.MicroInstruction;
+import net.mograsim.machine.mi.MicroInstructionDefinition;
+import net.mograsim.machine.mi.parameters.IntegerClassification;
+import net.mograsim.machine.mi.parameters.IntegerImmediate;
+import net.mograsim.plugin.tables.NumberCellEditingSupport;
+import net.mograsim.plugin.tables.memory.DisplaySettings;
+
+public class IntegerEditingSupport extends NumberCellEditingSupport
+{
+       private IntegerClassification classification;
+       private int index;
+
+       public IntegerEditingSupport(TableViewer viewer, MicroInstructionDefinition miDef, int index, DisplaySettings displaySettings)
+       {
+               super(viewer, displaySettings);
+               classification = (IntegerClassification) miDef.getParameterClassifications()[index];
+               this.index = index;
+       }
+
+       @Override
+       protected void setAsBigInteger(Object element, BigInteger value)
+       {
+               ((MicroInstruction) element).setParameter(index, new IntegerImmediate(value, classification.getExpectedBits()));
+       }
+
+       @Override
+       protected BigInteger getAsBigInteger(Object element)
+       {
+               return ((IntegerImmediate) ((MicroInstruction) element).getParameter(index)).getValueAsBigInteger();
+       }
+
+}