PTP
Release 7.0

org.eclipse.ptp.pldt.common.actions
Class AnalysisDropdownHandler

java.lang.Object
  extended by org.eclipse.core.commands.common.EventManager
      extended by org.eclipse.core.commands.AbstractHandler
          extended by org.eclipse.ptp.pldt.common.actions.AnalysisDropdownHandler
All Implemented Interfaces:
java.util.EventListener, org.eclipse.core.commands.IHandler, org.eclipse.core.commands.IHandler2, org.eclipse.ui.ISelectionListener

public class AnalysisDropdownHandler
extends org.eclipse.core.commands.AbstractHandler
implements org.eclipse.ui.ISelectionListener

Default handler for the "Parallel Analysis" toolbar icon command - the work would be done by the menus that get registered (by other plugins) to appear beneath it, but this itself can do something useful by repeating the last-initiated submenu action. ("Do the last thing again") This class also acts as a single point to cache the current structured selection so that when a menu item is selected, the current selection can be accessed. It registers as a selection listener to actively listen for selection changes, instead of relying on HandlerUtil which won't get the first one (e.g. before the plugin is loaded).


Field Summary
protected static AnalysisDropdownHandler instance
           
protected static RunAnalyseHandler lastAnalysisHandler
           
protected static org.eclipse.jface.viewers.IStructuredSelection lastAnalysisSelection
           
protected  org.eclipse.jface.viewers.IStructuredSelection lastSelection
           
 
Constructor Summary
AnalysisDropdownHandler()
          Constructor: set singleton instance, and set up selection listener to listen for selections so we can report them more efficiently than relying on HandlerUtil.getCurrentSelection(); if the current selection isn't a structured selection (e.g. editor selection or something we don't care about) then we want the last structured selection.
 
Method Summary
 java.lang.Object execute(org.eclipse.core.commands.ExecutionEvent event)
           
static AnalysisDropdownHandler getInstance()
          Get the singleton instance of this class, probably for accessing its knowledge about the current/last selection of interest.
static org.eclipse.jface.viewers.IStructuredSelection getLastAnalysisSelection()
          For repeat analysis (clicking on the icon in the toolbar) returns the previous selection so that it can be reused
 org.eclipse.jface.viewers.IStructuredSelection getLastSelection()
          The last structured selection seen (e.g. selection of a file, folder, or project within the Project Explorer)
 void selectionChanged(org.eclipse.ui.IWorkbenchPart part, org.eclipse.jface.viewers.ISelection selection)
          Implemented for SelectionListener interface: Listen for selection changes and cache the ones that might be interesting to us.
static void setLastHandledAnalysis(RunAnalyseHandler handler, org.eclipse.jface.viewers.IStructuredSelection selection)
          Remember what was last executed, so that we can give a repeat performance
 
Methods inherited from class org.eclipse.core.commands.AbstractHandler
addHandlerListener, dispose, fireHandlerChanged, hasListeners, isEnabled, isHandled, removeHandlerListener, setBaseEnabled, setEnabled
 
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastAnalysisHandler

protected static RunAnalyseHandler lastAnalysisHandler

lastAnalysisSelection

protected static org.eclipse.jface.viewers.IStructuredSelection lastAnalysisSelection

lastSelection

protected org.eclipse.jface.viewers.IStructuredSelection lastSelection

instance

protected static AnalysisDropdownHandler instance
Constructor Detail

AnalysisDropdownHandler

public AnalysisDropdownHandler()
Constructor: set singleton instance, and set up selection listener to listen for selections so we can report them more efficiently than relying on HandlerUtil.getCurrentSelection(); if the current selection isn't a structured selection (e.g. editor selection or something we don't care about) then we want the last structured selection. If we can't find a structured selection at the time this ctor is called, go get the selection in the Project Explorer; it's probably what we want (for the case when an editor has just been opened by double-clicking on its entry in the project explorer: it's still selected in the Proj explorer, but the editor now has the focus).

Method Detail

execute

public java.lang.Object execute(org.eclipse.core.commands.ExecutionEvent event)
                         throws org.eclipse.core.commands.ExecutionException
Specified by:
execute in interface org.eclipse.core.commands.IHandler
Throws:
org.eclipse.core.commands.ExecutionException

setLastHandledAnalysis

public static void setLastHandledAnalysis(RunAnalyseHandler handler,
                                          org.eclipse.jface.viewers.IStructuredSelection selection)
Remember what was last executed, so that we can give a repeat performance

Parameters:
handler -
selection - - cache the selection too; this will be used as a last resort if another analysis doesn't see a recent selection it likes.

getLastAnalysisSelection

public static org.eclipse.jface.viewers.IStructuredSelection getLastAnalysisSelection()
For repeat analysis (clicking on the icon in the toolbar) returns the previous selection so that it can be reused

Returns:

selectionChanged

public void selectionChanged(org.eclipse.ui.IWorkbenchPart part,
                             org.eclipse.jface.viewers.ISelection selection)
Implemented for SelectionListener interface: Listen for selection changes and cache the ones that might be interesting to us.

Specified by:
selectionChanged in interface org.eclipse.ui.ISelectionListener

getLastSelection

public org.eclipse.jface.viewers.IStructuredSelection getLastSelection()
The last structured selection seen (e.g. selection of a file, folder, or project within the Project Explorer)

Returns:

getInstance

public static AnalysisDropdownHandler getInstance()
Get the singleton instance of this class, probably for accessing its knowledge about the current/last selection of interest.

Returns:

PTP
Release 7.0

Copyright (c) 2011 IBM Corporation and others. All Rights Reserved.