Project

General

Profile

« Previous | Next » 

Revision b0ce5b17

Added by Patrick Plitzner over 10 years ago

merged trunk into branch

View differences:

eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchResultView.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
41 41
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
42 42
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
43 43
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
44
import eu.etaxonomy.taxeditor.model.AbstractUtility;
44 45
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
45 46
import eu.etaxonomy.taxeditor.model.IContextListener;
46 47
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
......
56 57
 * @version 1.0
57 58
 */
58 59
public class SearchResultView extends ViewPart implements IConversationEnabled{
59
	
60

  
60 61
	private static Object[] EMPTY = new Object[0];
61
	
62

  
62 63
	private class ContextListener extends ContextListenerAdapter{
63 64
		/* (non-Javadoc)
64 65
		 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
......
66 67
		@Override
67 68
		public void contextStop(IMemento memento, IProgressMonitor monitor) {
68 69
			monitor.subTask("Getting rid of search results");
69
			NavigationUtil.hideView(SearchResultView.this);
70
			AbstractUtility.hideView(SearchResultView.this);
70 71
		}
71 72
	}
72
	
73

  
73 74
	/** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.searc"{trunked}</code> */
74
	public static final String ID = 
75
	public static final String ID =
75 76
			"eu.etaxonomy.taxeditor.navigation.search.searchResultView"; //$NON-NLS-1$
76 77

  
77 78
	private TableViewer resultViewer;
......
85 86
	private Text status;
86 87

  
87 88
	private SearchJob searchJob;
88
	
89

  
89 90
	private IContextListener contextListener;
90
	
91

  
91 92
	/* (non-Javadoc)
92 93
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
93 94
	 */
94 95
	/** {@inheritDoc} */
95 96
	@Override
96 97
	public void createPartControl(Composite parent) {
97
		
98

  
98 99
		conversation = CdmStore.createConversation();
99 100
		contextListener = new ContextListener();
100 101
		CdmStore.getContextManager().addContextListener(contextListener);
101
		
102

  
102 103
		GridLayout layout = new GridLayout();
103 104
		layout.marginWidth = 0;
104 105
		layout.marginHeight = 0;
105
		
106

  
106 107
		parent.setLayout(layout);
107
		
108

  
108 109
		Composite infoComposite = createInfoComposite(parent);
109 110
		infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
110
		
111

  
111 112
		resultViewer = new TableViewer(parent, SWT.NONE);
112 113
		resultViewer.setContentProvider(new ArrayContentProvider());
113 114
		resultViewer.setLabelProvider(new SearchResultLabelProvider());
114 115
		resultViewer.addDoubleClickListener(new IDoubleClickListener() {
115
			public void doubleClick(DoubleClickEvent event) {
116
			@Override
117
            public void doubleClick(DoubleClickEvent event) {
116 118
				NavigationUtil.executeEditHandler();
117 119
			}
118 120
		});
119
		
121

  
120 122
		resultViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
121
		
123

  
122 124
		getSite().setSelectionProvider(resultViewer);
123
		
125

  
124 126
		// register context menu
125 127
		MenuManager menuMgr = new MenuManager();
126 128
		menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
......
128 130

  
129 131
		Control control = resultViewer.getControl();
130 132
		Menu menu = menuMgr.createContextMenu(control);
131
		control.setMenu(menu);	
133
		control.setMenu(menu);
132 134
	}
133
	
135

  
134 136
	private Composite createInfoComposite(Composite parent){
135 137
		Composite composite = new Composite(parent, SWT.NULL);
136
		
138

  
137 139
		composite.setLayout(new GridLayout(2, false));
138
		
140

  
139 141
		Label searchStringLabel = new Label(composite, SWT.NULL);
140 142
		searchStringLabel.setText("Search String:");
141
		
143

  
142 144
		searchString = new Text(composite, SWT.NULL);
143 145
		searchString.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
144 146
		searchString.setEditable(false);
145 147
//		searchString.setText("                                               ");
146
		
148

  
147 149
		Label configurationDescriptionLabel = new Label(composite, SWT.NULL);
148 150
		configurationDescriptionLabel.setText("Search for:");
149
		
151

  
150 152
		configurationLabel = new Text(composite, SWT.WRAP);
151 153
		configurationLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
152 154
		configurationLabel.setEditable(false);
153
		
155

  
154 156
		Label statusLabel = new Label(composite, SWT.NULL);
155 157
		statusLabel.setText("Status:");
156
		
158

  
157 159
		status = new Text(composite, SWT.NULL);
158 160
		status.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
159 161
		status.setEditable(false);
160
		
162

  
161 163
		return composite;
162 164
	}
163
	
165

  
164 166
	/**
165 167
	 * <p>performSearch</p>
166 168
	 *
......
168 170
	 */
169 171
	public void performSearch(IFindTaxaAndNamesConfigurator configurator){
170 172
		setPartName("Search: '" + configurator.getTitleSearchString() + "'");
171
		
173

  
172 174
		searchString.setText(configurator.getTitleSearchString());
173
		
175

  
174 176
		List<String> includedEntities = new ArrayList<String>();
175
		if(configurator.isDoTaxa())
176
			includedEntities.add(SearchOption.TAXON.getLabel());
177
		if(configurator.isDoSynonyms())
178
			includedEntities.add(SearchOption.SYNONYM.getLabel());
179
		if(configurator.isDoNamesWithoutTaxa())
180
			includedEntities.add(SearchOption.NAME.getLabel());
177
		if(configurator.isDoTaxa()) {
178
            includedEntities.add(SearchOption.TAXON.getLabel());
179
        }
180
		if(configurator.isDoSynonyms()) {
181
            includedEntities.add(SearchOption.SYNONYM.getLabel());
182
        }
183
		if(configurator.isDoNamesWithoutTaxa()) {
184
            includedEntities.add(SearchOption.NAME.getLabel());
185
        }
181 186
		if(configurator.isDoTaxaByCommonNames()){
182 187
			includedEntities.add(SearchOption.COMMON_NAME.getLabel());
183 188
		}
184
		
189

  
185 190
		String includedEntitiesString = "";
186 191
		for (int i = 0; i < includedEntities.size(); i++){
187 192
			includedEntitiesString += includedEntities.get(i);
......
189 194
				includedEntitiesString += ", ";
190 195
			}
191 196
		}
192
		
197

  
193 198
		configurationLabel.setText(includedEntitiesString);
194
		
199

  
195 200
		status.setText("Searching...");
196
		
201

  
197 202
		searchJob = new SearchJob(Display.getCurrent(), configurator);
198 203
		searchJob.schedule();
199
		
204

  
200 205
	}
201
	
206

  
202 207
	/**
203 208
	 * <p>displaySearchResult</p>
204 209
	 *
......
206 211
	 */
207 212
	protected void displaySearchResult(List<UuidAndTitleCache<TaxonBase>> result) {
208 213
		if(result.size() > 0){
209
			resultViewer.setInput(result); 
214
			resultViewer.setInput(result);
210 215
			status.setText(result.size() + " entities found");
211 216
		}else{
212
			resultViewer.setInput(EMPTY); 
217
			resultViewer.setInput(EMPTY);
213 218
			status.setText("Search returned no results");
214 219
		}
215 220
	}
......
234 239
	 *
235 240
	 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
236 241
	 */
237
	public ConversationHolder getConversationHolder() {
242
	@Override
243
    public ConversationHolder getConversationHolder() {
238 244
		return this.conversation;
239 245
	}
240 246

  
......
242 248
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
243 249
	 */
244 250
	/** {@inheritDoc} */
245
	public void update(CdmDataChangeMap changeEvents) {
251
	@Override
252
    public void update(CdmDataChangeMap changeEvents) {
246 253
		// TODO Auto-generated method stub
247
		
254

  
248 255
	}
249
	
256

  
250 257
	/* (non-Javadoc)
251 258
	 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
252 259
	 */
......
255 262
	public void dispose() {
256 263
		super.dispose();
257 264
		conversation.close();
258
		if(searchJob != null)
259
			searchJob.cancel();
265
		if(searchJob != null) {
266
            searchJob.cancel();
267
        }
260 268
		CdmStore.getContextManager().removeContextListener(contextListener);
261 269
	}
262
	
270

  
263 271
	/**
264
	 * 
272
	 *
265 273
	 * @author n.hoffmann
266 274
	 * @created Feb 2, 2010
267 275
	 * @version 1.0
268 276
	 */
269 277
	class SearchJob extends Job{
270 278

  
271
		private IFindTaxaAndNamesConfigurator configurator;
272
		
273
		private Display display;
274
		
279
		private final IFindTaxaAndNamesConfigurator configurator;
280

  
281
		private final Display display;
282

  
275 283
		/**
276 284
		 * @param name
277 285
		 */
......
288 296
		protected IStatus run(IProgressMonitor monitor) {
289 297
			monitor.beginTask("", 100);
290 298
			monitor.worked(20);
291
			
299

  
292 300
			final List<UuidAndTitleCache<TaxonBase>> searchResult = CdmStore.getSearchManager().findTaxaAndNames(configurator);
293 301
			monitor.worked(40);
294
			
302

  
295 303
			if(! monitor.isCanceled()){
296 304
				display.asyncExec(new Runnable() {
297
					public void run() {
305
					@Override
306
                    public void run() {
298 307
						displaySearchResult(searchResult);
299 308
					}
300 309
				});
301 310
			}else{
302 311
				display.asyncExec(new Runnable() {
303
					public void run() {
312
					@Override
313
                    public void run() {
304 314
						status.setText("Cancelled");
305 315
					}
306 316
				});
......
308 318
			monitor.done();
309 319
			return Status.OK_STATUS;
310 320
		}
311
		
312
	}	
321

  
322
	}
313 323
}

Also available in: Unified diff