1 19 20 package org.netbeans.modules.db.explorer.nodes; 21 22 import java.awt.datatransfer.Transferable ; 23 import java.io.IOException ; 24 25 import java.util.*; 26 import java.text.MessageFormat ; 27 28 import org.openide.*; 29 import org.openide.util.NbBundle; 30 31 import org.netbeans.lib.ddl.*; 32 import org.netbeans.lib.ddl.impl.*; 33 import org.netbeans.modules.db.*; 34 import org.netbeans.modules.db.explorer.*; 35 import org.netbeans.modules.db.explorer.infos.*; 36 import org.openide.nodes.Node; 37 import org.openide.nodes.NodeTransfer; 38 import org.openide.util.Lookup; 39 import org.openide.util.datatransfer.ExTransferable; 40 import org.openide.util.datatransfer.PasteType; 41 42 43 45 public class ViewNode extends DatabaseNode { 46 public void setName(String newname) 47 { 48 try { 49 DatabaseNodeInfo info = getInfo(); 50 Specification spec = (Specification)info.getSpecification(); 51 AbstractCommand cmd = spec.createCommandRenameView(info.getName(), newname); 52 cmd.setObjectOwner((String )info.get(DatabaseNodeInfo.SCHEMA)); 53 cmd.execute(); 54 super.setName(newname); 55 info.put(DatabaseNode.TABLE, newname); 56 info.put(DatabaseNode.VIEW, newname); 57 } catch (CommandNotSupportedException exc) { 58 String message = MessageFormat.format(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_UnableToChangeName"), new String [] {exc.getCommand()}); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE)); 60 } catch (Exception e) { 61 e.printStackTrace(); 62 } 63 } 64 65 public String getShortDescription() { 66 return NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ND_View"); } 68 69 public Transferable clipboardCopy() throws IOException { 70 Transferable result; 71 final DbMetaDataTransferProvider dbTansferProvider = (DbMetaDataTransferProvider)Lookup.getDefault().lookup(DbMetaDataTransferProvider.class); 72 if (dbTansferProvider != null) { 73 ExTransferable exTransferable = ExTransferable.create(super.clipboardCopy()); 74 ConnectionNodeInfo cni = (ConnectionNodeInfo)getInfo().getParent(DatabaseNode.CONNECTION); 75 final DatabaseConnection dbconn = ConnectionList.getDefault().getConnection(cni.getDatabaseConnection()); 76 exTransferable.put(new ExTransferable.Single(dbTansferProvider.getViewDataFlavor()) { 77 protected Object getData() { 78 return dbTansferProvider.createViewData(dbconn.getDatabaseConnection(), dbconn.findJDBCDriver(), getInfo().getName()); 79 } 80 }); 81 result = exTransferable; 82 } else { 83 result = super.clipboardCopy(); 84 } 85 return result; 86 } 87 } 88 | Popular Tags |