]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/editors/GenericNodeEditor.java
Jcr Explorer refactoring and packaging
[lgpl/argeo-commons.git] / server / plugins / org.argeo.jcr.ui.explorer / src / main / java / org / argeo / jcr / ui / explorer / editors / GenericNodeEditor.java
1 package org.argeo.jcr.ui.explorer.editors;
2
3 import javax.jcr.Node;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.argeo.ArgeoException;
8 import org.argeo.jcr.JcrUtils;
9 import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
10 import org.eclipse.core.runtime.IProgressMonitor;
11 import org.eclipse.ui.IEditorInput;
12 import org.eclipse.ui.IEditorSite;
13 import org.eclipse.ui.PartInitException;
14 import org.eclipse.ui.forms.editor.FormEditor;
15
16 /**
17 * Parent Abstract GR multitab editor. Insure the presence of a GrBackend
18 */
19 public class GenericNodeEditor extends FormEditor {
20
21 private final static Log log = LogFactory.getLog(GenericNodeEditor.class);
22 public final static String ID = "org.argeo.jcr.ui.explorer.genericNodeEditor";
23
24 private Node currentNode;
25
26 private GenericNodePage networkDetailsPage;
27
28 public void init(IEditorSite site, IEditorInput input)
29 throws PartInitException {
30 super.init(site, input);
31 GenericNodeEditorInput nei = (GenericNodeEditorInput) getEditorInput();
32 this.setPartName(JcrUtils.lastPathElement(nei.getPath()));
33 }
34
35 @Override
36 protected void addPages() {
37 EmptyNodePage enp = new EmptyNodePage(this, "Empty node page");
38 try {
39 addPage(enp);
40 } catch (PartInitException e) {
41 throw new ArgeoException("Not able to add an empty page ", e);
42 }
43 }
44
45 private void addPagesAfterNodeSet() {
46 try {
47 networkDetailsPage = new GenericNodePage(this,
48 JcrExplorerPlugin.getMessage("genericNodePageTitle"),
49 currentNode);
50 addPage(networkDetailsPage);
51 this.setActivePage(networkDetailsPage.getIndex());
52 } catch (PartInitException e) {
53 throw new ArgeoException("Not able to add page ", e);
54 }
55 }
56
57 @Override
58 public void doSaveAs() {
59 // unused compulsory method
60 }
61
62 @Override
63 public void doSave(IProgressMonitor monitor) {
64 try {
65 // Automatically commit all pages of the editor
66 commitPages(true);
67 firePropertyChange(PROP_DIRTY);
68 } catch (Exception e) {
69 throw new ArgeoException("Error while saving node", e);
70 }
71
72 }
73
74 @Override
75 public boolean isSaveAsAllowed() {
76 return true;
77 }
78
79 Node getCurrentNode() {
80 return currentNode;
81 }
82
83 public void setCurrentNode(Node currentNode) {
84 boolean nodeWasNull = this.currentNode == null;
85 this.currentNode = currentNode;
86 if (nodeWasNull) {
87 this.removePage(0);
88 addPagesAfterNodeSet();
89 }
90 }
91 }