1 19 20 package org.netbeans.modules.db.explorer.actions; 21 22 import java.sql.*; 23 import java.text.MessageFormat ; 24 import java.util.*; 25 26 import org.openide.*; 27 import org.openide.nodes.*; 28 29 import org.netbeans.lib.ddl.*; 30 import org.netbeans.lib.ddl.impl.*; 31 import org.netbeans.lib.ddl.adaptors.*; 32 import org.netbeans.modules.db.explorer.*; 33 import org.netbeans.modules.db.explorer.dlg.*; 34 import org.netbeans.modules.db.explorer.nodes.*; 35 import org.netbeans.modules.db.explorer.infos.*; 36 37 public class AddIndexAction extends DatabaseAction { 38 public void performAction (Node[] activatedNodes) { 39 Node node; 40 if (activatedNodes != null && activatedNodes.length>0) 41 node = activatedNodes[0]; 42 else 43 return; 44 45 try { 46 DatabaseNodeInfo info = (DatabaseNodeInfo)node.getCookie(DatabaseNodeInfo.class); 47 IndexListNodeInfo nfo = (IndexListNodeInfo)info.getParent(nodename); 48 49 String tablename = (String )nfo.get(DatabaseNode.TABLE); 50 String columnname = (String )nfo.get(DatabaseNode.COLUMN); 51 52 Specification spec = (Specification)nfo.getSpecification(); 53 String index = (String )nfo.get(DatabaseNode.INDEX); 54 DriverSpecification drvSpec = info.getDriverSpecification(); 55 56 Vector cols = new Vector(5); 58 59 drvSpec.getColumns(tablename, "%"); 60 ResultSet rs = drvSpec.getResultSet(); 61 HashMap rset = new HashMap(); 62 while (rs.next()) { 63 rset = drvSpec.getRow(); 64 cols.add((String ) rset.get(new Integer (4))); 65 rset.clear(); 66 } 67 rs.close(); 68 69 if (cols.size() == 0) 70 throw new Exception (bundle().getString("EXC_NoUsableColumnInPlace")); 72 AddIndexDialog dlg = new AddIndexDialog(cols, spec, info); 74 dlg.setIndexName(tablename + "_idx"); if (dlg.run()) { 76 nfo.addIndex(dlg.getIndexName()); 77 } 78 } catch(Exception exc) { 79 String message = MessageFormat.format(bundle().getString("ERR_UnableToPerformOperation"), new String [] {node.getName(), exc.getMessage()}); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE)); 81 } 82 } 83 } 84 | Popular Tags |