SHARE
TWEET

Untitled

fpuga Jul 24th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package es.icarto.gvsig.example;
  2.  
  3. import org.gvsig.andami.PluginServices;
  4. import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
  5. import org.gvsig.app.project.documents.view.toc.ITocItem;
  6. import org.gvsig.fmap.mapcontext.layers.FLayer;
  7. import org.gvsig.tools.ToolsLocator;
  8. import org.gvsig.tools.extensionpoint.ExtensionPoint;
  9. import org.gvsig.tools.extensionpoint.ExtensionPointManager;
  10. import org.gvsig.i18n.Messages;
  11. import org.gvsig.raster.fmap.layers.FLyrRaster;
  12.  
  13.  
  14. public class Example extends Extension {
  15.  
  16.     private final class MyTOCMenuItem extends AbstractTocContextMenuAction {
  17.         public static final String EXTENSION_POINT_NAME = "MyTOCMenuItem";
  18.         public static final String DESCRIPTION = "A nice description";
  19.        
  20.         // Check interface IContextMenuAction for more customization options like
  21.         // set the group or the order in which the item will appear in the TOC
  22.        
  23.         @Override
  24.         public String getText() {
  25.             return Messages.getText("_toc_menu_item");
  26.         }
  27.        
  28.         @Override
  29.         public void execute(ITocItem item, FLayer[] selectedItems) {
  30.             System.out.println("It works!");
  31.         }
  32.        
  33.         @Override
  34.         public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
  35.             return true;
  36.         }
  37.        
  38.         @Override
  39.         public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
  40.             System.out.println("It's visible");
  41.             return oneAndOnlyOneRasterActive(selectedItems);
  42.         }
  43.        
  44.         private boolean oneAndOnlyOneRasterActive(FLayer[] selectedItems) {
  45.             if (selectedItems.length == 1) {
  46.                 for (FLayer flayer : selectedItems) {
  47.                     if (flayer instanceof FLyrRaster) {
  48.                         return true;
  49.                     }
  50.                 }
  51.             }
  52.             return false;
  53.         }
  54.     }
  55.    
  56.     @Override
  57.     public void initialize() {
  58.         // "View_TocActions" harcoded name used to add actions to the TOC.
  59.         // ToolsLocator.getExtensionPointManager().get("View_TocActions") can be also used, but you can safely call
  60.         // add() more than one time, so it ensures that if your code is called before another this extension
  61.         // point will exists
  62.         ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add("View_TocActions", "");
  63.         exPoint.append(MyTOCMenuItem.EXTENSION_POINT_NAME,  MyTOCMenuItem.DESCRIPTIONnew MyTOCMenuItem());
  64.     }
  65.  
  66.     @Override
  67.     public void execute(String actionCommand) {
  68.         System.out.println("Executing extension");
  69.     }
  70.    
  71.     @Override
  72.     public boolean isVisible() {
  73.         return true;
  74.     }
  75.    
  76.     @Override
  77.     public boolean isEnabled() {
  78.         return true;
  79.     }
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top