projectviewer
Class PVActions

java.lang.Object
  extended by projectviewer.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.

Part of Project Viewer api should not be used from outside Project Viewer, although it is public in java sense. Some methods are considered internal and their public signature comes only from the layout of packages. Many of those methods have javadoc remarks, that forbids outside usage. But there may still be a lot of methods, which are not marked, but it's better not to use them. Improper usage of those methods may lead to data corruption or application failures. From the other side they may change and break other plugins. To be safe it's best to limit the public api to the following list:

Public api

Probably this list is not complete. If you would like to use some api but are not sure, please ask on jedit-devel. It you think some api is missing, please also let us know about it.

Author:
Marcelo Vanzin

Constructor Summary
PVActions()
           
 
Method Summary
static void addCurrentBuffer(org.gjt.sp.jedit.View v)
           
static java.lang.String clipText(java.lang.String base, int maxWidth, java.awt.FontMetrics metrics, boolean clipEnd)
          Returns a string that fits in the given bounds based on the given metrics.
static void closeAllProjectFiles(org.gjt.sp.jedit.View view)
          If a project is currently active, close all its files.
static VPTProject createProject(VPTGroup parent)
          Opens project creation dialog.
static VPTProject createProject(VPTGroup parent, int flags)
          Opens project creation dialog, like in "Add project" action, but it does not depend on currently selected node.
static VPTProject createProject(VPTProject proj, VPTGroup parent, int flags)
          Opens project creation dialog, like in "Add project" action, but it does not depend on currently selected node.
static void editCurrentProject(org.gjt.sp.jedit.View v, java.lang.String startupPane)
          Opens project properties pane for the active project or for the project pointed by the selected node.
static void editProject(VPTProject proj, java.lang.String startupPane)
          Opens project properties pane for a given project.
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 void launchCurrentBuffer(org.gjt.sp.jedit.View view)
          Tries to launch the current buffer in the configured browser for project viewer.
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 void openParentGroup(org.gjt.sp.jedit.View v)
           
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 void searchInProject(org.gjt.sp.jedit.View view)
           
static void setActiveFromSelectedNode(org.gjt.sp.jedit.View v)
           
static java.lang.String stripSeparator(java.lang.String path)
          Strips the trailing file separator from a path, if it exists.
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.


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)

setActiveFromSelectedNode

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

openParentGroup

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

addCurrentBuffer

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

editCurrentProject

public static void editCurrentProject(org.gjt.sp.jedit.View v,
                                      java.lang.String startupPane)
Opens project properties pane for the active project or for the project pointed by the selected node.

Parameters:
startupPane - The name of the pane is declared in OptionPane's constructor, for example "projectviewer.auto_reimport_props". Possible null.
Since:
3.4.2

editProject

public static void editProject(VPTProject proj,
                               java.lang.String startupPane)
Opens project properties pane for a given project.

Parameters:
startupPane - The name of the pane is declared in OptionPane's constructor, for example "projectviewer.auto_reimport_props". Possible null.
Since:
3.4.2

createProject

public static VPTProject createProject(VPTProject proj,
                                       VPTGroup parent,
                                       int flags)
Opens project creation dialog, like in "Add project" action, but it does not depend on currently selected node.

Parameters:
proj - A new VPTProject object, with some fields set by the caller. May be null.
parent - A parent group. If null, root node assumed.
flags - AddProjectAction.NO_IMPORT or AddProjectAction.NO_FLAGS
Returns:
null if user cancelled the dialog.
Since:
3.4.2

createProject

public static VPTProject createProject(VPTGroup parent,
                                       int flags)
Opens project creation dialog, like in "Add project" action, but it does not depend on currently selected node.

Parameters:
parent - A parent group. If null, root node assumed.
flags - AddProjectAction.NO_IMPORT or AddProjectAction.NO_FLAGS
Returns:
null if user cancelled the dialog.
Since:
3.4.2

createProject

public static VPTProject createProject(VPTGroup parent)
Opens project creation dialog. Same as createProject(VPTGroup, int), but with no flags.

Since:
3.4.2

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.


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

clipText

public static java.lang.String clipText(java.lang.String base,
                                        int maxWidth,
                                        java.awt.FontMetrics metrics,
                                        boolean clipEnd)
Returns a string that fits in the given bounds based on the given metrics. If the given string doesn't fit, it will be clipped either at the start or the end, being prepended or appended with an ellipsis to signal the clipping.

Parameters:
base - The base string.
maxWidth - Width within which the string should fit.
metrics - Font metrics to use.
clipEnd - true if should clip the end of the string.
Returns:
A clipped version of the base string, or the base one if it fits.
Since:
PV 3.0.0

searchInProject

public static void searchInProject(org.gjt.sp.jedit.View view)

stripSeparator

public static java.lang.String stripSeparator(java.lang.String path)
Strips the trailing file separator from a path, if it exists.

Parameters:
path - The path.
Returns:
The path without a trailing file separator.
Since:
PV 3.0.1