Class JythonManager

All Implemented Interfaces:
ActionListener, EventListener, IdvConstants

public class JythonManager extends IdvManager implements ActionListener
Manages jython related functionality:
Author:
IDV development team
  • Field Details

  • Constructor Details

    • JythonManager

      public JythonManager(IntegratedDataViewer idv)
      Create the manager and call initPython.
      Parameters:
      idv - The IDV
  • Method Details

    • showJythonEditor

      public void showJythonEditor()
      Create, if needed, and show the jython editor.
    • exportSelectedToPlugin

      public void exportSelectedToPlugin()
      Export selcted text of current tab to plugin
    • exportToPlugin

      public void exportToPlugin()
      Export to plugin
    • doMakeContents

      protected JComponent doMakeContents()
      Create the jython editor. We create a tree panel that holds each valid jython library defined in the IDV's resource manager.
      Overrides:
      doMakeContents in class WindowHolder
      Returns:
      The gui contents
    • saveOnExit

      public boolean saveOnExit()
      Save on exit if anything is changed
      Returns:
      continue with exit
    • makeFormula

      public void makeFormula(org.python.core.PyFunction func)
      Make a formula
      Parameters:
      func - function
    • makeNewLibrary

      public void makeNewLibrary()
      make new library
    • getLibHolders

      public List getLibHolders()
      the libs
      Returns:
      the libs
    • removeLibrary

      public void removeLibrary(JythonManager.LibHolder holder)
      remove lib
      Parameters:
      holder - lib
    • makeFileMenu

      public void makeFileMenu(JMenu fileMenu)
      make men
      Parameters:
      fileMenu - menu
    • applicationClosing

      protected void applicationClosing()
      Gets called when the IDV is quitting. Kills the editor process if there is one
    • editInExternalEditor

      public void editInExternalEditor()
      Edit the jython in the external editor
    • editInExternalEditorInner

      public void editInExternalEditorInner(JythonManager.LibHolder holder)
      Edit the jython in the external editor
      Parameters:
      holder - lib
    • getWindowTitle

      public String getWindowTitle()
      Get the window titlexxx
      Overrides:
      getWindowTitle in class WindowHolder
      Returns:
      window title
    • showHelp

      public void showHelp()
      SHow help
    • showHelp

      public void showHelp(String help)
      show the help
      Parameters:
      help - the help id
    • createInterpreter

      public org.python.util.PythonInterpreter createInterpreter()
      Factory method to create and interpreter. This also adds the interpreter into the list of interpreters.
      Returns:
      The new interpreter
    • createShell

      public JythonShell createShell()
      Create a jython shell
      Returns:
      shell
    • removeInterpreter

      public void removeInterpreter(org.python.util.PythonInterpreter interp)
      Remove the interpreter from the list of interpreters.
      Parameters:
      interp - The interpreter to remove
    • getInError

      public boolean getInError()
      Any errors
      Returns:
      in error
    • getUsersJythonText

      public String getUsersJythonText()
      Get the end user edited text from the jython editor.
      Returns:
      The end user jython code
    • appendTmpJython

      public void appendTmpJython(String jython)
      Append the given jython to the temp jython
      Parameters:
      jython - The jython from the bundle
    • appendJythonFromBundle

      public void appendJythonFromBundle(String jython)
      Append the given jython to that is from a bundle to the users jython
      Parameters:
      jython - The jython from the bundle
    • appendJython

      public void appendJython(String jython)
      APpend jython to main editable lib
      Parameters:
      jython - jython
    • writeJythonLib

      public boolean writeJythonLib(JythonManager.LibHolder holder)
      Save the end user jython code from the jython editor into the user's .unidata/idv area.
      Parameters:
      holder - lib
      Returns:
      success
    • checkUntrustedJython

      protected static boolean checkUntrustedJython(String jython)
      Make sure the given jython code matches the pattern (after removing whitespace): idv.procedure_name ('arg1', arg2, ..., argn) where if an arg is not in single quotes it cannot contain a procedure call.

      We have this here so (hopefully) a user won't inadvertently execute rogue jython code on their machine.

      Parameters:
      jython - The code
      Returns:
      Does the code just call into idv or datamanager methods.
    • evaluateUntrusted

      public void evaluateUntrusted(String jythonCode)
      Evaluate the given jython code. This code is untrusted and has to be of the form (idv|datamanager).some_method (param1, param2, ..., paramN);
      Parameters:
      jythonCode - The code to execute
    • evaluateUntrusted

      public void evaluateUntrusted(String jythonCode, Hashtable properties)
      Evaluate the given jython code. This code is untrusted and has to be of the form (idv|datamanager).some_method (param1, param2, ..., paramN);
      Parameters:
      jythonCode - The code to execute
      properties - If non-null then populate the interpreter with the name/value pairs
    • evaluateTrusted

      public void evaluateTrusted(String code)
      Interpret the given jython code. This code is trusted, i.e., it is not checked to make sure it is only calling idv or datamanager methods.
      Parameters:
      code - The code toe evaluate
    • evaluateTrusted

      public void evaluateTrusted(String code, Hashtable properties)
      Interpret the given jython code. This code is trusted, i.e., it is not checked to make sure it is only calling idv or datamanager methods.
      Parameters:
      code - The code toe evaluate
      properties - If non-null then populate the interpreter with the name/value pairs
    • dataGroupsChanged

      public void dataGroupsChanged()
      Update derived needs when the DataGroups change
    • initUserFormulas

      protected void initUserFormulas(IdvResourceManager newIrm)
      Initialize the DerivedDataDescriptors that are defined in the RSC_DERIVED resource collection from the given resource manager.
      Parameters:
      newIrm - The resource manager to get the derived resources from
    • selectFormulas

      protected List selectFormulas()
      Popup dialog to select formulas
      Returns:
      List of selected formulas
    • exportFormulasToPlugin

      public void exportFormulasToPlugin()
      Export selected formulas to plugin
    • exportFormulas

      public void exportFormulas()
      Export user formulas
    • importFormulas

      public void importFormulas()
      Import user formulas
    • writeUserFormulas

      protected void writeUserFormulas()
      Save the user created formulas.
    • doMakeDataChoiceMenuItems

      public void doMakeDataChoiceMenuItems(DataChoice dataChoice, List items)
      Create the list of menu items for editing a data choice that represents an end user formula.
      Parameters:
      dataChoice - The end user formula data choice
      items - List of menu items to add to
    • deleteKeyPressed

      public void deleteKeyPressed(DataChoice dataChoice)
      Delete the data choice if it is a user formula
      Parameters:
      dataChoice - The data choice to delete
    • evaluateDataChoice

      public void evaluateDataChoice(DataChoice dataChoice)
      This simply clones the given data choice and calls getData on it. We have this here so the user can explicitly, through the GUI, evaluate a formula data choice. This way they don't have to create a display to simply evaluate a formula.
      Parameters:
      dataChoice - The data chocie to evaluate
    • removeFormula

      public void removeFormula(DerivedDataChoice dataChoice)
      Remove a formula from the IDV. You can only remove end user formulas that are in the editable list.
      Parameters:
      dataChoice - formula data choice
    • removeFormula

      public void removeFormula(DerivedDataDescriptor ddd)
      remove formula
      Parameters:
      ddd - ddd
    • descriptorChanged

      public void descriptorChanged(DerivedDataDescriptor ddd)
      Called when a formula data choice has changed (i.e., added, removed or edited.
      Parameters:
      ddd - descriptor for the formula.
    • addFormula

      public void addFormula(DerivedDataDescriptor ddd)
      Add a formula to the IDV.
      Parameters:
      ddd - formula descriptor
    • doMakeFormulaDataSourceMenuItems

      public List doMakeFormulaDataSourceMenuItems(DataSource dataSource)
      Return the list of menu items to use when the user has clicked on a formula DataSource.
      Parameters:
      dataSource - The data source clicked on
      Returns:
      List of menu items
    • doMakeEditMenuItems

      public List doMakeEditMenuItems()
      make the edit menu items for the formula data source
      Returns:
      List of menu items
    • doMakeEditMenuItems

      public List doMakeEditMenuItems(DescriptorDataSource dds)
      make the edit menu items for the given formula data source
      Parameters:
      dds - The formula data source
      Returns:
      List of menu items
    • showFormulaDialog

      public void showFormulaDialog()
      Show the formula dialog with no initial state. We do this to create a new formula.
    • getDescriptors

      public List getDescriptors()
      get formula descriptors
      Returns:
      descriptors
    • getEndUserDescriptors

      public List getEndUserDescriptors()
      Get all end user formulas
      Returns:
      end user formulas
    • getLocalDescriptors

      public List getLocalDescriptors()
      Get all local descriptors
      Returns:
      local descriptors
    • getDefaultDescriptors

      public List getDefaultDescriptors()
      Get all end user formulas
      Returns:
      end user formulas
    • showFormulaDialog

      public void showFormulaDialog(DerivedDataDescriptor descriptor)
      Show formula dialog with the given initial DDD.
      Parameters:
      descriptor - The descriptor for the formula.
    • showFormulaDialog

      public void showFormulaDialog(DerivedDataDescriptor descriptor, boolean isNew)
      show the formula dialog
      Parameters:
      descriptor - the formula
      isNew - is this a new one or are we just changing it
    • getDescriptorDataSource

      public DescriptorDataSource getDescriptorDataSource()
      Get the descriptor data source
      Returns:
      The descriptor data source
    • getDerivedDataInterpreter

      public org.python.util.PythonInterpreter getDerivedDataInterpreter()
      Create a (singleton) jython interpreter and initialize it with the set of classes defined in the xml
      Returns:
      The singleton Jython interpreter for derived data execution
    • getDerivedDataInterpreter

      public org.python.util.PythonInterpreter getDerivedDataInterpreter(String methodName)
      Create a (singleton) jython interpreter and initialize it with the set of classes defined in the xml and (if needed) with the class path represented by the methodName argument (if methodName is of the form: some.package.path.SomeClass.someMethod).
      Parameters:
      methodName - Used to initialize the interpreter (if non -null)
      Returns:
      The singleton Jython interpreter for derived data execution
    • makeProcedureMenu

      public List makeProcedureMenu(Object object, String method, String prefix)
      Make menu
      Parameters:
      object - object to call
      method - method to call
      prefix - prefic
      Returns:
      menus
    • findJythonMethods

      public List findJythonMethods(boolean justList)
      find methods
      Parameters:
      justList - If true just the functions
      Returns:
      A list of Object arrays. First element in array is the name of the lib. Second is the list of PyFunction-s
    • findJythonMethods

      public List findJythonMethods(boolean justList, List holders)
      find methods
      Parameters:
      justList - If true just the function
      holders - libs
      Returns:
      A list of Object arrays. First element in array is the name of the lib. Second is the list of PyFunction-s
    • main

      public static void main(String[] args) throws Exception
      main
      Parameters:
      args - args
      Throws:
      Exception - on badness