de.jwic.controls.combo.DropDown Maven / Gradle / Ivy
/*
* Copyright 2005-2007 jWic group (http://www.jwic.de)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* de.jwic.controls.combo.DropDown
* Created on Jan 8, 2010
* $Id: DropDown.java,v 1.8 2012/11/09 16:41:22 lordsam Exp $
*/
package de.jwic.controls.combo;
import java.util.ArrayList;
import java.util.List;
import de.jwic.base.IControlContainer;
import de.jwic.base.ImageRef;
import de.jwic.data.ISelectElement;
import de.jwic.data.SelectElement;
import de.jwic.data.SelectElementBaseLabelProvider;
import de.jwic.data.SelectElementContentProvider;
/**
* Basic Drop-Down control. The content may either be added directly, to be
* stored in the control or it is provided by a custom IContentProvider.
*
* @author lippisch
*/
public class DropDown extends Combo {
private static final long serialVersionUID = 1L;
protected List elements = null; // default to null
/**
* @param container
* @param name
*/
public DropDown(IControlContainer container, String name) {
super(container, name);
baseLabelProvider = new SelectElementBaseLabelProvider();
comboBehavior.setOpenContentOnTextboxFocus(true);
comboBehavior.setSelectTextOnFocus(true);
comboBehavior.setTextEditable(true);
}
/**
* Add an element.
* @param element
*/
public void addElement(ISelectElement element) {
if (elements == null) {
elements = new ArrayList();
setContentProvider(new SelectElementContentProvider(elements));
}
elements.add(element);
}
/**
* Add an element. The key will automatically be assigned.
* @param title
*/
public ISelectElement addElement(String title) {
SelectElement elm = new SelectElement(title);
addElement(elm);
return elm;
}
/**
* Add the element with a custom key.
* @param title
* @param key
*/
public ISelectElement addElement(String title, String key) {
SelectElement elm = new SelectElement(title, key);
addElement(elm);
return elm;
}
/**
* Add the element with a custom key.
* @param title
* @param key
*/
public ISelectElement addElement(String title, String key, ImageRef image) {
SelectElement elm = new SelectElement(title, key, image);
addElement(elm);
return elm;
}
/**
* Select the element with the specified key. Works only with elements that
* do have a key.
* @param key
*/
public void selectedByKey(String key) {
if (key != null && elements != null) {
for (ISelectElement se : elements) {
if (key.equals(se.getKey())) {
setSelectedElement(se);
return;
}
}
}
setSelectedKey(null);
}
/**
*
*/
public void clear() {
if(elements != null){
elements.clear();
}
setSelectedElement(null);
requireRedraw();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy