1 package net.mograsim.plugin.tables.memory;
3 import org.eclipse.jface.viewers.ILazyContentProvider;
4 import org.eclipse.jface.viewers.TableViewer;
5 import org.eclipse.jface.viewers.Viewer;
6 import org.eclipse.swt.widgets.Display;
8 import net.mograsim.machine.MainMemory;
9 import net.mograsim.machine.MemoryObserver;
11 public class MemoryTableContentProvider implements ILazyContentProvider, MemoryObserver
14 private TableViewer viewer;
15 private final static int limit = 10_000;
16 private int amount = 0;
17 private MainMemory memory;
19 public void setLowerBound(long lower)
22 this.lower = Long.min(memory.getDefinition().getMaximalAddress(), Long.max(memory.getDefinition().getMinimalAddress(), lower));
28 public void updateItemCount()
32 long size = memory.getDefinition().getMaximalAddress() - lower;
33 viewer.setItemCount(size > amount ? amount : (int) size);
35 viewer.setItemCount(0);
38 public long getLowerBound()
43 public void setAmount(int amount)
45 this.amount = Integer.min(amount, limit);
49 public int getAmount()
55 public void updateElement(int index)
57 long address = lower + index;
58 if (address <= memory.getDefinition().getMaximalAddress())
59 viewer.replace(new MemoryTableRow(address, memory), index);
63 public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
65 this.viewer = (TableViewer) viewer;
66 this.memory = (MainMemory) newInput;
68 ((MainMemory) oldInput).deregisterObserver(this);
70 memory.registerObserver(this);
75 public void update(long address)
77 Display.getDefault().asyncExec(() -> updateElement((int) (address - lower)));