projects
/
lgpl
/
argeo-commons.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4f6cfbd
)
Improve generic editable components.
author
Mathieu Baudier <mbaudier@argeo.org>
Mon, 18 Jan 2021 10:38:16 +0000
(11:38 +0100)
committer
Mathieu Baudier <mbaudier@argeo.org>
Mon, 18 Jan 2021 10:38:16 +0000
(11:38 +0100)
org.argeo.cms.ui/src/org/argeo/cms/ui/viewers/AbstractPageViewer.java
patch
|
blob
|
history
org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/EditableText.java
patch
|
blob
|
history
org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/StyledControl.java
patch
|
blob
|
history
diff --git
a/org.argeo.cms.ui/src/org/argeo/cms/ui/viewers/AbstractPageViewer.java
b/org.argeo.cms.ui/src/org/argeo/cms/ui/viewers/AbstractPageViewer.java
index e23e3ba7957320a67cdd82cb0d5de5f18c4561be..004bd943531aa9854c318ac184cecd7a03c3f776 100644
(file)
--- a/
org.argeo.cms.ui/src/org/argeo/cms/ui/viewers/AbstractPageViewer.java
+++ b/
org.argeo.cms.ui/src/org/argeo/cms/ui/viewers/AbstractPageViewer.java
@@
-13,7
+13,6
@@
import javax.security.auth.Subject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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;
import org.argeo.cms.ui.CmsEditable;
import org.argeo.cms.ui.widgets.ScrolledPage;
import org.argeo.jcr.JcrException;
@@
-75,8
+74,8
@@
public abstract class AbstractPageViewer extends ContentViewer implements Observ
initModel(node);
node.getSession().save();
}
initModel(node);
node.getSession().save();
}
- } catch (Exception e) {
- throw new
Cms
Exception("Cannot initialize model", e);
+ } catch (
Repository
Exception e) {
+ throw new
Jcr
Exception("Cannot initialize model", e);
}
}
}
}
@@
-121,6
+120,16
@@
public abstract class AbstractPageViewer extends ContentViewer implements Observ
}
}
}
}
+ 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)
@Override
public void update(Observable o, Object arg) {
if (o == cmsEditable)
@@
-154,9
+163,10
@@
public abstract class AbstractPageViewer extends ContentViewer implements Observ
else
mouseListener = null;
refresh(getControl());
else
mouseListener = null;
refresh(getControl());
- layout(getControl());
+ // layout(getControl());
+ layoutPage();
} catch (RepositoryException e) {
} catch (RepositoryException e) {
- throw new
Cms
Exception("Cannot refresh", e);
+ throw new
Jcr
Exception("Cannot refresh", e);
}
return null;
});
}
return null;
});
@@
-192,6
+202,7
@@
public abstract class AbstractPageViewer extends ContentViewer implements Observ
prepare(part, caretPosition);
edited = part;
edited.getControl().addFocusListener(new FocusListener() {
prepare(part, caretPosition);
edited = part;
edited.getControl().addFocusListener(new FocusListener() {
+ private static final long serialVersionUID = 6883521812717097017L;
@Override
public void focusLost(FocusEvent event) {
@Override
public void focusLost(FocusEvent event) {
@@
-204,8
+215,9
@@
public abstract class AbstractPageViewer extends ContentViewer implements Observ
});
layout(part.getControl());
});
layout(part.getControl());
+ showControl(part.getControl());
} catch (RepositoryException e) {
} catch (RepositoryException e) {
- throw new
Cms
Exception("Cannot edit " + part, e);
+ throw new
Jcr
Exception("Cannot edit " + part, e);
}
}
}
}
@@
-262,14
+274,14
@@
public abstract class AbstractPageViewer extends ContentViewer implements Observ
if (parent.getParent() != null)
return findDataParent(parent.getParent());
else
if (parent.getParent() != null)
return findDataParent(parent.getParent());
else
- throw new
Cms
Exception("No data parent found");
+ throw new
IllegalState
Exception("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())
}
// 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
Cms
Exception("Edited should not be null or disposed at this stage");
+ throw new
IllegalState
Exception("Edited should not be null or disposed at this stage");
}
/** Persist all changes. */
}
/** Persist all changes. */
@@
-302,7
+314,7
@@
public abstract class AbstractPageViewer extends ContentViewer implements Observ
res = Subject.getSubject(accessControlContext);
}
if (res == null)
res = Subject.getSubject(accessControlContext);
}
if (res == null)
- throw new
Cms
Exception("No subject associated with this viewer");
+ throw new
IllegalState
Exception("No subject associated with this viewer");
return res;
}
return res;
}
diff --git
a/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/EditableText.java
b/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/EditableText.java
index 1ae44d0f74147843243ddb54710fc45a7d819c1b..5fadbc07ba436b0a0a867f4c602e3b68d3ba51df 100644
(file)
--- a/
org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/EditableText.java
+++ b/
org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/EditableText.java
@@
-5,8
+5,7
@@
import javax.jcr.RepositoryException;
import org.argeo.cms.ui.util.CmsUiUtils;
import org.eclipse.swt.SWT;
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;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@
-19,9
+18,13
@@
public class EditableText extends StyledControl {
private boolean editable = true;
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));
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) throws RepositoryException {
@@
-31,6
+34,7
@@
public class EditableText extends StyledControl {
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));
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
}
@Override
@@
-46,7
+50,8
@@
public class EditableText extends StyledControl {
protected Label createLabel(Composite box, String style) {
Label lbl = new Label(box, getStyle() | SWT.WRAP);
lbl.setLayoutData(CmsUiUtils.fillWidth());
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);
CmsUiUtils.markup(lbl);
if (mouseListener != null)
lbl.addMouseListener(mouseListener);
@@
-54,16
+59,31
@@
public class EditableText extends StyledControl {
}
protected Text createText(Composite box, String style, boolean editable) {
}
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);
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;
}
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 void setText(String text) {
Control child = getControl();
if (child instanceof Label)
@@
-82,7
+102,7
@@
public class EditableText extends StyledControl {
public String getText() {
Control child = getControl();
public String getText() {
Control child = getControl();
-
+
if (child instanceof Label)
return ((Label) child).getText();
else if (child instanceof Text)
if (child instanceof Label)
return ((Label) child).getText();
else if (child instanceof Text)
diff --git
a/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/StyledControl.java
b/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/StyledControl.java
index 0455d2cdc9e1f0669b8e5eecd521f1a5c53c83d3..1814131f4b39d5f8bc32dc73a572512ec2d405fb 100644
(file)
--- a/
org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/StyledControl.java
+++ b/
org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/StyledControl.java
@@
-39,11
+39,17
@@
public abstract class StyledControl extends JcrComposite implements CmsConstants
protected abstract Control createControl(Composite box, String style);
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());
setContainerLayoutData(box);
box.setLayout(CmsUiUtils.noSpaceGridLayout());
- // new Label(box, SWT.NONE).setText("BOX");
return box;
}
return box;
}
@@
-91,10
+97,10
@@
public abstract class StyledControl extends JcrComposite implements CmsConstants
control = createControl(box, style);
setControlLayoutData(control);
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 */
}
/** To be overridden */
@@
-111,8
+117,8
@@
public abstract class StyledControl extends JcrComposite implements CmsConstants
if (deep) {
for (Control control : getChildren())
control.dispose();
if (deep) {
for (Control control : getChildren())
control.dispose();
- container = create
Box(this
);
- box = createBox(
container
);
+ container = create
Container(
);
+ box = createBox();
} else {
control.dispose();
}
} else {
control.dispose();
}