KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > html > palette > HTMLPaletteActions


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.html.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  * @author Libor Kotouc
40  */

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

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

104         }
105     }
106     
107 }
108
Popular Tags