| /** |
| * |
| * 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 java.util.Set; |
| |
| import org.eclipse.e4.core.services.events.IEventBroker; |
| |
| import com.vaadin.data.Property.ValueChangeEvent; |
| import com.vaadin.data.Property.ValueChangeListener; |
| import com.vaadin.ui.ComboBox; |
| import com.vaadin.ui.VerticalLayout; |
| import com.vaadin.ui.Window; |
| |
| import org.eclipse.osbp.eventbroker.EventBrokerMsg; |
| import org.eclipse.osbp.ui.api.metadata.IDSLMetadataService; |
| |
| @SuppressWarnings("serial") |
| public class SelectUserWindow extends Window { |
| private IEventBroker eventBroker; |
| private EventBrokerMsg msg = null; |
| private String eventTarget = null; |
| private ComboBox usersCombo; |
| private String selectedUser = null; |
| |
| public SelectUserWindow(String caption, String comboCaption) { |
| super(); |
| super.setCaption(caption); |
| setClosable(false); |
| setModal(true); |
| VerticalLayout subContent = new VerticalLayout(); |
| subContent.setMargin(true); |
| setContent(subContent); |
| usersCombo = new ComboBox(comboCaption); |
| usersCombo.setNullSelectionAllowed(false); |
| usersCombo.addValueChangeListener(new ValueChangeListener() { |
| |
| @Override |
| public void valueChange(ValueChangeEvent event) { |
| selectedUser = (String)usersCombo.getValue(); |
| msg.setName(selectedUser); |
| eventBroker.send(eventTarget, msg); |
| close(); |
| } |
| }); |
| subContent.addComponent(usersCombo); |
| center(); |
| } |
| |
| public SelectUserWindow init(Set<String> users, IEventBroker eventBroker, String eventTarget) { |
| return init(users, eventBroker, eventTarget, null); |
| } |
| |
| public SelectUserWindow init(Set<String> users, IEventBroker eventBroker, String eventTarget, EventBrokerMsg msg) { |
| this.eventBroker = eventBroker; |
| this.eventTarget = eventTarget; |
| if (msg == null) { |
| this.msg = new EventBrokerMsg(null, null); |
| } else { |
| this.msg = msg; |
| } |
| usersCombo.addItems(users); |
| return this; |
| } |
| public String getSelectedUser() { |
| return selectedUser; |
| } |
| |
| public void setSelectedUser(String selectedUser) { |
| this.selectedUser = selectedUser; |
| } |
| } |
| |
| |