1 package org
.argeo
.cms
.widgets
;
4 import javax
.jcr
.RepositoryException
;
6 import org
.argeo
.cms
.CmsConstants
;
7 import org
.argeo
.cms
.CmsNames
;
8 import org
.argeo
.cms
.util
.CmsUtils
;
9 import org
.eclipse
.swt
.SWT
;
10 import org
.eclipse
.swt
.events
.FocusListener
;
11 import org
.eclipse
.swt
.events
.MouseListener
;
12 import org
.eclipse
.swt
.widgets
.Composite
;
13 import org
.eclipse
.swt
.widgets
.Control
;
15 /** Editable text part displaying styled text. */
16 public abstract class StyledControl
extends JcrComposite
implements
17 CmsConstants
, CmsNames
{
18 private static final long serialVersionUID
= -6372283442330912755L;
19 private Control control
;
21 private Composite container
;
22 private Composite box
;
24 protected MouseListener mouseListener
;
25 protected FocusListener focusListener
;
27 private Boolean editing
= Boolean
.FALSE
;
29 public StyledControl(Composite parent
, int swtStyle
) {
30 super(parent
, swtStyle
);
31 setLayout(CmsUtils
.noSpaceGridLayout());
34 public StyledControl(Composite parent
, int style
, Item item
)
35 throws RepositoryException
{
36 super(parent
, style
, item
);
39 public StyledControl(Composite parent
, int style
, Item item
,
40 boolean cacheImmediately
) throws RepositoryException
{
41 super(parent
, style
, item
, cacheImmediately
);
44 protected abstract Control
createControl(Composite box
, String style
);
46 protected Composite
createBox(Composite parent
) {
47 Composite box
= new Composite(parent
, SWT
.INHERIT_DEFAULT
);
48 setContainerLayoutData(box
);
49 box
.setLayout(CmsUtils
.noSpaceGridLayout());
50 // new Label(box, SWT.NONE).setText("BOX");
54 public Control
getControl() {
58 protected synchronized Boolean
isEditing() {
62 public synchronized void startEditing() {
65 // int height = control.getSize().y;
66 String style
= (String
) control
.getData(STYLE
);
68 control
= createControl(box
, style
);
69 setControlLayoutData(control
);
71 // add the focus listener to the newly created edition control
72 if (focusListener
!= null)
73 control
.addFocusListener(focusListener
);
76 public synchronized void stopEditing() {
79 String style
= (String
) control
.getData(STYLE
);
81 control
= createControl(box
, style
);
82 setControlLayoutData(control
);
85 public void setStyle(String style
) {
86 Object currentStyle
= null;
88 currentStyle
= control
.getData(STYLE
);
89 if (currentStyle
!= null && currentStyle
.equals(style
))
92 // Integer preferredHeight = control != null ? control.getSize().y :
95 control
= createControl(box
, style
);
96 setControlLayoutData(control
);
98 control
.getParent().setData(STYLE
, style
+ "_box");
99 control
.getParent().getParent().setData(STYLE
, style
+ "_container");
102 /** To be overridden */
103 protected void setControlLayoutData(Control control
) {
104 control
.setLayoutData(CmsUtils
.fillWidth());
107 /** To be overridden */
108 protected void setContainerLayoutData(Composite composite
) {
109 composite
.setLayoutData(CmsUtils
.fillWidth());
112 protected void clear(boolean deep
) {
114 for (Control control
: getChildren())
116 container
= createBox(this);
117 box
= createBox(container
);
123 public void setMouseListener(MouseListener mouseListener
) {
124 if (this.mouseListener
!= null && control
!= null)
125 control
.removeMouseListener(this.mouseListener
);
126 this.mouseListener
= mouseListener
;
127 if (control
!= null && this.mouseListener
!= null)
128 control
.addMouseListener(mouseListener
);
131 public void setFocusListener(FocusListener focusListener
) {
132 if (this.focusListener
!= null && control
!= null)
133 control
.removeFocusListener(this.focusListener
);
134 this.focusListener
= focusListener
;
135 if (control
!= null && this.focusListener
!= null)
136 control
.addFocusListener(focusListener
);