blob: c057bc6980e578e9d3fd28cd9aba1b1d44d2d13e [file] [log] [blame]
/**
*
* 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.Map;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.osbp.eventbroker.EventBrokerMsg;
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 {
/**
*
*/
private static final long serialVersionUID = 3461161019240158996L;
private IEventBroker eventBroker;
private Label label;
private ComboBox combo;
private Button ok;
private String uuid;
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) {
if(eventBroker!=null) {
EventBrokerMsg msg = new EventBrokerMsg(EventBrokerMsg.QUERY_OK);
msg.setName((String) combo.getValue());
eventBroker.send(EventBrokerMsg.QUERY_ANSWER+uuid, msg);
}
}
});
subContent.addComponent(ok);
center();
}
public SelectDialog init(IEventBroker eventBroker, Map<String, String> list, String selectedItem, String messageText, String okText, String uuid) {
this.eventBroker = eventBroker;
this.uuid = uuid;
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;
}
}