001: package org.osbl.orga.gui;
002:
003: import org.osbl.client.wings.form.*;
004: import org.osbl.client.wings.form.layouter.*;
005: import org.osbl.client.wings.shell.Client;
006: import org.osbl.client.wings.shell.Window;
007: import org.osbl.client.wings.action.ShowEditorAction;
008: import org.osbl.client.action.*;
009: import org.osbl.persistence.*;
010: import org.osbl.*;
011: import org.osbl.orga.model.*;
012: import org.osbl.orga.logic.OrgaStructureLogic;
013: import org.osbl.identity.model.Identity;
014: import org.conform.*;
015: import org.conform.modifier.InlineModifier;
016: import org.wings.SComponent;
017: import org.wingx.XScrollPane;
018: import org.hibernate.Hibernate;
019:
020: import java.util.*;
021:
022: public class OrgaSubForm extends GenericObjectSubForm {
023: Persistence persistence = (Persistence) ServiceProvider
024: .getInstance().getService("IdentityPersistence");
025: Persistence orgaPersistence = (Persistence) ServiceProvider
026: .getInstance().getService("OrgaPersistence");
027:
028: private Division orgaDivision;
029: private MembershipList membershipList;
030: private RelationshipList relationshipList;
031:
032: public void setObject(Object object) {
033: super .setObject(object);
034: if (object != null) {
035: membershipList.refresh();
036: relationshipList.refresh();
037: }
038: }
039:
040: public Object getObject(String path) {
041: return null;
042: }
043:
044: public void setObject(String path, Object object) {
045: }
046:
047: public BeanMeta createBeanMeta(String path) {
048: return null;
049: }
050:
051: public void appendLayoutInstructions(Instruction mainInstruction) {
052: PageSet pageSet = (PageSet) mainInstruction;
053: Page identityPage = pageSet.pages.get(0);
054: orgaDivision = new Division(Organisation.class.getName(),
055: new Column(new LabelAndCustomEditor("memberships")),
056: new Column(new LabelAndCustomEditor("relationships")));
057: identityPage.divisions.add(orgaDivision);
058: }
059:
060: public SComponent createCustomComponent(String key) {
061: if ("memberships".equals(key)) {
062: XScrollPane scrollPane = (XScrollPane) (membershipList = new MembershipList())
063: .getComponent();
064: scrollPane.setVerticalExtent(8);
065: return scrollPane;
066: } else if ("relationships".equals(key)) {
067: XScrollPane scrollPane = (XScrollPane) (relationshipList = new RelationshipList())
068: .getComponent();
069: scrollPane.setVerticalExtent(8);
070: return scrollPane;
071: }
072:
073: return null;
074: }
075:
076: protected Identity getIdentity() {
077: return (Identity) getGenericObjectForm().getObject();
078: }
079:
080: public class MembershipList extends GenericObjectList {
081: OrgaStructureLogic logic = (OrgaStructureLogic) ServiceProvider
082: .getInstance().getService("OrgaStructureLogic");
083:
084: protected BeanMeta createBeanMeta() {
085: return new VariationBeanMetaProvider(Client.getInstance()
086: .getBeanMetaProvider()).addModifier(
087: new InlineModifier() {
088: protected void configure() {
089: property("member").setWritable(false);
090: property("group").setWritable(false);
091: property("role").setWritable(false);
092: }
093: }).getBeanMeta(Membership.class);
094: }
095:
096: protected ObjectTableModel createModel(BeanMeta beanMeta) {
097: GenericObjectTableModel tableModel = new GenericObjectTableModel(
098: beanMeta, "role", "group") {
099: public void refresh() {
100: Identity identity = getIdentity();
101: this .rows = identity != null
102: && identity.getId() != null ? logic
103: .memberships(identity.getId())
104: : Collections.EMPTY_LIST;
105: super .refresh();
106: }
107: };
108: return tableModel;
109: }
110:
111: protected void initializeList() {
112: setLinkAction("group", new AbstractObjectAction() {
113: public void actionPerformed(ObjectActionEvent event) {
114: Window parent = org.osbl.client.wings.shell.Window
115: .currentWindow(getEnvironment());
116: ShowEditorAction action = new ShowEditorAction(
117: parent, Group.class, "push");
118: Membership membership = (Membership) event
119: .getTargets()[0];
120: action.navigate(membership.getGroup());
121: }
122: });
123: }
124:
125: public Object getRow(int index) {
126: return ((GenericObjectTableModel) getModel()).getRow(index);
127: }
128: }
129:
130: public class RelationshipList extends GenericObjectList {
131: OrgaStructureLogic logic = (OrgaStructureLogic) ServiceProvider
132: .getInstance().getService("OrgaStructureLogic");
133:
134: protected BeanMeta createBeanMeta() {
135: return new VariationBeanMetaProvider(Client.getInstance()
136: .getBeanMetaProvider()).addModifier(
137: new InlineModifier() {
138: protected void configure() {
139: property("relation").setWritable(false);
140: property("peer").setWritable(false);
141: }
142: }).getBeanMeta(Relationship.class);
143: }
144:
145: protected ObjectTableModel createModel(BeanMeta beanMeta) {
146: GenericObjectTableModel tableModel = new GenericObjectTableModel(
147: beanMeta, "relation", "peer") {
148: public void refresh() {
149: Identity identity = getIdentity();
150: this .rows = identity != null
151: && identity.getId() != null ? logic
152: .relationships(identity.getId())
153: : Collections.EMPTY_LIST;
154: super .refresh();
155: }
156: };
157: return tableModel;
158: }
159:
160: protected void initializeList() {
161: setLinkAction("peer", new AbstractObjectAction() {
162: public void actionPerformed(ObjectActionEvent event) {
163: Window parent = org.osbl.client.wings.shell.Window
164: .currentWindow(getEnvironment());
165: ShowEditorAction action = new ShowEditorAction(
166: parent, Member.class, "push");
167: Relationship relationship = (Relationship) event
168: .getTargets()[0];
169: Member peer = relationship.getPeer();
170: // TODO: resolve
171: RevertCommand command = (RevertCommand) orgaPersistence
172: .createCommand("revert");
173: command.setObject(peer);
174: command.execute();
175: Hibernate.initialize(peer.getOrganisation()
176: .getRelations());
177: action.navigate(peer);
178: }
179: });
180: }
181:
182: public Object getRow(int index) {
183: return ((GenericObjectTableModel) getModel()).getRow(index);
184: }
185: }
186: }
|