]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/text/TextEditorHeader.java
Improve DocBook
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / text / TextEditorHeader.java
1 package org.argeo.cms.text;
2
3 import java.util.Observable;
4 import java.util.Observer;
5
6 import org.argeo.cms.ui.CmsEditable;
7 import org.argeo.cms.util.CmsUtils;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.events.SelectionEvent;
10 import org.eclipse.swt.events.SelectionListener;
11 import org.eclipse.swt.widgets.Button;
12 import org.eclipse.swt.widgets.Composite;
13
14 /** Adds editing capabilities to a page editing text */
15 public class TextEditorHeader implements SelectionListener, Observer {
16 private static final long serialVersionUID = 4186756396045701253L;
17
18 private final CmsEditable cmsEditable;
19 private Button publish;
20
21 private Composite parent;
22 private Composite display;
23 private Object layoutData;
24
25 public TextEditorHeader(CmsEditable cmsEditable, Composite parent, int style) {
26 this.cmsEditable = cmsEditable;
27 this.parent = parent;
28 if (this.cmsEditable instanceof Observable)
29 ((Observable) this.cmsEditable).addObserver(this);
30 refresh();
31 }
32
33 protected void refresh() {
34 if (display != null && !display.isDisposed())
35 display.dispose();
36 display = null;
37 publish = null;
38 if (cmsEditable.isEditing()) {
39 display = new Composite(parent, SWT.NONE);
40 // display.setBackgroundMode(SWT.INHERIT_NONE);
41 display.setLayoutData(layoutData);
42 display.setLayout(CmsUtils.noSpaceGridLayout());
43 CmsUtils.style(display, TextStyles.TEXT_EDITOR_HEADER);
44 publish = new Button(display, SWT.FLAT | SWT.PUSH);
45 publish.setText(getPublishButtonLabel());
46 CmsUtils.style(publish, TextStyles.TEXT_EDITOR_HEADER);
47 publish.addSelectionListener(this);
48 display.moveAbove(null);
49 }
50 parent.layout();
51 }
52
53 private String getPublishButtonLabel() {
54 if (cmsEditable.isEditing())
55 return "Publish";
56 else
57 return "Edit";
58 }
59
60 @Override
61 public void widgetSelected(SelectionEvent e) {
62 if (e.getSource() == publish) {
63 if (cmsEditable.isEditing()) {
64 cmsEditable.stopEditing();
65 } else {
66 cmsEditable.startEditing();
67 }
68 // publish.setText(getPublishButtonLabel());
69 }
70 }
71
72 @Override
73 public void widgetDefaultSelected(SelectionEvent e) {
74 }
75
76 @Override
77 public void update(Observable o, Object arg) {
78 if (o == cmsEditable) {
79 // publish.setText(getPublishButtonLabel());
80 refresh();
81 }
82 }
83
84 public void setLayoutData(Object layoutData) {
85 this.layoutData = layoutData;
86 if (display != null && !display.isDisposed())
87 display.setLayoutData(layoutData);
88 }
89
90 }