]> git.argeo.org Git - lgpl/argeo-commons.git/blob - eclipse/org.argeo.cms.swt/src/org/argeo/cms/swt/app/AcrContentTreeView.java
cb339929f1042c1e1963edbabe73254b96b13a9a
[lgpl/argeo-commons.git] / eclipse / org.argeo.cms.swt / src / org / argeo / cms / swt / 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 return toPrefixedName(model);
61 }
62 });
63 attributesPart.addColumn(new Column<QName>() {
64
65 @Override
66 public String getText(QName model) {
67 return attributesPart.getInput().get(model).toString();
68 }
69
70 @Override
71 public int getWidth() {
72 return 400;
73 }
74
75 });
76 // attributesPart.setInput(selected);
77
78 SwtTabularPart<Content, QName> attributeTable = new SwtTabularPart<>(area, style, attributesPart);
79 attributeTable.setLayoutData(CmsSwtUtils.fillAll());
80
81 // types
82 DefaultTabularPart<Content, QName> typesPart = new DefaultTabularPart<>() {
83
84 @Override
85 protected List<QName> asList(Content input) {
86 return input.getContentClasses();
87 }
88 };
89 typesPart.addColumn(new Column<QName>() {
90
91 @Override
92 public String getText(QName model) {
93 return toPrefixedName(model);
94 }
95
96 });
97
98 // typesPart.setInput(selected);
99
100 SwtTabularPart<Content, QName> typesTable = new SwtTabularPart<>(area, style, typesPart);
101 typesTable.setLayoutData(CmsSwtUtils.fillAll());
102
103 // controller
104 contentPart.setInput(rootContent);
105 contentPart.onSelected((o) -> {
106 Content c = (Content) o;
107 // selected = c;
108 attributesPart.setInput(c);
109 typesPart.setInput(c);
110 });
111
112 attributesPart.refresh();
113 typesPart.refresh();
114 }
115
116 // protected void refreshTable() {
117 // for (TableItem item : table.getItems()) {
118 // item.dispose();
119 // }
120 // for (QName key : selected.keySet()) {
121 // TableItem item = new TableItem(table, 0);
122 // item.setText(0, key.toString());
123 // Object value = selected.get(key);
124 // item.setText(1, value.toString());
125 // }
126 // table.getColumn(0).pack();
127 // table.getColumn(1).pack();
128 // }
129
130 // public static void main(String[] args) {
131 // Path basePath;
132 // if (args.length > 0) {
133 // basePath = Paths.get(args[0]);
134 // } else {
135 // basePath = Paths.get(System.getProperty("user.home"));
136 // }
137 //
138 // final Display display = new Display();
139 // final Shell shell = new Shell(display);
140 // shell.setText(basePath.toString());
141 // shell.setLayout(new FillLayout());
142 //
143 // FsContentProvider contentSession = new FsContentProvider("/", basePath);
144 //// GcrContentTreeView treeView = new GcrContentTreeView(shell, 0, contentSession.get("/"));
145 //
146 // shell.setSize(shell.computeSize(800, 600));
147 // shell.open();
148 // while (!shell.isDisposed()) {
149 // if (!display.readAndDispatch())
150 // display.sleep();
151 // }
152 // display.dispose();
153 // }
154 }