1 package org
.argeo
.cms
.swt
.app
;
3 import static org
.argeo
.api
.acr
.NamespaceUtils
.toPrefixedName
;
5 import java
.util
.ArrayList
;
8 import javax
.xml
.namespace
.QName
;
10 import org
.argeo
.api
.acr
.Content
;
11 import org
.argeo
.api
.acr
.NamespaceUtils
;
12 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
13 import org
.argeo
.cms
.swt
.widgets
.SwtTableView
;
14 import org
.argeo
.cms
.swt
.widgets
.SwtTreeView
;
15 import org
.argeo
.cms
.ux
.acr
.ContentHierarchicalPart
;
16 import org
.argeo
.cms
.ux
.widgets
.Column
;
17 import org
.argeo
.cms
.ux
.widgets
.DefaultTabularPart
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.custom
.SashForm
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
22 /** A simple ACR browser. */
23 public class AcrContentTreeView
extends Composite
{
24 private static final long serialVersionUID
= -3707881216246077323L;
26 private Content rootContent
;
28 // private Content selected;
30 public AcrContentTreeView(Composite parent
, int style
, Content content
) {
32 this.rootContent
= content
;
33 // this.selected = rootContent;
34 setLayout(CmsSwtUtils
.noSpaceGridLayout());
36 SashForm split
= new SashForm(this, SWT
.HORIZONTAL
);
37 split
.setLayoutData(CmsSwtUtils
.fillAll());
39 ContentHierarchicalPart contentPart
= new ContentHierarchicalPart();
40 contentPart
.addColumn((model
) -> {
42 return NamespaceUtils
.toPrefixedName(model
.getName());
43 } catch (IllegalStateException e
) {
44 return model
.getName().toString();
47 contentPart
.setInput(rootContent
);
49 new SwtTreeView
<>(split
, getStyle(), contentPart
);
51 Composite area
= new Composite(split
, SWT
.BORDER
);
52 area
.setLayout(CmsSwtUtils
.noSpaceGridLayout(2));
53 split
.setWeights(new int[] { 30, 70 });
56 DefaultTabularPart
<Content
, QName
> attributesPart
= new DefaultTabularPart
<>() {
59 protected List
<QName
> asList(Content input
) {
60 return new ArrayList
<>(input
.keySet());
64 attributesPart
.addColumn(new Column
<QName
>() {
67 public String
getText(QName model
) {
69 return NamespaceUtils
.toPrefixedName(model
);
70 } catch (IllegalStateException e
) {
71 return model
.toString();
75 attributesPart
.addColumn(new Column
<QName
>() {
78 public String
getText(QName model
) {
79 return attributesPart
.getInput().get(model
).toString();
83 public int getWidth() {
88 // attributesPart.setInput(selected);
90 SwtTableView
<Content
, QName
> attributeTable
= new SwtTableView
<>(area
, style
, attributesPart
);
91 attributeTable
.setLayoutData(CmsSwtUtils
.fillAll());
94 DefaultTabularPart
<Content
, QName
> typesPart
= new DefaultTabularPart
<>() {
97 protected List
<QName
> asList(Content input
) {
98 return input
.getContentClasses();
101 typesPart
.addColumn(new Column
<QName
>() {
104 public String
getText(QName model
) {
105 return toPrefixedName(model
);
110 // typesPart.setInput(selected);
112 SwtTableView
<Content
, QName
> typesTable
= new SwtTableView
<>(area
, style
, typesPart
);
113 typesTable
.setLayoutData(CmsSwtUtils
.fillAll());
116 contentPart
.setInput(rootContent
);
117 contentPart
.onSelected((o
) -> {
118 Content c
= (Content
) o
;
120 attributesPart
.setInput(c
);
121 typesPart
.setInput(c
);
124 attributesPart
.refresh();
128 // protected void refreshTable() {
129 // for (TableItem item : table.getItems()) {
132 // for (QName key : selected.keySet()) {
133 // TableItem item = new TableItem(table, 0);
134 // item.setText(0, key.toString());
135 // Object value = selected.get(key);
136 // item.setText(1, value.toString());
138 // table.getColumn(0).pack();
139 // table.getColumn(1).pack();
142 // public static void main(String[] args) {
144 // if (args.length > 0) {
145 // basePath = Paths.get(args[0]);
147 // basePath = Paths.get(System.getProperty("user.home"));
150 // final Display display = new Display();
151 // final Shell shell = new Shell(display);
152 // shell.setText(basePath.toString());
153 // shell.setLayout(new FillLayout());
155 // FsContentProvider contentSession = new FsContentProvider("/", basePath);
156 //// GcrContentTreeView treeView = new GcrContentTreeView(shell, 0, contentSession.get("/"));
158 // shell.setSize(shell.computeSize(800, 600));
160 // while (!shell.isDisposed()) {
161 // if (!display.readAndDispatch())
164 // display.dispose();