KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > explorer > nodes > ColumnNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.db.explorer.nodes;
21
22 import java.awt.datatransfer.Transferable JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.Map JavaDoc;
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 JavaDoc name, Class JavaDoc type, String JavaDoc displayName, String JavaDoc shortDescription, DatabaseNodeInfo rep, boolean writable, boolean expert) {
43         PropertySupport ps;
44         if (name.equals("datatype")) //NOI18N
45
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 JavaDoc newname) {
53         try {
54             DatabaseNodeInfo info = getInfo();
55             String JavaDoc table = (String JavaDoc) 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 JavaDoc) info.get(DatabaseNodeInfo.SCHEMA));
60             cmd.execute();
61             super.setName(newname);
62         } catch (CommandNotSupportedException ex) {
63         } catch (Exception JavaDoc ex) {
64             ex.printStackTrace();
65         }
66     }
67
68     public Transferable JavaDoc clipboardCopy() throws IOException JavaDoc {
69         Transferable JavaDoc 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 JavaDoc 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 JavaDoc getShortDescription() {
88         return NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ND_Column"); //NOI18N
89
}
90
91     public boolean canDestroy() {
92         if (getCookie(ViewColumnNodeInfo.class) != null)
93             return false;
94         
95         Map JavaDoc removeColumnProps = (Map JavaDoc)getInfo().getSpecification().getProperties().get(Specification.REMOVE_COLUMN);
96         String JavaDoc supported = (String JavaDoc)removeColumnProps.get("Supported"); // NOI18N
97
if (supported != null) {
98             return Boolean.valueOf(supported).booleanValue();
99         }
100         return true;
101     }
102 }
103
Popular Tags