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