1 19 20 package org.netbeans.modules.web.core.palette; 21 22 import java.awt.event.ActionEvent ; 23 import java.io.IOException ; 24 import javax.swing.AbstractAction ; 25 import javax.swing.Action ; 26 import javax.swing.text.JTextComponent ; 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 42 public class JSPPaletteActions extends PaletteActions { 43 44 45 public JSPPaletteActions() { 46 } 47 48 public Action [] getImportActions() { 49 return new Action [0]; } 51 52 public Action [] getCustomCategoryActions(Lookup category) { 53 return new Action [0]; } 55 56 public Action [] getCustomItemActions(Lookup item) { 57 return new Action [0]; } 59 60 public Action [] getCustomPaletteActions() { 61 return new Action [0]; } 63 64 public Action getPreferredAction( Lookup item ) { 65 return new J2EEPaletteItemInsertAction(item); 66 } 67 68 private static class J2EEPaletteItemInsertAction extends AbstractAction { 69 70 private Lookup item; 71 72 J2EEPaletteItemInsertAction(Lookup item) { 73 this.item = item; 74 } 75 76 public void actionPerformed(ActionEvent e) { 77 78 ActiveEditorDrop drop = (ActiveEditorDrop) item.lookup(ActiveEditorDrop.class); 79 84 JTextComponent target = Utilities.getFocusedComponent(); 85 if (target == null) { 86 String 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 ioe) {} } 104 } 105 106 } 107 | Popular Tags |