1 19 20 21 package org.netbeans.modules.palette; 22 23 import java.awt.datatransfer.Transferable ; 24 import java.io.IOException ; 25 import javax.swing.Action ; 26 import org.netbeans.spi.palette.PaletteController; 27 import org.netbeans.spi.palette.PaletteActions; 28 import org.netbeans.spi.palette.DragAndDropHandler; 29 import org.openide.nodes.*; 30 import org.openide.util.HelpCtx; 31 import org.openide.util.Lookup; 32 import org.openide.util.datatransfer.ExTransferable; 33 import org.openide.util.datatransfer.PasteType; 34 35 40 class ItemNode extends FilterNode { 41 42 43 private Action [] actions; 44 45 public ItemNode( Node originalNode ) { 46 super( originalNode, Children.LEAF ); 47 } 48 49 public Action [] getActions(boolean context) { 50 if (actions == null) { 51 Node n = getParentNode(); 52 actions = new Action [] { 53 new Utils.CutItemAction( this ), 54 new Utils.CopyItemAction( this ), 55 new Utils.PasteItemAction( n ), 56 null, 57 new Utils.RemoveItemAction( this ), 58 null, 59 new Utils.SortItemsAction( n ), 60 null, 61 new Utils.RefreshPaletteAction() 62 }; 63 } 64 PaletteActions customActions = getCustomActions(); 65 if( null != customActions ) { 66 return Utils.mergeActions( actions, customActions.getCustomItemActions( getLookup() ) ); 67 } 68 return actions; 69 } 70 71 public Transferable clipboardCut() throws java.io.IOException { 72 ExTransferable t = ExTransferable.create( super.clipboardCut() ); 73 74 customizeTransferable( t ); 75 t.put( createTransferable() ); 76 77 return t; 78 } 79 80 public Transferable clipboardCopy() throws IOException { 81 ExTransferable t = ExTransferable.create( super.clipboardCopy() ); 82 83 customizeTransferable( t ); 84 t.put( createTransferable() ); 85 86 return t; 87 } 88 89 public PasteType getDropType( Transferable t, int action, int index ) { 90 return null; 91 } 92 93 public Transferable drag() throws IOException { 94 ExTransferable t = ExTransferable.create( super.drag() ); 96 customizeTransferable( t ); 97 t.put( createTransferable() ); 98 99 return t; 100 } 101 102 private ExTransferable.Single createTransferable() { 103 final Lookup lkp = getLookup(); 104 return new ExTransferable.Single( PaletteController.ITEM_DATA_FLAVOR ) { 105 public Object getData () { 106 return lkp; 107 } 108 }; 109 } 110 111 private void customizeTransferable( ExTransferable t ) { 112 DragAndDropHandler tp = getTransferableProvider(); 113 if( null != tp ) { 114 tp.customize( t, getLookup() ); 115 } 116 } 117 118 private PaletteActions getCustomActions() { 119 Node category = getParentNode(); 120 assert null != category; 121 Node root = category.getParentNode(); 122 assert null != root; 123 return (PaletteActions)root.getLookup().lookup( PaletteActions.class ); 124 } 125 126 private DragAndDropHandler getTransferableProvider() { 127 Node category = getParentNode(); 128 assert null != category; 129 Node root = category.getParentNode(); 130 assert null != root; 131 return (DragAndDropHandler)root.getLookup().lookup( DragAndDropHandler.class ); 132 } 133 134 public Action getPreferredAction() { 135 136 PaletteActions customActions = getCustomActions(); 137 138 if( null == customActions ) 139 return null;; 140 141 return customActions.getPreferredAction( getLookup() ); 142 } 143 144 public boolean canDestroy() { 145 146 return !Utils.isReadonly( getOriginal() ); 147 } 148 149 Node getOriginalNode() { 150 return getOriginal(); 151 } 152 153 public HelpCtx getHelpCtx() { 154 return Utils.getHelpCtx( this, super.getHelpCtx() ); 155 } 156 } 157 | Popular Tags |