From e2f36a0166c4843c4a5d79e23ee52cb0a6010896 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Thu, 26 Sep 2019 11:29:06 +0200 Subject: [PATCH] InstructionView now reacts to memory reassignments and machine changes --- .../plugin/tables/mi/InstructionView.java | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java index 10d2f4db..235e3e53 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java @@ -19,6 +19,7 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.EditorPart; import net.mograsim.machine.Memory.MemoryCellModifiedListener; +import net.mograsim.machine.mi.AssignableMicroInstructionMemory.MIMemoryReassignedListener; import net.mograsim.machine.mi.MicroInstructionMemory; import net.mograsim.machine.mi.MicroInstructionMemory.ActiveMicroInstructionChangedListener; import net.mograsim.machine.mi.MicroInstructionMemoryParseException; @@ -67,9 +68,13 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis LazyTableViewer viewer = table.getTableViewer(); viewer.highlightRow(highlighted, false); highlighted = index; - viewer.highlightRow(index, true); - viewer.getTable().showItem(viewer.getTable().getItem(Math.min((int) memory.getDefinition().getMaximalAddress(), index + 2))); - viewer.getTable().showItem(viewer.getTable().getItem(index)); + if (index != -1) + { + viewer.highlightRow(index, true); + viewer.getTable() + .showItem(viewer.getTable().getItem(Math.min((int) memory.getDefinition().getMaximalAddress(), index + 2))); + viewer.getTable().showItem(viewer.getTable().getItem(index)); + } }); } @@ -77,8 +82,26 @@ public class InstructionView extends EditorPart implements MemoryCellModifiedLis { Button activationButton = new Button(parent, SWT.PUSH); activationButton.setText("Set Active"); - activationButton.addListener(SWT.Selection, - e -> context.getActiveMachine().ifPresent(m -> m.getMicroInstructionMemory().bind(memory))); + activationButton.addListener(SWT.Selection, e -> context.getActiveMachine().ifPresent(m -> + { + // clear highlighting if the memory is reassigned + MIMemoryReassignedListener memReassignedListener = n -> + { + if (n != memory) + highlight(-1); + }; + m.getMicroInstructionMemory().registerMemoryReassignedListener(memReassignedListener); + // clear highlighting if the active machine changes + context.addActiveMachineListener(n -> + { + if (n.isEmpty() || n.get() != m) + { + highlight(-1); + m.getMicroInstructionMemory().deregisterMemoryReassignedListener(memReassignedListener); + } + }); + m.getMicroInstructionMemory().bind(memory); + })); } public void bindMicroInstructionMemory(MicroInstructionMemory memory) -- 2.17.1