IssueZilla 10518 - Add BeanShell support
Added a clone method to ScriptEntry Updated the MethodPanel to search for scripts based on language Added bsh files to the BinaryOnlyFilter
This commit is contained in:
@@ -2,9 +2,9 @@
|
|||||||
*
|
*
|
||||||
* $RCSfile: BinaryOnlyFilter.java,v $
|
* $RCSfile: BinaryOnlyFilter.java,v $
|
||||||
*
|
*
|
||||||
* $Revision: 1.2 $
|
* $Revision: 1.3 $
|
||||||
*
|
*
|
||||||
* last change: $Author: toconnor $ $Date: 2002-11-13 17:44:08 $
|
* last change: $Author: toconnor $ $Date: 2003-01-16 17:47:56 $
|
||||||
*
|
*
|
||||||
* The Contents of this file are made available subject to the terms of
|
* The Contents of this file are made available subject to the terms of
|
||||||
* either of the following licenses
|
* either of the following licenses
|
||||||
@@ -62,8 +62,8 @@
|
|||||||
package org.openoffice.idesupport.filter;
|
package org.openoffice.idesupport.filter;
|
||||||
|
|
||||||
public class BinaryOnlyFilter implements FileFilter {
|
public class BinaryOnlyFilter implements FileFilter {
|
||||||
private static final String[] EXTENSIONS = {".class", ".jar"};
|
private static final String[] EXTENSIONS = {".class", ".jar", ".bsh"};
|
||||||
private static final String DESCRIPTION = "Binaries Only";
|
private static final String DESCRIPTION = "Executable Files Only";
|
||||||
private static final BinaryOnlyFilter filter = new BinaryOnlyFilter();
|
private static final BinaryOnlyFilter filter = new BinaryOnlyFilter();
|
||||||
|
|
||||||
private BinaryOnlyFilter() {
|
private BinaryOnlyFilter() {
|
||||||
@@ -80,12 +80,13 @@ public class BinaryOnlyFilter implements FileFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buf = new StringBuffer(DESCRIPTION + ": ");
|
/* StringBuffer buf = new StringBuffer(DESCRIPTION + ": ");
|
||||||
|
|
||||||
for (int i = 0; i < EXTENSIONS.length - 1; i++)
|
for (int i = 0; i < EXTENSIONS.length - 1; i++)
|
||||||
buf.append("<" + EXTENSIONS[i] + "> ");
|
buf.append("<" + EXTENSIONS[i] + "> ");
|
||||||
buf.append("<" + EXTENSIONS[EXTENSIONS.length - 1] + ">");
|
buf.append("<" + EXTENSIONS[EXTENSIONS.length - 1] + ">");
|
||||||
|
|
||||||
return buf.toString();
|
return buf.toString(); */
|
||||||
|
return DESCRIPTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
*
|
*
|
||||||
* $RCSfile: ConfigurePanel.java,v $
|
* $RCSfile: ConfigurePanel.java,v $
|
||||||
*
|
*
|
||||||
* $Revision: 1.2 $
|
* $Revision: 1.3 $
|
||||||
*
|
*
|
||||||
* last change: $Author: toconnor $ $Date: 2002-11-13 17:44:11 $
|
* last change: $Author: toconnor $ $Date: 2003-01-16 17:47:56 $
|
||||||
*
|
*
|
||||||
* The Contents of this file are made available subject to the terms of
|
* The Contents of this file are made available subject to the terms of
|
||||||
* either of the following licenses
|
* either of the following licenses
|
||||||
@@ -93,10 +93,29 @@ public class ConfigurePanel extends JPanel {
|
|||||||
private ScriptPanel scriptPanel;
|
private ScriptPanel scriptPanel;
|
||||||
private ParcelDescriptor descriptor = ParcelDescriptor.getParcelDescriptor();
|
private ParcelDescriptor descriptor = ParcelDescriptor.getParcelDescriptor();
|
||||||
|
|
||||||
public ConfigurePanel(String basedir, Vector classpath, Document doc) {
|
public static final String DIALOG_TITLE = "Choose What to Export as Scripts";
|
||||||
|
|
||||||
|
public ConfigurePanel(String basedir, Vector classpath, Document doc,
|
||||||
|
String language) {
|
||||||
|
|
||||||
this.basedir = new File(basedir);
|
this.basedir = new File(basedir);
|
||||||
this.classpath = classpath;
|
this.classpath = classpath;
|
||||||
initUI(doc);
|
initUI(doc, language);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reload(String basedir, Vector classpath, Document doc,
|
||||||
|
String language) {
|
||||||
|
|
||||||
|
if (basedir != null)
|
||||||
|
this.basedir = new File(basedir);
|
||||||
|
|
||||||
|
if (classpath != null)
|
||||||
|
this.classpath = classpath;
|
||||||
|
|
||||||
|
methodPanel.reload(this.basedir, this.classpath, language);
|
||||||
|
|
||||||
|
if (doc != null)
|
||||||
|
scriptPanel.reload(descriptor.parse(doc));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Document getConfiguration() throws Exception {
|
public Document getConfiguration() throws Exception {
|
||||||
@@ -104,10 +123,10 @@ public class ConfigurePanel extends JPanel {
|
|||||||
return descriptor.generate(scripts);
|
return descriptor.generate(scripts);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initUI(Document doc) {
|
private void initUI(Document doc, String language) {
|
||||||
JPanel leftPanel = new JPanel();
|
JPanel leftPanel = new JPanel();
|
||||||
JPanel methodButtons = initMethodButtons();
|
JPanel methodButtons = initMethodButtons();
|
||||||
methodPanel = new MethodPanel(basedir, classpath);
|
methodPanel = new MethodPanel(basedir, classpath, language);
|
||||||
leftPanel.setLayout(new BorderLayout());
|
leftPanel.setLayout(new BorderLayout());
|
||||||
leftPanel.add(methodPanel, BorderLayout.CENTER);
|
leftPanel.add(methodPanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
*
|
*
|
||||||
* $RCSfile: MethodPanel.java,v $
|
* $RCSfile: MethodPanel.java,v $
|
||||||
*
|
*
|
||||||
* $Revision: 1.2 $
|
* $Revision: 1.3 $
|
||||||
*
|
*
|
||||||
* last change: $Author: toconnor $ $Date: 2002-11-13 17:44:11 $
|
* last change: $Author: toconnor $ $Date: 2003-01-16 17:47:56 $
|
||||||
*
|
*
|
||||||
* The Contents of this file are made available subject to the terms of
|
* The Contents of this file are made available subject to the terms of
|
||||||
* either of the following licenses
|
* either of the following licenses
|
||||||
@@ -71,6 +71,8 @@ import java.lang.reflect.Modifier;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.table.AbstractTableModel;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
|
||||||
@@ -82,18 +84,32 @@ public class MethodPanel extends JPanel {
|
|||||||
|
|
||||||
private File basedir;
|
private File basedir;
|
||||||
private Vector classpath;
|
private Vector classpath;
|
||||||
private final static String FIRST_PARAM = "drafts.com.sun.star.script.framework.XScriptContext";
|
private final static String FIRST_PARAM =
|
||||||
|
"drafts.com.sun.star.script.framework.XScriptContext";
|
||||||
|
|
||||||
|
// private JTable table;
|
||||||
|
// private MethodTableModel model;
|
||||||
private JList list;
|
private JList list;
|
||||||
private Vector values = new Vector(11);
|
private Vector values = new Vector(11);
|
||||||
|
|
||||||
public MethodPanel(File basedir, Vector classpath) {
|
public MethodPanel(File basedir, Vector classpath, String language) {
|
||||||
this.basedir = basedir;
|
this.basedir = basedir;
|
||||||
this.classpath = classpath;
|
this.classpath = classpath;
|
||||||
initValues();
|
|
||||||
|
initValues(language);
|
||||||
initUI();
|
initUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reload(File basedir, Vector classpath, String language) {
|
||||||
|
this.basedir = basedir;
|
||||||
|
this.classpath = classpath;
|
||||||
|
|
||||||
|
values.removeAllElements();
|
||||||
|
initValues(language);
|
||||||
|
|
||||||
|
list.setListData(values);
|
||||||
|
}
|
||||||
|
|
||||||
public ScriptEntry[] getSelectedEntries() {
|
public ScriptEntry[] getSelectedEntries() {
|
||||||
Object[] selections = list.getSelectedValues();
|
Object[] selections = list.getSelectedValues();
|
||||||
ScriptEntry[] entries = new ScriptEntry[selections.length];
|
ScriptEntry[] entries = new ScriptEntry[selections.length];
|
||||||
@@ -107,7 +123,9 @@ public class MethodPanel extends JPanel {
|
|||||||
|
|
||||||
private void initUI() {
|
private void initUI() {
|
||||||
JLabel label = new JLabel("Available Methods:");
|
JLabel label = new JLabel("Available Methods:");
|
||||||
|
// table = new JTable(model);
|
||||||
list = new JList(values);
|
list = new JList(values);
|
||||||
|
|
||||||
JScrollPane pane = new JScrollPane(list);
|
JScrollPane pane = new JScrollPane(list);
|
||||||
label.setLabelFor(pane);
|
label.setLabelFor(pane);
|
||||||
|
|
||||||
@@ -119,58 +137,81 @@ public class MethodPanel extends JPanel {
|
|||||||
add(pane, BorderLayout.CENTER);
|
add(pane, BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initValues() {
|
private void initValues(String language) {
|
||||||
String[] classNames;
|
|
||||||
String parcelName;
|
String parcelName;
|
||||||
|
|
||||||
if (basedir == null || basedir.exists() == false ||
|
if (basedir == null || basedir.exists() == false ||
|
||||||
basedir.isDirectory() == false)
|
basedir.isDirectory() == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
classNames = findClassNames();
|
|
||||||
if (classNames == null || classNames.length == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
parcelName = basedir.getName();
|
parcelName = basedir.getName();
|
||||||
if (parcelName.equals(ParcelZipper.CONTENTS_DIRNAME))
|
if (parcelName.equals(ParcelZipper.CONTENTS_DIRNAME))
|
||||||
parcelName = basedir.getParentFile().getName();
|
parcelName = basedir.getParentFile().getName();
|
||||||
|
|
||||||
DefaultScriptClassLoader classloader =
|
if (language == null)
|
||||||
new DefaultScriptClassLoader(classpath);
|
initJavaValues(parcelName);
|
||||||
|
else if (language.toLowerCase().equals("beanshell"))
|
||||||
|
initBeanShellValues(parcelName);
|
||||||
|
else
|
||||||
|
initJavaValues(parcelName);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < classNames.length; i++)
|
private void initJavaValues(String parcelName) {
|
||||||
{
|
String[] classNames;
|
||||||
try
|
|
||||||
|
classNames = findClassNames();
|
||||||
|
if (classNames != null && classNames.length != 0) {
|
||||||
|
|
||||||
|
DefaultScriptClassLoader classloader =
|
||||||
|
new DefaultScriptClassLoader(classpath);
|
||||||
|
|
||||||
|
for (int i = 0; i < classNames.length; i++)
|
||||||
{
|
{
|
||||||
Class clazz = classloader.loadClass(classNames[i]);
|
try
|
||||||
Method[] methods = clazz.getDeclaredMethods();
|
|
||||||
for (int k = 0; k < methods.length; k++)
|
|
||||||
{
|
{
|
||||||
if (Modifier.isPublic(methods[k].getModifiers()))
|
Class clazz = classloader.loadClass(classNames[i]);
|
||||||
|
Method[] methods = clazz.getDeclaredMethods();
|
||||||
|
for (int k = 0; k < methods.length; k++)
|
||||||
{
|
{
|
||||||
Class[] params = methods[k].getParameterTypes();
|
if (Modifier.isPublic(methods[k].getModifiers()))
|
||||||
if(params.length > 0)
|
|
||||||
{
|
{
|
||||||
if(params[0].getName().equals(FIRST_PARAM))
|
Class[] params = methods[k].getParameterTypes();
|
||||||
|
if(params.length > 0)
|
||||||
{
|
{
|
||||||
ScriptEntry entry =
|
if(params[0].getName().equals(FIRST_PARAM))
|
||||||
new ScriptEntry(classNames[i] + "." + methods[k].getName(),
|
{
|
||||||
parcelName);
|
ScriptEntry entry =
|
||||||
values.addElement(entry);
|
new ScriptEntry(classNames[i] + "." +
|
||||||
|
methods[k].getName(), parcelName);
|
||||||
|
values.addElement(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (ClassNotFoundException e)
|
||||||
|
{
|
||||||
|
System.err.println("Class Not Found Exception...");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
catch (NoClassDefFoundError nc)
|
||||||
|
{
|
||||||
|
System.err.println("No Class Definition Found...");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException e)
|
}
|
||||||
{
|
}
|
||||||
System.err.println("Class Not Found Exception...");
|
|
||||||
continue;
|
private void initBeanShellValues(String parcelName) {
|
||||||
}
|
|
||||||
catch (NoClassDefFoundError nc)
|
ArrayList bshFiles = findFiles(basedir, ".bsh");
|
||||||
{
|
|
||||||
System.err.println("No Class Definition Found...");
|
if (bshFiles != null) {
|
||||||
continue;
|
for (int i = 0; i < bshFiles.size(); i++) {
|
||||||
|
File f = (File)bshFiles.get(i);
|
||||||
|
values.addElement(new ScriptEntry("BeanShell", f.getName(),
|
||||||
|
f.getName(), parcelName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,4 +270,70 @@ public class MethodPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
return (String[])result.toArray(new String[0]);
|
return (String[])result.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
private class MethodTableModel extends AbstractTableModel {
|
||||||
|
final String[] columnNames = {"Method",
|
||||||
|
"Language"};
|
||||||
|
|
||||||
|
private Vector methods;
|
||||||
|
private int nextRow;
|
||||||
|
|
||||||
|
public MethodTableModel() {
|
||||||
|
methods = new Vector(11);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColumnCount() {
|
||||||
|
return columnNames.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRowCount() {
|
||||||
|
return methods.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColumnName(int col) {
|
||||||
|
return columnNames[col];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(ScriptEntry entry) {
|
||||||
|
methods.addElement(entry);
|
||||||
|
fireTableRowsInserted(nextRow, nextRow);
|
||||||
|
nextRow++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(int row) {
|
||||||
|
methods.removeElementAt(row);
|
||||||
|
fireTableRowsDeleted(row, row);
|
||||||
|
nextRow--;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAll() {
|
||||||
|
methods.removeAllElements();
|
||||||
|
fireTableRowsDeleted(0, nextRow);
|
||||||
|
nextRow = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getValueAt(int row) {
|
||||||
|
return methods.elementAt(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getValueAt(int row, int col) {
|
||||||
|
String result = "";
|
||||||
|
ScriptEntry entry;
|
||||||
|
|
||||||
|
entry = (ScriptEntry)methods.elementAt(row);
|
||||||
|
|
||||||
|
if (col == 0)
|
||||||
|
result = entry.getLanguageName();
|
||||||
|
else if (col == 1)
|
||||||
|
result = entry.getLanguage();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCellEditable(int row, int col) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
*
|
*
|
||||||
* $RCSfile: ScriptPanel.java,v $
|
* $RCSfile: ScriptPanel.java,v $
|
||||||
*
|
*
|
||||||
* $Revision: 1.2 $
|
* $Revision: 1.3 $
|
||||||
*
|
*
|
||||||
* last change: $Author: toconnor $ $Date: 2002-11-13 17:44:11 $
|
* last change: $Author: toconnor $ $Date: 2003-01-16 17:47:56 $
|
||||||
*
|
*
|
||||||
* The Contents of this file are made available subject to the terms of
|
* The Contents of this file are made available subject to the terms of
|
||||||
* either of the following licenses
|
* either of the following licenses
|
||||||
@@ -84,18 +84,31 @@ import org.openoffice.idesupport.ScriptEntry;
|
|||||||
public class ScriptPanel extends JPanel {
|
public class ScriptPanel extends JPanel {
|
||||||
private ScriptTableModel model;
|
private ScriptTableModel model;
|
||||||
private JTable table;
|
private JTable table;
|
||||||
private File descriptor;
|
|
||||||
|
|
||||||
public ScriptPanel(ScriptEntry[] scripts) {
|
public ScriptPanel(ScriptEntry[] scripts) {
|
||||||
model = new ScriptTableModel(scripts);
|
model = new ScriptTableModel(scripts);
|
||||||
initUI();
|
initUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reload(ScriptEntry[] entries) {
|
||||||
|
model.removeAll();
|
||||||
|
addScriptEntries(entries);
|
||||||
|
}
|
||||||
|
|
||||||
public void addScriptEntries(ScriptEntry[] entries) {
|
public void addScriptEntries(ScriptEntry[] entries) {
|
||||||
for (int i = 0; i < entries.length; i++) {
|
for (int i = 0; i < entries.length; i++) {
|
||||||
ScriptEntry entry = new ScriptEntry(entries[i].getLanguageName(),
|
ScriptEntry entry;
|
||||||
entries[i].getLocation());
|
|
||||||
entry.setLogicalName(entries[i].getLanguageName());
|
try {
|
||||||
|
entry = (ScriptEntry) entries[i].clone();
|
||||||
|
}
|
||||||
|
catch (CloneNotSupportedException cnse) {
|
||||||
|
entry = new ScriptEntry(entries[i].getLanguage(),
|
||||||
|
entries[i].getLanguageName(),
|
||||||
|
entries[i].getLogicalName(),
|
||||||
|
entries[i].getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
model.add(entry);
|
model.add(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user