Make default edition layer more flexible.
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 22 Nov 2020 10:37:36 +0000 (11:37 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 22 Nov 2020 10:37:36 +0000 (11:37 +0100)
org.argeo.suite.ui/src/org/argeo/suite/ui/DefaultEditionLayer.java

index 6e77937f82a7347af2ede52208df397381c84f78..2070d9004e8b96ce0c6813b6416a74c794d030b9 100644 (file)
@@ -16,25 +16,44 @@ import org.eclipse.swt.widgets.Control;
 /** An app layer based on an entry area and an editor area. */
 public class DefaultEditionLayer implements SuiteLayer {
        private CmsUiProvider entryArea;
+       private CmsUiProvider workArea;
 
        @Override
        public Control createUi(Composite parent, Node context) throws RepositoryException {
-               DefaultEditionArea workArea = new DefaultEditionArea(parent, parent.getStyle());
                if (entryArea != null) {
-                       entryArea.createUi(workArea.getEntryArea(), context);
+                       SashFormEditionArea sashFormEditionArea = new SashFormEditionArea(parent, parent.getStyle());
+                       entryArea.createUi(sashFormEditionArea.getEntryArea(), context);
+                       if (this.workArea != null) {
+                               this.workArea.createUi(sashFormEditionArea.getEditorArea(), context);
+                       }
+                       return sashFormEditionArea;
+               } else {
+                       if (this.workArea != null) {
+                               Composite area = new Composite(parent, SWT.NONE);
+                               this.workArea.createUi(area, context);
+                               return area;
+                       }
+                       CmsTheme theme = CmsTheme.getCmsTheme(parent);
+                       TabbedArea tabbedArea = createTabbedArea(parent, theme);
+                       return tabbedArea;
                }
-               return workArea;
        }
 
        @Override
        public void view(CmsUiProvider uiProvider, Composite workArea, Node context) {
-               TabbedArea tabbedArea = ((DefaultEditionArea) workArea).getTabbedArea();
+               TabbedArea tabbedArea;
+               if (workArea instanceof SashFormEditionArea) {
+                       tabbedArea = ((SashFormEditionArea) workArea).getTabbedArea();
+               } else if (workArea instanceof TabbedArea) {
+                       tabbedArea = (TabbedArea) workArea;
+               } else
+                       throw new IllegalArgumentException("Unsupported work area " + workArea.getClass().getName());
                tabbedArea.view(uiProvider, context);
        }
 
        @Override
        public void open(CmsUiProvider uiProvider, Composite workArea, Node context) {
-               TabbedArea tabbedArea = ((DefaultEditionArea) workArea).getTabbedArea();
+               TabbedArea tabbedArea = ((SashFormEditionArea) workArea).getTabbedArea();
                tabbedArea.open(uiProvider, context);
        }
 
@@ -42,19 +61,31 @@ public class DefaultEditionLayer implements SuiteLayer {
                this.entryArea = entryArea;
        }
 
-       class DefaultEditionArea extends SashForm {
+       public void setWorkArea(CmsUiProvider workArea) {
+               this.workArea = workArea;
+       }
+
+       TabbedArea createTabbedArea(Composite parent, CmsTheme theme) {
+               TabbedArea tabbedArea = new TabbedArea(parent, SWT.NONE);
+               tabbedArea.setBodyStyle(SuiteStyle.mainTabBody.toStyleClass());
+               tabbedArea.setTabStyle(SuiteStyle.mainTab.toStyleClass());
+               tabbedArea.setTabSelectedStyle(SuiteStyle.mainTabSelected.toStyleClass());
+               tabbedArea.setCloseIcon(SuiteIcon.close.getSmallIcon(theme));
+               tabbedArea.setLayoutData(CmsUiUtils.fillAll());
+               return tabbedArea;
+       }
+
+       /** A work area based on an entry area and and a tabbed area. */
+       class SashFormEditionArea extends SashForm {
                private static final long serialVersionUID = 2219125778722702618L;
                private CmsTheme theme;
-//             private SashForm area;
                private Composite entryArea;
                private Composite editorArea;
                private TabbedArea tabbedArea;
 
-               DefaultEditionArea(Composite parent, int style) {
+               SashFormEditionArea(Composite parent, int style) {
                        super(parent, SWT.HORIZONTAL);
                        theme = CmsTheme.getCmsTheme(parent);
-//                     area = new SashForm(parent, SWT.HORIZONTAL);
-//                     area.setLayoutData(CmsUiUtils.coversAll());
 
                        if (SWT.RIGHT_TO_LEFT == (style & SWT.RIGHT_TO_LEFT)) {// arabic, hebrew, etc.
                                editorArea = new Composite(this, SWT.BORDER);
@@ -63,29 +94,26 @@ public class DefaultEditionLayer implements SuiteLayer {
                                entryArea = new Composite(this, SWT.NONE);
                                editorArea = new Composite(this, SWT.NONE);
                        }
-                       int[] weights = new int[] { 2000, 8000 };
+                       int[] weights = new int[] { 3000, 7000 };
                        setWeights(weights);
-//                     editorArea.setLayout(CmsUiUtils.noSpaceGridLayout());
                        editorArea.setLayout(new GridLayout());
 
-                       tabbedArea = new TabbedArea(editorArea, SWT.NONE);
-                       tabbedArea.setBodyStyle(SuiteStyle.mainTabBody.toStyleClass());
-                       tabbedArea.setTabStyle(SuiteStyle.mainTab.toStyleClass());
-                       tabbedArea.setTabSelectedStyle(SuiteStyle.mainTabSelected.toStyleClass());
-                       tabbedArea.setCloseIcon(SuiteIcon.close.getSmallIcon(theme));
-                       tabbedArea.setLayoutData(CmsUiUtils.fillAll());
+                       if (DefaultEditionLayer.this.workArea == null) {
+                               tabbedArea = createTabbedArea(editorArea, theme);
+                       }
                }
 
-//             Composite getArea() {
-//                     return area;
-//             }
-//
-               public Composite getEntryArea() {
+               Composite getEntryArea() {
                        return entryArea;
                }
 
-               public TabbedArea getTabbedArea() {
+               TabbedArea getTabbedArea() {
                        return tabbedArea;
                }
+
+               Composite getEditorArea() {
+                       return editorArea;
+               }
+
        }
 }
\ No newline at end of file