001: package org.osbl.riskmanagement.gui;
002:
003: import org.conform.*;
004: import org.conform.modifier.InlineModifier;
005: import org.conform.wings.editor.BooleanEditor;
006: import org.osbl.client.wings.concern.ObjectFormViewModes;
007: import org.osbl.client.wings.form.ComponentProvider;
008: import org.osbl.riskmanagement.model.RiskType;
009: import org.osbl.identity.model.Identity;
010: import org.osbl.identity.model.User;
011: import org.osbl.persistence.Persistence;
012: import org.osbl.persistence.LoadCommand;
013: import org.osbl.ServiceProvider;
014: import org.wings.session.SessionManager;
015:
016: public class QualifyRiskForm extends RiskForm {
017: public QualifyRiskForm() {
018: addViewModeVariation(ObjectFormViewModes.ACTIVITY_VIEW,
019: new InlineModifier() {
020: protected void configure() {
021: property("type").setWritable(false);
022: property("coverage").setWritable(false);
023: property("amount").setWritable(false);
024: property("probability").setWritable(false);
025: property("comment").setWritable(false);
026: property("assignee").setWritable(false);
027: property("criticality").setWritable(false);
028: property("progression").setWritable(false);
029: property("obsolete").setWritable(false);
030:
031: property("assignee").setAttribute(
032: org.conform.wings.Editor.CUSTOM_EDITOR,
033: new BooleanEditor());
034: property("assignee").setAttribute(
035: BooleanEditor.TEXT, "assign to me");
036: property("assignee").setAttribute(
037: DefaultBeanData.PROPERTY_DATA_CLASS,
038: MePropertyData.class.getName());
039:
040: property("type").setWritable(true);
041: property("assignee").setWritable(true);
042: property("coverage").setWritable(true);
043: property("amount").setWritable(true);
044: property("probability").setWritable(true);
045: property("comment").setWritable(true);
046:
047: property("type").setAttribute(
048: PropertyMeta.ATTRIBUTE_CHANGE_LISTENER,
049: new PropertyChangeHandler() {
050: protected void propertyChange(
051: Object oldValue,
052: Object newValue) {
053: RiskType riskType = (RiskType) newValue;
054:
055: BeanMeta beanMeta = bean();
056: PropertyMeta assigneeMeta = property("assignee");
057: PropertyData assigneeData = propertyData("assignee");
058: PropertyMeta typMeta = beanMeta
059: .getProperty("type");
060:
061: if (!typMeta.isWritable())
062: return;
063:
064: if (riskType == null) {
065: assigneeMeta
066: .setWritable(false);
067: return;
068: }
069:
070: Identity responsible = riskType
071: .getResponsible();
072: Persistence persistence = (Persistence) ServiceProvider
073: .getInstance()
074: .getService(
075: "IdentityPersistence");
076: LoadCommand command = (LoadCommand) persistence
077: .createCommand("load");
078: command.setType(User.class);
079: command.setId(responsible
080: .getId());
081: User user = (User) command
082: .execute();
083:
084: boolean itIsMe = user != null
085: && SessionManager
086: .getSession()
087: .getServletRequest()
088: .getUserPrincipal()
089: .getName()
090: .equals(
091: user
092: .getAccount());
093: assigneeMeta
094: .setWritable(itIsMe);
095: if (!itIsMe)
096: assigneeData
097: .setValue(false);
098:
099: updateLabelAndEditor(
100: ComponentProvider.ROOT,
101: "assignee");
102: }
103: });
104: }
105: });
106: setViewMode(ObjectFormViewModes.ACTIVITY_VIEW);
107: }
108: }
|