Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<reactome.web.carrousel>1.0.2</reactome.web.carrousel>
<reactome.web.diagram>3.6.7</reactome.web.diagram>
<reactome.web.fireworks>1.8.6</reactome.web.fireworks>
<reactome.web.model>2.1.20</reactome.web.model>
<reactome.web.model>2.1.21-SNAPSHOT</reactome.web.model>
<reactome.web.pdb>2.3.1</reactome.web.pdb>
<reactome.web.chebi>1.2.0</reactome.web.chebi>
<reactome.web.rhea>1.3.1</reactome.web.rhea>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/reactome/web/pwp/client/AppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
import org.reactome.web.pwp.client.tools.analysis.AnalysisLauncher;
import org.reactome.web.pwp.client.tools.analysis.AnalysisLauncherDisplay;
import org.reactome.web.pwp.client.tools.analysis.AnalysisLauncherPresenter;
import org.reactome.web.pwp.client.tools.citation.CitationLauncher;
import org.reactome.web.pwp.client.tools.citation.CitationLauncherDisplay;
import org.reactome.web.pwp.client.tools.citation.CitationLauncherPresenter;
import org.reactome.web.pwp.client.tools.launcher.ToolLauncher;
import org.reactome.web.pwp.client.tools.launcher.ToolLauncherDisplay;
import org.reactome.web.pwp.client.tools.launcher.ToolLauncherPresenter;
Expand Down Expand Up @@ -207,6 +210,10 @@ private void initialiseDetailsTabsList(){
private void initialiseTools(){
AnalysisLauncher.Display analysisDisplay = new AnalysisLauncherDisplay();
new AnalysisLauncherPresenter(this.eventBus, analysisDisplay);

CitationLauncher.Display citationDisplay = new CitationLauncherDisplay();
new CitationLauncherPresenter(this.eventBus, citationDisplay);

}

private void printMessage(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
public enum PathwayPortalTool {

NONE ("XX", "No Tool"),
ANALYSIS ("AT", "Analysis Tool");
ANALYSIS ("AT", "Analysis Tool"),
CITATION ("CT", "Cite Us!");

private String code;
private String title;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.reactome.web.pwp.client.tools.citation;

import org.reactome.web.pwp.client.common.module.BrowserModule;

/**
* @author Yusra Haider <yhaider@ebi.ac.uk>
*/

public interface CitationLauncher {

interface Presenter extends BrowserModule.Presenter {
void displayClosed();
}

interface Display extends BrowserModule.Display {
void hide();

void center();

void show();

void setPresenter(CitationLauncher.Presenter presenter);

void setCitation(String citation);

void setExportBar(String id);
}
}





Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
package org.reactome.web.pwp.client.tools.citation;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.*;
import org.reactome.web.pwp.client.tools.launcher.LauncherButton;

import java.util.Date;

public class CitationLauncherDisplay extends PopupPanel implements CitationLauncher.Display, CloseHandler<PopupPanel>,
ResizeHandler {

private CitationLauncher.Presenter presenter;
private Label citation;
private HorizontalPanel buttonBar;
private Label buttonBarHeading;

public CitationLauncherDisplay() {
super(true, true);
setAnimationEnabled(true);
setGlassEnabled(true);
setAutoHideOnHistoryEventsEnabled(false);
addStyleName(RESOURCES.getCSS().popupPanel());
Window.addResizeHandler(this);

int width = (int) Math.round(Window.getClientWidth() * 0.9);
int height = (int) Math.round(Window.getClientHeight() * 0.9);
this.setWidth(width + "px");
this.setHeight(height + "px");

FlowPanel mainPanel = new FlowPanel(); // Main panel
mainPanel.addStyleName(RESOURCES.getCSS().mainPanel());
mainPanel.add(setTitlePanel()); // Title panel with heading & close button

FlowPanel citationPanel = new FlowPanel(); // panel that will contain the citation text
citationPanel.addStyleName(RESOURCES.getCSS().citationPanel());
citation = new Label();
citation.addStyleName(RESOURCES.getCSS().citationText());
citationPanel.add(citation);
mainPanel.add(citationPanel);

buttonBarHeading = new Label();
buttonBarHeading.addStyleName(RESOURCES.getCSS().buttonHeading());
mainPanel.add(buttonBarHeading);

buttonBar = new HorizontalPanel(); // panel with all the export buttons
FlowPanel buttonPanel = new FlowPanel();
buttonPanel.addStyleName(RESOURCES.getCSS().buttonPanel());
buttonPanel.add(buttonBar);
mainPanel.add(buttonPanel);
this.addCloseHandler(this);
this.add(mainPanel);
}

@Override
public void show() {
super.show();
}

public void setCitation(String citation) {
this.citation.setText(citation);
}

@Override
public void onClose(CloseEvent<PopupPanel> event) {
presenter.displayClosed();
buttonBar = new HorizontalPanel();
}

@Override
public void onResize(ResizeEvent event) {
if (isVisible()) {
int width = (int) Math.round(RootLayoutPanel.get().getOffsetWidth() * 0.9);
int height = (int) Math.round(RootLayoutPanel.get().getOffsetHeight() * 0.9);
this.setWidth(width + "px");
this.setHeight(height + "px");
}
}

@Override
public void setPresenter(CitationLauncher.Presenter presenter) {
this.presenter = presenter;
}

// sets the panel title and close button
private Widget setTitlePanel() {
FlowPanel header = new FlowPanel();
header.setStyleName(RESOURCES.getCSS().header());
header.addStyleName(RESOURCES.getCSS().unselectable());
Label title = new Label("Cite Us!");
title.setStyleName(RESOURCES.getCSS().headerText());
Button closeBtn = new LauncherButton("Close citation modal", RESOURCES.getCSS().close(), clickEvent -> CitationLauncherDisplay.this.hide());
header.add(title);
header.add(closeBtn);
return header;
}

public void setExportBar(String id) {
this.buttonBarHeading.setText("Download As: ");
for (ExportType ef : ExportType.values()) {
this.buttonBar.add(getExportButton(ef.getIcon(), ef.getTitle(), ef.getUrl() + "&id=" + id
+ "&dateAccessed=" + DateTimeFormat.getFormat("E MMM dd yyyy").format(new Date()),
"reactome_citation_" + id + ef.getExt()));
}
}

public FlowPanel getExportButton(ImageResource icon, String title, String url, String filename) {

FlowPanel button = new FlowPanel();
button.addStyleName(RESOURCES.getCSS().exportItem());
button.setTitle(title);

FlowPanel image = new FlowPanel();
image.add(new Image(icon));

Anchor anchor = new Anchor(SafeHtmlUtils.fromTrustedString(image.toString()), url, "_blank");
anchor.getElement().setAttribute("rel", "noindex,nofollow");
anchor.getElement().setAttribute("download", filename);

button.add(anchor);

return button;
}

public static CitationLauncherDisplay.Resources RESOURCES;

static {
RESOURCES = GWT.create(CitationLauncherDisplay.Resources.class);
RESOURCES.getCSS().ensureInjected();
}

/**
* A ClientBundle of resources used by this widget.
*/
public interface Resources extends ClientBundle {
/**
* The styles used in this widget.
*/
@Source(CitationLauncherDisplay.ResourceCSS.CSS)
CitationLauncherDisplay.ResourceCSS getCSS();

@Source("images/close_clicked.png")
ImageResource closeClicked();

@Source("images/close_hovered.png")
ImageResource closeHovered();

@Source("images/close_normal.png")
ImageResource closeNormal();
}

/**
* Styles used by this widget.
*/
@CssResource.ImportedWithPrefix("pwp-CitationLauncher")
public interface ResourceCSS extends CssResource {
/**
* The path to the default CSS styles used by this resource.
*/
String CSS = "org/reactome/web/pwp/client/tools/citation/CitationLauncher.css";

String popupPanel();

String mainPanel();

String citationPanel();

String header();

String headerText();

String citationText();

String close();

String unselectable();

String buttonPanel();

String exportItem();

String buttonHeading();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.reactome.web.pwp.client.tools.citation;

import com.google.gwt.event.shared.EventBus;
import org.reactome.web.pwp.client.common.PathwayPortalTool;
import org.reactome.web.pwp.client.common.events.BrowserReadyEvent;
import org.reactome.web.pwp.client.common.events.StateChangedEvent;
import org.reactome.web.pwp.client.common.events.ToolSelectedEvent;
import org.reactome.web.pwp.client.common.handlers.BrowserReadyHandler;
import org.reactome.web.pwp.client.common.module.AbstractPresenter;
import org.reactome.web.pwp.model.client.common.ContentClientHandler;
import org.reactome.web.pwp.model.client.content.ContentClient;
import org.reactome.web.pwp.model.client.content.ContentClientError;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;


public class CitationLauncherPresenter extends AbstractPresenter implements CitationLauncher.Presenter, BrowserReadyHandler {

private CitationLauncher.Display display;
private static final Map<String, String> CITATIONS;
private static final String PATHWAY_ANALYSIS_CITATION_ID = "28249561";
private static final String DIAGRAM_VIEWER_CITATION_ID = "29186351";

static {
Map<String, String> citations = new HashMap<>();
citations.put("28249561", "Fabregat A, Sidiropoulos K, Viteri G, Forner O, Marin-Garcia P, Arnau V, D'Eustachio P, Stein L, Hermjakob H. Reactome pathway analysis: a high-performance in-memory approach. BMC Bioinformatics. 2017 Mar 2;18(1):142. doi: 10.1186/s12859-017-1559-2. PubMed PMID: 28249561");
citations.put("29186351", "Fabregat A, Sidiropoulos K, Viteri G, Marin-Garcia P, Ping P, Stein L, D'Eustachio P, Hermjakob H. Reactome diagram viewer: data structures and strategies to boost performance. Bioinformatics. 2018 Apr 1;34(7):1208-1214. doi: 10.1093/bioinformatics/btx752. PubMed PMID: 29186351");
CITATIONS = Collections.unmodifiableMap(citations);
}


public CitationLauncherPresenter(EventBus eventBus, CitationLauncher.Display display) {
super(eventBus);
this.display = display;
this.display.setPresenter(this);
this.eventBus.addHandler(BrowserReadyEvent.TYPE, this);
}

@Override
public void displayClosed() {
this.eventBus.fireEventFromSource(new ToolSelectedEvent(PathwayPortalTool.NONE), this);
}

@Override
public void onBrowserReady(BrowserReadyEvent event) {
// do your stuff
}

@Override
public void onStateChanged(StateChangedEvent event) {
PathwayPortalTool tool = event.getState().getTool();
if (tool.equals(PathwayPortalTool.CITATION)) {
if (event.getState().getAnalysisStatus().getToken() != null) getCitation(PATHWAY_ANALYSIS_CITATION_ID);
else getCitation(DIAGRAM_VIEWER_CITATION_ID);
} else {
display.hide();
}
}

private void showDisplay() {
display.show();
display.center();
}

private void getCitation(String id) {
ContentClient.getStaticCitation(id, new ContentClientHandler.Citation() {
@Override
public void onCitationTextLoaded(String citation) {
// happy flow
display.setCitation(citation);
// call method for including the export buttons on display
display.setExportBar(id);
showDisplay();
}

@Override
public void onContentClientException(Type type, String message) {
display.setCitation(CITATIONS.get(id));
showDisplay();
//TODO add code for showing banner
}

@Override
public void onContentClientError(ContentClientError error) {
display.setCitation(CITATIONS.get(id));
showDisplay();
//TODO add code for showing banner
}
});
}

}


Loading