1 package org
.argeo
.cms
.ui
.widgets
;
5 import org
.argeo
.cms
.ui
.CmsConstants
;
6 import org
.argeo
.cms
.ui
.util
.CmsUiUtils
;
7 import org
.argeo
.eclipse
.ui
.specific
.EclipseUiSpecificUtils
;
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(CmsUiUtils
.noSpaceGridLayout());
32 public StyledControl(Composite parent
, int style
, Item item
) {
33 super(parent
, style
, item
);
36 public StyledControl(Composite parent
, int style
, Item item
, boolean cacheImmediately
) {
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(CmsUiUtils
.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
) EclipseUiSpecificUtils
.getStyleData(control
);
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
) EclipseUiSpecificUtils
.getStyleData(control
);
77 control
= createControl(box
, style
);
78 setControlLayoutData(control
);
81 public void setStyle(String style
) {
82 Object currentStyle
= null;
84 currentStyle
= EclipseUiSpecificUtils
.getStyleData(control
);
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 EclipseUiSpecificUtils
.setStyleData(control
.getParent(), style
+ "_box");
96 // control.getParent().getParent().setData(STYLE, style + "_container");
97 EclipseUiSpecificUtils
.setStyleData(control
.getParent().getParent(), style
+ "_container");
100 /** To be overridden */
101 protected void setControlLayoutData(Control control
) {
102 control
.setLayoutData(CmsUiUtils
.fillWidth());
105 /** To be overridden */
106 protected void setContainerLayoutData(Composite composite
) {
107 composite
.setLayoutData(CmsUiUtils
.fillWidth());
110 protected void clear(boolean deep
) {
112 for (Control control
: getChildren())
114 container
= createBox(this);
115 box
= createBox(container
);
121 public void setMouseListener(MouseListener mouseListener
) {
122 if (this.mouseListener
!= null && control
!= null)
123 control
.removeMouseListener(this.mouseListener
);
124 this.mouseListener
= mouseListener
;
125 if (control
!= null && this.mouseListener
!= null)
126 control
.addMouseListener(mouseListener
);
129 public void setFocusListener(FocusListener focusListener
) {
130 if (this.focusListener
!= null && control
!= null)
131 control
.removeFocusListener(this.focusListener
);
132 this.focusListener
= focusListener
;
133 if (control
!= null && this.focusListener
!= null)
134 control
.addFocusListener(focusListener
);