package org.argeo.cms.ui.widgets;
import javax.jcr.Item;
-import javax.jcr.RepositoryException;
+import org.argeo.cms.swt.CmsSwtUtils;
import org.argeo.cms.ui.CmsConstants;
-import org.argeo.cms.ui.util.CmsUiUtils;
+import org.argeo.eclipse.ui.specific.EclipseUiSpecificUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.MouseListener;
private Boolean editing = Boolean.FALSE;
+ private Composite ancestorToLayout;
+
public StyledControl(Composite parent, int swtStyle) {
super(parent, swtStyle);
- setLayout(CmsUiUtils.noSpaceGridLayout());
+ setLayout(CmsSwtUtils.noSpaceGridLayout());
}
- public StyledControl(Composite parent, int style, Item item) throws RepositoryException {
+ public StyledControl(Composite parent, int style, Item item) {
super(parent, style, item);
}
- public StyledControl(Composite parent, int style, Item item, boolean cacheImmediately) throws RepositoryException {
+ public StyledControl(Composite parent, int style, Item item, boolean cacheImmediately) {
super(parent, style, item, cacheImmediately);
}
protected abstract Control createControl(Composite box, String style);
- protected Composite createBox(Composite parent) {
- Composite box = new Composite(parent, SWT.INHERIT_DEFAULT);
+ protected Composite createBox() {
+ Composite box = new Composite(container, SWT.INHERIT_DEFAULT);
setContainerLayoutData(box);
- box.setLayout(CmsUiUtils.noSpaceGridLayout());
- // new Label(box, SWT.NONE).setText("BOX");
+ box.setLayout(CmsSwtUtils.noSpaceGridLayout(3));
return box;
}
+ protected Composite createContainer() {
+ Composite container = new Composite(this, SWT.INHERIT_DEFAULT);
+ setContainerLayoutData(container);
+ container.setLayout(CmsSwtUtils.noSpaceGridLayout());
+ return container;
+ }
+
public Control getControl() {
return control;
}
assert !isEditing();
editing = true;
// int height = control.getSize().y;
- String style = (String) control.getData(STYLE);
+ String style = (String) EclipseUiSpecificUtils.getStyleData(control);
clear(false);
- control = createControl(box, style);
- setControlLayoutData(control);
+ refreshControl(style);
// add the focus listener to the newly created edition control
if (focusListener != null)
public synchronized void stopEditing() {
assert isEditing();
editing = false;
- String style = (String) control.getData(STYLE);
+ String style = (String) EclipseUiSpecificUtils.getStyleData(control);
clear(false);
+ refreshControl(style);
+ }
+
+ protected void refreshControl(String style) {
control = createControl(box, style);
setControlLayoutData(control);
+ if (ancestorToLayout != null)
+ ancestorToLayout.layout(true, true);
+ else
+ getParent().layout(true, true);
}
public void setStyle(String style) {
Object currentStyle = null;
if (control != null)
- currentStyle = control.getData(STYLE);
+ currentStyle = EclipseUiSpecificUtils.getStyleData(control);
if (currentStyle != null && currentStyle.equals(style))
return;
- // Integer preferredHeight = control != null ? control.getSize().y :
- // null;
clear(true);
- control = createControl(box, style);
- setControlLayoutData(control);
+ refreshControl(style);
- control.getParent().setData(STYLE, style + "_box");
- control.getParent().getParent().setData(STYLE, style + "_container");
+ if (style != null) {
+ CmsSwtUtils.style(box, style + "_box");
+ CmsSwtUtils.style(container, style + "_container");
+ }
}
/** To be overridden */
protected void setControlLayoutData(Control control) {
- control.setLayoutData(CmsUiUtils.fillWidth());
+ control.setLayoutData(CmsSwtUtils.fillWidth());
}
/** To be overridden */
protected void setContainerLayoutData(Composite composite) {
- composite.setLayoutData(CmsUiUtils.fillWidth());
+ composite.setLayoutData(CmsSwtUtils.fillWidth());
}
protected void clear(boolean deep) {
if (deep) {
for (Control control : getChildren())
control.dispose();
- container = createBox(this);
- box = createBox(container);
+ container = createContainer();
+ box = createBox();
} else {
control.dispose();
}
if (control != null && this.focusListener != null)
control.addFocusListener(focusListener);
}
+
+ public void setAncestorToLayout(Composite ancestorToLayout) {
+ this.ancestorToLayout = ancestorToLayout;
+ }
+
}