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 2010/07/23 16:42:45 UTC
svn commit: r967111 - in
/incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient:
details/ObjectPanel.java model/ClientModel.java
Author: fmui
Date: Fri Jul 23 14:42:45 2010
New Revision: 967111
URL: http://svn.apache.org/viewvc?rev=967111&view=rev
Log:
- added refresh button
Modified:
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/details/ObjectPanel.java
incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/model/ClientModel.java
Modified: incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/details/ObjectPanel.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/details/ObjectPanel.java?rev=967111&r1=967110&r2=967111&view=diff
==============================================================================
--- incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/details/ObjectPanel.java (original)
+++ incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/details/ObjectPanel.java Fri Jul 23 14:42:45 2010
@@ -18,6 +18,11 @@
*/
package org.apache.chemistry.opencmis.swingclient.details;
+import java.awt.Cursor;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JTextField;
@@ -30,61 +35,72 @@ import org.apache.chemistry.opencmis.swi
public class ObjectPanel extends InfoPanel implements ObjectListener {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private ClientModel model;
+ private ClientModel model;
- private JTextField nameField;
- private JTextField idField;
- private JTextField typeField;
- private JTextField basetypeField;
- private JList allowableActionsList;
-
- public ObjectPanel(ClientModel model) {
- super();
-
- this.model = model;
- model.addObjectListener(this);
-
- createGUI();
- }
-
- public void objectLoaded(ClientModelEvent event) {
- CmisObject object = model.getCurrentObject();
-
- if (object == null) {
- nameField.setText("");
- idField.setText("");
- typeField.setText("");
- basetypeField.setText("");
- allowableActionsList.removeAll();
- } else {
- try {
- nameField.setText(object.getName());
- idField.setText(object.getId());
- typeField.setText(object.getType().getId());
- basetypeField.setText(object.getBaseTypeId().toString());
- if (object.getAllowableActions() != null) {
- allowableActionsList.setListData(object
- .getAllowableActions().getAllowableActions()
- .toArray());
- } else {
- allowableActionsList
- .setListData(new String[] { "(missing)" });
- }
- } catch (Exception e) {
- ClientHelper.showError(this, e);
- }
- }
- }
-
- private void createGUI() {
- setupGUI();
-
- nameField = addLine("Name:", true);
- idField = addLine("Id:");
- typeField = addLine("Type:");
- basetypeField = addLine("Base Type:");
- allowableActionsList = addComponent("Allowable Actions:", new JList());
- }
+ private JTextField nameField;
+ private JTextField idField;
+ private JTextField typeField;
+ private JTextField basetypeField;
+ private JList allowableActionsList;
+
+ public ObjectPanel(ClientModel model) {
+ super();
+
+ this.model = model;
+ model.addObjectListener(this);
+
+ createGUI();
+ }
+
+ public void objectLoaded(ClientModelEvent event) {
+ CmisObject object = model.getCurrentObject();
+
+ if (object == null) {
+ nameField.setText("");
+ idField.setText("");
+ typeField.setText("");
+ basetypeField.setText("");
+ allowableActionsList.removeAll();
+ } else {
+ try {
+ nameField.setText(object.getName());
+ idField.setText(object.getId());
+ typeField.setText(object.getType().getId());
+ basetypeField.setText(object.getBaseTypeId().toString());
+ if (object.getAllowableActions() != null) {
+ allowableActionsList.setListData(object.getAllowableActions().getAllowableActions().toArray());
+ } else {
+ allowableActionsList.setListData(new String[] { "(missing)" });
+ }
+ } catch (Exception e) {
+ ClientHelper.showError(this, e);
+ }
+ }
+ }
+
+ private void createGUI() {
+ setupGUI();
+
+ nameField = addLine("Name:", true);
+ idField = addLine("Id:");
+ typeField = addLine("Type:");
+ basetypeField = addLine("Base Type:");
+ allowableActionsList = addComponent("Allowable Actions:", new JList());
+ JButton refreshButton = addComponent("", new JButton("Refresh"));
+
+ refreshButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ try {
+ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ model.reloadObject();
+ } catch (Exception ex) {
+ ClientHelper.showError(null, ex);
+ } finally {
+ setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+ }
+ });
+ }
}
Modified: incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/model/ClientModel.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/model/ClientModel.java?rev=967111&r1=967110&r2=967111&view=diff
==============================================================================
--- incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/model/ClientModel.java (original)
+++ incubator/chemistry/opencmis-swingclient/trunk/src/main/java/org/apache/chemistry/opencmis/swingclient/model/ClientModel.java Fri Jul 23 14:42:45 2010
@@ -53,276 +53,272 @@ import org.apache.chemistry.opencmis.com
public class ClientModel {
- private static final Set<String> PROPERTY_SET = new HashSet<String>();
- static {
- PROPERTY_SET.add(PropertyIds.OBJECT_ID);
- PROPERTY_SET.add(PropertyIds.OBJECT_TYPE_ID);
- PROPERTY_SET.add(PropertyIds.NAME);
- PROPERTY_SET.add(PropertyIds.CONTENT_STREAM_MIME_TYPE);
- PROPERTY_SET.add(PropertyIds.CONTENT_STREAM_LENGTH);
- PROPERTY_SET.add(PropertyIds.CONTENT_STREAM_FILE_NAME);
- PROPERTY_SET.add(PropertyIds.CREATED_BY);
- PROPERTY_SET.add(PropertyIds.CREATION_DATE);
- PROPERTY_SET.add(PropertyIds.LAST_MODIFIED_BY);
- PROPERTY_SET.add(PropertyIds.LAST_MODIFICATION_DATE);
- }
-
- private static OperationContext FOLDER_OC = null;
-
- private static final OperationContext OBJECT_OC = new OperationContextImpl(
- Collections.singleton("*"), true, true, true,
- IncludeRelationships.BOTH, Collections.singleton("*"), false, null,
- true, 1000);
-
- // object details must not be older than 60 seconds
- private static final long OLD = 60 * 1000;
-
- private ClientSession clientSession;
-
- private Folder currentFolder = null;
- private List<CmisObject> currentChildren = Collections.emptyList();
- private CmisObject currentObject = null;
-
- private EventListenerList listenerList = new EventListenerList();
-
- public ClientModel() {
-
- }
-
- public void addFolderListener(FolderListener listener) {
- listenerList.add(FolderListener.class, listener);
- }
-
- public void removeFolderListener(FolderListener listener) {
- listenerList.remove(FolderListener.class, listener);
- }
-
- public void addObjectListener(ObjectListener listener) {
- listenerList.add(ObjectListener.class, listener);
- }
-
- public void removeObjectListener(ObjectListener listener) {
- listenerList.remove(ObjectListener.class, listener);
- }
-
- public synchronized void setClientSession(ClientSession clientSession) {
- this.clientSession = clientSession;
- FOLDER_OC = createFolderOperationContext();
- }
-
- public synchronized RepositoryInfo getRepositoryInfo() throws Exception {
- Session session = clientSession.getSession();
- return session.getRepositoryInfo();
- }
-
- public synchronized String getRepositoryName() {
- try {
- return getRepositoryInfo().getName();
- } catch (Exception e) {
- return "?";
- }
- }
-
- public synchronized boolean supportsQuery() {
- try {
- RepositoryCapabilities cap = getRepositoryInfo().getCapabilities();
- if (cap == null) {
- return true;
- }
-
- return (cap.getQueryCapability() != null)
- && (cap.getQueryCapability() != CapabilityQuery.NONE);
- } catch (Exception e) {
- return false;
- }
- }
-
- public synchronized void loadFolder(String folderId, boolean byPath)
- throws Exception {
- try {
- Session session = clientSession.getSession();
- CmisObject folderObject = null;
-
- if (byPath) {
- folderObject = session.getObjectByPath(folderId);
- } else {
- folderObject = session.getObject(session
- .createObjectId(folderId));
- }
-
- if (!(folderObject instanceof Folder)) {
- throw new Exception("Not a folder!");
- }
-
- List<CmisObject> children = new ArrayList<CmisObject>();
- ItemIterable<CmisObject> iter = ((Folder) folderObject)
- .getChildren(FOLDER_OC);
- for (CmisObject child : iter) {
- children.add(child);
- }
-
- setCurrentFolder((Folder) folderObject, children);
- } catch (Exception ex) {
- setCurrentFolder(null, new ArrayList<CmisObject>(0));
- throw ex;
- }
- }
-
- public synchronized void reloadFolder() throws Exception {
- loadFolder(currentFolder.getId(), false);
- }
-
- public synchronized void loadObject(String objectId) throws Exception {
- try {
- Session session = clientSession.getSession();
- CmisObject object = session.getObject(session
- .createObjectId(objectId), OBJECT_OC);
- object.refreshIfOld(OLD);
-
- setObjectFolder(object);
- } catch (Exception ex) {
- setObjectFolder(null);
- throw ex;
- }
- }
-
- public synchronized ItemIterable<QueryResult> query(String q,
- boolean searchAllVersions, int maxHits) throws Exception {
- OperationContext queryContext = new OperationContextImpl(null, false,
- false, false, IncludeRelationships.NONE, null, false, null,
- false, maxHits);
-
- Session session = clientSession.getSession();
- return session.query(q, searchAllVersions, queryContext);
- }
-
- public synchronized List<Tree<ObjectType>> getTypeDescendants()
- throws Exception {
- Session session = clientSession.getSession();
- return session.getTypeDescendants(null, -1, true);
- }
-
- public ContentStream createContentStream(String filename) throws Exception {
- ContentStream content = null;
- if ((filename != null) && (filename.length() > 0)) {
- File file = new File(filename);
- InputStream stream = new FileInputStream(file);
-
- content = clientSession.getSession().getObjectFactory()
- .createContentStream(file.getName(), file.length(),
- MIMETypes.getMIMEType(file), stream);
- }
-
- return content;
- }
-
- public synchronized void createDocument(String name, String type,
- String filename, VersioningState versioningState) throws Exception {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(PropertyIds.NAME, name);
- properties.put(PropertyIds.OBJECT_TYPE_ID, type);
-
- ContentStream content = createContentStream(filename);
- clientSession.getSession().createDocument(properties, currentFolder,
- content, versioningState, null, null, null);
- }
-
- public synchronized void createFolder(String name, String type)
- throws Exception {
- Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(PropertyIds.NAME, name);
- properties.put(PropertyIds.OBJECT_TYPE_ID, type);
-
- clientSession.getSession().createFolder(properties, currentFolder,
- null, null, null);
- }
-
- public synchronized List<ObjectType> getCreateableTypes(String rootTypeId) {
- List<ObjectType> result = new ArrayList<ObjectType>();
-
- List<Tree<ObjectType>> types = clientSession.getSession()
- .getTypeDescendants(rootTypeId, -1, false);
- addType(types, result);
-
- ObjectType rootType = clientSession.getSession().getTypeDefinition(
- rootTypeId);
- boolean isCreatable = (rootType.isCreatable() == null ? true : rootType
- .isCreatable().booleanValue());
- if (isCreatable) {
- result.add(rootType);
- }
-
- Collections.sort(result, new Comparator<ObjectType>() {
- public int compare(ObjectType ot1, ObjectType ot2) {
- return ot1.getDisplayName().compareTo(ot2.getDisplayName());
- }
- });
-
- return result;
- }
-
- private void addType(List<Tree<ObjectType>> types,
- List<ObjectType> resultList) {
- for (Tree<ObjectType> tt : types) {
- if (tt.getItem() != null) {
- boolean isCreatable = (tt.getItem().isCreatable() == null ? true
- : tt.getItem().isCreatable().booleanValue());
-
- if (isCreatable) {
- resultList.add(tt.getItem());
- }
-
- addType(tt.getChildren(), resultList);
- }
- }
- }
-
- public synchronized Folder getCurrentFolder() {
- return currentFolder;
- }
-
- public synchronized List<CmisObject> getCurrentChildren() {
- return currentChildren;
- }
-
- private synchronized void setCurrentFolder(Folder folder,
- List<CmisObject> children) {
- currentFolder = folder;
- currentChildren = children;
-
- for (FolderListener fl : listenerList
- .getListeners(FolderListener.class)) {
- fl.folderLoaded(new ClientModelEvent(this));
- }
- }
-
- public synchronized CmisObject getCurrentObject() {
- return currentObject;
- }
-
- private synchronized void setObjectFolder(CmisObject object) {
- currentObject = object;
-
- for (ObjectListener ol : listenerList
- .getListeners(ObjectListener.class)) {
- ol.objectLoaded(new ClientModelEvent(this));
- }
- }
-
- private synchronized OperationContext createFolderOperationContext() {
- ObjectType type = clientSession.getSession().getTypeDefinition(
- BaseTypeId.CMIS_DOCUMENT.value());
-
- Set<String> filter = new HashSet<String>();
- for (String propId : PROPERTY_SET) {
- PropertyDefinition<?> propDef = type.getPropertyDefinitions().get(
- propId);
- if (propDef != null) {
- filter.add(propDef.getQueryName());
- }
- }
-
- return new OperationContextImpl(filter, false, true, false,
- IncludeRelationships.NONE, null, false, null, false, 1000);
- }
+ private static final Set<String> PROPERTY_SET = new HashSet<String>();
+ static {
+ PROPERTY_SET.add(PropertyIds.OBJECT_ID);
+ PROPERTY_SET.add(PropertyIds.OBJECT_TYPE_ID);
+ PROPERTY_SET.add(PropertyIds.NAME);
+ PROPERTY_SET.add(PropertyIds.CONTENT_STREAM_MIME_TYPE);
+ PROPERTY_SET.add(PropertyIds.CONTENT_STREAM_LENGTH);
+ PROPERTY_SET.add(PropertyIds.CONTENT_STREAM_FILE_NAME);
+ PROPERTY_SET.add(PropertyIds.CREATED_BY);
+ PROPERTY_SET.add(PropertyIds.CREATION_DATE);
+ PROPERTY_SET.add(PropertyIds.LAST_MODIFIED_BY);
+ PROPERTY_SET.add(PropertyIds.LAST_MODIFICATION_DATE);
+ }
+
+ private static OperationContext FOLDER_OC = null;
+
+ private static final OperationContext OBJECT_OC = new OperationContextImpl(Collections.singleton("*"), true, true,
+ true, IncludeRelationships.BOTH, Collections.singleton("*"), false, null, true, 1000);
+
+ // object details must not be older than 60 seconds
+ private static final long OLD = 60 * 1000;
+
+ private ClientSession clientSession;
+
+ private Folder currentFolder = null;
+ private List<CmisObject> currentChildren = Collections.emptyList();
+ private CmisObject currentObject = null;
+
+ private EventListenerList listenerList = new EventListenerList();
+
+ public ClientModel() {
+
+ }
+
+ public void addFolderListener(FolderListener listener) {
+ listenerList.add(FolderListener.class, listener);
+ }
+
+ public void removeFolderListener(FolderListener listener) {
+ listenerList.remove(FolderListener.class, listener);
+ }
+
+ public void addObjectListener(ObjectListener listener) {
+ listenerList.add(ObjectListener.class, listener);
+ }
+
+ public void removeObjectListener(ObjectListener listener) {
+ listenerList.remove(ObjectListener.class, listener);
+ }
+
+ public synchronized void setClientSession(ClientSession clientSession) {
+ this.clientSession = clientSession;
+ FOLDER_OC = createFolderOperationContext();
+ }
+
+ public synchronized RepositoryInfo getRepositoryInfo() throws Exception {
+ Session session = clientSession.getSession();
+ return session.getRepositoryInfo();
+ }
+
+ public synchronized String getRepositoryName() {
+ try {
+ return getRepositoryInfo().getName();
+ } catch (Exception e) {
+ return "?";
+ }
+ }
+
+ public synchronized boolean supportsQuery() {
+ try {
+ RepositoryCapabilities cap = getRepositoryInfo().getCapabilities();
+ if (cap == null) {
+ return true;
+ }
+
+ return (cap.getQueryCapability() != null) && (cap.getQueryCapability() != CapabilityQuery.NONE);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ public synchronized void loadFolder(String folderId, boolean byPath) throws Exception {
+ try {
+ Session session = clientSession.getSession();
+ CmisObject folderObject = null;
+
+ if (byPath) {
+ folderObject = session.getObjectByPath(folderId);
+ } else {
+ folderObject = session.getObject(session.createObjectId(folderId));
+ }
+
+ if (!(folderObject instanceof Folder)) {
+ throw new Exception("Not a folder!");
+ }
+
+ List<CmisObject> children = new ArrayList<CmisObject>();
+ ItemIterable<CmisObject> iter = ((Folder) folderObject).getChildren(FOLDER_OC);
+ for (CmisObject child : iter) {
+ children.add(child);
+ }
+
+ setCurrentFolder((Folder) folderObject, children);
+ } catch (Exception ex) {
+ setCurrentFolder(null, new ArrayList<CmisObject>(0));
+ throw ex;
+ }
+ }
+
+ public synchronized void reloadFolder() throws Exception {
+ loadFolder(currentFolder.getId(), false);
+ }
+
+ public synchronized void loadObject(String objectId) throws Exception {
+ try {
+ Session session = clientSession.getSession();
+ CmisObject object = session.getObject(session.createObjectId(objectId), OBJECT_OC);
+ object.refreshIfOld(OLD);
+
+ setCurrentObject(object);
+ } catch (Exception ex) {
+ setCurrentObject(null);
+ throw ex;
+ }
+ }
+
+ public synchronized void reloadObject() throws Exception {
+ if (currentObject == null) {
+ return;
+ }
+
+ try {
+ Session session = clientSession.getSession();
+ CmisObject object = session.getObject(currentObject, OBJECT_OC);
+ object.refresh();
+
+ setCurrentObject(object);
+ } catch (Exception ex) {
+ setCurrentObject(null);
+ throw ex;
+ }
+ }
+
+ public synchronized ItemIterable<QueryResult> query(String q, boolean searchAllVersions, int maxHits)
+ throws Exception {
+ OperationContext queryContext = new OperationContextImpl(null, false, false, false, IncludeRelationships.NONE,
+ null, false, null, false, maxHits);
+
+ Session session = clientSession.getSession();
+ return session.query(q, searchAllVersions, queryContext);
+ }
+
+ public synchronized List<Tree<ObjectType>> getTypeDescendants() throws Exception {
+ Session session = clientSession.getSession();
+ return session.getTypeDescendants(null, -1, true);
+ }
+
+ public ContentStream createContentStream(String filename) throws Exception {
+ ContentStream content = null;
+ if ((filename != null) && (filename.length() > 0)) {
+ File file = new File(filename);
+ InputStream stream = new FileInputStream(file);
+
+ content = clientSession.getSession().getObjectFactory().createContentStream(file.getName(), file.length(),
+ MIMETypes.getMIMEType(file), stream);
+ }
+
+ return content;
+ }
+
+ public synchronized void createDocument(String name, String type, String filename, VersioningState versioningState)
+ throws Exception {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(PropertyIds.NAME, name);
+ properties.put(PropertyIds.OBJECT_TYPE_ID, type);
+
+ ContentStream content = createContentStream(filename);
+ clientSession.getSession()
+ .createDocument(properties, currentFolder, content, versioningState, null, null, null);
+ }
+
+ public synchronized void createFolder(String name, String type) throws Exception {
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(PropertyIds.NAME, name);
+ properties.put(PropertyIds.OBJECT_TYPE_ID, type);
+
+ clientSession.getSession().createFolder(properties, currentFolder, null, null, null);
+ }
+
+ public synchronized List<ObjectType> getCreateableTypes(String rootTypeId) {
+ List<ObjectType> result = new ArrayList<ObjectType>();
+
+ List<Tree<ObjectType>> types = clientSession.getSession().getTypeDescendants(rootTypeId, -1, false);
+ addType(types, result);
+
+ ObjectType rootType = clientSession.getSession().getTypeDefinition(rootTypeId);
+ boolean isCreatable = (rootType.isCreatable() == null ? true : rootType.isCreatable().booleanValue());
+ if (isCreatable) {
+ result.add(rootType);
+ }
+
+ Collections.sort(result, new Comparator<ObjectType>() {
+ public int compare(ObjectType ot1, ObjectType ot2) {
+ return ot1.getDisplayName().compareTo(ot2.getDisplayName());
+ }
+ });
+
+ return result;
+ }
+
+ private void addType(List<Tree<ObjectType>> types, List<ObjectType> resultList) {
+ for (Tree<ObjectType> tt : types) {
+ if (tt.getItem() != null) {
+ boolean isCreatable = (tt.getItem().isCreatable() == null ? true : tt.getItem().isCreatable()
+ .booleanValue());
+
+ if (isCreatable) {
+ resultList.add(tt.getItem());
+ }
+
+ addType(tt.getChildren(), resultList);
+ }
+ }
+ }
+
+ public synchronized Folder getCurrentFolder() {
+ return currentFolder;
+ }
+
+ public synchronized List<CmisObject> getCurrentChildren() {
+ return currentChildren;
+ }
+
+ private synchronized void setCurrentFolder(Folder folder, List<CmisObject> children) {
+ currentFolder = folder;
+ currentChildren = children;
+
+ for (FolderListener fl : listenerList.getListeners(FolderListener.class)) {
+ fl.folderLoaded(new ClientModelEvent(this));
+ }
+ }
+
+ public synchronized CmisObject getCurrentObject() {
+ return currentObject;
+ }
+
+ private synchronized void setCurrentObject(CmisObject object) {
+ currentObject = object;
+
+ for (ObjectListener ol : listenerList.getListeners(ObjectListener.class)) {
+ ol.objectLoaded(new ClientModelEvent(this));
+ }
+ }
+
+ private synchronized OperationContext createFolderOperationContext() {
+ ObjectType type = clientSession.getSession().getTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value());
+
+ Set<String> filter = new HashSet<String>();
+ for (String propId : PROPERTY_SET) {
+ PropertyDefinition<?> propDef = type.getPropertyDefinitions().get(propId);
+ if (propDef != null) {
+ filter.add(propDef.getQueryName());
+ }
+ }
+
+ return new OperationContextImpl(filter, false, true, false, IncludeRelationships.NONE, null, false, null,
+ false, 1000);
+ }
}