1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.svg.edit.client.inspector;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.vectomatic.svg.edit.client.model.AbstractModel;
24 import org.vectomatic.svg.edit.client.model.MetaModel;
25 import org.vectomatic.svg.edit.client.model.ModelCategory;
26
27 import com.extjs.gxt.ui.client.core.El;
28 import com.extjs.gxt.ui.client.widget.Container;
29 import com.extjs.gxt.ui.client.widget.ContentPanel;
30 import com.extjs.gxt.ui.client.widget.layout.AccordionLayout;
31 import com.google.gwt.core.client.GWT;
32
33
34
35
36
37
38
39
40
41 public class Inspector<M extends AbstractModel<?>> extends ContentPanel {
42 private List<IInspectorSection<M>> sections;
43 private IInspectorSection<M> currentSection;
44 private MetaModel<?> metamodel;
45 private M model;
46
47 public Inspector(MetaModel<?> metamodel) {
48 this.metamodel = metamodel;
49 setHeaderVisible(false);
50 setBodyBorder(false);
51 setLayout(new AccordionLayout() {
52
53
54
55
56
57 @Override
58 protected void onLayout(Container<?> container, El target) {
59 if (currentSection != null) {
60 currentSection.unbind();
61 }
62 for (IInspectorSection<M> section : sections) {
63 if (section.getPanel() == activeItem) {
64 section.bind(model);
65 currentSection = section;
66 break;
67 }
68 }
69 super.onLayout(container, target);
70 }
71 });
72
73 sections = new ArrayList<IInspectorSection<M>>();
74 for (ModelCategory<?> category : metamodel.getCategories()) {
75 IInspectorSection<M> section = category.getInspectorSection();
76 if (section != null) {
77 sections.add(section);
78 add(section.getPanel());
79 }
80 }
81 }
82
83 public void bind(M model) {
84 GWT.log("Inspector.bind(" + model + ")");
85 this.model = model;
86 if (currentSection != null) {
87 currentSection.unbind();
88 currentSection.bind(model);
89 }
90 }
91
92 public void unbind() {
93 GWT.log("unbind()");
94 if (currentSection != null) {
95 currentSection.unbind();
96 }
97 this.model = null;
98 }
99 @Override
100 public String toString() {
101 StringBuilder builder = new StringBuilder("SVGInspector(");
102 builder.append(metamodel);
103 builder.append(")");
104 return builder.toString();
105 }
106
107 }