KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencrx > kernel > gui > generic > servlet > Evaluator


1 /*
2  * ====================================================================
3  * Project: openmdx, http://www.openmdx.org/
4  * Name: $Id: Evaluator.java,v 1.56 2006/03/24 01:07:23 wfro Exp $
5  * Description: Evaluator
6  * Revision: $Revision: 1.56 $
7  * Owner: CRIXP AG, Switzerland, http://www.crixp.com
8  * Date: $Date: 2006/03/24 01:07:23 $
9  * ====================================================================
10  *
11  * This software is published under the BSD license
12  * as listed below.
13  *
14  * Copyright (c) 2004, CRIXP Corp., Switzerland
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  *
21  * * Redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer.
23  *
24  * * Redistributions in binary form must reproduce the above copyright
25  * notice, this list of conditions and the following disclaimer in
26  * the documentation and/or other materials provided with the
27  * distribution.
28  *
29  * * Neither the name of CRIXP Corp. nor the names of the contributors
30  * to openCRX may be used to endorse or promote products derived
31  * from this software without specific prior written permission
32  *
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
35  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
36  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
37  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
39  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
40  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
41  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
43  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46  * POSSIBILITY OF SUCH DAMAGE.
47  *
48  * ------------------
49  *
50  * This product includes software developed by the Apache Software
51  * Foundation (http://www.apache.org/).
52  *
53  * This product includes software developed by contributors to
54  * openMDX (http://www.openmdx.org/)
55  */

56 package org.opencrx.kernel.gui.generic.servlet;
57
58 import java.io.Serializable JavaDoc;
59 import java.text.DateFormat JavaDoc;
60 import java.text.DecimalFormat JavaDoc;
61 import java.util.ArrayList JavaDoc;
62 import java.util.Collection JavaDoc;
63 import java.util.HashMap JavaDoc;
64 import java.util.Iterator JavaDoc;
65 import java.util.List JavaDoc;
66 import java.util.Locale JavaDoc;
67 import java.util.Map JavaDoc;
68
69 import org.opencrx.kernel.address1.cci.Addressable;
70 import org.opencrx.kernel.address1.cci.RoomAddressable;
71 import org.opencrx.kernel.building1.cci.Building;
72 import org.opencrx.kernel.contract1.cci.ContractPosition;
73 import org.opencrx.kernel.depot1.cci.BundledProductDepotPosition;
74 import org.opencrx.kernel.depot1.cci.Depot;
75 import org.opencrx.kernel.depot1.cci.DepotContract;
76 import org.opencrx.kernel.depot1.cci.DepotEntity;
77 import org.opencrx.kernel.depot1.cci.DepotPosition;
78 import org.opencrx.kernel.depot1.cci.DepotReport;
79 import org.opencrx.kernel.depot1.cci.DepotReportItem;
80 import org.opencrx.kernel.depot1.cci.ProductBundleDepotPosition;
81 import org.opencrx.kernel.depot1.cci.ProductOfferingDepotPosition;
82 import org.opencrx.kernel.product1.cci.BundledProductPosition;
83 import org.opencrx.kernel.product1.cci.Product;
84 import org.opencrx.kernel.product1.cci.ProductBundlePosition;
85 import org.opencrx.kernel.product1.cci.ProductOfferingPosition;
86 import org.opencrx.kernel.product1.cci.SelectableBundledProduct;
87 import org.opencrx.kernel.product1.cci.SelectableItem;
88 import org.opencrx.kernel.product1.cci.SelectableProductBundle;
89 import org.opencrx.kernel.product1.cci.SelectableProductConfiguration;
90 import org.openmdx.application.gui.generic.servlet.ApplicationContext;
91 import org.openmdx.application.gui.generic.servlet.Codes;
92 import org.openmdx.application.gui.generic.servlet.DefaultEvaluator;
93 import org.openmdx.application.gui.generic.servlet.ObjectReference;
94 import org.openmdx.application.log.AppLog;
95 import org.openmdx.base.accessor.jmi.cci.RefObject_1_0;
96 import org.openmdx.base.accessor.jmi.cci.RefPackage_1_0;
97 import org.openmdx.base.exception.ServiceException;
98 import org.openmdx.compatibility.base.dataprovider.cci.Orders;
99 import org.openmdx.compatibility.base.dataprovider.cci.SystemAttributes;
100 import org.openmdx.compatibility.base.naming.Path;
101 import org.openmdx.compatibility.base.query.FilterOperators;
102
103 public class Evaluator
104     extends DefaultEvaluator
105     implements Serializable JavaDoc {
106
107     //-------------------------------------------------------------------------
108
private DateFormat JavaDoc getDateFormat(
109         String JavaDoc language
110     ) {
111         Map JavaDoc dateFormatters = (Map JavaDoc)Evaluator.cachedDateFormat.get();
112         DateFormat JavaDoc dateFormat = (DateFormat JavaDoc)dateFormatters.get(language);
113         if(dateFormat == null) {
114             dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, new Locale JavaDoc(language));
115             dateFormatters.put(
116                 language,
117                 dateFormat
118             );
119         }
120         return dateFormat;
121     }
122     
123     //-------------------------------------------------------------------------
124
private DateFormat JavaDoc getTimeFormat(
125         String JavaDoc language
126     ) {
127         Map JavaDoc timeFormatters = (Map JavaDoc)Evaluator.cachedTimeFormat.get();
128         DateFormat JavaDoc timeFormat = (DateFormat JavaDoc)timeFormatters.get(language);
129         if(timeFormat == null) {
130             timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, new Locale JavaDoc(language));
131             timeFormatters.put(
132                 language,
133                 timeFormat
134             );
135         }
136         return timeFormat;
137     }
138     
139     //-------------------------------------------------------------------------
140
private DecimalFormat JavaDoc getDecimalFormat(
141         String JavaDoc language
142     ) {
143         Map JavaDoc decimalFormatters = (Map JavaDoc)Evaluator.cachedDecimalFormat.get();
144         DecimalFormat JavaDoc decimalFormat = (DecimalFormat JavaDoc)decimalFormatters.get(language);
145         if(decimalFormat == null) {
146             decimalFormat = (DecimalFormat JavaDoc)DecimalFormat.getInstance(new Locale JavaDoc(language));
147             decimalFormatters.put(
148                 language,
149                 decimalFormat
150             );
151         }
152         return decimalFormat;
153     }
154
155     //-------------------------------------------------------------------------
156
public String JavaDoc getTitle(
157         RefObject_1_0 refObj,
158         short locale,
159         String JavaDoc localeAsString,
160         Codes codes
161     ) {
162         if(refObj == null) {
163             return "#NULL";
164         }
165         if(refObj.refIsNew() || !refObj.refIsPersistent()) {
166             return "Untitled";
167         }
168         try {
169     
170           String JavaDoc language = localeAsString.substring(0, 2);
171           DateFormat JavaDoc dateFormat = this.getDateFormat(language);
172           DateFormat JavaDoc timeFormat = this.getTimeFormat(language);
173           DecimalFormat JavaDoc decimalFormat = this.getDecimalFormat(language);
174           
175           if(refObj instanceof org.openmdx.base.cci.Segment) {
176             return "";
177           }
178           else if(refObj instanceof org.opencrx.kernel.account1.cci.Account) {
179               org.opencrx.kernel.account1.cci.Account obj = (org.opencrx.kernel.account1.cci.Account)refObj;
180               return toS(obj.getFullName());
181           }
182           else if(refObj instanceof org.opencrx.kernel.product1.cci.ProductBasePrice) {
183               org.opencrx.kernel.product1.cci.ProductBasePrice obj = (org.opencrx.kernel.product1.cci.ProductBasePrice)refObj;
184               Map JavaDoc currencyTexts = codes.getLongText("org:opencrx:kernel:product1:AbstractProductPrice:priceCurrency", locale, true, true);
185               try {
186                   return toS(obj.getPrice() == null ? "N/A" : decimalFormat.format(obj.getPrice().doubleValue())) + " " + toS(currencyTexts.get(new Short JavaDoc(obj.getPriceCurrency())));
187               }
188               catch(Exception JavaDoc e) {
189                   return toS(obj.getPrice() == null ? "N/A" : decimalFormat.format(obj.getPrice().doubleValue())) + " N/A";
190               }
191           }
192           else if(refObj instanceof org.opencrx.kernel.product1.cci.PriceListEntry) {
193               org.opencrx.kernel.product1.cci.PriceListEntry obj = (org.opencrx.kernel.product1.cci.PriceListEntry)refObj;
194               return toS(obj.getProductName());
195           }
196           else if(refObj instanceof org.opencrx.kernel.activity1.cci.Activity) {
197               org.opencrx.kernel.activity1.cci.Activity obj = (org.opencrx.kernel.activity1.cci.Activity)refObj;
198               return toS(obj.getActivityNumber()) + ": " + toS(obj.getName());
199           }
200           else if(refObj instanceof org.opencrx.kernel.activity1.cci.AddressGroupMember) {
201             return (refObj.refGetValue("address") == null ? "Untitled" : this.getTitle((RefObject_1_0)refObj.refGetValue("address"), locale, localeAsString, codes));
202           }
203           else if(refObj instanceof org.opencrx.kernel.contract1.cci.AccountAddress) {
204              return (refObj.refGetValue("address") == null ? "Untitled" : this.getTitle((RefObject_1_0)refObj.refGetValue("address"), locale, localeAsString, codes));
205           }
206           else if(refObj instanceof org.opencrx.kernel.address1.cci.EMailAddressable) {
207             return toS(refObj.refGetValue("emailAddress"));
208           }
209           else if(refObj instanceof org.opencrx.kernel.contract1.cci.ContractPosition) {
210             return toS(refObj.refGetValue("lineItemNumber"));
211           }
212           else if(refObj instanceof org.opencrx.kernel.product1.cci.Product) {
213               Product obj = (Product)refObj;
214               return obj.getProductNumber() == null || obj.getProductNumber().length() == 0
215                   ? toS(obj.getName())
216                   : toS(obj.getName() + " / " + obj.getProductNumber());
217           }
218           else if(refObj instanceof org.opencrx.kernel.address1.cci.PostalAddressable) {
219               String JavaDoc address = "";
220               int ii = 0;
221               for(Iterator JavaDoc i = ((List JavaDoc)refObj.refGetValue("postalAddressLine")).iterator(); i.hasNext(); ii++) {
222                   if(ii > 0) address += "<br />";
223                   address += toS(i.next());
224               }
225               for(Iterator JavaDoc i = ((List JavaDoc)refObj.refGetValue("postalStreet")).iterator(); i.hasNext(); ii++) {
226                   if(ii > 0) address += "<br />";
227                   address += toS(i.next());
228               }
229               Object JavaDoc postalCountry = refObj.refGetValue("postalCountry");
230               String JavaDoc postalCountryS = codes == null
231                   ? "" + postalCountry
232                   : toS(codes.getLongText("org:opencrx:kernel:address1:PostalAddressable:postalCountry", locale, true, true).get(postalCountry));
233               return address + "<br />" + toS(refObj.refGetValue("postalCode")) + " " + toS(refObj.refGetValue("postalCity")) + "<br />" + postalCountryS;
234           }
235           else if(refObj instanceof org.opencrx.kernel.activity1.cci.MmsSlide) {
236             return toS(refObj.refGetValue("order"));
237           }
238           else if(refObj instanceof org.opencrx.kernel.address1.cci.PhoneNumberAddressable) {
239             return toS(refObj.refGetValue("phoneNumberFull"));
240           }
241           else if(refObj instanceof org.opencrx.kernel.address1.cci.RoomAddressable) {
242               RoomAddressable obj = (RoomAddressable)refObj;
243               if(refObj instanceof Addressable) {
244                   Building building = ((Addressable)refObj).getBuilding();
245                   if(building == null) {
246                       return toS(obj.getRoomNumber());
247                   }
248                   else {
249                       return this.getTitle(building, locale, localeAsString, codes) + " " + toS(obj.getRoomNumber());
250                   }
251               }
252               else {
253                   return toS(obj.getRoomNumber());
254               }
255           }
256           else if(refObj instanceof org.opencrx.kernel.generic.cci.Rating) {
257             return toS(refObj.refGetValue("ratingLevel"));
258           }
259           else if(refObj instanceof org.opencrx.kernel.account1.cci.RevenueReport) {
260             return toS(refObj.refGetValue("reportNumber"));
261           }
262           else if(refObj instanceof org.opencrx.kernel.forecast1.cci.Budget) {
263             return toS(refObj.refGetValue("underlying"));
264           }
265           else if(refObj instanceof org.opencrx.kernel.address1.cci.WebAddressable) {
266             return toS(refObj.refGetValue("webUrl"));
267           }
268           else if(refObj instanceof org.opencrx.kernel.code1.cci.CodeValueEntry) {
269             return toS(refObj.refGetValue("shortText"));
270           }
271           else if(refObj instanceof org.opencrx.kernel.generic.cci.Description) {
272             return toS(refObj.refGetValue("language"));
273           }
274           else if(refObj instanceof org.opencrx.kernel.account1.cci.Member) {
275             return (refObj.refGetValue("account") == null ? "Untitled" : this.getTitle((RefObject_1_0)refObj.refGetValue("account"), locale, localeAsString, codes));
276           }
277           else if(refObj instanceof org.opencrx.kernel.account1.cci.ContactRelationship) {
278             return (refObj.refGetValue("toContact") == null ? "Untitled" : this.getTitle((RefObject_1_0)refObj.refGetValue("toContact"), locale, localeAsString, codes));
279           }
280           else if(refObj instanceof org.opencrx.kernel.home1.cci.UserHome) {
281             return (refObj.refGetValue("contact") == null ? "Untitled" : this.getTitle((RefObject_1_0)refObj.refGetValue("contact"), locale, localeAsString, codes));
282           }
283           else if(refObj instanceof org.opencrx.kernel.home1.cci.AccessHistory) {
284             return (refObj.refGetValue("reference") == null ? "Untitled" : this.getTitle((RefObject_1_0)refObj.refGetValue("reference"), locale, localeAsString, codes));
285           }
286           else if(refObj instanceof org.opencrx.kernel.home1.cci.EMailAccount) {
287             return toS(refObj.refGetValue("eMailAddress"));
288           }
289           else if(refObj instanceof org.opencrx.kernel.home1.cci.WfProcessInstance) {
290             return (refObj.refGetValue("process") == null ? "Untitled" : this.getTitle((RefObject_1_0)refObj.refGetValue("process"), locale, localeAsString, codes) + " " + toS(refObj.refGetValue("startedOn")));
291           }
292           else if(refObj instanceof org.opencrx.kernel.base.cci.AuditEntry) {
293               Object JavaDoc createdAt = refObj.refGetValue(SystemAttributes.CREATED_AT);
294               return (refObj.refGetValue(SystemAttributes.CREATED_AT) == null) ? "Untitled" : dateFormat.format(createdAt) + " " + timeFormat.format(createdAt);
295           }
296           else if(refObj instanceof org.opencrx.kernel.base.cci.Note) {
297               Object JavaDoc createdAt = refObj.refGetValue(SystemAttributes.CREATED_AT);
298               Object JavaDoc modifiedAt = refObj.refGetValue(SystemAttributes.MODIFIED_AT);
299               return "<b>" + toS(refObj.refGetValue("title")) + "</b><br /><span><b>" + toS(refObj.refGetValue(SystemAttributes.CREATED_BY)) + "</b><br />" + dateFormat.format(createdAt) + " " + timeFormat.format(createdAt) + "<br /><b>" + toS(refObj.refGetValue(SystemAttributes.MODIFIED_BY)) + "</b><br />" + dateFormat.format(modifiedAt) + " " + timeFormat.format(modifiedAt) + "</span>";
300           }
301           else if(refObj instanceof org.opencrx.kernel.base.cci.Chart) {
302               return toS(refObj.refGetValue("description"));
303           }
304           else if(refObj instanceof org.opencrx.kernel.base.cci.TemplateReplacement) {
305               return toS(refObj.refGetValue("description"));
306           }
307           else if(refObj instanceof org.opencrx.kernel.model1.cci.Element) {
308               String JavaDoc title = toS(refObj.refGetValue("qualifiedName"));
309               if(title.indexOf(":") > 0) {
310                   int pos = title.lastIndexOf(":");
311                   title = title.substring(pos + 1) + " (" + title.substring(0, pos) + ")";
312               }
313               return title;
314           }
315           else if(refObj instanceof DepotEntity) {
316               DepotEntity obj = (DepotEntity)refObj;
317               return obj.getDepotEntityNumber() == null ? toS(obj.getName()) : toS(obj.getDepotEntityNumber());
318           }
319           else if(refObj instanceof DepotContract) {
320               DepotContract obj = (DepotContract)refObj;
321               return obj.getDepotHolderNumber() == null ? toS(obj.getName()) : toS(obj.getDepotHolderNumber());
322           }
323           else if(refObj instanceof Depot) {
324               Depot obj = (Depot)refObj;
325               return obj.getDepotNumber() == null ? toS(obj.getName()) : toS(obj.getDepotNumber());
326           }
327           else if(refObj instanceof DepotPosition) {
328               DepotPosition obj = (DepotPosition)refObj;
329               String JavaDoc depotTitle = this.getTitle(obj.getDepot(), locale, localeAsString, codes);
330               return depotTitle + " / " + toS(obj.getName());
331           }
332           else if(refObj instanceof DepotReport) {
333               DepotReport obj = (DepotReport)refObj;
334               String JavaDoc depotTitle = this.getTitle(obj.getDepot(), locale, localeAsString, codes);
335               return depotTitle + " / " + toS(obj.getName());
336           }
337           else if(refObj instanceof DepotReportItem) {
338               DepotReportItem obj = (DepotReportItem)refObj;
339               return obj.getPositionName();
340           }
341           else {
342               return super.getTitle(refObj, locale, localeAsString, codes);
343           }
344         }
345         catch(Exception JavaDoc e) {
346             ServiceException e0 = new ServiceException(e);
347             AppLog.warning(e0.getMessage(), e0.getCause(), 1);
348             AppLog.warning("can not evaluate. object", refObj.refMofId());
349             return "#ERR (" + e.getMessage() + ")";
350         }
351     }
352
353     //-------------------------------------------------------------------------
354
public boolean isEnabled(
355         String JavaDoc uiElementName,
356         RefObject_1_0 refObj,
357         ApplicationContext context
358     ) {
359         if(refObj instanceof org.opencrx.kernel.depot1.cci.CompoundBooking) {
360             try {
361                 org.opencrx.kernel.depot1.cci.CompoundBooking cb = (org.opencrx.kernel.depot1.cci.CompoundBooking)refObj;
362                 boolean isPending = cb.getBookingStatus() == 1;
363                 boolean isProcessed = cb.getBookingStatus() == 2;
364                 boolean isReversal = cb.getBookingType() == 30;
365                 if("org:opencrx:kernel:depot1:CompoundBooking:cancelCb".equals(uiElementName)) {
366                     return isProcessed && !isReversal;
367                 }
368                 else if("org:opencrx:kernel:depot1:CompoundBooking:acceptCb".equals(uiElementName)) {
369                     return isPending;
370                 }
371                 else if("org:opencrx:kernel:depot1:CompoundBooking:finalizeCb".equals(uiElementName)) {
372                     return isPending;
373                 }
374             }
375             catch(Exception JavaDoc e) {
376                 ServiceException e0 = new ServiceException(e);
377                 AppLog.warning(e0.getMessage(), e0.getCause(), 1);
378             }
379         }
380         else if(refObj instanceof org.opencrx.kernel.base.cci.TemplateEnabled) {
381             try {
382                 Boolean JavaDoc isTemplateAsBoolean = ((org.opencrx.kernel.base.cci.TemplateEnabled)refObj).isTemplate();
383                 boolean isTemplate = isTemplateAsBoolean == null ? false : isTemplateAsBoolean.booleanValue();
384                 if("org:opencrx:kernel:base:TemplateEnabled:applyReplacements".equals(uiElementName)) {
385                     return !isTemplate;
386                 }
387                 else if("org:opencrx:kernel:base:TemplateEnabled:createObject".equals(uiElementName)) {
388                     return isTemplate;
389                 }
390                 else if("org:opencrx:kernel:base:TemplateEnabled:deleteObject".equals(uiElementName)) {
391                     return !isTemplate;
392                 }
393             }
394             catch(Exception JavaDoc e) {
395                 ServiceException e0 = new ServiceException(e);
396                 AppLog.warning(e0.getMessage(), e0.getCause(), 1);
397             }
398         }
399         return super.isEnabled(
400             uiElementName,
401             refObj,
402             context
403         );
404     }
405     
406     //-------------------------------------------------------------------------
407
public String JavaDoc getTitleAttribute(
408         String JavaDoc qualifiedReferenceName
409     ) {
410         String JavaDoc referenceName = qualifiedReferenceName.substring(qualifiedReferenceName.lastIndexOf(":") + 1);
411         if(
412             "org:opencrx:kernel:contract1:AbstractContract:salesRep".equals(qualifiedReferenceName) ||
413             "org:opencrx:kernel:contract1:AbstractContract:customer".equals(qualifiedReferenceName) ||
414             "org:opencrx:kernel:activity1:Activity:assignedTo".equals(qualifiedReferenceName) ||
415             "org:opencrx:kernel:activity1:FilteredActivity:assignedTo".equals(qualifiedReferenceName) ||
416             "org:opencrx:kernel:activity1:FilteredActivity:activity".equals(qualifiedReferenceName) ||
417             "org:opencrx:kernel:product1:PriceListEntry:product".equals(qualifiedReferenceName) ||
418             "org:opencrx:kernel:home1:UserHome:contact".equals(qualifiedReferenceName)
419         ) {
420             // TODO: p$$... are private ORDER BY attributes managed by the database plugin.
421
// The private columns contain the title of referenced objects (calculated by
422
// configured VIEWs). The p$$.. attributes are not modeled. However, openMDX 1.x
423
// allows non-modeled attributes to be propagated as filter properties.
424
// openMDX 2.x will support filters which may include attributes of referenced
425
// objects.
426
return "p$$" + referenceName + "Title";
427         }
428         else {
429             return super.getTitleAttribute(qualifiedReferenceName);
430         }
431     }
432     
433     //-------------------------------------------------------------------------
434
public int getGridRowNestingLevel(
435         RefObject_1_0 refObj
436     ) {
437         if(
438             (refObj instanceof ProductOfferingPosition ||
439             refObj instanceof SelectableProductBundle) &&
440             !(refObj instanceof ProductOfferingDepotPosition)
441         ) {
442             return 0;
443         }
444         else if(
445             (refObj instanceof ProductBundlePosition ||
446             refObj instanceof SelectableBundledProduct) &&
447             !(refObj instanceof ProductBundleDepotPosition)
448         ) {
449             return 1;
450         }
451         else if(
452             (refObj instanceof BundledProductPosition ||
453             refObj instanceof SelectableProductConfiguration) &&
454             !(refObj instanceof BundledProductDepotPosition)
455         ) {
456             return 2;
457         }
458         else {
459             return super.getGridRowNestingLevel(refObj);
460         }
461     }
462
463     //-------------------------------------------------------------------------
464
public String JavaDoc getGridRowLevelId(
465         RefObject_1_0 refObj
466     ) {
467         if(refObj instanceof ContractPosition) {
468             int lineItemNumber = ((ContractPosition)refObj).getLineItemNumber();
469             return (lineItemNumber / 100000) + "-" + ((lineItemNumber % 100000) / 100) + "-" + (lineItemNumber % 100);
470         }
471         else if(refObj instanceof SelectableItem) {
472             int itemNumber = ((SelectableItem)refObj).getItemNumber();
473             return (itemNumber / 100000) + "-" + ((itemNumber % 100000) / 100) + "-" + (itemNumber % 100);
474         }
475         else {
476             return super.getGridRowLevelId(refObj);
477         }
478     }
479
480     //-------------------------------------------------------------------------
481
public int getGridPageSize(
482         String JavaDoc referencedTypeName
483     ) {
484         if("org:opencrx:kernel:product1:SelectableItem".equals(referencedTypeName)) {
485             return 200;
486         }
487         else if("org:opencrx:kernel:model1:EditableOperation".equals(referencedTypeName)) {
488             return 200;
489         }
490         else if("org:opencrx:kernel:model1:EditableParameter".equals(referencedTypeName)) {
491             return 200;
492         }
493         else if("org:opencrx:kernel:model1:EditableAttribute".equals(referencedTypeName)) {
494             return 200;
495         }
496         else if("org:opencrx:kernel:model1:EditableStructureField".equals(referencedTypeName)) {
497             return 200;
498         }
499         else {
500             return super.getGridPageSize(referencedTypeName);
501         }
502     }
503     
504     //-------------------------------------------------------------------------
505
public List JavaDoc getSelectableValues(
506         ApplicationContext application,
507         RefObject_1_0 context,
508         String JavaDoc qualifiedFeatureName
509     ) {
510         RefPackage_1_0 rootPkg = (RefPackage_1_0)context.refOutermostPackage();
511         Path contextIdentity = new Path(context.refMofId());
512         // org:opencrx:kernel:base:ExecuteWorkflowParams:workflow
513
if("org:opencrx:kernel:base:ExecuteWorkflowParams:workflow".equals(qualifiedFeatureName)) {
514             org.opencrx.kernel.workflow1.cci.Segment workflowSegment =
515                 (org.opencrx.kernel.workflow1.cci.Segment)rootPkg.refObject(
516                     "xri:@openmdx:org.opencrx.kernel.workflow1/provider/" + contextIdentity.get(2) + "/segment/" + contextIdentity.get(4)
517                 );
518             Collection JavaDoc wfProcesses = workflowSegment.getWfProcess();
519             List JavaDoc selectableValues = new ArrayList JavaDoc();
520             for(Iterator JavaDoc i = wfProcesses.iterator(); i.hasNext(); ) {
521                 selectableValues.add(
522                     new ObjectReference((org.opencrx.kernel.workflow1.cci.AbstractTask)i.next(), application)
523                 );
524             }
525             return selectableValues;
526         }
527         // org:opencrx:kernel:activity1:ActivityDoFollowUpParams:transition
528
else if("org:opencrx:kernel:activity1:ActivityDoFollowUpParams:transition".equals(qualifiedFeatureName)) {
529             List JavaDoc selectableValues = null;
530             if(context instanceof org.opencrx.kernel.activity1.cci.Activity) {
531                 org.opencrx.kernel.activity1.cci.Activity activity = (org.opencrx.kernel.activity1.cci.Activity)context;
532                 if((activity.getActivityType() != null) && (activity.getProcessState() != null)) {
533                     selectableValues = new ArrayList JavaDoc();
534                     org.opencrx.kernel.activity1.cci.ActivityProcess activityProcess = activity.getActivityType().getControlledBy();
535                     org.opencrx.kernel.activity1.cci.ActivityProcessState processState = activity.getProcessState();
536                     for(Iterator JavaDoc i = activityProcess.getTransition().iterator(); i.hasNext(); ) {
537                         org.opencrx.kernel.activity1.cci.ActivityProcessTransition transition =
538                             (org.opencrx.kernel.activity1.cci.ActivityProcessTransition)i.next();
539                         if(transition.getPrevState().equals(processState)) {
540                             selectableValues.add(
541                                 new ObjectReference(transition, application)
542                             );
543                         }
544                     }
545                 }
546             }
547             return selectableValues;
548         }
549         // org:opencrx:kernel:activity1:ActivityAssignToParams:resource
550
else if("org:opencrx:kernel:activity1:ActivityAssignToParams:resource".equals(qualifiedFeatureName)) {
551             List JavaDoc selectableValues = null;
552             if(context instanceof org.opencrx.kernel.activity1.cci.Activity) {
553                 org.opencrx.kernel.activity1.cci.Activity activity = (org.opencrx.kernel.activity1.cci.Activity)context;
554                 selectableValues = new ArrayList JavaDoc();
555                 for(Iterator JavaDoc i = activity.getAssignedResource().iterator(); i.hasNext(); ) {
556                     org.opencrx.kernel.activity1.cci.ResourceAssignment resourceAssignment =
557                         (org.opencrx.kernel.activity1.cci.ResourceAssignment)i.next();
558                     org.opencrx.kernel.activity1.cci.Resource resource = resourceAssignment.getResource();
559                     if(resource != null) {
560                         selectableValues.add(
561                             new ObjectReference(resource, application)
562                         );
563                     }
564                 }
565             }
566             return selectableValues;
567         }
568         // org:opencrx:kernel:activity1:ResourceAddWorkRecordByPeriodParams:activity
569
// org:opencrx:kernel:activity1:ResourceAddWorkRecordByDurationParams:activity
570
else if(
571             "org:opencrx:kernel:activity1:ResourceAddWorkRecordByPeriodParams:activity".equals(qualifiedFeatureName) ||
572             "org:opencrx:kernel:activity1:ResourceAddWorkRecordByDurationParams:activity".equals(qualifiedFeatureName)
573         ) {
574             List JavaDoc selectableValues = null;
575             if(context instanceof org.opencrx.kernel.activity1.cci.Resource) {
576                 org.opencrx.kernel.activity1.cci.Resource resource =
577                     (org.opencrx.kernel.activity1.cci.Resource)context;
578                 org.opencrx.kernel.activity1.cci.activity1Package activityPkg =
579                     (org.opencrx.kernel.activity1.cci.activity1Package)rootPkg.refPackage(
580                         org.opencrx.kernel.activity1.cci.activity1Package.class.getName()
581                     );
582                 org.opencrx.kernel.activity1.cci.ActivityFilter filter = activityPkg.createActivityFilter();
583                 filter.thereExistsPercentComplete(
584                     FilterOperators.IS_LESS,
585                     new short[]{100}
586                 );
587                 filter.orderByActivityNumber(
588                     Orders.DESCENDING
589                 );
590                 selectableValues = new ArrayList JavaDoc();
591                 int count = 0;
592                 for(
593                     Iterator JavaDoc i = resource.getAssignedActivity(filter).iterator();
594                     i.hasNext() && count < 20;
595                     count++
596                 ) {
597                     selectableValues.add(
598                         new ObjectReference((org.opencrx.kernel.activity1.cci.Activity)i.next(), application)
599                     );
600                 }
601                 // Show at most 20 values in drop down. Otherwise show lookup
602
if(count >= 20) {
603                     selectableValues = null;
604                 }
605             }
606             return selectableValues;
607         }
608         else {
609             return super.getSelectableValues(
610                 application,
611                 context,
612                 qualifiedFeatureName
613             );
614         }
615     }
616         
617     //-------------------------------------------------------------------------
618
private static final long serialVersionUID = 3761691203816992816L;
619
620     private static ThreadLocal JavaDoc cachedDateFormat = new ThreadLocal JavaDoc() {
621         protected synchronized Object JavaDoc initialValue() {
622             return new HashMap JavaDoc();
623         }
624     };
625     private static ThreadLocal JavaDoc cachedTimeFormat = new ThreadLocal JavaDoc() {
626         protected synchronized Object JavaDoc initialValue() {
627             return new HashMap JavaDoc();
628         }
629     };
630     private static ThreadLocal JavaDoc cachedDecimalFormat = new ThreadLocal JavaDoc() {
631         protected synchronized Object JavaDoc initialValue() {
632             return new HashMap JavaDoc();
633         }
634     };
635     
636 }
637
638 //--- End of File -----------------------------------------------------------
639
Popular Tags