001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.web.ui.dt.component.propertyeditors;
042:
043: import com.sun.rave.designtime.DesignBean;
044: import com.sun.rave.designtime.DesignProperty;
045: import com.sun.rave.propertyeditors.domains.AttachedDomain;
046: import com.sun.rave.propertyeditors.domains.Element;
047: import com.sun.rave.web.ui.component.Tab;
048: import com.sun.rave.web.ui.component.TabSet;
049: import java.util.ArrayList;
050: import java.util.Iterator;
051: import java.util.List;
052: import java.util.Set;
053: import java.util.Stack;
054: import java.util.TreeSet;
055: import javax.faces.component.UIComponent;
056:
057: /**
058: * Domain of identifiers of all {@link com.sun.rave.web.ui.dt.component.Tab} components
059: * within the currently selected {@link com.sun.rave.web.ui.dt.component.TabSet}
060: * component. Used to provide an enumeration of values for the <code>selected</code>
061: * property. Iterates over all tabs in the tabSet in document order.
062: *
063: * @author gjmurphy
064: */
065: public class TabIdsDomain extends AttachedDomain {
066:
067: public Element[] getElements() {
068: // If we have not been attached yet, there is nothing we can do
069: // except return an empty list
070: if (this .getDesignProperty() == null)
071: return Element.EMPTY_ARRAY;
072: // Construct a list of all tab descendants
073: Stack beanStack = new Stack();
074: beanStack.push(this .getDesignProperty().getDesignBean());
075: List beanList = new ArrayList();
076: while (!beanStack.isEmpty()) {
077: DesignBean bean = (DesignBean) beanStack.pop();
078: if (bean.getInstance() instanceof Tab)
079: beanList.add(bean);
080: DesignBean[] childBeans = bean.getChildBeans();
081: for (int i = bean.getChildBeanCount() - 1; i >= 0; i--)
082: beanStack.push(childBeans[i]);
083: }
084: if (beanList.size() == 0)
085: return Element.EMPTY_ARRAY;
086: // Construct an array of elements from the labels and identifiers of
087: // the retained tab components
088: Element elements[] = new Element[beanList.size()];
089: for (int i = 0; i < elements.length; i++) {
090: DesignBean bean = (DesignBean) beanList.get(i);
091: Tab tab = (Tab) bean.getInstance();
092: String id = tab.getId();
093: String text = tab.getText().toString();
094: String gutter = "";
095: if (bean.getBeanParent().getInstance() instanceof Tab) {
096: gutter = " ";
097: if (bean.getBeanParent().getBeanParent().getInstance() instanceof Tab) {
098: gutter = " ";
099: }
100: }
101: if (text == null)
102: elements[i] = new Element(id, gutter + id);
103: else
104: elements[i] = new Element(id, gutter + text + " (" + id
105: + ")");
106: }
107: return elements;
108:
109: }
110:
111: }
|