Remove static style constants.
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 16 Oct 2020 08:52:21 +0000 (10:52 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 16 Oct 2020 08:52:21 +0000 (10:52 +0200)
org.argeo.cms.ui/src/org/argeo/cms/ui/CmsConstants.java
org.argeo.cms.ui/src/org/argeo/cms/ui/forms/EditableMultiStringProperty.java
org.argeo.cms.ui/src/org/argeo/cms/ui/forms/EditablePropertyDate.java
org.argeo.cms.ui/src/org/argeo/cms/ui/forms/EditablePropertyString.java
org.argeo.cms.ui/src/org/argeo/cms/ui/forms/FormStyle.java
org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsUiUtils.java
org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/StyledControl.java
org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/EclipseUiConstants.java [deleted file]
org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/EclipseUiSpecificUtils.java

index 15716850842fc6d63e7705ac50760b4b1415cc0a..304cba62711ee8ffd5a29ceb1ff77092d998bbd7 100644 (file)
@@ -1,13 +1,12 @@
 package org.argeo.cms.ui;
 
-import org.argeo.eclipse.ui.specific.EclipseUiConstants;
 import org.eclipse.swt.graphics.Point;
 
 /** Commons constants */
 public interface CmsConstants {
        // DATAKEYS
-       public final static String STYLE = EclipseUiConstants.CSS_CLASS;
-       public final static String MARKUP = EclipseUiConstants.MARKUP_SUPPORT;
+//     public final static String STYLE = EclipseUiConstants.CSS_CLASS;
+//     public final static String MARKUP = EclipseUiConstants.MARKUP_SUPPORT;
        @Deprecated
        /* RWT.CUSTOM_ITEM_HEIGHT */
        public final static String ITEM_HEIGHT = "org.eclipse.rap.rwt.customItemHeight";
index 24b1d0c67b9fd583126742b3aac92deb26b02fb8..2b3f61e943883edd819c620909d6fc2e5ff100ed 100644 (file)
@@ -30,7 +30,7 @@ public class EditableMultiStringProperty extends StyledControl implements Editab
        private String propertyName;
        private String message;
        // TODO implement the ability to provide a list of possible values
-       private String[] possibleValues;
+//     private String[] possibleValues;
        private boolean canEdit;
        private SelectionListener removeValueSL;
        private List<String> values;
@@ -50,7 +50,7 @@ public class EditableMultiStringProperty extends StyledControl implements Editab
 
                this.propertyName = propertyName;
                this.values = values;
-               this.possibleValues = new String[]{"Un", "Deux", "Trois"};
+//             this.possibleValues = new String[] { "Un", "Deux", "Trois" };
                this.message = addValueMsg;
                this.canEdit = removeValueSelectionListener != null;
                this.removeValueSL = removeValueSelectionListener;
@@ -107,10 +107,10 @@ public class EditableMultiStringProperty extends StyledControl implements Editab
        }
 
        /**
-        * Override to provide specific layout for the existing values, typically
-        * adding a pound (#) char for tags or anchor info for browsable links. We
-        * assume the parent composite already has a layout and it is the caller
-        * responsibility to apply corresponding layout data
+        * Override to provide specific layout for the existing values, typically adding
+        * a pound (#) char for tags or anchor info for browsable links. We assume the
+        * parent composite already has a layout and it is the caller responsibility to
+        * apply corresponding layout data
         */
        protected Label createValueLabel(Composite parent, int style, String value) {
                Label label = new Label(parent, style);
@@ -244,12 +244,14 @@ public class EditableMultiStringProperty extends StyledControl implements Editab
        }
 
        public synchronized void startEditing() {
-               getControl().setData(STYLE, FormStyle.propertyText.style());
+               CmsUiUtils.style(getControl(), FormStyle.propertyText.style());
+//             getControl().setData(STYLE, FormStyle.propertyText.style());
                super.startEditing();
        }
 
        public synchronized void stopEditing() {
-               getControl().setData(STYLE, FormStyle.propertyMessage.style());
+               CmsUiUtils.style(getControl(), FormStyle.propertyMessage.style());
+//             getControl().setData(STYLE, FormStyle.propertyMessage.style());
                super.stopEditing();
        }
 
index 4428d14515d15d5d91b27901648ef3986ce2e6af..fd7095f87d4b0671147f9aa5b6f591945c97befe 100644 (file)
@@ -51,14 +51,12 @@ public class EditablePropertyDate extends StyledControl implements EditablePart
         * @param node
         * @param propertyName
         * @param message
-        * @param dateFormat
-        *            provide a {@link DateFormat} as contract to be able to
-        *            read/write dates as strings
+        * @param dateFormat   provide a {@link DateFormat} as contract to be able to
+        *                     read/write dates as strings
         * @throws RepositoryException
         */
-       public EditablePropertyDate(Composite parent, int style, Node node,
-                       String propertyName, String message, DateFormat dateFormat)
-                       throws RepositoryException {
+       public EditablePropertyDate(Composite parent, int style, Node node, String propertyName, String message,
+                       DateFormat dateFormat) throws RepositoryException {
                super(parent, style, node, false);
 
                this.propertyName = propertyName;
@@ -67,8 +65,7 @@ public class EditablePropertyDate extends StyledControl implements EditablePart
 
                if (node.hasProperty(propertyName)) {
                        this.setStyle(FormStyle.propertyText.style());
-                       this.setText(dateFormat.format(node.getProperty(propertyName)
-                                       .getDate().getTime()));
+                       this.setText(dateFormat.format(node.getProperty(propertyName).getDate().getTime()));
                } else {
                        this.setStyle(FormStyle.propertyMessage.style());
                        this.setText(message);
@@ -94,15 +91,18 @@ public class EditablePropertyDate extends StyledControl implements EditablePart
 
        public synchronized void startEditing() {
                // if (dateTxt != null && !dateTxt.isDisposed())
-               getControl().setData(STYLE, FormStyle.propertyText.style());
+               CmsUiUtils.style(getControl(), FormStyle.propertyText);
+//             getControl().setData(STYLE, FormStyle.propertyText.style());
                super.startEditing();
        }
 
        public synchronized void stopEditing() {
                if (EclipseUiUtils.isEmpty(dateTxt.getText()))
-                       getControl().setData(STYLE, FormStyle.propertyMessage.style());
+                       CmsUiUtils.style(getControl(), FormStyle.propertyMessage);
+//                     getControl().setData(STYLE, FormStyle.propertyMessage.style());
                else
-                       getControl().setData(STYLE, FormStyle.propertyText.style());
+                       CmsUiUtils.style(getControl(), FormStyle.propertyText);
+//             getControl().setData(STYLE, FormStyle.propertyText.style());
                super.stopEditing();
        }
 
@@ -131,19 +131,16 @@ public class EditablePropertyDate extends StyledControl implements EditablePart
        private Control createCustomEditableControl(Composite box, String style) {
                box.setLayoutData(CmsUiUtils.fillWidth());
                Composite dateComposite = new Composite(box, SWT.NONE);
-               GridLayout gl = EclipseUiUtils.noSpaceGridLayout(new GridLayout(2,
-                               false));
+               GridLayout gl = EclipseUiUtils.noSpaceGridLayout(new GridLayout(2, false));
                gl.horizontalSpacing = fieldBtnSpacing;
                dateComposite.setLayout(gl);
                dateTxt = new Text(dateComposite, SWT.BORDER);
                CmsUiUtils.style(dateTxt, style);
                dateTxt.setLayoutData(new GridData(120, SWT.DEFAULT));
-               dateTxt.setToolTipText("Enter a date with form \""
-                               + FormUtils.DEFAULT_SHORT_DATE_FORMAT
-                               + "\" or use the calendar");
+               dateTxt.setToolTipText(
+                               "Enter a date with form \"" + FormUtils.DEFAULT_SHORT_DATE_FORMAT + "\" or use the calendar");
                openCalBtn = new Button(dateComposite, SWT.FLAT);
-               CmsUiUtils.style(openCalBtn, FormStyle.calendar.style()
-                               + FormStyle.BUTTON_SUFFIX);
+               CmsUiUtils.style(openCalBtn, FormStyle.calendar.style() + FormStyle.BUTTON_SUFFIX);
                GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);
                gd.heightHint = 17;
                openCalBtn.setLayoutData(gd);
@@ -231,8 +228,7 @@ public class EditablePropertyDate extends StyledControl implements EditablePart
                        CmsUiUtils.style(CalendarPopup.this, FormStyle.popupCalendar.style());
                        pack();
                        layout();
-                       setLocation(source.toDisplay((source.getLocation().x - 2),
-                                       (source.getSize().y) + 3));
+                       setLocation(source.toDisplay((source.getLocation().x - 2), (source.getSize().y) + 3));
 
                        addShellListener(new ShellAdapter() {
                                private static final long serialVersionUID = 5178980294808435833L;
@@ -264,12 +260,10 @@ public class EditablePropertyDate extends StyledControl implements EditablePart
                        dateTimeCtl = new DateTime(this, SWT.CALENDAR);
                        dateTimeCtl.setLayoutData(EclipseUiUtils.fillAll());
 
-                       Calendar calendar = FormUtils.parseDate(dateFormat,
-                                       dateTxt.getText());
+                       Calendar calendar = FormUtils.parseDate(dateFormat, dateTxt.getText());
 
                        if (calendar != null)
-                               dateTimeCtl.setDate(calendar.get(Calendar.YEAR),
-                                               calendar.get(Calendar.MONTH),
+                               dateTimeCtl.setDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                                                calendar.get(Calendar.DAY_OF_MONTH));
 
                        dateTimeCtl.addSelectionListener(new SelectionAdapter() {
index 1ab0338cbdf87945692f4d404b9669fb0b6cdbd8..265621d32c0b838bc3c7ae4562df763000a36c59 100644 (file)
@@ -6,6 +6,7 @@ import static org.argeo.cms.ui.forms.FormStyle.propertyText;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
+import org.argeo.cms.ui.util.CmsUiUtils;
 import org.argeo.cms.ui.viewers.EditablePart;
 import org.argeo.cms.ui.widgets.EditableText;
 import org.argeo.eclipse.ui.EclipseUiUtils;
@@ -15,8 +16,7 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 
 /** Editable String in a CMS context */
-public class EditablePropertyString extends EditableText implements
-               EditablePart {
+public class EditablePropertyString extends EditableText implements EditablePart {
        private static final long serialVersionUID = 5055000749992803591L;
 
        private String propertyName;
@@ -26,8 +26,8 @@ public class EditablePropertyString extends EditableText implements
        private final static String AMPERSAND = "&#38;";
        private final static String AMPERSAND_REGEX = "&(?![#a-zA-Z0-9]+;)";
 
-       public EditablePropertyString(Composite parent, int style, Node node,
-                       String propertyName, String message) throws RepositoryException {
+       public EditablePropertyString(Composite parent, int style, Node node, String propertyName, String message)
+                       throws RepositoryException {
                super(parent, style, node, true);
 
                this.propertyName = propertyName;
@@ -62,15 +62,18 @@ public class EditablePropertyString extends EditableText implements
        }
 
        public synchronized void startEditing() {
-               getControl().setData(STYLE, propertyText.style());
+               CmsUiUtils.style(getControl(), FormStyle.propertyText);
+//             getControl().setData(STYLE, propertyText.style());
                super.startEditing();
        }
 
        public synchronized void stopEditing() {
                if (EclipseUiUtils.isEmpty(((Text) getControl()).getText()))
-                       getControl().setData(STYLE, propertyMessage.style());
+                       CmsUiUtils.style(getControl(), FormStyle.propertyMessage);
+//                     getControl().setData(STYLE, propertyMessage.style());
                else
-                       getControl().setData(STYLE, propertyText.style());
+                       CmsUiUtils.style(getControl(), FormStyle.propertyText);
+//                     getControl().setData(STYLE, propertyText.style());
                super.stopEditing();
        }
 
index 7e1b8b02951989eb6bd9115937b10f773ac13c8f..5f3f1c288d778c917c28d6b605789732135f4fe8 100644 (file)
@@ -1,7 +1,9 @@
 package org.argeo.cms.ui.forms;
 
+import org.argeo.cms.ui.util.CmsStyle;
+
 /** Syles used */
-public enum FormStyle {
+public enum FormStyle implements CmsStyle {
        // Main
        form, title,
        // main part
index 4e5572dbde6f19cf9bb9e84f683b45bd9100ac73..5d6030ec4b72aa6de533281405ef7fff89eacd91 100644 (file)
@@ -16,6 +16,7 @@ import org.argeo.api.NodeUtils;
 import org.argeo.cms.ui.CmsConstants;
 import org.argeo.cms.ui.CmsView;
 import org.argeo.eclipse.ui.Selected;
+import org.argeo.eclipse.ui.specific.EclipseUiSpecificUtils;
 import org.argeo.jcr.JcrUtils;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.service.ResourceManager;
@@ -180,7 +181,7 @@ public class CmsUiUtils implements CmsConstants {
        public static <T extends Widget> T style(T widget, String style) {
                if (style == null)
                        return widget;// does nothing
-               widget.setData(CmsConstants.STYLE, style);
+               EclipseUiSpecificUtils.setStyleData(widget, style);
                if (widget instanceof Control)
                        CmsView.getCmsView(((Control) widget).getParent()).applyStyles(widget);
                return widget;
@@ -193,8 +194,7 @@ public class CmsUiUtils implements CmsConstants {
 
        /** Enable markups on widget */
        public static <T extends Widget> T markup(T widget) {
-               if (CmsConstants.MARKUP != null)
-                       widget.setData(CmsConstants.MARKUP, true);
+               EclipseUiSpecificUtils.setMarkupData(widget);
                return widget;
        }
 
index 9d7037c25a9ef315427eb0e0624d474c17fc1f01..0455d2cdc9e1f0669b8e5eecd521f1a5c53c83d3 100644 (file)
@@ -1,10 +1,10 @@
 package org.argeo.cms.ui.widgets;
 
 import javax.jcr.Item;
-import javax.jcr.RepositoryException;
 
 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;
@@ -59,7 +59,7 @@ public abstract class StyledControl extends JcrComposite implements CmsConstants
                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);
@@ -72,7 +72,7 @@ public abstract class StyledControl extends JcrComposite implements CmsConstants
        public synchronized void stopEditing() {
                assert isEditing();
                editing = false;
-               String style = (String) control.getData(STYLE);
+               String style = (String) EclipseUiSpecificUtils.getStyleData(control);
                clear(false);
                control = createControl(box, style);
                setControlLayoutData(control);
@@ -81,7 +81,7 @@ public abstract class StyledControl extends JcrComposite implements CmsConstants
        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;
 
@@ -91,8 +91,10 @@ public abstract class StyledControl extends JcrComposite implements CmsConstants
                control = createControl(box, style);
                setControlLayoutData(control);
 
-               control.getParent().setData(STYLE, style + "_box");
-               control.getParent().getParent().setData(STYLE, style + "_container");
+//             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");
        }
 
        /** To be overridden */
diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/EclipseUiConstants.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/EclipseUiConstants.java
deleted file mode 100644 (file)
index 76ad973..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.argeo.eclipse.ui.specific;
-
-import org.eclipse.rap.rwt.RWT;
-
-/** Constants which are specific to RWT.*/
-public interface EclipseUiConstants {
-       final static String CSS_CLASS = RWT.CUSTOM_VARIANT;
-       final static String MARKUP_SUPPORT = RWT.MARKUP_ENABLED;
-}
index b196bfc03e1e1500e14ced4efe559aa84ad897ca..f79c7fd88ab910ca16702d3e1ccdcdf4226e98d0 100644 (file)
@@ -4,10 +4,24 @@ import org.eclipse.jface.viewers.AbstractTableViewer;
 import org.eclipse.jface.viewers.ColumnViewer;
 import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
 import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.rap.rwt.RWT;
+import org.eclipse.swt.widgets.Widget;
 
 /** Static utilities to bridge differences between RCP and RAP */
 public class EclipseUiSpecificUtils {
 
+       public static void setStyleData(Widget widget, Object data) {
+               widget.setData(RWT.CUSTOM_VARIANT, data);
+       }
+
+       public static Object getStyleData(Widget widget) {
+               return widget.getData(RWT.CUSTOM_VARIANT);
+       }
+
+       public static void setMarkupData(Widget widget) {
+               widget.setData(RWT.MARKUP_ENABLED, true);
+       }
+
        /**
         * TootlTip support is supported only for {@link AbstractTableViewer} in RAP
         */