6755 |
20 Feb 15 |
nicklas |
1 |
/** |
6755 |
20 Feb 15 |
nicklas |
$Id$ |
6755 |
20 Feb 15 |
nicklas |
3 |
|
6755 |
20 Feb 15 |
nicklas |
Copyright (C) 2015 Nicklas Nordborg |
6755 |
20 Feb 15 |
nicklas |
5 |
|
6755 |
20 Feb 15 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
6755 |
20 Feb 15 |
nicklas |
Available at http://base.thep.lu.se/ |
6755 |
20 Feb 15 |
nicklas |
8 |
|
6755 |
20 Feb 15 |
nicklas |
BASE is free software; you can redistribute it and/or |
6755 |
20 Feb 15 |
nicklas |
modify it under the terms of the GNU General Public License |
6755 |
20 Feb 15 |
nicklas |
as published by the Free Software Foundation; either version 3 |
6755 |
20 Feb 15 |
nicklas |
of the License, or (at your option) any later version. |
6755 |
20 Feb 15 |
nicklas |
13 |
|
6755 |
20 Feb 15 |
nicklas |
BASE is distributed in the hope that it will be useful, |
6755 |
20 Feb 15 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
6755 |
20 Feb 15 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6755 |
20 Feb 15 |
nicklas |
GNU General Public License for more details. |
6755 |
20 Feb 15 |
nicklas |
18 |
|
6755 |
20 Feb 15 |
nicklas |
You should have received a copy of the GNU General Public License |
6755 |
20 Feb 15 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
6755 |
20 Feb 15 |
nicklas |
21 |
*/ |
6755 |
20 Feb 15 |
nicklas |
22 |
package net.sf.basedb.util.overview.loader; |
6755 |
20 Feb 15 |
nicklas |
23 |
|
6755 |
20 Feb 15 |
nicklas |
24 |
import net.sf.basedb.core.BasicItem; |
6755 |
20 Feb 15 |
nicklas |
25 |
import net.sf.basedb.core.DbControl; |
6755 |
20 Feb 15 |
nicklas |
26 |
import net.sf.basedb.core.Item; |
6755 |
20 Feb 15 |
nicklas |
27 |
import net.sf.basedb.core.ItemList; |
6755 |
20 Feb 15 |
nicklas |
28 |
import net.sf.basedb.core.ItemQuery; |
6755 |
20 Feb 15 |
nicklas |
29 |
import net.sf.basedb.core.ItemResultIterator; |
6755 |
20 Feb 15 |
nicklas |
30 |
import net.sf.basedb.core.Listable; |
6755 |
20 Feb 15 |
nicklas |
31 |
import net.sf.basedb.util.overview.Node; |
6755 |
20 Feb 15 |
nicklas |
32 |
import net.sf.basedb.util.overview.OverviewContext; |
6755 |
20 Feb 15 |
nicklas |
33 |
import net.sf.basedb.util.overview.node.ChildNodeDirection; |
6755 |
20 Feb 15 |
nicklas |
34 |
import net.sf.basedb.util.overview.node.ItemListMemberNameGenerator; |
6755 |
20 Feb 15 |
nicklas |
35 |
import net.sf.basedb.util.overview.node.NameableNameGenerator; |
6755 |
20 Feb 15 |
nicklas |
36 |
import net.sf.basedb.util.overview.node.NodeFactory; |
6755 |
20 Feb 15 |
nicklas |
37 |
import net.sf.basedb.util.overview.validator.NodeValidator; |
6755 |
20 Feb 15 |
nicklas |
38 |
|
6755 |
20 Feb 15 |
nicklas |
39 |
|
6755 |
20 Feb 15 |
nicklas |
40 |
/** |
6755 |
20 Feb 15 |
nicklas |
Node loader implementation for item lists. Item |
6755 |
20 Feb 15 |
nicklas |
lists can only be loaded as root nodes. The forward-loading |
6755 |
20 Feb 15 |
nicklas |
direction goes to the item that is member of the list. |
6755 |
20 Feb 15 |
nicklas |
44 |
|
6755 |
20 Feb 15 |
nicklas |
@author nicklas |
6755 |
20 Feb 15 |
nicklas |
@since 3.5 |
6755 |
20 Feb 15 |
nicklas |
47 |
*/ |
6755 |
20 Feb 15 |
nicklas |
48 |
public class ItemListLoader |
6755 |
20 Feb 15 |
nicklas |
49 |
extends BasicItemNodeLoader<ItemList> |
6755 |
20 Feb 15 |
nicklas |
50 |
{ |
6755 |
20 Feb 15 |
nicklas |
51 |
public ItemListLoader() |
6755 |
20 Feb 15 |
nicklas |
52 |
{ |
6755 |
20 Feb 15 |
nicklas |
53 |
super(Item.ITEMLIST, ALLOW_ROOT_NODE, |
6755 |
20 Feb 15 |
nicklas |
54 |
new NameableNameGenerator<ItemList>("list", "List")); |
6755 |
20 Feb 15 |
nicklas |
55 |
} |
6755 |
20 Feb 15 |
nicklas |
56 |
|
6755 |
20 Feb 15 |
nicklas |
57 |
/* |
6755 |
20 Feb 15 |
nicklas |
From the AbstractNodeLoader class |
6755 |
20 Feb 15 |
nicklas |
59 |
---------------------------------- |
6755 |
20 Feb 15 |
nicklas |
60 |
*/ |
6755 |
20 Feb 15 |
nicklas |
61 |
/** |
6755 |
20 Feb 15 |
nicklas |
Loads property nodes of a item list. |
6755 |
20 Feb 15 |
nicklas |
<ul> |
6755 |
20 Feb 15 |
nicklas |
<li>Annotations: {@link AnnotationLoader#createPropertyNode(DbControl, OverviewContext, Node)} |
6755 |
20 Feb 15 |
nicklas |
<li>Any-to-any: {@link AnyToAnyLoader#createPropertyNode(DbControl, OverviewContext, Node)} |
6755 |
20 Feb 15 |
nicklas |
</ul> |
6755 |
20 Feb 15 |
nicklas |
67 |
*/ |
6755 |
20 Feb 15 |
nicklas |
68 |
@Override |
6755 |
20 Feb 15 |
nicklas |
69 |
protected void loadPropertyChildNodes(DbControl dc, OverviewContext context, Node listNode) |
6755 |
20 Feb 15 |
nicklas |
70 |
{ |
6755 |
20 Feb 15 |
nicklas |
71 |
getNodeLoader(context, Item.ANNOTATION).createPropertyNode(dc, context, listNode); |
6755 |
20 Feb 15 |
nicklas |
72 |
getNodeLoader(context, Item.ANYTOANY).createPropertyNode(dc, context, listNode); |
6755 |
20 Feb 15 |
nicklas |
73 |
} |
6755 |
20 Feb 15 |
nicklas |
74 |
|
6755 |
20 Feb 15 |
nicklas |
75 |
/** |
6755 |
20 Feb 15 |
nicklas |
Loads the list members. |
6755 |
20 Feb 15 |
nicklas |
77 |
*/ |
6755 |
20 Feb 15 |
nicklas |
78 |
@Override |
6755 |
20 Feb 15 |
nicklas |
79 |
protected void loadForwardChildNodes(DbControl dc, OverviewContext context, Node listNode) |
6755 |
20 Feb 15 |
nicklas |
80 |
{ |
6755 |
20 Feb 15 |
nicklas |
81 |
ItemList list = (ItemList)listNode.getItem(dc); |
6755 |
20 Feb 15 |
nicklas |
82 |
getNodeLoader(context, list.getMemberType()).createForwardNode(dc, context, listNode); |
6755 |
20 Feb 15 |
nicklas |
83 |
} |
6755 |
20 Feb 15 |
nicklas |
84 |
// --------------------------------------- |
6755 |
20 Feb 15 |
nicklas |
85 |
|
6755 |
20 Feb 15 |
nicklas |
86 |
/** |
6755 |
20 Feb 15 |
nicklas |
Utiltity method to be used by other loaders to load members of an item list. |
6755 |
20 Feb 15 |
nicklas |
The loader should be one that loads {@link Listable} items. |
6755 |
20 Feb 15 |
nicklas |
The member nodes are created as child nodes to the list node without any |
6755 |
20 Feb 15 |
nicklas |
intermediate folder node. |
6755 |
20 Feb 15 |
nicklas |
91 |
|
6755 |
20 Feb 15 |
nicklas |
@param loader The loader implementation to load member items |
6755 |
20 Feb 15 |
nicklas |
@param listNode The parent item list node |
6755 |
20 Feb 15 |
nicklas |
94 |
*/ |
6755 |
20 Feb 15 |
nicklas |
95 |
@SuppressWarnings("unchecked") |
6755 |
20 Feb 15 |
nicklas |
96 |
public static <T extends BasicItem & Listable> void loadMemberNodes(BasicItemNodeLoader<T> loader, DbControl dc, OverviewContext context, Node listNode) |
6755 |
20 Feb 15 |
nicklas |
97 |
{ |
6755 |
20 Feb 15 |
nicklas |
98 |
NodeValidator<T> validator = loader.getNodeValidator(context); |
6755 |
20 Feb 15 |
nicklas |
99 |
NodeFactory<T> factory = loader.getNodeFactory(dc, context, validator, new ItemListMemberNameGenerator()); |
6755 |
20 Feb 15 |
nicklas |
100 |
ItemList list = (ItemList)listNode.getItem(dc); |
6755 |
20 Feb 15 |
nicklas |
101 |
|
6755 |
20 Feb 15 |
nicklas |
// Find all members of the list |
6755 |
20 Feb 15 |
nicklas |
103 |
ItemQuery<T> query = (ItemQuery<T>)context.initQuery(list.getMembers(), "name"); |
6755 |
20 Feb 15 |
nicklas |
104 |
|
6755 |
20 Feb 15 |
nicklas |
105 |
ItemResultIterator<T> it = query.iterate(dc); |
6755 |
20 Feb 15 |
nicklas |
106 |
while (it.hasNext()) |
6755 |
20 Feb 15 |
nicklas |
107 |
{ |
6755 |
20 Feb 15 |
nicklas |
108 |
T item = it.next(); |
6755 |
20 Feb 15 |
nicklas |
109 |
loader.createItemNode(factory, item, item, false, listNode, ChildNodeDirection.ALL); |
6755 |
20 Feb 15 |
nicklas |
110 |
} |
6755 |
20 Feb 15 |
nicklas |
111 |
} |
6755 |
20 Feb 15 |
nicklas |
112 |
|
6755 |
20 Feb 15 |
nicklas |
113 |
} |