]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/forms/FormEditorHeader.java
1 package org
.argeo
.cms
.forms
;
3 import java
.util
.Observable
;
4 import java
.util
.Observer
;
8 import org
.argeo
.cms
.ui
.CmsEditable
;
9 import org
.argeo
.cms
.util
.CmsUtils
;
10 import org
.eclipse
.swt
.SWT
;
11 import org
.eclipse
.swt
.events
.SelectionEvent
;
12 import org
.eclipse
.swt
.events
.SelectionListener
;
13 import org
.eclipse
.swt
.widgets
.Button
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
16 /** Add life cycle management abilities to an editable form page */
17 public class FormEditorHeader
implements SelectionListener
, Observer
{
18 private static final long serialVersionUID
= 7392898696542484282L;
20 // private final Node context;
21 private final CmsEditable cmsEditable
;
22 private Button publishBtn
;
24 // Should we provide here the ability to switch from read only to edition
26 // private Button editBtn;
27 // private boolean readOnly;
29 // TODO add information about the current node status, typically if it is
32 private Composite parent
;
33 private Composite display
;
34 private Object layoutData
;
36 public FormEditorHeader(Composite parent
, int style
, Node context
,
37 CmsEditable cmsEditable
) {
38 this.cmsEditable
= cmsEditable
;
40 // readOnly = SWT.READ_ONLY == (style & SWT.READ_ONLY);
41 // this.context = context;
42 if (this.cmsEditable
instanceof Observable
)
43 ((Observable
) this.cmsEditable
).addObserver(this);
47 public void setLayoutData(Object layoutData
) {
48 this.layoutData
= layoutData
;
49 if (display
!= null && !display
.isDisposed())
50 display
.setLayoutData(layoutData
);
53 protected void refresh() {
54 if (display
!= null && !display
.isDisposed())
57 display
= new Composite(parent
, SWT
.NONE
);
58 display
.setLayoutData(layoutData
);
60 CmsUtils
.style(display
, FormStyle
.header
.style());
61 display
.setBackgroundMode(SWT
.INHERIT_FORCE
);
63 display
.setLayout(CmsUtils
.noSpaceGridLayout());
65 publishBtn
= createSimpleBtn(display
, getPublishButtonLabel());
66 display
.moveAbove(null);
70 private Button
createSimpleBtn(Composite parent
, String label
) {
71 Button button
= new Button(parent
, SWT
.FLAT
| SWT
.PUSH
);
72 button
.setText(label
);
73 CmsUtils
.style(button
, FormStyle
.header
.style());
74 button
.addSelectionListener(this);
78 private String
getPublishButtonLabel() {
79 // Rather check if the current node differs from what has been
80 // previously committed
81 // For the time being, we always reach here, the underlying CmsEditable
83 if (cmsEditable
.isEditing())
90 public void widgetSelected(SelectionEvent e
) {
91 if (e
.getSource() == publishBtn
) {
92 // For the time being, the underlying CmsEditable
93 // is always editing when we reach this point
94 if (cmsEditable
.isEditing()) {
95 // we always leave the node in a check outed state
96 cmsEditable
.stopEditing();
97 cmsEditable
.startEditing();
99 cmsEditable
.startEditing();
105 public void widgetDefaultSelected(SelectionEvent e
) {
109 public void update(Observable o
, Object arg
) {
110 if (o
== cmsEditable
) {