001: package org.osbl.riskmanagement.gui;
002:
003: import org.conform.modifier.InlineModifier;
004: import org.conform.wings.editor.BooleanEditor;
005: import org.conform.*;
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 CreateRiskForm extends RiskForm {
017: public CreateRiskForm() {
018: addViewModeVariation(ObjectFormViewModes.CREATE_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("key").setWritable(true);
041: property("type").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").setMandatory(true);
048:
049: property("type").setAttribute(
050: PropertyMeta.ATTRIBUTE_CHANGE_LISTENER,
051: new PropertyChangeHandler() {
052: protected void propertyChange(
053: Object oldValue,
054: Object newValue) {
055: RiskType riskType = (RiskType) newValue;
056:
057: BeanMeta beanMeta = bean();
058: PropertyMeta assigneeMeta = property("assignee");
059: PropertyData assigneeData = propertyData("assignee");
060: PropertyMeta typMeta = beanMeta
061: .getProperty("type");
062:
063: if (!typMeta.isWritable())
064: return;
065:
066: if (riskType == null) {
067: assigneeMeta
068: .setWritable(false);
069: return;
070: }
071:
072: Identity responsible = riskType
073: .getResponsible();
074: Persistence persistence = (Persistence) ServiceProvider
075: .getInstance()
076: .getService(
077: "IdentityPersistence");
078: LoadCommand command = (LoadCommand) persistence
079: .createCommand("load");
080: command.setType(User.class);
081: command.setId(responsible
082: .getId());
083: User user = (User) command
084: .execute();
085:
086: boolean itIsMe = user != null
087: && SessionManager
088: .getSession()
089: .getServletRequest()
090: .getUserPrincipal()
091: .getName()
092: .equals(
093: user
094: .getAccount());
095: assigneeMeta
096: .setWritable(itIsMe);
097: if (!itIsMe)
098: assigneeData
099: .setValue(false);
100:
101: updateLabelAndEditor(
102: ComponentProvider.ROOT,
103: "assignee");
104: }
105: });
106: }
107: });
108: setViewMode(ObjectFormViewModes.CREATE_VIEW);
109: }
110: }
|