Merge branch 'development' of https://gitlab.lrz.de/lrr-tum/students/eragp-misim...
[Mograsim.git] / net.mograsim.plugin.core / src / net / mograsim / plugin / tables / mi / IntegerEditingSupport.java
1 package net.mograsim.plugin.tables.mi;
2
3 import java.math.BigInteger;
4
5 import org.eclipse.jface.viewers.TableViewer;
6
7 import net.mograsim.machine.mi.MicroInstruction;
8 import net.mograsim.machine.mi.MicroInstructionDefinition;
9 import net.mograsim.machine.mi.parameters.IntegerClassification;
10 import net.mograsim.machine.mi.parameters.IntegerImmediate;
11 import net.mograsim.plugin.tables.NumberCellEditingSupport;
12 import net.mograsim.plugin.tables.memory.DisplaySettings;
13
14 public class IntegerEditingSupport extends NumberCellEditingSupport
15 {
16         private IntegerClassification classification;
17         private int index;
18
19         public IntegerEditingSupport(TableViewer viewer, MicroInstructionDefinition miDef, int index, DisplaySettings displaySettings)
20         {
21                 super(viewer, displaySettings);
22                 classification = (IntegerClassification) miDef.getParameterClassifications()[index];
23                 this.index = index;
24         }
25
26         @Override
27         protected void setAsBigInteger(Object element, BigInteger value)
28         {
29                 ((MicroInstruction) element).setParameter(index, new IntegerImmediate(value, classification.getExpectedBits()));
30         }
31
32         @Override
33         protected BigInteger getAsBigInteger(Object element)
34         {
35                 return ((IntegerImmediate) ((MicroInstruction) element).getParameter(index)).getValueAsBigInteger();
36         }
37
38 }