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
.eclipse
.ui
.workbench
.jcr
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.RepositoryException
;
23 import javax
.jcr
.nodetype
.NodeType
;
24 import javax
.jcr
.security
.AccessControlManager
;
25 import javax
.jcr
.security
.Privilege
;
27 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
28 import org
.argeo
.eclipse
.ui
.workbench
.WorkbenchUiPlugin
;
29 import org
.argeo
.eclipse
.ui
.workbench
.internal
.jcr
.parts
.ChildNodesPage
;
30 import org
.argeo
.eclipse
.ui
.workbench
.internal
.jcr
.parts
.GenericNodeEditorInput
;
31 import org
.argeo
.eclipse
.ui
.workbench
.internal
.jcr
.parts
.GenericNodePage
;
32 import org
.argeo
.eclipse
.ui
.workbench
.internal
.jcr
.parts
.GenericPropertyPage
;
33 import org
.argeo
.eclipse
.ui
.workbench
.internal
.jcr
.parts
.NodePrivilegesPage
;
34 import org
.argeo
.eclipse
.ui
.workbench
.internal
.jcr
.parts
.NodeVersionHistoryPage
;
35 import org
.argeo
.jcr
.JcrUtils
;
36 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
37 import org
.eclipse
.ui
.IEditorInput
;
38 import org
.eclipse
.ui
.IEditorSite
;
39 import org
.eclipse
.ui
.PartInitException
;
40 import org
.eclipse
.ui
.forms
.editor
.FormEditor
;
42 /** Default form editor for a Jcr {@link Node} */
43 public class DefaultNodeEditor
extends FormEditor
{
44 private static final long serialVersionUID
= 8322127770921612239L;
46 // private final static Log log =
47 // LogFactory.getLog(GenericNodeEditor.class);
48 public final static String ID
= WorkbenchUiPlugin
.ID
+ ".defaultNodeEditor";
50 private Node currentNode
;
52 private GenericNodePage genericNodePage
;
53 private GenericPropertyPage genericPropertyPage
;
54 private ChildNodesPage childNodesPage
;
55 private NodePrivilegesPage nodeRightsManagementPage
;
56 private NodeVersionHistoryPage nodeVersionHistoryPage
;
58 public void init(IEditorSite site
, IEditorInput input
)
59 throws PartInitException
{
60 super.init(site
, input
);
61 GenericNodeEditorInput nei
= (GenericNodeEditorInput
) getEditorInput();
62 currentNode
= nei
.getCurrentNode();
63 this.setPartName(JcrUtils
.lastPathElement(nei
.getPath()));
67 protected void addPages() {
69 genericPropertyPage
= new GenericPropertyPage(this,
70 WorkbenchUiPlugin
.getMessage("genericNodePageTitle"),
72 addPage(genericPropertyPage
);
74 childNodesPage
= new ChildNodesPage(this,
75 WorkbenchUiPlugin
.getMessage("childNodesPageTitle"),
77 addPage(childNodesPage
);
79 AccessControlManager accessControlManager
= currentNode
80 .getSession().getAccessControlManager();
81 List
<Privilege
> privileges
= new ArrayList
<Privilege
>();
82 privileges
.add(accessControlManager
83 .privilegeFromName(Privilege
.JCR_READ_ACCESS_CONTROL
));
84 if (accessControlManager
.hasPrivileges(currentNode
.getPath(),
85 privileges
.toArray(new Privilege
[0]))) {
86 nodeRightsManagementPage
= new NodePrivilegesPage(this,
88 .getMessage("nodeRightsManagementPageTitle"),
90 addPage(nodeRightsManagementPage
);
92 if (currentNode
.isNodeType(NodeType
.MIX_VERSIONABLE
)) {
93 nodeVersionHistoryPage
= new NodeVersionHistoryPage(this,
95 .getMessage("nodeVersionHistoryPageTitle"),
97 addPage(nodeVersionHistoryPage
);
100 privileges
= new ArrayList
<Privilege
>();
101 privileges
.add(accessControlManager
102 .privilegeFromName(Privilege
.JCR_ALL
));
103 if (accessControlManager
.hasPrivileges(currentNode
.getPath(),
104 privileges
.toArray(new Privilege
[0]))) {
105 genericNodePage
= new GenericNodePage(this,
106 WorkbenchUiPlugin
.getMessage("propertyEditorPageTitle"),
108 addPage(genericNodePage
);
111 } catch (RepositoryException e
) {
112 throw new EclipseUiException("Cannot get node info for " + currentNode
,
114 } catch (PartInitException e
) {
115 throw new EclipseUiException("Cannot add page " + "on node editor for "
121 public void doSaveAs() {
122 // unused compulsory method
126 public void doSave(IProgressMonitor monitor
) {
128 // Automatically commit all pages of the editor
130 firePropertyChange(PROP_DIRTY
);
131 } catch (Exception e
) {
132 throw new EclipseUiException("Error while saving node", e
);
138 public boolean isSaveAsAllowed() {
142 Node
getCurrentNode() {