public synchronized void startEditing() {
CmsUiUtils.style(getControl(), FormStyle.propertyText);
-// getControl().setData(STYLE, propertyText.style());
super.startEditing();
}
public synchronized void stopEditing() {
if (EclipseUiUtils.isEmpty(((Text) getControl()).getText()))
CmsUiUtils.style(getControl(), FormStyle.propertyMessage);
-// getControl().setData(STYLE, propertyMessage.style());
else
CmsUiUtils.style(getControl(), FormStyle.propertyText);
-// getControl().setData(STYLE, propertyText.style());
super.stopEditing();
}
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.eclipse.jface.viewers.ContentViewer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
updateContent(part);
prepare(part, caretPosition);
edited = part;
+ edited.getControl().addFocusListener(new FocusListener() {
+
+ @Override
+ public void focusLost(FocusEvent event) {
+ stopEditing(true);
+ }
+
+ @Override
+ public void focusGained(FocusEvent event) {
+ }
+ });
+
layout(part.getControl());
} catch (RepositoryException e) {
throw new CmsException("Cannot edit " + part, e);
}
}
- private void stopEditing(Boolean save) throws RepositoryException {
+ protected void stopEditing(Boolean save) {
if (edited instanceof Widget && ((Widget) edited).isDisposed()) {
edited = null;
return;
return;
}
- if (save)
- save(edited);
+ try {
+ if (save)
+ save(edited);
- edited.stopEditing();
- updateContent(edited);
- layout(((EditablePart) edited).getControl());
- edited = null;
+ edited.stopEditing();
+ updateContent(edited);
+ layout(((EditablePart) edited).getControl());
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot stop editing", e);
+ } finally {
+ edited = null;
+ }
}
// METHODS AVAILABLE TO EXTENDING CLASSES
protected void saveEdit() {
- try {
- if (edited != null)
- stopEditing(true);
- } catch (RepositoryException e) {
- throw new CmsException("Cannot stop editing", e);
- }
+ if (edited != null)
+ stopEditing(true);
}
protected void cancelEdit() {
- try {
- if (edited != null)
- stopEditing(false);
- } catch (RepositoryException e) {
- throw new CmsException("Cannot cancel editing", e);
- }
+ if (edited != null)
+ stopEditing(false);
}
/** Layout this controls from the related base page. */
import org.eclipse.swt.widgets.Control;
+/** Manages whether an editable or non editable control is shown. */
public interface EditablePart {
public void startEditing();
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.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
public class EditableText extends StyledControl {
private static final long serialVersionUID = -6372283442330912755L;
- public EditableText(Composite parent, int swtStyle) {
- super(parent, swtStyle);
+ private boolean editable = true;
+
+ public EditableText(Composite parent, int style) {
+ super(parent, style);
+ editable = !(SWT.READ_ONLY == (style & SWT.READ_ONLY));
}
- public EditableText(Composite parent, int style, Item item)
- throws RepositoryException {
+ public EditableText(Composite parent, int style, Item item) throws RepositoryException {
this(parent, style, item, false);
}
- public EditableText(Composite parent, int style, Item item,
- boolean cacheImmediately) 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));
}
@Override
protected Control createControl(Composite box, String style) {
- if (isEditing())
- return createText(box, style);
- else
+ if (isEditing() && getEditable()) {
+ return createText(box, style, true);
+ } else {
+// return createText(box, style, false);
return createLabel(box, style);
+ }
}
protected Label createLabel(Composite box, String style) {
return lbl;
}
- protected Text createText(Composite box, String style) {
+ protected Text createText(Composite box, String style, boolean editable) {
final Text text = new Text(box, getStyle() | SWT.MULTI | SWT.WRAP);
+ text.setEditable(editable);
GridData textLayoutData = CmsUiUtils.fillWidth();
// textLayoutData.heightHint = preferredHeight;
text.setLayoutData(textLayoutData);
return (Label) getControl();
}
+ public String getText() {
+ Control child = getControl();
+
+ if (child instanceof Label)
+ return ((Label) child).getText();
+ else if (child instanceof Text)
+ return ((Text) child).getText();
+ else
+ throw new IllegalStateException("Unsupported control " + child.getClass());
+ }
+
+ public boolean getEditable() {
+ return editable;
+ }
+
}
if (item != null)
try {
this.session = item.getSession();
- if (!cacheImmediately && (SWT.READ_ONLY == (style & SWT.READ_ONLY))) {
- // (useless?) optimization: we only save a pointer to the session,
- // not even a reference to the item
- this.nodeId = null;
- } else {
+// if (!cacheImmediately && (SWT.READ_ONLY == (style & SWT.READ_ONLY))) {
+// // (useless?) optimization: we only save a pointer to the session,
+// // not even a reference to the item
+// this.nodeId = null;
+// } else {
Node node;
Property property = null;
if (item instanceof Node) {
this.nodeId = node.getIdentifier();
if (cacheImmediately)
this.cache = node;
- }
+// }
setLayout(CmsUiUtils.noSpaceGridLayout());
} catch (RepositoryException e) {
throw new IllegalStateException("Cannot create composite from " + item, e);
try {
if (node.hasNode(name)) {
Node child = node.getNode(name);
- if (!child.hasNode(Jcr.JCR_XMLTEXT))
- child.addNode(Jcr.JCR_XMLTEXT, JcrxType.JCRX_XMLTEXT);
- child.getNode(Jcr.JCR_XMLTEXT).setProperty(Jcr.JCR_XMLCHARACTERS, value);
+ setXmlValue(node, child, value);
} else
node.addNode(name, JcrxType.JCRX_XMLVALUE).addNode(Jcr.JCR_XMLTEXT, JcrxType.JCRX_XMLTEXT)
.setProperty(Jcr.JCR_XMLCHARACTERS, value);
} catch (RepositoryException e) {
- throw new IllegalStateException("Cannot set " + name + " as XML text", e);
+ throw new JcrException("Cannot set " + name + " as XML text", e);
+ }
+ }
+
+ public static void setXmlValue(Node node, Node child, String value) {
+ try {
+ if (!child.hasNode(Jcr.JCR_XMLTEXT))
+ child.addNode(Jcr.JCR_XMLTEXT, JcrxType.JCRX_XMLTEXT);
+ child.getNode(Jcr.JCR_XMLTEXT).setProperty(Jcr.JCR_XMLCHARACTERS, value);
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot set " + child + " as XML text", e);
}
}