Project

General

Profile

« Previous | Next » 

Revision 11329ecc

Added by Katja Luther about 9 years ago

factual data for bulkeditor, improving referencing objects view, make delete in bulkeditor visible for synonyms

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
4
* European Distributed Institute of Taxonomy 
5 5
* http://www.e-taxonomy.eu
6
*
6
* 
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
15 15
import java.util.Comparator;
16 16
import java.util.List;
17 17
import java.util.Set;
18
import java.util.UUID;
18 19

  
19 20
import org.apache.log4j.Logger;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Status;
24
import org.eclipse.core.runtime.jobs.Job;
20 25
import org.eclipse.jface.viewers.ISelection;
21 26
import org.eclipse.jface.viewers.IStructuredSelection;
22 27
import org.eclipse.jface.viewers.TableViewer;
23 28
import org.eclipse.jface.viewers.TableViewerColumn;
24 29
import org.eclipse.jface.viewers.Viewer;
25 30
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.internal.ole.win32.ISpecifyPropertyPages;
26 32
import org.eclipse.swt.widgets.Composite;
27 33
import org.eclipse.swt.widgets.Display;
28 34
import org.eclipse.swt.widgets.Table;
29 35
import org.eclipse.ui.INullSelectionListener;
36
import org.eclipse.ui.ISelectionListener;
30 37
import org.eclipse.ui.IWorkbenchPart;
31 38

  
39
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
32 40
import eu.etaxonomy.cdm.api.service.IAgentService;
33 41
import eu.etaxonomy.cdm.api.service.ICommonService;
42
import eu.etaxonomy.cdm.api.service.IGroupService;
43
import eu.etaxonomy.cdm.api.service.IIdentifiableEntityService;
44
import eu.etaxonomy.cdm.api.service.INameService;
45
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
46
import eu.etaxonomy.cdm.api.service.IReferenceService;
47
import eu.etaxonomy.cdm.api.service.ITaxonService;
48
import eu.etaxonomy.cdm.api.service.IUserService;
49
import eu.etaxonomy.cdm.model.agent.AgentBase;
34 50
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
35 51
import eu.etaxonomy.cdm.model.common.CdmBase;
52
import eu.etaxonomy.cdm.model.common.Group;
53
import eu.etaxonomy.cdm.model.common.ICdmBase;
36 54
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
55
import eu.etaxonomy.cdm.model.common.User;
56
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
57
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
58
import eu.etaxonomy.cdm.model.reference.Reference;
59
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
60
import eu.etaxonomy.cdm.persistence.dao.agent.IAgentDao;
37 61
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
38 62
import eu.etaxonomy.taxeditor.model.DescriptionHelper;
39 63
import eu.etaxonomy.taxeditor.model.LineSelection;
......
53 77

  
54 78
	/** Constant <code>ID="eu.etaxonomy.taxeditor.bulkeditor.refer"{trunked}</code> */
55 79
	public static final String ID = "eu.etaxonomy.taxeditor.bulkeditor.view.referencingobjects";
56

  
80
	
57 81
	private TableViewer viewer;
58 82

  
59
	private CdmBase referencedObject;
60

  
83
	private String referencedObjectTitleCache;
84
	
61 85
	/* (non-Javadoc)
62 86
	 * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createViewer(org.eclipse.swt.widgets.Composite)
63 87
	 */
......
65 89
	@Override
66 90
	public void createViewer(Composite parent) {
67 91
		selectionService.addSelectionListener(this);
68

  
92
		
69 93
		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
70 94
				| SWT.V_SCROLL | SWT.FULL_SELECTION);
71 95
		createColumns(viewer);
......
73 97
		viewer.setLabelProvider(new ReferencingObjectsLabelProvider());
74 98
//		viewer.setInput(new ArrayList<CdmBase>());
75 99
	}
76

  
100
	
77 101
	/**
78 102
	 * Create the columns for the table
79 103
	 * @param viewer
......
99 123
	 *
100 124
	 * @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object.
101 125
	 */
102
	public void updateReferencingObjects(final IdentifiableEntity entity) {
103

  
126
	public void updateReferencingObjects(final UUID entityUUID, final Class objectClass) {
127
		
104 128
		final Display display = Display.getCurrent();
105

  
106
		//TODO see ticket #4537 (Re-enable asynchronous loading for ReferencingObjectsView)
107
		//this is a workaround for #1569
108
		//Job job = new Job("Update Referencing Objects") {
109
//
110
//			@Override
111
//			protected IStatus run(IProgressMonitor monitor) {
112
//				monitor.beginTask("Calculating referencing objects", 10);
113
//
114
//				monitor.worked(3);
115
//
116
//				display.asyncExec(new Runnable() {
117
//
118
//					@Override
119
//					public void run() {
120
//						ConversationHolder conversation = CdmStore.createConversation();
121
						List<CdmBase> referencingObjects = getReferencingObjects(entity);
122
						updateView(referencingObjects);
123
//						conversation.close();
124
//					}
125
//				});
126
//
127
//				monitor.done();
128
//
129
//
130
//				return Status.OK_STATUS;
131
//			}
132
//		};
133
//
134
//		job.setPriority(Job.DECORATE);
135
//		job.schedule();
129
		
130
		Job job = new Job("Update Referencing Objects") {
131
			
132
			@Override
133
			protected IStatus run(IProgressMonitor monitor) {
134
				monitor.beginTask("Calculating referencing objects", 10);
135
			
136
				monitor.worked(3);
137
				
138
				display.asyncExec(new Runnable() {
139
					
140
					@Override
141
					public void run() {
142
						if (entityUUID != null){
143
							ConversationHolder conversation = CdmStore.createConversation();
144
							List<CdmBase> referencingObjects = getReferencingObjects(entityUUID, objectClass);
145
							conversation.close();
146
							updateView(referencingObjects);
147
						}
148
					}
149
				});
150
				
151
				monitor.done();
152
				
153
				
154
				return Status.OK_STATUS;
155
			}
156
		};
157
		
158
		job.setPriority(Job.DECORATE);
159
		job.schedule();
136 160
	}
137 161

  
138
	private List<CdmBase> getReferencingObjects(Object entity) {
162
	private List<CdmBase> getReferencingObjects(UUID entity, Class objectClass) {
163
		CdmBase referencedObject = null;
139 164
        try {
140
        	if(entity instanceof CdmBase){
141
	        	referencedObject = (CdmBase) entity;
142
	        	if (referencedObject instanceof TeamOrPersonBase){
143
	        		referencedObject = CdmStore.getService(IAgentService.class).load(referencedObject.getUuid());
144
	        	}
165
        	if (objectClass.getSuperclass().equals(TeamOrPersonBase.class) ){
166
	        	referencedObject = CdmStore.getService(IAgentService.class).load(entity);
167
        	} else if (objectClass.getSuperclass().equals(TaxonNameBase.class)){
168
        		referencedObject = CdmStore.getService(INameService.class).load(entity);
169
        	} else if (objectClass.getSuperclass().equals(TaxonBase.class)){
170
        		referencedObject = CdmStore.getService(ITaxonService.class).load(entity);
171
        	} else if (objectClass.getSuperclass().equals(Reference.class)){
172
        		referencedObject = CdmStore.getService(IReferenceService.class).load(entity);
173
        	} else if (objectClass.getSuperclass().equals(SpecimenOrObservationBase.class)){
174
        		referencedObject = CdmStore.getService(IOccurrenceService.class).load(entity);
175
        	} else if (objectClass.isAssignableFrom(User.class)){
176
        		referencedObject = CdmStore.getService(IUserService.class).load(entity);
177
        	} else if (objectClass.isAssignableFrom(Group.class)){
178
        		referencedObject = CdmStore.getService(IGroupService.class).load(entity);
179
        	}
145 180
	        	//referencedObject =(CdmBase) CdmStore.getService(IIdentifiableEntityService.class).load(referencedObject.getUuid());
146
	        	Set<CdmBase> setOfReferencingObjects = CdmStore.getService(ICommonService.class).getReferencingObjects(referencedObject);
147
	        	if (setOfReferencingObjects != null){
148
		        	List<CdmBase> referencingObjects = new ArrayList<CdmBase>(setOfReferencingObjects);
149

  
150
		    		Collections.sort(referencingObjects, new ReferencingClassComparator());
151

  
152
		    		return referencingObjects;
153
	        	}
181
        	Set<CdmBase> setOfReferencingObjects = null;
182
        	
183
        	if (referencedObject != null){
184
        		referencedObjectTitleCache = ((IdentifiableEntity)referencedObject).getTitleCache();
185
        		setOfReferencingObjects = CdmStore.getService(ICommonService.class).getReferencingObjects(referencedObject);
186
        	}
187
	        if (setOfReferencingObjects != null){
188
		       	List<CdmBase> referencingObjects = new ArrayList<CdmBase>(setOfReferencingObjects);	        	
189
		       	
190
		    	Collections.sort(referencingObjects, new ReferencingClassComparator());
191
		    		
192
		    	return referencingObjects;
193
	        	
154 194
        	}
155 195
        } catch (Exception e) {
156 196
            logger.error("Error retrieving referencing objects", e);
157 197
        }
158 198
		return null;
159 199
	}
160

  
200
	
161 201
	class ReferencingClassComparator implements Comparator<CdmBase> {
162 202

  
163 203
		/* (non-Javadoc)
164 204
		 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
165 205
		 */
166
		@Override
167
        public int compare(CdmBase o1, CdmBase o2) {
206
		public int compare(CdmBase o1, CdmBase o2) {
168 207
			String string1 = o1.getClass().getSimpleName();
169 208
			String string2 = o2.getClass().getSimpleName();
170 209
			int classCompare = string1.compareToIgnoreCase(string2);
......
177 216
			}
178 217
		}
179 218
	}
180

  
219
	
181 220
	/**
182
	 *
221
	 * 
183 222
	 */
184 223
	private void updateView(List<CdmBase> referencingObjects) {
185
		viewer.setInput(referencingObjects);
186
		setContentDescription("'" + referencedObject + "' is referenced by:");
187
		showViewer();
224
		if (viewer != null && !viewer.getControl().isDisposed()){
225
			viewer.setInput(referencingObjects);
226
			/*if (referencedObjectTitleCache != null){
227
				setContentDescription("'" + referencedObjectTitleCache + "' is referenced by:");
228
			} else {
229
				setContentDescription("");
230
			}*/
231
			showViewer();
232
		}
188 233
	}
189 234

  
190 235
	/** {@inheritDoc} */
191
	@Override
192
    public void selectionChanged(IWorkbenchPart part, ISelection selection) {
193
	    if(part==null){
194
	        return;
195
	    }
236
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
196 237
		if(! (part instanceof BulkEditor)){
197 238
			setContentDescription("");
198 239
			showEmptyPage();
199 240
			return;
200 241
		}
201

  
242
		
202 243
		if(! (selection instanceof LineSelection)){
203 244
			return;
204 245
		}
205 246
		LineSelection lineSelection = (LineSelection) selection;
206

  
247
		
207 248
		if(lineSelection.size() != 1){
208 249
			return;
209 250
		}
210

  
251
			
211 252
		if(! (lineSelection.getFirstElement() instanceof IdentifiableEntity)){
212 253
			return;
213 254
		}
214

  
255
		
215 256
		showViewer(part, lineSelection);
216 257
	}
217

  
258
	
218 259
	/* (non-Javadoc)
219 260
	 * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#showViewer(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
220 261
	 */
......
222 263
	@Override
223 264
	public void showViewer(IWorkbenchPart part, IStructuredSelection selection) {
224 265
		this.part = part;
225

  
226
		updateReferencingObjects((IdentifiableEntity) selection.getFirstElement());
266
		
267
		updateReferencingObjects(((IdentifiableEntity) selection.getFirstElement()).getUuid(),selection.getFirstElement().getClass() );
227 268
	}
228

  
269
	
229 270
	/** {@inheritDoc} */
230 271
	@Override
231 272
	public void dispose() {
232 273
		selectionService.removePostSelectionListener(this);
233 274
		selectionService.removeSelectionListener(this);
234 275
		super.dispose();
235

  
276
		
236 277
	}
237 278

  
238 279
	/* (non-Javadoc)
......
252 293
	public void changed(Object object) {
253 294
		// no editing in this view
254 295
	}
255

  
296
	
256 297
	/* (non-Javadoc)
257 298
	 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#onComplete()
258 299
	 */
......
261 302
	public boolean onComplete() {
262 303
		return false;
263 304
	}
264

  
305
	
265 306
	public void refresh(){
266 307
		selectionService.removePostSelectionListener(this);
267 308
		selectionService.removeSelectionListener(this);
268 309
		selectionService.addPostSelectionListener(this);
269 310
		selectionService.addSelectionListener(this);
270

  
311
		
271 312
	}
272 313

  
273 314

  

Also available in: Unified diff