diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/ExtendedCCombo.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/ExtendedCCombo.java index 75d4620d51092a3ea05645aeaa087a784966b39b..2186aeb6b02d19b476133b8dd5921b69842d1870 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/ExtendedCCombo.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/widget/ExtendedCCombo.java @@ -21,51 +21,104 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; /** - * Extention of {@link CCombo} that links the combo box entries with foreign data that can be + * Extension of {@link CCombo} that links the combo box entries with foreign data that can be * added using {@link #add(String, Object)} and queried using {@link #getObject(int)}. * - * @author diewald + * @author diewald, barner * @author $Author$ * @version $Rev$ * @ConQAT.Rating RED Hash: */ public class ExtendedCCombo<T> extends CCombo { - /** Correlates the entries in the combobox with arbitrary objects */ + /** Correlates the entries in the {@link CCombo} with arbitrary objects */ private List<T> objectReferenceList; - /** - * Constructor. - * - * A CCombo is created by this class. Additionally, the layout is defined. - */ + /** Constructs an {@link ExtendedCCombo} */ public ExtendedCCombo(Composite parent, int style) { super(parent, style); objectReferenceList = new ArrayList<T>(); + } - GridData propertyValueGridData = new GridData(); - propertyValueGridData.grabExcessHorizontalSpace = true; - propertyValueGridData.horizontalAlignment = GridData.FILL; + /** + * Adds a {@code comboString} to the {@link CCombo} and references the object + * {@code referencedObject} for this entry. + */ + public void add(String comboString, T referencedObject) { + super.add(comboString); - this.setLayoutData(propertyValueGridData); - this.setEditable(false); + objectReferenceList.add(referencedObject); } - /** Adds a String to the CCombo-box and references an Object for this entry. */ - public void add(String comboString, T referencedObject) { - if(comboString == null || comboString.isEmpty() || referencedObject == null) - return; + /** + * <p> + * {@inheritDoc} + * </p> + * <p> + * <b>NOTE:</b>This method references {@code null} with the given {@code comboString}. Use + * {@link #add(String, Object)} for actually linking an object with a given {@code comboString}. + * </p> + */ + @Override + public void add(String comboString, int index) { + super.add(comboString, index); - this.add(comboString); + objectReferenceList.add(index, null); + } - objectReferenceList.add(referencedObject); + /** + * <p> + * {@inheritDoc} + * </p> + * <p> + * <b>NOTE:</b>This method references {@code null} with the given {@code comboString}. Use + * {@link #add(String, Object)} for actually linking an object with a given {@code comboString}. + * </p> + */ + @Override + public void add(String string) { + add(string, null); + } + + /** {@inheritDoc} */ + @Override + public void removeAll() { + super.removeAll(); + objectReferenceList.clear(); + } + + /** {@inheritDoc} */ + @Override + public void remove(int index) { + super.remove(index); + objectReferenceList.remove(index); + } + + /** {@inheritDoc} */ + @Override + public void remove(int start, int end) { + super.remove(start, end); + // Elements are shifted to the left + // i <= end: super.remove() works in the range [start; end]. + for(int i = start; i <= end; i++) { + objectReferenceList.remove(start); + } + } + + /** {@inheritDoc} */ + @Override + public void remove(String string) { + int index = indexOf(string); + if(index != -1) { + super.remove(string); + objectReferenceList.remove(index); + } } - /** Returns the object(type T) stored at the given index. */ + /** Returns the object (type T) stored at the given index. */ public T getObject(int index) { return objectReferenceList.get(index); }