Improve read-only terms parts.
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 14 Feb 2021 07:33:03 +0000 (08:33 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 14 Feb 2021 07:33:03 +0000 (08:33 +0100)
core/org.argeo.entity.ui/src/org/argeo/entity/ui/forms/AbstractTermsPart.java
core/org.argeo.entity.ui/src/org/argeo/entity/ui/forms/MultiTermsPart.java
core/org.argeo.entity.ui/src/org/argeo/entity/ui/forms/SingleTermPart.java

index 1d9b6bc713b7e59dfce9f97915111520434448d9..36ae2746f8a5e83d74b1205ec961a2cc8987dd70 100644 (file)
@@ -27,7 +27,7 @@ public abstract class AbstractTermsPart extends StyledControl implements Editabl
        protected final TermsManager termsManager;
        protected final Typology typology;
 
        protected final TermsManager termsManager;
        protected final Typology typology;
 
-       protected final boolean editable;
+       private final boolean editable;
 
        private CmsIcon deleteIcon;
        private CmsIcon addIcon;
 
        private CmsIcon deleteIcon;
        private CmsIcon addIcon;
@@ -37,7 +37,7 @@ public abstract class AbstractTermsPart extends StyledControl implements Editabl
        private Composite highlight;
 
        protected final CmsTheme theme;
        private Composite highlight;
 
        protected final CmsTheme theme;
-
+       
        public AbstractTermsPart(Composite parent, int style, Item item, TermsManager termsManager, String typology) {
                super(parent, style, item);
                if (item == null)
        public AbstractTermsPart(Composite parent, int style, Item item, TermsManager termsManager, String typology) {
                super(parent, style, item);
                if (item == null)
@@ -49,6 +49,10 @@ public abstract class AbstractTermsPart extends StyledControl implements Editabl
                highlightColor = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY);
        }
 
                highlightColor = parent.getDisplay().getSystemColor(SWT.COLOR_GRAY);
        }
 
+       public boolean isEditable() {
+               return editable;
+       }
+
        protected void createHighlight(Composite block) {
                highlight = new Composite(block, SWT.NONE);
                highlight.setBackground(highlightColor);
        protected void createHighlight(Composite block) {
                highlight = new Composite(block, SWT.NONE);
                highlight.setBackground(highlightColor);
index 9c3618d8d262c981449480d82af77be14209513f..711596f22433cf7cfa77ccad0a63babea42d0bb5 100644 (file)
@@ -55,7 +55,7 @@ public class MultiTermsPart extends AbstractTermsPart {
                                String display = getTermLabel(value);
                                lbl.setText(display);
                                CmsUiUtils.style(lbl, style == null ? FormStyle.propertyText.style() : style);
                                String display = getTermLabel(value);
                                lbl.setText(display);
                                CmsUiUtils.style(lbl, style == null ? FormStyle.propertyText.style() : style);
-                               if (editable)
+                               if (isEditable())
                                        lbl.addMouseListener((MouseDoubleClick) (e) -> {
                                                startEditing();
                                        });
                                        lbl.addMouseListener((MouseDoubleClick) (e) -> {
                                                startEditing();
                                        });
@@ -79,7 +79,7 @@ public class MultiTermsPart extends AbstractTermsPart {
                                }
                        }
                else {// empty
                                }
                        }
                else {// empty
-                       if (editable && !isEditing()) {
+                       if (isEditable() && !isEditing()) {
                                ToolBar toolBar = new ToolBar(placeholder, SWT.HORIZONTAL);
                                ToolItem addItem = new ToolItem(toolBar, SWT.FLAT);
                                styleAdd(addItem);
                                ToolBar toolBar = new ToolBar(placeholder, SWT.HORIZONTAL);
                                ToolItem addItem = new ToolItem(toolBar, SWT.FLAT);
                                styleAdd(addItem);
index 0dcf13d128c5e43659ceeff3950336d126dc500a..4be4d0205741bc008421d1b714f6b205a24f582a 100644 (file)
@@ -101,17 +101,20 @@ public class SingleTermPart extends AbstractTermsPart {
                                String display = getTermLabel(currentValue);
                                lbl.setText(display);
                                CmsUiUtils.style(lbl, style == null ? FormStyle.propertyText.style() : style);
                                String display = getTermLabel(currentValue);
                                lbl.setText(display);
                                CmsUiUtils.style(lbl, style == null ? FormStyle.propertyText.style() : style);
-
-                               lbl.addMouseListener((MouseDoubleClick) (e) -> {
-                                       startEditing();
-                               });
+                               if (isEditable()) {
+                                       lbl.addMouseListener((MouseDoubleClick) (e) -> {
+                                               startEditing();
+                                       });
+                               }
                        } else {
                        } else {
-                               ToolBar toolBar = new ToolBar(block, SWT.HORIZONTAL);
-                               ToolItem addItem = new ToolItem(toolBar, SWT.FLAT);
-                               styleAdd(addItem);
-                               addItem.addSelectionListener((Selected) (e) -> {
-                                       startEditing();
-                               });
+                               if (isEditable()) {
+                                       ToolBar toolBar = new ToolBar(block, SWT.HORIZONTAL);
+                                       ToolItem addItem = new ToolItem(toolBar, SWT.FLAT);
+                                       styleAdd(addItem);
+                                       addItem.addSelectionListener((Selected) (e) -> {
+                                               startEditing();
+                                       });
+                               }
                        }
                        return block;
                }
                        }
                        return block;
                }