1 19 20 package org.netbeans.modules.db.explorer.nodes; 21 22 import java.awt.datatransfer.Transferable ; 23 import java.io.IOException ; 24 import java.util.Map ; 25 import org.openide.nodes.PropertySupport; 26 import org.openide.util.Lookup; 27 import org.openide.util.NbBundle; 28 import org.openide.util.datatransfer.ExTransferable; 29 30 import org.netbeans.lib.ddl.CommandNotSupportedException; 31 import org.netbeans.lib.ddl.impl.RenameColumn; 32 import org.netbeans.lib.ddl.impl.Specification; 33 import org.netbeans.modules.db.explorer.ConnectionList; 34 import org.netbeans.modules.db.explorer.DatabaseConnection; 35 import org.netbeans.modules.db.explorer.DatabaseTypePropertySupport; 36 import org.netbeans.modules.db.explorer.DbMetaDataTransferProvider; 37 import org.netbeans.modules.db.explorer.infos.ConnectionNodeInfo; 38 import org.netbeans.modules.db.explorer.infos.DatabaseNodeInfo; 39 import org.netbeans.modules.db.explorer.infos.ViewColumnNodeInfo; 40 41 public class ColumnNode extends LeafNode { 42 protected PropertySupport createPropertySupport(String name, Class type, String displayName, String shortDescription, DatabaseNodeInfo rep, boolean writable, boolean expert) { 43 PropertySupport ps; 44 if (name.equals("datatype")) ps = new DatabaseTypePropertySupport(name, type, displayName, shortDescription, rep, writable, expert); 46 else 47 ps = super.createPropertySupport(name, type, displayName, shortDescription, rep, writable, expert); 48 49 return ps; 50 } 51 52 public void setName(String newname) { 53 try { 54 DatabaseNodeInfo info = getInfo(); 55 String table = (String ) info.get(DatabaseNode.TABLE); 56 Specification spec = (Specification) info.getSpecification(); 57 RenameColumn cmd = spec.createCommandRenameColumn(table); 58 cmd.renameColumn(info.getName(), newname); 59 cmd.setObjectOwner((String ) info.get(DatabaseNodeInfo.SCHEMA)); 60 cmd.execute(); 61 super.setName(newname); 62 } catch (CommandNotSupportedException ex) { 63 } catch (Exception ex) { 64 ex.printStackTrace(); 65 } 66 } 67 68 public Transferable clipboardCopy() throws IOException { 69 Transferable result; 70 final DbMetaDataTransferProvider dbTansferProvider = (DbMetaDataTransferProvider)Lookup.getDefault().lookup(DbMetaDataTransferProvider.class); 71 if (dbTansferProvider != null) { 72 ExTransferable exTransferable = ExTransferable.create(super.clipboardCopy()); 73 ConnectionNodeInfo cni = (ConnectionNodeInfo)getInfo().getParent(DatabaseNode.CONNECTION); 74 final DatabaseConnection dbconn = ConnectionList.getDefault().getConnection(cni.getDatabaseConnection()); 75 exTransferable.put(new ExTransferable.Single(dbTansferProvider.getColumnDataFlavor()) { 76 protected Object getData() { 77 return dbTansferProvider.createColumnData(dbconn.getDatabaseConnection(), dbconn.findJDBCDriver(), getInfo().getTable(), getInfo().getName()); 78 } 79 }); 80 result = exTransferable; 81 } else { 82 result = super.clipboardCopy(); 83 } 84 return result; 85 } 86 87 public String getShortDescription() { 88 return NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ND_Column"); } 90 91 public boolean canDestroy() { 92 if (getCookie(ViewColumnNodeInfo.class) != null) 93 return false; 94 95 Map removeColumnProps = (Map )getInfo().getSpecification().getProperties().get(Specification.REMOVE_COLUMN); 96 String supported = (String )removeColumnProps.get("Supported"); if (supported != null) { 98 return Boolean.valueOf(supported).booleanValue(); 99 } 100 return true; 101 } 102 } 103 | Popular Tags |