1 19 20 package org.netbeans.modules.html.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 41 public class HTMLPaletteActions extends PaletteActions { 42 43 44 public HTMLPaletteActions() { 45 } 46 47 public Action [] getImportActions() { 48 return new Action [0]; } 50 51 public Action [] getCustomCategoryActions(Lookup category) { 52 return new Action [0]; } 54 55 public Action [] getCustomItemActions(Lookup item) { 56 return new Action [0]; } 58 59 public Action [] getCustomPaletteActions() { 60 return new Action [0]; } 62 63 public Action getPreferredAction( Lookup item ) { 64 return new HTMLPaletteInsertAction(item); 65 } 66 67 private static class HTMLPaletteInsertAction extends AbstractAction { 68 69 private Lookup item; 70 71 HTMLPaletteInsertAction(Lookup item) { 72 this.item = item; 73 } 74 75 public void actionPerformed(ActionEvent e) { 76 77 ActiveEditorDrop drop = (ActiveEditorDrop) item.lookup(ActiveEditorDrop.class); 78 83 JTextComponent target = Utilities.getFocusedComponent(); 84 if (target == null) { 85 String 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 ioe) { 102 } 104 } 105 } 106 107 } 108 | Popular Tags |