]> 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
fix grouping issue for workspaces that have the same prefix.
[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 Argeo GmbH
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.argeo.ArgeoException;
24 import org.argeo.eclipse.ui.jcr.utils.JcrFileProvider;
25 import org.argeo.eclipse.ui.specific.FileHandler;
26 import org.argeo.slc.client.ui.dist.DistConstants;
27 import org.argeo.slc.client.ui.dist.DistPlugin;
28 import org.argeo.slc.client.ui.dist.editors.GenericBundleEditor;
29 import org.argeo.slc.client.ui.dist.editors.GenericBundleEditorInput;
30 import org.argeo.slc.jcr.SlcNames;
31 import org.argeo.slc.jcr.SlcTypes;
32 import org.eclipse.jface.dialogs.MessageDialog;
33 import org.eclipse.jface.viewers.DoubleClickEvent;
34 import org.eclipse.jface.viewers.IDoubleClickListener;
35 import org.eclipse.jface.viewers.IStructuredSelection;
36 import org.eclipse.ui.PartInitException;
37
38 /**
39 * Centralizes the management of double click on an viewer that displays
40 * artifacts.
41 */
42 public class GenericDoubleClickListener implements IDoubleClickListener,
43 SlcTypes, SlcNames, DistConstants {
44
45 // private final static Log log = LogFactory
46 // .getLog(GenericDoubleClickListener.class);
47
48 private JcrFileProvider jfp;
49 private FileHandler fileHandler;
50
51 public GenericDoubleClickListener() {
52 jfp = new JcrFileProvider();
53 fileHandler = new FileHandler(jfp);
54 }
55
56 public void doubleClick(DoubleClickEvent event) {
57 if (event.getSelection() == null || event.getSelection().isEmpty())
58 return;
59 Object obj = ((IStructuredSelection) event.getSelection())
60 .getFirstElement();
61 try {
62 if (obj instanceof Node) {
63 Node node = (Node) obj;
64 if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE)) {
65 GenericBundleEditorInput gaei = new GenericBundleEditorInput(
66 node);
67 DistPlugin.getDefault().getWorkbench()
68 .getActiveWorkbenchWindow().getActivePage()
69 .openEditor(gaei, GenericBundleEditor.ID);
70 } else if (node.isNodeType(NodeType.NT_FILE)) {
71 String name = node.getName();
72 String id = node.getIdentifier();
73 jfp.setReferenceNode(node);
74 fileHandler.openFile(name, id);
75 }
76
77 } else if (obj instanceof Row) {
78 Row row = (Row) obj;
79 // String uuid;
80 // try {
81 // uuid = row.getValue(
82 // SLC_ARTIFACT_VERSION_BASE + "." + JCR_IDENTIFIER)
83 // .getString();
84 // } catch (ItemNotFoundException infe) {
85 // MessageDialog.openError(DistPlugin.getDefault()
86 // .getWorkbench().getActiveWorkbenchWindow()
87 // .getShell(), "Invalid request",
88 // "The request must return a value for "
89 // + SLC_ARTIFACT_VERSION_BASE + "."
90 // + JCR_IDENTIFIER
91 // + " in order to open the artifact editor");
92 // return;
93 // }
94 // Node node =
95 // row.getNode(SLC_ARTIFACT_VERSION_BASE).getSession()
96 // .getNodeByIdentifier(uuid);
97
98 Node node = row.getNode(SLC_ARTIFACT_VERSION_BASE);
99 if (node == null)
100 MessageDialog.openError(DistPlugin.getDefault()
101 .getWorkbench().getActiveWorkbenchWindow()
102 .getShell(), "Invalid request",
103 "The request must return a "
104 + SLC_ARTIFACT_VERSION_BASE + " node "
105 + " in order to open the artifact editor");
106 else {
107 GenericBundleEditorInput gaei = new GenericBundleEditorInput(
108 node);
109 DistPlugin.getDefault().getWorkbench()
110 .getActiveWorkbenchWindow().getActivePage()
111 .openEditor(gaei, GenericBundleEditor.ID);
112 }
113 }
114 } catch (RepositoryException re) {
115 throw new ArgeoException(
116 "Repository error while getting node info", re);
117 } catch (PartInitException pie) {
118 throw new ArgeoException(
119 "Unexepected exception while opening artifact editor", pie);
120 }
121 }
122 }