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: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.modules.j2ee.sun.ddloaders.multiview;
029:
030: import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
031: import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer;
032: import org.openide.ErrorManager;
033:
034: /**
035: *
036: * @author Peter Williams
037: */
038: public abstract class DDTextFieldEditorModel extends
039: TextItemEditorModel {
040:
041: private final String nameProperty;
042: private final String attrProperty;
043:
044: public DDTextFieldEditorModel(
045: final XmlMultiViewDataSynchronizer synchronizer,
046: final String np) {
047: super (synchronizer, true, true);
048: this .nameProperty = np;
049: this .attrProperty = null;
050: }
051:
052: public DDTextFieldEditorModel(
053: final XmlMultiViewDataSynchronizer synchronizer,
054: final String np, String ap) {
055: super (synchronizer, true, true);
056: this .nameProperty = np;
057: this .attrProperty = ap;
058: }
059:
060: /** Override this to return the parent bean that this object manipulates.
061: */
062: protected abstract CommonDDBean getBean();
063:
064: /** Override this if the parent really provides a wrapper for a child bean,
065: * ala JavaWebStartAccess in SunApplicationClient or EnterpriseBeans in SunEjbJar.
066: *
067: * Used by setValue() method to ensure such child beans are created only when
068: * needed.
069: */
070: protected CommonDDBean getBean(boolean create) {
071: return getBean();
072: }
073:
074: protected String getValue() {
075: String result = null;
076: CommonDDBean bean = getBean();
077: if (bean != null) {
078: if (attrProperty == null) {
079: result = (String) bean.getValue(nameProperty);
080: } else if (nameProperty == null) {
081: result = bean.getAttributeValue(attrProperty);
082: } else {
083: result = bean.getAttributeValue(nameProperty,
084: attrProperty);
085: }
086: }
087: return result;
088: }
089:
090: protected void setValue(String value) {
091: CommonDDBean bean = getBean(true);
092: if (bean != null) {
093: if (attrProperty == null) {
094: getBean().setValue(nameProperty, value);
095: } else if (nameProperty == null) {
096: getBean().setAttributeValue(attrProperty, value);
097: } else {
098: getBean().setAttributeValue(nameProperty, attrProperty,
099: value);
100: }
101: } else {
102: ErrorManager.getDefault().log(
103: ErrorManager.INFORMATIONAL,
104: "Unable to set property (" + nameProperty + ", "
105: + attrProperty + ") -- bean is null");
106: }
107: }
108:
109: }
|