1 package org
.argeo
.cms
.widgets
;
4 import javax
.jcr
.RepositoryException
;
6 import org
.argeo
.cms
.ui
.CmsConstants
;
7 import org
.argeo
.cms
.util
.CmsUtils
;
8 import org
.eclipse
.swt
.SWT
;
9 import org
.eclipse
.swt
.events
.FocusListener
;
10 import org
.eclipse
.swt
.events
.MouseListener
;
11 import org
.eclipse
.swt
.widgets
.Composite
;
12 import org
.eclipse
.swt
.widgets
.Control
;
14 /** Editable text part displaying styled text. */
15 public abstract class StyledControl
extends JcrComposite
implements CmsConstants
{
16 private static final long serialVersionUID
= -6372283442330912755L;
17 private Control control
;
19 private Composite container
;
20 private Composite box
;
22 protected MouseListener mouseListener
;
23 protected FocusListener focusListener
;
25 private Boolean editing
= Boolean
.FALSE
;
27 public StyledControl(Composite parent
, int swtStyle
) {
28 super(parent
, swtStyle
);
29 setLayout(CmsUtils
.noSpaceGridLayout());
32 public StyledControl(Composite parent
, int style
, Item item
) throws RepositoryException
{
33 super(parent
, style
, item
);
36 public StyledControl(Composite parent
, int style
, Item item
, boolean cacheImmediately
) throws RepositoryException
{
37 super(parent
, style
, item
, cacheImmediately
);
40 protected abstract Control
createControl(Composite box
, String style
);
42 protected Composite
createBox(Composite parent
) {
43 Composite box
= new Composite(parent
, SWT
.INHERIT_DEFAULT
);
44 setContainerLayoutData(box
);
45 box
.setLayout(CmsUtils
.noSpaceGridLayout());
46 // new Label(box, SWT.NONE).setText("BOX");
50 public Control
getControl() {
54 protected synchronized Boolean
isEditing() {
58 public synchronized void startEditing() {
61 // int height = control.getSize().y;
62 String style
= (String
) control
.getData(STYLE
);
64 control
= createControl(box
, style
);
65 setControlLayoutData(control
);
67 // add the focus listener to the newly created edition control
68 if (focusListener
!= null)
69 control
.addFocusListener(focusListener
);
72 public synchronized void stopEditing() {
75 String style
= (String
) control
.getData(STYLE
);
77 control
= createControl(box
, style
);
78 setControlLayoutData(control
);
81 public void setStyle(String style
) {
82 Object currentStyle
= null;
84 currentStyle
= control
.getData(STYLE
);
85 if (currentStyle
!= null && currentStyle
.equals(style
))
88 // Integer preferredHeight = control != null ? control.getSize().y :
91 control
= createControl(box
, style
);
92 setControlLayoutData(control
);
94 control
.getParent().setData(STYLE
, style
+ "_box");
95 control
.getParent().getParent().setData(STYLE
, style
+ "_container");
98 /** To be overridden */
99 protected void setControlLayoutData(Control control
) {
100 control
.setLayoutData(CmsUtils
.fillWidth());
103 /** To be overridden */
104 protected void setContainerLayoutData(Composite composite
) {
105 composite
.setLayoutData(CmsUtils
.fillWidth());
108 protected void clear(boolean deep
) {
110 for (Control control
: getChildren())
112 container
= createBox(this);
113 box
= createBox(container
);
119 public void setMouseListener(MouseListener mouseListener
) {
120 if (this.mouseListener
!= null && control
!= null)
121 control
.removeMouseListener(this.mouseListener
);
122 this.mouseListener
= mouseListener
;
123 if (control
!= null && this.mouseListener
!= null)
124 control
.addMouseListener(mouseListener
);
127 public void setFocusListener(FocusListener focusListener
) {
128 if (this.focusListener
!= null && control
!= null)
129 control
.removeFocusListener(this.focusListener
);
130 this.focusListener
= focusListener
;
131 if (control
!= null && this.focusListener
!= null)
132 control
.addFocusListener(focusListener
);