001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.war.beans.admin.content;
034:
035: import com.flexive.shared.CacheAdmin;
036: import com.flexive.shared.content.FxData;
037: import com.flexive.shared.content.FxGroupData;
038: import com.flexive.shared.content.FxPropertyData;
039: import com.flexive.shared.structure.FxAssignment;
040: import com.flexive.shared.structure.FxEnvironment;
041:
042: import javax.faces.model.SelectItem;
043: import java.util.ArrayList;
044: import java.util.Hashtable;
045: import java.util.List;
046:
047: /**
048: * Helper class for the ContentEditor.
049: * <p/>
050: * It provides lookups for a property assignment's display name.
051: *
052: * @author Gregor Schober (gregor.schober@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
053: */
054: class CeAddElementOptions extends Hashtable<FxData, List<SelectItem>> {
055:
056: private ContentEditorBean parent;
057:
058: /**
059: * Constructor.
060: *
061: * @param parent the associated content editor
062: */
063: protected CeAddElementOptions(ContentEditorBean parent) {
064: super (0);
065: this .parent = parent;
066: }
067:
068: public List<SelectItem> get(Object element) {
069:
070: // Avoid null pointer
071: if (element == null) {
072: return new ArrayList<SelectItem>(0);
073: }
074:
075: try {
076: ArrayList<SelectItem> result = new ArrayList<SelectItem>(10);
077:
078: // Get the group data to work on
079: FxGroupData gd;
080: if (element instanceof FxPropertyData) {
081: gd = ((FxPropertyData) element).getParent();
082: } else {
083: gd = (FxGroupData) element;
084: }
085:
086: // Determine the available options
087: if (gd != null) {
088: List<String> createable = gd
089: .getCreateableChildren(true);
090: final FxEnvironment environment = CacheAdmin
091: .getFilteredEnvironment();
092: for (String createable_xpath : createable) {
093: String display = createable_xpath;
094: try {
095: FxAssignment ass = environment.getType(
096: parent.getType()).getAssignment(
097: createable_xpath);
098: display = ContentEditorBean.getDisplay(ass)
099: .getBestTranslation();
100: } catch (Throwable t) { /*ignore*/
101: }
102: result
103: .add(new SelectItem(createable_xpath,
104: display));
105: }
106: result.trimToSize();
107: }
108:
109: return result;
110: } catch (Throwable t) {
111: System.err.println(t.getMessage());
112: t.printStackTrace();
113: return new ArrayList<SelectItem>(0);
114: }
115:
116: }
117: }
|