chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1209965 - in /chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main: java/org/apache/chemistry/opencmis/workbench/ java/org/apache/chemistry/opencmis/workbench/model/ resources/images/
Date Sat, 03 Dec 2011 18:24:45 GMT
Author: fmui
Date: Sat Dec  3 18:24:44 2011
New Revision: 1209965

URL: http://svn.apache.org/viewvc?rev=1209965&view=rev
Log:
Workbench: added Create Relationship dialog

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateRelationshipDialog.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/images/newrelationship.png
  (with props)
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/CreateDocumentDialog.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateFolderDialog.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.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=1209965&r1=1209964&r2=1209965&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
Sat Dec  3 18:24:44 2011
@@ -59,8 +59,9 @@ public class ClientFrame extends JFrame 
     private static final int BUTTON_TCK = 6;
     private static final int BUTTON_CREATE_DOCUMENT = 7;
     private static final int BUTTON_CREATE_FOLDER = 8;
-    private static final int BUTTON_LOG = 9;
-    private static final int BUTTON_INFO = 10;
+    private static final int BUTTON_CREATE_RELATIONSHIP = 9;
+    private static final int BUTTON_LOG = 10;
+    private static final int BUTTON_INFO = 11;
 
     private static final String PREFS_X = "x";
     private static final String PREFS_Y = "y";
@@ -115,7 +116,7 @@ public class ClientFrame extends JFrame 
 
         toolBar = new JToolBar("CMIS Toolbar", JToolBar.HORIZONTAL);
 
-        toolbarButton = new JButton[11];
+        toolbarButton = new JButton[12];
 
         toolbarButton[BUTTON_CONNECT] = new JButton("Connection", ClientHelper.getIcon("connect.png"));
         toolbarButton[BUTTON_CONNECT].addActionListener(new ActionListener() {
@@ -224,6 +225,17 @@ public class ClientFrame extends JFrame 
 
         toolBar.add(toolbarButton[BUTTON_CREATE_FOLDER]);
 
+        toolbarButton[BUTTON_CREATE_RELATIONSHIP] = new JButton("Create Relationship",
+                ClientHelper.getIcon("newrelationship.png"));
+        toolbarButton[BUTTON_CREATE_RELATIONSHIP].setEnabled(false);
+        toolbarButton[BUTTON_CREATE_RELATIONSHIP].addActionListener(new ActionListener()
{
+            public void actionPerformed(ActionEvent e) {
+                new CreateRelationshipDialog(thisFrame, model);
+            }
+        });
+
+        toolBar.add(toolbarButton[BUTTON_CREATE_RELATIONSHIP]);
+
         toolBar.addSeparator();
 
         toolbarButton[BUTTON_LOG] = new JButton("Log", ClientHelper.getIcon("log.png"));
@@ -293,6 +305,7 @@ public class ClientFrame extends JFrame 
                 toolbarButton[BUTTON_TCK].setEnabled(true);
                 toolbarButton[BUTTON_CREATE_DOCUMENT].setEnabled(true);
                 toolbarButton[BUTTON_CREATE_FOLDER].setEnabled(true);
+                toolbarButton[BUTTON_CREATE_RELATIONSHIP].setEnabled(model.supportsRelationships());
 
                 setTitle(WINDOW_TITLE + " - " + clientSession.getSession().getRepositoryInfo().getName());
             } catch (Exception ex) {
@@ -304,6 +317,7 @@ public class ClientFrame extends JFrame 
                 toolbarButton[BUTTON_TCK].setEnabled(false);
                 toolbarButton[BUTTON_CREATE_DOCUMENT].setEnabled(false);
                 toolbarButton[BUTTON_CREATE_FOLDER].setEnabled(false);
+                toolbarButton[BUTTON_CREATE_RELATIONSHIP].setEnabled(false);
 
                 ClientHelper.showError(null, ex);
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateDocumentDialog.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateDocumentDialog.java?rev=1209965&r1=1209964&r2=1209965&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateDocumentDialog.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateDocumentDialog.java
Sat Dec  3 18:24:44 2011
@@ -107,7 +107,14 @@ public class CreateDocumentDialog extend
         nameField = new JTextField(60);
         createRow("Name:", nameField, 1);
 
-        typeBox = new JComboBox(getTypes(BaseTypeId.CMIS_DOCUMENT.value()));
+        Object[] types = getTypes(BaseTypeId.CMIS_DOCUMENT.value());
+        if (types.length == 0) {
+            JOptionPane.showMessageDialog(this, "No creatable type!", "Creatable Types",
JOptionPane.ERROR_MESSAGE);
+            thisDialog.dispose();
+            return;
+        }
+
+        typeBox = new JComboBox(types);
         typeBox.setSelectedIndex(0);
         typeBox.addItemListener(new ItemListener() {
             public void itemStateChanged(ItemEvent e) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateFolderDialog.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateFolderDialog.java?rev=1209965&r1=1209964&r2=1209965&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateFolderDialog.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateFolderDialog.java
Sat Dec  3 18:24:44 2011
@@ -25,6 +25,7 @@ import java.awt.event.ActionListener;
 
 import javax.swing.JButton;
 import javax.swing.JComboBox;
+import javax.swing.JOptionPane;
 import javax.swing.JTextField;
 
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
@@ -49,7 +50,14 @@ public class CreateFolderDialog extends 
         nameField = new JTextField(60);
         createRow("Name:", nameField, 0);
 
-        typeBox = new JComboBox(getTypes(BaseTypeId.CMIS_FOLDER.value()));
+        Object[] types = getTypes(BaseTypeId.CMIS_FOLDER.value());
+        if (types.length == 0) {
+            JOptionPane.showMessageDialog(this, "No creatable type!", "Creatable Types",
JOptionPane.ERROR_MESSAGE);
+            thisDialog.dispose();
+            return;
+        }
+
+        typeBox = new JComboBox(types);
         typeBox.setSelectedIndex(0);
         createRow("Type:", typeBox, 1);
 

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateRelationshipDialog.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateRelationshipDialog.java?rev=1209965&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateRelationshipDialog.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateRelationshipDialog.java
Sat Dec  3 18:24:44 2011
@@ -0,0 +1,109 @@
+/*
+ * 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 org.apache.chemistry.opencmis.workbench;
+
+import java.awt.Cursor;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JOptionPane;
+import javax.swing.JTextField;
+
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import org.apache.chemistry.opencmis.workbench.model.ClientModel;
+import org.apache.chemistry.opencmis.workbench.swing.CreateDialog;
+
+public class CreateRelationshipDialog extends CreateDialog {
+
+    private static final long serialVersionUID = 1L;
+
+    private JTextField nameField;
+    private JComboBox typeBox;
+    private JTextField sourceIdField;
+    private JTextField targetIdField;
+
+    public CreateRelationshipDialog(Frame owner, ClientModel model) {
+        super(owner, "Create Relationship", model);
+        createGUI();
+    }
+
+    private void createGUI() {
+        final CreateRelationshipDialog thisDialog = this;
+
+        nameField = new JTextField(60);
+        createRow("Name:", nameField, 0);
+
+        Object[] types = getTypes(BaseTypeId.CMIS_RELATIONSHIP.value());
+        if (types.length == 0) {
+            JOptionPane.showMessageDialog(this, "No creatable type!", "Creatable Types",
JOptionPane.ERROR_MESSAGE);
+            thisDialog.dispose();
+            return;
+        }
+
+        typeBox = new JComboBox(types);
+        typeBox.setSelectedIndex(0);
+        createRow("Type:", typeBox, 1);
+
+        sourceIdField = new JTextField(60);
+        if (getClientModel().getCurrentObject() != null) {
+            sourceIdField.setText(getClientModel().getCurrentObject().getId());
+        }
+        createRow("Source Id:", sourceIdField, 2);
+
+        targetIdField = new JTextField(60);
+        createRow("Target Id:", targetIdField, 3);
+
+        JButton createButton = new JButton("Create Relationship");
+        createButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent event) {
+                String name = nameField.getText();
+                String type = ((ObjectTypeItem) typeBox.getSelectedItem()).getObjectType().getId();
+                String sourceId = sourceIdField.getText();
+                String targetId = targetIdField.getText();
+
+                try {
+                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
+                    getClientModel().createRelationship(name, type, sourceId, targetId);
+
+                    thisDialog.setVisible(false);
+                    thisDialog.dispose();
+                } catch (Exception e) {
+                    ClientHelper.showError(null, e);
+                } finally {
+                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+
+                    try {
+                        getClientModel().reloadFolder();
+                    } catch (Exception e) {
+                        ClientHelper.showError(null, e);
+                    }
+                }
+            }
+        });
+        createRow("", createButton, 4);
+
+        getRootPane().setDefaultButton(createButton);
+
+        showDialog();
+    }
+}

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java?rev=1209965&r1=1209964&r2=1209965&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java
Sat Dec  3 18:24:44 2011
@@ -46,6 +46,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.data.RepositoryCapabilities;
 import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.CapabilityChanges;
 import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery;
 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
@@ -133,6 +134,15 @@ public class ClientModel {
         }
     }
 
+    public synchronized boolean supportsRelationships() {
+        try {
+            ObjectType relType = clientSession.getSession().getTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value());
+            return relType != null;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
     public synchronized ObjectId loadFolder(String folderId, boolean byPath) throws Exception
{
         try {
             Session session = clientSession.getSession();
@@ -274,6 +284,17 @@ public class ClientModel {
         return clientSession.getSession().createFolder(properties, currentFolder, null, null,
null);
     }
 
+    public synchronized ObjectId createRelationship(String name, String type, String sourceId,
String targetId)
+            throws Exception {
+        Map<String, Object> properties = new HashMap<String, Object>();
+        properties.put(PropertyIds.NAME, name);
+        properties.put(PropertyIds.OBJECT_TYPE_ID, type);
+        properties.put(PropertyIds.SOURCE_ID, sourceId);
+        properties.put(PropertyIds.TARGET_ID, targetId);
+
+        return clientSession.getSession().createRelationship(properties, null, null, null);
+    }
+
     public synchronized List<ObjectType> getCreateableTypes(String rootTypeId) {
         List<ObjectType> result = new ArrayList<ObjectType>();
 

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/images/newrelationship.png
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/images/newrelationship.png?rev=1209965&view=auto
==============================================================================
Binary file - no diff available.

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/images/newrelationship.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message