001: package org.osbl.identity.gui;
002:
003: import org.osbl.client.wings.form.*;
004: import org.osbl.client.wings.shell.Client;
005: import org.osbl.client.ClientResourceProvider;
006: import org.osbl.client.ClientServiceProvider;
007: import org.osbl.persistence.*;
008: import org.osbl.persistence.model.Concrete;
009: import org.conform.*;
010: import org.conform.modifier.InlineModifier;
011: import org.conform.hibernate.HibernateEnvironment;
012: import org.osbl.identity.model.Identity;
013: import org.osbl.ServiceProvider;
014: import org.osbl.plugin.*;
015: import org.wings.table.SDefaultTableCellRenderer;
016: import org.wings.SComponent;
017: import org.wings.STable;
018:
019: import java.io.Serializable;
020: import java.util.*;
021:
022: public class IdentityList extends GenericObjectList {
023: private Persistence persistence;
024:
025: protected BeanMeta createBeanMeta() {
026: return new VariationBeanMetaProvider(Client.getInstance()
027: .getBeanMetaProvider()).addModifier(
028: new InlineModifier() {
029: protected void configure() {
030: property("id").setWritable(false);
031: property("key").setWritable(false);
032: property("created").setWritable(false);
033: property("createdBy").setWritable(false);
034: }
035: }).getBeanMeta(Identity.class);
036: }
037:
038: protected ObjectTableModel createModel(BeanMeta beanMeta) {
039: SimpleQueryCommand command = (SimpleQueryCommand) getCommandFactory()
040: .createCommand("list");
041: command.setType(Identity.class);
042: SimpleQueryCommandTableModel tableModel = new SimpleQueryCommandTableModel(
043: command, beanMeta, "key", "qualifications", "created",
044: "createdBy");
045: tableModel.setSortableColumns("key", "qualifications",
046: "created");
047: tableModel.setFilterableColumns("key", "qualifications");
048: tableModel.getColumnModel().getColumn("qualifications")
049: .setCellRenderer(new QualificationsCellRenderer());
050: tableModel.getColumnModel().getColumn("qualifications")
051: .setFilterRenderer(
052: new DomainEditableCellRenderer(
053: new QualificationsDomainProvider(
054: Identity.class)));
055: return tableModel;
056: }
057:
058: public Object getRow(int index) { // was protected
059: LoadCommand command = (LoadCommand) getCommandFactory()
060: .createCommand("load");
061: command.setType(Identity.class);
062: command.setId((Serializable) ((ObjectTableModel) getModel())
063: .getRowId(index));
064: try {
065: HibernateEnvironment.getInstance().beginTransaction();
066: return command.execute();
067: } finally {
068: HibernateEnvironment.getInstance().endTransaction();
069: }
070: }
071:
072: public Persistence getCommandFactory() {
073: if (persistence == null)
074: persistence = (Persistence) ServiceProvider.getInstance()
075: .getService("IdentityPersistence");
076: return persistence;
077: }
078:
079: static class QualificationsCellRenderer extends
080: SDefaultTableCellRenderer {
081: public SComponent getTableCellRendererComponent(STable table,
082: Object value, boolean selected, int row, int col) {
083: ClientResourceProvider resourceProvider = Client
084: .getInstance().getResourceProvider();
085: StringBuilder builder = new StringBuilder();
086: String qualifications = (String) value;
087: for (StringTokenizer tokenizer = new StringTokenizer(
088: qualifications, "|"); tokenizer.hasMoreTokens();) {
089: String qualification = tokenizer.nextToken();
090: if (builder.length() > 0)
091: builder.append(", ");
092: builder.append(resourceProvider
093: .getMessage(Identity.class.getName()
094: + ".qualifications." + qualification));
095: }
096: value = builder.toString();
097:
098: return super .getTableCellRendererComponent(table, value,
099: selected, row, col);
100: }
101: }
102:
103: static class QualificationsDomainProvider extends
104: AbstractDomainProvider {
105: ClientResourceProvider resourceProvider = Client.getInstance()
106: .getResourceProvider();
107: private Class type;
108:
109: public QualificationsDomainProvider(Class type) {
110: this .type = type;
111: }
112:
113: protected List createValues() {
114: final PluginManager pluginManager = (PluginManager) ClientServiceProvider
115: .getInstance().getService("PluginManager");
116: final ExtensionPoint extensionPoint = new ExtensionPoint(
117: type.getName() + ".concrete", Concrete.class);
118: final List<Extension> list = pluginManager
119: .getExtensions(extensionPoint);
120:
121: List<String> qualifications = new ArrayList<String>(list
122: .size());
123: for (Extension extension : list) {
124: final Class<Concrete> concreteClass = (Class<Concrete>) extension
125: .getImplementation();
126: qualifications.add(concreteClass.getSimpleName());
127: }
128: return qualifications;
129: }
130:
131: protected String formatValue(Object value) {
132: return resourceProvider.getMessage(Identity.class.getName()
133: + ".qualifications." + value);
134: }
135: }
136: }
|