Revision ae7e2680
Added by Cherian Mathew almost 9 years ago
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 |
*/ |
... | ... | |
28 | 28 |
import org.eclipse.jface.viewers.TableViewerColumn; |
29 | 29 |
import org.eclipse.jface.viewers.Viewer; |
30 | 30 |
import org.eclipse.swt.SWT; |
31 |
|
|
32 | 31 |
import org.eclipse.swt.widgets.Composite; |
33 | 32 |
import org.eclipse.swt.widgets.Display; |
34 | 33 |
import org.eclipse.swt.widgets.Table; |
35 |
import org.eclipse.ui.INullSelectionListener; |
|
36 |
import org.eclipse.ui.ISelectionListener; |
|
37 |
|
|
38 | 34 |
import org.eclipse.ui.IWorkbenchPart; |
39 | 35 |
|
36 |
import eu.etaxonomy.cdm.api.application.CdmChangeEvent; |
|
40 | 37 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
41 | 38 |
import eu.etaxonomy.cdm.api.service.IAgentService; |
42 |
import eu.etaxonomy.cdm.api.service.ICommonService; |
|
43 | 39 |
import eu.etaxonomy.cdm.api.service.IGroupService; |
44 |
|
|
45 | 40 |
import eu.etaxonomy.cdm.api.service.INameService; |
46 | 41 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
47 | 42 |
import eu.etaxonomy.cdm.api.service.IReferenceService; |
48 | 43 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
49 | 44 |
import eu.etaxonomy.cdm.api.service.IUserService; |
50 |
|
|
51 | 45 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
52 | 46 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
53 | 47 |
import eu.etaxonomy.cdm.model.common.Group; |
54 |
|
|
55 | 48 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
56 | 49 |
import eu.etaxonomy.cdm.model.common.User; |
57 | 50 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
58 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
59 | 51 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
60 | 52 |
import eu.etaxonomy.cdm.model.reference.Reference; |
61 | 53 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
62 |
|
|
63 | 54 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor; |
64 | 55 |
import eu.etaxonomy.taxeditor.model.DescriptionHelper; |
65 | 56 |
import eu.etaxonomy.taxeditor.model.LineSelection; |
... | ... | |
79 | 70 |
|
80 | 71 |
/** Constant <code>ID="eu.etaxonomy.taxeditor.bulkeditor.refer"{trunked}</code> */ |
81 | 72 |
public static final String ID = "eu.etaxonomy.taxeditor.bulkeditor.view.referencingobjects"; |
82 |
|
|
73 |
|
|
83 | 74 |
private TableViewer viewer; |
84 | 75 |
|
85 | 76 |
private String referencedObjectTitleCache; |
86 |
private ConversationHolder conversation;
|
|
87 |
|
|
77 |
private ConversationHolder conversation; |
|
78 |
|
|
88 | 79 |
/* (non-Javadoc) |
89 | 80 |
* @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createViewer(org.eclipse.swt.widgets.Composite) |
90 | 81 |
*/ |
... | ... | |
100 | 91 |
viewer.setLabelProvider(new ReferencingObjectsLabelProvider()); |
101 | 92 |
// viewer.setInput(new ArrayList<CdmBase>()); |
102 | 93 |
} |
103 |
|
|
94 |
|
|
104 | 95 |
/** |
105 | 96 |
* Create the columns for the table |
106 | 97 |
* @param viewer |
... | ... | |
127 | 118 |
* @param entity a {@link eu.etaxonomy.cdm.model.common.IdentifiableEntity} object. |
128 | 119 |
*/ |
129 | 120 |
public void updateReferencingObjects(final UUID entityUUID, final Class objectClass) { |
130 |
|
|
121 |
|
|
131 | 122 |
final Display display = Display.getCurrent(); |
132 |
|
|
123 |
|
|
133 | 124 |
Job job = new Job("Update Referencing Objects") { |
134 |
|
|
125 |
|
|
135 | 126 |
@Override |
136 | 127 |
protected IStatus run(IProgressMonitor monitor) { |
137 | 128 |
monitor.beginTask("Calculating referencing objects", 10); |
138 |
|
|
129 |
|
|
139 | 130 |
monitor.worked(3); |
140 |
|
|
131 |
|
|
141 | 132 |
display.asyncExec(new Runnable() { |
142 |
|
|
133 |
|
|
143 | 134 |
@Override |
144 | 135 |
public void run() { |
145 | 136 |
if (entityUUID != null){ |
146 |
|
|
137 |
|
|
147 | 138 |
List<CdmBase> referencingObjects = getReferencingObjects(entityUUID, objectClass); |
148 |
|
|
139 |
|
|
149 | 140 |
updateView(referencingObjects); |
150 |
|
|
151 |
|
|
141 |
|
|
142 |
|
|
152 | 143 |
} |
153 | 144 |
} |
154 | 145 |
}); |
155 |
|
|
146 |
|
|
156 | 147 |
monitor.done(); |
157 |
|
|
158 |
|
|
148 |
|
|
149 |
|
|
159 | 150 |
return Status.OK_STATUS; |
160 | 151 |
} |
161 | 152 |
}; |
162 |
|
|
153 |
|
|
163 | 154 |
job.setPriority(Job.DECORATE); |
164 | 155 |
job.schedule(); |
165 | 156 |
} |
... | ... | |
184 | 175 |
} |
185 | 176 |
//referencedObject =(CdmBase) CdmStore.getService(IIdentifiableEntityService.class).load(referencedObject.getUuid()); |
186 | 177 |
Set<CdmBase> setOfReferencingObjects = null; |
187 |
|
|
178 |
|
|
188 | 179 |
if (referencedObject != null){ |
189 | 180 |
referencedObjectTitleCache = ((IdentifiableEntity)referencedObject).getTitleCache(); |
190 | 181 |
setOfReferencingObjects = CdmStore.getCommonService().getReferencingObjects(referencedObject); |
191 | 182 |
} |
192 | 183 |
if (setOfReferencingObjects != null){ |
193 |
List<CdmBase> referencingObjects = new ArrayList<CdmBase>(setOfReferencingObjects);
|
|
194 |
|
|
184 |
List<CdmBase> referencingObjects = new ArrayList<CdmBase>(setOfReferencingObjects); |
|
185 |
|
|
195 | 186 |
Collections.sort(referencingObjects, new ReferencingClassComparator()); |
196 |
|
|
187 |
|
|
197 | 188 |
return referencingObjects; |
198 |
|
|
189 |
|
|
199 | 190 |
} |
200 | 191 |
} catch (Exception e) { |
201 | 192 |
logger.error("Error retrieving referencing objects", e); |
202 | 193 |
} |
203 | 194 |
return null; |
204 | 195 |
} |
205 |
|
|
196 |
|
|
206 | 197 |
class ReferencingClassComparator implements Comparator<CdmBase> { |
207 | 198 |
|
208 | 199 |
/* (non-Javadoc) |
209 | 200 |
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) |
210 | 201 |
*/ |
211 |
public int compare(CdmBase o1, CdmBase o2) { |
|
202 |
@Override |
|
203 |
public int compare(CdmBase o1, CdmBase o2) { |
|
212 | 204 |
String string1 = o1.getClass().getSimpleName(); |
213 | 205 |
String string2 = o2.getClass().getSimpleName(); |
214 | 206 |
int classCompare = string1.compareToIgnoreCase(string2); |
... | ... | |
221 | 213 |
} |
222 | 214 |
} |
223 | 215 |
} |
224 |
|
|
216 |
|
|
225 | 217 |
/** |
226 |
*
|
|
218 |
* |
|
227 | 219 |
*/ |
228 | 220 |
private void updateView(List<CdmBase> referencingObjects) { |
229 | 221 |
if (viewer != null && !viewer.getControl().isDisposed()){ |
... | ... | |
238 | 230 |
} |
239 | 231 |
|
240 | 232 |
/** {@inheritDoc} */ |
241 |
public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
|
233 |
@Override |
|
234 |
public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
|
242 | 235 |
if(! (part instanceof BulkEditor)){ |
243 | 236 |
setContentDescription(""); |
244 | 237 |
showEmptyPage(); |
245 | 238 |
return; |
246 | 239 |
} |
247 |
|
|
240 |
|
|
248 | 241 |
if(! (selection instanceof LineSelection)){ |
249 | 242 |
return; |
250 | 243 |
} |
251 | 244 |
LineSelection lineSelection = (LineSelection) selection; |
252 |
|
|
245 |
|
|
253 | 246 |
if(lineSelection.size() != 1){ |
254 | 247 |
return; |
255 | 248 |
} |
256 |
|
|
249 |
|
|
257 | 250 |
if(! (lineSelection.getFirstElement() instanceof IdentifiableEntity)){ |
258 | 251 |
return; |
259 | 252 |
} |
260 |
|
|
253 |
|
|
261 | 254 |
showViewer(part, lineSelection); |
262 | 255 |
} |
263 |
|
|
256 |
|
|
264 | 257 |
/* (non-Javadoc) |
265 | 258 |
* @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#showViewer(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) |
266 | 259 |
*/ |
... | ... | |
268 | 261 |
@Override |
269 | 262 |
public void showViewer(IWorkbenchPart part, IStructuredSelection selection) { |
270 | 263 |
// this.part = part; |
271 |
|
|
264 |
|
|
272 | 265 |
updateReferencingObjects(((IdentifiableEntity) selection.getFirstElement()).getUuid(),selection.getFirstElement().getClass() ); |
273 | 266 |
} |
274 |
|
|
267 |
|
|
275 | 268 |
/** {@inheritDoc} */ |
276 | 269 |
@Override |
277 | 270 |
public void dispose() { |
... | ... | |
279 | 272 |
selectionService.removePostSelectionListener(this); |
280 | 273 |
selectionService.removeSelectionListener(this); |
281 | 274 |
super.dispose(); |
282 |
|
|
275 |
|
|
283 | 276 |
} |
284 | 277 |
|
285 | 278 |
/* (non-Javadoc) |
... | ... | |
299 | 292 |
public void changed(Object object) { |
300 | 293 |
// no editing in this view |
301 | 294 |
} |
302 |
|
|
295 |
|
|
303 | 296 |
/* (non-Javadoc) |
304 | 297 |
* @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#onComplete() |
305 | 298 |
*/ |
... | ... | |
308 | 301 |
public boolean onComplete() { |
309 | 302 |
return false; |
310 | 303 |
} |
311 |
|
|
304 |
|
|
312 | 305 |
public void refresh(){ |
313 |
|
|
306 |
|
|
314 | 307 |
selectionService.removePostSelectionListener(this); |
315 | 308 |
selectionService.removeSelectionListener(this); |
316 | 309 |
selectionService.addPostSelectionListener(this); |
317 | 310 |
selectionService.addSelectionListener(this); |
318 |
|
|
311 |
|
|
319 | 312 |
} |
320 | 313 |
|
314 |
/* (non-Javadoc) |
|
315 |
* @see eu.etaxonomy.cdm.api.application.ICdmChangeListener#onChange(eu.etaxonomy.cdm.api.application.CdmChangeEvent) |
|
316 |
*/ |
|
317 |
@Override |
|
318 |
public void onChange(CdmChangeEvent event) { |
|
319 |
// TODO Auto-generated method stub |
|
320 |
|
|
321 |
} |
|
322 |
|
|
321 | 323 |
|
322 | 324 |
} |
Also available in: Unified diff
ICdmDataChangeService, CdmUIDataChangeService, CdmDataChangeService : added new data change service with different services for the ui and non-ui states
CdmApplicationState, CdmStore : added data change service to app state
CdmChangeEvent, ICdmChangeListener : added change listener and even to fire in case of data changes
ICdmEntitySessionEnabled : extends new change service interface
ICdmEntitySession, CdmEntitySession : removed data change un/registration since this is now handled by the new data change service
BaseRemotingTest, MockCdmEntitySession, *Editor, *ViewPart, *Navigator : refactoring with new change listener
RemotingCdmHandler, RemotingCdmOperation, RemotingCdmUpdateOperation : added new handler / operation architecture base classes
AbstractUtility : added method for running async operation with callback to handler
RemotingChangeAcceptedTaxonToSynonymHandler,RemotingChangeAcceptedTaxonToSynonymOperation : first implementations of new handler / operation architecture
plugin.xml : added standalone and remoting handlers for ChangeAcceptedTaxonToSynonym
*Test : adapted for new handler / operation and change service