package org.argeo.slc.akb.ui.editors;
import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.akb.AkbException;
-import org.argeo.slc.akb.ui.AkbUiPlugin;
+import org.argeo.slc.akb.AkbService;
+import org.argeo.slc.akb.ui.AkbUiUtils;
+import org.argeo.slc.akb.utils.AkbJcrUtils;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.part.EditorPart;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
/**
- * Parent Abstract Node editor for AKB. Manage life cycle of the JCR session that
- * is bound to it.
+ * Parent Abstract Node editor for AKB. Manage life cycle of the JCR session
+ * that is bound to it.
*/
-public abstract class AbstractAkbNodeEditor extends EditorPart {
+public abstract class AbstractAkbNodeEditor extends FormEditor {
// private final static Log log = LogFactory
// .getLog(AbstractEntityEditor.class);
// changes life cycle
private Repository repository;
private Session session;
+ private AkbService akbService;
// Business Objects
private Node akbNode;
- // LIFE CYCLE
+ // Some constants
+ private final static int SHORT_NAME_LENGHT = 10;
+
+ // to implement methods
+ protected abstract String getEditorId();
+
+ protected abstract void populateMainPage(Composite parent,
+ IManagedForm managedForm);
+
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
setSite(site);
session = repository.login();
AkbNodeEditorInput anei = (AkbNodeEditorInput) getEditorInput();
akbNode = session.getNodeByIdentifier(anei.getIdentifier());
+ updatePartNameAndToolTip();
+ } catch (RepositoryException e) {
+ throw new AkbException("Unable open editor for akb node", e);
+ }
+ }
+
+ /**
+ * Overwrite to provide a specific part Name and / or tooltip
+ */
+ protected void updatePartNameAndToolTip() {
+ String name = JcrUtils.get(akbNode, Property.JCR_TITLE);
+
+ // Name
+ if (AkbJcrUtils.checkNotEmptyString(name)) {
+ if (name.length() > SHORT_NAME_LENGHT)
+ name = name.substring(0, SHORT_NAME_LENGHT - 1) + "...";
+ setPartName(name);
+ }
- // try to set a default part name
- updatePartName();
+ // Tooltip
+ if (AkbJcrUtils.isEmptyString(name))
+ name = "current item";
+ setTitleToolTip("Display and edit " + name);
+ }
- // update tooltip
- // String displayName = CommonsJcrUtils.get(getEntity(),
- // Property.JCR_TITLE);
+ /** Overwrite to provide supplementary pages between main and history page */
+ protected void addOtherPages() throws PartInitException {
+ }
- // if (CommonsJcrUtils.isEmptyString(displayName))
- // displayName = "current item";
- // setTitleToolTip("Display and edit information for " +
- // displayName);
- } catch (RepositoryException e) {
- throw new AkbException("Unable open editor for akb node", e);
+ /* Pages management */
+ @Override
+ protected void addPages() {
+ try {
+ addPage(new ConnectorAliasPage(this, "mainPage", "Main"));
+ // Add AKB Type specific pages
+ addOtherPages();
+ addPage(new HistoryPage(this, "historyPage", "History"));
+ } catch (PartInitException e) {
+ throw new AkbException("Unable to initialise pages for editor "
+ + getEditorId(), e);
}
}
/**
- * Overwrite to provide a specific part Name
+ * Display and edit info
*/
- protected void updatePartName() {
- // String name = CommonsJcrUtils.get(entity, Property.JCR_TITLE);
- // if (CommonsJcrUtils.checkNotEmptyString(name)) {
- // if (name.length() > SHORT_NAME_LENGHT)
- // name = name.substring(0, SHORT_NAME_LENGHT - 1) + "...";
- // setPartName(name);
- // }
+ private class ConnectorAliasPage extends FormPage {
+
+ public ConnectorAliasPage(FormEditor editor, String id, String title) {
+ super(editor, id, title);
+ }
+
+ protected void createFormContent(IManagedForm managedForm) {
+ super.createFormContent(managedForm);
+ ScrolledForm form = managedForm.getForm();
+ form.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ populateMainPage(form.getBody(), managedForm);
+ }
+ }
+
+ /**
+ * Display history
+ */
+ private class HistoryPage extends FormPage {
+
+ public HistoryPage(FormEditor editor, String id, String title) {
+ super(editor, id, title);
+ }
+
+ protected void createFormContent(IManagedForm managedForm) {
+ super.createFormContent(managedForm);
+ ScrolledForm form = managedForm.getForm();
+ form.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ Composite parent = form.getBody();
+ parent.setLayout(AkbUiUtils.gridLayoutNoBorder());
+ getToolkit().createLabel(parent,
+ "This page will display history " + "for current AKB Node");
+ }
}
/* EXPOSES TO CHILDREN CLASSES */
return session;
}
+ protected AkbService getAkbService() {
+ return akbService;
+ }
+
+ protected Node getAkbNode() {
+ return akbNode;
+ }
+
+ /* LIFE CYCLE MANAGEMENT */
@Override
public void dispose() {
try {
@Override
public void doSave(IProgressMonitor monitor) {
- throw new AkbException("Implement this");
+ try {
+ if (getSession().hasPendingChanges())
+ JcrUtils.updateLastModified(getAkbNode());
+ getSession().save();
+ updatePartNameAndToolTip();
+ this.firePropertyChange(PROP_DIRTY);
+ } catch (Exception e) {
+ throw new AkbException("Error getting session status.", e);
+ }
}
@Override
public void setRepository(Repository repository) {
this.repository = repository;
}
+
+ public void setAkbService(AkbService akbService) {
+ this.akbService = akbService;
+ }
}
\ No newline at end of file