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 private Composite ancestorToLayout
;
29 public StyledControl(Composite parent
, int swtStyle
) {
30 super(parent
, swtStyle
);
31 setLayout(CmsUiUtils
.noSpaceGridLayout());
34 public StyledControl(Composite parent
, int style
, Item item
) {
35 super(parent
, style
, item
);
38 public StyledControl(Composite parent
, int style
, Item item
, boolean cacheImmediately
) {
39 super(parent
, style
, item
, cacheImmediately
);
42 protected abstract Control
createControl(Composite box
, String style
);
44 protected Composite
createBox() {
45 Composite box
= new Composite(container
, SWT
.INHERIT_DEFAULT
);
46 setContainerLayoutData(box
);
47 box
.setLayout(CmsUiUtils
.noSpaceGridLayout(3));
51 protected Composite
createContainer() {
52 Composite container
= new Composite(this, SWT
.INHERIT_DEFAULT
);
53 setContainerLayoutData(container
);
54 container
.setLayout(CmsUiUtils
.noSpaceGridLayout());
58 public Control
getControl() {
62 protected synchronized Boolean
isEditing() {
66 public synchronized void startEditing() {
69 // int height = control.getSize().y;
70 String style
= (String
) EclipseUiSpecificUtils
.getStyleData(control
);
72 refreshControl(style
);
74 // add the focus listener to the newly created edition control
75 if (focusListener
!= null)
76 control
.addFocusListener(focusListener
);
79 public synchronized void stopEditing() {
82 String style
= (String
) EclipseUiSpecificUtils
.getStyleData(control
);
84 refreshControl(style
);
87 protected void refreshControl(String style
) {
88 control
= createControl(box
, style
);
89 setControlLayoutData(control
);
90 if (ancestorToLayout
!= null)
91 ancestorToLayout
.layout(true, true);
93 getParent().layout(true, true);
96 public void setStyle(String style
) {
97 Object currentStyle
= null;
99 currentStyle
= EclipseUiSpecificUtils
.getStyleData(control
);
100 if (currentStyle
!= null && currentStyle
.equals(style
))
104 refreshControl(style
);
107 CmsUiUtils
.style(box
, style
+ "_box");
108 CmsUiUtils
.style(container
, style
+ "_container");
112 /** To be overridden */
113 protected void setControlLayoutData(Control control
) {
114 control
.setLayoutData(CmsUiUtils
.fillWidth());
117 /** To be overridden */
118 protected void setContainerLayoutData(Composite composite
) {
119 composite
.setLayoutData(CmsUiUtils
.fillWidth());
122 protected void clear(boolean deep
) {
124 for (Control control
: getChildren())
126 container
= createContainer();
133 public void setMouseListener(MouseListener mouseListener
) {
134 if (this.mouseListener
!= null && control
!= null)
135 control
.removeMouseListener(this.mouseListener
);
136 this.mouseListener
= mouseListener
;
137 if (control
!= null && this.mouseListener
!= null)
138 control
.addMouseListener(mouseListener
);
141 public void setFocusListener(FocusListener focusListener
) {
142 if (this.focusListener
!= null && control
!= null)
143 control
.removeFocusListener(this.focusListener
);
144 this.focusListener
= focusListener
;
145 if (control
!= null && this.focusListener
!= null)
146 control
.addFocusListener(focusListener
);
149 public void setAncestorToLayout(Composite ancestorToLayout
) {
150 this.ancestorToLayout
= ancestorToLayout
;