Merge branch threads into development
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 5 Oct 2019 21:08:21 +0000 (23:08 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 5 Oct 2019 21:08:21 +0000 (23:08 +0200)
1  2 
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineDebugContextListener.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineDebugTarget.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/views/SimulationView.java

index d8ea399,0000000..837da0a
mode 100644,000000..100644
--- /dev/null
@@@ -1,61 -1,0 +1,60 @@@
-                               MachineDebugTarget debugTarget;
-                               if (selectedElement instanceof MachineDebugTarget)
-                                       debugTarget = (MachineDebugTarget) selectedElement;
 +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)
 +                      {
-                               {
-                                       ILaunch launch = (ILaunch) selectedElement;
-                                       IDebugTarget genericDebugTarget = launch.getDebugTarget();
-                                       if (genericDebugTarget instanceof MachineDebugTarget)
-                                               debugTarget = (MachineDebugTarget) genericDebugTarget;
-                                       else
-                                               continue;
-                               } else
++                              IDebugTarget debugTarget;
++                              if (selectedElement instanceof IDebugElement)
++                                      debugTarget = ((IDebugElement) selectedElement).getDebugTarget();
 +                              else if (selectedElement instanceof ILaunch)
-                               {
-                                       MachineDebugTarget oldTarget = this.debugTarget;
-                                       this.debugTarget = debugTarget;
-                                       machineDebugContextChanged(Optional.ofNullable(oldTarget), Optional.of(debugTarget));
-                               }
++                                      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 = debugTarget;
-                       debugTarget = null;
-                       machineDebugContextChanged(Optional.ofNullable(oldTarget), Optional.empty());
++                                      updateContextAndCallContextChanged((MachineDebugTarget) debugTarget);
 +                              return;
 +                      }
 +              }
++              // 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<MachineDebugTarget> oldTarget, Optional<MachineDebugTarget> newTarget);
 +}
@@@ -181,11 -176,34 +181,10 @@@ public class SimulationView extends Vie
                instPreview.setContentProvider(contentProvider);
        }
  
 -      private void debugContextChanged(ISelection selection)
 +      private void debugContextChanged(Optional<MachineDebugTarget> 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)