root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / gui / WizardPanel.java @ 38564
History | View | Annotate | Download (5.78 KB)
1 | 36628 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 1103 | fjp | *
|
3 | 36628 | cordinyana | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 | * of the Valencian Government (CIT)
|
||
5 | 1103 | fjp | *
|
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 2
|
||
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 | 36628 | cordinyana | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 1103 | fjp | *
|
21 | */
|
||
22 | 29598 | jpiera | package org.gvsig.app.gui; |
23 | 858 | fernando | |
24 | 34937 | jjdelcerro | import java.awt.Window; |
25 | |||
26 | 858 | fernando | import javax.swing.JPanel; |
27 | |||
28 | 36760 | nbrodin | import org.cresques.cts.IProjection; |
29 | 34937 | jjdelcerro | import org.gvsig.andami.messages.NotificationManager; |
30 | import org.gvsig.app.ApplicationLocator; |
||
31 | import org.gvsig.app.ApplicationManager; |
||
32 | 29598 | jpiera | import org.gvsig.app.gui.wizards.WizardListener; |
33 | import org.gvsig.app.gui.wizards.WizardListenerSupport; |
||
34 | 34937 | jjdelcerro | import org.gvsig.app.prepareAction.PrepareContextView; |
35 | 24759 | jmvivo | import org.gvsig.fmap.dal.DataStoreParameters; |
36 | 34937 | jjdelcerro | import org.gvsig.fmap.mapcontext.MapContext; |
37 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
38 | import org.gvsig.fmap.mapcontext.MapContextManager; |
||
39 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
40 | 20994 | jmvivo | import org.gvsig.fmap.mapcontrol.MapControl; |
41 | 37827 | jjdelcerro | import org.slf4j.Logger; |
42 | import org.slf4j.LoggerFactory; |
||
43 | 20994 | jmvivo | |
44 | 36628 | cordinyana | public abstract class WizardPanel extends JPanel { |
45 | 858 | fernando | |
46 | 37827 | jjdelcerro | private static final Logger logger = LoggerFactory.getLogger(WizardPanel.class); |
47 | 36628 | cordinyana | private static final long serialVersionUID = 5317749209668850863L; |
48 | private String tabName = "TabName"; |
||
49 | 3083 | fjp | private MapControl mapCtrl = null; |
50 | 36628 | cordinyana | private WizardListenerSupport listenerSupport = new WizardListenerSupport(); |
51 | 858 | fernando | |
52 | 36628 | cordinyana | public void addWizardListener(WizardListener listener) { |
53 | listenerSupport.addWizardListener(listener); |
||
54 | } |
||
55 | 31284 | cordinyana | |
56 | 36628 | cordinyana | public void callError(Exception descripcion) { |
57 | listenerSupport.callError(descripcion); |
||
58 | } |
||
59 | 31284 | cordinyana | |
60 | 36628 | cordinyana | public void removeWizardListener(WizardListener listener) { |
61 | listenerSupport.removeWizardListener(listener); |
||
62 | } |
||
63 | |||
64 | public void callStateChanged(boolean finishable) { |
||
65 | listenerSupport.callStateChanged(finishable); |
||
66 | } |
||
67 | |||
68 | protected void setTabName(String name) { |
||
69 | tabName = name; |
||
70 | } |
||
71 | |||
72 | public String getTabName() { |
||
73 | return tabName;
|
||
74 | } |
||
75 | |||
76 | abstract public void initWizard(); |
||
77 | |||
78 | 36631 | cordinyana | /**
|
79 | * @deprecated use {@link #executeWizard()} instead.
|
||
80 | */
|
||
81 | 36628 | cordinyana | abstract public void execute(); |
82 | |||
83 | 36631 | cordinyana | /**
|
84 | * Executes the wizard and returns anything created in the process.
|
||
85 | *
|
||
86 | * @return anything created in the process
|
||
87 | */
|
||
88 | public Object executeWizard() { |
||
89 | execute(); |
||
90 | return null; |
||
91 | } |
||
92 | |||
93 | 36628 | cordinyana | abstract public void close(); |
94 | |||
95 | abstract public DataStoreParameters[] getParameters(); |
||
96 | |||
97 | 3083 | fjp | /**
|
98 | * You can use it to extract information from
|
||
99 | * the mapControl that will receive the new layer.
|
||
100 | * For example, projection to use, or visible extent.
|
||
101 | 36628 | cordinyana | *
|
102 | 3083 | fjp | * @return Returns the mapCtrl.
|
103 | */
|
||
104 | public MapControl getMapCtrl() {
|
||
105 | return mapCtrl;
|
||
106 | } |
||
107 | 36628 | cordinyana | |
108 | 3083 | fjp | /**
|
109 | 36628 | cordinyana | * @param mapCtrl
|
110 | * The mapCtrl to set.
|
||
111 | 3083 | fjp | */
|
112 | public void setMapCtrl(MapControl mapCtrl) { |
||
113 | this.mapCtrl = mapCtrl;
|
||
114 | } |
||
115 | 36628 | cordinyana | |
116 | 34937 | jjdelcerro | protected void doAddLayer(final MapControl mapControl, |
117 | final String layerName, final DataStoreParameters parameters) { |
||
118 | final ApplicationManager application = ApplicationLocator.getManager();
|
||
119 | final MapContextManager manager =
|
||
120 | MapContextLocator.getMapContextManager(); |
||
121 | final MapContext mapContext = mapControl.getMapContext();
|
||
122 | |||
123 | 37827 | jjdelcerro | logger.info("addLayer('{}','{}')", layerName, parameters.toString());
|
124 | 34937 | jjdelcerro | Thread task = new Thread(new Runnable() { |
125 | |||
126 | public void run() { |
||
127 | FLayer layer = null;
|
||
128 | FLayer preparedLayer = null;
|
||
129 | try {
|
||
130 | layer = manager.createLayer(layerName, parameters); |
||
131 | preparedLayer = |
||
132 | application.prepareOpenLayer(layer, |
||
133 | new PrepareContextView() {
|
||
134 | |||
135 | public Window getOwnerWindow() { |
||
136 | return null; |
||
137 | } |
||
138 | |||
139 | public MapControl getMapControl() {
|
||
140 | return mapControl;
|
||
141 | } |
||
142 | 36760 | nbrodin | |
143 | public IProjection getViewProjection() {
|
||
144 | return mapControl.getProjection();
|
||
145 | } |
||
146 | 34937 | jjdelcerro | }); |
147 | if (preparedLayer != null) { |
||
148 | mapContext.getLayers().addLayer(preparedLayer); |
||
149 | } |
||
150 | } catch (Exception e) { |
||
151 | NotificationManager.addError(e); |
||
152 | return;
|
||
153 | } finally {
|
||
154 | if (preparedLayer != null && preparedLayer != layer) { |
||
155 | preparedLayer.dispose(); |
||
156 | preparedLayer = null;
|
||
157 | } |
||
158 | if (layer != null) { |
||
159 | layer.dispose(); |
||
160 | layer = null;
|
||
161 | } |
||
162 | } |
||
163 | } |
||
164 | }); |
||
165 | task.start(); |
||
166 | } |
||
167 | 38518 | jldominguez | |
168 | 38519 | jldominguez | /**
|
169 | * This method is called for example when user changes
|
||
170 | * tab in add layer dialog (new tab's settings are valid?)
|
||
171 | *
|
||
172 | * @return whether current wizard settings are enough
|
||
173 | * (for example, to enable an Accept button in a container)
|
||
174 | */
|
||
175 | public boolean areSettingsValid() { |
||
176 | return true; |
||
177 | } |
||
178 | 858 | fernando | } |