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
.CmsUtils
;
9 import org
.eclipse
.swt
.SWT
;
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
16 CmsConstants
, CmsNames
{
17 private static final long serialVersionUID
= -6372283442330912755L;
18 private Control control
;
20 private Composite container
;
21 private Composite box
;
23 protected MouseListener mouseListener
;
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
)
33 throws RepositoryException
{
34 super(parent
, style
, item
);
37 public StyledControl(Composite parent
, int style
, Item item
,
38 boolean cacheImmediately
) throws RepositoryException
{
39 super(parent
, style
, item
, cacheImmediately
);
42 protected abstract Control
createControl(Composite box
, String style
);
44 protected Composite
createBox(Composite parent
) {
45 Composite box
= new Composite(parent
, SWT
.INHERIT_DEFAULT
);
46 setContainerLayoutData(box
);
47 box
.setLayout(CmsUtils
.noSpaceGridLayout());
48 // new Label(box, SWT.NONE).setText("BOX");
52 public Control
getControl() {
56 protected synchronized Boolean
isEditing() {
60 public synchronized void startEditing() {
63 // int height = control.getSize().y;
64 String style
= (String
) control
.getData(STYLE
);
66 control
= createControl(box
, style
);
67 setControlLayoutData(control
);
70 public synchronized void stopEditing() {
73 String style
= (String
) control
.getData(STYLE
);
75 control
= createControl(box
, style
);
76 setControlLayoutData(control
);
79 public void setStyle(String style
) {
80 Object currentStyle
= null;
82 currentStyle
= control
.getData(STYLE
);
83 if (currentStyle
!= null && currentStyle
.equals(style
))
86 // Integer preferredHeight = control != null ? control.getSize().y :
89 control
= createControl(box
, style
);
90 setControlLayoutData(control
);
92 control
.getParent().setData(STYLE
, style
+ "_box");
93 control
.getParent().getParent().setData(STYLE
, style
+ "_container");
96 /** To be overridden */
97 protected void setControlLayoutData(Control control
) {
98 control
.setLayoutData(CmsUtils
.fillWidth());
101 /** To be overridden */
102 protected void setContainerLayoutData(Composite composite
) {
103 composite
.setLayoutData(CmsUtils
.fillWidth());
106 protected void clear(boolean deep
) {
108 for (Control control
: getChildren())
110 container
= createBox(this);
111 box
= createBox(container
);
117 public void setMouseListener(MouseListener mouseListener
) {
118 if (this.mouseListener
!= null && control
!= null)
119 control
.removeMouseListener(this.mouseListener
);
120 this.mouseListener
= mouseListener
;
121 if (control
!= null && this.mouseListener
!= null)
122 control
.addMouseListener(mouseListener
);