You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2011/05/15 15:06:18 UTC
svn commit: r1103365 - in
/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench:
ClientFrame.java ClientHelper.java details/ObjectPanel.java
Author: fmui
Date: Sun May 15 13:06:18 2011
New Revision: 1103365
URL: http://svn.apache.org/viewvc?rev=1103365&view=rev
Log:
CMIS Workbench: open and run Groovy scripts stored in the repository
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/ObjectPanel.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java?rev=1103365&r1=1103364&r2=1103365&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientFrame.java Sun May 15 13:06:18 2011
@@ -18,21 +18,15 @@
*/
package org.apache.chemistry.opencmis.workbench;
-import groovy.ui.Console;
-
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Cursor;
-import java.awt.Desktop;
-import java.awt.Desktop.Action;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
-import java.io.IOException;
-import java.net.URI;
import java.util.Collections;
import java.util.List;
import java.util.prefs.Preferences;
@@ -40,7 +34,6 @@ import java.util.prefs.Preferences;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
-import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JSplitPane;
@@ -193,7 +186,7 @@ public class ClientFrame extends JFrame
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- openConsole(file);
+ ClientHelper.openConsole(ClientFrame.this, model, file);
}
});
toolbarConsolePopup.add(menuItem);
@@ -321,56 +314,6 @@ public class ClientFrame extends JFrame
}
}
- private void openConsole(String file) {
- try {
- setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
-
- Console console = new Console(this.getClass().getClassLoader());
- console.setVariable("session", model.getClientSession().getSession());
- console.setVariable("binding", model.getClientSession().getSession().getBinding());
-
- console.run();
-
- JMenu cmisMenu = new JMenu("CMIS");
- console.getFrame().getRootPane().getJMenuBar().add(cmisMenu);
-
- addConsoleMenu(cmisMenu, "CMIS 1.0 Specification", new URI(
- "http://docs.oasis-open.org/cmis/CMIS/v1.0/os/cmis-spec-v1.0.html"));
- addConsoleMenu(cmisMenu, "OpenCMIS Documentation",
- new URI("http://chemistry.apache.org/java/opencmis.html"));
- addConsoleMenu(
- cmisMenu,
- "OpenCMIS Client API JavaDoc",
- new URI(
- "http://incubator.apache.org/chemistry/javadoc/org/apache/chemistry/opencmis/client/api/package-summary.html"));
-
- console.getInputArea().setText(ClientHelper.readFileAndRemoveHeader(file));
- } catch (Exception ex) {
- ClientHelper.showError(null, ex);
- } finally {
- setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- }
-
- private void addConsoleMenu(JMenu menu, String title, final URI url) {
- if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Action.BROWSE)) {
- return;
- }
-
- JMenuItem menuItem = new JMenuItem(title);
- menuItem.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- Desktop.getDesktop().browse(url);
- } catch (IOException e1) {
- }
- }
- });
-
- menu.add(menuItem);
- }
-
private List<FileEntry> readScriptLibrary() {
List<FileEntry> result = ClientHelper.readFileProperties(GROOVY_SCRIPT_FOLDER + GROOVY_SCRIPT_LIBRARY,
GROOVY_SCRIPT_FOLDER);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java?rev=1103365&r1=1103364&r2=1103365&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java Sun May 15 13:06:18 2011
@@ -18,9 +18,17 @@
*/
package org.apache.chemistry.opencmis.workbench;
+import groovy.lang.Binding;
+import groovy.ui.Console;
+import groovy.util.GroovyScriptEngine;
+
import java.awt.Color;
import java.awt.Component;
+import java.awt.Cursor;
import java.awt.Desktop;
+import java.awt.Desktop.Action;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
@@ -30,6 +38,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.io.Writer;
+import java.net.URI;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -41,6 +51,8 @@ import java.util.Properties;
import javax.swing.ImageIcon;
import javax.swing.InputMap;
import javax.swing.JFileChooser;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
@@ -53,6 +65,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
import org.apache.chemistry.opencmis.commons.impl.MimeTypes;
+import org.apache.chemistry.opencmis.workbench.model.ClientModel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -393,6 +406,78 @@ public class ClientHelper {
}
}
+ public static Console openConsole(final Component parent, final ClientModel model, final String file) {
+ try {
+ parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
+ Console console = new Console(parent.getClass().getClassLoader());
+ console.setVariable("session", model.getClientSession().getSession());
+ console.setVariable("binding", model.getClientSession().getSession().getBinding());
+
+ console.run();
+
+ JMenu cmisMenu = new JMenu("CMIS");
+ console.getFrame().getRootPane().getJMenuBar().add(cmisMenu);
+
+ addConsoleMenu(cmisMenu, "CMIS 1.0 Specification", new URI(
+ "http://docs.oasis-open.org/cmis/CMIS/v1.0/os/cmis-spec-v1.0.html"));
+ addConsoleMenu(cmisMenu, "OpenCMIS Documentation",
+ new URI("http://chemistry.apache.org/java/opencmis.html"));
+ addConsoleMenu(
+ cmisMenu,
+ "OpenCMIS Client API JavaDoc",
+ new URI(
+ "http://incubator.apache.org/chemistry/javadoc/org/apache/chemistry/opencmis/client/api/package-summary.html"));
+
+ console.getInputArea().setText(ClientHelper.readFileAndRemoveHeader(file));
+
+ return console;
+ } catch (Exception ex) {
+ ClientHelper.showError(null, ex);
+ return null;
+ } finally {
+ parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
+ private static void addConsoleMenu(JMenu menu, String title, final URI url) {
+ if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Action.BROWSE)) {
+ return;
+ }
+
+ JMenuItem menuItem = new JMenuItem(title);
+ menuItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ try {
+ Desktop.getDesktop().browse(url);
+ } catch (IOException e1) {
+ }
+ }
+ });
+
+ menu.add(menuItem);
+ }
+
+ public static void runGroovyScript(final Component parent, final ClientModel model, final File file,
+ final Writer out) {
+ try {
+ parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
+ String[] roots = new String[] { file.getParentFile().getAbsolutePath() };
+ GroovyScriptEngine gse = new GroovyScriptEngine(roots, parent.getClass().getClassLoader());
+ Binding binding = new Binding();
+ binding.setVariable("session", model.getClientSession().getSession());
+ binding.setVariable("binding", model.getClientSession().getSession().getBinding());
+ binding.setVariable("out", out);
+ gse.run(file.getName(), binding);
+ } catch (Exception ex) {
+ ClientHelper.showError(null, ex);
+ } finally {
+ parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
public static class FileEntry implements Comparable<FileEntry> {
private final String name;
private final String file;
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/ObjectPanel.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/ObjectPanel.java?rev=1103365&r1=1103364&r2=1103365&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/ObjectPanel.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/ObjectPanel.java Sun May 15 13:06:18 2011
@@ -18,13 +18,24 @@
*/
package org.apache.chemistry.opencmis.workbench.details;
+import groovy.ui.Console;
+
+import java.awt.BorderLayout;
import java.awt.Cursor;
+import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
import java.util.Collections;
import java.util.List;
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
@@ -54,6 +65,11 @@ public class ObjectPanel extends InfoPan
private InfoList paths;
private InfoList allowableActionsList;
private JButton refreshButton;
+ private JPanel groovyPanel;
+ private JButton groovyOpenButton;
+ private JButton groovyRunButton;
+ private JTextArea groovyOutput;
+ private JTextAreaWriter groovyOutputWriter;
public ObjectPanel(ClientModel model) {
super(model);
@@ -77,6 +93,7 @@ public class ObjectPanel extends InfoPan
contentUrlField.setText("");
allowableActionsList.removeAll();
refreshButton.setEnabled(false);
+ groovyPanel.setVisible(false);
} else {
try {
nameField.setText(object.getName());
@@ -146,6 +163,13 @@ public class ObjectPanel extends InfoPan
}
refreshButton.setEnabled(true);
+
+ if ((object instanceof Document) && (object.getName().toLowerCase().endsWith(".groovy"))) {
+ groovyPanel.setVisible(true);
+ groovyOutput.setVisible(false);
+ } else {
+ groovyPanel.setVisible(false);
+ }
} catch (Exception e) {
ClientHelper.showError(this, e);
}
@@ -169,6 +193,26 @@ public class ObjectPanel extends InfoPan
refreshButton = addComponent("", new JButton("Refresh"));
refreshButton.setEnabled(false);
+ groovyPanel = addComponent("", new JPanel(new BorderLayout()));
+ groovyPanel.setOpaque(false);
+ groovyPanel.setVisible(false);
+
+ JPanel buttonPanel = new JPanel();
+ buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
+ buttonPanel.setOpaque(false);
+ groovyPanel.add(buttonPanel, BorderLayout.PAGE_START);
+ groovyOpenButton = new JButton("Open Script");
+ buttonPanel.add(groovyOpenButton);
+ groovyRunButton = new JButton("Run Script");
+ buttonPanel.add(groovyRunButton);
+
+ groovyOutput = new JTextArea(null, 1, 80);
+ groovyOutput.setEditable(false);
+ groovyOutput.setFont(Font.decode("Monospaced"));
+ groovyOutput.setBorder(BorderFactory.createTitledBorder(""));
+ groovyOutputWriter = new JTextAreaWriter(groovyOutput);
+ groovyPanel.add(groovyOutput, BorderLayout.CENTER);
+
refreshButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
@@ -181,6 +225,43 @@ public class ObjectPanel extends InfoPan
}
}
});
+
+ groovyOpenButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ try {
+ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ Document doc = (Document) getClientModel().getCurrentObject();
+ File file = ClientHelper.createTempFileFromDocument(doc, null);
+ Console console = ClientHelper.openConsole(ObjectPanel.this, getClientModel(), null);
+ if (console != null) {
+ console.loadScriptFile(file);
+ }
+ } catch (Exception ex) {
+ ClientHelper.showError(null, ex);
+ } finally {
+ setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+ });
+
+ groovyRunButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ try {
+ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ Document doc = (Document) getClientModel().getCurrentObject();
+ File file = ClientHelper.createTempFileFromDocument(doc, null);
+ groovyOutput.setText("");
+ groovyOutput.setVisible(true);
+ groovyOutput.invalidate();
+ ClientHelper.runGroovyScript(ObjectPanel.this, getClientModel(), file, groovyOutputWriter);
+ } catch (Exception ex) {
+ ClientHelper.showError(null, ex);
+ } finally {
+ setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+ });
+
}
public String getDocumentURL(final CmisObject document, final Session session) {
@@ -191,4 +272,30 @@ public class ObjectPanel extends InfoPan
return null;
}
+
+ private static class JTextAreaWriter extends Writer {
+ private final JTextArea textArea;
+
+ public JTextAreaWriter(JTextArea textArea) {
+ this.textArea = textArea;
+ }
+
+ @Override
+ public void write(final char[] cbuf, final int off, final int len) throws IOException {
+ final String s = new String(cbuf, off, len);
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ textArea.append(s);
+ }
+ });
+ }
+
+ @Override
+ public void flush() throws IOException {
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
+ }
}