001: package org.conform.wings.devel;
002:
003: import org.wings.*;
004: import org.wings.border.SLineBorder;
005: import org.conform.wings.Table;
006: import org.conform.*;
007: import org.conform.modifier.InlineModifier;
008:
009: import javax.swing.event.ListSelectionListener;
010: import javax.swing.event.ListSelectionEvent;
011: import javax.swing.*;
012: import java.util.*;
013:
014: /**
015: * @author hengels
016: * @version $Revision: 787 $
017: */
018: public class MetaViewer extends SPanel {
019: private static final String[] RELATION_TYPES = new String[] {
020: "NONE", "ONE_TO_ONE", "ONE_TO_MANY", "MANY_TO_MANY",
021: "MANY_TO_ONE", "DERIVATE", "VALUE", };
022:
023: private static BeanMeta beanMetaMeta;
024: private static BeanMeta propertyMetaMeta;
025:
026: BeanMeta beanMeta;
027:
028: Table beanTable = new Table();
029: Table propertiesTable = new Table();
030:
031: SLabel label = new SLabel();
032: SLabel microHelp = new SLabel();
033: SLabel initializer = new SLabel();
034: SLabel validators = new SLabel();
035: SLabel attributes = new SLabel();
036: SLabel relationType = new SLabel();
037: SLabel relationBean = new SLabel();
038: SLabel relationProperty = new SLabel();
039:
040: public MetaViewer(BeanMeta beanMeta) {
041: super (new SBorderLayout(8, 8));
042:
043: DefaultTableData beanTableData = new DefaultTableData(
044: getBeanMetaMeta());
045: beanTableData.setRows(Collections.singletonList(beanMeta));
046: beanTable.setTableData(beanTableData);
047: beanTable.setEditable(false);
048: beanTable.setBorder(new SLineBorder(1));
049:
050: final DefaultTableData propertiesTableData = new DefaultTableData(
051: getPropertyMetaMeta());
052: propertiesTableData.setRows(Arrays.asList(beanMeta
053: .getProperties()));
054: propertiesTable.setTableData(propertiesTableData);
055: propertiesTable.setEditable(false);
056: propertiesTable.setBorder(new SLineBorder(1));
057:
058: SPanel details = new SPanel(new SGridLayout(2));
059: details.add(new SLabel("label: "));
060: details.add(label);
061: details.add(new SLabel("microHelp: "));
062: details.add(microHelp);
063: details.add(new SLabel("initializer: "));
064: details.add(initializer);
065: details.add(new SLabel("validators: "));
066: details.add(validators);
067: details.add(new SLabel("attributes: "));
068: details.add(attributes);
069: details.add(new SLabel("relationType: "));
070: details.add(relationType);
071: details.add(new SLabel("relationBean: "));
072: details.add(relationBean);
073: details.add(new SLabel("relationProperty: "));
074: details.add(relationProperty);
075:
076: propertiesTable
077: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
078: propertiesTable
079: .addSelectionListener(new ListSelectionListener() {
080: public void valueChanged(ListSelectionEvent e) {
081: int index = propertiesTable.getSelectedRow();
082: if (index == -1)
083: return;
084:
085: PropertyMeta propertyMeta = (PropertyMeta) propertiesTableData
086: .getRows().get(index);
087:
088: label.setText(propertyMeta.getLabel());
089: microHelp.setText(propertyMeta.getMicroHelp());
090: initializer.setText(""
091: + propertyMeta.getInitializer());
092: validators.setText(""
093: + propertyMeta.getValidators());
094: attributes.setText(""
095: + propertyMeta.getAttributes());
096: relationType
097: .setText(RELATION_TYPES[propertyMeta
098: .getRelationType()]);
099: relationBean.setText(""
100: + propertyMeta.getRelationBean());
101: attributes.setText(""
102: + propertyMeta.getRelationProperty());
103: }
104: });
105:
106: add(beanTable, SBorderLayout.NORTH);
107: add(propertiesTable, SBorderLayout.CENTER);
108: add(details, SBorderLayout.SOUTH);
109: }
110:
111: private static BeanMeta getBeanMetaMeta() {
112: if (beanMetaMeta == null)
113: initMetaMeta();
114: return beanMetaMeta;
115: }
116:
117: private static BeanMeta getPropertyMetaMeta() {
118: if (beanMetaMeta == null)
119: initMetaMeta();
120: return propertyMetaMeta;
121: }
122:
123: static void initMetaMeta() {
124: beanMetaMeta = new BeanMeta(BeanMeta.class);
125: new InlineModifier() {
126: protected void configure() {
127: property("type").setPriority(1);
128: property("domainProvider").setPriority(2);
129: property("format").setPriority(3);
130:
131: property("name").setReadable(false);
132: property("properties").setReadable(false);
133: property("attributes").setReadable(false);
134: property("label").setReadable(false);
135: property("microHelp").setReadable(false);
136: property("validators").setReadable(false);
137: }
138: }.modify(beanMetaMeta);
139: new NoLocalizationModifier().modify(beanMetaMeta);
140: Arrays.sort(beanMetaMeta.getProperties(),
141: DefaultPropertySorter.INSTANCE);
142:
143: propertyMetaMeta = new BeanMeta(PropertyMeta.class);
144: new InlineModifier() {
145: protected void configure() {
146: property("name").setPriority(1);
147: property("type").setPriority(2);
148: property("readable").setPriority(3);
149: property("writable").setPriority(4);
150: property("applicable").setPriority(5);
151: property("mandatory").setPriority(6);
152: property("domainProvider").setPriority(7);
153: property("format").setPriority(8);
154:
155: property("beanMeta").setReadable(false);
156: property("attributes").setReadable(false);
157: property("initializer").setReadable(false);
158: property("label").setReadable(false);
159: property("microHelp").setReadable(false);
160: property("priority").setReadable(false);
161: property("relationBean").setReadable(false);
162: property("relationProperty").setReadable(false);
163: property("relationType").setReadable(false);
164: property("validators").setReadable(false);
165: }
166: }.modify(propertyMetaMeta);
167: new NoLocalizationModifier().modify(propertyMetaMeta);
168: Arrays.sort(propertyMetaMeta.getProperties(),
169: DefaultPropertySorter.INSTANCE);
170: }
171:
172: static class NoLocalizationModifier implements Modifier {
173: public void modify(BeanMeta beanMeta) throws ModifierException {
174: for (int i = 0; i < beanMeta.getProperties().length; i++) {
175: PropertyMeta propertyMeta = beanMeta.getProperties()[i];
176: propertyMeta.setLabel(propertyMeta.getName());
177: }
178: }
179: }
180: }
|