From: Daniel Kirschten Date: Sat, 5 Oct 2019 21:08:21 +0000 (+0200) Subject: Merge branch threads into development X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=2d1f3e4780616f3b638133a243fcdb7a6738baf9;p=Mograsim.git Merge branch threads into development --- 2d1f3e4780616f3b638133a243fcdb7a6738baf9 diff --cc plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineDebugContextListener.java index d8ea3993,00000000..837da0ae mode 100644,000000..100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineDebugContextListener.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineDebugContextListener.java @@@ -1,61 -1,0 +1,60 @@@ +package net.mograsim.plugin.launch; + +import java.util.Optional; + +import org.eclipse.debug.core.ILaunch; ++import org.eclipse.debug.core.model.IDebugElement; +import org.eclipse.debug.core.model.IDebugTarget; +import org.eclipse.debug.ui.contexts.DebugContextEvent; +import org.eclipse.debug.ui.contexts.IDebugContextListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.TreeSelection; + +public abstract class MachineDebugContextListener implements IDebugContextListener +{ + private MachineDebugTarget debugTarget; + + @Override + public void debugContextChanged(DebugContextEvent e) + { + debugContextChanged(e.getContext()); + } + + public void debugContextChanged(ISelection selection) + { + if (selection != null && selection instanceof TreeSelection) + { + TreeSelection treeSelection = (TreeSelection) selection; + Object[] selectedElements = treeSelection.toArray(); + for (Object selectedElement : selectedElements) + { - MachineDebugTarget debugTarget; - if (selectedElement instanceof MachineDebugTarget) - debugTarget = (MachineDebugTarget) selectedElement; ++ IDebugTarget debugTarget; ++ if (selectedElement instanceof IDebugElement) ++ debugTarget = ((IDebugElement) selectedElement).getDebugTarget(); + else if (selectedElement instanceof ILaunch) - { - ILaunch launch = (ILaunch) selectedElement; - IDebugTarget genericDebugTarget = launch.getDebugTarget(); - if (genericDebugTarget instanceof MachineDebugTarget) - debugTarget = (MachineDebugTarget) genericDebugTarget; - else - continue; - } else ++ debugTarget = ((ILaunch) selectedElement).getDebugTarget(); ++ else ++ continue; ++ if (!(debugTarget instanceof MachineDebugTarget)) + continue; + if (debugTarget.isTerminated()) + continue; + // we found a selected MachineDebugTarget + if (this.debugTarget != debugTarget) - { - MachineDebugTarget oldTarget = this.debugTarget; - this.debugTarget = debugTarget; - machineDebugContextChanged(Optional.ofNullable(oldTarget), Optional.of(debugTarget)); - } ++ updateContextAndCallContextChanged((MachineDebugTarget) debugTarget); + return; + } - MachineDebugTarget oldTarget = debugTarget; - debugTarget = null; - machineDebugContextChanged(Optional.ofNullable(oldTarget), Optional.empty()); + } ++ // we didn't find a selected MachineDebugTarget ++ updateContextAndCallContextChanged(null); ++ } ++ ++ private void updateContextAndCallContextChanged(MachineDebugTarget newTarget) ++ { ++ MachineDebugTarget oldTarget = this.debugTarget; ++ this.debugTarget = newTarget; ++ machineDebugContextChanged(Optional.ofNullable(oldTarget), Optional.ofNullable(newTarget)); + } + + public abstract void machineDebugContextChanged(Optional oldTarget, Optional newTarget); +} diff --cc plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java index 9f9f60b4,12126616..a8fcfd7c --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java @@@ -181,11 -176,34 +181,10 @@@ public class SimulationView extends Vie instPreview.setContentProvider(contentProvider); } - private void debugContextChanged(ISelection selection) + private void debugContextChanged(Optional newTarget) { - // if we didn't find a selected MachineDebugTarget - if (selection != null && selection instanceof TreeSelection) - { - TreeSelection treeSelection = (TreeSelection) selection; - Object[] selectedElements = treeSelection.toArray(); - for (Object selectedElement : selectedElements) - { - IDebugTarget debugTarget; - if (selectedElement instanceof IDebugElement) - debugTarget = ((IDebugElement) selectedElement).getDebugTarget(); - else if (selectedElement instanceof ILaunch) - debugTarget = ((ILaunch) selectedElement).getDebugTarget(); - else - continue; - if (!(debugTarget instanceof MachineDebugTarget)) - continue; - if (debugTarget.isTerminated()) - continue; - // we found a selected MachineDebugTarget - if (this.debugTarget != debugTarget) - bindToDebugTarget((MachineDebugTarget) debugTarget); - return; - } - } - // we didn't find a selected MachineDebugTarget -- // call binToDebugTarget even if this.debugTarget==null - bindToDebugTarget(null); ++ // call binToDebugTarget even if we didn't find a selected MachineDebugTarget + bindToDebugTarget(newTarget.orElse(null)); } private void bindToDebugTarget(MachineDebugTarget debugTarget)