package org.gcube.portlets.user.gcubeloggedin.client.ui; import org.gcube.portlets.user.gcubeloggedin.client.LoggedinServiceAsync; import org.gcube.portlets.user.gcubeloggedin.shared.VObject; import org.gcube.portlets.user.gcubeloggedin.shared.VREClient; import org.gcube.portlets.widgets.sessionchecker.client.CheckSession; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Heading; import com.github.gwtbootstrap.client.ui.Hero; import com.github.gwtbootstrap.client.ui.Image; import com.github.gwtbootstrap.client.ui.Paragraph; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window.Location; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Widget; public class AboutView extends Composite { private static int MAX_CHAR_DESC = 400; private static String SEE_LESS = "See less"; private static String SEE_MORE = "See more"; private static AboutViewUiBinder uiBinder = GWT .create(AboutViewUiBinder.class); interface AboutViewUiBinder extends UiBinder { } public AboutView() { initWidget(uiBinder.createAndBindUi(this)); } private WarningAlert wa; private String vreDescription; @UiField Image vreImage; @UiField Heading vreName; @UiField HTML description; @UiField Button seeMore; @UiField Button leaveButton; @UiField Hero mainPanel; private LoggedinServiceAsync loggedinService; public AboutView(VObject vobj, LoggedinServiceAsync loggedinService) { initWidget(uiBinder.createAndBindUi(this)); this.loggedinService = loggedinService; this.vreDescription = vobj.getDescription(); vreName.setText(vobj.getName()); vreImage.setUrl(vobj.getImageURL()); String desc = vreDescription = vobj.getDescription(); if (desc.length() > MAX_CHAR_DESC) { desc = desc.substring(0, MAX_CHAR_DESC) + " ..."; //description.getElement().setInnerHTML(desc); description.setHTML(desc); description.addStyleName("vre-description"); seeMore.setVisible(true); seeMore.setText(SEE_MORE); } if (vobj instanceof VREClient && !vobj.isMandatory()) { leaveButton.setVisible(true); wa = new WarningAlert("Are you sure you want to leave this group? " + "By leaving this group you will no longer receive updates and lose the workspace folder related to the group.", this); } else { //remove the login button Scheduler.get().scheduleDeferred(new Command() { public void execute () { DOM.getElementById("removable-item-li").removeFromParent(); } }); } } boolean open = false; @UiHandler("seeMore") void onSeemore(ClickEvent e) { GWT.log(seeMore.getText()); if (!open) { description.setHTML(vreDescription); seeMore.setText(SEE_LESS); open = true; } else { description.setHTML(vreDescription.substring(0, MAX_CHAR_DESC) + " ..."); seeMore.setText(SEE_MORE); open = false; } } @UiHandler("leaveButton") void onUnsubscribe(ClickEvent e) { mainPanel.add(wa); } protected void abandonGroup() { mainPanel.remove(wa); final Widget loading = getLoadingHTML(); mainPanel.add(loading); loggedinService.removeUserFromVRE(new AsyncCallback() { @Override public void onSuccess(String result) { if (result != null) Location.assign(result); else CheckSession.showLogoutDialog(); } @Override public void onFailure(Throwable caught) { mainPanel.remove(loading); Window.alert("We're sorry we couldn't reach the server, try again later ... " + caught.getMessage()); } }); } /** * * @return */ public static Widget getLoadingHTML() { return new LoadingText(); } }