X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Ftables%2Fmi%2FActiveInstructionPreviewContentProvider.java;h=7078f9a1b20317adda54dfc1a7c5c8c776e5dd3b;hb=648fc6e69e09fe4467cb6bac47934be1a7dcf0d6;hp=604c2859e094c65d846cf8fe09062b44e5c41b7e;hpb=41292b984ee229deb329c83b525006fd2840becb;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ActiveInstructionPreviewContentProvider.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ActiveInstructionPreviewContentProvider.java index 604c2859..7078f9a1 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ActiveInstructionPreviewContentProvider.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ActiveInstructionPreviewContentProvider.java @@ -3,14 +3,24 @@ package net.mograsim.plugin.tables.mi; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; +import net.mograsim.machine.Machine; +import net.mograsim.machine.Machine.ActiveMicroInstructionChangedListener; import net.mograsim.machine.mi.MicroInstructionMemory; -import net.mograsim.machine.mi.MicroInstructionMemory.ActiveMicroInstructionChangedListener; +import net.mograsim.plugin.util.SingleSWTRequest; -public class ActiveInstructionPreviewContentProvider implements InstructionTableContentProvider, ActiveMicroInstructionChangedListener +public class ActiveInstructionPreviewContentProvider implements InstructionTableContentProvider { private TableViewer viewer; private MicroInstructionMemory memory; private InstructionTableRow activeRow; + private Machine machine; + private SingleSWTRequest requester = new SingleSWTRequest(); + + private ActiveMicroInstructionChangedListener instChanged = (oldAddress, newAddress) -> + { + activeRow = new InstructionTableRow(Long.max(0, newAddress), memory); + requester.request(() -> updateElement(0)); + }; public ActiveInstructionPreviewContentProvider(TableViewer viewer) { @@ -18,13 +28,6 @@ public class ActiveInstructionPreviewContentProvider implements InstructionTable viewer.setItemCount(1); } - @Override - public void activeMicroInstructionChanged(long address) - { - this.activeRow = new InstructionTableRow(address, memory); - viewer.refresh(); - } - @Override public void update(long address) { @@ -34,20 +37,26 @@ public class ActiveInstructionPreviewContentProvider implements InstructionTable @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - if (oldInput != null) - ((MicroInstructionMemory) oldInput).deregisterActiveMicroInstructionChangedListener(this); - memory = (MicroInstructionMemory) newInput; - if (memory != null) + } + + public void setMachine(Machine newMachine) + { + if (machine != null) + machine.removeActiveMicroInstructionChangedListener(instChanged); + + machine = newMachine; + if (machine != null) { - activeMicroInstructionChanged(0); - memory.registerActiveMicroInstructionChangedListener(this); + instChanged.instructionChanged(-1, 0); + machine.addActiveMicroInstructionChangedListener(instChanged); } } @Override public void updateElement(int index) { - viewer.replace(activeRow, index); + if (activeRow != null && !viewer.getControl().isDisposed()) + viewer.replace(activeRow, index); } }