All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.viaoa.html.OAList Maven / Gradle / Ivy

The newest version!
/* 
This software and documentation is the confidential and proprietary 
information of ViaOA, Inc. ("Confidential Information").  
You shall not disclose such Confidential Information and shall use 
it only in accordance with the terms of the license agreement you 
entered into with ViaOA, Inc..

ViaOA, Inc. MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. ViaOA, Inc. SHALL NOT BE LIABLE FOR ANY DAMAGES
SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
THIS SOFTWARE OR ITS DERIVATIVES.
 
Copyright (c) 2001 ViaOA, Inc.
All rights reserved.
*/ 
package com.viaoa.html;


import java.lang.reflect.*;
import java.util.Vector;
import com.viaoa.hub.*;
import com.viaoa.object.OAObject;
import com.viaoa.util.*;


/** creates a multiList using two hubs: one with all the options, and another with selected options.

    [Java Code]
    Hub hub = employee.getDepartments();
    Hub masterHub = oasession.getHub("dept");
    OAList lst = new OAList(hub, masterHub, "name");
    lst.setNullDescription(null); // Default: "None"
    lst.setAllDescription(null);  // Detault: "All"
    form.add("lstDept",lst);

    ....
    [HTML Code]
    <select name="lstDept" multiple size="4"> <%=form.getOptions("lstDept")%> </select>

*/ public class OAList extends OAHtmlComponent { private static final long serialVersionUID = 1L; protected Hub hubMaster; protected String propertyPath; protected String recursiveProperty; protected Method[] methodGet; protected Method recursiveMethod; protected Object[] objects = null; // values selected on form protected String nullDescription = "None"; protected String allDescription = "All"; protected Object currentObject; // the object that this is working with protected int columns, rows=-1; public OAList(Hub hub, Hub masterHub, String propertyPath) { this(hub,masterHub,propertyPath,0); } public OAList(Hub hub, Hub masterHub, String propertyPath, int columns) { this(hub, masterHub, propertyPath, -1, columns); } public OAList(Hub hub, Hub masterHub, String propertyPath, int rows, int columns) { setHub(hub); setMasterHub(masterHub); setPropertyPath(propertyPath); setRows(rows); setColumns(columns); } public OAList(Hub masterHub, String propertyPath) { this(null, masterHub, propertyPath,0); } public void setPropertyPath(String propertyPath) { this.propertyPath = propertyPath; methodGet = null; } public Hub getMasterHub() { return hubMaster; } public void setMasterHub(Hub h) { this.hubMaster = h; } public void setColumns(int cols) { this.columns = cols; } public int getColumns() { return columns; } public int getRows() { return rows; } /** number of rows. */ public void setRows(int x) { rows = x; } /** if this is a recursive hub: has parent and children of same class. @param prop property name of method to get Hub of children. ex: categories */ public void setRecursivePropertyName(String prop) { recursiveProperty = prop; } public String getRecursivePropertyName() { return recursiveProperty; } /** the "word(s)" to use for the empty slot (null value). Set to null if not needed. Default: "None" set to null if none should be used */ public String getNullDescription() { return nullDescription; } public void setNullDescription(String s) { nullDescription = s; } /** the "word(s)" to use for the Select ALL slot. Default: "All". Set to null if not needed. */ public String getAllDescription() { return allDescription; } public void setAllDescription(String s) { allDescription = s; } /** selected objects */ public Object[] getValues() { initialize(); return objects; } protected void initialize() { if (hub != null && (objects == null || HubDetailDelegate.getMasterObject(hub) != currentObject)) { // hub has changed currentObject = HubDetailDelegate.getMasterObject(hub); hub.loadAllData(); int x = hub.getSize(); objects = new Object[x]; for (int i=0; i <%=form.getOptions("lstDept")%> NOTE: jsp tag must be last in select tag */ public String getOptions() { StringBuffer sb = new StringBuffer(512); try { getValues(); // load objects if (hubMaster == null) return "OAList hubMaster not set"; if (methodGet == null) { methodGet = ClassModifier.getMethods(hubMaster.getObjectClass(), propertyPath); if (methodGet == null) return "OAList methods for propertyPath \""+propertyPath+"\" not found"; } if (recursiveProperty != null && recursiveMethod == null) { recursiveMethod = ClassModifier.getMethod(hubMaster.getObjectClass(), "get"+recursiveProperty ); if (recursiveMethod == null) { throw new RuntimeException("method for property \""+recursiveProperty + "\" class="+actualHub.getObjectClass()); } } hubMaster.loadAllData(); int x = hubMaster.getSize(); if (allDescription != null) { String s = format(allDescription); sb.append(""); } if (nullDescription != null) { String s = format(nullDescription); sb.append(""); } getOptions(hubMaster, sb, new String[0], isAllSelected()); } catch (Exception e) { handleException(e,"getOptions()"); return ""; } lastValue = new String(sb); return lastValue; } /* @param ids the objectIds for all parents if this is using a recursiveHub. */ void getOptions(Hub hub, StringBuffer sb, String[] ids, boolean bAllFlag) { String s; hub.loadAllData(); for (int i=0; ; i++) { Object obj = hub.elementAt(i); if (obj == null) break; String id = Util.getObjectIdAsString(hub, obj); s = ClassModifier.getPropertyValueAsString(obj, methodGet,getFormat()); if (obj instanceof OAObject && ((OAObject)obj).isNull(propertyPath)) s = ""; if (s == null) s = ""; sb.append(""); if (recursiveMethod != null) { Hub h = (Hub) ClassModifier.getPropertyValue(obj, recursiveMethod); String[] ss = new String[ids.length+1]; System.arraycopy(ids, 0, ss, 0, ids.length); ss[ids.length] = id; if (h != null) getOptions(h, sb, ss, bAllFlag); } } } private String format(String s) { if (columns > 0) { int j = s.length(); if (j > columns) s = s.substring(0,columns); else { for ( ;j <%=form.getHtmlOptions("lstDept")%> String s = ""; if (htmlBefore != null) s += htmlBefore; s += "= 0) s += " size=\""+rows+"\""; s += ">"+getOptions()+"" ; if (htmlAfter != null) s += htmlAfter; return s; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy