X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/be497f38c5dd0e2ffccb31c0991eb3083d177a93..47d72e6386937315094b9039c319e7f4524300fe:/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java index db4403611..5bd973b91 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java @@ -1,4 +1,3 @@ -// $Id$ /** * Copyright (C) 2007 EDIT * European Distributed Institute of Taxonomy @@ -11,33 +10,33 @@ package eu.etaxonomy.taxeditor.ui.dialog.selection; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.UUID; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; -import eu.etaxonomy.cdm.api.conversation.ConversationHolder; +import eu.etaxonomy.cdm.api.service.ITermService; import eu.etaxonomy.cdm.api.service.IVocabularyService; -import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; -import eu.etaxonomy.cdm.model.common.CdmBase; -import eu.etaxonomy.cdm.model.common.TermVocabulary; -import eu.etaxonomy.cdm.model.common.UuidAndTitleCache; -import eu.etaxonomy.cdm.model.location.Country; import eu.etaxonomy.cdm.model.location.NamedArea; +import eu.etaxonomy.cdm.model.term.DefinedTermBase; +import eu.etaxonomy.cdm.model.term.TermType; +import eu.etaxonomy.cdm.model.term.TermVocabulary; +import eu.etaxonomy.taxeditor.model.ImageResources; +import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard; +import eu.etaxonomy.taxeditor.preference.CdmPreferenceCache; +import eu.etaxonomy.taxeditor.preference.PreferencesUtil; import eu.etaxonomy.taxeditor.store.CdmStore; /** - *

FilteredNamedAreaSelectionDialog class.

- * * @author n.hoffmann * @created May 11, 2010 * @version 1.0 @@ -46,7 +45,7 @@ public class NamedAreaSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog { private class IncludeNamedAreaVocabulary extends Action { - private TermVocabulary vocabulary; + private final TermVocabulary vocabulary; /** * Creates a new instance of the class. @@ -63,12 +62,14 @@ public class NamedAreaSelectionDialog extends }else{ selectedVocabularies.remove(vocabulary); } - - initModel(); + PreferencesUtil.setBooleanValue(getPrefKey(vocabulary), !isChecked()); + search(); } } - private Collection> selectedVocabularies; + protected List selectedVocabularies; + protected List vocabularies; + /** @@ -79,91 +80,125 @@ public class NamedAreaSelectionDialog extends * @param namedArea * A namedArea that should be selected when the dialog opens * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. + * @param preferenceId a class which is used for generating the preference key so that every + * dialogs can be grouped to have their own preferences depending on this id + * @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected vocabularies * @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object. */ - public static NamedArea select(Shell shell, ConversationHolder conversation, NamedArea namedArea) { - NamedAreaSelectionDialog dialog = new NamedAreaSelectionDialog(shell, conversation, - "Choose an area", false, namedArea); + public static NamedArea select(Shell shell, //ConversationHolder conversation, + NamedArea namedArea, String preferenceId, UUID... preselectedVocabularyUuids) { + NamedAreaSelectionDialog dialog = new NamedAreaSelectionDialog(shell, //conversation, + "Choose an area", false, namedArea, preferenceId, preselectedVocabularyUuids); return getSelectionFromDialog(dialog); } - /** - *

Constructor for FilteredNamedAreaSelectionDialog.

- * - * @param shell a {@link org.eclipse.swt.widgets.Shell} object. - * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. - * @param title a {@link java.lang.String} object. - * @param multi a boolean. - * @param namedArea a {@link eu.etaxonomy.cdm.model.location.NamedArea} object. - */ - protected NamedAreaSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, NamedArea namedArea) { - super(shell, conversation, title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea); - } + protected NamedAreaSelectionDialog(Shell shell, //ConversationHolder conversation, + String title, boolean multi, NamedArea namedArea, Object preferenceId, UUID... preselectedVocabularyUuids) { + super(shell, //conversation, + title, multi, NamedAreaSelectionDialog.class.getCanonicalName(), namedArea); - /** {@inheritDoc} */ - @Override - protected void fillViewMenu(IMenuManager menuManager) { + selectedVocabularies = new ArrayList(); + this.preferenceID = preferenceId; - super.fillViewMenu(menuManager); + if (preselectedVocabularyUuids != null && preselectedVocabularyUuids.length > 0){ + for(int i=0;i vocabulary : getVocabularies()){ - IncludeNamedAreaVocabulary action = new IncludeNamedAreaVocabulary(vocabulary); - menuManager.add(action); - action.setChecked(true); + protected List createSelectedVocabularies() { + List tempSelectedVocabularies = new ArrayList(); + for(TermVocabulary vocabulary:vocabularies){ + if((selectedVocabularies.contains(vocabulary) && !PreferencesUtil.getBooleanValue(getPrefKey(vocabulary))) + || !PreferencesUtil.getBooleanValue(getPrefKey(vocabulary))){ + tempSelectedVocabularies.add(vocabulary); + } } + return tempSelectedVocabularies; + } + +// private static UUID[] createVocabularyUuidList() { +// String preselectedVocString = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()); +// if (StringUtils.isBlank(preselectedVocString)){ +// return null; +// } +// String[] preselectedVocArray = preselectedVocString.split(";"); +// UUID[] uuidList = new UUID[preselectedVocArray.length]; +// int i = 0; +// for (String uuidString: preselectedVocArray){ +// uuidList[i]= UUID.fromString(uuidString); +// i++; +// } +// return uuidList; +// } + + + private String getPrefKey(TermVocabulary vocabulary){ + return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceID; } /** {@inheritDoc} */ @Override protected NamedArea getPersistentObject(UUID uuid) { - for(TermVocabulary vocabulary : selectedVocabularies){ - for(Object object : vocabulary.getTerms()){ - CdmBase cdmBaseObject = (CdmBase) object; - if(uuid.equals(cdmBaseObject.getUuid())){ - return (NamedArea) cdmBaseObject; - } - } - } + + DefinedTermBase area = CdmStore.getService(ITermService.class).find(uuid); + if (area instanceof NamedArea){ + return (NamedArea) area; + } + return null; } /** {@inheritDoc} */ @Override protected void init() { - selectedVocabularies = getVocabularies(); + vocabularies = getAvailableVocabularies(); } - private List> getVocabularies(){ - List> vocabularies = CdmStore.getService(IVocabularyService.class).listByTermClass(NamedArea.class, null, null, null, null); - vocabularies.add(CdmStore.getService(IVocabularyService.class).find(Country.uuidCountryVocabulary)); + private List getAvailableVocabularies(){ + vocabularies = new ArrayList(); + CdmPreferenceCache cache = CdmPreferenceCache.instance(); +// CdmPreference pref = cache.get(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()); +// if (pref != null && !pref.isAllowOverride()){ +// UUID[] preselectedVocabularyUuids = createVocabularyUuidList(); +// +// for(int i=0;i vocabularies = CdmStore.getService(IVocabularyService.class).listByTermType(TermType.NamedArea, true, null, null, null, null); return vocabularies; } - /** {@inheritDoc} */ - @Override - protected void initModel() { - - Set terms = new HashSet(); - for(TermVocabulary vocabulary : selectedVocabularies){ - terms.addAll(vocabulary.getTermsOrderedByLabels(CdmStore.getDefaultLanguage())); - } - - if(model == null){ - model = new ArrayList>(); - } - model.clear(); - for(Object areaObject : terms){ - NamedArea area = (NamedArea) HibernateProxyHelper.deproxy(areaObject); - UuidAndTitleCache element = new UuidAndTitleCache(NamedArea.class, area.getUuid(), getTitle(area)); - model.add(element); - } - } +// /** {@inheritDoc} */ +// @Override +// protected void search() { +// Control control =getSearchField(); +// String pattern = null; +// if (control != null){ +// pattern = ((Text)control).getText(); +// } +// +// if (pattern == null || pattern.equals("?")){ +// model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, null, PreferencesUtil.getGlobalLanguage()); +// }else{ +// model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage()); +// } +// } - /** {@inheritDoc} */ - @Override - protected Control createExtendedContentArea(Composite parent) { - return null; - } +// /** {@inheritDoc} */ +// @Override +// protected Control createExtendedContentArea(Composite parent) { +// return null; +// } /** {@inheritDoc} */ @Override @@ -172,8 +207,7 @@ public class NamedAreaSelectionDialog extends String result = NamedArea.labelWithLevel(namedArea, CdmStore.getDefaultLanguage()); return result; } catch (Exception e) { - //TODO still need to learn how errors are handled in the Tax Editor - System.out.println("Error occurred when trying retrieve title for Named Area: " + namedArea.getUuid()); + MessagingUtils.error(NamedAreaSelectionDialog.class, "Error occurred when trying retrieve title for Named Area: " + namedArea.getUuid(), e); return namedArea.getTitleCache(); } } @@ -186,7 +220,61 @@ public class NamedAreaSelectionDialog extends /** {@inheritDoc} */ @Override - protected String getNewWizardLinkText() { + protected String[] getNewWizardText() { return null; } + + @Override + void createFilterButton(Composite searchAndFilter) + { + filterButton = new Button(searchAndFilter, SWT.NONE); +// filterButton.setText("Filter"); + filterButton.setImage(ImageResources.getImage(ImageResources.FUNNEL_ICON)); +// SelectionListener filterSelectionListener = new FilterSelectionListener(preferenceID, this); + filterButton.addSelectionListener(new SelectionListener(){ + @Override + public void widgetSelected(SelectionEvent e) { + + Object source = e.getSource(); + String text = null; + if (source instanceof Button){ + Shell shell = ((Button)source).getShell(); + Dialog dialog = new FilterDialog(getShell(), preferenceID, selectedVocabularies, vocabularies); + if(dialog!=null){ + dialog.open(); + } + createSelectedVocabularies(); + search(); + } + + + + + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // TODO Auto-generated method stub + + } + + + }); + + } + + + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#callService(java.lang.String) + */ + @Override + void callService(String pattern) { + if (selectedVocabularies == null || selectedVocabularies.size() == 0){ + model = CdmStore.getService(ITermService.class).getUuidAndTitleCacheNamedArea(vocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage()); + }else{ + model = CdmStore.getService(ITermService.class).getUuidAndTitleCacheNamedArea(selectedVocabularies, limitOfInitialElements, pattern, PreferencesUtil.getGlobalLanguage()); + } + } + }