6046 |
17 Apr 12 |
nicklas |
1 |
/** |
6046 |
17 Apr 12 |
nicklas |
$Id$ |
6046 |
17 Apr 12 |
nicklas |
3 |
|
6046 |
17 Apr 12 |
nicklas |
Copyright (C) 2012 Nicklas Nordborg |
6046 |
17 Apr 12 |
nicklas |
5 |
|
6046 |
17 Apr 12 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
6046 |
17 Apr 12 |
nicklas |
Available at http://base.thep.lu.se/ |
6046 |
17 Apr 12 |
nicklas |
8 |
|
6046 |
17 Apr 12 |
nicklas |
BASE is free software; you can redistribute it and/or |
6046 |
17 Apr 12 |
nicklas |
modify it under the terms of the GNU General Public License |
6046 |
17 Apr 12 |
nicklas |
as published by the Free Software Foundation; either version 3 |
6046 |
17 Apr 12 |
nicklas |
of the License, or (at your option) any later version. |
6046 |
17 Apr 12 |
nicklas |
13 |
|
6046 |
17 Apr 12 |
nicklas |
BASE is distributed in the hope that it will be useful, |
6046 |
17 Apr 12 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
6046 |
17 Apr 12 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6046 |
17 Apr 12 |
nicklas |
GNU General Public License for more details. |
6046 |
17 Apr 12 |
nicklas |
18 |
|
6046 |
17 Apr 12 |
nicklas |
You should have received a copy of the GNU General Public License |
6046 |
17 Apr 12 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
6046 |
17 Apr 12 |
nicklas |
21 |
*/ |
6046 |
17 Apr 12 |
nicklas |
22 |
package net.sf.basedb.util.overview.loader; |
6046 |
17 Apr 12 |
nicklas |
23 |
|
6046 |
17 Apr 12 |
nicklas |
24 |
import net.sf.basedb.core.Application; |
6046 |
17 Apr 12 |
nicklas |
25 |
import net.sf.basedb.core.DbControl; |
6046 |
17 Apr 12 |
nicklas |
26 |
import net.sf.basedb.util.extensions.ClientContext; |
6046 |
17 Apr 12 |
nicklas |
27 |
import net.sf.basedb.util.extensions.ExtensionsInvoker; |
6046 |
17 Apr 12 |
nicklas |
28 |
import net.sf.basedb.util.extensions.Registry; |
6088 |
21 Aug 12 |
nicklas |
29 |
import net.sf.basedb.util.extensions.manager.Settings; |
6046 |
17 Apr 12 |
nicklas |
30 |
import net.sf.basedb.util.overview.OverviewContext; |
6046 |
17 Apr 12 |
nicklas |
31 |
import net.sf.basedb.util.overview.Node; |
6046 |
17 Apr 12 |
nicklas |
32 |
import net.sf.basedb.util.overview.extensions.ChildNodeLoaderAction; |
6046 |
17 Apr 12 |
nicklas |
33 |
|
6046 |
17 Apr 12 |
nicklas |
34 |
/** |
6046 |
17 Apr 12 |
nicklas |
Wrapper for node loaders that automatically hooks into the |
6046 |
17 Apr 12 |
nicklas |
extension system when loading child nodes for a parent node. |
6046 |
17 Apr 12 |
nicklas |
It works by first delegating all method calls to the parent |
6046 |
17 Apr 12 |
nicklas |
node loader, but the {@link #loadChildNodes(DbControl, OverviewContext, Node)} |
6046 |
17 Apr 12 |
nicklas |
contains additional logic to query the extension system and |
6046 |
17 Apr 12 |
nicklas |
call {@link ChildNodeLoaderAction#createChildNodes(DbControl, OverviewContext, Node)} |
6046 |
17 Apr 12 |
nicklas |
for any action created by the an extension. |
6046 |
17 Apr 12 |
nicklas |
42 |
|
6046 |
17 Apr 12 |
nicklas |
@author Nicklas |
6046 |
17 Apr 12 |
nicklas |
@since 3.2 |
6046 |
17 Apr 12 |
nicklas |
45 |
*/ |
6046 |
17 Apr 12 |
nicklas |
46 |
public class ExtensionChildNodeLoader<I> |
6046 |
17 Apr 12 |
nicklas |
47 |
implements NodeLoader<I> |
6046 |
17 Apr 12 |
nicklas |
48 |
{ |
6046 |
17 Apr 12 |
nicklas |
49 |
|
6046 |
17 Apr 12 |
nicklas |
50 |
private final NodeLoader<I> parent; |
6046 |
17 Apr 12 |
nicklas |
51 |
|
6046 |
17 Apr 12 |
nicklas |
52 |
/** |
6046 |
17 Apr 12 |
nicklas |
Wrap the given parent node loader. |
6046 |
17 Apr 12 |
nicklas |
54 |
*/ |
6046 |
17 Apr 12 |
nicklas |
55 |
public ExtensionChildNodeLoader(NodeLoader<I> parent) |
6046 |
17 Apr 12 |
nicklas |
56 |
{ |
6046 |
17 Apr 12 |
nicklas |
57 |
this.parent = parent; |
6046 |
17 Apr 12 |
nicklas |
58 |
} |
6046 |
17 Apr 12 |
nicklas |
59 |
/* |
6046 |
17 Apr 12 |
nicklas |
From the NodeLoader interface |
6046 |
17 Apr 12 |
nicklas |
61 |
----------------------------- |
6046 |
17 Apr 12 |
nicklas |
62 |
*/ |
6046 |
17 Apr 12 |
nicklas |
63 |
/** |
6046 |
17 Apr 12 |
nicklas |
Call the same method on the 'parent' node loader. |
6046 |
17 Apr 12 |
nicklas |
@return The node that the parent node loader creates (may be null) |
6046 |
17 Apr 12 |
nicklas |
66 |
*/ |
6046 |
17 Apr 12 |
nicklas |
67 |
@Override |
6046 |
17 Apr 12 |
nicklas |
68 |
public Node createForwardNode(DbControl dc, OverviewContext context, Node parentNode) |
6046 |
17 Apr 12 |
nicklas |
69 |
{ |
6046 |
17 Apr 12 |
nicklas |
70 |
return parent.createForwardNode(dc, context, parentNode); |
6046 |
17 Apr 12 |
nicklas |
71 |
} |
6046 |
17 Apr 12 |
nicklas |
72 |
|
6046 |
17 Apr 12 |
nicklas |
73 |
/** |
6046 |
17 Apr 12 |
nicklas |
Call the same method on the 'parent' node loader. |
6046 |
17 Apr 12 |
nicklas |
@return The node that the parent node loader creates (may be null) |
6046 |
17 Apr 12 |
nicklas |
76 |
*/ |
6046 |
17 Apr 12 |
nicklas |
77 |
@Override |
6046 |
17 Apr 12 |
nicklas |
78 |
public Node createPropertyNode(DbControl dc, OverviewContext context, Node parentNode) |
6046 |
17 Apr 12 |
nicklas |
79 |
{ |
6046 |
17 Apr 12 |
nicklas |
80 |
return parent.createPropertyNode(dc, context, parentNode); |
6046 |
17 Apr 12 |
nicklas |
81 |
} |
6046 |
17 Apr 12 |
nicklas |
82 |
|
6046 |
17 Apr 12 |
nicklas |
83 |
/** |
6046 |
17 Apr 12 |
nicklas |
Call the same method on the 'parent' node loader. If one or more |
6046 |
17 Apr 12 |
nicklas |
child nodes are added to the parent node, the |
6046 |
17 Apr 12 |
nicklas |
{@link #loadChildNodes(DbControl, OverviewContext, Node)} is called |
6046 |
17 Apr 12 |
nicklas |
for each of the new nodes. |
6046 |
17 Apr 12 |
nicklas |
@return The node that the parent node loader creates (may be null) |
6046 |
17 Apr 12 |
nicklas |
89 |
*/ |
6046 |
17 Apr 12 |
nicklas |
90 |
@Override |
6046 |
17 Apr 12 |
nicklas |
91 |
public Node createReverseNode(DbControl dc, OverviewContext context, Node childNode) |
6046 |
17 Apr 12 |
nicklas |
92 |
{ |
6046 |
17 Apr 12 |
nicklas |
93 |
return parent.createReverseNode(dc, context, childNode); |
6046 |
17 Apr 12 |
nicklas |
94 |
} |
6046 |
17 Apr 12 |
nicklas |
95 |
|
6046 |
17 Apr 12 |
nicklas |
96 |
/** |
6046 |
17 Apr 12 |
nicklas |
Call the same method on the 'parent' node loader. |
6046 |
17 Apr 12 |
nicklas |
@return The node that the parent node loader creates (may be null) |
6046 |
17 Apr 12 |
nicklas |
99 |
*/ |
6046 |
17 Apr 12 |
nicklas |
100 |
@Override |
6046 |
17 Apr 12 |
nicklas |
101 |
public Node createRootNode(DbControl dc, OverviewContext context, I item) |
6046 |
17 Apr 12 |
nicklas |
102 |
{ |
6046 |
17 Apr 12 |
nicklas |
103 |
return parent.createRootNode(dc, context, item); |
6046 |
17 Apr 12 |
nicklas |
104 |
} |
6046 |
17 Apr 12 |
nicklas |
105 |
|
6046 |
17 Apr 12 |
nicklas |
106 |
/** |
6046 |
17 Apr 12 |
nicklas |
Call the same method on the 'parent' node loader. Then, |
6046 |
17 Apr 12 |
nicklas |
check the extension system for extensions to the 'net.sf.basedb.util.overview.loader' |
6046 |
17 Apr 12 |
nicklas |
extension point and ask the factories for {@link ChildNodeLoaderAction}:s and let |
6046 |
17 Apr 12 |
nicklas |
each of them create their child nodes. |
6046 |
17 Apr 12 |
nicklas |
111 |
|
6046 |
17 Apr 12 |
nicklas |
@return TRUE if new nodes were added to the parent node, FALSE if not |
6046 |
17 Apr 12 |
nicklas |
113 |
*/ |
6046 |
17 Apr 12 |
nicklas |
114 |
@Override |
6046 |
17 Apr 12 |
nicklas |
115 |
public boolean loadChildNodes(DbControl dc, OverviewContext context, Node node) |
6046 |
17 Apr 12 |
nicklas |
116 |
{ |
6046 |
17 Apr 12 |
nicklas |
117 |
if (node.isChildrenLoaded()) return false; |
6046 |
17 Apr 12 |
nicklas |
// Delegate to parent first |
6046 |
17 Apr 12 |
nicklas |
119 |
parent.loadChildNodes(dc, context, node); |
6046 |
17 Apr 12 |
nicklas |
120 |
|
6046 |
17 Apr 12 |
nicklas |
// Create a context with the parent node as the current item |
6046 |
17 Apr 12 |
nicklas |
122 |
ClientContext clientContext = new ClientContext(dc, node); |
6046 |
17 Apr 12 |
nicklas |
123 |
|
6046 |
17 Apr 12 |
nicklas |
// Find and use any registered extensions |
6046 |
17 Apr 12 |
nicklas |
125 |
Registry registry = Application.getExtensionsManager().getRegistry(); |
6088 |
21 Aug 12 |
nicklas |
126 |
Settings settings = Application.getExtensionsManager().getSettings(); |
6046 |
17 Apr 12 |
nicklas |
127 |
ExtensionsInvoker<ChildNodeLoaderAction> invoker = |
7605 |
26 Feb 19 |
nicklas |
128 |
registry.useExtensions(clientContext, settings, "net.sf.basedb.util.overview.loader"); |
6046 |
17 Apr 12 |
nicklas |
129 |
|
6046 |
17 Apr 12 |
nicklas |
130 |
for (ChildNodeLoaderAction a : invoker) |
6046 |
17 Apr 12 |
nicklas |
131 |
{ |
6046 |
17 Apr 12 |
nicklas |
132 |
a.createChildNodes(dc, context, node); |
6046 |
17 Apr 12 |
nicklas |
133 |
} |
6046 |
17 Apr 12 |
nicklas |
134 |
node.setChildrenLoaded(); |
6046 |
17 Apr 12 |
nicklas |
135 |
return node.numChildren() > 0; |
6046 |
17 Apr 12 |
nicklas |
136 |
} |
6046 |
17 Apr 12 |
nicklas |
137 |
// -------------------------------- |
6046 |
17 Apr 12 |
nicklas |
138 |
|
6046 |
17 Apr 12 |
nicklas |
139 |
@Override |
6046 |
17 Apr 12 |
nicklas |
140 |
public String toString() |
6046 |
17 Apr 12 |
nicklas |
141 |
{ |
6046 |
17 Apr 12 |
nicklas |
142 |
return super.toString() + "-->" + parent.toString(); |
6046 |
17 Apr 12 |
nicklas |
143 |
} |
6046 |
17 Apr 12 |
nicklas |
144 |
|
6046 |
17 Apr 12 |
nicklas |
145 |
} |