Page tree

Versions Compared

Key

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

...

Context Menu API Overview

Image RemovedImage Added

Interface

Code Block
themeMidnight
package org.lorainelab.igb.context.menu;
import java.util.List;
import java.util.Optional;
import org.lorainelab.igb.context.menu.model.AnnotationContextEvent;
import org.lorainelab.igb.context.menu.model.ContextMenuItem;

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

...

Code Block
themeMidnight
package org.lorainelab.igb.context.menu.model;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import org.lorainelab.igb.context.menu.MenuSection;
/**
 *
 * @author dcnorris
 */
public class ContextMenuItem {
    private final String menuLabel;
    private MenuIcon menuIcon;
    private Function<Void, Void> action;
    private Set<ContextMenuItem> subMenuItems;
    private int weight = 0;
    private MenuSection menuSection = MenuSection.APP;
    public ContextMenuItem(String menuLabel, Set<ContextMenuItem> subMenuItems) {
        checkNotNull(menuLabel);
        checkNotNull(subMenuItems);
        checkState(!Strings.isNullOrEmpty(menuLabel));
        checkState(!subMenuItems.isEmpty());
        this.menuLabel = menuLabel;
        this.subMenuItems = ImmutableSet.copyOf(subMenuItems);
    }
    public ContextMenuItem(String menuLabel, Function<Void, Void> action) {
        checkNotNull(menuLabel);
        checkState(!Strings.isNullOrEmpty(menuLabel));
        checkNotNull(action);
        this.menuLabel = menuLabel;
        this.action = action;
        subMenuItems = ImmutableSet.of();
    }
    public String getMenuLabel() {
        return menuLabel;
    }
    public Function<Void, Void> getAction() {
        return action;
    }
    public Set<ContextMenuItem> getSubMenuItems() {
        return subMenuItems;
    }
    public voidint setWeightgetWeight(int weight) {
        this.weight =return weight;
    }
    public void setMenuIconsetWeight(MenuIconint menuIconweight) {
        this.menuIconweight = menuIconweight;
    }
    public Optional<MenuIcon>void getMenuIconsetMenuIcon(MenuIcon menuIcon) {
        return Optional.ofNullable(menuIcon)this.menuIcon = menuIcon;
    }
    public Optional<MenuIcon> getMenuIcon() {
        return Optional.ofNullable(menuIcon);
    }
    public void setMenuSection(MenuSection menuSection) {
        this.menuSection = menuSection;
    }
    public MenuSection getMenuSection() {
        return menuSection;
    }
}




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 {
    private String encodedImage;
    private static final Logger logger = LoggerFactory.getLogger(MenuIcon.class);
    public MenuIcon(InputStream resourceAsStream) {
        try {
            encodedImage = BaseEncoding.base64().encode(IOUtils.toByteArray(resourceAsStream));
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
    public byte[] getEncodedImage() {
        return BaseEncoding.base64().decode(encodedImage);
    }
}

...

Code Block
themeMidnight
package org.lorainelab.igb.context.menu.api.quickstart;
import aQute.bnd.annotation.component.Component;
import java.io.InputStream;
import aQutejava.bnd.annotation.component.Componentutil.Arrays;
import java.ioutil.InputStreamList;
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>Optional<List<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 OptionalcontextMenuItem.ofNullablesetMenuSection(contextMenuItemMenuSection.INFORMATION);
    }
    @Override
    public MenuSection getMenuSection() {
        return MenuSection.INFORMATIONreturn Optional.ofNullable(Arrays.asList(contextMenuItem));
    }
}



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>
            <groupId>biz.aQute.bnd</groupId>
            <artifactId>bndlib</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.affymetrix</groupId>
            <artifactId>genometry</artifactId>
            <scope>provided</scope>
        </dependency>  
        <dependency>
            <groupId>com.affymetrix</groupId>
            <artifactId>igb-services</artifactId>
            <scope>provided</scope>
        </dependency>      
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <scope>provided</scope>
        </dependency>
        <!--Start of logging dependencies-->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <!--End of logging dependencies-->
        <dependency>
            <groupId>com.affymetrix</groupId>
            <artifactId>affymetrix-common</artifactId>
            <scope>provided</scope>           
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <scope>provided</scope>       
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
            </plugin>          
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Import-Package>*</Import-Package>
                        <Export-Package>
                            ${project.groupId}.context.menu,
                            ${project.groupId}.context.menu.model
                        </Export-Package>
                        <Service-Component>*</Service-Component>
                    </instructions>
                </configuration>
            </plugin>  
        </plugins>
    </build>
</project>

...