1 19 20 package org.netbeans.modules.xml.wsdl.ui.wizard; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import java.util.StringTokenizer ; 28 import org.netbeans.modules.xml.schema.model.Schema; 29 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 30 import org.netbeans.modules.xml.wsdl.ui.view.ImportSchemaCustomizer; 31 import org.netbeans.modules.xml.xam.Model; 32 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceDataNode; 33 import org.netbeans.modules.xml.xam.ui.customizer.ExternalReferenceNode; 34 import org.openide.filesystems.FileObject; 35 import org.openide.filesystems.FileUtil; 36 import org.openide.loaders.DataObject; 37 import org.openide.nodes.Node; 38 39 45 public class ImportSchemaCreator extends ImportSchemaCustomizer { 46 47 private static final long serialVersionUID = 1L; 48 49 private List <String > selectedFiles; 50 51 private boolean ignorePropertyChange; 52 53 60 public ImportSchemaCreator(Schema schema, WSDLModel model, String files) { 61 super(schema, model); 62 StringTokenizer tokenizer = new StringTokenizer (files, ","); 63 selectedFiles = new ArrayList <String >(); 64 while (tokenizer.hasMoreTokens()) { 65 selectedFiles.add(tokenizer.nextToken()); 66 } 67 } 68 69 protected boolean allowEmptySelection() { 70 return true; 73 } 74 75 @Override 76 public void applyChanges() throws IOException { 77 } 81 82 public ExternalReferenceDataNode createExternalReferenceNode(Node original) { 83 ExternalReferenceDataNode erdn = super.createExternalReferenceNode(original); 84 if (selectedFiles != null) { 87 DataObject dobj = (DataObject) erdn.getLookup().lookup(DataObject.class); 89 String location = dataObjectToURI(dobj); 90 if (selectedFiles.contains(location)) { 91 ignorePropertyChange = true; 92 erdn.setSelected(true); 93 ignorePropertyChange = false; 94 } 95 } 96 return erdn; 97 } 98 99 105 private static String dataObjectToURI(DataObject dobj) { 106 FileObject fobj = dobj.getPrimaryFile(); 107 File file = FileUtil.toFile(fobj); 108 return file.toURI().normalize().toString(); 109 } 110 111 116 public String getSelectedFiles() { 117 StringBuilder sb = new StringBuilder (); 118 for (String uri : selectedFiles) { 119 if (sb.length() > 0){ 120 sb.append(","); 121 } 122 sb.append(uri); 123 } 124 return sb.toString(); 125 } 126 127 public void propertyChange(PropertyChangeEvent event) { 128 super.propertyChange(event); 130 if (!ignorePropertyChange && event.getPropertyName().equals( 135 ExternalReferenceDataNode.PROP_SELECTED)) { 136 ExternalReferenceDataNode erdn = 137 (ExternalReferenceDataNode) event.getSource(); 138 boolean selected = ((Boolean ) event.getNewValue()).booleanValue(); 139 DataObject dobj = (DataObject) erdn.getLookup().lookup(DataObject.class); 140 String uri = dataObjectToURI(dobj); 141 if (selected) { 142 selectedFiles.add(uri); 143 } else { 144 selectedFiles.remove(uri); 145 } 146 } 147 } 148 } 149 | Popular Tags |