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 java.io.*; 17 import java.net.URL ; 18 import java.util.*; 19 import javax.swing.*; 20 import org.w3c.dom.*; 21 22 28 public class ExternalPackages extends XMLCollection { 29 34 public ExternalPackages (Package myOwner) { 35 super(myOwner); 36 } 37 38 45 73 74 80 public XMLElement generateNewElement() { 81 ExternalPackage ep=new ExternalPackage(this); 82 ep.setRequired(true); 83 return ep; 84 } 85 86 public boolean canInsertElement (XMLElement el) { 87 boolean canInsert=true; 88 try { 90 System.setProperty("user.dir",((Package )myOwner).getXMLInterface().getParentDirectory((Package )myOwner)); 91 } catch (Exception ex) {} 92 93 try { 94 String extID=((Package )myOwner).getXMLInterface().getIDFromFile(el.toString()); 96 97 if (extID.length()==0) { 99 canInsert=false; 100 } 101 102 String myOwnerId=myOwner.get("Id").toString().trim(); 105 if (canInsert && myOwnerId.equals(extID)) { 106 canInsert=false; 107 } 108 109 if (canInsert) { 112 Iterator it=refCollectionElements.iterator(); 113 while (it.hasNext()) { 114 ExternalPackage ep=(ExternalPackage)it.next(); 115 String epId=((Package )myOwner).getXMLInterface().getExternalPackageByRelativeFilePath( 116 ep.toString(),(Package )myOwner).get("Id").toString(); 117 if (extID.equals(epId)) { 118 canInsert=false; 119 break; 120 } 121 } 122 } 123 124 if (canInsert) { 128 String cp=XMLUtil.getCanonicalPath(el.toString(), false); 129 Iterator it=((Package )myOwner).getXMLInterface().getAllPackages().iterator(); 130 while (it.hasNext()) { 131 Package p=(Package )it.next(); 132 String pId=p.get("Id").toString(); 133 if (extID.equals(pId) && !((Package )myOwner).getXMLInterface().getAllPackageFilenames().contains(cp)) { 134 canInsert=false; 135 break; 136 } 137 } 138 } 139 140 } catch (Exception ex) { 141 } 143 if (!canInsert) { 144 XMLUtil.message(XMLUtil.getLanguageDependentString("InformationExternalPackageCannotBeInserted"), 145 JOptionPane.INFORMATION_MESSAGE); 146 } 147 return canInsert; 148 } 149 150 151 159 public void onElementInserted (XMLElement el) { 160 ExternalPackage ep = (ExternalPackage) el; 161 String xmlFile = XMLUtil.getCanonicalPath(ep.toString(), false); 164 if (((Package )myOwner).getXMLInterface().doesPackageFileExists(xmlFile) && ((Package )myOwner).getXMLInterface().getIDFromFile(xmlFile).length()>0) { 165 ((Package )myOwner).insertFromExternal(ep); 166 } else { 167 XMLUtil.message(XMLUtil.getLanguageDependentString("InformationErrorWhileOpeningFile"), 168 JOptionPane.INFORMATION_MESSAGE); 169 refCollectionElements.remove(ep); 170 } 171 } 172 173 183 public boolean canRemoveElement (XMLElement el) { 184 return ((Package )myOwner).canRemoveExternalPackage((ExternalPackage)el); 185 } 186 187 194 public void onElementRemoved (XMLElement el) { 195 ((Package )myOwner).removeExternal ((ExternalPackage)el); 196 197 } 198 199 210 public XMLPanel getPanel () { 211 controlledPanel=new XMLListPanel(this,"",false,true,false); 212 controlPanel=new XMLListControlPanel(this,"",true,false,true); 213 return new XMLGroupPanel(this,new XMLPanel[]{ 214 controlledPanel,controlPanel},toLabel(),XMLPanel.BOX_LAYOUT, 215 false,true); 216 } 217 218 public String getInUseMessageName (XMLComplexElement el) { 219 return "ErrorCannotRemoveExternalPackage"; 220 } 221 222 223 } 224 | Popular Tags |