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