Added active instruction preview to LogicUIPart
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / tables / mi / ActiveInstructionPreviewContentProvider.java
1 package net.mograsim.plugin.tables.mi;
2
3 import org.eclipse.jface.viewers.TableViewer;
4 import org.eclipse.jface.viewers.Viewer;
5
6 import net.mograsim.machine.mi.MicroInstructionMemory;
7 import net.mograsim.machine.mi.MicroInstructionMemory.ActiveMicroInstructionChangedListener;
8
9 public class ActiveInstructionPreviewContentProvider implements InstructionTableContentProvider, ActiveMicroInstructionChangedListener
10 {
11         private TableViewer viewer;
12         private MicroInstructionMemory memory;
13         private InstructionTableRow activeRow;
14
15         public ActiveInstructionPreviewContentProvider(TableViewer viewer)
16         {
17                 this.viewer = viewer;
18                 viewer.setItemCount(1);
19         }
20
21         @Override
22         public void activeMicroInstructionChanged(long address)
23         {
24                 this.activeRow = new InstructionTableRow(address, memory);
25                 viewer.refresh();
26         }
27
28         @Override
29         public void update(long address)
30         {
31                 // Nothing to do here
32         }
33
34         @Override
35         public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
36         {
37                 if (oldInput != null)
38                         ((MicroInstructionMemory) oldInput).deregisterActiveMicroInstructionChangedListener(this);
39
40                 memory = (MicroInstructionMemory) newInput;
41                 if (memory != null)
42                 {
43                         activeMicroInstructionChanged(0);
44                         memory.registerActiveMicroInstructionChangedListener(this);
45                 }
46         }
47
48         @Override
49         public void updateElement(int index)
50         {
51                 viewer.replace(activeRow, index);
52         }
53 }