| package org.eclipse.osbp.utils.vaadin; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.eclipse.osbp.ui.api.message.IMessageRequester; |
| import org.eclipse.osbp.ui.api.message.MessageEvent; |
| import org.eclipse.osbp.ui.api.message.MessageRequesterEvent; |
| |
| import com.vaadin.ui.Button; |
| import com.vaadin.ui.Button.ClickEvent; |
| import com.vaadin.ui.HorizontalLayout; |
| import com.vaadin.ui.Label; |
| import com.vaadin.ui.VerticalLayout; |
| import com.vaadin.ui.Window; |
| |
| public class MessageDialog extends Window implements IMessageRequester { |
| /** |
| * |
| */ |
| private static final long serialVersionUID = 6245024141021744210L; |
| private String id; |
| private Label label; |
| private String message; |
| private List<IMessageRequester.ClickRecipient> recipients = new ArrayList<>(); |
| HorizontalLayout buttons = new HorizontalLayout(); |
| |
| public MessageDialog(String id, String messageText) { |
| super(); |
| this.id = id; |
| this.message = messageText; |
| setClosable(false); |
| setModal(true); |
| VerticalLayout subContent = new VerticalLayout(); |
| subContent.setWidth("300px"); |
| subContent.setHeight("200px"); |
| subContent.setMargin(true); |
| setContent(subContent); |
| label = new Label(messageText); |
| label.addStyleName("os-querylabel"); |
| subContent.addComponent(label); |
| subContent.addComponent(buttons); |
| center(); |
| } |
| |
| public String getId() { |
| return id; |
| } |
| |
| public void addButton(String buttonText, MessageEvent eventData) { |
| Button ok = new Button(buttonText); |
| ok.setData(eventData); |
| ok.addClickListener(new Button.ClickListener() { |
| /** |
| * |
| */ |
| private static final long serialVersionUID = 1407416153865271378L; |
| |
| @Override |
| public void buttonClick(ClickEvent event) { |
| for (ClickRecipient recipient : recipients) { |
| recipient.messageButtonPressed(new MessageRequesterEvent(this, getId(), (MessageEvent)event.getButton().getData())); |
| } |
| } |
| }); |
| buttons.addComponent(ok); |
| } |
| |
| @Override |
| public void addButtonListener(ClickRecipient recipient) { |
| recipients.add(recipient); |
| } |
| |
| @Override |
| public void removeButtonListener(ClickRecipient recipient) { |
| recipients.remove(recipient); |
| } |
| |
| public String getMessage() { |
| return message; |
| } |
| } |