/** * */ package org.gcube.portlets.user.speciesdiscovery.client.window; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.ControlGroup; import com.github.gwtbootstrap.client.ui.Form; import com.github.gwtbootstrap.client.ui.TextArea; import com.github.gwtbootstrap.client.ui.constants.ResizeType; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.Widget; /** * The Class DialogInfo. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jan 12, 2017 */ public abstract class MessageForm extends Composite { /** * */ private static final String LOADING_DEFAULT_MSG = "Loading..."; @UiField TextArea text_info; @UiField Button close_dialog; @UiField Form form_info; @UiField ControlGroup text_info_group; @UiField FlowPanel loading_field; @UiField HorizontalPanel hp_form_actions; private Label loadingLabel = new Label(); private static AbstractFormReleaseUiBinder uiBinder = GWT.create(AbstractFormReleaseUiBinder.class); private int width = 400; /** * Close handler. */ public abstract void closeHandler(); /** * The Interface AbstractFormReleaseUiBinder. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jan 12, * 2017 */ interface AbstractFormReleaseUiBinder extends UiBinder { } /** * Instantiates a new dialog info. * * @param waiting * the waiting * @param msgWaiting * the msg waiting */ public MessageForm(boolean waiting, String msgWaiting) { initDialog(); if (waiting) { showWaiting(msgWaiting); } } /** * Instantiates a new dialog info. * * @param msgInfo * the msg info */ public MessageForm(String msgInfo) { initDialog(); setTextMessage(msgInfo, true); } /** * Inits the dialog. */ private void initDialog() { initWidget(uiBinder.createAndBindUi(this)); setWaitingMessageVisible(false); text_info.setWidth(width - 10 + "px"); text_info.setReadOnly(true); text_info.setResize(ResizeType.VERTICAL); close_dialog.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { closeHandler(); } }); hp_form_actions.setCellHorizontalAlignment( close_dialog, HasHorizontalAlignment.ALIGN_RIGHT); } /** * Inits the waiting. * * @param msg * the msg */ private void showWaiting(String msg) { HorizontalPanel hp = new HorizontalPanel(); loadingLabel.getElement().getStyle().setMarginBottom(2, Unit.PX); loadingLabel.getElement().getStyle().setMarginRight(2, Unit.PX); // loadingLabel.setClose(false); msg = msg == null || msg.isEmpty() ? LOADING_DEFAULT_MSG : msg; loadingLabel.setText(msg); HTML imgLoading = new HTML( ""); loading_field.add(imgLoading); setWaitingMessageVisible(true); hp.add(loadingLabel); hp.add(imgLoading); loading_field.add(hp); } /** * Sets the waiting alert visible. * * @param bool * the new waiting alert visible */ public void setWaitingMessageVisible(boolean bool) { loading_field.setVisible(bool); // text_info.setEnabled(!bool); } /** * Sets the text message. * * @param msg * the msg * @param hideLoadingAlertIfShown * the hide loading alert if shown */ public void setTextMessage(String msg, boolean hideLoadingAlertIfShown) { if (hideLoadingAlertIfShown) setWaitingMessageVisible(false); else setWaitingMessageVisible(true); text_info.getElement().getStyle().setBackgroundColor("#fcfcfc"); text_info.setText(msg); //text_info.setVisible(true); text_info.setFocus(true); text_info.selectAll(); //markText(text_info.getElement()); } }