svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / panelGroup / loaders / PanelGroupLoaderFromList.java @ 40561
History | View | Annotate | Download (4.45 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.gui.beans.panelGroup.loaders; |
25 |
|
26 |
import java.io.Serializable; |
27 |
import java.util.ArrayList; |
28 |
import java.util.Map; |
29 |
|
30 |
import org.gvsig.gui.beans.Messages; |
31 |
import org.gvsig.gui.beans.panelGroup.exceptions.ListCouldntLoadPanelException; |
32 |
import org.gvsig.gui.beans.panelGroup.exceptions.PanelBaseException; |
33 |
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel; |
34 |
import org.gvsig.gui.beans.panelGroup.panels.IPanel; |
35 |
import org.slf4j.Logger; |
36 |
import org.slf4j.LoggerFactory; |
37 |
|
38 |
/**
|
39 |
* <p>Panel loader version that doesn't load the panels, only stores and returns them.</p>
|
40 |
* <p>This loader is useful to mask the load of panels and eliminate the dependence to the extension
|
41 |
* points, and, consequently, the dependence between the <i>libUIComponents</i> project to other
|
42 |
* projects.</p>
|
43 |
* <p>This loader is used together with {@link PanelGroupLoaderUtilities PanelGroupLoaderUtilities} (allocated
|
44 |
* in other project), that is which really loads the panels. First use <code>PanelGroupLoaderUtilities</code>
|
45 |
* and after <code>PanelGroupLoaderFromList</code>.</p>
|
46 |
*
|
47 |
* @see IPanelGroupLoader
|
48 |
*
|
49 |
* @version 15/10/2007
|
50 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
51 |
*/
|
52 |
public class PanelGroupLoaderFromList implements IPanelGroupLoader, Serializable { |
53 |
private static final long serialVersionUID = 3066607004928429045L; |
54 |
final static private Logger logger = LoggerFactory.getLogger(PanelGroupLoaderFromList.class); |
55 |
|
56 |
/**
|
57 |
* Array with the panels loaded.
|
58 |
*
|
59 |
* @see #loadPanels()
|
60 |
*/
|
61 |
private Class<IPanel>[] list; |
62 |
|
63 |
/**
|
64 |
* <p>Initializes this loader with the panels.</p>
|
65 |
*
|
66 |
* @param list array with the panels that this loader supposedly load
|
67 |
*/
|
68 |
public PanelGroupLoaderFromList(Class<IPanel>[] list) { |
69 |
this.list = list;
|
70 |
} |
71 |
|
72 |
/*
|
73 |
* (non-Javadoc)
|
74 |
* @see org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader#loadPanels(java.util.ArrayList)
|
75 |
*/
|
76 |
public void loadPanels(ArrayList<IPanel> panels) throws ListCouldntLoadPanelException { |
77 |
if (list == null) { |
78 |
return;
|
79 |
} |
80 |
|
81 |
ListCouldntLoadPanelException lCLPException = null;
|
82 |
AbstractPanel panel = null;
|
83 |
|
84 |
for (int i = 0; i< list.length; i++) { |
85 |
if (list[i] != null) { |
86 |
try {
|
87 |
panel = null;
|
88 |
panel = (AbstractPanel) list[i].newInstance(); |
89 |
panels.add(panel); |
90 |
} catch (Exception e) { |
91 |
logger.debug(Messages.getText("panel_loading_exception"), e);
|
92 |
|
93 |
if ( lCLPException == null ) { |
94 |
lCLPException = new ListCouldntLoadPanelFromListException();
|
95 |
} |
96 |
|
97 |
PanelBaseException bew = null;
|
98 |
|
99 |
if (panel == null) { |
100 |
bew = new PanelBaseException(e, ""); |
101 |
} else {
|
102 |
bew = new PanelBaseException(e, panel.getLabel());
|
103 |
} |
104 |
|
105 |
lCLPException.add(bew); |
106 |
} |
107 |
} |
108 |
} |
109 |
|
110 |
if ( lCLPException != null ) { |
111 |
throw lCLPException;
|
112 |
} |
113 |
} |
114 |
|
115 |
/**
|
116 |
* <p>Exception produced when fails the load of a panel by a loader of type <code>PanelGroupLoaderFromList</code>.</p>
|
117 |
*
|
118 |
* @version 27/11/2007
|
119 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
120 |
*/
|
121 |
public class ListCouldntLoadPanelFromListException extends ListCouldntLoadPanelException { |
122 |
private static final long serialVersionUID = -8607556361881436022L; |
123 |
|
124 |
private static final String formatString = "Couldn't load some panels from a list of classes:"; |
125 |
private static final String messageKey = "couldnt_load_panels_from_list_exception"; |
126 |
|
127 |
/**
|
128 |
* <p>Creates an initializes a new instance of <code>ListCouldntLoadPanelFromListException</code>.</p>
|
129 |
*/
|
130 |
public ListCouldntLoadPanelFromListException() {
|
131 |
super();
|
132 |
|
133 |
} |
134 |
|
135 |
protected Map<String, String> values() { |
136 |
return null; |
137 |
} |
138 |
} |
139 |
} |
140 |
|