X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=org.argeo.suite.ui%2Fsrc%2Forg%2Fargeo%2Fsuite%2Fui%2FDefaultEditionLayer.java;h=b36778c2caf02a3e88961c34dc99f245f22dc302;hp=6e77937f82a7347af2ede52208df397381c84f78;hb=3cf66bc01bb8ad4c55139ae01be5a5bdb3759e2c;hpb=f21589b7f2a19a79edcc213b867c47130faa76cd diff --git a/org.argeo.suite.ui/src/org/argeo/suite/ui/DefaultEditionLayer.java b/org.argeo.suite.ui/src/org/argeo/suite/ui/DefaultEditionLayer.java index 6e77937..b36778c 100644 --- a/org.argeo.suite.ui/src/org/argeo/suite/ui/DefaultEditionLayer.java +++ b/org.argeo.suite.ui/src/org/argeo/suite/ui/DefaultEditionLayer.java @@ -1,91 +1,286 @@ package org.argeo.suite.ui; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + import javax.jcr.Node; import javax.jcr.RepositoryException; -import org.argeo.cms.ui.CmsTheme; +import org.argeo.api.cms.CmsTheme; +import org.argeo.cms.Localized; +import org.argeo.cms.swt.CmsSwtUtils; import org.argeo.cms.ui.CmsUiProvider; -import org.argeo.cms.ui.util.CmsUiUtils; -import org.argeo.cms.ui.widgets.TabbedArea; +import org.argeo.jcr.JcrException; +import org.argeo.suite.ui.widgets.TabbedArea; +import org.argeo.util.LangUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.osgi.framework.BundleContext; +import org.osgi.framework.wiring.BundleWiring; /** An app layer based on an entry area and an editor area. */ public class DefaultEditionLayer implements SuiteLayer { private CmsUiProvider entryArea; + private CmsUiProvider defaultView; + private CmsUiProvider workArea; + private List weights = new ArrayList<>(); + private boolean startMaximized = false; + private boolean fixedEntryArea = false; + private boolean singleTab = false; + private Localized title = null; @Override public Control createUi(Composite parent, Node context) throws RepositoryException { - DefaultEditionArea workArea = new DefaultEditionArea(parent, parent.getStyle()); + // TODO Factorize more, or split into more specialised classes? if (entryArea != null) { - entryArea.createUi(workArea.getEntryArea(), context); + if (fixedEntryArea) { + FixedEditionArea editionArea = new FixedEditionArea(parent, parent.getStyle()); + Control entryAreaC = entryArea.createUi(editionArea.getEntryArea(), context); + CmsSwtUtils.style(entryAreaC, SuiteStyle.entryArea); + if (this.defaultView != null) { + editionArea.getTabbedArea().view(defaultView, context); + } + return editionArea; + } else { + SashFormEditionArea editionArea = new SashFormEditionArea(parent, parent.getStyle()); + entryArea.createUi(editionArea.getEntryArea(), context); + if (this.defaultView != null) { + editionArea.getTabbedArea().view(defaultView, context); + } + return editionArea; + } + } else { + if (this.workArea != null) { + Composite area = new Composite(parent, SWT.NONE); + this.workArea.createUi(area, context); + return area; + } + CmsTheme theme = CmsSwtUtils.getCmsTheme(parent); + TabbedArea tabbedArea = createTabbedArea(parent, theme); + return tabbedArea; + } + } + + @Override + public void view(CmsUiProvider uiProvider, Composite workAreaC, Node context) { + if (workArea != null) { + try { + CmsSwtUtils.clear(workAreaC); + workArea.createUi(workAreaC, context); + workAreaC.layout(true, true); + return; + } catch (RepositoryException e) { + throw new JcrException("Cannot rebuild work area", e); + } + } + + // tabbed area + TabbedArea tabbedArea = findTabbedArea(workAreaC); + if (tabbedArea == null) + throw new IllegalArgumentException("Unsupported work area " + workAreaC.getClass().getName()); + if (uiProvider == null) { + // reset + tabbedArea.closeAllTabs(); + if (this.defaultView != null) { + tabbedArea.view(defaultView, context); + } + } else { + tabbedArea.view(uiProvider, context); } - return workArea; } @Override - public void view(CmsUiProvider uiProvider, Composite workArea, Node context) { - TabbedArea tabbedArea = ((DefaultEditionArea) workArea).getTabbedArea(); - tabbedArea.view(uiProvider, context); + public Node getCurrentContext(Composite workArea) { + TabbedArea tabbedArea = findTabbedArea(workArea); + if (tabbedArea == null) + return null; + return tabbedArea.getCurrentContext(); + } + + private TabbedArea findTabbedArea(Composite workArea) { + TabbedArea tabbedArea = null; + if (workArea instanceof SashFormEditionArea) { + tabbedArea = ((SashFormEditionArea) workArea).getTabbedArea(); + } else if (workArea instanceof FixedEditionArea) { + tabbedArea = ((FixedEditionArea) workArea).getTabbedArea(); + } else if (workArea instanceof TabbedArea) { + tabbedArea = (TabbedArea) workArea; + } + return tabbedArea; } @Override public void open(CmsUiProvider uiProvider, Composite workArea, Node context) { - TabbedArea tabbedArea = ((DefaultEditionArea) workArea).getTabbedArea(); + TabbedArea tabbedArea = ((SashFormEditionArea) workArea).getTabbedArea(); tabbedArea.open(uiProvider, context); } + @Override + public Localized getTitle() { + return title; + } + + public void init(BundleContext bundleContext, Map properties) { + weights = LangUtils.toStringList(properties.get(Property.weights.name())); + startMaximized = properties.containsKey(Property.startMaximized.name()) + && "true".equals(properties.get(Property.startMaximized.name())); + fixedEntryArea = properties.containsKey(Property.fixedEntryArea.name()) + && "true".equals(properties.get(Property.fixedEntryArea.name())); + if (fixedEntryArea && weights.size() != 0) { + throw new IllegalArgumentException("Property " + Property.weights.name() + " should not be set if property " + + Property.fixedEntryArea.name() + " is set."); + } + singleTab = properties.containsKey(Property.singleTab.name()) + && "true".equals(properties.get(Property.singleTab.name())); + + String titleStr = (String) properties.get(SuiteLayer.Property.title.name()); + if (titleStr != null) { + if (titleStr.startsWith("%")) { + title = new Localized() { + + @Override + public String name() { + return titleStr; + } + + @Override + public ClassLoader getL10nClassLoader() { + return bundleContext != null + ? bundleContext.getBundle().adapt(BundleWiring.class).getClassLoader() + : getClass().getClassLoader(); + } + }; + } else { + title = new Localized.Untranslated(titleStr); + } + } + } + + public void destroy(BundleContext bundleContext, Map properties) { + + } + public void setEntryArea(CmsUiProvider entryArea) { this.entryArea = entryArea; } - class DefaultEditionArea extends SashForm { + public void setWorkArea(CmsUiProvider workArea) { + this.workArea = workArea; + } + + public void setDefaultView(CmsUiProvider defaultView) { + this.defaultView = defaultView; + } + + TabbedArea createTabbedArea(Composite parent, CmsTheme theme) { + TabbedArea tabbedArea = new TabbedArea(parent, SWT.NONE); + tabbedArea.setSingleTab(singleTab); + tabbedArea.setBodyStyle(SuiteStyle.mainTabBody.style()); + tabbedArea.setTabStyle(SuiteStyle.mainTab.style()); + tabbedArea.setTabSelectedStyle(SuiteStyle.mainTabSelected.style()); + tabbedArea.setCloseIcon(SuiteIcon.close.getSmallIcon(theme)); + tabbedArea.setLayoutData(CmsSwtUtils.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; + private Composite entryC; - 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()); + CmsTheme theme = CmsSwtUtils.getCmsTheme(parent); + Composite editorC; if (SWT.RIGHT_TO_LEFT == (style & SWT.RIGHT_TO_LEFT)) {// arabic, hebrew, etc. - editorArea = new Composite(this, SWT.BORDER); - entryArea = new Composite(this, SWT.BORDER); + editorC = new Composite(this, SWT.BORDER); + entryC = new Composite(this, SWT.BORDER); } else { - entryArea = new Composite(this, SWT.NONE); - editorArea = new Composite(this, SWT.NONE); + entryC = new Composite(this, SWT.NONE); + editorC = new Composite(this, SWT.NONE); } - int[] weights = new int[] { 2000, 8000 }; - 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()); + + // sash form specific + if (weights.size() != 0) { + int[] actualWeight = new int[weights.size()]; + for (int i = 0; i < weights.size(); i++) { + actualWeight[i] = Integer.parseInt(weights.get(i)); + } + setWeights(actualWeight); + } else { + int[] actualWeights = new int[] { 3000, 7000 }; + setWeights(actualWeights); + } + if (startMaximized) + setMaximizedControl(editorC); + + GridLayout editorAreaLayout = CmsSwtUtils.noSpaceGridLayout(); +// editorAreaLayout.verticalSpacing = 0; +// editorAreaLayout.marginBottom = 0; +// editorAreaLayout.marginHeight = 0; +// editorAreaLayout.marginLeft = 0; +// editorAreaLayout.marginRight = 0; + editorC.setLayout(editorAreaLayout); + + tabbedArea = createTabbedArea(editorC, theme); + } + + TabbedArea getTabbedArea() { + return tabbedArea; + } + + Composite getEntryArea() { + return entryC; } -// Composite getArea() { -// return area; -// } -// - public Composite getEntryArea() { - return entryArea; + } + + class FixedEditionArea extends Composite { + private static final long serialVersionUID = -5525672639277322465L; + private TabbedArea tabbedArea; + private Composite entryC; + + public FixedEditionArea(Composite parent, int style) { + super(parent, style); + CmsTheme theme = CmsSwtUtils.getCmsTheme(parent); + + setLayout(CmsSwtUtils.noSpaceGridLayout(2)); + + Composite editorC; + if (SWT.RIGHT_TO_LEFT == (style & SWT.RIGHT_TO_LEFT)) {// arabic, hebrew, etc. + editorC = new Composite(this, SWT.NONE); + entryC = new Composite(this, SWT.NONE); + } else { + entryC = new Composite(this, SWT.NONE); + editorC = new Composite(this, SWT.NONE); + } + entryC.setLayoutData(CmsSwtUtils.fillHeight()); + + GridLayout editorAreaLayout = CmsSwtUtils.noSpaceGridLayout(); +// editorAreaLayout.verticalSpacing = 0; +// editorAreaLayout.marginBottom = 0; +// editorAreaLayout.marginHeight = 0; +// editorAreaLayout.marginLeft = 0; +// editorAreaLayout.marginRight = 0; + editorC.setLayout(editorAreaLayout); + editorC.setLayoutData(CmsSwtUtils.fillAll()); + + tabbedArea = createTabbedArea(editorC, theme); } - public TabbedArea getTabbedArea() { + TabbedArea getTabbedArea() { return tabbedArea; } + + Composite getEntryArea() { + return entryC; + } } + } \ No newline at end of file