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 | 15734 | vcaballero | /* 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 | 17026 | vcaballero | import java.io.Serializable; |
23 | 17543 | jmvivo | import java.util.ArrayList; |
24 | 17026 | vcaballero | import java.util.Map; |
25 | |||
26 | 17743 | vcaballero | import org.gvsig.gui.beans.Messages; |
27 | 17026 | vcaballero | import org.gvsig.gui.beans.panelGroup.exceptions.ListCouldntLoadPanelException; |
28 | 17543 | jmvivo | import org.gvsig.gui.beans.panelGroup.exceptions.PanelBaseException; |
29 | 15734 | vcaballero | import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel; |
30 | 17026 | vcaballero | import org.gvsig.gui.beans.panelGroup.panels.IPanel; |
31 | 25544 | vcaballero | import org.slf4j.Logger; |
32 | import org.slf4j.LoggerFactory; |
||
33 | 15734 | vcaballero | |
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 | 25544 | vcaballero | * and after <code>PanelGroupLoaderFromList</code>.</p>
|
42 | *
|
||
43 | 15734 | vcaballero | * @see IPanelGroupLoader
|
44 | *
|
||
45 | * @version 15/10/2007
|
||
46 | 25544 | vcaballero | * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
47 | 15734 | vcaballero | */
|
48 | 17026 | vcaballero | public class PanelGroupLoaderFromList implements IPanelGroupLoader, Serializable { |
49 | 17543 | jmvivo | private static final long serialVersionUID = 3066607004928429045L; |
50 | 25544 | vcaballero | final static private Logger logger = LoggerFactory.getLogger(PanelGroupLoaderFromList.class); |
51 | 17026 | vcaballero | |
52 | 15734 | vcaballero | /**
|
53 | * Array with the panels loaded.
|
||
54 | 25544 | vcaballero | *
|
55 | 15734 | vcaballero | * @see #loadPanels()
|
56 | */
|
||
57 | 17026 | vcaballero | private Class<IPanel>[] list; |
58 | 25544 | vcaballero | |
59 | 15734 | vcaballero | /**
|
60 | * <p>Initializes this loader with the panels.</p>
|
||
61 | 25544 | vcaballero | *
|
62 | 15734 | vcaballero | * @param list array with the panels that this loader supposedly load
|
63 | */
|
||
64 | 17026 | vcaballero | public PanelGroupLoaderFromList(Class<IPanel>[] list) { |
65 | 15734 | vcaballero | this.list = list;
|
66 | } |
||
67 | 25544 | vcaballero | |
68 | 15734 | vcaballero | /*
|
69 | * (non-Javadoc)
|
||
70 | 17543 | jmvivo | * @see org.gvsig.gui.beans.panelGroup.loaders.IPanelGroupLoader#loadPanels(java.util.ArrayList)
|
71 | 15734 | vcaballero | */
|
72 | 17543 | jmvivo | public void loadPanels(ArrayList<IPanel> panels) throws ListCouldntLoadPanelException { |
73 | 23745 | jjdelcerro | if (list == null) { |
74 | 17543 | jmvivo | return;
|
75 | 23745 | jjdelcerro | } |
76 | 17543 | jmvivo | |
77 | ListCouldntLoadPanelException lCLPException = null;
|
||
78 | AbstractPanel panel = null;
|
||
79 | 25544 | vcaballero | |
80 | 15734 | vcaballero | for (int i = 0; i< list.length; i++) { |
81 | 17026 | vcaballero | if (list[i] != null) { |
82 | try {
|
||
83 | 17543 | jmvivo | panel = null;
|
84 | panel = (AbstractPanel) list[i].newInstance(); |
||
85 | panels.add(panel); |
||
86 | } catch (Exception e) { |
||
87 | 25544 | vcaballero | logger.debug(Messages.getText("panel_loading_exception"), e);
|
88 | |||
89 | 17026 | vcaballero | if ( lCLPException == null ) { |
90 | lCLPException = new ListCouldntLoadPanelFromListException();
|
||
91 | } |
||
92 | |||
93 | 17543 | jmvivo | PanelBaseException bew = null;
|
94 | 25544 | vcaballero | |
95 | 23745 | jjdelcerro | if (panel == null) { |
96 | 17543 | jmvivo | bew = new PanelBaseException(e, ""); |
97 | 23745 | jjdelcerro | } else {
|
98 | 17543 | jmvivo | bew = new PanelBaseException(e, panel.getLabel());
|
99 | 23745 | jjdelcerro | } |
100 | 17543 | jmvivo | |
101 | lCLPException.add(bew); |
||
102 | 17026 | vcaballero | } |
103 | } |
||
104 | 15734 | vcaballero | } |
105 | 17026 | vcaballero | |
106 | if ( lCLPException != null ) { |
||
107 | throw lCLPException;
|
||
108 | } |
||
109 | 15734 | vcaballero | } |
110 | 17026 | vcaballero | |
111 | /**
|
||
112 | * <p>Exception produced when fails the load of a panel by a loader of type <code>PanelGroupLoaderFromList</code>.</p>
|
||
113 | 25544 | vcaballero | *
|
114 | 17026 | vcaballero | * @version 27/11/2007
|
115 | 25544 | vcaballero | * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
116 | 17026 | vcaballero | */
|
117 | public class ListCouldntLoadPanelFromListException extends ListCouldntLoadPanelException { |
||
118 | private static final long serialVersionUID = -8607556361881436022L; |
||
119 | |||
120 | 27723 | jmvivo | 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 | 17026 | vcaballero | /**
|
124 | 25544 | vcaballero | * <p>Creates an initializes a new instance of <code>ListCouldntLoadPanelFromListException</code>.</p>
|
125 | 17026 | vcaballero | */
|
126 | public ListCouldntLoadPanelFromListException() {
|
||
127 | super();
|
||
128 | 25544 | vcaballero | |
129 | 17026 | vcaballero | } |
130 | 25544 | vcaballero | |
131 | 17543 | jmvivo | protected Map<String, String> values() { |
132 | 17026 | vcaballero | return null; |
133 | } |
||
134 | } |
||
135 | 15734 | vcaballero | } |