1 19 20 21 package org.netbeans.modules.i18n.form; 22 23 import org.netbeans.modules.form.I18nValue; 24 import org.netbeans.modules.form.FormDesignValue; 25 import org.netbeans.modules.form.FormEditor; 26 import org.netbeans.modules.form.FormModel; 27 import org.netbeans.modules.form.FormProperty; 28 import org.netbeans.modules.i18n.I18nSupport; 29 import org.netbeans.modules.i18n.I18nUtil; 30 import org.netbeans.modules.i18n.ResourceHolder; 31 import org.netbeans.modules.i18n.java.JavaI18nString; 32 import org.netbeans.modules.i18n.java.JavaResourceHolder; 33 import org.openide.loaders.DataObject; 34 35 44 public class FormI18nString extends JavaI18nString implements I18nValue { 45 46 String bundleName; 48 Object allData; 51 52 public FormI18nString(I18nSupport i18nSupport) { 53 super(i18nSupport); 54 } 55 56 58 public FormI18nString(JavaI18nString source) { 59 this(createNewSupport(source.getSupport()), 60 source.getKey(), 61 source.getValue(), 62 source.getComment(), 63 source.getArguments(), 64 source.getReplaceFormat()); 65 } 66 67 FormI18nString(DataObject srcDataObject) { 68 super(new FormI18nSupport.Factory().createI18nSupport(srcDataObject)); 69 70 boolean nbBundle = org.netbeans.modules.i18n.Util.isNbBundleAvailable(srcDataObject); 71 if (I18nUtil.getDefaultReplaceFormat(!nbBundle).equals(getReplaceFormat())) { 72 setReplaceFormat(I18nUtil.getDefaultReplaceFormat(nbBundle)); 73 } 74 } 75 76 private FormI18nString(I18nSupport i18nSupport, String key, String value, String commment, String [] arguments, String replaceFormat) { 77 super(i18nSupport); 78 79 this.key = key; 80 this.value = value; 81 this.comment = comment; 82 83 this.arguments = arguments; 84 this.replaceFormat = replaceFormat; 85 } 86 87 public Object copy(FormProperty formProperty) { 88 FormModel form = formProperty.getPropertyContext().getFormModel(); 89 if (form == null) 90 return getValue(); 91 92 DataObject sourceDO = FormEditor.getFormDataObject(form); 93 if (sourceDO == null) 94 return getValue(); 95 96 boolean sameForm = (sourceDO == support.getSourceDataObject()); 97 boolean autoMode = form.getSettings().getI18nAutoMode(); 98 DataObject resource = sameForm || !autoMode ? 99 support.getResourceHolder().getResource() : null; 100 I18nSupport newSupport = createNewSupport(sourceDO, resource); 101 102 FormI18nString newI18nString; 103 if (autoMode) { newI18nString = new FormI18nString(newSupport, 105 COMPUTE_AUTO_KEY, getValue(), getComment(), 106 getArguments(), getReplaceFormat()); 107 JavaResourceHolder jrh = (JavaResourceHolder) support.getResourceHolder(); 108 newI18nString.allData = jrh.getAllData(getKey()); 109 } 110 else { 111 newI18nString = new FormI18nString(newSupport, 112 getKey(), getValue(), getComment(), 113 getArguments(), getReplaceFormat()); 114 if (!sameForm) { ResourceHolder rh = newSupport.getResourceHolder(); 116 newI18nString.value = rh.getValueForKey(getKey()); 117 newI18nString.comment = rh.getCommentForKey(getKey()); 118 } 119 } 120 return newI18nString; 121 } 122 123 public String toString() { 124 return getValue(); 125 } 126 127 private static I18nSupport createNewSupport(I18nSupport support) { 128 return createNewSupport(support.getSourceDataObject(), support.getResourceHolder().getResource()); 129 } 130 131 private static I18nSupport createNewSupport(DataObject sourceDataObject, DataObject resource) { 132 I18nSupport newSupport = new FormI18nSupport.Factory().createI18nSupport(sourceDataObject); 133 if(resource != null) { 134 newSupport.getResourceHolder().setResource(resource); 135 } 136 return newSupport; 137 } 138 139 142 public Object getDesignValue() { 143 String designValue = getValue(); 145 if(designValue == null) 146 return FormDesignValue.IGNORED_VALUE; 147 else 148 return designValue; 149 } 150 151 153 public String getDescription() { 154 return "<" + getKey() + ">"; } 156 } 157 | Popular Tags |