]> git.argeo.org Git - lgpl/argeo-commons.git/blob - AcrContentTreeView.java
cfae59b49e1a06c525b3962b58acd7569ba77524
[lgpl/argeo-commons.git] / AcrContentTreeView.java
1 package org.argeo.cms.swt.app;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.xml.namespace.QName;
7
8 import org.argeo.api.acr.Content;
9 import org.argeo.cms.swt.CmsSwtUtils;
10 import org.argeo.cms.swt.acr.SwtContentHierarchicalPart;
11 import org.argeo.cms.swt.widgets.SwtTabularPart;
12 import org.argeo.cms.ux.widgets.Column;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.custom.SashForm;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.widgets.Composite;
17
18 public class AcrContentTreeView extends Composite {
19 private static final long serialVersionUID = -3707881216246077323L;
20
21 private Content rootContent;
22
23 private Content selected;
24
25 public AcrContentTreeView(Composite parent, int style, Content content) {
26 super(parent, style);
27 this.rootContent = content;
28 this.selected = rootContent;
29 setLayout(CmsSwtUtils.noSpaceGridLayout());
30
31 SashForm split = new SashForm(this, SWT.HORIZONTAL);
32 split.setLayoutData(CmsSwtUtils.fillAll());
33
34 SwtContentHierarchicalPart hPart = new SwtContentHierarchicalPart(split, getStyle());
35 Composite area = new Composite(split, SWT.NONE);
36 area.setLayout(CmsSwtUtils.noSpaceGridLayout(2));
37 split.setWeights(new int[] { 30, 70 });
38
39 // attributes
40 SwtTabularPart attributesPart = new SwtTabularPart(area, SWT.NONE) {
41 List<QName> data;
42
43 @Override
44 protected Object getData(int row) {
45 return data.get(row);
46 }
47
48 @Override
49 protected int getItemCount() {
50 data = new ArrayList<>(selected.keySet());
51 return data.size();
52 }
53 };
54 attributesPart.getArea().setLayoutData(CmsSwtUtils.fillHeight());
55
56 attributesPart.addColumn(new Column<QName>() {
57
58 @Override
59 public String getText(QName model) {
60 return model.toString();
61 }
62 });
63 attributesPart.addColumn(new Column<QName>() {
64
65 @Override
66 public String getText(QName model) {
67 return selected.get(model).toString();
68 }
69
70 @Override
71 public int getWidth() {
72 return 400;
73 }
74
75 });
76
77 // types
78 SwtTabularPart typesPart = new SwtTabularPart(area, SWT.NONE) {
79 List<QName> data;
80
81 @Override
82 protected Object getData(int row) {
83 return data.get(row);
84 }
85
86 @Override
87 protected int getItemCount() {
88 data = new ArrayList<>(selected.getTypes());
89 return data.size();
90 }
91 };
92 typesPart.addColumn(new Column<QName>() {
93
94 @Override
95 public String getText(QName model) {
96 return model.toString();
97 }
98 });
99 typesPart.getArea().setLayoutData(CmsSwtUtils.fillHeight());
100
101 // controller
102 hPart.setInput(rootContent);
103 hPart.onSelected((o) -> {
104 Content c = (Content) o;
105 selected = c;
106 attributesPart.refresh();
107 typesPart.refresh();
108 });
109
110 attributesPart.refresh();
111 typesPart.refresh();
112 }
113
114 // protected void refreshTable() {
115 // for (TableItem item : table.getItems()) {
116 // item.dispose();
117 // }
118 // for (QName key : selected.keySet()) {
119 // TableItem item = new TableItem(table, 0);
120 // item.setText(0, key.toString());
121 // Object value = selected.get(key);
122 // item.setText(1, value.toString());
123 // }
124 // table.getColumn(0).pack();
125 // table.getColumn(1).pack();
126 // }
127
128 // public static void main(String[] args) {
129 // Path basePath;
130 // if (args.length > 0) {
131 // basePath = Paths.get(args[0]);
132 // } else {
133 // basePath = Paths.get(System.getProperty("user.home"));
134 // }
135 //
136 // final Display display = new Display();
137 // final Shell shell = new Shell(display);
138 // shell.setText(basePath.toString());
139 // shell.setLayout(new FillLayout());
140 //
141 // FsContentProvider contentSession = new FsContentProvider("/", basePath);
142 //// GcrContentTreeView treeView = new GcrContentTreeView(shell, 0, contentSession.get("/"));
143 //
144 // shell.setSize(shell.computeSize(800, 600));
145 // shell.open();
146 // while (!shell.isDisposed()) {
147 // if (!display.readAndDispatch())
148 // display.sleep();
149 // }
150 // display.dispose();
151 // }
152 }