Improve content widgets
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 23 Jun 2023 09:19:29 +0000 (11:19 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 23 Jun 2023 09:19:29 +0000 (11:19 +0200)
org.argeo.api.cms/src/org/argeo/api/cms/ux/CmsView.java
org.argeo.cms.ux/src/org/argeo/cms/ux/acr/ContentPart.java
swt/org.argeo.cms.swt/src/org/argeo/cms/swt/acr/AbstractPageViewer.java
swt/org.argeo.cms.swt/src/org/argeo/cms/swt/acr/ContentComposite.java
swt/org.argeo.cms.swt/src/org/argeo/cms/swt/acr/ContentStyledControl.java [new file with mode: 0644]
swt/org.argeo.cms.swt/src/org/argeo/cms/swt/acr/Img.java

index 15b6a5dc7aac338a7180f748fa404c31f4f28bb0..a36baf8e08b642cd2c7b625162494ae9710b9d14 100644 (file)
@@ -31,7 +31,7 @@ public interface CmsView {
        // SERVICES
        void exception(Throwable e);
 
-       CmsImageManager<?, ?> getImageManager();
+       <V,M> CmsImageManager<V, M> getImageManager();
 
        boolean isAnonymous();
 
index 0a0ad0ea5e6eb2c81a96417bf92ed05f360e056a..db8a746fcf5d4be79b614c7c7f2a29b66525e2a3 100644 (file)
@@ -6,9 +6,9 @@ import org.argeo.api.acr.Content;
 public interface ContentPart {
        Content getContent();
 
-       @Deprecated
-       default Content getNode() {
-               return getContent();
-       }
+//     @Deprecated
+//     default Content getNode() {
+//             return getContent();
+//     }
 
 }
index cf05f6f6455d939f7dd4618ad62e3ec9de78677c..fab29fa3b1625c7e782ab7d3aaf8aa80df866e79 100644 (file)
@@ -4,9 +4,6 @@ import java.security.PrivilegedAction;
 
 import javax.security.auth.Subject;
 
-import org.argeo.api.acr.Content;
-import org.argeo.api.acr.ContentSession;
-import org.argeo.api.acr.spi.ProvidedContent;
 import org.argeo.api.cms.CmsLog;
 import org.argeo.api.cms.ux.CmsEditable;
 import org.argeo.cms.CurrentUser;
@@ -274,17 +271,17 @@ public abstract class AbstractPageViewer {
                        throw new IllegalStateException("Edited should not be null or disposed at this stage");
        }
 
-       /** Persist all changes. */
-       protected void persistChanges(ContentSession session) {
-//             session.save();
-//             session.refresh(false);
-               // TODO notify that changes have been persisted
-       }
-
-       /** Convenience method using a Node in order to save the underlying session. */
-       protected void persistChanges(Content anyNode) {
-               persistChanges(((ProvidedContent) anyNode).getSession());
-       }
+//     /** Persist all changes. */
+//     protected void persistChanges(ContentSession session) {
+////           session.save();
+////           session.refresh(false);
+//             // TODO notify that changes have been persisted
+//     }
+//
+//     /** Convenience method using a Node in order to save the underlying session. */
+//     protected void persistChanges(Content anyNode) {
+//             persistChanges(((ProvidedContent) anyNode).getSession());
+//     }
 
        /** Notify edition exception */
        protected void notifyEditionException(Throwable e) {
index 4a35a3bdd2b697e519662858f258989b7b752787..4cab6d0083d40a08ad31e315031a0a530712d518 100644 (file)
@@ -2,10 +2,11 @@ package org.argeo.cms.swt.acr;
 
 import org.argeo.api.acr.Content;
 import org.argeo.api.acr.spi.ProvidedContent;
+import org.argeo.cms.ux.acr.ContentPart;
 import org.eclipse.swt.widgets.Composite;
 
 /** A composite which can (optionally) manage a content. */
-public class ContentComposite extends Composite {
+public class ContentComposite extends Composite implements ContentPart {
        private static final long serialVersionUID = -1447009015451153367L;
 
        public ContentComposite(Composite parent, int style, Content item) {
@@ -20,6 +21,7 @@ public class ContentComposite extends Composite {
                return getData() instanceof Content;
        }
 
+       @Override
        public Content getContent() {
                return (Content) getData();
        }
diff --git a/swt/org.argeo.cms.swt/src/org/argeo/cms/swt/acr/ContentStyledControl.java b/swt/org.argeo.cms.swt/src/org/argeo/cms/swt/acr/ContentStyledControl.java
new file mode 100644 (file)
index 0000000..78ec800
--- /dev/null
@@ -0,0 +1,22 @@
+package org.argeo.cms.swt.acr;
+
+import org.argeo.api.acr.Content;
+import org.argeo.cms.swt.widgets.StyledControl;
+import org.argeo.cms.ux.acr.ContentPart;
+import org.eclipse.swt.widgets.Composite;
+
+public abstract class ContentStyledControl extends StyledControl implements ContentPart {
+
+       private static final long serialVersionUID = -5714246408818696583L;
+
+       public ContentStyledControl(Composite parent, int swtStyle, Content content) {
+               super(parent, swtStyle);
+               setData(content);
+       }
+
+       @Override
+       public Content getContent() {
+               return (Content) getData();
+       }
+
+}
index eb52fc6a37904ad00ed20e193d241559da714edd..a5d22bca1b2fe5dde04b5ed48adcd5c27b6323a4 100644 (file)
@@ -44,8 +44,7 @@ public class Img extends EditableImage implements SwtSectionPart, ContentPart {
                        CmsImageManager<Control, Content> imageManager) {
                super(parent, swtStyle, preferredImageSize);
                this.section = section;
-               this.imageManager = imageManager != null ? imageManager
-                               : (CmsImageManager<Control, Content>) CmsSwtUtils.getCmsView(section).getImageManager();
+               this.imageManager = imageManager != null ? imageManager : CmsSwtUtils.getCmsView(section).getImageManager();
 //             CmsSwtUtils.style(this, TextStyles.TEXT_IMG);
                setData(imgNode);
        }