]> git.argeo.org Git - lgpl/argeo-commons.git/blob - AcrContentTreeView.java
a3d533e2fb879b3d43bf222fd42736c1a94d0205
[lgpl/argeo-commons.git] / AcrContentTreeView.java
1 package org.argeo.cms.swt.app;
2
3 import static org.argeo.api.acr.NamespaceUtils.toPrefixedName;
4
5 import java.util.ArrayList;
6 import java.util.List;
7
8 import javax.xml.namespace.QName;
9
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;
21
22 /** A simple ACR browser. */
23 public class AcrContentTreeView extends Composite {
24 private static final long serialVersionUID = -3707881216246077323L;
25
26 private Content rootContent;
27
28 // private Content selected;
29
30 public AcrContentTreeView(Composite parent, int style, Content content) {
31 super(parent, style);
32 this.rootContent = content;
33 // this.selected = rootContent;
34 setLayout(CmsSwtUtils.noSpaceGridLayout());
35
36 SashForm split = new SashForm(this, SWT.HORIZONTAL);
37 split.setLayoutData(CmsSwtUtils.fillAll());
38
39 ContentHierarchicalPart contentPart = new ContentHierarchicalPart();
40 contentPart.addColumn((model) -> {
41 try {
42 return NamespaceUtils.toPrefixedName(model.getName());
43 } catch (IllegalStateException e) {
44 return model.getName().toString();
45 }
46 });
47 contentPart.setInput(rootContent);
48
49 new SwtTreeView<>(split, getStyle(), contentPart);
50
51 Composite area = new Composite(split, SWT.BORDER);
52 area.setLayout(CmsSwtUtils.noSpaceGridLayout(2));
53 split.setWeights(new int[] { 30, 70 });
54
55 // attributes
56 DefaultTabularPart<Content, QName> attributesPart = new DefaultTabularPart<>() {
57
58 @Override
59 protected List<QName> asList(Content input) {
60 return new ArrayList<>(input.keySet());
61 }
62 };
63
64 attributesPart.addColumn(new Column<QName>() {
65
66 @Override
67 public String getText(QName model) {
68 try {
69 return NamespaceUtils.toPrefixedName(model);
70 } catch (IllegalStateException e) {
71 return model.toString();
72 }
73 }
74 });
75 attributesPart.addColumn(new Column<QName>() {
76
77 @Override
78 public String getText(QName model) {
79 return attributesPart.getInput().get(model).toString();
80 }
81
82 @Override
83 public int getWidth() {
84 return 400;
85 }
86
87 });
88 // attributesPart.setInput(selected);
89
90 SwtTableView<Content, QName> attributeTable = new SwtTableView<>(area, style, attributesPart);
91 attributeTable.setLayoutData(CmsSwtUtils.fillAll());
92
93 // types
94 DefaultTabularPart<Content, QName> typesPart = new DefaultTabularPart<>() {
95
96 @Override
97 protected List<QName> asList(Content input) {
98 return input.getContentClasses();
99 }
100 };
101 typesPart.addColumn(new Column<QName>() {
102
103 @Override
104 public String getText(QName model) {
105 return toPrefixedName(model);
106 }
107
108 });
109
110 // typesPart.setInput(selected);
111
112 SwtTableView<Content, QName> typesTable = new SwtTableView<>(area, style, typesPart);
113 typesTable.setLayoutData(CmsSwtUtils.fillAll());
114
115 // controller
116 contentPart.setInput(rootContent);
117 contentPart.onSelected((o) -> {
118 Content c = (Content) o;
119 // selected = c;
120 attributesPart.setInput(c);
121 typesPart.setInput(c);
122 });
123
124 attributesPart.refresh();
125 typesPart.refresh();
126 }
127
128 // protected void refreshTable() {
129 // for (TableItem item : table.getItems()) {
130 // item.dispose();
131 // }
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());
137 // }
138 // table.getColumn(0).pack();
139 // table.getColumn(1).pack();
140 // }
141
142 // public static void main(String[] args) {
143 // Path basePath;
144 // if (args.length > 0) {
145 // basePath = Paths.get(args[0]);
146 // } else {
147 // basePath = Paths.get(System.getProperty("user.home"));
148 // }
149 //
150 // final Display display = new Display();
151 // final Shell shell = new Shell(display);
152 // shell.setText(basePath.toString());
153 // shell.setLayout(new FillLayout());
154 //
155 // FsContentProvider contentSession = new FsContentProvider("/", basePath);
156 //// GcrContentTreeView treeView = new GcrContentTreeView(shell, 0, contentSession.get("/"));
157 //
158 // shell.setSize(shell.computeSize(800, 600));
159 // shell.open();
160 // while (!shell.isDisposed()) {
161 // if (!display.readAndDispatch())
162 // display.sleep();
163 // }
164 // display.dispose();
165 // }
166 }