| /** |
| * |
| * 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 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| * |
| */ |
| package org.eclipse.osbp.utils.vaadin; |
| |
| import java.util.Map; |
| |
| import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; |
| 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.ComboBox; |
| import com.vaadin.ui.Label; |
| import com.vaadin.ui.VerticalLayout; |
| import com.vaadin.ui.Window; |
| |
| public class SelectDialog extends Window { //NOSONAR |
| /** |
| * |
| */ |
| private static final long serialVersionUID = 3461161019240158996L; |
| private Label label; |
| private ComboBox combo; |
| private Button ok; |
| private transient IEventDispatcher eventDispatcher; |
| private String sender; |
| private String topic; |
| |
| public SelectDialog() { |
| super(); |
| setClosable(false); |
| setModal(true); |
| VerticalLayout subContent = new VerticalLayout(); |
| subContent.setMargin(true); |
| setContent(subContent); |
| label = new Label(); |
| label.addStyleName("os-querylabel"); |
| subContent.addComponent(label); |
| combo = new ComboBox(); |
| subContent.addComponent(combo); |
| ok = new Button(); |
| ok.addClickListener(new Button.ClickListener() { |
| /** |
| * |
| */ |
| private static final long serialVersionUID = -2681219482010299972L; |
| |
| @Override |
| public void buttonClick(ClickEvent event) { |
| EventDispatcherEvent evnt = new EventDispatcherEvent(null, EventDispatcherCommand.OK, topic, sender); |
| evnt.addItem(EventDispatcherDataTag.OBJECT, combo.getValue()); |
| eventDispatcher.sendEvent(evnt); |
| } |
| }); |
| subContent.addComponent(ok); |
| center(); |
| } |
| |
| public SelectDialog init(IEventDispatcher eventDispatcher, String sender, String topic, Map<String, Object> list, Object selectedItem, String messageText, String okText) { |
| this.eventDispatcher = eventDispatcher; |
| this.sender = sender; |
| this.topic = topic; |
| label.setCaption(messageText); |
| ok.setCaption(okText); |
| for(String item:list.keySet()) { |
| combo.addItem(list.get(item)); |
| combo.setItemCaption(list.get(item), item); |
| } |
| combo.select(selectedItem); |
| return this; |
| } |
| } |