X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=core%2Forg.argeo.suite.ui%2Fsrc%2Forg%2Fargeo%2Fsuite%2Fui%2Fwidgets%2FTabbedArea.java;h=c281904e989d8d4b8b67b47f4c6ce4cb99b0a468;hp=63de5ffa312780cc3687aed7813d3c9a7331388f;hb=38b1c40accd8da0b5bd791cc2b2257773b69ac56;hpb=287466b8c977b06a215756668b6f3e240b7188cc diff --git a/core/org.argeo.suite.ui/src/org/argeo/suite/ui/widgets/TabbedArea.java b/core/org.argeo.suite.ui/src/org/argeo/suite/ui/widgets/TabbedArea.java index 63de5ff..c281904 100644 --- a/core/org.argeo.suite.ui/src/org/argeo/suite/ui/widgets/TabbedArea.java +++ b/core/org.argeo.suite.ui/src/org/argeo/suite/ui/widgets/TabbedArea.java @@ -11,8 +11,8 @@ import org.argeo.cms.ui.viewers.Section; import org.argeo.eclipse.ui.Selected; import org.argeo.jcr.Jcr; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StackLayout; import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -40,8 +40,12 @@ public class TabbedArea extends Composite { private String bodyStyle; private Image closeIcon; + private StackLayout stackLayout; + + private boolean singleTab = false; + public TabbedArea(Composite parent, int style) { - super(parent, style); + super(parent, SWT.NONE); CmsUiUtils.style(parent, bodyStyle); setLayout(CmsUiUtils.noSpaceGridLayout()); @@ -51,7 +55,9 @@ public class TabbedArea extends Composite { headers.setLayoutData(CmsUiUtils.fillWidth()); body = new Composite(this, SWT.NONE); body.setLayoutData(CmsUiUtils.fillAll()); - body.setLayout(new FormLayout()); + // body.setLayout(new FormLayout()); + stackLayout = new StackLayout(); + body.setLayout(stackLayout); emptyState(); } @@ -77,7 +83,7 @@ public class TabbedArea extends Composite { boolean selected = section == currentSection; Composite sectionHeader = section.createHeader(headers); CmsUiUtils.style(sectionHeader, selected ? tabSelectedStyle : tabStyle); - int headerColumns = 2; + int headerColumns = singleTab ? 1 : 2; sectionHeader.setLayout(new GridLayout(headerColumns, false)); sectionHeader.setLayout(CmsUiUtils.noSpaceGridLayout(headerColumns)); Button title = new Button(sectionHeader, SWT.FLAT); @@ -85,15 +91,19 @@ public class TabbedArea extends Composite { title.setLayoutData(CmsUiUtils.fillWidth()); title.addSelectionListener((Selected) (e) -> showTab(tabIndex(section.getNode()))); Node node = section.getNode(); - title.setText(Jcr.getTitle(node)); - ToolBar toolBar = new ToolBar(sectionHeader, SWT.NONE); - ToolItem closeItem = new ToolItem(toolBar, SWT.FLAT); - if (closeIcon != null) - closeItem.setImage(closeIcon); - else - closeItem.setText("X"); - CmsUiUtils.style(closeItem, selected ? tabSelectedStyle : tabStyle); - closeItem.addSelectionListener((Selected) (e) -> closeTab(section)); + String titleStr = Jcr.getTitle(node); + // TODO internationalize + title.setText(titleStr); + if (!singleTab) { + ToolBar toolBar = new ToolBar(sectionHeader, SWT.NONE); + ToolItem closeItem = new ToolItem(toolBar, SWT.FLAT); + if (closeIcon != null) + closeItem.setImage(closeIcon); + else + closeItem.setText("X"); + CmsUiUtils.style(closeItem, selected ? tabSelectedStyle : tabStyle); + closeItem.addSelectionListener((Selected) (e) -> closeTab(section)); + } } } @@ -118,15 +128,20 @@ public class TabbedArea extends Composite { } currentUiProvider = uiProvider; section.setNode(context); - section.setLayoutData(CmsUiUtils.coverAll()); + // section.setLayoutData(CmsUiUtils.coverAll()); build(section, uiProvider, context); if (sections.size() == 0) sections.add(section); refreshTabHeaders(); + index = tabIndex(context); + showTab(index); layout(true, true); } public void open(CmsUiProvider uiProvider, Node context) { + if (singleTab) + throw new UnsupportedOperationException("Open is not supported in single tab mode."); + if (previousNode != null && Jcr.getIdentifier(previousNode).equals(Jcr.getIdentifier(context))) { // does nothing return; @@ -137,15 +152,18 @@ public class TabbedArea extends Composite { int currentIndex = sections.indexOf(currentSection); Section previousSection = new Section(body, SWT.NONE, context); build(previousSection, previousUiProvider, previousNode); - previousSection.setLayoutData(CmsUiUtils.coverAll()); - sections.add(currentIndex + 1, previousSection); + // previousSection.setLayoutData(CmsUiUtils.coverAll()); + int index = currentIndex + 1; + sections.add(index, previousSection); + showTab(index); refreshTabHeaders(); layout(true, true); } - + public void showTab(int index) { Section sectionToShow = sections.get(index); - sectionToShow.moveAbove(null); + // sectionToShow.moveAbove(null); + stackLayout.topControl = sectionToShow; refreshTabHeaders(); layout(true, true); } @@ -182,6 +200,16 @@ public class TabbedArea extends Composite { refreshTabHeaders(); showTab(nextIndex); } + + public void closeAllTabs() { + for(Section section:sections) { + section.dispose(); + } + sections.clear(); + emptyState(); + refreshTabHeaders(); + layout(true, true); + } protected void emptyState() { new Section(body, SWT.NONE, null); @@ -193,7 +221,16 @@ public class TabbedArea extends Composite { } protected Section getCurrentSection() { - return (Section) body.getChildren()[0]; + return (Section) stackLayout.topControl; + } + + public Node getCurrentContext() { + Section section = getCurrentSection(); + if (section != null) { + return section.getNode(); + } else { + return null; + } } public void setTabStyle(String tabStyle) { @@ -211,4 +248,9 @@ public class TabbedArea extends Composite { public void setCloseIcon(Image closeIcon) { this.closeIcon = closeIcon; } + + public void setSingleTab(boolean singleTab) { + this.singleTab = singleTab; + } + }