1 10 11 package org.enhydra.jawe.xml.elements; 12 13 import org.enhydra.jawe.xml.*; 14 import org.enhydra.jawe.xml.panels.*; 15 16 import javax.swing.*; 17 import java.util.*; 18 import org.w3c.dom.*; 19 20 30 public class Participant extends XMLCollectionElement { 31 private ParticipantType refParticipantType=new ParticipantType(); 32 private Description refDescription=new Description(); private ExternalReference refExternalReference=new ExternalReference(); private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); 36 private XMLAttribute attrName=new XMLAttribute("Name"); 37 38 39 private ExtendedAttributes clonedEAs; 40 41 private int graphReferences=0; 42 43 47 48 private static Participant freeTextExpressionParticipant=new Participant(null); 49 static { 50 freeTextExpressionParticipant.set("Id","FreeTextExpressionParticipant"); 51 freeTextExpressionParticipant.set("Name",XMLUtil.getLanguageDependentString("FreeTextExpressionParticipantKey")); 52 freeTextExpressionParticipant.setReadOnly(true); 53 } 54 57 public static Participant getFreeTextExpressionParticipant () { 58 return freeTextExpressionParticipant; 59 } 60 61 67 public Participant (Participants p) { 68 super(p); 69 70 fillStructure(); 71 } 72 73 77 protected void fillStructure () { 78 super.fillStructure(); 79 complexStructure.add(attrName); 81 attributes.add(attrName); 82 refParticipantType.setRequired(true); 83 complexStructure.add(refParticipantType); 84 complexStructure.add(refDescription); 85 complexStructure.add(refExternalReference); 86 complexStructure.add(refExtendedAttributes); 87 } 88 89 95 public Object toValue () { 96 return attrName.toValue(); 97 } 98 99 110 public String toString () { 111 String partTypeString = refParticipantType.toValue().toString(); 112 if (partTypeString.equals("ROLE")) { 113 partTypeString = " - rol"; 114 } else if (partTypeString.equals("ORGANIZATIONAL_UNIT")) { 115 partTypeString = " - org"; 116 } else if (partTypeString.equals("RESOURCE_SET")) { 117 partTypeString = " - set"; 118 } else if (partTypeString.equals("RESOURCE")) { 119 partTypeString = " - res"; 120 } else if (partTypeString.equals("HUMAN")) { 121 partTypeString = " - man"; 122 } else if (partTypeString.equals("SYSTEM")) { 123 partTypeString = " - sys"; 124 } 125 String disp=attrName.toString(); 126 if (disp.trim().length()==0) { 127 disp=attrId.toString().trim(); 128 } 129 return disp + partTypeString; 130 } 131 132 133 140 public String getTooltip () { 141 return XMLUtil.makeTooltip(new XMLElement[] {attrId,attrName, 142 refParticipantType, refDescription}); 143 } 144 145 152 public XMLPanel getPanel () { 153 clonedEAs=(ExtendedAttributes)refExtendedAttributes.clone(); 154 return new XMLGroupPanel(this, 155 new XMLElement[] { 156 attrId, 157 attrName, 158 refParticipantType, 159 refDescription, 160 refExternalReference, 161 clonedEAs 162 },toLabel()); 163 } 164 165 public Package getPackage () { 166 if (myCollection!=null) { 167 return ((Participants)myCollection).getPackage(); 168 } else { 169 return null; 170 } 171 } 172 173 public void graphReferenceAdded () { 174 graphReferences++; 175 } 176 177 public void graphReferenceRemoved () { 178 graphReferences--; 179 } 180 181 public int getNoOfGraphReferences () { 182 return graphReferences; 183 } 184 185 189 public boolean isGraphContained () { 190 return graphReferences>0; 191 } 192 193 196 public boolean isIDUniqueAndValid (XMLPanel groupPanel) { 197 if (this==freeTextExpressionParticipant) return true; 198 XMLTextPanel tp=(XMLTextPanel)((XMLGroupPanel)groupPanel).getPanel(0); 199 String IDToCheck=tp.getText(); 200 XMLComplexElement p=getCollection().getCollectionElement(IDToCheck); 202 boolean isOK=true; 203 String message=null; 204 String dialogTitle=null; 205 if ((p!=null && p!=this) || IDToCheck.equals(Participant.getFreeTextExpressionParticipant().getID())) { 206 message=XMLUtil.getLanguageDependentString("ErrorIDMustBeUnique"); 207 dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotUnique"); 208 isOK=false; 209 } else if (!XMLCollection.isIdValid(IDToCheck)) { 210 message=XMLUtil.getLanguageDependentString("ErrorIDMustBeValid"); 211 dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotValid"); 212 isOK=false; 213 } else { 214 Participant pp=((Participants)myCollection).getParticipant(IDToCheck); 215 if (pp!=null && pp.isGraphContained() && pp!=this) { 216 message=XMLUtil.getLanguageDependentString("ErrorCannotRedefineParticipantThatIsShownInTheGraph"); 217 dialogTitle=XMLUtil.getLanguageDependentString("Title"); 218 isOK=false; 219 } 220 } 221 if (!isOK) { 222 XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,"",message); 223 ((JTextField)tp.getComponent(2)).requestFocus(); 224 } 225 return isOK; 226 } 227 228 235 public boolean isValidEnter (XMLPanel groupPanel) { 236 if (clonedEAs!=null) { 237 complexStructure.remove(refExtendedAttributes); 238 refExtendedAttributes=clonedEAs; 239 complexStructure.add(5,refExtendedAttributes); 240 } 241 return true; 242 } 243 244 247 public Collection toComplexTypeValues () { 248 java.util.List l=new ArrayList(); 249 Iterator it=complexStructure.iterator(); 250 while (it.hasNext()) { 251 XMLElement el=(XMLElement)it.next(); 252 if (el instanceof XMLAttribute || el instanceof ParticipantType) { 253 l.add(el.toString()); 254 } else { 255 l.add(el.toValue()); 256 } 257 } 258 return l; 259 } 260 261 } 262 | Popular Tags |