package org.gcube.portlets.user.reportgenerator.client.targets; import org.gcube.portlets.user.reportgenerator.client.ReportGenerator; import org.gcube.portlets.user.reportgenerator.client.Presenter.Presenter; import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem; import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExternalImage; import com.extjs.gxt.ui.client.widget.Component; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HasAlignment; import com.google.gwt.user.client.ui.HasVerticalAlignment; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; /** * DroppingArea class is a Widget you can drop image on * * @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it * @version May 20012 (3.5) */ public class DroppingArea extends Component { private String expectedContent = ""; private VerticalPanel mainPanel; private Image droppedImage; private Presenter presenter; private String idInBasket; private String currentUser; private String currentScope; Label label; private int width, height; /** * @param presenter . * @param width . * @param height . * @param tag the label to display */ public DroppingArea(Presenter presenter, int width, int height, String tag) { if (tag.equals("")) { tag = "No suggestions available"; } this.width = width; this.height = height; this.presenter = presenter; mainPanel = new VerticalPanel(); super.setWidth(width+"px"); super.setHeight(height+"px"); mainPanel.setWidth(width+"px"); mainPanel.setHeight(height+"px"); setElement(mainPanel.getElement()); addStyleName("droppingArea-Image"); mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); label = new Label(tag); label.addStyleName("label"); mainPanel.add(label); droppedImage = null; } public void add(Widget w) { mainPanel.add(w); } /** * called when dropped an image on the area * @param toShow the image to show */ public void showImage(Image toShow) { //mainPanel.remove(label); mainPanel.clear(); this.droppedImage = toShow; toShow.setPixelSize(width, height); mainPanel.add(toShow); presenter.storeChangeInSession(this); } /** * * @param url . * @param id the id in the folder */ public void dropImage(String url, String id) { GWT.log("URL:" + url, null); idInBasket = id; showImage(new Image(url)); } public void fetchImage(String identifier, boolean isInteralImage, boolean fullDetails) { this.mask("fetching image, pleas wait", "loading-indicator"); ReportGenerator.get().getWSTreeService().getImageById(identifier, isInteralImage, fullDetails, new AsyncCallback() { public void onSuccess(GWTWorkspaceItem result) { unmask(); GWTExternalImage image = (GWTExternalImage) result; dropImage(image.getImageUrl(), image.getId()); } public void onFailure(Throwable caught) { unmask(); Window.alert("Could not fetch image from infrastructure " + caught.getCause()); } }); } /** * * @return the image */ public Image getDroppedImage() { if (droppedImage == null) return new Image(); return droppedImage; } /** * * @return the possible content */ public Label getLabel() { return label; } /** * * @param label set the label */ public void setLabel(Label label) { this.label = label; } /** * return a URL which is lookable for on the web * @param imageName . * @param templateName . * @return . */ public String getImageURL(String imageName, String templateName) { currentUser = presenter.getCurrentUser().getUsername(); currentScope = presenter.getCurrentScope(); /** * Images will be stored under webapps/usersArea... * GWT.getModuleBaseURL() returns * e.g. http://dlib28.isti.cnr.it/templatecreator/html/ * need to get just http://dlib28.isti.cnr.it/ */ //remove "/html/" and get e.g. http://dlib28.isti.cnr.it/templatecreator String host = GWT.getModuleBaseURL().substring(0, GWT.getModuleBaseURL().length()-6); //loog for last slash int lastSlash = host.lastIndexOf("/"); //get what i need : e.g. http://dlib28.isti.cnr.it/ or host = "http://localhost:8080/"; host = host.substring(0, lastSlash +1 ); //host = "http://localhost:8080/"; String imgURL = host + "usersArea/" + currentScope + "/templates/" + currentUser + "/CURRENT_OPEN/images/" + imageName; return imgURL; } /** * * @return . */ public String getIdInBasket() { return idInBasket; } /** * * @param idInBasket . */ public void setIdInBasket(String idInBasket) { this.idInBasket = idInBasket; } /** * * @return expectedContent */ public String getExpectedContent() { return expectedContent; } /** * * @param expectedContent . */ public void setExpectedContent(String expectedContent) { this.expectedContent = expectedContent; if (expectedContent.compareTo("") != 0) label.setText(expectedContent); } }