Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Introduction to the Context Menu API

The goal of this quickstart is to introduce you to the the context menu api, so you will be able to add context menu extensions in your IGB Apps. 

Getting Started

What is a context menu?

Info
titleWikipedia

"A context menu (also called contextual, shortcut, and popup or pop-up menu) is a menu in a graphical user interface (GUI) that appears upon user interaction, such as a right-click mouse operation. A context menu offers a limited set of choices that are available in the current state, or context, of the operating system or application. Usually the available choices are actions related to the selected object."

Example Context Menu on OS X 10.9

Image Modified

IGB Context Menu

Image Modified

 

Design

...

Context Menu API Overview

Image Added

 

Interface

Code Block
themeMidnight
package org.lorainelab.igb.context.menumenu.api;

import java.util.List;
import java.util.Optional;
import org.lorainelab.igb.context.menu.api.model.AnnotationContextEvent;
import org.lorainelab.igb.contextmenu.menuapi.model.ContextMenuItem;

/**
 *
 * @author dcnorris
 */
public interface AnnotationContextMenuProvider {public interface AnnotationContextMenuProvider {
   
    public Optional<ContextMenuItem>Optional<List<ContextMenuItem>> buildMenuItem(AnnotationContextEvent event);
    public MenuSection getMenuSection();
}}

Data Model

AnnotationContextEvent

Code Block
themeMidnight
package org.lorainelab.igb.contextmenu.menuapi.model;
import com.affymetrix.genometry.symmetry.impl.SeqSymmetry;
import java.util.List;
/**
public *
class *AnnotationContextEvent @author dcnorris{
 */
public class AnnotationContextEvent {
    private final List<SeqSymmetry> selectedItems;
    public AnnotationContextEvent(List<SeqSymmetry> selectedItems) {
        this.selectedItems = selectedItems;
    }

    public List<SeqSymmetry> getSelectedItems() {
        return selectedItems;
    }
}

ContextMenuItem

Code Block
themeMidnight
package org.lorainelab.igb.context.menu.api.quickstartmodel;

import aQutejava.bnd.annotation.component.Componentutil.Set;
import java.util.function.OptionalFunction;
import org.lorainelab.igb.context.menu.AnnotationContextMenuProvider;
import org.lorainelab.igb.context.menu.MenuSection;
import org.lorainelab.igb.context.menu.model.AnnotationContextEvent;
import org.lorainelab.igb.context.menu.model.ContextMenuItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 *
 * @author dcnorris
 */
@Component(immediate = true)
public class ContextMenuExtension implements AnnotationContextMenuProvider 
public class ContextMenuItem extends MenuItem {
    private ContextMenuSection menuSection = ContextMenuSection.APP;
    public ContextMenuItem(String menuLabel, Set<MenuItem> subMenuItems) {
    private static final Logger logger = LoggerFactory.getLogger(ContextMenuExtension.classsuper(menuLabel, subMenuItems);
    @Override}
    public Optional<ContextMenuItem> buildMenuItem(AnnotationContextEvent eventContextMenuItem(String menuLabel, Function<Void, Void> action) {
        ContextMenuItem contextMenuItem = new ContextMenuItem("Log Selection ids", (Void t) -> {
   super(menuLabel, action);
    }
    public void setMenuSection(ContextMenuSection menuSection) {
         event.getSelectedItems().stream().map(selectedSym -> selectedSym.getID()).forEach(logger::info)this.menuSection = menuSection;
    }
    public ContextMenuSection   return t;getMenuSection() {
        });
        return Optional.ofNullable(contextMenuItem)return menuSection;
    }
    @Override
    public MenuSection getMenuSection() {
        return MenuSection.INFORMATION;
    }
}

MenuIcon

Code Block
themeMidnight
package org.lorainelab.igb.context.menu.model;
import com.google.common.io.BaseEncoding;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 *
 * @author dcnorris
 */
public class MenuIcon}

MenuIcon

Code Block
themeMidnight
package org.lorainelab.igb.menu.api.model;
import com.google.common.io.BaseEncoding;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class MenuIcon {
    private String encodedImage;
    private static final Logger logger = LoggerFactory.getLogger(MenuIcon.class);
    public MenuIcon(InputStream resourceAsStream) {
        try {
    private  String encodedImage;
    private static final Logger logger = LoggerFactory.getLogger(MenuIcon.class);
    public MenuIcon(InputStream resourceAsStreamencodedImage = BaseEncoding.base64().encode(IOUtils.toByteArray(resourceAsStream));
        } catch (Exception ex) {
        try {
   logger.error(ex.getMessage(), ex);
        encodedImage = BaseEncoding.base64().encode(IOUtils.toByteArray(resourceAsStream));}
    }
    }public catchbyte[] getEncodedImage(Exception ex) {
        return    logger.error(ex.getMessage(), ex);
    BaseEncoding.base64().decode(encodedImage);
    }
    }
    public byte[] getEncodedImage()
ContextMenuSection
Code Block
themeMidnight
package org.lorainelab.igb.menu.api.model;

public enum ContextMenuSection {
    INFORMATION,
    return BaseEncoding.base64().decode(encodedImage);SEQUENCE,
    }
}

...

APP,
    UI_ACTION;
}

Context Menu Sections

Image Added

Context Menu Quickstart Code

ContextMenuExtension

Code Block
themeMidnight
package org.lorainelab.igb.context.menu.api.quickstart;
/**
 *
 * @author dcnorris
 */
public enum MenuSection {
    INFORMATION, SEQUENCE, APP, UI_ACTION;
}

Context Menu Sections

Image Removed

pom.xml

Code Block
themeMidnight
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.affymetrix</groupId>
        <artifactId>igb-project</artifactId>
        <version>9.0.0</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    <groupId>org.lorainelab.igb</groupId>
    <artifactId>context-menu-api</artifactId>
    <packaging>bundle</packaging>
    <name>Context Menu API</name>
    
    <dependencies>
        <dependency>
import aQute.bnd.annotation.component.Component;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.lorainelab.igb.menu.api.AnnotationContextMenuProvider;
import org.lorainelab.igb.menu.api.model.AnnotationContextEvent;
import org.lorainelab.igb.menu.api.model.ContextMenuItem;
import org.lorainelab.igb.menu.api.model.ContextMenuSection;
import org.lorainelab.igb.menu.api.model.MenuIcon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(immediate = true)
public class ContextMenuExtension implements AnnotationContextMenuProvider {
    private static final Logger LOG = LoggerFactory.getLogger(ContextMenuExtension.class);
    private static final String ICONPATH = "terminal.png";
    @Override
    public Optional<List<ContextMenuItem>> buildMenuItem(AnnotationContextEvent event) {
        ContextMenuItem contextMenuItem = new ContextMenuItem("Log Selection ids", (Void t) -> {
            event.getSelectedItems().stream().map(selectedSym -> selectedSym.getID()).forEach(LOG::info);
              <groupId>biz.aQute.bnd</groupId>return t;
        });
    <artifactId>bndlib</artifactId>
    try (InputStream resourceAsStream = ContextMenuExtension.class.getClassLoader().getResourceAsStream(ICONPATH)) {
    <scope>provided</scope>
         </dependency>contextMenuItem.setMenuIcon(new MenuIcon(resourceAsStream));
        <dependency>} catch (Exception ex) {
            <groupId>com.affymetrix</groupId>LOG.error(ex.getMessage(), ex);
            <artifactId>genometry</artifactId>}
            <scope>provided</scope>contextMenuItem.setMenuSection(ContextMenuSection.INFORMATION);
        </dependency>  return Optional.ofNullable(Arrays.asList(contextMenuItem));
        <dependency>
            <groupId>com.affymetrix</groupId>
            <artifactId>igb-services</artifactId>}
}

pom.xml

Code Block
themeMidnight
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            <scope>provided</scope>
        </dependency>      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
        <dependency><parent>
            <groupId>com.google.guava<<groupId>org.lorainelab.igb</groupId>
            <artifactId>guava<<artifactId>igb-project</artifactId>
        <version>9.0.0</version>
    <scope>provided<</scope>parent>
    <groupId>org.lorainelab.igb</groupId>
    </dependency><artifactId>org.lorainelab.igb.menu.api.quickstart</artifactId>
    <version>1.0.0</version>
    <!--Start of logging dependencies--><packaging>bundle</packaging>
    <name>Context Menu Extension Quickstart</name>
    
    <dependencies>
        <dependency>
            <groupId>org<groupId>biz.aQute.slf4j<bnd</groupId>
            <artifactId>slf4j-api<<artifactId>bndlib</artifactId>
            <scope>provided</scope>
        </dependency>
        <!--End of logging dependencies--><dependency>
        <dependency>
            <groupId>com.affymetrix<<groupId>org.lorainelab.igb</groupId>
            <artifactId>affymetrix-common<<artifactId>genometry</artifactId>
            <scope>provided</scope>
         </dependency>  
        </dependency>!--Start of logging dependencies-->
        <dependency>
            <groupId>commons-io<<groupId>org.slf4j</groupId>
            <artifactId>commons<artifactId>slf4j-io<api</artifactId>
            <scope>provided</scope>       
        </dependency>
    </dependencies>
    <build>
   <!--End of logging dependencies-->
      <plugins>
    <dependency>
        <plugin>
    <groupId>org.lorainelab.igb</groupId>
            <artifactId>maven-clean-plugin<<artifactId>org.lorainelab.igb.menu.api</artifactId>
            <<scope>provided</plugin>scope>
        </dependency>
    <plugin></dependencies>
    <build>
        <plugins>
    <groupId>org        <plugin>
                <groupId>org.apache.maven.plugins<felix</groupId>
                <artifactId>maven-dependencybundle-plugin</artifactId>
                <<extensions>true</plugin>extensions>
           
     <executions>
       <plugin>
             <execution>
   <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
     <id>build plugin repository</id>
         <extensions>true</extensions>
               <goals>
 <configuration>
                    <instructions>
       <goal>
                 <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
               index
         <Import-Package>*</Import-Package>
                   </goal>     <Export-Package>
                  
          ${project.groupId}.context.menu,
                </goals>
            ${project.groupId}.context.menu.model
             <phase>package</phase>
           </Export-Package>
             <configuration>
           <Service-Component>*</Service-Component>
                 <obrRepository>${project.build.directory}</obrRepository>   </instructions> 
                </configuration>
            <mavenRepository>${project.build.directory}</mavenRepository>                    </plugin>  
          </plugins>
       </build>
</project>

       </configuration>
                    </execution>
                </executions>
                <configuration>
                    <instructions>
                       <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Import-Package>*</Import-Package>
                        <Export-Package/>
                        <Service-Component>*</Service-Component>
                        <Bundle-Description>${bundleDescription}</Bundle-Description>
                    </instructions>
                </configuration>
            </plugin>     
            <plugin>
                <groupId>org.lorainelab</groupId>
                <artifactId>bundle-markdown-encoder</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>encodeMarkdown</goal>
                        </goals>
                    </execution> 
                </executions>
                <configuration>
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                </configuration>
            </plugin>       
        </plugins>
    </build>
</project>

(Optional) Add README.md

Add a README.md markdown file to the root of the project for a customized APP manager display of your new app.

Example

Code Block
themeMidnight
# Context Menu API Quickstart
A small example context menu extension that logs the ids of all selected SeqSymmetry objects

```java
package org.lorainelab.igb.context.menu.api.quickstart;
import aQute.bnd.annotation.component.Component;
import java.io.InputStream;
import java.util.Optional;
import org.lorainelab.igb.context.menu.AnnotationContextMenuProvider;
import org.lorainelab.igb.context.menu.MenuSection;
import org.lorainelab.igb.context.menu.model.AnnotationContextEvent;
import org.lorainelab.igb.context.menu.model.ContextMenuItem;
import org.lorainelab.igb.context.menu.model.MenuIcon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 *
 * @author dcnorris
 */
@Component(immediate = true)
public class ContextMenuExtension implements AnnotationContextMenuProvider {
    private static final Logger logger = LoggerFactory.getLogger(ContextMenuExtension.class);
    private static final String ICONPATH = "terminal.png";
    @Override
    public Optional<ContextMenuItem> buildMenuItem(AnnotationContextEvent event) {
        ContextMenuItem contextMenuItem = new ContextMenuItem("Log Selection ids", (Void t) -> {
            event.getSelectedItems().stream().map(selectedSym -> selectedSym.getID()).forEach(logger::info);
            return t;
        });
        try (InputStream resourceAsStream = ContextMenuExtension.class.getClassLoader().getResourceAsStream(ICONPATH)) {
            contextMenuItem.setMenuIcon(new MenuIcon(resourceAsStream));
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
        return Optional.ofNullable(contextMenuItem);
    }
    @Override
    public MenuSection getMenuSection() {
        return MenuSection.INFORMATION;
    }
}
```

 

Building the Example

Code Block
mvn clean install
  • The build process will result in a new folder being added into your project directory (i.e. the target folder)
  • Add the target directory as a new IGB App repository
    • IGB App Manger Tab -> Launch App Manager -> Manage Repositories -> Add...
      • Image Added
      • Image Added
    • Select and add the target directory
    • Use the IGB App Manager to Install the new plugin
      • Image Added

 

Results

 

Image Added