X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Fwidgets%2FTabbedArea.java;h=8a021f1de9ca3586cbcc7760298f417701366ad8;hb=11c9710b1d2456c8304a5841d775af008a794431;hp=ba1e2f6f4daaf45279ceca92b30331576d3a1958;hpb=32315b6eea1e2284e4269536b5fb7fee8cc03b8d;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/TabbedArea.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/TabbedArea.java index ba1e2f6f4..8a021f1de 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/TabbedArea.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/widgets/TabbedArea.java @@ -22,6 +22,7 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; +/** Manages {@link Section} in a tab-like structure. */ public class TabbedArea extends Composite { private static final long serialVersionUID = 8659669229482033444L; @@ -36,29 +37,37 @@ public class TabbedArea extends Composite { private String tabStyle; private String tabSelectedStyle; + private String bodyStyle; private Image closeIcon; - private long openingTimer = 500; - public TabbedArea(Composite parent, int style) { super(parent, style); + CmsUiUtils.style(parent, bodyStyle); setLayout(CmsUiUtils.noSpaceGridLayout()); // TODO manage tabs at bottom or sides headers = new Composite(this, SWT.NONE); headers.setLayoutData(CmsUiUtils.fillWidth()); + // CmsUiUtils.style(headers, bodyStyle); body = new Composite(this, SWT.NONE); body.setLayoutData(CmsUiUtils.fillAll()); - body.setLayout(new FormLayout()); emptyState(); } protected void refreshTabHeaders() { + // TODO deal with initialisation better +// CmsUiUtils.style(body, bodyStyle); + +// int tabCount = sections.size() > 0 ?(sections.size()>1?sections.size()+1:1) : 1; int tabCount = sections.size() > 0 ? sections.size() : 1; for (Control tab : headers.getChildren()) tab.dispose(); + +// GridLayout headersGridLayout = new GridLayout(tabCount, true); +// headersGridLayout.marginHeight=0; +// headers.setLayout(headersGridLayout); headers.setLayout(CmsUiUtils.noSpaceGridLayout(new GridLayout(tabCount, true))); if (sections.size() == 0) { @@ -66,7 +75,7 @@ public class TabbedArea extends Composite { emptyHeader.setLayoutData(CmsUiUtils.fillAll()); emptyHeader.setLayout(new GridLayout()); Label lbl = new Label(emptyHeader, SWT.NONE); - lbl.setText("-"); + lbl.setText(""); lbl.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false)); } @@ -78,24 +87,36 @@ public class TabbedArea extends Composite { CmsUiUtils.style(sectionHeader, selected ? tabSelectedStyle : tabStyle); int headerColumns = 2; sectionHeader.setLayout(new GridLayout(headerColumns, false)); + sectionHeader.setLayout(CmsUiUtils.noSpaceGridLayout(headerColumns)); Button title = new Button(sectionHeader, SWT.FLAT); CmsUiUtils.style(title, selected ? tabSelectedStyle : tabStyle); title.setLayoutData(CmsUiUtils.fillWidth()); - title.addSelectionListener((Selected) (e) -> section.moveAbove(null)); + title.addSelectionListener((Selected) (e) -> showTab(tabIndex(section.getNode()))); Node node = section.getNode(); title.setText(Jcr.getTitle(node)); ToolBar toolBar = new ToolBar(sectionHeader, SWT.NONE); - CmsUiUtils.style(toolBar, selected ? tabSelectedStyle : tabStyle); +// CmsUiUtils.style(toolBar, selected ? tabSelectedStyle : tabStyle); 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)); } + +// if(sections.size()>1) +// { +// ToolBar toolBar = new ToolBar(headers, SWT.NONE); +// CmsUiUtils.style(toolBar, tabStyle); +// ToolItem closeAllItem = new ToolItem(toolBar, SWT.FLAT); +// closeAllItem.setText("X"); +// } } public void view(CmsUiProvider uiProvider, Node context) { + if (body.isDisposed()) + return; int index = tabIndex(context); if (index >= 0) { showTab(index); @@ -113,10 +134,8 @@ public class TabbedArea extends Composite { } currentUiProvider = uiProvider; section.setNode(context); - section.setLayoutData(CmsUiUtils.coversAll()); - for (Control child : section.getChildren()) - child.dispose(); - uiProvider.createUiPart(section, context); + section.setLayoutData(CmsUiUtils.coverAll()); + build(section, uiProvider, context); if (sections.size() == 0) sections.add(section); refreshTabHeaders(); @@ -124,12 +143,12 @@ public class TabbedArea extends Composite { } public void open(CmsUiProvider uiProvider, Node context) { - try { - if (openingTimer > 0) - Thread.sleep(openingTimer); - } catch (InterruptedException e) { - // silent - } +// try { +// if (openingTimer > 0) +// Thread.sleep(openingTimer); +// } catch (InterruptedException e) { +// // silent +// } // int index = tabIndex(context); if (previousNode != null && Jcr.getIdentifier(previousNode).equals(Jcr.getIdentifier(context))) { @@ -140,15 +159,16 @@ public class TabbedArea extends Composite { CmsUiUtils.clear(body); Section currentSection = getCurrentSection(); int currentIndex = sections.indexOf(currentSection); - Section nextCurrentSection = new Section(body, SWT.NONE, context); - nextCurrentSection.setLayoutData(CmsUiUtils.coversAll()); - sections.remove(currentSection); - sections.add(currentIndex, nextCurrentSection); - sections.add(currentSection); - nextCurrentSection.moveAbove(null); - if (previousNode != null) { - view(previousUiProvider, previousNode); - } + Section previousSection = new Section(body, SWT.NONE, context); + build(previousSection, previousUiProvider, previousNode); + previousSection.setLayoutData(CmsUiUtils.coverAll()); +// sections.remove(currentSection); + sections.add(currentIndex + 1, previousSection); +// sections.add(currentSection); +// nextCurrentSection.moveAbove(null); +// if (previousNode != null) { +// view(previousUiProvider, previousNode); +// } refreshTabHeaders(); layout(true, true); } @@ -156,9 +176,19 @@ public class TabbedArea extends Composite { public void showTab(int index) { Section sectionToShow = sections.get(index); sectionToShow.moveAbove(null); + refreshTabHeaders(); layout(true, true); } + protected void build(Section section, CmsUiProvider uiProvider, Node context) { + for (Control child : section.getChildren()) + child.dispose(); + CmsUiUtils.style(section, bodyStyle); + section.setNode(context); + uiProvider.createUiPart(section, context); + + } + private int tabIndex(Node node) { for (int i = 0; i < sections.size(); i++) { Section section = sections.get(i); @@ -204,12 +234,11 @@ public class TabbedArea extends Composite { this.tabSelectedStyle = tabSelectedStyle; } - public void setCloseIcon(Image closeIcon) { - this.closeIcon = closeIcon; + public void setBodyStyle(String bodyStyle) { + this.bodyStyle = bodyStyle; } - public void setOpeningTimer(long openingTimer) { - this.openingTimer = openingTimer; + public void setCloseIcon(Image closeIcon) { + this.closeIcon = closeIcon; } - }