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