This project has retired. For details please refer to its Attic page.
RepositoryInfoFrame xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.workbench;
20  
21  import java.awt.Dimension;
22  import java.util.List;
23  
24  import javax.swing.JFrame;
25  import javax.swing.JScrollPane;
26  import javax.swing.JTable;
27  import javax.swing.JTree;
28  import javax.swing.tree.DefaultMutableTreeNode;
29  import javax.swing.tree.DefaultTreeModel;
30  import javax.swing.tree.TreeSelectionModel;
31  
32  import org.apache.chemistry.opencmis.commons.data.AclCapabilities;
33  import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
34  import org.apache.chemistry.opencmis.commons.data.PermissionMapping;
35  import org.apache.chemistry.opencmis.commons.data.RepositoryCapabilities;
36  import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
37  import org.apache.chemistry.opencmis.commons.definitions.PermissionDefinition;
38  import org.apache.chemistry.opencmis.workbench.model.ClientModel;
39  import org.apache.chemistry.opencmis.workbench.swing.InfoPanel;
40  
41  public class RepositoryInfoFrame extends JFrame {
42  
43      private static final long serialVersionUID = 1L;
44  
45      private static final String WINDOW_TITLE = "CMIS Repository Info";
46  
47      private final ClientModel model;
48  
49      public RepositoryInfoFrame(ClientModel model) {
50          super();
51  
52          this.model = model;
53          createGUI();
54      }
55  
56      private void createGUI() {
57          setTitle(WINDOW_TITLE + " - " + model.getRepositoryName());
58          setPreferredSize(new Dimension(700, 700));
59          setMinimumSize(new Dimension(200, 60));
60  
61          RepositoryInfo repInfo = null;
62          try {
63              repInfo = model.getRepositoryInfo();
64          } catch (Exception e) {
65              ClientHelper.showError(this, e);
66              dispose();
67              return;
68          }
69  
70          add(new JScrollPane(new RepositoryInfoPanel(model, repInfo)));
71  
72          ClientHelper.installEscapeBinding(this, getRootPane(), true);
73  
74          setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
75          pack();
76  
77          setLocationRelativeTo(null);
78          setVisible(true);
79      }
80  
81      static class RepositoryInfoPanel extends InfoPanel {
82  
83          private static final long serialVersionUID = 1L;
84  
85          private final RepositoryInfo repInfo;
86  
87          public RepositoryInfoPanel(ClientModel model, RepositoryInfo repInfo) {
88              super(model);
89  
90              this.repInfo = repInfo;
91              createGUI();
92          }
93  
94          private void createGUI() {
95              setupGUI();
96  
97              addLine("Name:", true).setText(repInfo.getName());
98              addLine("Id:").setText(repInfo.getId());
99              addLine("Description:").setText(repInfo.getDescription());
100             addLine("Vendor:").setText(repInfo.getVendorName());
101             addLine("Product:").setText(repInfo.getProductName() + " " + repInfo.getProductVersion());
102             addLine("CMIS Version:").setText(repInfo.getCmisVersionSupported());
103             addId("Root folder Id:").setText(repInfo.getRootFolderId());
104             addLine("Latest change token:").setText(repInfo.getLatestChangeLogToken());
105             addLink("Thin client URI:").setText(repInfo.getThinClientUri());
106             addLine("Principal id anonymous:").setText(repInfo.getPrincipalIdAnonymous());
107             addLine("Principal id anyone:").setText(repInfo.getPrincipalIdAnyone());
108             addYesNoLabel("Changes incomplete:").setValue(is(repInfo.getChangesIncomplete()));
109             addLine("Changes on type:").setText(
110                     repInfo.getChangesOnType() == null ? "" : repInfo.getChangesOnType().toString());
111 
112             if (repInfo.getCapabilities() != null) {
113                 RepositoryCapabilities cap = repInfo.getCapabilities();
114 
115                 addLine("Capabilities", true).setText("");
116 
117                 addYesNoLabel("Get descendants supported:").setValue(is(cap.isGetDescendantsSupported()));
118                 addYesNoLabel("Get folder tree supported:").setValue(is(cap.isGetFolderTreeSupported()));
119                 addYesNoLabel("Unfiling supported:").setValue(is(cap.isUnfilingSupported()));
120                 addYesNoLabel("Multifiling supported:").setValue(is(cap.isMultifilingSupported()));
121                 addYesNoLabel("Version specific filing supported:")
122                         .setValue(is(cap.isVersionSpecificFilingSupported()));
123                 addLine("Query:").setText(str(cap.getQueryCapability()));
124                 addLine("Joins:").setText(str(cap.getJoinCapability()));
125                 addYesNoLabel("All versions searchable:").setValue(is(cap.isAllVersionsSearchableSupported()));
126                 addYesNoLabel("PWC searchable:").setValue(is(cap.isPwcSearchableSupported()));
127                 addYesNoLabel("PWC updatable:").setValue(is(cap.isPwcUpdatableSupported()));
128                 addLine("Content stream updates:").setText(str(cap.getContentStreamUpdatesCapability()));
129                 addLine("Renditions:").setText(str(cap.getRenditionsCapability()));
130                 addLine("Changes:").setText(str(cap.getChangesCapability()));
131                 addLine("ACLs:").setText(str(cap.getAclCapability()));
132             }
133 
134             if (repInfo.getAclCapabilities() != null) {
135                 AclCapabilities cap = repInfo.getAclCapabilities();
136 
137                 addLine("ACL Capabilities:", true).setText("");
138 
139                 addLine("Supported permissions:").setText(str(cap.getSupportedPermissions()));
140                 addLine("ACL propagation:").setText(str(cap.getAclPropagation()));
141 
142                 if (cap.getPermissions() != null) {
143                     String[][] data = new String[cap.getPermissions().size()][2];
144 
145                     int i = 0;
146                     for (PermissionDefinition pd : cap.getPermissions()) {
147                         data[i][0] = pd.getId();
148                         data[i][1] = pd.getDescription();
149                         i++;
150                     }
151 
152                     JTable permTable = new JTable(data, new String[] { "Permission", "Description" });
153                     permTable.setFillsViewportHeight(true);
154                     addComponent("Permissions:", new JScrollPane(permTable));
155                 }
156 
157                 if (cap.getPermissionMapping() != null) {
158                     String[][] data = new String[cap.getPermissionMapping().size()][2];
159 
160                     int i = 0;
161                     for (PermissionMapping pm : cap.getPermissionMapping().values()) {
162                         data[i][0] = pm.getKey();
163                         data[i][1] = (pm.getPermissions() == null ? "" : pm.getPermissions().toString());
164                         i++;
165                     }
166 
167                     JTable permMapTable = new JTable(data, new String[] { "Key", "Permissions" });
168                     permMapTable.setFillsViewportHeight(true);
169                     addComponent("Permission mapping:", new JScrollPane(permMapTable));
170                 }
171             }
172 
173             if (repInfo.getExtensions() != null && !repInfo.getExtensions().isEmpty()) {
174                 JTree extensionsTree = new JTree();
175                 extensionsTree.setRootVisible(false);
176                 extensionsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
177 
178                 DefaultMutableTreeNode extRootNode = new DefaultMutableTreeNode("Extensions");
179                 addExtension(extRootNode, repInfo.getExtensions());
180 
181                 extensionsTree.setModel(new DefaultTreeModel(extRootNode));
182 
183                 addComponent("Extensions:", new JScrollPane(extensionsTree));
184             }
185         }
186 
187         private void addExtension(DefaultMutableTreeNode parent, List<CmisExtensionElement> extensions) {
188             if ((extensions == null) || (extensions.isEmpty())) {
189                 return;
190             }
191 
192             for (CmisExtensionElement ext : extensions) {
193                 DefaultMutableTreeNode node = new DefaultMutableTreeNode(new ExtensionNode(ext));
194                 parent.add(node);
195 
196                 if (ext.getChildren().size() > 0) {
197                     addExtension(node, ext.getChildren());
198                 }
199             }
200         }
201 
202         private boolean is(Boolean b) {
203             if (b == null) {
204                 return false;
205             }
206 
207             return b.booleanValue();
208         }
209 
210         private String str(Object o) {
211             if (o == null) {
212                 return "?";
213             }
214 
215             return o.toString();
216         }
217 
218         static class ExtensionNode {
219             private final CmisExtensionElement extension;
220 
221             public ExtensionNode(CmisExtensionElement extension) {
222                 this.extension = extension;
223             }
224 
225             @Override
226             public String toString() {
227                 return (extension.getNamespace() == null ? "" : "{" + extension.getNamespace() + "}")
228                         + extension.getName()
229                         + (!extension.getAttributes().isEmpty() ? " " + extension.getAttributes() : "")
230                         + (extension.getChildren().isEmpty() ? ": " + extension.getValue() : "");
231             }
232         }
233     }
234 }