|
From: <j_m...@us...> - 2004-02-29 12:22:29
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11310/src/org/cobricks/item Modified Files: ItemPresenter.java Log Message: Index: ItemPresenter.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemPresenter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ItemPresenter.java 11 Feb 2004 14:31:52 -0000 1.1 --- ItemPresenter.java 29 Feb 2004 12:04:25 -0000 1.2 *************** *** 16,19 **** --- 16,24 ---- import org.cobricks.core.ComponentPresenterInterface; import org.cobricks.core.util.LogUtil; + import org.cobricks.core.Ontology; + import org.cobricks.core.OntologyClassAttr; + import org.cobricks.core.OntologyDataType; + import org.cobricks.core.OntologyClass; + import java.util.List; *************** *** 21,28 **** implements ComponentPresenterInterface { ! static Logger logger = Logger.getLogger(ItemPresenter.class); ! /** * --- 26,36 ---- implements ComponentPresenterInterface { ! private static String DEFAULT_ITEM_CREATION_ITEM_CLASS = "item"; ! private static String[] LANGUAGES = {"de", "en", "fr"}; static Logger logger = Logger.getLogger(ItemPresenter.class); + private Ontology ontology = null; ! private ItemManager itemManager = null; ! private CoreManager coreManager = null; /** * *************** *** 36,39 **** --- 44,51 ---- throws Exception { logger.info("Initializing item presenter"); + this.itemManager = (ItemManager) coreManager.getComponentDirectory(). + getManager("itemManager"); + this.coreManager = coreManager; + ontology = itemManager.getOntology(); } *************** *** 49,53 **** return "/item/itemclass=item"; } - } --- 61,164 ---- return "/item/itemclass=item"; } + public String printAttrInput(String itemClass, String aname, int rows,int cols){ + String result = ""; + OntologyClassAttr oca = this.ontology.getClass(itemClass).getAttribute(aname); + OntologyDataType odat = oca.getOntologyDataType(); + String defaultVal = oca.getDefault(); + if (!oca.getValues().isEmpty()){ //There are possible values + result += "<select name=\""+aname+"\" size=\"1\">\n"; + List options = oca.getValues(); + Iterator it = options.iterator(); + //result += "<option selected=\"selected\">" + + //(String) it.next() + "</option>"; + String next; + while (it.hasNext()){ + result += "<option"; + next = (String) it.next(); + if (defaultVal !=null && next.equals(defaultVal)) { + result+=" selected=\"selected\""; + } + result +=">" + next + "</option>\n"; + } + result += "</select>"; + } else if (odat.getTypeName().equals("boolean")){ + result += "<input type=\"checkbox\" name=\"" + aname + "\" value=" + + "\"true\""; + if (defaultVal !=null && defaultVal.equals("true")) { + result+=" checked=\"checked\""; + } + result+= "/>"; + } else if (rows < 2){ + result += "<input name=\"" + aname + "\" type=\"text\""; + if (odat.hasMaxLength()){ + result += " size=\"" + odat.getMaxLength() + "\" maxlength=\""+ + odat.getMaxLength() + "\""; + }else{ + result += " size=\"" + cols + "\""; + } + if (defaultVal != null) { + result += " value=\"" + defaultVal + "\""; + } + result += "/>"; + } else { + result += "<textarea name=\"" + aname + "\" cols=\"" + cols + + "\" rows=\"" + rows + "\">"; + if (defaultVal != null) { + result += defaultVal; + } + result += "</textarea>"; + } + return result; + } + + public String printMultiLangDropDown(String defaultLang){ + String result = "<select size=1>\n"; + for(int i=0; i<LANGUAGES.length; i++){ + result += "<option"; + if(LANGUAGES[i].equals(defaultLang)){ + result += " selected=\"selected\""; + } + result += ">" + LANGUAGES[i] + "</option>\n"; + } + result += "</select>"; + return result; + } + + public String printItemClassesDropDown(String defaultClassName){ + String result = "<select size=1>\n"; + Collection classes = this.ontology.getClasses(); + Iterator iter = classes.iterator(); + String className; + while(iter.hasNext()){ + className = ((OntologyClass)iter.next()).getName(); + result += "<option"; + if(className.equals(defaultClassName)){ + result += " selected=\"selected\""; + } + result += ">" + className + "</option>\n"; + } + result += "</select>"; + return result; + } + + public String printHiddenAttr(String name, String value){ + return "<input type=\"hidden\" name=\"" + name + "\" value=\"" + + value +"\"/>"; + } + + + public Set getAttributeNames(String itemClassName) { + OntologyClass oc = ontology.getClass(itemClassName); + if (oc == null && !itemClassName.equals(DEFAULT_ITEM_CREATION_ITEM_CLASS) ) { + logger.warn("Item class "+ itemClassName + " not found. Returning default"); + return this.getAttributeNames(DEFAULT_ITEM_CREATION_ITEM_CLASS); + } else if (oc==null){ + logger.error("Default item class not available. Check Ontology!"); + return new HashSet(); + } else { + return oc.getAttributeNames(); + } + } + } |