KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > palette > ActiveEditorDropProvider


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.palette;
21
22 import org.openide.ErrorManager;
23 import org.openide.text.ActiveEditorDrop;
24 import org.openide.util.Lookup;
25 import org.openide.util.lookup.InstanceContent;
26
27 /**
28  *
29  * @author Libor Kotouc
30  */

31 class ActiveEditorDropProvider implements InstanceContent.Convertor<String JavaDoc,ActiveEditorDrop> {
32
33     private static ActiveEditorDropProvider instance = new ActiveEditorDropProvider();
34
35     /** Creates a new instance of ActiveEditorDropProvider */
36     private ActiveEditorDropProvider() {
37     }
38
39     static ActiveEditorDropProvider getInstance() {
40         return instance;
41     }
42     
43     public Class JavaDoc<? extends ActiveEditorDrop> type(String JavaDoc obj) {
44         //able to convert String instances only
45
return ActiveEditorDrop.class;
46     }
47
48     public String JavaDoc id(String JavaDoc obj) {
49         return obj;
50     }
51
52     public String JavaDoc displayName(String JavaDoc obj) {
53         return obj;
54     }
55
56     public ActiveEditorDrop convert(String JavaDoc obj) {
57         return getActiveEditorDrop(obj);
58     }
59     
60     private ActiveEditorDrop getActiveEditorDrop(String JavaDoc instanceName) {
61
62         ActiveEditorDrop drop = null;
63
64         if (instanceName != null && instanceName.trim().length() > 0) {//we should try to instantiate item drop
65
try {
66                 ClassLoader JavaDoc loader = (ClassLoader JavaDoc)Lookup.getDefault().lookup(ClassLoader JavaDoc.class);
67                 if (loader == null)
68                     loader = getClass ().getClassLoader ();
69                 Class JavaDoc instanceClass = loader.loadClass (instanceName);
70                 drop = (ActiveEditorDrop)instanceClass.newInstance();
71             }
72             catch (Exception JavaDoc ex) {
73                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
74             }
75         }
76
77         return drop;
78     }
79     
80 }
81
Popular Tags