blob: 280eec24862b8a1c4b495fadc6a8923898883582 [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 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.xtext.datamart.common;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.eclipse.osbp.runtime.common.event.IDualData;
import org.eclipse.osbp.ui.api.datamart.IDatamartSelectable;
import org.eclipse.osbp.ui.api.themes.EnumCssClass;
import com.vaadin.data.Container;
import com.vaadin.ui.ComboBox;
public class DatamartSingleSelect extends ComboBox implements
IDatamartSelectable {
private static final long serialVersionUID = -5673052113801450589L;
private String hierarchy = null;
private boolean slicer = false;
private IDualData firstItem = null;
public static long getSerialversionuid() {
return serialVersionUID;
}
public boolean isSlicer() {
return slicer;
}
public DatamartSingleSelect(boolean isExcept, boolean isSlicer,
Collection<IDualData> data) {
addStyleName(EnumCssClass.SINGLE_SELECTION.styleName());
slicer = isSlicer;
update(data);
}
public DatamartSingleSelect() {
}
/**
* (re)set all options visible in this box
*
* @param options
*/
public void update(Collection<IDualData> options) {
getUI().getCurrent().access(new Runnable() {
@Override
public void run() {
removeAllItems();
firstItem = null;
for (IDualData dd : options) {
setHierarchy(dd.getHierarchy());
String item = dd.getSelectionValue();
if (item != null) {
if (firstItem == null) {
firstItem = dd;
}
addItem(dd);
setItemCaption(dd, dd.getFormattedValue());
}
}
// always select the first option
setValue(firstItem);
setEnabled(true);
setNullSelectionAllowed(false);
setImmediate(true);
}
});
}
public List<IDualData> getSelectedItems() {
List<IDualData> items = new ArrayList<IDualData>();
items.add((IDualData) getValue());
return items;
}
public IDualData getFirstItem() {
return firstItem;
}
public String getHierarchy() {
return hierarchy;
}
public void setHierarchy(String hierarchy) {
this.hierarchy = hierarchy;
}
@Override
public Container getContainerDataSource() {
return super.getContainerDataSource();
}
@Override
public void select(Object obj) {
super.select(obj);
}
@Override
public void addValueChangeListener(ValueChangeListener listener) {
super.addValueChangeListener(listener);
}
@Override
public void removeValueChangeListener(ValueChangeListener listener) {
super.removeValueChangeListener(listener);
}
@Override
public void setCaption(String caption) {
super.setCaption(caption);
}
@Override
public void setDescription(String description) {
super.setDescription(description);
}
@Override
public float getHeight() {
return super.getHeight();
}
@Override
public Unit getHeightUnits() {
return super.getHeightUnits();
}
@Override
public boolean isMultiSelected() {
return false;
}
@Override
public Object getValue() {
return super.getValue();
}
}