This project has retired. For details please refer to its
Attic page.
ClientFrame 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;
20
21 import java.awt.BorderLayout;
22 import java.awt.Container;
23 import java.awt.Cursor;
24 import java.awt.Dimension;
25 import java.awt.Image;
26 import java.awt.Point;
27 import java.awt.Window;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.WindowEvent;
31 import java.awt.event.WindowListener;
32 import java.io.File;
33 import java.lang.reflect.Method;
34 import java.net.URI;
35 import java.util.Collections;
36 import java.util.List;
37 import java.util.prefs.Preferences;
38
39 import javax.swing.ImageIcon;
40 import javax.swing.JButton;
41 import javax.swing.JFrame;
42 import javax.swing.JMenuItem;
43 import javax.swing.JPopupMenu;
44 import javax.swing.JSplitPane;
45 import javax.swing.JToolBar;
46
47 import org.apache.chemistry.opencmis.commons.SessionParameter;
48 import org.apache.chemistry.opencmis.workbench.ClientHelper.FileEntry;
49 import org.apache.chemistry.opencmis.workbench.details.DetailsTabs;
50 import org.apache.chemistry.opencmis.workbench.model.ClientModel;
51 import org.apache.chemistry.opencmis.workbench.model.ClientSession;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54
55 public class ClientFrame extends JFrame implements WindowListener {
56
57 private static final long serialVersionUID = 1L;
58
59 private static final Logger LOG = LoggerFactory.getLogger(ClientFrame.class);
60
61 public static final String SYSPROP_SCRIPTS = ClientSession.WORKBENCH_PREFIX + "scripts";
62
63 private static final String WINDOW_TITLE = "CMIS Workbench";
64
65 private static final int BUTTON_CONNECT = 0;
66 private static final int BUTTON_REPOSITORY_INFO = 1;
67 private static final int BUTTON_TYPES = 2;
68 private static final int BUTTON_QUERY = 3;
69 private static final int BUTTON_CHANGELOG = 4;
70 private static final int BUTTON_CONSOLE = 5;
71 private static final int BUTTON_TCK = 6;
72 private static final int BUTTON_CREATE = 7;
73 private static final int BUTTON_LOG = 8;
74 private static final int BUTTON_INFO = 9;
75
76 private static final String PREFS_X = "x";
77 private static final String PREFS_Y = "y";
78 private static final String PREFS_WIDTH = "width";
79 private static final String PREFS_HEIGHT = "height";
80 private static final String PREFS_DIV = "div";
81
82 private static final String GROOVY_SCRIPT_FOLDER = "/scripts/";
83 private static final String GROOVY_SCRIPT_LIBRARY = "script-library.properties";
84
85 private final Preferences prefs = Preferences.userNodeForPackage(this.getClass());
86
87 private LoginDialog loginDialog;
88 private LogFrame logFrame;
89 private InfoDialog infoDialog;
90
91 private JToolBar toolBar;
92 private JButton[] toolbarButton;
93 private JPopupMenu toolbarConsolePopup;
94 private JPopupMenu toolbarCreatePopup;
95 private JMenuItem documentMenuItem;
96 private JMenuItem itemMenuItem;
97 private JMenuItem folderMenuItem;
98 private JMenuItem relationshipMenuItem;
99
100 private JSplitPane split;
101 private FolderPanel folderPanel;
102 private DetailsTabs detailsTabs;
103
104 private final ClientModel model;
105
106 public ClientFrame() {
107 super();
108
109 model = new ClientModel();
110 createGUI();
111 showLoginForm();
112 }
113
114 private void createGUI() {
115 setTitle(WINDOW_TITLE);
116
117 ImageIcon icon = ClientHelper.getIcon("icon.png");
118 if (icon != null) {
119 setIconImage(icon.getImage());
120 }
121
122
123 if (ClientHelper.isMacOSX()) {
124 try {
125 Class<?> macAppClass = Class.forName("com.apple.eawt.Application");
126 Method macAppGetApp = macAppClass.getMethod("getApplication", (Class<?>[]) null);
127 Object macApp = macAppGetApp.invoke(null, (Object[]) null);
128
129 if (icon != null) {
130 try {
131 macAppClass.getMethod("setDockIconImage", new Class<?>[] { Image.class }).invoke(macApp,
132 new Object[] { icon.getImage() });
133 } catch (Exception e) {
134 LOG.debug("Could not set dock icon!", e);
135 }
136 }
137
138 try {
139 Class<?> fullscreenClass = Class.forName("com.apple.eawt.FullScreenUtilities");
140 fullscreenClass.getMethod("setWindowCanFullScreen", new Class<?>[] { Window.class, Boolean.TYPE })
141 .invoke(fullscreenClass, this, true);
142 } catch (Exception e) {
143 LOG.debug("Could not add fullscreen button!", e);
144 }
145 } catch (Exception e) {
146 LOG.debug("Could not get com.apple.eawt.Application object!", e);
147 }
148 }
149
150 setLayout(new BorderLayout());
151
152 final ClientFrame thisFrame = this;
153 loginDialog = new LoginDialog(this);
154 logFrame = new LogFrame();
155 infoDialog = new InfoDialog(this);
156
157 Container pane = getContentPane();
158
159 toolBar = new JToolBar("CMIS Toolbar", JToolBar.HORIZONTAL);
160
161 toolbarButton = new JButton[10];
162
163 toolbarButton[BUTTON_CONNECT] = new JButton("Connection", ClientHelper.getIcon("connect.png"));
164 toolbarButton[BUTTON_CONNECT].addActionListener(new ActionListener() {
165 public void actionPerformed(ActionEvent e) {
166 showLoginForm();
167 }
168 });
169
170 toolBar.add(toolbarButton[BUTTON_CONNECT]);
171
172 toolBar.addSeparator();
173
174 toolbarButton[BUTTON_REPOSITORY_INFO] = new JButton("Repository Info",
175 ClientHelper.getIcon("repository-info.png"));
176 toolbarButton[BUTTON_REPOSITORY_INFO].setEnabled(false);
177 toolbarButton[BUTTON_REPOSITORY_INFO].addActionListener(new ActionListener() {
178 public void actionPerformed(ActionEvent e) {
179 new RepositoryInfoFrame(model);
180 }
181 });
182
183 toolBar.add(toolbarButton[BUTTON_REPOSITORY_INFO]);
184
185 toolbarButton[BUTTON_TYPES] = new JButton("Types", ClientHelper.getIcon("types.png"));
186 toolbarButton[BUTTON_TYPES].setEnabled(false);
187 toolbarButton[BUTTON_TYPES].addActionListener(new ActionListener() {
188 public void actionPerformed(ActionEvent e) {
189 new TypesFrame(model);
190 }
191 });
192
193 toolBar.add(toolbarButton[BUTTON_TYPES]);
194
195 toolbarButton[BUTTON_QUERY] = new JButton("Query", ClientHelper.getIcon("query.png"));
196 toolbarButton[BUTTON_QUERY].setEnabled(false);
197 toolbarButton[BUTTON_QUERY].addActionListener(new ActionListener() {
198 public void actionPerformed(ActionEvent e) {
199 new QueryFrame(model);
200 }
201 });
202
203 toolBar.add(toolbarButton[BUTTON_QUERY]);
204
205 toolbarButton[BUTTON_CHANGELOG] = new JButton("Change Log", ClientHelper.getIcon("changelog.png"));
206 toolbarButton[BUTTON_CHANGELOG].setEnabled(false);
207 toolbarButton[BUTTON_CHANGELOG].addActionListener(new ActionListener() {
208 public void actionPerformed(ActionEvent e) {
209 new ChangeLogFrame(model);
210 }
211 });
212
213 toolBar.add(toolbarButton[BUTTON_CHANGELOG]);
214
215 toolbarButton[BUTTON_CONSOLE] = new JButton("Console", ClientHelper.getIcon("console.png"));
216 toolbarButton[BUTTON_CONSOLE].setEnabled(false);
217 toolbarButton[BUTTON_CONSOLE].addActionListener(new ActionListener() {
218 public void actionPerformed(ActionEvent e) {
219 toolbarConsolePopup.show(toolbarButton[BUTTON_CONSOLE], 0, toolbarButton[BUTTON_CONSOLE].getHeight());
220 }
221 });
222
223 toolBar.add(toolbarButton[BUTTON_CONSOLE]);
224
225 toolbarConsolePopup = new JPopupMenu();
226 for (FileEntry fe : readScriptLibrary()) {
227 JMenuItem menuItem = new JMenuItem(fe.getName());
228 final URI file = fe.getFile();
229 menuItem.addActionListener(new ActionListener() {
230 @Override
231 public void actionPerformed(ActionEvent e) {
232 ClientHelper.openConsole(ClientFrame.this, model, file);
233 }
234 });
235 toolbarConsolePopup.add(menuItem);
236 }
237
238 toolbarButton[BUTTON_TCK] = new JButton("TCK", ClientHelper.getIcon("tck.png"));
239 toolbarButton[BUTTON_TCK].setEnabled(false);
240 toolbarButton[BUTTON_TCK].addActionListener(new ActionListener() {
241 public void actionPerformed(ActionEvent e) {
242 new TckDialog(thisFrame, model);
243 }
244 });
245
246 toolBar.add(toolbarButton[BUTTON_TCK]);
247
248 toolBar.addSeparator();
249
250 toolbarCreatePopup = new JPopupMenu();
251 documentMenuItem = new JMenuItem("Document");
252 documentMenuItem.setEnabled(true);
253 toolbarCreatePopup.add(documentMenuItem);
254 documentMenuItem.addActionListener(new ActionListener() {
255 @Override
256 public void actionPerformed(ActionEvent event) {
257 new CreateDocumentDialog(thisFrame, model);
258 }
259 });
260
261 itemMenuItem = new JMenuItem("Item");
262 itemMenuItem.setEnabled(false);
263 toolbarCreatePopup.add(itemMenuItem);
264 itemMenuItem.addActionListener(new ActionListener() {
265 @Override
266 public void actionPerformed(ActionEvent event) {
267 new CreateItemDialog(thisFrame, model);
268 }
269 });
270
271 folderMenuItem = new JMenuItem("Folder");
272 folderMenuItem.setEnabled(true);
273 toolbarCreatePopup.add(folderMenuItem);
274 folderMenuItem.addActionListener(new ActionListener() {
275 @Override
276 public void actionPerformed(ActionEvent event) {
277 new CreateFolderDialog(thisFrame, model);
278 }
279 });
280
281 relationshipMenuItem = new JMenuItem("Relationship");
282 relationshipMenuItem.setEnabled(false);
283 toolbarCreatePopup.add(relationshipMenuItem);
284 relationshipMenuItem.addActionListener(new ActionListener() {
285 @Override
286 public void actionPerformed(ActionEvent event) {
287 new CreateRelationshipDialog(thisFrame, model);
288 }
289 });
290
291 toolbarButton[BUTTON_CREATE] = new JButton("Create Object", ClientHelper.getIcon("newdocument.png"));
292 toolbarButton[BUTTON_CREATE].setEnabled(false);
293 toolbarButton[BUTTON_CREATE].addActionListener(new ActionListener() {
294 public void actionPerformed(ActionEvent e) {
295 toolbarCreatePopup.show(toolbarButton[BUTTON_CREATE], 0, toolbarButton[BUTTON_CREATE].getHeight());
296 }
297 });
298
299 toolBar.add(toolbarButton[BUTTON_CREATE]);
300
301 toolBar.addSeparator();
302
303 toolbarButton[BUTTON_LOG] = new JButton("Log", ClientHelper.getIcon("log.png"));
304 toolbarButton[BUTTON_LOG].addActionListener(new ActionListener() {
305 public void actionPerformed(ActionEvent e) {
306 logFrame.showFrame();
307 }
308 });
309
310 toolBar.add(toolbarButton[BUTTON_LOG]);
311
312 toolbarButton[BUTTON_INFO] = new JButton("Info", ClientHelper.getIcon("info.png"));
313 toolbarButton[BUTTON_INFO].addActionListener(new ActionListener() {
314 public void actionPerformed(ActionEvent e) {
315 infoDialog.showDialog();
316 }
317 });
318
319 toolBar.add(toolbarButton[BUTTON_INFO]);
320
321 pane.add(toolBar, BorderLayout.PAGE_START);
322
323 folderPanel = new FolderPanel(model);
324 detailsTabs = new DetailsTabs(model);
325
326 split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, folderPanel, detailsTabs);
327
328 pane.add(split, BorderLayout.CENTER);
329
330 addWindowListener(this);
331
332 setPreferredSize(new Dimension(prefs.getInt(PREFS_WIDTH, 1000), prefs.getInt(PREFS_HEIGHT, 600)));
333 setMinimumSize(new Dimension(200, 60));
334
335 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
336 pack();
337
338 split.setDividerLocation(prefs.getInt(PREFS_DIV, 500));
339
340 if (prefs.getInt(PREFS_X, Integer.MAX_VALUE) == Integer.MAX_VALUE) {
341 setLocationRelativeTo(null);
342 } else {
343 setLocation(prefs.getInt(PREFS_X, 0), prefs.getInt(PREFS_Y, 0));
344 }
345
346 setVisible(true);
347 }
348
349 private void showLoginForm() {
350 loginDialog.showDialog();
351 if (!loginDialog.isCanceled()) {
352 ClientSession clientSession = loginDialog.getClientSession();
353
354 model.setClientSession(clientSession);
355
356 try {
357 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
358
359 model.loadFolder(clientSession.getSession().getRepositoryInfo().getRootFolderId(), false);
360 model.loadObject(clientSession.getSession().getRepositoryInfo().getRootFolderId());
361
362 toolbarButton[BUTTON_REPOSITORY_INFO].setEnabled(true);
363 toolbarButton[BUTTON_TYPES].setEnabled(true);
364 toolbarButton[BUTTON_QUERY].setEnabled(model.supportsQuery());
365 toolbarButton[BUTTON_CHANGELOG].setEnabled(model.supportsChangeLog());
366 toolbarButton[BUTTON_CONSOLE].setEnabled(true);
367 toolbarButton[BUTTON_TCK].setEnabled(true);
368 toolbarButton[BUTTON_CREATE].setEnabled(true);
369
370 itemMenuItem.setEnabled(model.supportsItems());
371 relationshipMenuItem.setEnabled(model.supportsRelationships());
372
373 String user = clientSession.getSessionParameters().get(SessionParameter.USER);
374 if (user != null) {
375 user = " - (" + user + ")";
376 } else {
377 user = "";
378 }
379
380 setTitle(WINDOW_TITLE + user + " - " + clientSession.getSession().getRepositoryInfo().getName());
381 } catch (Exception ex) {
382 toolbarButton[BUTTON_REPOSITORY_INFO].setEnabled(false);
383 toolbarButton[BUTTON_TYPES].setEnabled(false);
384 toolbarButton[BUTTON_QUERY].setEnabled(false);
385 toolbarButton[BUTTON_CHANGELOG].setEnabled(false);
386 toolbarButton[BUTTON_CONSOLE].setEnabled(false);
387 toolbarButton[BUTTON_TCK].setEnabled(false);
388 toolbarButton[BUTTON_CREATE].setEnabled(false);
389
390 ClientHelper.showError(null, ex);
391
392 setTitle(WINDOW_TITLE);
393 } finally {
394 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
395 }
396 }
397 }
398
399 private List<FileEntry> readScriptLibrary() {
400
401 URI propFile = null;
402
403 String externalScripts = System.getProperty(SYSPROP_SCRIPTS);
404 if (externalScripts == null) {
405 propFile = ClientHelper.getClasspathURI(GROOVY_SCRIPT_FOLDER + GROOVY_SCRIPT_LIBRARY);
406 } else {
407 propFile = (new File(externalScripts)).toURI();
408 }
409
410 List<FileEntry> result = ClientHelper.readFileProperties(propFile);
411
412 if (result == null || result.isEmpty()) {
413 result = Collections.singletonList(new FileEntry("Groovy Console", null));
414 }
415
416 return result;
417 }
418
419 public void windowOpened(WindowEvent e) {
420 }
421
422 public void windowClosing(WindowEvent e) {
423 Point p = getLocation();
424 prefs.putInt(PREFS_X, p.x);
425 prefs.putInt(PREFS_Y, p.y);
426 prefs.putInt(PREFS_WIDTH, getWidth());
427 prefs.putInt(PREFS_HEIGHT, getHeight());
428 prefs.putInt(PREFS_DIV, split.getDividerLocation());
429 }
430
431 public void windowClosed(WindowEvent e) {
432 }
433
434 public void windowIconified(WindowEvent e) {
435 }
436
437 public void windowDeiconified(WindowEvent e) {
438 }
439
440 public void windowActivated(WindowEvent e) {
441 }
442
443 public void windowDeactivated(WindowEvent e) {
444 }
445 }