Author: fmui
Date: Thu Sep 23 21:59:49 2010
New Revision: 1000647
URL: http://svn.apache.org/viewvc?rev=1000647&view=rev
Log:
added script library to Swing Client
Added:
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/getdescendants.groovy
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/script-library.properties
(with props)
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/template.groovy
Modified:
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientFrame.java
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientHelper.java
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/CMIS.groovy
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/startup.groovy
Modified:
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientFrame.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientFrame.java?rev=1000647&r1=1000646&r2=1000647&view=diff
==============================================================================
---
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientFrame.java
(original)
+++
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientFrame.java
Thu Sep 23 21:59:49 2010
@@ -27,12 +27,19 @@ import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
@@ -58,7 +65,7 @@ public class ClientFrame extends JFrame
private static final int BUTTON_INFO = 9;
private static final String GROOVY_SCRIPT_FOLDER = "/scripts/";
- private static final String GROOVY_STARTUP_SCRIPT = "startup.groovy";
+ private static final String GROOVY_SCRIPT_LIBRARY =
"script-library.properties";
private LoginDialog loginDialog;
private LogFrame logFrame;
@@ -66,6 +73,7 @@ public class ClientFrame extends JFrame
private JToolBar toolBar;
private JButton[] toolbarButton;
+ private JPopupMenu toolbarConsolePopup;
private FolderPanel folderPanel;
private DetailsTabs detailsTabs;
@@ -149,42 +157,25 @@ public class ClientFrame extends JFrame
toolbarButton[BUTTON_CONSOLE].setEnabled(false);
toolbarButton[BUTTON_CONSOLE].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- try {
- setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
-
- Console console = new Console();
- console.setVariable("session",
model.getClientSession().getSession());
- console.setVariable("binding",
model.getClientSession().getSession().getBinding());
- console.run();
-
- InputStream stream = this.getClass().getResourceAsStream(
- GROOVY_SCRIPT_FOLDER + GROOVY_STARTUP_SCRIPT);
- if (stream == null) {
- throw new Exception("Groovy startup script is
missing!");
- } else {
- BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, "UTF-8"));
- StringBuilder sb = new StringBuilder();
- String s;
-
- while ((s = reader.readLine()) != null) {
- sb.append(s);
- sb.append("\n");
- }
-
- console.getInputArea().setText(sb.toString());
-
- reader.close();
- }
- } catch (Exception ex) {
- ClientHelper.showError(thisFrame, ex);
- } finally {
-
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
+ toolbarConsolePopup.show(toolbarButton[BUTTON_CONSOLE], 0,
toolbarButton[BUTTON_CONSOLE].getHeight());
}
});
toolBar.add(toolbarButton[BUTTON_CONSOLE]);
+ toolbarConsolePopup = new JPopupMenu();
+ for (CmisScript s : readScriptLibrary()) {
+ JMenuItem menuItem = new JMenuItem(s.getName());
+ final String path = s.getPath();
+ menuItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ openConsole(path);
+ }
+ });
+ toolbarConsolePopup.add(menuItem);
+ }
+
toolBar.addSeparator();
toolbarButton[BUTTON_CREATE_DOCUMENT] = new JButton("Create Document",
ClientHelper.getIcon("newdocument.png"));
@@ -282,4 +273,111 @@ public class ClientFrame extends JFrame
}
}
}
+
+ private void openConsole(String path) {
+ try {
+ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
+ Console console = new Console();
+ console.setVariable("session",
model.getClientSession().getSession());
+ console.setVariable("binding",
model.getClientSession().getSession().getBinding());
+ console.run();
+
+ console.getInputArea().setText(readScript(path));
+ } catch (Exception ex) {
+ ClientHelper.showError(null, ex);
+ } finally {
+ setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+
+ private List<CmisScript> readScriptLibrary() {
+ InputStream stream =
this.getClass().getResourceAsStream(GROOVY_SCRIPT_FOLDER +
GROOVY_SCRIPT_LIBRARY);
+ if (stream == null) {
+ return Collections.singletonList(new CmisScript("Groovy Console",
null));
+ }
+
+ try {
+ Properties properties = new Properties();
+ properties.load(stream);
+ stream.close();
+
+ List<CmisScript> result = new ArrayList<CmisScript>();
+ for (String script : properties.stringPropertyNames()) {
+ result.add(new CmisScript(properties.getProperty(script),
GROOVY_SCRIPT_FOLDER + script));
+ }
+ Collections.sort(result);
+
+ return result;
+ } catch (IOException e) {
+ return Collections.singletonList(new CmisScript("Groovy Console",
null));
+ }
+ }
+
+ private String readScript(String path) throws Exception {
+ if (path == null) {
+ return "";
+ }
+
+ InputStream stream = this.getClass().getResourceAsStream(path);
+ if (stream == null) {
+ throw new Exception("Groovy script is missing!");
+ } else {
+ BufferedReader reader = new BufferedReader(new
InputStreamReader(stream, "UTF-8"));
+ StringBuilder sb = new StringBuilder();
+ String s;
+ boolean header = true;
+
+ while ((s = reader.readLine()) != null) {
+ // remove header
+ if (header) {
+ String st = s.trim();
+ if (st.length() == 0) {
+ continue;
+ }
+
+ char c = st.charAt(0);
+ header = (c == '/') || (c == '*');
+ if (header) {
+ continue;
+ }
+ }
+
+ sb.append(s);
+ sb.append("\n");
+ }
+
+ reader.close();
+
+ return sb.toString();
+ }
+ }
+
+ static class CmisScript implements Comparable<CmisScript> {
+ private String name;
+ private String path;
+
+ public CmisScript(String name, String path) {
+ this.name = name;
+ this.path = path;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ @Override
+ public int compareTo(CmisScript o) {
+ return name.compareToIgnoreCase(o.getName());
+ }
+ }
}
Modified:
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientHelper.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientHelper.java?rev=1000647&r1=1000646&r2=1000647&view=diff
==============================================================================
---
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientHelper.java
(original)
+++
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/ClientHelper.java
Thu Sep 23 21:59:49 2010
@@ -98,6 +98,10 @@ public class ClientHelper {
OutputStream outStream = null;
try {
ContentStream content = doc.getContentStream(streamId);
+ if (content == null) {
+ throw new Exception("No content!");
+ }
+
inStream = new BufferedInputStream(content.getStream());
outStream = new
FileOutputStream(fileChooser.getSelectedFile());
@@ -145,6 +149,10 @@ public class ClientHelper {
try {
ContentStream content = doc.getContentStream();
+ if (content == null) {
+ throw new Exception("No content!");
+ }
+
inStream = new BufferedInputStream(content.getStream());
String filename = doc.getContentStreamFileName();
Modified:
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/CMIS.groovy
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/CMIS.groovy?rev=1000647&r1=1000646&r2=1000647&view=diff
==============================================================================
---
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/CMIS.groovy
(original)
+++
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/CMIS.groovy
Thu Sep 23 21:59:49 2010
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package scripts
import java.io.ByteArrayInputStream;
Added:
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/getdescendants.groovy
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/getdescendants.groovy?rev=1000647&view=auto
==============================================================================
---
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/getdescendants.groovy
(added)
+++
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/getdescendants.groovy
Thu Sep 23 21:59:49 2010
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import org.apache.chemistry.opencmis.client.api.*
+
+session.rootFolder.getDescendants(-1).each {
+ printTree(it, 0)
+}
+
+def printTree(Tree tree, int depth) {
+ for(i in 0..depth) { print " " }
+
+ println tree.item.name
+
+ if(tree.children.size > 0) {
+ tree.children.each {
+ printTree(it, depth + 1)
+ }
+ }
+}
\ No newline at end of file
Added:
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/script-library.properties
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/script-library.properties?rev=1000647&view=auto
==============================================================================
---
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/script-library.properties
(added)
+++
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/script-library.properties
Thu Sep 23 21:59:49 2010
@@ -0,0 +1,29 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+
+#
+# Add more scripts here.
+# key = script file, value = title
+#
+
+startup.groovy = - Demo -
+template.groovy = - Basic template -
+getdescendants.groovy = Print descendants tree
Propchange:
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/script-library.properties
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/startup.groovy
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/startup.groovy?rev=1000647&r1=1000646&r2=1000647&view=diff
==============================================================================
---
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/startup.groovy
(original)
+++
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/startup.groovy
Thu Sep 23 21:59:49 2010
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
import org.apache.chemistry.opencmis.commons.*
import org.apache.chemistry.opencmis.commons.data.*
import org.apache.chemistry.opencmis.commons.enums.*
Added:
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/template.groovy
URL:
http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/template.groovy?rev=1000647&view=auto
==============================================================================
---
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/template.groovy
(added)
+++
incubator/chemistry/opencmis-swingclient/trunk/src/main/resources/scripts/template.groovy
Thu Sep 23 21:59:49 2010
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import org.apache.chemistry.opencmis.commons.*
+import org.apache.chemistry.opencmis.commons.data.*
+import org.apache.chemistry.opencmis.commons.enums.*
+import org.apache.chemistry.opencmis.client.api.*
+
+// def cmis = new scripts.CMIS(session)
+// println session.repositoryInfo.name
\ No newline at end of file