]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/utils/GenericDoubleClickListener.java
d18b3f0f184e1ed6b3f1e4f82f4caa59b9c7afc6
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / utils / GenericDoubleClickListener.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.client.ui.dist.utils;
17
18 import javax.jcr.Node;
19 import javax.jcr.RepositoryException;
20 import javax.jcr.nodetype.NodeType;
21 import javax.jcr.query.Row;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.argeo.ArgeoException;
26 import org.argeo.eclipse.ui.jcr.utils.JcrFileProvider;
27 import org.argeo.eclipse.ui.specific.FileHandler;
28 import org.argeo.slc.client.ui.dist.DistConstants;
29 import org.argeo.slc.client.ui.dist.DistPlugin;
30 import org.argeo.slc.client.ui.dist.editors.GenericArtifactEditor;
31 import org.argeo.slc.client.ui.dist.editors.GenericArtifactEditorInput;
32 import org.argeo.slc.jcr.SlcNames;
33 import org.argeo.slc.jcr.SlcTypes;
34 import org.eclipse.jface.dialogs.MessageDialog;
35 import org.eclipse.jface.viewers.DoubleClickEvent;
36 import org.eclipse.jface.viewers.IDoubleClickListener;
37 import org.eclipse.jface.viewers.IStructuredSelection;
38 import org.eclipse.jface.viewers.TreeViewer;
39 import org.eclipse.ui.PartInitException;
40
41 /**
42 * Centralizes the management of double click on an ArtifactTreeViewer
43 */
44 public class GenericDoubleClickListener implements IDoubleClickListener,
45 SlcTypes, SlcNames, DistConstants {
46
47 private final static Log log = LogFactory
48 .getLog(GenericDoubleClickListener.class);
49
50 private TreeViewer viewer;
51
52 private JcrFileProvider jfp;
53 private FileHandler fileHandler;
54
55 public GenericDoubleClickListener(TreeViewer viewer) {
56 this.viewer = viewer;
57 jfp = new JcrFileProvider();
58 fileHandler = new FileHandler(jfp);
59 }
60
61 public void doubleClick(DoubleClickEvent event) {
62 if (event.getSelection() == null || event.getSelection().isEmpty())
63 return;
64 Object obj = ((IStructuredSelection) event.getSelection())
65 .getFirstElement();
66 try {
67 if (obj instanceof Node) {
68 Node node = (Node) obj;
69 if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE)) {
70 GenericArtifactEditorInput gaei = new GenericArtifactEditorInput(
71 node);
72 DistPlugin.getDefault().getWorkbench()
73 .getActiveWorkbenchWindow().getActivePage()
74 .openEditor(gaei, GenericArtifactEditor.ID);
75 } else if (node.isNodeType(NodeType.NT_FILE)) {
76 String name = node.getName();
77 String id = node.getIdentifier();
78 jfp.setReferenceNode(node);
79 fileHandler.openFile(name, id);
80 }
81
82 } else if (obj instanceof Row) {
83 Row row = (Row) obj;
84 // String uuid;
85 // try {
86 // uuid = row.getValue(
87 // SLC_ARTIFACT_VERSION_BASE + "." + JCR_IDENTIFIER)
88 // .getString();
89 // } catch (ItemNotFoundException infe) {
90 // MessageDialog.openError(DistPlugin.getDefault()
91 // .getWorkbench().getActiveWorkbenchWindow()
92 // .getShell(), "Invalid request",
93 // "The request must return a value for "
94 // + SLC_ARTIFACT_VERSION_BASE + "."
95 // + JCR_IDENTIFIER
96 // + " in order to open the artifact editor");
97 // return;
98 // }
99 // Node node =
100 // row.getNode(SLC_ARTIFACT_VERSION_BASE).getSession()
101 // .getNodeByIdentifier(uuid);
102
103 Node node = row.getNode(SLC_ARTIFACT_VERSION_BASE);
104 if (node == null)
105 MessageDialog.openError(DistPlugin.getDefault()
106 .getWorkbench().getActiveWorkbenchWindow()
107 .getShell(), "Invalid request",
108 "The request must return a "
109 + SLC_ARTIFACT_VERSION_BASE + " node "
110 + " in order to open the artifact editor");
111 else {
112 GenericArtifactEditorInput gaei = new GenericArtifactEditorInput(
113 node);
114 DistPlugin.getDefault().getWorkbench()
115 .getActiveWorkbenchWindow().getActivePage()
116 .openEditor(gaei, GenericArtifactEditor.ID);
117 }
118 }
119 } catch (RepositoryException re) {
120 throw new ArgeoException(
121 "Repository error while getting node info", re);
122 } catch (PartInitException pie) {
123 throw new ArgeoException(
124 "Unexepected exception while opening artifact editor", pie);
125 }
126 }
127 }