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
.SwtTreeView
;
14 import org
.argeo
.cms
.swt
.widgets
.SwtTableView
;
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
.setInput(rootContent
);
42 new SwtTreeView
<>(split
, getStyle(), contentPart
);
44 Composite area
= new Composite(split
, SWT
.BORDER
);
45 area
.setLayout(CmsSwtUtils
.noSpaceGridLayout(2));
46 split
.setWeights(new int[] { 30, 70 });
49 DefaultTabularPart
<Content
, QName
> attributesPart
= new DefaultTabularPart
<>() {
52 protected List
<QName
> asList(Content input
) {
53 return new ArrayList
<>(input
.keySet());
57 attributesPart
.addColumn(new Column
<QName
>() {
60 public String
getText(QName model
) {
62 return NamespaceUtils
.toPrefixedName(model
);
63 } catch (IllegalStateException e
) {
64 return model
.toString();
68 attributesPart
.addColumn(new Column
<QName
>() {
71 public String
getText(QName model
) {
72 return attributesPart
.getInput().get(model
).toString();
76 public int getWidth() {
81 // attributesPart.setInput(selected);
83 SwtTableView
<Content
, QName
> attributeTable
= new SwtTableView
<>(area
, style
, attributesPart
);
84 attributeTable
.setLayoutData(CmsSwtUtils
.fillAll());
87 DefaultTabularPart
<Content
, QName
> typesPart
= new DefaultTabularPart
<>() {
90 protected List
<QName
> asList(Content input
) {
91 return input
.getContentClasses();
94 typesPart
.addColumn(new Column
<QName
>() {
97 public String
getText(QName model
) {
98 return toPrefixedName(model
);
103 // typesPart.setInput(selected);
105 SwtTableView
<Content
, QName
> typesTable
= new SwtTableView
<>(area
, style
, typesPart
);
106 typesTable
.setLayoutData(CmsSwtUtils
.fillAll());
109 contentPart
.setInput(rootContent
);
110 contentPart
.onSelected((o
) -> {
111 Content c
= (Content
) o
;
113 attributesPart
.setInput(c
);
114 typesPart
.setInput(c
);
117 attributesPart
.refresh();
121 // protected void refreshTable() {
122 // for (TableItem item : table.getItems()) {
125 // for (QName key : selected.keySet()) {
126 // TableItem item = new TableItem(table, 0);
127 // item.setText(0, key.toString());
128 // Object value = selected.get(key);
129 // item.setText(1, value.toString());
131 // table.getColumn(0).pack();
132 // table.getColumn(1).pack();
135 // public static void main(String[] args) {
137 // if (args.length > 0) {
138 // basePath = Paths.get(args[0]);
140 // basePath = Paths.get(System.getProperty("user.home"));
143 // final Display display = new Display();
144 // final Shell shell = new Shell(display);
145 // shell.setText(basePath.toString());
146 // shell.setLayout(new FillLayout());
148 // FsContentProvider contentSession = new FsContentProvider("/", basePath);
149 //// GcrContentTreeView treeView = new GcrContentTreeView(shell, 0, contentSession.get("/"));
151 // shell.setSize(shell.computeSize(800, 600));
153 // while (!shell.isDisposed()) {
154 // if (!display.readAndDispatch())
157 // display.dispose();