KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > palette > JSPPaletteActions


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.web.core.palette;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.io.IOException JavaDoc;
24 import javax.swing.AbstractAction JavaDoc;
25 import javax.swing.Action JavaDoc;
26 import javax.swing.text.JTextComponent JavaDoc;
27 import org.netbeans.editor.Utilities;
28 import org.netbeans.spi.palette.PaletteActions;
29 import org.netbeans.spi.palette.PaletteController;
30 import org.openide.DialogDisplayer;
31 import org.openide.NotifyDescriptor;
32 import org.openide.text.ActiveEditorDrop;
33 import org.openide.util.Lookup;
34 import org.openide.util.NbBundle;
35
36
37
38 /**
39  *
40  * @author Libor Kotouc
41  */

42 public class JSPPaletteActions extends PaletteActions {
43     
44     /** Creates a new instance of FormPaletteProvider */
45     public JSPPaletteActions() {
46     }
47
48     public Action JavaDoc[] getImportActions() {
49         return new Action JavaDoc[0]; //TODO implement this
50
}
51
52     public Action JavaDoc[] getCustomCategoryActions(Lookup category) {
53         return new Action JavaDoc[0]; //TODO implement this
54
}
55
56     public Action JavaDoc[] getCustomItemActions(Lookup item) {
57         return new Action JavaDoc[0]; //TODO implement this
58
}
59
60     public Action JavaDoc[] getCustomPaletteActions() {
61         return new Action JavaDoc[0]; //TODO implement this
62
}
63
64     public Action JavaDoc getPreferredAction( Lookup item ) {
65         return new J2EEPaletteItemInsertAction(item);
66     }
67     
68     private static class J2EEPaletteItemInsertAction extends AbstractAction JavaDoc {
69         
70         private Lookup item;
71         
72         J2EEPaletteItemInsertAction(Lookup item) {
73             this.item = item;
74         }
75                 
76         public void actionPerformed(ActionEvent JavaDoc e) {
77       
78             ActiveEditorDrop drop = (ActiveEditorDrop) item.lookup(ActiveEditorDrop.class);
79 // if (drop == null) {
80
// String body = (String) item.lookup(String.class);
81
// drop = new JSPEditorDropDefault(body);
82
// }
83

84             JTextComponent JavaDoc target = Utilities.getFocusedComponent();
85             if (target == null) {
86                 String JavaDoc msg = NbBundle.getMessage(JSPPaletteActions.class, "MSG_ErrorNoFocusedDocument");
87                 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE));
88                 return;
89             }
90             
91             try {
92                 drop.handleTransfer(target);
93             }
94             finally {
95                 Utilities.requestFocus(target);
96             }
97             
98             try {
99                 PaletteController pc = JSPPaletteFactory.getPalette();
100                 pc.clearSelection();
101             }
102             catch (IOException JavaDoc ioe) {} //should not occur
103
}
104     }
105     
106 }
107
Popular Tags