projectviewer
Class PVActions

java.lang.Object
  extended byprojectviewer.PVActions

public final class PVActions
extends java.lang.Object

A collection of actions accessible through jEdit's Action mechanism, and other utility methods that may be interesting for interacting with the plugin.

Version:
$Id: PVActions.java 8743 2007-01-24 08:07:10Z vanza $
Author:
Marcelo Vanzin

Constructor Summary
PVActions()
           
 
Method Summary
protected static void cleanup(org.gjt.sp.jedit.PluginJAR jar)
          Used internally to clean up resources when unloading other plugins.
static void closeAllProjectFiles(org.gjt.sp.jedit.View view)
          If a project is currently active, close all its files.
static byte[] decodeBase64(java.lang.String data)
          Decodes a Base64-encoded string into a byte array.
static byte[] encodeBase64(byte[] data)
          Encodes a byte array into a base64-encoded byte array.
static boolean focusActiveBuffer(org.gjt.sp.jedit.View v, VPTNode where)
          Check the current active node in the given view and see if a node representing the current active buffer is a descendant of that node.
static void focusProjectViewer(org.gjt.sp.jedit.View view)
          If a project viewer window is open in the current view, make sure it's visible and them focus the active tree; if it's not open, open it and then focus the active tree.
static VPTProject getCurrentProject(org.gjt.sp.jedit.View view)
          Deprecated. Use ProjectViewer.getActiveProject(View) instead.
static void launchCurrentBuffer(org.gjt.sp.jedit.View view)
          Tries to launch the current buffer in the configured browser for project viewer.
static java.util.Collection listToObjectCollection(java.lang.String list, org.gjt.sp.jedit.PluginJAR jar, java.lang.Class base)
          Creates a collection of instances from a comma-separated list of class names.
static void newFile(org.gjt.sp.jedit.View v)
           
static org.xml.sax.XMLReader newXMLReader(org.xml.sax.helpers.DefaultHandler handler)
          Returns a new SAX 2.0 parser; convenience method that catches all exceptions and prints a log message in case they occur (returning null).
static void openAllProjectFiles(org.gjt.sp.jedit.View view)
          If a project is currently active, open all its files.
static java.util.Collection prune(java.util.Collection c, org.gjt.sp.jedit.PluginJAR jar)
          Iterates through the objects in the given collection, removing any objects that were loaded from the given plugin.
static void pvActionWrapper(Action a, org.gjt.sp.jedit.View v, boolean force)
          Used to execute a PV action from the jEdit action mechanism.
static void removeAllProjectFiles(org.gjt.sp.jedit.View view)
          Removes all the children from the project active in the view.
static void requestFocus(java.awt.Component c)
          Requests the focus for the given component.
static java.lang.String serialize(java.lang.Object o)
           
static void swingInvoke(java.lang.Runnable r)
          Invokes the given runnable in the AWT Event Dispatcher Thread.
static void writeXML(java.lang.String str, java.io.Writer out)
          Writes the given String to the output, taking care to escape any caharcters that need escaping.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PVActions

public PVActions()
Method Detail

openAllProjectFiles

public static void openAllProjectFiles(org.gjt.sp.jedit.View view)
If a project is currently active, open all its files.


closeAllProjectFiles

public static void closeAllProjectFiles(org.gjt.sp.jedit.View view)
If a project is currently active, close all its files.


removeAllProjectFiles

public static void removeAllProjectFiles(org.gjt.sp.jedit.View view)
Removes all the children from the project active in the view.


focusProjectViewer

public static void focusProjectViewer(org.gjt.sp.jedit.View view)
If a project viewer window is open in the current view, make sure it's visible and them focus the active tree; if it's not open, open it and then focus the active tree. If no active tree exists in the dockable, focus will not be explicitly requested (even though the dockable will be opened if it was closed, potentially requesting the focus).

Since:
PV 2.1.0

requestFocus

public static void requestFocus(java.awt.Component c)
Requests the focus for the given component. If the component is not in the active window, then activates the window first, then focus the component.


getCurrentProject

public static VPTProject getCurrentProject(org.gjt.sp.jedit.View view)
Deprecated. Use ProjectViewer.getActiveProject(View) instead.

Returns the active project for the given view.

Returns:
The currently active project, or null if no project is active.

launchCurrentBuffer

public static void launchCurrentBuffer(org.gjt.sp.jedit.View view)
Tries to launch the current buffer in the configured browser for project viewer. Works only if the current buffer has a file that is part of the current active project for the given view.


focusActiveBuffer

public static boolean focusActiveBuffer(org.gjt.sp.jedit.View v,
                                        VPTNode where)
Check the current active node in the given view and see if a node representing the current active buffer is a descendant of that node. If it is, focus that node in the tree, expanding the tree as necessary.

Parameters:
v - The view to ask for the active buffer.
where - Where to look for the node (null will start the search at the active node for the given view).

newFile

public static void newFile(org.gjt.sp.jedit.View v)

pvActionWrapper

public static void pvActionWrapper(Action a,
                                   org.gjt.sp.jedit.View v,
                                   boolean force)

Used to execute a PV action from the jEdit action mechanism. This is meant to be called from beanshell code in the action.xml file. It will check if the action accepts the current selected tree nodes before executing it by using the prepareForNode() method and then checking the visibility of the component returned by getMenuItem(), unless the "force" parameter is set to true. When forcing the execution, no checks are made, so it may be the case that the viewer doesn't exist yet and there's no active project for the current view.

When executing the action, a null is passed as the event in the actionPerformed method, so this won't work for actions that expect a proper event notification.


listToObjectCollection

public static java.util.Collection listToObjectCollection(java.lang.String list,
                                                          org.gjt.sp.jedit.PluginJAR jar,
                                                          java.lang.Class base)
Creates a collection of instances from a comma-separated list of class names. Classes that are not subclasses of "base" will be considered an error and will not be instantiated.

Parameters:
list - Comma-separated list of class names of which to create instances.
jar - The plugin JAR that provides the class loader for the classes.
base - The minimal base class to accept for the created objects.

prune

public static java.util.Collection prune(java.util.Collection c,
                                         org.gjt.sp.jedit.PluginJAR jar)
Iterates through the objects in the given collection, removing any objects that were loaded from the given plugin. This assumes that the objects were loaded by calling the method listToObjectCollection(String,PluginJAR,Class), so that the relationship class -> pluginJAR is registered.

Returns:
A list with the removed objects (may be null).
Since:
PV 2.1.1

cleanup

protected static void cleanup(org.gjt.sp.jedit.PluginJAR jar)
Used internally to clean up resources when unloading other plugins.


writeXML

public static void writeXML(java.lang.String str,
                            java.io.Writer out)
                     throws java.io.IOException
Writes the given String to the output, taking care to escape any caharcters that need escaping.

Throws:
java.io.IOException
Since:
PV 2.1.0

swingInvoke

public static void swingInvoke(java.lang.Runnable r)
Invokes the given runnable in the AWT Event Dispatcher Thread.


newXMLReader

public static org.xml.sax.XMLReader newXMLReader(org.xml.sax.helpers.DefaultHandler handler)
Returns a new SAX 2.0 parser; convenience method that catches all exceptions and prints a log message in case they occur (returning null).

Since:
PV 2.1.3.4

encodeBase64

public static byte[] encodeBase64(byte[] data)
Encodes a byte array into a base64-encoded byte array. For more details about the algorithm, see RFC 3548. This implementation does not create (76-byte) chunks for MIME encoding.

Note by Marcelo Vanzin: I know about Jakarta Commons Codec. In fact, I used it when my first implementation was not working well. But I don't want to add another jar to the plugin, and I don't want to add a dependency on the Jakarta Commons plugin (and add Codec there) either.


decodeBase64

public static byte[] decodeBase64(java.lang.String data)
Decodes a Base64-encoded string into a byte array. Very little error checking is done here - it's not guaranteed that an invalid base64 string will cause errors, since the alphabet is not being checked for the sake of speed.

Throws:
java.lang.IllegalArgumentException - If the string length is not a multiple of 4 (generally, lack of padding).
java.lang.ArrayIndexOutOfBoundsException - If an unrecognized character is found in the stream.

serialize

public static java.lang.String serialize(java.lang.Object o)