1 19 20 package org.netbeans.modules.xml.wsdl.ui.api.property; 21 22 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement; 23 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility; 24 import org.netbeans.modules.xml.wsdl.ui.view.property.XSDBooleanAttributeProperty; 25 import org.openide.util.NbBundle; 26 27 public class ExtensibilityElementPropertyAdapter extends PropertyAdapter { 28 private ExtensibilityElement element; 29 private String attributeName; 30 private String defaultValue; 31 private boolean supportsDefaultValue; 32 private String valueNotSetMessage = NbBundle.getMessage(XSDBooleanAttributeProperty.class, "LBL_ValueNotSet"); 33 private boolean isOptional; 34 35 public ExtensibilityElementPropertyAdapter(ExtensibilityElement element, String name, boolean isOptional) { 36 super(element); 37 this.element = element; 38 this.attributeName = name; 39 this.isOptional = isOptional; 40 } 41 42 public ExtensibilityElementPropertyAdapter(ExtensibilityElement element, String name) { 43 this(element, name, false); 44 } 45 46 public ExtensibilityElementPropertyAdapter(ExtensibilityElement element, String name, String defaultValue) { 47 this(element, name, false); 48 this.defaultValue = defaultValue; 49 this.supportsDefaultValue = true; 50 } 51 52 56 public String getValue() { 57 String value = element.getAttribute(attributeName); 58 if (value == null) { 59 value = supportsDefaultValue ? defaultValue : ""; 60 } 61 return value; 62 } 63 64 68 public void setValue(String value) { 69 boolean inTransaction = Utility.startTransaction(element.getModel()); 70 if (value == null || value.trim().length() == 0 || value.equalsIgnoreCase(valueNotSetMessage)) { 71 value = supportsDefaultValue ? defaultValue : null; 72 } 73 element.setAttribute(attributeName, value); 74 Utility.endTransaction(element.getModel(), inTransaction); 75 } 76 77 82 public void setValue(Object val) { 83 84 } 85 86 public ExtensibilityElement getExtensibilityElement() { 87 return element; 88 } 89 90 91 public String getDefaultValue() { 92 if (defaultValue == null) { 93 return valueNotSetMessage; 94 } 95 return defaultValue; 96 } 97 98 public boolean supportsDefaultValue() { 99 return supportsDefaultValue || isOptional; 100 } 101 102 public void setOptional(boolean bool) { 103 isOptional = bool; 104 } 105 106 public boolean isOptional() { 107 return isOptional; 108 } 109 110 public String getMessageForUnSet() { 111 return valueNotSetMessage; 112 } 113 114 } 115 | Popular Tags |