import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
-import eu.etaxonomy.taxeditor.preference.Resources;
import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.store.TermManager;
-import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
-import eu.etaxonomy.taxeditor.ui.element.ISelectable;
-import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
/**
- * <p>
- * Abstract AbstractTermComboElement class.
- * </p>
- *
* @author n.hoffmann
* @created Nov 5, 2009
* @version 1.0
* @param <T>
*/
public class TermComboElement<T extends DefinedTermBase>
- extends AbstractCdmFormElement implements SelectionListener,
- DisposeListener, IEnableableFormElement, ISelectable {
-
- private static final int DEFAULT_VISIBLE_ITEMS = 10;
-
- private T selection;
+ extends AbstractComboElement<T> {
private T emptyElement;
private static String EMPTY_ELEMENT_LABEL = "";
- protected Label label;
- private final Combo combo;
-
private ArrayList<T> terms;
private Comparator<T> termComparator;
private List<T> customPreferredTerms;
+ private boolean useAbbrevLabel = false;
private boolean addEmptyElement;
public TermComboElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, TermType termType, String labelString, T selection, boolean addEmptyElement,
- int style) {
- this(formFactory, parentElement, null, termType, null, labelString, selection, addEmptyElement, style);
+ int style, boolean useAbbrevLabel) {
+ this(formFactory, parentElement, null, termType, null, labelString, selection, addEmptyElement, style, useAbbrevLabel);
}
public TermComboElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, TermVocabulary<?> termVocabulary, String labelString, T selection, boolean addEmptyElement,
int style) {
- this(formFactory, parentElement, null, null, termVocabulary, labelString, selection, addEmptyElement, style);
+ this(formFactory, parentElement, null, null, termVocabulary, labelString, selection, addEmptyElement, style, false);
}
public TermComboElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, Class<T> termClass, String labelString, T selection, boolean addEmptyElement,
int style) {
- this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style);
+ this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, false);
+ }
+ public TermComboElement(CdmFormFactory formFactory,
+ ICdmFormElement parentElement, Class<T> termClass, String labelString, T selection, boolean addEmptyElement,
+ int style, boolean useAbbrevLabel) {
+ this(formFactory, parentElement, termClass, null, null, labelString, selection, addEmptyElement, style, useAbbrevLabel);
+
}
private TermComboElement(CdmFormFactory formFactory,
ICdmFormElement parentElement, Class<T> termClass, TermType termType, TermVocabulary<?> termVocabulary, String labelString, T selection, boolean addEmptyElement,
- int style) {
+ int style, boolean useAbbrevLabel) {
super(formFactory, parentElement);
this.termType = termType;
this.termVocabulary = termVocabulary;
this.termClass = termClass;
this.addEmptyElement = addEmptyElement;
-
+ this.useAbbrevLabel = useAbbrevLabel;
if (labelString != null) {
- label = formFactory.createLabel(getLayoutComposite(), labelString);
- addControl(label);
+ label.setText(labelString);
}
- // create combo
- combo = new Combo(getLayoutComposite(), SWT.BORDER | SWT.READ_ONLY );//FIXME: removed this parameter seems break windows version: | style
- addControl(combo);
- combo.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
- combo.setVisibleItemCount(DEFAULT_VISIBLE_ITEMS);
-
if(termType!=null){
//TODO try to remove generic T and avoid classes to be used
populateTerms((List<T>) getTermManager().getPreferredTerms(termType));
}
}
- /**
- * <p>
- * Getter for the field <code>selection</code>.
- * </p>
- *
- * @return a T object.
- */
- public T getSelection() {
- return selection;
- }
-
/**
* <p>Sets the selection of the combo to the given T object.</p>
* <p>Passing <code>null</code> to this method will set the selection to
* @param selection
* a T object or <code>null</code> to clear the selection
*/
- public void setSelection(T selection) {
+ @Override
+ public void setSelection(T selection) {
this.selection = selection;
Listener[] listeners = combo.getListeners(SWT.Selection);
combo.select(index);
}
- /*
- * (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.forms.IEnableableFormElement#setEnabled(boolean)
- */
- /** {@inheritDoc} */
- @Override
- public void setEnabled(boolean enabled) {
- combo.setEnabled(enabled);
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement#isEnabled()
- */
- @Override
- public boolean isEnabled() {
- return combo.isEnabled();
- }
-
- /**
- * <p>
- * preferredTerms
- * </p>
- *
- * @return a {@link java.util.List} object.
- */
protected List<T> getPreferredTerms(){
List<T> preferredTerms = new ArrayList<T>();
if (customPreferredTerms != null){
if (term == null){
return "";
}else{
- String termLabel = term.getLabel(CdmStore.getDefaultLanguage());
+ String termLabel = null;
+ if (useAbbrevLabel){
+ termLabel = term.getIdInVocabulary();
+ }else{
+ termLabel = term.getLabel(CdmStore.getDefaultLanguage());
+ }
if (termLabel == null){
termLabel = term.getLabel();
}
populateTerms(preferredTerms);
}
- /**
- * <p>
- * addSelectionListener
- * </p>
- *
- * @param listener
- * a {@link org.eclipse.swt.events.SelectionListener} object.
- */
- public void addSelectionListener(SelectionListener listener) {
- combo.addSelectionListener(listener);
- }
-
- /**
- * <p>
- * removeSelectionListener
- * </p>
- *
- * @param listener
- * a {@link org.eclipse.swt.events.SelectionListener} object.
- */
- public void removeSelectionListener(SelectionListener listener) {
- combo.removeSelectionListener(listener);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt
- * .events.SelectionEvent)
- */
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
}
- /*
- * (non-Javadoc)
- *
- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.
- * PropertyChangeEvent)
- */
/** {@inheritDoc} */
@Override
public void propertyChange(PropertyChangeEvent event) {
}
}
- /** {@inheritDoc} */
- @Override
- public void setSelected(boolean selected) {
- setBackground(selected ? SELECTED : getPersistentBackground());
- }
-
- /** {@inheritDoc} */
- @Override
- public void widgetDisposed(DisposeEvent e) {
- PreferencesUtil.getPreferenceStore().removePropertyChangeListener(this);
- }
-
- // not used
- /** {@inheritDoc} */
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- /** {@inheritDoc} */
- @Override
- public void setIrrelevant(boolean irrelevant) {
- String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT
- : Resources.COLOR_COMPOSITE_BACKGROUND;
-
- Color color = StoreUtil.getColor(colorId);
- combo.setBackground(color);
- }
-
- /** {@inheritDoc} */
- @Override
- public void setBackground(Color color) {
- if (label != null) {
- label.setBackground(color);
- }
- }
-
- /**
- *
- */
protected TermManager getTermManager() {
return CdmStore.getTermManager();
}
- /**
- *
- * @return
- */
public int getVisibleItemCount(){
return combo.getVisibleItemCount();
}
- /**
- *
- * @param count
- */
- public void setVisibleItemCount(int count){
- combo.setVisibleItemCount(count);
- }
-
/**
* <p>A {@link List} of term objects may be passed to this combo box. In this case, the default behaviour
* of displaying the preferred terms for the T type will be overridden and the combo will only display the