import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.argeo.cms.CmsException;
import org.argeo.cms.ui.CmsEditable;
import org.argeo.cms.ui.widgets.ScrolledPage;
import org.argeo.jcr.JcrException;
initModel(node);
node.getSession().save();
}
- } catch (Exception e) {
- throw new CmsException("Cannot initialize model", e);
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot initialize model", e);
}
}
}
}
+ protected void layoutPage() {
+ if (page != null)
+ page.layout(true, true);
+ }
+
+ protected void showControl(Control control) {
+ if (page != null && (page instanceof ScrolledPage))
+ ((ScrolledPage) page).showControl(control);
+ }
+
@Override
public void update(Observable o, Object arg) {
if (o == cmsEditable)
else
mouseListener = null;
refresh(getControl());
- layout(getControl());
+ // layout(getControl());
+ layoutPage();
} catch (RepositoryException e) {
- throw new CmsException("Cannot refresh", e);
+ throw new JcrException("Cannot refresh", e);
}
return null;
});
prepare(part, caretPosition);
edited = part;
edited.getControl().addFocusListener(new FocusListener() {
+ private static final long serialVersionUID = 6883521812717097017L;
@Override
public void focusLost(FocusEvent event) {
});
layout(part.getControl());
+ showControl(part.getControl());
} catch (RepositoryException e) {
- throw new CmsException("Cannot edit " + part, e);
+ throw new JcrException("Cannot edit " + part, e);
}
}
if (parent.getParent() != null)
return findDataParent(parent.getParent());
else
- throw new CmsException("No data parent found");
+ throw new IllegalStateException("No data parent found");
}
// UTILITIES
/** Check whether the edited part is in a proper state */
protected void checkEdited() {
if (edited == null || (edited instanceof Widget) && ((Widget) edited).isDisposed())
- throw new CmsException("Edited should not be null or disposed at this stage");
+ throw new IllegalStateException("Edited should not be null or disposed at this stage");
}
/** Persist all changes. */
res = Subject.getSubject(accessControlContext);
}
if (res == null)
- throw new CmsException("No subject associated with this viewer");
+ throw new IllegalStateException("No subject associated with this viewer");
return res;
}
import org.argeo.cms.ui.util.CmsUiUtils;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
private boolean editable = true;
+ private Color highlightColor;
+ private Composite highlight;
+
public EditableText(Composite parent, int style) {
super(parent, style);
editable = !(SWT.READ_ONLY == (style & SWT.READ_ONLY));
+ highlightColor = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY);
}
public EditableText(Composite parent, int style, Item item) throws RepositoryException {
public EditableText(Composite parent, int style, Item item, boolean cacheImmediately) throws RepositoryException {
super(parent, style, item, cacheImmediately);
editable = !(SWT.READ_ONLY == (style & SWT.READ_ONLY));
+ highlightColor = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY);
}
@Override
protected Label createLabel(Composite box, String style) {
Label lbl = new Label(box, getStyle() | SWT.WRAP);
lbl.setLayoutData(CmsUiUtils.fillWidth());
- CmsUiUtils.style(lbl, style);
+ if (style != null)
+ CmsUiUtils.style(lbl, style);
CmsUiUtils.markup(lbl);
if (mouseListener != null)
lbl.addMouseListener(mouseListener);
}
protected Text createText(Composite box, String style, boolean editable) {
+ highlight = new Composite(box, SWT.NONE);
+ highlight.setBackground(highlightColor);
+ GridData highlightGd = new GridData(SWT.FILL, SWT.FILL, false, false);
+ highlightGd.widthHint = 5;
+ highlightGd.heightHint = 3;
+ highlight.setLayoutData(highlightGd);
+
final Text text = new Text(box, getStyle() | SWT.MULTI | SWT.WRAP);
text.setEditable(editable);
GridData textLayoutData = CmsUiUtils.fillWidth();
// textLayoutData.heightHint = preferredHeight;
text.setLayoutData(textLayoutData);
- CmsUiUtils.style(text, style);
+ if (style != null)
+ CmsUiUtils.style(text, style);
text.setFocus();
return text;
}
+ @Override
+ protected void clear(boolean deep) {
+ if (highlight != null)
+ highlight.dispose();
+ super.clear(deep);
+ }
+
public void setText(String text) {
Control child = getControl();
if (child instanceof Label)
public String getText() {
Control child = getControl();
-
+
if (child instanceof Label)
return ((Label) child).getText();
else if (child instanceof Text)
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(3));
+ return box;
+ }
+
+ protected Composite createContainer() {
+ Composite box = new Composite(this, SWT.INHERIT_DEFAULT);
setContainerLayoutData(box);
box.setLayout(CmsUiUtils.noSpaceGridLayout());
- // new Label(box, SWT.NONE).setText("BOX");
return box;
}
control = createControl(box, style);
setControlLayoutData(control);
-// control.getParent().setData(STYLE, style + "_box");
- EclipseUiSpecificUtils.setStyleData(control.getParent(), style + "_box");
-// control.getParent().getParent().setData(STYLE, style + "_container");
- EclipseUiSpecificUtils.setStyleData(control.getParent().getParent(), style + "_container");
+ if (style != null) {
+ CmsUiUtils.style(box, style + "_box");
+ CmsUiUtils.style(container, style + "_container");
+ }
}
/** To be overridden */
if (deep) {
for (Control control : getChildren())
control.dispose();
- container = createBox(this);
- box = createBox(container);
+ container = createContainer();
+ box = createBox();
} else {
control.dispose();
}