forked from ome/openmicroscopy
/
MetadataViewerModel.java
1088 lines (999 loc) · 29.6 KB
/
MetadataViewerModel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* org.openmicroscopy.shoola.agents.metadata.view.MetadataViewerModel
*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2013 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*------------------------------------------------------------------------------
*/
package org.openmicroscopy.shoola.agents.metadata.view;
//Java imports
import java.awt.Component;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
//Third-party libraries
import org.apache.commons.collections.CollectionUtils;
//Application-internal dependencies
import org.openmicroscopy.shoola.agents.metadata.AdminEditor;
import org.openmicroscopy.shoola.agents.metadata.DataBatchSaver;
import org.openmicroscopy.shoola.agents.metadata.DataSaver;
import org.openmicroscopy.shoola.agents.metadata.ExperimenterEditor;
import org.openmicroscopy.shoola.agents.metadata.GroupEditor;
import org.openmicroscopy.shoola.agents.metadata.MetadataLoader;
import org.openmicroscopy.shoola.agents.metadata.ContainersLoader;
import org.openmicroscopy.shoola.agents.metadata.MetadataViewerAgent;
import org.openmicroscopy.shoola.agents.metadata.RenderingSettingsLoader;
import org.openmicroscopy.shoola.agents.metadata.StructuredDataLoader;
import org.openmicroscopy.shoola.agents.metadata.ThumbnailLoader;
import org.openmicroscopy.shoola.agents.metadata.browser.Browser;
import org.openmicroscopy.shoola.agents.metadata.browser.BrowserFactory;
import org.openmicroscopy.shoola.agents.metadata.browser.TreeBrowserSet;
import org.openmicroscopy.shoola.agents.metadata.editor.Editor;
import org.openmicroscopy.shoola.agents.metadata.editor.EditorFactory;
import org.openmicroscopy.shoola.agents.metadata.rnd.Renderer;
import org.openmicroscopy.shoola.agents.metadata.util.DataToSave;
import org.openmicroscopy.shoola.agents.util.EditorUtil;
import org.openmicroscopy.shoola.env.data.model.AdminObject;
import org.openmicroscopy.shoola.env.data.model.MovieExportParam;
import org.openmicroscopy.shoola.env.data.util.SecurityContext;
import org.openmicroscopy.shoola.env.data.util.StructuredDataResults;
import org.openmicroscopy.shoola.env.rnd.RndProxyDef;
import pojos.AnnotationData;
import pojos.DataObject;
import pojos.DatasetData;
import pojos.ExperimenterData;
import pojos.FileAnnotationData;
import pojos.GroupData;
import pojos.ImageData;
import pojos.PlateAcquisitionData;
import pojos.PlateData;
import pojos.ProjectData;
import pojos.ScreenData;
import pojos.WellSampleData;
/**
* The Model component in the <code>MetadataViewer</code> MVC triad.
* This class tracks the <code>MetadataViewer</code>'s state and knows how to
* initiate data retrievals. It also knows how to store and manipulate
* the results. This class provides a suitable data loader.
* The {@link MetadataViewerComponent} intercepts the results of data loadings,
* feeds them back to this class and fires state transitions as appropriate.
*
* @author Jean-Marie Burel
* <a href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a>
* @author Donald MacDonald
* <a href="mailto:donald@lifesci.dundee.ac.uk">donald@lifesci.dundee.ac.uk</a>
* @version 3.0
* @since OME3.0
*/
class MetadataViewerModel
{
/** Holds one of the state flags defined by {@link MetadataViewer}. */
private int state;
/** Reference to the component that embeds this model. */
private MetadataViewer component;
/** The object of reference for the viewer i.e. the root. */
private Object refObject;
/** The object of reference for the viewer i.e. the root. */
private Object parentRefObject;
/** The object of reference for the viewer i.e. the root. */
private Object grandParent;
/** The object hosting the various annotations linked to an object. */
private Map<DataObject, StructuredDataResults> data;
/** The object hosting the various annotations linked to an object. */
private StructuredDataResults parentData;
/** Reference to the browser. */
private Browser browser;
/** Reference to the editor. */
private Editor editor;
/** Use to load annotations when multiple objects are selected.*/
private StructuredDataLoader multiDataLoader;
/** Only used when it is a batch call. */
private Class dataType;
/**
* Flag indicating the selection mode, <code>true</code>
* if single selection, <code>false</code> otherwise.
*/
private boolean singleMode;
/** Collection of nodes related to the node of reference. */
private List<DataObject> relatedNodes;
/**
* One of the Rendering constants defined by the
* <code>MetadataViewer</code> interface.
*/
private int index;
/**
* The id of the possible owner, this should only be used
* to handle unregistered objects.
*/
private long userID;
/** The collection of rendering settings related to the image. */
private Map viewedBy;
/** The security context.*/
private SecurityContext ctx;
/** The number of loader used.*/
private int loaderID;
/** The active loaders.*/
private Map<Integer, MetadataLoader> loaders;
/**
* Creates a new context if <code>null</code>.
*
* @param ho The node to handle.
* @return See above.
*/
private SecurityContext retrieveContext(DataObject ho)
{
if (ctx != null) return ctx;
return new SecurityContext(ho.getGroupId());
}
/**
* Returns the loader's ID if any corresponding to the class.
*
* @param refClass The class of reference.
* @return See above.
*/
private Integer getLoaderID(Class refClass)
{
Entry<Integer, MetadataLoader> e;
Iterator<Entry<Integer, MetadataLoader>>
i = loaders.entrySet().iterator();
while (i.hasNext()) {
e = i.next();
if (e.getValue().getClass().equals(refClass))
return e.getKey();
}
return null;
}
/**
* Returns the collection of the attachments linked to the
* <code>DataObject</code>.
*
* @return See above.
*/
private List<FileAnnotationData> getTabularData()
{
StructuredDataResults data = getStructuredData();
List<FileAnnotationData> l = new ArrayList<FileAnnotationData>();
if (data == null) return l;
Collection<FileAnnotationData> attachments = data.getAttachments();
if (attachments == null) return l;
Iterator<FileAnnotationData> i = attachments.iterator();
FileAnnotationData f;
String ns;
while (i.hasNext()) {
f = i.next();
ns = f.getNameSpace();
if (FileAnnotationData.BULK_ANNOTATIONS_NS.equals(ns)) {
l.add(f);
}
}
return l;
}
/**
* Creates a new object and sets its state to {@link MetadataViewer#NEW}.
*
* @param refObject The reference object.
* @param index One of the rendering constants defined by the
* <code>MetadataViewer</code> I/F.
*/
MetadataViewerModel(Object refObject, int index)
{
state = MetadataViewer.NEW;
switch (index) {
case MetadataViewer.RND_GENERAL:
case MetadataViewer.RND_SPECIFIC:
this.index = index;
break;
default:
this.index = MetadataViewer.RND_GENERAL;
}
this.refObject = refObject;
loaderID = 0;
loaders = new HashMap<Integer, MetadataLoader>();
data = null;
dataType = null;
singleMode = true;
userID = MetadataViewerAgent.getUserDetails().getId();
}
/**
* Called by the <code>MetadataViewer</code> after creation to allow this
* object to store a back reference to the embedding component.
*
* @param component The embedding component.
*/
void initialize(MetadataViewer component)
{
this.component = component;
browser = BrowserFactory.createBrowser(component, refObject);
editor = EditorFactory.createEditor(component, refObject, browser);
}
/**
* Returns the id of the user. Only use to handle <code>FileData</code>
* objects.
*
* @return See above.
*/
long getUserID() { return userID; }
/**
* Sets the data type, this value is only used for batch annotation.
*
* @param dataType The value to set.
*/
void setDataType(Class dataType) { this.dataType = dataType; }
/**
* Returns the current state.
*
* @return One of the flags defined by the {@link MetadataViewer} interface.
*/
int getState() { return state; }
/**
* Sets the object in the {@link MetadataViewer#DISCARDED} state.
* Any ongoing data loading will be cancelled.
*/
void discard()
{
state = MetadataViewer.DISCARDED;
loaders.entrySet().iterator();
Iterator<Entry<Integer, MetadataLoader>>
i = loaders.entrySet().iterator();
MetadataLoader loader;
while (i.hasNext()) {
loader = i.next().getValue();
if (loader != null) loader.cancel();
}
loaders.clear();
if (multiDataLoader != null) multiDataLoader.cancel();
}
/**
* Sets the object of reference.
*
* @param refObject The value to set.
* @param ctx The security context.
*/
void setRootObject(Object refObject, SecurityContext ctx)
{
this.refObject = refObject;
this.ctx = ctx;
if (ctx == null && refObject instanceof DataObject) {
DataObject data = (DataObject) refObject;
if (data.getId() >= 0)
this.ctx = new SecurityContext(data.getGroupId());
}
browser.setRootObject(refObject);
editor.setRootObject(refObject);
data = null;
if (!(refObject instanceof WellSampleData) && parentData != null) {
parentData = null;
}
parentRefObject = null;
viewedBy = null;
}
/**
* Sets the parent of the object of reference.
*
* @param parentRefObject The value to set.
* @param grandParent The value to set.
*/
void setParentRootObject(Object parentRefObject, Object grandParent)
{
this.parentRefObject = parentRefObject;
this.grandParent = grandParent;
editor.setParentRootObject(parentRefObject, grandParent);
}
/**
* Returns the parent of the reference object.
*
* @return See above.
*/
Object getParentRefObject() { return parentRefObject; }
/**
* Returns the object of reference.
*
* @return See above.
*/
Object getRefObject()
{
if (data == null) return refObject;
return refObject;
}
/**
* Returns the <code>Browser</code> displaying the metadata.
*
* @return See above.
*/
Browser getBrowser() { return browser; }
/**
* Returns the <code>Editor</code> displaying the metadata.
*
* @return See above.
*/
Editor getEditor() { return editor; }
/**
* Cancels any ongoing data loading.
*
* @param loaderID The identifier of the loader.
*/
void cancel(int loaderID)
{
MetadataLoader loader = loaders.get(loaderID);
if (loader != null) {
loader.cancel();
loaders.remove(loaderID);
}
}
/**
* Starts the asynchronous retrieval of the attachments related
* to the parent node.
*
* @param refNode The menu node of reference.
* @param rootType The type of reference.
*/
void fireParentLoading(TreeBrowserSet refNode)
{
Integer id = getLoaderID(ContainersLoader.class);
if (id != null) cancel(id);
Object ho = refNode.getUserObject();
if (ho instanceof DataObject) {
loaderID++;
ctx = retrieveContext((DataObject) ho);
ContainersLoader loader = new ContainersLoader(
component, ctx, refNode, ho.getClass(),
((DataObject) ho).getId(), loaderID);
loaders.put(loaderID, loader);
loader.load();
}
}
/**
* Starts the asynchronous retrieval of the structured data related
* to the passed node.
*
* @param node The node to handle.
*/
void fireStructuredDataLoading(Object node)
{
if (!(node instanceof DataObject)) return;
if (node instanceof ExperimenterData) return;
if (node instanceof DataObject) {
Integer id = getLoaderID(StructuredDataLoader.class);
if (id != null) cancel(id);
loaderID++;
if (node instanceof WellSampleData) {
node = ((WellSampleData) node).getImage();
}
ctx = retrieveContext((DataObject) node);
StructuredDataLoader loader = new StructuredDataLoader(component,
ctx, Arrays.asList((DataObject) node), loaderID);
loaders.put(loaderID, loader);
loader.load();
state = MetadataViewer.LOADING_METADATA;
}
}
/**
* Returns <code>true</code> if the passed object is the reference object,
* <code>false</code> otherwise.
*
* @param uo The object to compare.
* @param ref The object of reference.
* @return See above.
*/
boolean isSameObject(DataObject uo, Object ref)
{
if (uo == null || !(ref instanceof DataObject)) return false;
Class<?> klass = ref.getClass();
DataObject object;
if (ref instanceof WellSampleData) {
klass = ((WellSampleData) ref).getImage().getClass();
object = ((WellSampleData) ref).getImage();
} else object = (DataObject) ref;
Class<?> hoKlass = uo.getClass();
if (uo instanceof WellSampleData) {
hoKlass = ((WellSampleData) uo).getImage().getClass();
uo = ((WellSampleData) uo).getImage();
}
if (!hoKlass.equals(klass)) return false;
return uo.getId() == object.getId();
}
/**
* Returns <code>true</code> if the passed object is the reference object,
* <code>false</code> otherwise.
*
* @param uo The object to compare.
* @return See above.
*/
boolean isSameObject(Object uo)
{
if (uo instanceof DataObject)
return isSameObject((DataObject) uo, refObject);
return false;
}
/**
* Returns the object path i.e. if a dataset is selected,
* the name of the project_name of the dataset.
*
* @return See above.
*/
String getRefObjectPath()
{
return getRefObjectName();
}
/**
* Returns the name of the object if any.
*
* @return See above.
*/
String getRefObjectName()
{
Object ref = getRefObject();
if (ref instanceof ImageData)
return ((ImageData) ref).getName();
else if (ref instanceof DatasetData)
return ((DatasetData) ref).getName();
else if (ref instanceof ProjectData)
return ((ProjectData) ref).getName();
else if (ref instanceof PlateData)
return ((PlateData) ref).getName();
else if (ref instanceof ScreenData)
return ((ScreenData) ref).getName();
else if (ref instanceof ExperimenterData)
return EditorUtil.formatExperimenter((ExperimenterData) ref);
else if (ref instanceof GroupData)
return ((GroupData) ref).getName();
return "";
}
/**
* Returns the text indicating what to save.
*
* @return See above.
*/
String getInstanceToSave()
{
Object ref = getRefObject();
String v = "";
if (ref instanceof ImageData) {
v = "Image's Data: ";
v += EditorUtil.truncate(((ImageData) ref).getName());
} else if (ref instanceof DatasetData) {
v = "Dataset's Data: ";
v += EditorUtil.truncate(((DatasetData) ref).getName());
} else if (ref instanceof ProjectData) {
v = "Project's Data: ";
v += EditorUtil.truncate(((ProjectData) ref).getName());
} else if (ref instanceof PlateData) {
v = "Plate's Data: ";
v += EditorUtil.truncate(((PlateData) ref).getName());
} else if (ref instanceof PlateAcquisitionData) {
v = "Run's Data: ";
v += EditorUtil.truncate(
((PlateAcquisitionData) ref).getLabel());
} else if (ref instanceof ScreenData) {
v = "Screen's Data: ";
v += EditorUtil.truncate(((ScreenData) ref).getName());
} else if (ref instanceof ExperimenterData) {
v = EditorUtil.formatExperimenter((ExperimenterData) ref);
v += "'s details";
} if (ref instanceof GroupData) {
v = ((GroupData) ref).getName();
v += "'s details";
}
return v;
}
/**
* Fires an asynchronous call to save the data, add (resp. remove)
* annotations to (resp. from) the object.
*
* @param object The annotation/link to add or remove.
* @param metadata The acquisition metadata to save.
* @param data The object to update.
* @param asynch Pass <code>true</code> to save data asynchronously,
* <code>false</code> otherwise.
*/
void fireSaving(DataToSave object,
List<Object> metadata, Collection<DataObject> data, boolean asynch)
{
List<AnnotationData> toAdd = null;
List<Object> toRemove = null;
if (object != null) {
toAdd = object.getToAdd();
toRemove = object.getToRemove();
}
loaderID++;
DataSaver loader = new DataSaver(component, ctx, data, toAdd,
toRemove, metadata, loaderID);
loaders.put(loaderID, loader);
loader.load();
state = MetadataViewer.SAVING;
}
/**
* Fires an asynchronous call to update the passed experimenter.
*
* @param data The object to update.
* @param asynch Pass <code>true</code> to save data asynchronously,
* <code>false</code> otherwise.
*/
void fireExperimenterSaving(ExperimenterData data, boolean async)
{
loaderID++;
ctx = retrieveContext(data);
ExperimenterEditor loader = new ExperimenterEditor(component, ctx,
data, loaderID);
loaders.put(loaderID, loader);
loader.load();
state = MetadataViewer.SAVING;
}
/**
* Fires an asynchronous call to modify the default group of the
* logged in experimenter.
*
* @param group
*/
void fireChangeGroup(GroupData group)
{
SecurityContext c = ctx;
if (MetadataViewerAgent.isAdministrator())
c = getAdminContext();
MetadataLoader loader = new GroupEditor(component, c, group,
loaderID, GroupEditor.CHANGE);
loader.load();
}
/**
* Fires an asynchronous call to update the passed group.
*
* @param data The object to update.
* @param asynch Pass <code>true</code> to save data asynchronously,
* <code>false</code> otherwise.
*/
void fireAdminSaving(AdminObject data, boolean asynch)
{
MetadataLoader loader = null;
SecurityContext c = ctx;
if (MetadataViewerAgent.isAdministrator())
c = getAdminContext();
switch (data.getIndex()) {
case AdminObject.UPDATE_GROUP:
GroupData group = data.getGroup();
loaderID++;
loader = new GroupEditor(component, c, group,
data.getPermissions(), loaderID, GroupEditor.UPDATE);
loaders.put(loaderID, loader);
break;
case AdminObject.UPDATE_EXPERIMENTER:
loaderID++;
loader = new AdminEditor(component, c, data.getGroup(),
data.getExperimenters(), loaderID);
loaders.put(loaderID, loader);
}
if (loader != null) {
loader.load();
state = MetadataViewer.SAVING;
}
}
/**
* Sets the structured data.
*
* @param data The value to set.
* @param loaderID The identifier of the loader
*/
void setStructuredDataResults(Map<DataObject, StructuredDataResults> data,
int loaderID)
{
loaders.remove(loaderID);
this.data = data;
state = MetadataViewer.READY;
}
/**
* Sets the structured data of the parent.
*
* @param parentData The value to set.
* @param refNode The node of reference.
*/
void setParentDataResults(StructuredDataResults parentData,
DataObject node, int loaderID)
{
loaders.remove(loaderID);
this.parentData = parentData;
state = MetadataViewer.READY;
}
/**
* Returns the structured data.
*
* @return See above.
*/
StructuredDataResults getStructuredData()
{
return getStructuredData(refObject);
}
/**
* Returns the structured data.
*
* @param object The object to
* @return See above.
*/
StructuredDataResults getStructuredData(Object object)
{
if (data == null) return null;
if (object instanceof DataObject) {
if (object instanceof WellSampleData)
object = ((WellSampleData) object).getImage();
return data.get((DataObject) object);
}
return null;
}
/**
* Returns the structured data.
*
* @return See above.
*/
StructuredDataResults getParentStructuredData() { return parentData; }
/**
* Returns <code>true</code> if the imported set of pixels has been
* archived, <code>false</code> otherwise.
*
* @return See above.
*/
boolean isArchived()
{
if (!(refObject instanceof ImageData)) return false;
ImageData img = (ImageData) refObject;
return img.isArchived();
}
/**
* Fires an asynchronous call to save the objects contained
* in the passed <code>DataObject</code> to save, add (resp. remove)
* annotations to (resp. from) the object.
*
* @param toAdd Collection of annotations to add.
* @param toRemove Collection of annotations to remove.
* @param toSave Collection of data objects to handle.
*/
void fireBatchSaving(List<AnnotationData> toAdd, List<Object>
toRemove, Collection<DataObject> toSave)
{
DataBatchSaver loader = new DataBatchSaver(component, ctx,
toSave, toAdd, toRemove, loaderID);
loader.load();
loaderID++;
state = MetadataViewer.BATCH_SAVING;
}
/**
* Sets to <code>true</code> if the model is in single mode,
* to <code>false</code> otherwise.
*
* @param singleMode The value to set.
*/
void setSelectionMode(boolean singleMode)
{
this.singleMode = singleMode;
if (singleMode) relatedNodes = null;
}
/**
* Returns <code>true</code> if the model is in single mode,
* <code>false</code> otherwise.
*
* @return See above.
*/
boolean isSingleMode() { return singleMode; }
/**
* Sets the nodes related to the object of reference.
*
* @param relatedNodes The value to set.
*/
void setRelatedNodes(List<DataObject> relatedNodes)
{
this.relatedNodes = relatedNodes;
if (CollectionUtils.isEmpty(relatedNodes)) return;
DataObject ho = relatedNodes.get(0);
List<DataObject> l = new ArrayList<DataObject>();
if (ho instanceof WellSampleData) {
Iterator<DataObject> i = relatedNodes.iterator();
while (i.hasNext()) {
l.add(((WellSampleData) i.next()).getImage());
}
} else l.addAll(relatedNodes);
loaderID++;
ctx = retrieveContext(ho);
StructuredDataLoader loader = new StructuredDataLoader(component,
ctx, l, loaderID);
loaders.put(loaderID, loader);
loader.load();
state = MetadataViewer.LOADING_METADATA;
}
/**
* Returns the nodes related to the object of reference.
*
* @return See above.
*/
List<DataObject> getRelatedNodes() { return relatedNodes; }
/**
* Sets the state.
*
* @param state The value to set.
*/
void setState(int state) { this.state = state; }
/**
* Starts an asynchronous retrieval of the containers hosting the
* currently edited object.
*
* @param type The type of the edited object.
* @param id The id of the currently edited object.
*/
void loadParents(Class type, long id)
{
loaderID++;
ContainersLoader loader = new ContainersLoader(component, ctx, type,
id, loaderID);
loaders.put(loaderID, loader);
loader.load();
}
/**
* Starts an asynchronous call to create a movie.
*
* @param parameters The movie parameters.
*/
void createMovie(MovieExportParam parameters)
{
if (parameters == null) return;
if (!(refObject instanceof ImageData)) return;
}
/**
* Returns the rendering index.
*
* @return See above.
*/
int getIndex() { return index; }
/**
* Returns the instrument transfer function linked to the edited object.
*
* @return See above
*/
FileAnnotationData getIRF()
{
if (!(refObject instanceof ImageData)) return null;
if (data == null) return null;
Collection<FileAnnotationData> l = getStructuredData().getAttachments();
if (l == null || l.size() == 0) return null;
Iterator<FileAnnotationData> i = l.iterator();
FileAnnotationData fa;
while (i.hasNext()) {
fa = i.next();
if (fa.getFileName().contains("irf"))
return fa;
}
return null;
}
/**
* Returns <code>true</code> if it is an image with a lot of channels.
* <code>false</code> otherwise.
*
* @return See above.
*/
boolean isNumerousChannel()
{
if (!(refObject instanceof ImageData)) return false;
ImageData img = (ImageData) refObject;
return img.getDefaultPixels().getSizeC() >= Renderer.MAX_CHANNELS;
}
/**
* Sets the id of the possible owner. This should only be used for
* unregistered objects.
*
* @param userID The value to set.
*/
void setUserID(long userID) { this.userID = userID; }
/**
* Returns the rendering settings associated to the image.
*
* @return See above.
*/
Map getViewedBy() { return viewedBy; }
/**
* Sets the rendering settings associated to the image.
*
* @param viewedBy The value to set.
*/
void setViewedBy(Map viewedBy)
{
Map m = new LinkedHashMap();
if (viewedBy != null) {
long id = MetadataViewerAgent.getUserDetails().getId();
Entry entry;
Iterator i = viewedBy.entrySet().iterator();
ExperimenterData exp;
while (i.hasNext()) {
entry = (Entry) i.next();
exp = (ExperimenterData) entry.getKey();
if (exp.getId() == id) {
m.put(exp, entry.getValue());
}
}
i = viewedBy.entrySet().iterator();
while (i.hasNext()) {
entry = (Entry) i.next();
exp = (ExperimenterData) entry.getKey();
if (exp.getId() != id) {
m.put(exp, entry.getValue());
}
}
}
this.viewedBy = m;
Renderer rnd = getEditor().getRenderer();
if (rnd != null) {
rnd.loadRndSettings(true, null);
}
}
/**
* Starts an asynchronous call to load the rendering settings
* associated to the image.
*
* @param source The component invoking the loading.
* @param location The location of the mouse pressed.
*/
void fireViewedByLoading(Component source, Point location)
{
ImageData img = null;
if (refObject instanceof ImageData) img = (ImageData) refObject;
else if (refObject instanceof WellSampleData)
img = ((WellSampleData) refObject).getImage();
if (img == null) return;
getEditor().getRenderer().loadRndSettings(false, null);
loaderID++;
ctx = retrieveContext(img);
RenderingSettingsLoader loader = new RenderingSettingsLoader(component,
ctx, img.getDefaultPixels().getId(), loaderID);
loader.setLocation(source, location);
loaders.put(loaderID, loader);
loader.load();
}
/** Starts an asynchronous retrieval of the thumbnails. */
void fireThumbnailsLoading()
{
if (viewedBy == null) return;
ImageData image = null;
if (refObject instanceof ImageData) image = (ImageData) refObject;
else if (refObject instanceof WellSampleData)
image = ((WellSampleData) refObject).getImage();
Set experimenters = viewedBy.keySet();
Set<Long> ids = new HashSet<Long>();
Iterator i = experimenters.iterator();
while (i.hasNext()) {
ids.add(((ExperimenterData) i.next()).getId());
}
if (ids.size() == 0) return;
loaderID++;
ctx = retrieveContext(image);
ThumbnailLoader loader = new ThumbnailLoader(component, ctx, image,
ids, loaderID);
loaders.put(loaderID, loader);
loader.load();
}
/**
* Applies the specified rendering settings.
*
* @param rndDef The rendering settings to apply.
*/
void applyRenderingSettings(RndProxyDef rndDef)
{
Renderer rnd = getEditor().getRenderer();
if (rnd != null) rnd.resetSettings(rndDef, true);
}
/**
* Returns <code>true</code> if the object can be edited,
* <code>false</code> otherwise.
*
* @return See above.
*/
boolean canEdit()
{
if (editor == null) return false;
return editor.canEdit();
}
/**
* Returns <code>true</code> if the object can be annotated,
* <code>false</code> otherwise.
*
* @return See above.
*/
boolean canAnnotate()
{