KickJava   Java API By Example, From Geeks To Geeks.

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


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
25 import java.util.*;
26 import java.text.MessageFormat JavaDoc;
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 // Node for Table/View/Procedure things.
44

45 public class ViewNode extends DatabaseNode {
46     public void setName(String JavaDoc 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 JavaDoc)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 JavaDoc message = MessageFormat.format(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("EXC_UnableToChangeName"), new String JavaDoc[] {exc.getCommand()}); // NOI18N
59
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE));
60         } catch (Exception JavaDoc e) {
61             e.printStackTrace();
62         }
63     }
64
65     public String JavaDoc getShortDescription() {
66         return NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ND_View"); //NOI18N
67
}
68
69     public Transferable JavaDoc clipboardCopy() throws IOException JavaDoc {
70         Transferable JavaDoc 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 JavaDoc 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