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 com.sun.jsfcl.std;
042:
043: import java.awt.Component;
044: import java.beans.PropertyEditorSupport;
045: import java.util.ArrayList;
046: import javax.faces.component.UIComponent;
047: import javax.faces.component.UIViewRoot;
048: import com.sun.jsfcl.util.ComponentBundle;
049: import com.sun.rave.designtime.DesignBean;
050: import com.sun.rave.designtime.DesignProperty;
051: import com.sun.rave.designtime.PropertyEditor2;
052:
053: /**
054: * @deprecated
055: */
056:
057: public class UiComponentIdPropertyEditor extends PropertyEditorSupport
058: implements PropertyEditor2 {
059:
060: private static final ComponentBundle bundle = ComponentBundle
061: .getBundle(UiComponentIdPropertyEditor.class);
062:
063: private static final String EMPTY = bundle.getMessage("parenEmpty"); //NOI18N
064: private DesignProperty liveProperty;
065:
066: public String[] getTags() {
067: ArrayList list = new ArrayList();
068: DesignBean[] lbeans = getUIComponentBeans();
069: list.add(EMPTY);
070: for (int i = 0; i < lbeans.length; i++) {
071: DesignBean lbean = lbeans[i];
072: if (!(lbean.getInstance() instanceof UIViewRoot)
073: && (liveProperty == null || liveProperty
074: .getDesignBean().getInstance() != lbean
075: .getInstance())) {
076: list.add(lbean.getInstanceName());
077: }
078: }
079: return (String[]) list.toArray(new String[0]);
080: }
081:
082: public void setAsText(String text) throws IllegalArgumentException {
083: String uiComponentId = ""; //NOI18N
084: DesignBean[] lbeans = getUIComponentBeans();
085: if (!text.equals(EMPTY)) {
086: for (int i = 0; i < lbeans.length; i++) {
087: if (lbeans[i].getInstanceName().equals(text)) {
088: uiComponentId = ((UIComponent) lbeans[i]
089: .getInstance()).getId();
090: break;
091: }
092: }
093: }
094: setValue(uiComponentId);
095: }
096:
097: public String getAsText() {
098: String uiComponentId = (String) getValue();
099: if (uiComponentId == null) {
100: return ""; //NOI18N
101: }
102: DesignBean bean = getDesignBean();
103: return (bean == null) ? "" : ((UIComponent) bean.getInstance())
104: .getId(); //NOI18N
105: }
106:
107: public String getJavaInitializationString() {
108: if (getAsText().equals("null")) { //NOI18N
109: return "\"\""; //NOI18N
110: }
111: return (getValue() == null || getValue().equals("")) ? "\"\"" : //NOI18N
112: ("\""
113: + ((UIComponent) getDesignBean().getInstance())
114: .getId() + "\""); //NOI18N
115: }
116:
117: public boolean supportsCustomEditor() {
118: return false;
119: }
120:
121: public Component getCustomEditor() {
122: return null;
123: }
124:
125: public void setDesignProperty(DesignProperty liveProperty) {
126: this .liveProperty = liveProperty;
127: }
128:
129: private DesignBean getDesignBean() {
130: if (liveProperty == null) {
131: return null;
132: }
133: DesignBean[] lbeans = liveProperty.getDesignBean()
134: .getDesignContext().getBeansOfType(UIComponent.class);
135: for (int i = 0; i < lbeans.length; i++) {
136: if (getValue().equals(
137: ((UIComponent) lbeans[i].getInstance()).getId())) {
138: return lbeans[i];
139: }
140: }
141: return null;
142: }
143:
144: private DesignBean[] getUIComponentBeans() {
145: return (liveProperty == null) ? new DesignBean[0]
146: : liveProperty.getDesignBean().getDesignContext()
147: .getBeansOfType(UIComponent.class);
148: }
149: }
|