+ /*
+ * CONTENT
+ */
+ public static String toLink(Content content) {
+ return content != null ? "#" + ContentUtils.cleanPathForUrl(content.getPath()) : null;
+ }
+
+ public static Text addFormLine(Composite parent, Localized label, Content content, QNamed property,
+ CmsEditable cmsEditable) {
+ return addFormLine(parent, label.lead(), content, property.qName(), cmsEditable);
+ }
+
+ public static EditableText addTextLine(Composite parent, int style, Localized msg, Content content, QNamed attr,
+ CmsEditable cmsEditable, boolean line, Predicate<String> validator) {
+ Composite parentToUse = line ? SuiteSwtUtils.addLineComposite(parent, 2) : parent;
+ SuiteSwtUtils.addFormLabel(parentToUse, msg.lead());
+ EditableText text = createFormText(parentToUse, style, msg, content, attr, cmsEditable, validator);
+ return text;
+ }
+
+ public static EditableText createFormText(Composite parent, int style, Localized msg, Content content, QNamed attr,
+ CmsEditable cmsEditable, Predicate<String> validator) {
+ EditableText text = new EditableText(parent, style | SWT.FLAT | (cmsEditable.isEditing() ? 0 : SWT.READ_ONLY));
+ text.setMessage("-");
+ text.setLayoutData(CmsSwtUtils.fillWidth());
+ text.setStyle(SuiteStyle.simpleInput);
+ String txt = content.attr(attr);
+ if (txt == null)
+ txt = "";
+ text.setText(txt);
+ if (cmsEditable.isEditing())
+ text.setMouseListener(new MouseAdapter() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ String currentTxt = text.getText();
+ text.startEditing();
+ text.setText(currentTxt);
+
+ Runnable save = () -> {
+ String editedTxt = text.getText();
+ if (validator != null) {
+ if (!validator.test(editedTxt)) {
+ text.stopEditing();
+ text.setText(currentTxt);
+ CmsFeedback.show(editedTxt + " is not properly formatted");
+ return;
+ // throw new IllegalArgumentException(editedTxt + " is not properly formatted");
+ }
+ }
+ content.put(attr, editedTxt);
+ text.stopEditing();
+ text.setText(editedTxt);
+ text.getParent().layout(new Control[] { text.getControl() });
+ };
+ ((Text) text.getControl()).addSelectionListener(new SelectionListener() {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ save.run();
+ }
+ });
+ ((Text) text.getControl()).addFocusListener(new FocusListener() {
+
+ private static final long serialVersionUID = 333838002411959302L;
+
+ @Override
+ public void focusLost(FocusEvent event) {
+ save.run();
+ }
+
+ @Override
+ public void focusGained(FocusEvent event) {
+ }
+ });
+
+ }
+
+ });
+ return text;
+ }
+
+ public static Text addFormLine(Composite parent, String label, Content content, QName property,
+ CmsEditable cmsEditable) {
+ Composite lineComposite = SuiteSwtUtils.addLineComposite(parent, 2);
+ SuiteSwtUtils.addFormLabel(lineComposite, label);
+ String text = content.attr(property);
+ Text txt = SuiteSwtUtils.addFormTextField(lineComposite, text, null, SWT.WRAP);
+ if (cmsEditable != null && cmsEditable.isEditing()) {
+ txt.addModifyListener((e) -> {
+ content.put(property, txt.getText());
+ });
+ } else {
+ txt.setEditable(false);
+ }
+ txt.setLayoutData(CmsSwtUtils.fillWidth());
+ return txt;
+ }
+
+ public static Text addFormColumn(Composite parent, Localized label, Content content, QNamed property,
+ CmsEditable cmsEditable) {
+ return addFormColumn(parent, label.lead(), content, property.qName(), cmsEditable);
+ }
+
+ public static Text addFormColumn(Composite parent, String label, Content content, QName property,
+ CmsEditable cmsEditable) {
+ SuiteSwtUtils.addFormLabel(parent, label);
+ String text = content.attr(property);
+ Text txt = SuiteSwtUtils.addFormTextField(parent, text, null, 0);
+ if (cmsEditable != null && cmsEditable.isEditing()) {
+ txt.addModifyListener((e) -> {
+ content.put(property, txt.getText().trim());
+ });
+ } else {
+ txt.setEditable(false);
+ }
+ txt.setLayoutData(CmsSwtUtils.fillWidth());
+ return txt;
+ }
+
+ /*
+ * LINKS
+ */
+
+ /** Add a link to an internal content. */
+ public static Control addLink(Composite parent, String label, Content node, CmsStyle style) {
+ String target = toLink(node);
+ CmsLink link = new CmsLink(label, target, style);
+ return link.createUi(parent);