| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| */ |
| package org.eclipse.osbp.utils.vaadin; |
| |
| import org.eclipse.osbp.runtime.common.event.EventDispatcherEvent; |
| import org.eclipse.osbp.runtime.common.event.EventDispatcherEvent.EventDispatcherCommand; |
| import org.eclipse.osbp.runtime.common.event.EventDispatcherEvent.EventDispatcherDataTag; |
| import org.eclipse.osbp.runtime.common.event.IEventDispatcher; |
| |
| 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 YesNoDialog extends Window { //NOSONAR |
| /** |
| * |
| */ |
| private static final long serialVersionUID = 3461161019240158996L; |
| private Label label; |
| private Button yes; |
| private Button no; |
| private transient Object item; |
| private transient IEventDispatcher eventDispatcher; |
| private String sender; |
| private String topic; |
| |
| public YesNoDialog() { |
| super(); |
| setClosable(false); |
| setModal(true); |
| VerticalLayout subContent = new VerticalLayout(); |
| subContent.setMargin(true); |
| setContent(subContent); |
| label = new Label(); |
| label.addStyleName("os-querylabel"); |
| subContent.addComponent(label); |
| HorizontalLayout buttons = new HorizontalLayout(); |
| subContent.addComponent(buttons); |
| yes = new Button(); |
| yes.addClickListener(new Button.ClickListener() { |
| /** |
| * |
| */ |
| private static final long serialVersionUID = -2681219482010299972L; |
| |
| @Override |
| public void buttonClick(ClickEvent event) { |
| EventDispatcherEvent evnt = new EventDispatcherEvent(EventDispatcherCommand.YES, topic, sender); |
| evnt.addItem(EventDispatcherDataTag.OBJECT, item); |
| eventDispatcher.sendEvent(evnt); |
| } |
| }); |
| buttons.addComponent(yes); |
| no = new Button(); |
| no.addClickListener(new Button.ClickListener() { |
| /** |
| * |
| */ |
| private static final long serialVersionUID = -7307026891472599110L; |
| |
| @Override |
| public void buttonClick(ClickEvent event) { |
| EventDispatcherEvent evnt = new EventDispatcherEvent(EventDispatcherCommand.NO, topic, sender); |
| evnt.addItem(EventDispatcherDataTag.OBJECT, item); |
| eventDispatcher.sendEvent(evnt); |
| } |
| }); |
| buttons.addComponent(no); |
| center(); |
| } |
| |
| public YesNoDialog init(IEventDispatcher eventDispatcher, String sender, String topic, Object item, String messageText, String yesText, String noText) { |
| this.eventDispatcher = eventDispatcher; |
| this.item = item; |
| this.sender = sender; |
| this.topic = topic; |
| label.setCaption(messageText); |
| yes.setCaption(yesText); |
| no.setCaption(noText); |
| return this; |
| } |
| } |