2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.client
.ui
.dist
.utils
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
20 import javax
.jcr
.nodetype
.NodeType
;
21 import javax
.jcr
.query
.Row
;
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
;
39 * Centralizes the management of double click on an viewer that displays
42 public class GenericDoubleClickListener
implements IDoubleClickListener
,
43 SlcTypes
, SlcNames
, DistConstants
{
45 // private final static Log log = LogFactory
46 // .getLog(GenericDoubleClickListener.class);
48 private JcrFileProvider jfp
;
49 private FileHandler fileHandler
;
51 public GenericDoubleClickListener() {
52 jfp
= new JcrFileProvider();
53 fileHandler
= new FileHandler(jfp
);
56 public void doubleClick(DoubleClickEvent event
) {
57 if (event
.getSelection() == null || event
.getSelection().isEmpty())
59 Object obj
= ((IStructuredSelection
) event
.getSelection())
62 if (obj
instanceof Node
) {
63 Node node
= (Node
) obj
;
64 if (node
.isNodeType(SLC_ARTIFACT_VERSION_BASE
)) {
65 GenericBundleEditorInput gaei
= new GenericBundleEditorInput(
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
);
77 } else if (obj
instanceof Row
) {
81 // uuid = row.getValue(
82 // SLC_ARTIFACT_VERSION_BASE + "." + JCR_IDENTIFIER)
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 + "."
91 // + " in order to open the artifact editor");
95 // row.getNode(SLC_ARTIFACT_VERSION_BASE).getSession()
96 // .getNodeByIdentifier(uuid);
98 Node node
= row
.getNode(SLC_ARTIFACT_VERSION_BASE
);
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");
107 GenericBundleEditorInput gaei
= new GenericBundleEditorInput(
109 DistPlugin
.getDefault().getWorkbench()
110 .getActiveWorkbenchWindow().getActivePage()
111 .openEditor(gaei
, GenericBundleEditor
.ID
);
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
);