01: /*
02: * SnippetsPaletteActions.java
03: *
04: * Created on August 22, 2006, 6:21 PM
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: package org.netbeans.modules.mobility.snippets;
11:
12: import java.awt.event.ActionEvent;
13: import java.io.IOException;
14: import javax.swing.AbstractAction;
15: import javax.swing.Action;
16: import javax.swing.text.JTextComponent;
17: import org.netbeans.editor.Utilities;
18: import org.netbeans.spi.palette.PaletteActions;
19: import org.netbeans.spi.palette.PaletteController;
20: import org.openide.DialogDisplayer;
21: import org.openide.NotifyDescriptor;
22: import org.openide.text.ActiveEditorDrop;
23: import org.openide.util.Lookup;
24: import org.openide.util.NbBundle;
25:
26: /**
27: *
28: * @author bohemius
29: */
30: public class SnippetsPaletteActions extends PaletteActions {
31:
32: /** Creates a new instance of SnippetsPaletteActions */
33: public SnippetsPaletteActions() {
34: }
35:
36: public Action[] getImportActions() {
37: return new Action[0]; //TODO implement this
38: }
39:
40: public Action[] getCustomCategoryActions(Lookup category) {
41: return new Action[0]; //TODO implement this
42: }
43:
44: public Action[] getCustomItemActions(Lookup item) {
45: return new Action[0]; //TODO implement this
46: }
47:
48: public Action[] getCustomPaletteActions() {
49: return new Action[0]; //TODO implement this
50: }
51:
52: public Action getPreferredAction(Lookup item) {
53: return new SnippetsPaletteInsertAction(item);
54: }
55:
56: private static class SnippetsPaletteInsertAction extends
57: AbstractAction {
58:
59: private Lookup item;
60:
61: SnippetsPaletteInsertAction(Lookup item) {
62: this .item = item;
63: }
64:
65: public void actionPerformed(ActionEvent e) {
66:
67: ActiveEditorDrop drop = (ActiveEditorDrop) item
68: .lookup(ActiveEditorDrop.class);
69:
70: JTextComponent target = Utilities.getFocusedComponent();
71: if (target == null) {
72: String msg = NbBundle.getMessage(
73: SnippetsPaletteActions.class,
74: "MSG_ErrorNoFocusedDocument");
75: DialogDisplayer.getDefault().notify(
76: new NotifyDescriptor.Message(msg,
77: NotifyDescriptor.ERROR_MESSAGE));
78: return;
79: }
80:
81: try {
82: drop.handleTransfer(target);
83: } finally {
84: Utilities.requestFocus(target);
85: }
86:
87: try {
88: PaletteController mController = SnippetsPaletteSupport
89: .getPaletteController();
90: mController.clearSelection();
91: } catch (IOException ioe) {
92: ioe.printStackTrace();
93: }
94:
95: }
96: }
97:
98: }
|