This project has retired. For details please refer to its
Attic page.
VersionTable xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.workbench.details;
20
21 import java.awt.Cursor;
22 import java.awt.event.MouseEvent;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.concurrent.locks.ReentrantReadWriteLock;
26
27 import javax.swing.SwingUtilities;
28
29 import org.apache.chemistry.opencmis.client.api.Document;
30 import org.apache.chemistry.opencmis.client.api.ObjectId;
31 import org.apache.chemistry.opencmis.commons.enums.Action;
32 import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
33 import org.apache.chemistry.opencmis.workbench.ClientHelper;
34 import org.apache.chemistry.opencmis.workbench.model.ClientModel;
35 import org.apache.chemistry.opencmis.workbench.model.ClientModelEvent;
36
37 public class VersionTable extends AbstractDetailsTable {
38
39 private static final long serialVersionUID = 1L;
40
41 private static final String[] COLUMN_NAMES = { "Name", "Label", "Latest", "Major", "Latest Major", "Id",
42 "Filename", "MIME Type", "Length" };
43 private static final int[] COLUMN_WIDTHS = { 200, 200, 50, 50, 50, 400, 200, 100, 100 };
44
45 private List<Document> versions;
46 private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
47
48 public VersionTable(ClientModel model) {
49 super();
50
51 versions = Collections.emptyList();
52 init(model, COLUMN_NAMES, COLUMN_WIDTHS);
53 }
54
55 @Override
56 public void objectLoaded(ClientModelEvent event) {
57 lock.writeLock().lock();
58 try {
59 versions = Collections.emptyList();
60 } finally {
61 lock.writeLock().unlock();
62 }
63
64 if (getObject() instanceof Document) {
65 final Document doc = (Document) getObject();
66
67 if (doc.getAllowableActions().getAllowableActions().contains(Action.CAN_GET_ALL_VERSIONS)) {
68 SwingUtilities.invokeLater(new Runnable() {
69 @Override
70 public void run() {
71 try {
72 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
73 List<Document> newVersions = doc.getAllVersions(getClientModel().getClientSession()
74 .getVersionOperationContext());
75
76 lock.writeLock().lock();
77 try {
78 versions = newVersions;
79 } finally {
80 lock.writeLock().unlock();
81 }
82 } catch (Exception ex) {
83 if (!(ex instanceof CmisNotSupportedException)) {
84 ClientHelper.showError(null, ex);
85 }
86 } finally {
87 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
88 }
89 ((DetailsTableModel) getModel()).fireTableDataChanged();
90 }
91 });
92 }
93 }
94
95 super.objectLoaded(event);
96 }
97
98 @Override
99 public void singleClickAction(MouseEvent e, int rowIndex, int colIndex) {
100 if (getColumnClass(colIndex) != ObjectId.class) {
101 return;
102 }
103
104 String versionId = null;
105 lock.readLock().lock();
106 try {
107 versionId = versions.get(getRowSorter().convertRowIndexToModel(rowIndex)).getId();
108 } finally {
109 lock.readLock().unlock();
110 }
111
112 try {
113 getClientModel().loadObject(versionId);
114 setTab(0);
115 } catch (Exception ex) {
116 ClientHelper.showError(this, ex);
117 }
118 }
119
120 @Override
121 public void doubleClickAction(MouseEvent e, int rowIndex) {
122 lock.readLock().lock();
123 try {
124 if (e.isShiftDown()) {
125 ClientHelper.download(this.getParent(), versions.get(getRowSorter().convertRowIndexToModel(rowIndex)),
126 null);
127 } else {
128 ClientHelper
129 .open(this.getParent(), versions.get(getRowSorter().convertRowIndexToModel(rowIndex)), null);
130 }
131 } finally {
132 lock.readLock().unlock();
133 }
134 }
135
136 @Override
137 public int getDetailRowCount() {
138 if (!(getObject() instanceof Document)) {
139 return 0;
140 }
141
142 lock.readLock().lock();
143 try {
144 return versions.size();
145 } finally {
146 lock.readLock().unlock();
147 }
148 }
149
150 @Override
151 public Object getDetailValueAt(int rowIndex, int columnIndex) {
152 Document version = null;
153
154 lock.readLock().lock();
155 try {
156 version = versions.get(rowIndex);
157 } finally {
158 lock.readLock().unlock();
159 }
160
161 switch (columnIndex) {
162 case 0:
163 return version.getName();
164 case 1:
165 return version.getVersionLabel();
166 case 2:
167 return version.isLatestVersion();
168 case 3:
169 return version.isMajorVersion();
170 case 4:
171 return version.isLatestMajorVersion();
172 case 5:
173 return version;
174 case 6:
175 return version.getContentStreamFileName();
176 case 7:
177 return version.getContentStreamMimeType();
178 case 8:
179 return version.getContentStreamLength() == -1 ? null : version.getContentStreamLength();
180 }
181
182 return null;
183 }
184
185 @Override
186 public Class<?> getDetailColumClass(int columnIndex) {
187 if ((columnIndex == 2) || (columnIndex == 3) || (columnIndex == 4)) {
188 return Boolean.class;
189 } else if (columnIndex == 5) {
190 return ObjectId.class;
191 } else if (columnIndex == 8) {
192 return Long.class;
193 }
194
195 return super.getDetailColumClass(columnIndex);
196 }
197 }