Project

General

Profile

« Previous | Next » 

Revision 2fc2f07a

Added by Katja Luther over 6 years ago

implement areaSelectionDialog like the other selection dialogs

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NamedAreaSelectionDialog.java
10 10
package eu.etaxonomy.taxeditor.ui.dialog.selection;
11 11

  
12 12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.HashSet;
15 13
import java.util.List;
16
import java.util.Set;
17 14
import java.util.UUID;
18 15

  
19 16
import org.eclipse.jface.action.Action;
......
22 19
import org.eclipse.swt.widgets.Composite;
23 20
import org.eclipse.swt.widgets.Control;
24 21
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.swt.widgets.Text;
25 23

  
26 24
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
25
import eu.etaxonomy.cdm.api.service.ITermService;
27 26
import eu.etaxonomy.cdm.api.service.IVocabularyService;
28
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
29 27
import eu.etaxonomy.cdm.model.common.CdmBase;
30 28
import eu.etaxonomy.cdm.model.common.TermType;
31 29
import eu.etaxonomy.cdm.model.common.TermVocabulary;
32 30
import eu.etaxonomy.cdm.model.location.NamedArea;
33
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
34 31
import eu.etaxonomy.taxeditor.model.MessagingUtils;
35 32
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
36 33
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
......
67 64
		}
68 65
	}
69 66

  
70
	protected Collection<TermVocabulary> selectedVocabularies;
67
	protected List<TermVocabulary> selectedVocabularies;
71 68
    protected ArrayList<TermVocabulary> preselectedVocabularies;
72 69
    private Object preferenceID;
73 70

  
......
80 77
	 * @param namedArea
81 78
	 * 				A namedArea that should be selected when the dialog opens
82 79
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
83
	 * @param preferenceId a class which is used for generating the preference key so that every 
80
	 * @param preferenceId a class which is used for generating the preference key so that every
84 81
	 * dialogs can be grouped to have their own preferences depending on this id
85 82
	 * @param preselectedVocabularyUuids the {@link UUID}s of the pre-selected vocabularies
86 83
	 * @return a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
......
99 96
			TermVocabulary preselectedVocabulary = CdmStore.getService(IVocabularyService.class).find(preselectedVocabularyUuids[i]);
100 97
			preselectedVocabularies.add(preselectedVocabulary);
101 98
		}
102
		Collection<TermVocabulary> tempSelectedVocabularies = new HashSet<>();
99
		List<TermVocabulary> tempSelectedVocabularies = new ArrayList<>();
103 100
		for(TermVocabulary vocabulary:selectedVocabularies){
104 101
			if(preselectedVocabularies.contains(vocabulary)
105 102
					|| !PreferencesUtil.getPreferenceStore().getBoolean(getPrefKey(vocabulary))){
......
107 104
			}
108 105
		}
109 106
		selectedVocabularies = tempSelectedVocabularies;
110
		initModel();//re-init to consider pre-selected vocabularies
107
//		initModel();//re-init to consider pre-selected vocabularies
111 108
	}
112 109

  
113 110
	/** {@inheritDoc} */
......
127 124
			}
128 125
		}
129 126
	}
130
	
127

  
131 128
	private String getPrefKey(TermVocabulary vocabulary){
132 129
		return "hide_"+NamedAreaSelectionDialog.class.getCanonicalName()+vocabulary.getUuid()+preferenceID;
133 130
	}
......
160 157
	/** {@inheritDoc} */
161 158
	@Override
162 159
	protected void initModel() {
163

  
164
		Set<NamedArea> terms = new HashSet<NamedArea>();
165
		for(TermVocabulary<NamedArea> vocabulary : selectedVocabularies){
166
			terms.addAll(vocabulary.getTermsOrderedByLabels(CdmStore.getDefaultLanguage()));
167
		}
168

  
169
		if(model == null){
170
			model = new ArrayList<UuidAndTitleCache<NamedArea>>();
171
		}
172
		model.clear();
173
		for(Object areaObject : terms){
174
			NamedArea area = (NamedArea) HibernateProxyHelper.deproxy(areaObject);
175
			UuidAndTitleCache<NamedArea> element = new UuidAndTitleCache<NamedArea>(NamedArea.class, area.getUuid(), area.getId(), getTitle(area));
176
			model.add(element);
177
		}
160
	    Control control = getPatternControl();
161
        String pattern = null;
162
        if (control != null){
163
            pattern = ((Text)control).getText();
164
        }
165

  
166
        if (pattern == null || pattern.equals("?")){
167
            model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, null);
168
        }else{
169
            model = CdmStore.getService(ITermService.class).getUuidAndTitleCache(selectedVocabularies, limitOfInitialElements, pattern);
170
        }
171

  
172
//		Set<NamedArea> terms = new HashSet<NamedArea>();
173
//		for(TermVocabulary<NamedArea> vocabulary : selectedVocabularies){
174
//			terms.addAll(vocabulary.getTermsOrderedByLabels(CdmStore.getDefaultLanguage()));
175
//		}
176
//
177
//		if(model == null){
178
//			model = new ArrayList<UuidAndTitleCache<NamedArea>>();
179
//		}
180
//		model.clear();
181
//		for(Object areaObject : terms){
182
//			NamedArea area = (NamedArea) HibernateProxyHelper.deproxy(areaObject);
183
//			UuidAndTitleCache<NamedArea> element = new UuidAndTitleCache<NamedArea>(NamedArea.class, area.getUuid(), area.getId(), getTitle(area));
184
//			model.add(element);
185
//		}
178 186
	}
179 187

  
180 188
	/** {@inheritDoc} */

Also available in: Unified diff