From 20ebc923cc36d47fbfd41f70b231cd97716f3c0d Mon Sep 17 00:00:00 2001 From: Patric Plitzner Date: Wed, 30 Oct 2013 09:11:04 +0000 Subject: [PATCH] - created utility method in AbstractUtility for sorting/ordering IEnumTerms according to the term hierarchy - used method for EnumComboElement and OccurenceCreator (fixes #3736) --- .../entitycreator/OccurrenceCreator.java | 62 +---- .../taxeditor/model/AbstractUtility.java | 222 +++++++++++++----- .../taxeditor/ui/combo/EnumComboElement.java | 70 +++--- 3 files changed, 204 insertions(+), 150 deletions(-) diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/entitycreator/OccurrenceCreator.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/entitycreator/OccurrenceCreator.java index 3796a11f4..4c4e12549 100644 --- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/entitycreator/OccurrenceCreator.java +++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/entitycreator/OccurrenceCreator.java @@ -10,13 +10,9 @@ package eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator; -import java.util.Comparator; -import java.util.LinkedHashMap; +import java.util.Arrays; +import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; import org.apache.log4j.Logger; import org.eclipse.core.runtime.IStatus; @@ -27,6 +23,7 @@ import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator; import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil; +import eu.etaxonomy.taxeditor.model.AbstractUtility; import eu.etaxonomy.taxeditor.newWizard.NewDerivedUnitBaseWizard; /** @@ -77,56 +74,9 @@ public class OccurrenceCreator implements */ @Override public Map getKeyLabelPairs() { - Comparator comparator = new Comparator() { - @Override - public int compare(Object o1, Object o2) { - String key1 = ((SpecimenOrObservationType)o1).getKey(); - String key2 = ((SpecimenOrObservationType)o2).getKey(); - return key1.compareTo(key2); - } - }; - Map result = new LinkedHashMap(); - - Map> typeHierarchy = new TreeMap>(comparator); - - for(SpecimenOrObservationType sooType : SpecimenOrObservationType.values()) { - Set childList = new TreeSet(comparator); - // add root element as keys - if(sooType.getKindOf()==null){ - typeHierarchy.put(sooType, childList); - } - // add child element to topmost parent i.e. root - else{ - SpecimenOrObservationType root = getRootFor(sooType); - if(typeHierarchy.containsKey(root)){ - typeHierarchy.get(root).add(sooType); - } - else{ - childList.add(sooType); - typeHierarchy.put(root, childList); - } - } - } - - // create list according to the type hierarchy (root elements alphabetically with recursive children also alphabetically) - for(Entry> entry:typeHierarchy.entrySet()){ - SpecimenOrObservationType root = entry.getKey(); - result.put(root, root.getMessage()); - for(SpecimenOrObservationType child:entry.getValue()){ - result.put(child, " - " + child.getMessage()); - } - } - return result; - } - - private SpecimenOrObservationType getRootFor(SpecimenOrObservationType type){ - SpecimenOrObservationType parent = type.getKindOf(); - if(parent==null){ - return type; - } - else{ - return getRootFor(type.getKindOf()); - } + Map keyLabelPairs = new HashMap(); + keyLabelPairs.putAll(AbstractUtility.orderTerms(Arrays.asList(SpecimenOrObservationType.values()))); + return keyLabelPairs; } @Override diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java index 308d27587..5ad338254 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java @@ -1,9 +1,9 @@ // $Id$ /** * Copyright (C) 2007 EDIT - * European Distributed Institute of Taxonomy + * European Distributed Institute of Taxonomy * http://www.e-taxonomy.eu - * + * * The contents of this file are subject to the Mozilla Public License Version 1.1 * See LICENSE.TXT at the top of this package for the full license terms. */ @@ -11,6 +11,14 @@ package eu.etaxonomy.taxeditor.model; import java.lang.reflect.InvocationTargetException; +import java.util.Collection; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; import org.apache.log4j.Logger; import org.eclipse.core.commands.ExecutionException; @@ -49,6 +57,7 @@ import org.eclipse.ui.progress.IWorkbenchSiteProgressService; import org.eclipse.ui.themes.ITheme; import org.eclipse.ui.themes.IThemeManager; +import eu.etaxonomy.cdm.model.common.IEnumTerm; import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; @@ -60,7 +69,7 @@ import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart; *

* Abstract AbstractUtility class. *

- * + * * @author n.hoffmann * @created 11.05.2009 * @version 1.0 @@ -74,7 +83,7 @@ public abstract class AbstractUtility { *

* closeAll *

- * + * * @return a boolean. */ public static boolean closeAll() { @@ -83,7 +92,7 @@ public abstract class AbstractUtility { /** * Close the given editor. - * + * * @param editor * The MultipageTaxonEditor to close. * @return true on success @@ -96,7 +105,7 @@ public abstract class AbstractUtility { *

* getShell *

- * + * * @return a {@link org.eclipse.swt.widgets.Shell} object. */ public static Shell getShell() { @@ -109,7 +118,7 @@ public abstract class AbstractUtility { *

* getActivePage *

- * + * * @return a {@link org.eclipse.ui.IWorkbenchPage} object. */ public static IWorkbenchPage getActivePage() { @@ -122,7 +131,7 @@ public abstract class AbstractUtility { *

* getActivePart *

- * + * * @return a {@link org.eclipse.ui.IWorkbenchPart} object. */ public static IWorkbenchPart getActivePart() { @@ -137,7 +146,7 @@ public abstract class AbstractUtility { *

* getWorkbenchWindow *

- * + * * @return a {@link org.eclipse.jface.window.ApplicationWindow} object. */ public static ApplicationWindow getWorkbenchWindow() { @@ -151,7 +160,7 @@ public abstract class AbstractUtility { *

* showView *

- * + * * @param id * a {@link java.lang.String} object. * @return a {@link org.eclipse.ui.IViewPart} object. @@ -171,7 +180,7 @@ public abstract class AbstractUtility { *

* hideView *

- * + * * @param view * a {@link org.eclipse.ui.IViewPart} object. */ @@ -184,7 +193,7 @@ public abstract class AbstractUtility { *

* getView *

- * + * * @param id * a {@link java.lang.String} object. * @param restore @@ -206,7 +215,7 @@ public abstract class AbstractUtility { *

* getService *

- * + * * @param api * a {@link java.lang.Class} object. * @return a {@link java.lang.Object} object. @@ -219,7 +228,7 @@ public abstract class AbstractUtility { *

* getCurrentTheme *

- * + * * @return a {@link org.eclipse.ui.themes.ITheme} object. */ public static ITheme getCurrentTheme() { @@ -232,7 +241,7 @@ public abstract class AbstractUtility { * Fonts registered to the plugin may be obtained with the Eclipse themeing * functionality. Thus fonts are chooseable by the user via * Preferences->General->Appearance->Colors and Fonts - * + * * @return the FontRegistry for the current theme */ public static FontRegistry getFontRegistry() { @@ -243,7 +252,7 @@ public abstract class AbstractUtility { *

* getFont *

- * + * * @param symbolicName * a {@link java.lang.String} object. * @return a {@link org.eclipse.swt.graphics.Font} object. @@ -256,7 +265,7 @@ public abstract class AbstractUtility { * Color registered to the plugin may be obtained with the Eclipse themeing * functionality. Thus colors are editable by the user via * Preferences->General->Appearance->Colors and Fonts - * + * * @return the ColorRegistry for the current theme */ public static ColorRegistry getColorRegistry() { @@ -267,7 +276,7 @@ public abstract class AbstractUtility { *

* getColor *

- * + * * @param symbolicName * a {@link java.lang.String} object. * @return a {@link org.eclipse.swt.graphics.Color} object. @@ -279,7 +288,7 @@ public abstract class AbstractUtility { /** * Open a message box that informs the user about unimplemented * functionality. This method is for developer convenience. - * + * * @param source * a {@link java.lang.Object} object. */ @@ -292,7 +301,7 @@ public abstract class AbstractUtility { *

* informationDialog *

- * + * * @param title * a {@link java.lang.String} object. * @param message @@ -302,7 +311,8 @@ public abstract class AbstractUtility { final String message) { Display.getDefault().asyncExec(new Runnable() { - public void run() { + @Override + public void run() { MessageDialog.openInformation(getShell(), title, message); } }); @@ -312,12 +322,12 @@ public abstract class AbstractUtility { final IStatus status) { informationDialog(title, status.getMessage()); } - + /** *

* warningDialog *

- * + * * @param title * The dialogs title * @param source @@ -329,7 +339,8 @@ public abstract class AbstractUtility { final String message) { Display.getDefault().asyncExec(new Runnable() { - public void run() { + @Override + public void run() { MessageDialog.openWarning(getShell(), title, message); Class clazz = source != null ? source .getClass() : AbstractUtility.class; @@ -337,7 +348,7 @@ public abstract class AbstractUtility { } }); } - + /** * @param title * @param termBase @@ -352,7 +363,7 @@ public abstract class AbstractUtility { *

* errorDialog *

- * + * * @param title * The dialogs title * @param source @@ -368,7 +379,8 @@ public abstract class AbstractUtility { final String message, final Throwable t) { Display.getDefault().asyncExec(new Runnable() { - public void run() { + @Override + public void run() { MessageDialog.openError(getShell(), title, message + getCauseRecursively(t)); Class clazz = source != null ? source .getClass() : this.getClass(); @@ -379,7 +391,7 @@ public abstract class AbstractUtility { if(t == null){ return null; } - + if(t.getCause() != null){ return getCauseRecursively(t.getCause()); }else{ @@ -389,7 +401,7 @@ public abstract class AbstractUtility { } }); } - + public static void errorDialog(final String title, final Object source, final String message){ errorDialog(title, source, message, null); @@ -399,7 +411,7 @@ public abstract class AbstractUtility { *

* errorDialog *

- * + * * @param title * a {@link java.lang.String} object. * @param source @@ -411,7 +423,8 @@ public abstract class AbstractUtility { final IStatus status) { Display.getDefault().asyncExec(new Runnable() { - public void run() { + @Override + public void run() { MessageDialog.openError(getShell(), title, status.getMessage()); Class clazz = source != null ? source .getClass() : this.getClass(); @@ -424,7 +437,7 @@ public abstract class AbstractUtility { *

* confirmDialog *

- * + * * @param title * a {@link java.lang.String} object. * @param message @@ -439,7 +452,7 @@ public abstract class AbstractUtility { *

* executeOperation *

- * + * * @param operation * a * {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation} @@ -457,7 +470,8 @@ public abstract class AbstractUtility { IRunnableWithProgress runnable = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(operation.getLabel(), 100); IStatus status = Status.CANCEL_STATUS; @@ -470,7 +484,7 @@ public abstract class AbstractUtility { } finally { monitor.done(); } - + String statusString = status.equals(Status.OK_STATUS) ? "completed" : "cancelled"; setStatusLine(operation.getLabel() + " " + statusString + "."); @@ -527,7 +541,7 @@ public abstract class AbstractUtility { *

* getOperationHistory *

- * + * * @return a {@link org.eclipse.core.commands.operations.IOperationHistory} * object. */ @@ -539,14 +553,15 @@ public abstract class AbstractUtility { *

* setStatusLine *

- * + * * @param message * a {@link java.lang.String} object. */ public static void setStatusLine(final String message) { Display.getDefault().asyncExec(new Runnable() { - public void run() { + @Override + public void run() { statusLineManager.setMessage(message); } @@ -558,7 +573,7 @@ public abstract class AbstractUtility { *

* getMonitor *

- * + * * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object. */ public static IProgressMonitor getMonitor() { @@ -569,7 +584,7 @@ public abstract class AbstractUtility { /** * Starts either the given {@link IProgressMonitor} if it's not * null or a new {@link NullProgressMonitor}. - * + * * @param progressMonitor * The {@link IProgressMonitor} or null if no * progress should be reported. @@ -594,7 +609,7 @@ public abstract class AbstractUtility { * Creates a {@link SubProgressMonitor} if the given * {@link IProgressMonitor} is not null and not a * {@link NullProgressMonitor}. - * + * * @param progressMonitor * The parent {@link IProgressMonitor} of the * {@link SubProgressMonitor} to be created. @@ -619,7 +634,7 @@ public abstract class AbstractUtility { /** * Checks whether the user canceled this operation. If not canceled, the * given number of steps are declared as done. - * + * * @param newMonitor * a {@link org.eclipse.core.runtime.IProgressMonitor} object. * @param steps @@ -636,7 +651,7 @@ public abstract class AbstractUtility { /** * Present a progress dialog to the user. This dialog will block the UI - * + * * @param runnable * an implementation of {@link IRunnableWithProgress} * @throws java.lang.InterruptedException @@ -653,7 +668,7 @@ public abstract class AbstractUtility { *

* runInUI *

- * + * * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)} * @param runnable * a {@link org.eclipse.jface.operation.IRunnableWithProgress} @@ -676,7 +691,7 @@ public abstract class AbstractUtility { *

* run *

- * + * * @param fork * a boolean. * @param cancelable @@ -699,7 +714,7 @@ public abstract class AbstractUtility { *

* getProgressService *

- * + * * @return a {@link org.eclipse.ui.progress.IProgressService} object. */ public static IProgressService getProgressService() { @@ -711,7 +726,7 @@ public abstract class AbstractUtility { *

* getProgressService2 *

- * + * * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService} * object. */ @@ -723,7 +738,7 @@ public abstract class AbstractUtility { *

* info *

- * + * * @param message * a {@link java.lang.String} object. */ @@ -736,7 +751,7 @@ public abstract class AbstractUtility { *

* info *

- * + * * @param status * a {@link org.eclipse.core.runtime.IStatus} object. */ @@ -748,7 +763,7 @@ public abstract class AbstractUtility { *

* warn *

- * + * * @param source * a {@link java.lang.Class} object. * @param message @@ -759,12 +774,12 @@ public abstract class AbstractUtility { getLog4JLogger(source).warn(message); log(status); } - + public static void warn(Class source, IStatus status) { getLog4JLogger(source).warn(status.getMessage(), status.getException()); log(status); } - + public static void warn(Class source, Throwable t) { IStatus status = new Status(IStatus.WARNING, getPluginId(), t.getMessage(), t); getLog4JLogger(source).warn(t); @@ -775,7 +790,7 @@ public abstract class AbstractUtility { *

* error *

- * + * * @param source * a {@link java.lang.Class} object. * @param t @@ -789,7 +804,7 @@ public abstract class AbstractUtility { *

* error *

- * + * * @param source * a {@link java.lang.Class} object. * @param message @@ -806,7 +821,7 @@ public abstract class AbstractUtility { *

* error *

- * + * * @param source * a {@link java.lang.Class} object. * @param status @@ -822,7 +837,7 @@ public abstract class AbstractUtility { *

* getLog4JLogger *

- * + * * @param clazz * a {@link java.lang.Class} object. * @return a {@link org.apache.log4j.Logger} object. @@ -833,7 +848,7 @@ public abstract class AbstractUtility { /** * @see {@link ILog#log(IStatus)} - * + * * @param status */ private static void log(IStatus status) { @@ -844,7 +859,7 @@ public abstract class AbstractUtility { *

* getPluginId *

- * + * * @return a {@link java.lang.String} object. */ public static String getPluginId() { @@ -855,7 +870,7 @@ public abstract class AbstractUtility { *

* getActiveEditor *

- * + * * @return a {@link org.eclipse.ui.IEditorPart} object. */ public static IEditorPart getActiveEditor() { @@ -867,7 +882,7 @@ public abstract class AbstractUtility { *

* getDetailsView *

- * + * * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart} * object. */ @@ -908,5 +923,88 @@ public abstract class AbstractUtility { .reflow(); } } - - } + + /** + * Orders a Collection of {@link IEnumTerm}s according to the term + * hierarchy. The hierarchy will be reduced to two layers: one layer being + * the root elements (that have no parents) and the other being their + * children and children's children recursively.
+ * The returned map will be be ordered primarily by root elements and + * secondarily by the child elements, both ascending alphabetically.
+ *
+ * The reduced hierarchy could look like this:
+ *
    + *
  • Root1 + *
      + *
    • child1 + *
    • child2 + *
    • childOfChild2 + *
    + *
  • root2 + *
    • child4
    + *
+ * + * @param terms + * A {@link Collection} of {@link IEnumTerm}s for which the term + * hierarchy should be created + * @return a map which holds the terms as keys and their string + * representation via {@link IEnumTerm#getMessage()} as values + */ + public static > Map orderTerms(Collection terms) { + Comparator comparator = new Comparator() { + @Override + public int compare(T t1, T t2) { + return t1.getKey().compareTo(t2.getKey()); + } + }; + Map result = new LinkedHashMap(); + Map> termHierarchy = new TreeMap>(comparator); + + for(T term : terms) { + Set childList = new TreeSet(comparator); + // add root element as keys + if(term.getKindOf()==null){ + termHierarchy.put(term, childList); + } + // add child element to topmost parent i.e. root + else{ + T root = getRootFor(term); + if(termHierarchy.containsKey(root)){ + termHierarchy.get(root).add(term); + } + else{ + childList.add(term); + termHierarchy.put(root, childList); + } + } + } + + // create list according to the type hierarchy (root elements alphabetically with recursive children also alphabetically) + for(Entry> entry:termHierarchy.entrySet()){ + T root = entry.getKey(); + result.put(root, root.getMessage()); + for(T child:entry.getValue()){ + result.put(child, " - " + child.getMessage()); + } + } + return result; + } + + @SuppressWarnings("unchecked") + /** + * Recursively iterates over all term parents until no more parent is found i.e. the root node + * @param term The term for which the parent should be found + * @return the root terms of the term hierarchy + */ + private static> T getRootFor(T term){ + // PP: cast should be safe. Why is Eclipse complaining?? + T parent = (T) term.getKindOf(); + if(parent==null){ + return term; + } + else{ + return getRootFor((T) term.getKindOf()); + } + } + +} diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/EnumComboElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/EnumComboElement.java index 3371a6ae5..160478274 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/EnumComboElement.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/EnumComboElement.java @@ -1,9 +1,9 @@ // $Id$ /** * Copyright (C) 2007 EDIT - * European Distributed Institute of Taxonomy + * European Distributed Institute of Taxonomy * http://www.e-taxonomy.eu - * + * * The contents of this file are subject to the Mozilla Public License Version 1.1 * See LICENSE.TXT at the top of this package for the full license terms. */ @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Map.Entry; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; @@ -22,12 +23,12 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Label; -import eu.etaxonomy.cdm.model.common.IDefinedTerm; import eu.etaxonomy.cdm.model.common.IEnumTerm; import eu.etaxonomy.cdm.model.common.OriginalSourceType; import eu.etaxonomy.cdm.model.name.NomenclaturalCode; import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType; import eu.etaxonomy.cdm.model.reference.ReferenceType; +import eu.etaxonomy.taxeditor.model.AbstractUtility; import eu.etaxonomy.taxeditor.preference.Resources; import eu.etaxonomy.taxeditor.store.StoreUtil; import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement; @@ -42,7 +43,7 @@ import eu.etaxonomy.taxeditor.ui.element.LayoutConstants; *

* Abstract AbstractEnumComboElement class. *

- * + * * @author n.hoffmann * @created Mar 16, 2010 * @version 1.0 @@ -53,7 +54,7 @@ public class EnumComboElement extends private static CdmEnumDataHolder[] cdmEnumDataHolders = { new CdmEnumDataHolder(){ - + @Override public String getName() { return "Nomenclatural Code"; @@ -68,7 +69,7 @@ public class EnumComboElement extends public Class getClazz() { return NomenclaturalCode.class; } - + }, new CdmEnumDataHolder(){ @@ -86,7 +87,7 @@ public class EnumComboElement extends public Class getClazz() { return ReferenceType.class; } - + }, new CdmEnumDataHolder(){ @@ -104,7 +105,7 @@ public class EnumComboElement extends public Class getClazz() { return SpecimenOrObservationType.class; } - + }, new CdmEnumDataHolder(){ @@ -122,27 +123,27 @@ public class EnumComboElement extends public Class getClazz() { return OriginalSourceType.class; } - + } - + }; - + private static final int DEFAULT_VISIBLE_ITEMS = 10; protected T selection; protected List elementTypeList = new ArrayList(); - private Label label; + private final Label label; protected Combo combo; - private Class enumType; + private final Class enumType; /** *

* Constructor for AbstractEnumComboElement. *

- * + * * @param formFactory * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} * object. @@ -191,9 +192,9 @@ public class EnumComboElement extends *

*/ private void populateTypes(){ - for(T enumElement : getElementsForClass(enumType)){ - elementTypeList.add(enumElement); - combo.add(((Enum) enumElement).name()); + for(Entry keyLabelPair : AbstractUtility.orderTerms(getElementsForClass(enumType)).entrySet()){ + elementTypeList.add(keyLabelPair.getKey()); + combo.add(keyLabelPair.getValue()); } } @@ -201,7 +202,7 @@ public class EnumComboElement extends *

* Setter for the field selection. *

- * + * * @param selection * the selection to set */ @@ -214,7 +215,7 @@ public class EnumComboElement extends *

* addSelectionListener *

- * + * * @param listener * a {@link org.eclipse.swt.events.SelectionListener} object. */ @@ -226,7 +227,7 @@ public class EnumComboElement extends *

* removeSelectionListener *

- * + * * @param listener * a {@link org.eclipse.swt.events.SelectionListener} object. */ @@ -235,7 +236,8 @@ public class EnumComboElement extends } /** {@inheritDoc} */ - public void setSelected(boolean selected) { + @Override + public void setSelected(boolean selected) { setBackground(selected ? SELECTED : getPersistentBackground()); } @@ -243,7 +245,7 @@ public class EnumComboElement extends *

* Getter for the field selection. *

- * + * * @return the selection */ public T getSelection() { @@ -251,25 +253,28 @@ public class EnumComboElement extends } /** {@inheritDoc} */ - public void setEnabled(boolean enabled) { + @Override + public void setEnabled(boolean enabled) { combo.setEnabled(enabled); } /* * (non-Javadoc) - * + * * @see * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt * .events.SelectionEvent) */ /** {@inheritDoc} */ - public void widgetSelected(SelectionEvent e) { + @Override + public void widgetSelected(SelectionEvent e) { selection = elementTypeList.get(combo.getSelectionIndex()); firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e)); } /** {@inheritDoc} */ - public void setIrrelevant(boolean irrelevant) { + @Override + public void setIrrelevant(boolean irrelevant) { String colorId = irrelevant ? Resources.COLOR_COMPOSITE_IRRELEVANT : Resources.COLOR_COMPOSITE_BACKGROUND; @@ -284,21 +289,22 @@ public class EnumComboElement extends } /** {@inheritDoc} */ - public void widgetDefaultSelected(SelectionEvent e) { + @Override + public void widgetDefaultSelected(SelectionEvent e) { } - + public void setVisibleItemCount(int visibleItems){ combo.setVisibleItemCount(visibleItems); } - + private Collection getElementsForClass(Class clazz){ CdmEnumDataHolder dataHolder = getCdmEnumDataHolderForClass(clazz); if (dataHolder != null) { - return dataHolder.getElements(); + return dataHolder.getElements(); } return null; } - + private CdmEnumDataHolder getCdmEnumDataHolderForClass(Class clazz){ for (CdmEnumDataHolder dataHolder : cdmEnumDataHolders) { if (dataHolder.getClazz().equals(clazz)){ @@ -307,7 +313,7 @@ public class EnumComboElement extends } return null; } - + private interface CdmEnumDataHolder { Class getClazz(); String getName(); -- 2.34.1