1 30 package com.genimen.djeneric.structure; 31 32 import java.util.ArrayList ; 33 import java.util.HashMap ; 34 35 import com.genimen.djeneric.repository.exceptions.DjenericException; 36 import com.genimen.djeneric.util.DjLogger; 37 38 public class EditorDefinition implements Cloneable 39 { 40 41 String _name; 42 ScriptDefinition _scriptDefinition = new ScriptDefinition(); 43 ExtentUsage _usages; 44 boolean _markedForDelete = false; 45 String _customEditorClass = null; 46 47 public Object clone() 48 { 49 EditorDefinition result = null; 50 try 51 { 52 result = (EditorDefinition) super.clone(); 53 result._scriptDefinition = (ScriptDefinition) _scriptDefinition.clone(); 54 if (_usages != null) result._usages = (ExtentUsage) _usages.clone(); 55 } 56 catch (CloneNotSupportedException e) 57 { 58 DjLogger.log(e); 59 } 60 61 return result; 62 } 63 64 public void copyFrom(EditorDefinition source) 65 { 66 _name = source._name; 67 _customEditorClass = source._customEditorClass; 68 _scriptDefinition = (ScriptDefinition) source.getScriptDefinition().clone(); 69 _usages = (ExtentUsage) source._usages.clone(); 70 _markedForDelete = source._markedForDelete; 71 } 72 73 public boolean equals(Object obj) 74 { 75 if (obj == this) return true; 76 if (!(obj instanceof EditorDefinition)) return false; 77 EditorDefinition other = (EditorDefinition) obj; 78 79 return safeCompare(_name, other._name) && safeCompare(_customEditorClass, other._customEditorClass) 80 && safeCompare(_scriptDefinition, other._scriptDefinition) && safeCompare(_usages, other._usages); 81 } 82 83 public int hashCode() 84 { 85 int result = 0; 86 if (_name != null) result += _name.hashCode(); 87 if (_customEditorClass != null) result += _customEditorClass.hashCode(); 88 if (_scriptDefinition != null) result += _scriptDefinition.hashCode(); 89 return result; 90 } 91 92 private boolean safeCompare(Object one, Object two) 93 { 94 if (one == null && two == null) return true; 95 if (one == null || two == null) return false; 96 97 return one.equals(two); 98 } 99 100 public ScriptDefinition getScriptDefinition() 101 { 102 return _scriptDefinition; 103 } 104 105 108 public void setScriptDefinition(ScriptDefinition scriptDefinition) 109 { 110 _scriptDefinition = scriptDefinition; 111 } 112 113 public EditorDefinition() 114 { 115 } 116 117 public EditorDefinition(String name, ExtentUsage usages) 118 { 119 _usages = usages; 120 _name = name; 121 } 122 123 public String getName() 124 { 125 return _name; 126 } 127 128 public void setName(String name) 129 { 130 _name = name; 131 } 132 133 public void setUsages(ExtentUsage usages) 134 { 135 _usages = usages; 136 } 137 138 public ExtentUsage getUsages() 139 { 140 return _usages; 141 } 142 143 public String toString() 144 { 145 StringBuffer result = new StringBuffer (); 146 result.append(_name); 147 148 if (_usages != null) 149 { 150 result.append(" ("); 151 result.append(_usages.getExtent().getName()); 152 result.append(")"); 153 } 154 155 return result.toString(); 156 } 157 158 public boolean isMarkedForDelete() 159 { 160 return _markedForDelete; 161 } 162 163 public void setMarkedForDelete(boolean markedForDelete) 164 { 165 _markedForDelete = markedForDelete; 166 } 167 168 public String getCustomEditorClass() 169 { 170 return _customEditorClass; 171 } 172 173 public void setCustomEditorClass(String className) 174 { 175 if (className != null && className.trim().length() == 0) className = null; 176 177 _customEditorClass = className; 178 } 179 180 public void removeInvalidExtents() 181 { 182 ExtentUsage usages = getUsages(); 183 if (usages != null) usages.deleteInvalidNodes(); 184 } 185 186 public void validate() throws DjenericException 187 { 188 _usages.validate(); 189 } 190 191 public void getUsageIdAndTypes(HashMap variables) 192 { 193 ExtentUsage usages = getUsages(); 194 addUsages(variables, usages); 195 } 196 197 private void addUsages(HashMap variables, ExtentUsage usage) 198 { 199 variables.put(usage.getId(), usage.getExtent().getQualifiedObjectType()); 200 ExtentUsage[] children = usage.getChildren(); 201 for (int i = 0; i < children.length; i++) 202 addUsages(variables, children[i]); 203 } 204 205 public String [] getEvents() 206 { 207 ArrayList ev = new ArrayList (); 208 209 ev.add("validate"); 210 ev.add("accept"); 211 ev.add("cancel"); 212 213 addExtentEvents(getUsages(), ev); 214 return (String []) ev.toArray(new String [0]); 215 } 216 217 protected void addExtentEvents(ExtentUsage usg, ArrayList ev) 218 { 219 ev.add(usg.getId() + ".aftercreate"); 220 ev.add(usg.getId() + ".afterdelete"); 221 ev.add(usg.getId() + ".afterpropertychanged"); 222 ev.add(usg.getId() + ".beforecreate"); 223 ev.add(usg.getId() + ".beforedelete"); 224 ev.add(usg.getId() + ".beforepropertychanged"); 225 226 ExtentUsage[] children = usg.getChildren(); 227 for (int i = 0; i < children.length; i++) 228 { 229 addExtentEvents(children[i], ev); 230 } 231 } 232 233 } | Popular Tags |