Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
de.swm.commons.mobile.client.utils.SwmPopupUtilImpl Maven / Gradle / Ivy
package de.swm.commons.mobile.client.utils;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.*;
import de.swm.commons.mobile.client.SWMMobile;
import de.swm.commons.mobile.client.base.PanelBase;
import de.swm.commons.mobile.client.constants.I18NConstants;
import de.swm.commons.mobile.client.event.FastClickHelper;
import de.swm.commons.mobile.client.theme.SWMMobileImageBundle;
import de.swm.commons.mobile.client.widgets.Button;
import de.swm.commons.mobile.client.widgets.*;
import de.swm.commons.mobile.client.widgets.HorizontalPanel;
import de.swm.commons.mobile.client.widgets.command.CommandPopup;
import de.swm.gwt.client.interfaces.ITypedAction;
import java.util.*;
/**
* Hilfsklasse um ein popup fenser anzuzeigen.
*
* @author wiese.daniel
* copyright (C) 2012, SWM Services GmbH
*/
public class SwmPopupUtilImpl implements ISwmPopupUtil {
/**
* Erstellt ein HTML-Widget, welches Freizeichen zwischen Komponenten erstellt.
*/
private final SWMMobileImageBundle images = SWMMobile.getTheme().getMGWTImageBundle();
private final I18NConstants appConstants = GWT.create(I18NConstants.class);
@Override
public void showPopup(String header, String text) {
showPopup(false, header, text, null);
}
@Override
public void showPopup(boolean hasCancelButton, String header, String text, final ClickHandler okClickHanlder) {
List texts = new ArrayList();
texts.add(text);
showPopup(hasCancelButton, header, texts, okClickHanlder, null);
}
@Override
public void showPopup(boolean hasCancelButton, String header, List texts,
final ClickHandler okClickHanlder) {
showPopup(hasCancelButton, header, texts, okClickHanlder, null);
}
@Override
public void showPopup(boolean hasCancelButton, String header, String text, final ClickHandler okClickHanlder,
final ClickHandler cancelClickHanlder) {
List texts = new ArrayList();
texts.add(text);
showPopup(hasCancelButton, header, texts, appConstants.confirmButton(), appConstants.cancelButton(),
okClickHanlder, cancelClickHanlder);
}
@Override
public void showPopup(boolean hasCancelButton, String header, List texts, final ClickHandler okClickHanlder,
final ClickHandler cancelClickHanlder) {
showPopup(hasCancelButton, header, texts, appConstants.confirmButton(), appConstants.cancelButton(),
okClickHanlder, cancelClickHanlder);
}
@Override
public void showPopupYesNo(boolean hasCancelButton, String header, String text, final ClickHandler okClickHanlder,
final ClickHandler cancelClickHanlder) {
showPopup(hasCancelButton, header, text, appConstants.yesButton(), appConstants.noButton(), okClickHanlder,
cancelClickHanlder);
}
@Override
public void showPopup(boolean hasCancelButton, String header, String text,
String popupOkText, String popupCancelText, final ClickHandler okClickHanlder,
final ClickHandler cancelClickHanlder) {
List texts = new ArrayList();
texts.add(text);
showPopup(hasCancelButton, header, texts, popupOkText, popupCancelText, okClickHanlder, cancelClickHanlder);
}
@Override
public void showMultiButtonPopup(String header, List texts, List> buttonDesciptors) {
List textlabels = new ArrayList();
if (texts != null) {
for (String text : texts) {
textlabels.add(new Label(text));
}
}
// Sorieren der Buttons
Collections.sort(buttonDesciptors);
HorizontalPanel hp = new HorizontalPanel();
final CommandPopup commandPopup = new CommandPopup(header, this.images.information(),
getWidgetArray(textlabels, hp));
for (final ItemDesciptor buttonDesciptor : buttonDesciptors) {
Button button = new Button();
button.setText(buttonDesciptor.getText());
FastClickHelper.addClickHandler(button, new FastClickHelper.FastClickHandler() {
@Override
public void onFastClick(FastClickHelper.FastClickEvent event) {
commandPopup.hide();
buttonDesciptor.getAction().execute(buttonDesciptor.getType());
}
});
hp.add(button);
hp.add(createHtmlSpacer());
}
commandPopup.showCentered(true);
}
@Override
public CommandPopup buildMultiWidgetPopup(String header, Widget... widgets) {
return new CommandPopup(header, this.images.information(), widgets);
}
@Override
public void showListPopup(String header, final List listItemDesciptors) {
final DropDownList dropDownList = new DropDownList();
dropDownList.getElement().getStyle().setProperty("margin", "10px");
final Map keyValueMap = new HashMap();
for (ItemDesciptor descriptor : listItemDesciptors) {
keyValueMap.put(descriptor.getText(), descriptor.getAction());
dropDownList.add(new DropDownItem(descriptor.getText(), descriptor.getText()));
}
HTMLPanel panel = new HTMLPanel("");
panel.add(dropDownList);
HorizontalPanel hp = new HorizontalPanel();
Button cancel = new Button(appConstants.cancelButton());
cancel.getElement().getStyle().setProperty("margin", "10px");
hp.add(cancel);
hp.getElement().getStyle().setTextAlign(Style.TextAlign.CENTER);
Widget[] widgets = new Widget[2];
widgets[0] = panel;
widgets[1] = hp;
final CommandPopup popup = new CommandPopup(header, this.images.information(), widgets);
FastClickHelper.addClickHandler(cancel, new FastClickHelper.FastClickHandler() {
@Override
public void onFastClick(FastClickHelper.FastClickEvent event) {
popup.hide();
}
});
dropDownList.addValueChangeHandler(new ValueChangeHandler() {
@Override
public void onValueChange(ValueChangeEvent stringValueChangeEvent) {
String value = stringValueChangeEvent.getValue();
keyValueMap.get(value).execute(value);
popup.hide();
}
});
popup.showCentered(true);
}
/**
* Erzeugt immer einen nuen HTML-Spacer.
*
* @return .
*/
private HTML createHtmlSpacer() {
return new HTML(" ");
}
@Override
public StatusPopupHandler showStatusPopup(String header, List texts) {
List textlabels = new ArrayList();
for (String text : texts) {
textlabels.add(new Label(text));
}
HorizontalPanel statusPanel = new HorizontalPanel();
statusPanel.add(new Image(SWMMobile.getTheme().getMGWTImageBundle().loading()));
statusPanel.add(this.createHtmlSpacer());
final Label label = new Label();
statusPanel.add(label);
final CommandPopup commandPopup = new CommandPopup(header, this.images.information(),
getWidgetArray(textlabels, statusPanel));
commandPopup.showCentered(true);
return new StatusPopupHandler() {
@Override
public void changeStatus(String statusDescription) {
label.setText(statusDescription);
}
@Override
public void cancelStatusPopup() {
commandPopup.hide();
}
};
}
/**
* Die Defauls-showPopap-Implementierung.
*
* @param hasCancelButton .
* @param header .
* @param texts .
* @param popupOkText .
* @param popupCancelText .
* @param okClickHanlder .
* @param cancelClickHanlder .
*/
private void showPopup(boolean hasCancelButton, String header, List texts,
String popupOkText, String popupCancelText, final ClickHandler okClickHanlder,
final ClickHandler cancelClickHanlder) {
List textlabels = new ArrayList();
for (String text : texts) {
textlabels.add(new Label(text));
}
Button okButton = new Button();
Button cancelButton = new Button();
okButton.setText(popupOkText);
HorizontalPanel hp = new HorizontalPanel();
hp.add(okButton);
if (hasCancelButton) {
hp.add(createHtmlSpacer());
cancelButton.setText(popupCancelText);
hp.add(cancelButton);
}
final Widget[] widgets = getWidgetArray(textlabels, hp);
final CommandPopup commandPopup = new CommandPopup(header, images.information(), widgets);
FastClickHelper.addClickHandler(okButton, new FastClickHelper.FastClickHandler() {
@Override
public void onFastClick(FastClickHelper.FastClickEvent event) {
commandPopup.hide();
if (okClickHanlder != null) {
okClickHanlder.onClick(null);
}
}
});
if (hasCancelButton) {
FastClickHelper.addClickHandler(cancelButton, new FastClickHelper.FastClickHandler() {
@Override
public void onFastClick(FastClickHelper.FastClickEvent event) {
commandPopup.hide();
if (cancelClickHanlder != null) {
cancelClickHanlder.onClick(null);
}
}
});
}
commandPopup.showCentered(true);
}
/**
* Erzeugt ein Widget Array aus den übergebenen Widgets.
*
* @param labels eine liste von Labels
* @param panel das Panel für die Buttons
* @return alle zusammen als Array
*/
private Widget[] getWidgetArray(List labels, PanelBase panel) {
Widget[] result = new Widget[labels.size() + 1];
int i;
for (i = 0; i < labels.size(); i++) {
result[i] = labels.get(i);
}
result[i] = panel;
return result;
}
}