Author: fmui
Date: Sat May 23 21:40:31 2015
New Revision: 1681386
URL: http://svn.apache.org/r1681386
Log:
CMIS-912: Workbench: added UI to create policies
Added:
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreatePolicyDialog.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
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/CreateItemDialog.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-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java?rev=1681386&r1=1681385&r2=1681386&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
Sat May 23 21:40:31 2015
@@ -1028,7 +1028,7 @@ public class InMemoryObjectServiceImpl e
PropertyData<?> pd = propMap.get(PropertyIds.NAME);
String name = (String) pd.getFirstValue();
pd = propMap.get(PropertyIds.POLICY_TEXT);
- String policyText = (String) pd.getFirstValue();
+ String policyText = (pd == null ? null : (String) pd.getFirstValue());
ObjectStore objStore = fStoreManager.getObjectStore(repositoryId);
StoredObject storedObject = objStore.createPolicy(name, policyText,
propMap, user, aclAdd, aclRemove);
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=1681386&r1=1681385&r2=1681386&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 May 23 21:40:31 2015
@@ -97,6 +97,7 @@ public class ClientFrame extends JFrame
private JMenuItem itemMenuItem;
private JMenuItem folderMenuItem;
private JMenuItem relationshipMenuItem;
+ private JMenuItem policyMenuItem;
private JSplitPane split;
private FolderPanel folderPanel;
@@ -289,6 +290,16 @@ public class ClientFrame extends JFrame
}
});
+ policyMenuItem = new JMenuItem("Policy");
+ policyMenuItem.setEnabled(false);
+ toolbarCreatePopup.add(policyMenuItem);
+ policyMenuItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent event) {
+ new CreatePolicyDialog(thisFrame, model);
+ }
+ });
+
toolbarButton[BUTTON_CREATE] = new JButton("Create Object",
ClientHelper.getIcon("newdocument.png"));
toolbarButton[BUTTON_CREATE].setEnabled(false);
toolbarButton[BUTTON_CREATE].addActionListener(new ActionListener() {
@@ -372,6 +383,7 @@ public class ClientFrame extends JFrame
itemMenuItem.setEnabled(model.supportsItems());
relationshipMenuItem.setEnabled(model.supportsRelationships());
+ policyMenuItem.setEnabled(model.supportsPolicies());
String user =
clientSession.getSessionParameters().get(SessionParameter.USER);
if (user != null) {
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateItemDialog.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateItemDialog.java?rev=1681386&r1=1681385&r2=1681386&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateItemDialog.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreateItemDialog.java
Sat May 23 21:40:31 2015
@@ -19,15 +19,19 @@
package org.apache.chemistry.opencmis.workbench;
import java.awt.Cursor;
+import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
import javax.swing.JTextField;
import org.apache.chemistry.opencmis.client.api.ObjectId;
@@ -40,6 +44,8 @@ public class CreateItemDialog extends Cr
private static final long serialVersionUID = 1L;
+ private JRadioButton unfiledButton;
+ private JRadioButton currentPathButton;
private JTextField nameField;
private JComboBox<ObjectTypeItem> typeBox;
@@ -51,8 +57,25 @@ public class CreateItemDialog extends Cr
private void createGUI() {
final CreateItemDialog thisDialog = this;
+ unfiledButton = new JRadioButton("create unfiled");
+ unfiledButton.setSelected(false);
+
+ currentPathButton = new JRadioButton("create in the current folder: "
+ + getClientModel().getCurrentFolder().getPath());
+ currentPathButton.setSelected(true);
+
+ ButtonGroup filedGroup = new ButtonGroup();
+ filedGroup.add(unfiledButton);
+ filedGroup.add(currentPathButton);
+
+ JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ buttonPanel.add(unfiledButton);
+ buttonPanel.add(currentPathButton);
+
+ createRow("", buttonPanel, 0);
+
nameField = new JTextField(60);
- createRow("Name:", nameField, 0);
+ createRow("Name:", nameField, 1);
ObjectTypeItem[] types = getTypes(BaseTypeId.CMIS_ITEM.value());
if (types.length == 0) {
@@ -73,7 +96,7 @@ public class CreateItemDialog extends Cr
ObjectTypeItem type = (ObjectTypeItem) typeBox.getSelectedItem();
updateMandatoryFields(type.getObjectType());
- createRow("Type:", typeBox, 1);
+ createRow("Type:", typeBox, 2);
JButton createButton = new JButton("Create Item",
ClientHelper.getIcon("newfolder.png"));
createButton.addActionListener(new ActionListener() {
@@ -84,7 +107,8 @@ public class CreateItemDialog extends Cr
try {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- ObjectId objectId = getClientModel().createItem(name,
type, getMandatoryPropertyValues());
+ ObjectId objectId = getClientModel().createItem(name,
type, getMandatoryPropertyValues(),
+ unfiledButton.isSelected());
if (objectId != null) {
getClientModel().loadObject(objectId.getId());
Added:
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreatePolicyDialog.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreatePolicyDialog.java?rev=1681386&view=auto
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreatePolicyDialog.java
(added)
+++
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/CreatePolicyDialog.java
Sat May 23 21:40:31 2015
@@ -0,0 +1,143 @@
+/*
+ * 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.FlowLayout;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.JTextField;
+
+import org.apache.chemistry.opencmis.client.api.ObjectId;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+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 CreatePolicyDialog extends CreateDialog {
+
+ private static final long serialVersionUID = 1L;
+
+ private JRadioButton unfiledButton;
+ private JRadioButton currentPathButton;
+ private JTextField nameField;
+ private JTextField policyTextField;
+ private JComboBox<ObjectTypeItem> typeBox;
+
+ public CreatePolicyDialog(Frame owner, ClientModel model) {
+ super(owner, "Create Policy", model);
+ createGUI();
+ }
+
+ private void createGUI() {
+ final CreatePolicyDialog thisDialog = this;
+
+ unfiledButton = new JRadioButton("create unfiled");
+ unfiledButton.setSelected(false);
+
+ currentPathButton = new JRadioButton("create in the current folder: "
+ + getClientModel().getCurrentFolder().getPath());
+ currentPathButton.setSelected(true);
+
+ ButtonGroup filedGroup = new ButtonGroup();
+ filedGroup.add(unfiledButton);
+ filedGroup.add(currentPathButton);
+
+ JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ buttonPanel.add(unfiledButton);
+ buttonPanel.add(currentPathButton);
+
+ createRow("", buttonPanel, 0);
+
+ nameField = new JTextField(60);
+ createRow("Name:", nameField, 1);
+
+ ObjectTypeItem[] types = getTypes(BaseTypeId.CMIS_POLICY.value());
+ if (types.length == 0) {
+ JOptionPane.showMessageDialog(this, "No creatable type!",
"Creatable Types", JOptionPane.ERROR_MESSAGE);
+ thisDialog.dispose();
+ return;
+ }
+
+ typeBox = new JComboBox<ObjectTypeItem>(types);
+ typeBox.setSelectedIndex(0);
+ typeBox.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ TypeDefinition type = ((ObjectTypeItem)
typeBox.getSelectedItem()).getObjectType();
+ updateMandatoryFields(type);
+ }
+ });
+
+ ObjectTypeItem type = (ObjectTypeItem) typeBox.getSelectedItem();
+ updateMandatoryFields(type.getObjectType());
+
+ createRow("Type:", typeBox, 2);
+
+ policyTextField = new JTextField(60);
+ createRow("Policy Text:", policyTextField, 3);
+
+ JButton createButton = new JButton("Create Policy",
ClientHelper.getIcon("newpolicy.png"));
+ createButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ String name = nameField.getText();
+ String policyText = policyTextField.getText();
+ String type = ((ObjectTypeItem)
typeBox.getSelectedItem()).getObjectType().getId();
+
+ try {
+ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
+ ObjectId objectId = getClientModel().createPolicy(name,
type, policyText,
+ getMandatoryPropertyValues(),
unfiledButton.isSelected());
+
+ if (objectId != null) {
+ getClientModel().loadObject(objectId.getId());
+ }
+
+ 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);
+ }
+ }
+ }
+ });
+ createActionRow("", 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=1681386&r1=1681385&r2=1681386&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 May 23 21:40:31 2015
@@ -71,6 +71,7 @@ public class ClientModel {
private Folder currentFolder = null;
private List<CmisObject> currentChildren = Collections.emptyList();
private CmisObject currentObject = null;
+ private List<ObjectType> baseTypes = null;
private final EventListenerList listenerList = new EventListenerList();
@@ -95,6 +96,10 @@ public class ClientModel {
public synchronized void setClientSession(ClientSession clientSession) {
this.clientSession = clientSession;
+ this.currentFolder = null;
+ this.currentChildren = Collections.emptyList();
+ this.currentObject = null;
+ this.baseTypes = null;
}
public synchronized ClientSession getClientSession() {
@@ -140,8 +145,21 @@ public class ClientModel {
}
}
- public synchronized boolean supportsItems() {
+ private synchronized void loadBaseTypes() {
+ if (baseTypes != null) {
+ return;
+ }
+
+ baseTypes = new ArrayList<ObjectType>();
for (ObjectType type :
clientSession.getSession().getTypeChildren(null, false)) {
+ baseTypes.add(type);
+ }
+ }
+
+ public synchronized boolean supportsItems() {
+ loadBaseTypes();
+
+ for (ObjectType type : baseTypes) {
if (type.getBaseTypeId() == BaseTypeId.CMIS_ITEM) {
return true;
}
@@ -151,7 +169,9 @@ public class ClientModel {
}
public synchronized boolean supportsRelationships() {
- for (ObjectType type :
clientSession.getSession().getTypeChildren(null, false)) {
+ loadBaseTypes();
+
+ for (ObjectType type : baseTypes) {
if (type.getBaseTypeId() == BaseTypeId.CMIS_RELATIONSHIP) {
return true;
}
@@ -160,6 +180,18 @@ public class ClientModel {
return false;
}
+ public synchronized boolean supportsPolicies() {
+ loadBaseTypes();
+
+ for (ObjectType type : baseTypes) {
+ if (type.getBaseTypeId() == BaseTypeId.CMIS_POLICY) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
public synchronized ObjectId loadFolder(String folderId, boolean byPath) {
try {
Session session = clientSession.getSession();
@@ -327,7 +359,8 @@ public class ClientModel {
}
}
- public synchronized ObjectId createItem(String name, String type,
Map<String, Object> additionalProperties) {
+ public synchronized ObjectId createItem(String name, String type,
Map<String, Object> additionalProperties,
+ boolean unfiled) {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, type);
@@ -336,7 +369,7 @@ public class ClientModel {
properties.putAll(additionalProperties);
}
- return clientSession.getSession().createItem(properties,
currentFolder, null, null, null);
+ return clientSession.getSession().createItem(properties, (unfiled ?
null : currentFolder), null, null, null);
}
public synchronized ObjectId createFolder(String name, String type,
Map<String, Object> additionalProperties) {
@@ -366,6 +399,22 @@ public class ClientModel {
return clientSession.getSession().createRelationship(properties, null,
null, null);
}
+ public synchronized ObjectId createPolicy(String name, String type, String
policyText,
+ Map<String, Object> additionalProperties, boolean unfiled) {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(PropertyIds.NAME, name);
+ properties.put(PropertyIds.OBJECT_TYPE_ID, type);
+ if (policyText != null && policyText.length() > 0) {
+ properties.put(PropertyIds.POLICY_TEXT, policyText);
+ }
+
+ if (additionalProperties != null) {
+ properties.putAll(additionalProperties);
+ }
+
+ return clientSession.getSession().createPolicy(properties, (unfiled ?
null : currentFolder), null, null, null);
+ }
+
public synchronized List<ObjectType> getTypesAsList(String rootTypeId,
boolean creatableOnly) {
List<ObjectType> result = new ArrayList<ObjectType>();