01: package org.osbl.domain.gui;
02:
03: import org.conform.BeanMeta;
04: import org.conform.VariationBeanMetaProvider;
05: import org.conform.hibernate.HibernateEnvironment;
06: import org.conform.modifier.InlineModifier;
07: import org.osbl.client.wings.form.*;
08: import org.osbl.client.wings.form.format.LocalizationFormat;
09: import org.osbl.client.wings.shell.Client;
10: import org.osbl.persistence.*;
11: import org.osbl.identity.gui.SimpleQueryCommandTableModel;
12: import org.osbl.ServiceProvider;
13: import org.osbl.domain.model.Domain;
14: import org.osbl.domain.DomainRegistry;
15:
16: import java.io.Serializable;
17:
18: public class DomainList extends GenericObjectList {
19: private Persistence persistence;
20:
21: protected void initializeList() {
22: // make sure, newly registered domains are created
23: DomainRegistry.getDomains();
24: }
25:
26: protected BeanMeta createBeanMeta() {
27: return new VariationBeanMetaProvider(Client.getInstance()
28: .getBeanMetaProvider()).addModifier(
29: new InlineModifier() {
30: protected void configure() {
31: property("id").setWritable(false);
32: property("key").setWritable(false);
33: property("key").setFormat(
34: new LocalizationFormat());
35: property("type").setWritable(false);
36: }
37: }).getBeanMeta(Domain.class);
38: }
39:
40: protected ObjectTableModel createModel(BeanMeta beanMeta) {
41: SimpleQueryCommand command = (SimpleQueryCommand) getCommandFactory()
42: .createCommand("list");
43: command.setType(Domain.class);
44: SimpleQueryCommandTableModel tableModel = new SimpleQueryCommandTableModel(
45: command, beanMeta, "key", "type");
46: tableModel.setSortableColumns("key", "type");
47: tableModel.setFilterableColumns("key", "type");
48: return tableModel;
49: }
50:
51: public Object getRow(int index) { // was protected
52: LoadCommand command = (LoadCommand) getCommandFactory()
53: .createCommand("load");
54: command.setType(Domain.class);
55: command.setId((Serializable) ((ObjectTableModel) getModel())
56: .getRowId(index));
57: try {
58: HibernateEnvironment.getInstance().beginTransaction();
59: return command.execute();
60: } finally {
61: HibernateEnvironment.getInstance().endTransaction();
62: }
63: }
64:
65: public Persistence getCommandFactory() {
66: if (persistence == null)
67: persistence = (Persistence) ServiceProvider.getInstance()
68: .getService("DomainPersistence");
69: return persistence;
70: }
71: }
|