import java.util.List;
import java.util.Map;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-
+import org.argeo.api.acr.Content;
import org.argeo.api.cms.CmsTheme;
-import org.argeo.app.ui.widgets.TabbedArea;
import org.argeo.cms.Localized;
import org.argeo.cms.swt.CmsSwtUtils;
+import org.argeo.cms.swt.acr.SwtUiProvider;
+import org.argeo.cms.swt.widgets.SwtTabbedArea;
import org.argeo.cms.ui.CmsUiProvider;
-import org.argeo.jcr.JcrException;
import org.argeo.util.LangUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
private Localized title = null;
@Override
- public Control createUi(Composite parent, Node context) throws RepositoryException {
+ public Control createUiPart(Composite parent, Content context) {
// TODO Factorize more, or split into more specialised classes?
if (entryArea != null) {
if (fixedEntryArea) {
FixedEditionArea editionArea = new FixedEditionArea(parent, parent.getStyle());
- Control entryAreaC = entryArea.createUi(editionArea.getEntryArea(), context);
+ Control entryAreaC = entryArea.createUiPart(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);
+ entryArea.createUiPart(editionArea.getEntryArea(), context);
if (this.defaultView != null) {
editionArea.getTabbedArea().view(defaultView, context);
}
} else {
if (this.workArea != null) {
Composite area = new Composite(parent, SWT.NONE);
- this.workArea.createUi(area, context);
+ this.workArea.createUiPart(area, context);
return area;
}
CmsTheme theme = CmsSwtUtils.getCmsTheme(parent);
- TabbedArea tabbedArea = createTabbedArea(parent, theme);
+ SwtTabbedArea tabbedArea = createTabbedArea(parent, theme);
return tabbedArea;
}
}
@Override
- public void view(CmsUiProvider uiProvider, Composite workAreaC, Node context) {
+ public void view(SwtUiProvider uiProvider, Composite workAreaC, Content 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);
- }
+ CmsSwtUtils.clear(workAreaC);
+ workArea.createUiPart(workAreaC, context);
+ workAreaC.layout(true, true);
+ return;
}
// tabbed area
- TabbedArea tabbedArea = findTabbedArea(workAreaC);
+ SwtTabbedArea tabbedArea = findTabbedArea(workAreaC);
if (tabbedArea == null)
throw new IllegalArgumentException("Unsupported work area " + workAreaC.getClass().getName());
if (uiProvider == null) {
}
@Override
- public Node getCurrentContext(Composite workArea) {
- TabbedArea tabbedArea = findTabbedArea(workArea);
+ public Content getCurrentContext(Composite workArea) {
+ SwtTabbedArea tabbedArea = findTabbedArea(workArea);
if (tabbedArea == null)
return null;
return tabbedArea.getCurrentContext();
}
- private TabbedArea findTabbedArea(Composite workArea) {
- TabbedArea tabbedArea = null;
+ private SwtTabbedArea findTabbedArea(Composite workArea) {
+ SwtTabbedArea 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;
+ } else if (workArea instanceof SwtTabbedArea) {
+ tabbedArea = (SwtTabbedArea) workArea;
}
return tabbedArea;
}
@Override
- public void open(CmsUiProvider uiProvider, Composite workArea, Node context) {
- TabbedArea tabbedArea = ((SashFormEditionArea) workArea).getTabbedArea();
+ public void open(SwtUiProvider uiProvider, Composite workArea, Content context) {
+ SwtTabbedArea tabbedArea = ((SashFormEditionArea) workArea).getTabbedArea();
tabbedArea.open(uiProvider, context);
}
this.defaultView = defaultView;
}
- TabbedArea createTabbedArea(Composite parent, CmsTheme theme) {
- TabbedArea tabbedArea = new TabbedArea(parent, SWT.NONE);
+ SwtTabbedArea createTabbedArea(Composite parent, CmsTheme theme) {
+ SwtTabbedArea tabbedArea = new SwtTabbedArea(parent, SWT.NONE);
tabbedArea.setSingleTab(singleTab);
tabbedArea.setBodyStyle(SuiteStyle.mainTabBody.style());
tabbedArea.setTabStyle(SuiteStyle.mainTab.style());
// /** A work area based on an entry area and and a tabbed area. */
class SashFormEditionArea extends SashForm {
private static final long serialVersionUID = 2219125778722702618L;
- private TabbedArea tabbedArea;
+ private SwtTabbedArea tabbedArea;
private Composite entryC;
SashFormEditionArea(Composite parent, int style) {
tabbedArea = createTabbedArea(editorC, theme);
}
- TabbedArea getTabbedArea() {
+ SwtTabbedArea getTabbedArea() {
return tabbedArea;
}
class FixedEditionArea extends Composite {
private static final long serialVersionUID = -5525672639277322465L;
- private TabbedArea tabbedArea;
+ private SwtTabbedArea tabbedArea;
private Composite entryC;
public FixedEditionArea(Composite parent, int style) {
tabbedArea = createTabbedArea(editorC, theme);
}
- TabbedArea getTabbedArea() {
+ SwtTabbedArea getTabbedArea() {
return tabbedArea;
}
import org.argeo.cms.LocaleUtils;
import org.argeo.cms.Localized;
import org.argeo.cms.jcr.CmsJcrUtils;
+import org.argeo.cms.jcr.acr.JcrContent;
import org.argeo.cms.jcr.acr.JcrContentProvider;
import org.argeo.cms.swt.CmsSwtUtils;
import org.argeo.cms.swt.dialogs.CmsFeedback;
@Override
public void refreshUi(CmsUi cmsUi, String state) {
try {
- Node context = null;
+ Content context = null;
SuiteUi ui = (SuiteUi) cmsUi;
String uiName = Objects.toString(ui.getParent().getData(UI_NAME_PROPERTY), null);
}
- private void refreshPart(CmsUiProvider uiProvider, Composite part, Node context) {
+ private void refreshPart(CmsUiProvider uiProvider, Composite part, Content context) {
CmsSwtUtils.clear(part);
uiProvider.createUiPart(part, context);
}
return layersByPid.get(pid).get();
}
- private <T> T findByType(Map<String, RankedObject<T>> byType, Node context) {
- if (context == null)
+ private <T> T findByType(Map<String, RankedObject<T>> byType, Content content) {
+ if (content == null)
throw new IllegalArgumentException("A node should be provided");
+
+ if(content instanceof JcrContent) {
+ Node context = ((JcrContent)content).getJcrNode();
try {
// mixins
Set<String> types = new TreeSet<>();
} catch (RepositoryException e) {
throw new IllegalStateException(e);
}
+
+ }else {
+ throw new UnsupportedOperationException("Content "+content.getClass().getName()+" is not supported.");
+ }
}
private static String listTypes(Node context) {
return;
}
SuiteUi suiteUi = (SuiteUi) cmsUi;
- Node node = stateToNode(suiteUi, state);
+ Content node = stateToNode(suiteUi, state);
if (node == null) {
suiteUi.getCmsView().navigateTo(HOME_STATE);
} else {
}
// TODO move it to an internal package?
- static String nodeToState(Node node) {
- return '/' + Jcr.getWorkspaceName(node) + Jcr.getPath(node);
+ static String nodeToState(Content node) {
+ return node.getPath();
}
- private Node stateToNode(SuiteUi suiteUi, String state) {
+ private Content stateToNode(SuiteUi suiteUi, String state) {
if (suiteUi == null)
return null;
if (state == null || !state.startsWith("/"))
return null;
- String path = state.substring(1);
- String workspace;
- if (path.equals("")) {
- workspace = null;
- path = "/";
- } else {
- int index = path.indexOf('/');
- if (index == 0) {
- log.error("Cannot interpret " + state);
-// cmsView.navigateTo("~");
- return null;
- } else if (index > 0) {
- workspace = path.substring(0, index);
- path = path.substring(index);
- } else {// index<0, assuming root node
- workspace = path;
- path = "/";
- }
- }
+ String path=state;
+// String path = state.substring(1);
+// String workspace;
+// if (path.equals("")) {
+// workspace = null;
+// path = "/";
+// } else {
+// int index = path.indexOf('/');
+// if (index == 0) {
+// log.error("Cannot interpret " + state);
+//// cmsView.navigateTo("~");
+// return null;
+// } else if (index > 0) {
+// workspace = path.substring(0, index);
+// path = path.substring(index);
+// } else {// index<0, assuming root node
+// workspace = path;
+// path = "/";
+// }
+// }
ProvidedSession contentSession = (ProvidedSession) CmsUxUtils.getContentSession(contentRepository,
suiteUi.getCmsView());
- Session session = jcrContentProvider.getJcrSession(contentSession, workspace);
-// Session session = suiteUi.getSession(workspace);
- if (session == null)
- return null;
- Node node = Jcr.getNode(session, path);
- return node;
+ return contentSession.get(path);
+// Session session = jcrContentProvider.getJcrSession(contentSession, workspace);
+//// Session session = suiteUi.getSession(workspace);
+// if (session == null)
+// return null;
+// Node node = Jcr.getNode(session, path);
+// return node;
}
/*
// String currentLayerId = ui.getCurrentLayerId();
// SuiteLayer currentLayer = currentLayerId != null ? layersByPid.get(currentLayerId).get() : null;
if (SuiteUiUtils.isTopic(event, SuiteEvent.refreshPart)) {
- Node node = getNode(ui, event);
+ Content node = getNode(ui, event);
if (node == null)
return;
CmsUiProvider uiProvider = findByType(uiProvidersByType, node);
SuiteLayer layer = findByType(layersByType, node);
ui.switchToLayer(layer, node);
ui.getCmsView().runAs(() -> layer.view(uiProvider, ui.getCurrentWorkArea(), node));
- ui.getCmsView().stateChanged(nodeToState(node), appTitle + Jcr.getTitle(node));
+ ui.getCmsView().stateChanged(nodeToState(node), appTitle + CmsUxUtils.getTitle(node));
} else if (SuiteUiUtils.isTopic(event, SuiteEvent.openNewPart)) {
- Node node = getNode(ui, event);
+ Content node = getNode(ui, event);
if (node == null)
return;
CmsUiProvider uiProvider = findByType(uiProvidersByType, node);
SuiteLayer layer = findByType(layersByType, node);
ui.switchToLayer(layer, node);
ui.getCmsView().runAs(() -> layer.open(uiProvider, ui.getCurrentWorkArea(), node));
- ui.getCmsView().stateChanged(nodeToState(node), appTitle + Jcr.getTitle(node));
+ ui.getCmsView().stateChanged(nodeToState(node), appTitle + CmsUxUtils.getTitle(node));
} else if (SuiteUiUtils.isTopic(event, SuiteEvent.switchLayer)) {
String layerId = get(event, SuiteEvent.LAYER);
if (layerId != null) {
String title = null;
if (layerTitle != null)
title = layerTitle.lead();
- Node nodeFromState = getNode(ui, event);
+ Content nodeFromState = getNode(ui, event);
if (nodeFromState != null && nodeFromState.getPath().equals(ui.getUserDirNode().getPath())) {
// default layer view is forced
String state = defaultLayerPid.equals(layerId) ? "~" : layerId;
ui.getCmsView().stateChanged(state, appTitle + title);
suiteLayer.view(null, workArea, nodeFromState);
} else {
- Node layerCurrentContext = suiteLayer.getCurrentContext(workArea);
+ Content layerCurrentContext = suiteLayer.getCurrentContext(workArea);
if (layerCurrentContext != null) {
// layer was already showing a context so we set the state to it
ui.getCmsView().stateChanged(nodeToState(layerCurrentContext),
- appTitle + Jcr.getTitle(layerCurrentContext));
+ appTitle + CmsUxUtils.getTitle(layerCurrentContext));
} else {
// no context was shown
ui.getCmsView().stateChanged(layerId, appTitle + title);
}
}
} else {
- Node node = getNode(ui, event);
+ Content node = getNode(ui, event);
if (node != null) {
SuiteLayer layer = findByType(layersByType, node);
ui.getCmsView().runAs(() -> ui.switchToLayer(layer, node));
}
- private Node getNode(SuiteUi ui, Event event) {
+ private Content getNode(SuiteUi ui, Event event) {
ProvidedSession contentSession = (ProvidedSession) CmsUxUtils.getContentSession(contentRepository,
ui.getCmsView());
- String nodePath = get(event, SuiteEvent.NODE_PATH);
- if (nodePath != null && nodePath.equals(HOME_STATE))
- return ui.getUserDirNode();
- String workspace = get(event, SuiteEvent.WORKSPACE);
-
- Session session = jcrContentProvider.getJcrSession(contentSession, workspace);
-// Session session = ui.getSession(workspace);
- Node node;
- if (nodePath == null) {
+ String path = get(event,SuiteEvent.CONTENT_PATH);
+
+// String nodePath = get(event, SuiteEvent.NODE_PATH);
+ if (path != null && path.equals(HOME_STATE))
+ return ui.getUserDir();
+// String workspace = get(event, SuiteEvent.WORKSPACE);
+
+// Session session = jcrContentProvider.getJcrSession(contentSession, workspace);
+//// Session session = ui.getSession(workspace);
+ Content node;
+ if (path == null) {
// look for a user
String username = get(event, SuiteEvent.USERNAME);
if (username == null)
throw new IllegalArgumentException("Badly formatted username", e);
}
String userNodePath = SuiteUtils.getUserNodePath(userDn);
- if (Jcr.itemExists(session, userNodePath))
- node = Jcr.getNode(session, userNodePath);
- else {
- Session adminSession = null;
- try {
- adminSession = CmsJcrUtils.openDataAdminSession(getRepository(), workspace);
- SuiteUtils.getOrCreateUserNode(adminSession, userDn);
- } finally {
- Jcr.logout(adminSession);
- }
- node = Jcr.getNode(session, userNodePath);
- }
+ // FIXME deal with home path
+ return null;
+// if (Jcr.itemExists(session, userNodePath))
+// node = Jcr.getNode(session, userNodePath);
+// else {
+// Session adminSession = null;
+// try {
+// adminSession = CmsJcrUtils.openDataAdminSession(getRepository(), workspace);
+// SuiteUtils.getOrCreateUserNode(adminSession, userDn);
+// } finally {
+// Jcr.logout(adminSession);
+// }
+// node = Jcr.getNode(session, userNodePath);
+// }
} else {
- node = Jcr.getNode(session, nodePath);
+ node = contentSession.get(path);
}
return node;
}
List<String> types = LangUtils.toStringList(properties.get(EntityConstants.TYPE));
for (String type : types) {
if (layersByType.containsKey(type)) {
- if (layersByType.get(type).equals(new RankedObject<CmsUiProvider>(layer, properties))) {
+ if (layersByType.get(type).equals(new RankedObject<SuiteLayer>(layer, properties))) {
layersByType.remove(type);
}
}
public final static String CONTENT_PATH = "contentPath";
// JCR
+ @Deprecated
public final static String NODE_PATH = "path";
+ @Deprecated
public final static String WORKSPACE = "workspace";
public String getTopicBase() {
return properties;
}
+ @Deprecated
public static Map<String, Object> eventProperties(Node node) {
Map<String, Object> properties = new HashMap<>();
- properties.put(NODE_PATH, Jcr.getPath(node));
- properties.put(WORKSPACE, Jcr.getWorkspaceName(node));
+ String contentPath = '/'+ Jcr.getWorkspaceName(node)+ Jcr.getPath(node);
+ properties.put(CONTENT_PATH, contentPath);
+// properties.put(NODE_PATH, Jcr.getPath(node));
+// properties.put(WORKSPACE, Jcr.getWorkspaceName(node));
return properties;
}
package org.argeo.app.ui;
-import javax.jcr.Node;
-
+import org.argeo.api.acr.Content;
import org.argeo.cms.Localized;
-import org.argeo.cms.ui.CmsUiProvider;
+import org.argeo.cms.swt.acr.SwtUiProvider;
import org.eclipse.swt.widgets.Composite;
/** An UI layer for the main work area. */
-public interface SuiteLayer extends CmsUiProvider {
+public interface SuiteLayer extends SwtUiProvider {
static enum Property {
title, icon, weights, startMaximized, singleTab, fixedEntryArea;
}
- void view(CmsUiProvider uiProvider, Composite workArea, Node context);
+ void view(SwtUiProvider uiProvider, Composite workArea, Content context);
- Node getCurrentContext(Composite workArea);
+ Content getCurrentContext(Composite workArea);
- default void open(CmsUiProvider uiProvider, Composite workArea, Node context) {
+ default void open(SwtUiProvider uiProvider, Composite workArea, Content context) {
view(uiProvider, workArea, context);
}
import java.util.HashMap;
import java.util.Map;
-import javax.jcr.Node;
-
import org.argeo.api.acr.Content;
import org.argeo.api.cms.CmsLog;
import org.argeo.api.cms.CmsUi;
import org.argeo.api.cms.CmsView;
import org.argeo.cms.Localized;
-import org.argeo.cms.jcr.acr.JcrContent;
import org.argeo.cms.swt.CmsSwtUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormLayout;
return currentLayerId;
}
- private Composite getLayer(String id, Node context) {
+ private Composite getLayer(String id, Content context) {
if (!layers.containsKey(id))
return null;
if (!workAreas.containsKey(id))
return workAreas.get(id);
}
- Composite switchToLayer(String layerId, Node context) {
+ Composite switchToLayer(String layerId, Content context) {
Composite current = null;
if (currentLayerId != null) {
current = getCurrentWorkArea();
}
}
- Composite switchToLayer(SuiteLayer layer, Node context) {
+ Composite switchToLayer(SuiteLayer layer, Content context) {
// TODO make it more robust
for (String layerId : layers.keySet()) {
SuiteLayer l = layers.get(layerId);
}
}
- protected Composite initLayer(String id, SuiteLayer layer, Node context) {
+ protected Composite initLayer(String id, SuiteLayer layer, Content context) {
Composite workArea = cmsView.doAs(() -> (Composite) layer.createUiPart(dynamicArea, context));
CmsSwtUtils.style(workArea, SuiteStyle.workArea);
workArea.setLayoutData(CmsSwtUtils.coverAll());
// });
// }
- Node getUserDirNode() {
+ @Deprecated
+ Content getUserDirNode() {
if (userDir == null)
return null;
- return ((JcrContent) userDir).getJcrNode();
+ return userDir;
+ }
+
+ Content getUserDir() {
+ return userDir;
}
void setUserDir(Content userDir) {
import javax.jcr.Session;
import org.apache.commons.io.IOUtils;
+import org.argeo.api.acr.Content;
import org.argeo.api.cms.CmsEditable;
import org.argeo.api.cms.CmsEvent;
import org.argeo.api.cms.CmsStyle;
import org.argeo.cms.LocaleUtils;
import org.argeo.cms.Localized;
import org.argeo.cms.auth.CurrentUser;
+import org.argeo.cms.jcr.acr.JcrContent;
import org.argeo.cms.swt.CmsIcon;
import org.argeo.cms.swt.CmsSwtUtils;
import org.argeo.cms.swt.dialogs.LightweightDialog;
return img;
}
+ public static String toLink(Content node) {
+ return node != null ? "#" + CmsSwtUtils.cleanPathForUrl(SuiteApp.nodeToState(node)) : null;
+ }
+
public static String toLink(Node node) {
- return node != null ? "#" + CmsUiUtils.cleanPathForUrl(SuiteApp.nodeToState(node)) : null;
+ return node != null ? "#" + CmsSwtUtils.cleanPathForUrl(SuiteApp.nodeToState(JcrContent.nodeToContent(node)))
+ : null;
}
public static Control addLink(Composite parent, String label, Node node, CmsStyle style)
return null;
String path = arguments[0].toString();
Map<String, Object> properties = new HashMap<>();
- properties.put(SuiteEvent.NODE_PATH, path);
- properties.put(SuiteEvent.WORKSPACE, CmsConstants.SYS_WORKSPACE);
+// properties.put(SuiteEvent.NODE_PATH, path);
+// properties.put(SuiteEvent.WORKSPACE, CmsConstants.SYS_WORKSPACE);
+ properties.put(SuiteEvent.CONTENT_PATH, '/' + CmsConstants.SYS_WORKSPACE + path);
cmsView.sendEvent(SuiteEvent.refreshPart.topic(), properties);
return null;
}
+++ /dev/null
-package org.argeo.app.ui.widgets;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.jcr.Node;
-
-import org.argeo.cms.swt.CmsSwtUtils;
-import org.argeo.cms.swt.Selected;
-import org.argeo.cms.ui.CmsUiProvider;
-import org.argeo.cms.ui.viewers.Section;
-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.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-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;
-
- private Composite headers;
- private Composite body;
-
- private List<Section> sections = new ArrayList<>();
-
- private Node previousNode;
- private CmsUiProvider previousUiProvider;
- private CmsUiProvider currentUiProvider;
-
- private String tabStyle;
- private String tabSelectedStyle;
- private String bodyStyle;
- private Image closeIcon;
-
- private StackLayout stackLayout;
-
- private boolean singleTab = false;
-
- public TabbedArea(Composite parent, int style) {
- super(parent, SWT.NONE);
- CmsSwtUtils.style(parent, bodyStyle);
-
- setLayout(CmsSwtUtils.noSpaceGridLayout());
-
- // TODO manage tabs at bottom or sides
- headers = new Composite(this, SWT.NONE);
- headers.setLayoutData(CmsSwtUtils.fillWidth());
- body = new Composite(this, SWT.NONE);
- body.setLayoutData(CmsSwtUtils.fillAll());
- // body.setLayout(new FormLayout());
- stackLayout = new StackLayout();
- body.setLayout(stackLayout);
- emptyState();
- }
-
- protected void refreshTabHeaders() {
- int tabCount = sections.size() > 0 ? sections.size() : 1;
- for (Control tab : headers.getChildren())
- tab.dispose();
-
- headers.setLayout(CmsSwtUtils.noSpaceGridLayout(new GridLayout(tabCount, true)));
-
- if (sections.size() == 0) {
- Composite emptyHeader = new Composite(headers, SWT.NONE);
- emptyHeader.setLayoutData(CmsSwtUtils.fillAll());
- emptyHeader.setLayout(new GridLayout());
- Label lbl = new Label(emptyHeader, SWT.NONE);
- lbl.setText("");
- lbl.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
-
- }
-
- Section currentSection = getCurrentSection();
- for (Section section : sections) {
- boolean selected = section == currentSection;
- Composite sectionHeader = section.createHeader(headers);
- CmsSwtUtils.style(sectionHeader, selected ? tabSelectedStyle : tabStyle);
- int headerColumns = singleTab ? 1 : 2;
- sectionHeader.setLayout(new GridLayout(headerColumns, false));
- sectionHeader.setLayout(CmsSwtUtils.noSpaceGridLayout(headerColumns));
- Button title = new Button(sectionHeader, SWT.FLAT);
- CmsSwtUtils.style(title, selected ? tabSelectedStyle : tabStyle);
- title.setLayoutData(CmsSwtUtils.fillWidth());
- title.addSelectionListener((Selected) (e) -> showTab(tabIndex(section.getNode())));
- Node node = section.getNode();
- 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");
- CmsSwtUtils.style(closeItem, selected ? tabSelectedStyle : tabStyle);
- closeItem.addSelectionListener((Selected) (e) -> closeTab(section));
- }
- }
-
- }
-
- public void view(CmsUiProvider uiProvider, Node context) {
- if (body.isDisposed())
- return;
- int index = tabIndex(context);
- if (index >= 0) {
- showTab(index);
- previousNode = context;
- previousUiProvider = uiProvider;
- return;
- }
- Section section = (Section) body.getChildren()[0];
- previousNode = section.getNode();
- if (previousNode == null) {// empty state
- previousNode = context;
- previousUiProvider = uiProvider;
- } else {
- previousUiProvider = currentUiProvider;
- }
- currentUiProvider = uiProvider;
- section.setNode(context);
- // 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;
- }
- if (sections.size() == 0)
- CmsSwtUtils.clear(body);
- Section currentSection = getCurrentSection();
- int currentIndex = sections.indexOf(currentSection);
- Section previousSection = new Section(body, SWT.NONE, context);
- build(previousSection, previousUiProvider, previousNode);
- // previousSection.setLayoutData(CmsUiUtils.coverAll());
- int newIndex = currentIndex + 1;
- sections.add(currentIndex, previousSection);
-// sections.add(newIndex, previousSection);
- showTab(newIndex);
- refreshTabHeaders();
- layout(true, true);
- }
-
- public void showTab(int index) {
- Section sectionToShow = sections.get(index);
- // sectionToShow.moveAbove(null);
- stackLayout.topControl = sectionToShow;
- refreshTabHeaders();
- layout(true, true);
- }
-
- protected void build(Section section, CmsUiProvider uiProvider, Node context) {
- for (Control child : section.getChildren())
- child.dispose();
- CmsSwtUtils.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);
- if (Jcr.getIdentifier(section.getNode()).equals(Jcr.getIdentifier(node)))
- return i;
- }
- return -1;
- }
-
- public void closeTab(Section section) {
- int currentIndex = sections.indexOf(section);
- int nextIndex = currentIndex == 0 ? 0 : currentIndex - 1;
- sections.remove(section);
- section.dispose();
- if (sections.size() == 0) {
- emptyState();
- refreshTabHeaders();
- layout(true, true);
- return;
- }
- 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);
- refreshTabHeaders();
- }
-
- public Composite getCurrent() {
- return getCurrentSection();
- }
-
- protected Section getCurrentSection() {
- return (Section) stackLayout.topControl;
- }
-
- public Node getCurrentContext() {
- Section section = getCurrentSection();
- if (section != null) {
- return section.getNode();
- } else {
- return null;
- }
- }
-
- public void setTabStyle(String tabStyle) {
- this.tabStyle = tabStyle;
- }
-
- public void setTabSelectedStyle(String tabSelectedStyle) {
- this.tabSelectedStyle = tabSelectedStyle;
- }
-
- public void setBodyStyle(String bodyStyle) {
- this.bodyStyle = bodyStyle;
- }
-
- public void setCloseIcon(Image closeIcon) {
- this.closeIcon = closeIcon;
- }
-
- public void setSingleTab(boolean singleTab) {
- this.singleTab = singleTab;
- }
-
-}