2 * Copyright (C) 2007-2012 Mathieu Baudier
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
.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
;
42 * Centralizes the management of double click on an ArtifactTreeViewer
44 public class GenericDoubleClickListener
implements IDoubleClickListener
,
45 SlcTypes
, SlcNames
, DistConstants
{
47 private final static Log log
= LogFactory
48 .getLog(GenericDoubleClickListener
.class);
50 private TreeViewer viewer
;
52 private JcrFileProvider jfp
;
53 private FileHandler fileHandler
;
55 public GenericDoubleClickListener(TreeViewer viewer
) {
57 jfp
= new JcrFileProvider();
58 fileHandler
= new FileHandler(jfp
);
61 public void doubleClick(DoubleClickEvent event
) {
62 if (event
.getSelection() == null || event
.getSelection().isEmpty())
64 Object obj
= ((IStructuredSelection
) event
.getSelection())
67 if (obj
instanceof Node
) {
68 Node node
= (Node
) obj
;
69 if (node
.isNodeType(SLC_ARTIFACT_VERSION_BASE
)) {
70 GenericArtifactEditorInput gaei
= new GenericArtifactEditorInput(
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
);
82 } else if (obj
instanceof Row
) {
86 // uuid = row.getValue(
87 // SLC_ARTIFACT_VERSION_BASE + "." + JCR_IDENTIFIER)
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 + "."
96 // + " in order to open the artifact editor");
100 // row.getNode(SLC_ARTIFACT_VERSION_BASE).getSession()
101 // .getNodeByIdentifier(uuid);
103 Node node
= row
.getNode(SLC_ARTIFACT_VERSION_BASE
);
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");
112 GenericArtifactEditorInput gaei
= new GenericArtifactEditorInput(
114 DistPlugin
.getDefault().getWorkbench()
115 .getActiveWorkbenchWindow().getActivePage()
116 .openEditor(gaei
, GenericArtifactEditor
.ID
);
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
);