X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Ftables%2Fmi%2FRowHighlighter.java;h=e7435a20a46dbbf5ad3aafc794d513dbd1b7dc31;hb=2d1f3e4780616f3b638133a243fcdb7a6738baf9;hp=18e010849884b141f67cc0b8574a590ee1d5ec7c;hpb=ae2d1ae853d5232df4337e4b2c417a9d57e11aa7;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java index 18e01084..e7435a20 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/RowHighlighter.java @@ -1,54 +1,46 @@ package net.mograsim.plugin.tables.mi; -import java.util.concurrent.atomic.AtomicBoolean; +import java.util.Optional; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Table; import net.mograsim.plugin.tables.LazyTableViewer; +import net.mograsim.plugin.util.SingleSWTRequest; public class RowHighlighter { - private int highlighted, toHighlight; + private int highlighted = -1; private LazyTableViewer viewer; - private AtomicBoolean waiting = new AtomicBoolean(); + private FontAndColorHelper cProv; + private SingleSWTRequest requester = new SingleSWTRequest(); - public RowHighlighter(LazyTableViewer viewer) + public RowHighlighter(LazyTableViewer viewer, FontAndColorHelper cProv) { this.viewer = viewer; + this.cProv = cProv; } public void highlight(int row) { - synchronized (waiting) + requester.request(() -> { - toHighlight = row; - if (!waiting.get()) - { - waiting.set(true); - Display.getDefault().asyncExec(() -> - { - synchronized (waiting) - { - waiting.set(false); - if (!viewer.getTable().isDisposed()) - innerHighlight(toHighlight); - } - }); - } - } + if (!viewer.getTable().isDisposed()) + innerHighlight(row); + }); } private void innerHighlight(int row) { - viewer.highlightRow(highlighted, false); - highlighted = row; + Table table = viewer.getTable(); + cProv.highlight(row); if (row != -1) { - viewer.highlightRow(row, true); - Table table = viewer.getTable(); table.showItem(table.getItem(Math.min(table.getItemCount(), row + 2))); table.showItem(table.getItem(row)); + Optional.ofNullable(table.getItem(row).getData()).ifPresent(d -> viewer.update(d, null)); } + if (highlighted != -1) + Optional.ofNullable(table.getItem(highlighted).getData()).ifPresent(d -> viewer.update(d, null)); + highlighted = row; } }