Added View for micro instruction editor
[Mograsim.git] / net.mograsim.plugin.core / src / net / mograsim / plugin / tables / mi / MnemonicCellEditorValidator.java
diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicCellEditorValidator.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicCellEditorValidator.java
new file mode 100644 (file)
index 0000000..98181c4
--- /dev/null
@@ -0,0 +1,24 @@
+package net.mograsim.plugin.tables.mi;
+
+import org.eclipse.jface.viewers.ICellEditorValidator;
+
+import net.mograsim.machine.mi.parameters.MnemonicFamily;
+
+public class MnemonicCellEditorValidator implements ICellEditorValidator
+{
+       private MnemonicFamily family;
+
+       public MnemonicCellEditorValidator(MnemonicFamily family)
+       {
+               this.family = family;
+       }
+
+       @Override
+       public String isValid(Object value)
+       {
+               int index = (Integer) value;
+               return index >= 0 && index < family.size() ? null
+                               : String.format("MnemonicFamily has %s elements, index %s is out of bounds", family.size(), value.toString());
+       }
+
+}