1 19 package org.netbeans.modules.xml.core.wizard; 20 21 import java.awt.event.ActionEvent ; 22 import java.io.File ; 23 import java.util.Iterator ; 24 import java.util.Set ; 25 import java.util.StringTokenizer ; 26 import java.util.TreeSet ; 27 28 import javax.swing.JFileChooser ; 29 import javax.swing.filechooser.FileFilter ; 30 31 import org.openide.NotifyDescriptor; 32 import org.openide.DialogDisplayer; 33 import org.openide.actions.ActionManager; 34 import org.openide.windows.WindowManager; 35 36 import org.netbeans.api.xml.services.UserCatalog; 37 38 import org.netbeans.modules.xml.core.lib.AbstractUtil; 39 import org.openide.loaders.DataObject; 40 import org.openide.nodes.Node; 41 import org.openide.util.Lookup; 42 import org.openide.util.actions.SystemAction; 43 44 49 class Util extends AbstractUtil { 50 51 private static File lastDirectory; 53 54 55 public static final Util THIS = new Util(); 56 57 58 private Util () { 59 } 60 61 66 public static File selectSchemaFile(final String extensions) { 67 JFileChooser chooser = new JFileChooser (); 68 69 chooser.setFileFilter(new FileFilter () { 70 public boolean accept(File f) { 71 if (f.isDirectory()) return true; 72 StringTokenizer token = new StringTokenizer (extensions, " "); while (token.hasMoreElements()) { 74 if (f.getName().endsWith(token.nextToken())) return true; 75 } 76 return false; 77 } 78 public String getDescription() { 79 return Util.THIS.getString("PROP_schema_mask"); } 81 }); 82 83 if (lastDirectory != null) { 84 chooser.setCurrentDirectory(lastDirectory); 85 } 86 87 chooser.setDialogTitle(Util.THIS.getString("PROP_schema_dialog_name")); 88 while (chooser.showDialog(WindowManager.getDefault().getMainWindow(), 89 Util.THIS.getString("PROP_schema_select_button")) 90 == JFileChooser.APPROVE_OPTION) 91 { 92 File f = chooser.getSelectedFile(); 93 lastDirectory = chooser.getCurrentDirectory(); 94 if (f != null && f.isFile()) { 95 StringTokenizer token = new StringTokenizer (extensions, " "); while (token.hasMoreElements()) { 97 if (f.getName().endsWith(token.nextToken())) return f; 98 } 99 } 100 101 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( 102 Util.THIS.getString("MSG_inValidFile"), NotifyDescriptor.WARNING_MESSAGE)); 103 } 104 return null; 105 } 106 107 110 public static String [] getKnownDTDPublicIDs() { 111 UserCatalog catalog = UserCatalog.getDefault(); 112 if (catalog != null) { 113 Set idSet = new TreeSet (); 114 for (Iterator it = catalog.getPublicIDs(); it.hasNext(); ) { 115 String next = (String ) it.next(); 116 String nextLowerCase = next.toLowerCase(); 118 if (!nextLowerCase.startsWith("schema:") && !nextLowerCase.endsWith(".xsd")) { idSet.add(next); 120 } 121 } 122 return (String []) idSet.toArray(new String [idSet.size()]); 123 } else { 124 Util.THIS.debug("Note SourceResolver not found!"); return new String [0]; 126 } 127 } 128 129 132 public static void performDefaultAction (DataObject dataObject) { 133 134 Node node = dataObject.getNodeDelegate(); 135 SystemAction action = node.getDefaultAction(); 136 137 if (action != null) { 138 ActionManager manager = (ActionManager) Lookup.getDefault().lookup(ActionManager.class); 139 manager.invokeAction(action, new ActionEvent (node, ActionEvent.ACTION_PERFORMED, "")); } 141 } 142 143 } 144 | Popular Tags |