]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/DefaultNodeEditor.java
Clean internal package structure
[lgpl/argeo-commons.git] / org.argeo.eclipse.ui.workbench / src / org / argeo / eclipse / ui / workbench / jcr / DefaultNodeEditor.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.eclipse.ui.workbench.jcr;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
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;
26
27 import org.argeo.ArgeoException;
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.GenericPropertyPage;
32 import org.argeo.eclipse.ui.workbench.internal.jcr.parts.NodePrivilegesPage;
33 import org.argeo.eclipse.ui.workbench.internal.jcr.parts.NodeVersionHistoryPage;
34 import org.argeo.jcr.JcrUtils;
35 import org.eclipse.core.runtime.IProgressMonitor;
36 import org.eclipse.ui.IEditorInput;
37 import org.eclipse.ui.IEditorSite;
38 import org.eclipse.ui.PartInitException;
39 import org.eclipse.ui.forms.editor.FormEditor;
40
41 /** Default form editor for a Jcr {@link Node} */
42 public class DefaultNodeEditor extends FormEditor {
43 private static final long serialVersionUID = 8322127770921612239L;
44
45 // private final static Log log =
46 // LogFactory.getLog(GenericNodeEditor.class);
47 public final static String ID = WorkbenchUiPlugin.ID + ".defaultNodeEditor";
48
49 private Node currentNode;
50
51 private GenericPropertyPage genericPropertyPage;
52 private ChildNodesPage childNodesPage;
53 private NodePrivilegesPage nodeRightsManagementPage;
54 private NodeVersionHistoryPage nodeVersionHistoryPage;
55
56 public void init(IEditorSite site, IEditorInput input)
57 throws PartInitException {
58 super.init(site, input);
59 GenericNodeEditorInput nei = (GenericNodeEditorInput) getEditorInput();
60 currentNode = nei.getCurrentNode();
61 this.setPartName(JcrUtils.lastPathElement(nei.getPath()));
62 }
63
64 @Override
65 protected void addPages() {
66 try {
67 // genericNodePage = new GenericNodePage(this,
68 // JcrExplorerPlugin.getMessage("genericNodePageTitle"),
69 // currentNode);
70 // addPage(genericNodePage);
71
72 genericPropertyPage = new GenericPropertyPage(this,
73 WorkbenchUiPlugin.getMessage("genericNodePageTitle"),
74 currentNode);
75 addPage(genericPropertyPage);
76
77 childNodesPage = new ChildNodesPage(this,
78 WorkbenchUiPlugin.getMessage("childNodesPageTitle"),
79 currentNode);
80 addPage(childNodesPage);
81
82 AccessControlManager accessControlManager = currentNode
83 .getSession().getAccessControlManager();
84 List<Privilege> privileges = new ArrayList<Privilege>();
85 privileges.add(accessControlManager
86 .privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL));
87 if (accessControlManager.hasPrivileges(currentNode.getPath(),
88 privileges.toArray(new Privilege[0]))) {
89 nodeRightsManagementPage = new NodePrivilegesPage(this,
90 WorkbenchUiPlugin
91 .getMessage("nodeRightsManagementPageTitle"),
92 currentNode);
93 addPage(nodeRightsManagementPage);
94 }
95 if (currentNode.isNodeType(NodeType.MIX_VERSIONABLE)) {
96 nodeVersionHistoryPage = new NodeVersionHistoryPage(this,
97 WorkbenchUiPlugin
98 .getMessage("nodeVersionHistoryPageTitle"),
99 currentNode);
100 addPage(nodeVersionHistoryPage);
101 }
102
103 } catch (RepositoryException e) {
104 throw new ArgeoException("Cannot get node info for " + currentNode,
105 e);
106 } catch (PartInitException e) {
107 throw new ArgeoException("Cannot add page " + "on node editor for "
108 + currentNode, e);
109 }
110 }
111
112 @Override
113 public void doSaveAs() {
114 // unused compulsory method
115 }
116
117 @Override
118 public void doSave(IProgressMonitor monitor) {
119 try {
120 // Automatically commit all pages of the editor
121 commitPages(true);
122 firePropertyChange(PROP_DIRTY);
123 } catch (Exception e) {
124 throw new ArgeoException("Error while saving node", e);
125 }
126
127 }
128
129 @Override
130 public boolean isSaveAsAllowed() {
131 return true;
132 }
133
134 Node getCurrentNode() {
135 return currentNode;
136 }
137 }