Statistics
| Revision:

root / branches / v10 / extensions / extPublish / src / org / gvsig / publish / gui / wizard / PublishWizardPanel.java @ 19419

History | View | Annotate | Download (12 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004-2006 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
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Iba?ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.publish.gui.wizard;
42

    
43
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionListener;
45
import java.util.EventListener;
46

    
47
import javax.swing.JPanel;
48
import javax.swing.event.ChangeEvent;
49
import javax.swing.event.ChangeListener;
50
import javax.swing.event.TreeSelectionListener;
51
import javax.swing.tree.TreeModel;
52

    
53
import org.gvsig.publish.gui.addResource.AddResourceController;
54
import org.gvsig.publish.gui.publish.IPublishPluginPanel;
55
import org.gvsig.publish.serversmodel.Publication;
56
import org.gvsig.publish.serversmodel.Service;
57
/**
58
 * Wizard for showing server properties. Useful when the server has only one service.  
59
 * 
60
 * @author jvhigon
61
 *
62
 */
63
public class PublishWizardPanel extends JPanel implements IPublishPluginPanel, ActionListener, ChangeListener {
64
        /**
65
         * Generated versionUID
66
         */
67
        private static final long serialVersionUID = 8029981939846754399L;
68
        //Associations
69
        private Publication publication;
70
        
71
        //events
72
        private final String ISADVANCED_EVENT="isadvanced_event";
73
        private final String NEXT_PANEL_EVENT="next_panel_event";
74
        private final String PREV_PANEL_EVENT="prev_panel_event";
75
        
76
        //Constructor
77
        /**
78
         * Default constructor, initialize components and labels
79
         */
80
        public PublishWizardPanel() {                
81
                initComponents();
82
                initLabels();
83
                initIcons();
84
        }
85
        /**
86
         * Initialize icons from the classpath
87
         */
88
        private void initIcons() {
89
                
90
        mainTabPanel.setIconAt(0, new javax.swing.ImageIcon(getClass().getClassLoader().getResource("images/publish-server.png")));
91
        mainTabPanel.setIconAt(1, new javax.swing.ImageIcon(getClass().getClassLoader().getResource("images/publish-service.png")));
92
        mainTabPanel.setIconAt(2, new javax.swing.ImageIcon(getClass().getClassLoader().getResource("images/publish-rr.png")));
93
        }
94
        /**
95
         * Initialize gui labels for multilanguage 
96
         */
97
        private void initLabels() {
98
                // TODO Auto-generated method stub
99
                
100
        }
101
    private void initComponents() {
102

    
103
        mainTabPanel = new javax.swing.JTabbedPane();
104
        serverTab = new javax.swing.JScrollPane();
105
        serverPane = new javax.swing.JPanel();
106
        serverBasicPane = new javax.swing.JPanel();
107
        serverAdvancedPane = new javax.swing.JPanel();
108
        serviceTab = new javax.swing.JScrollPane();
109
        servicePane = new javax.swing.JPanel();
110
        serviceBasicPane = new javax.swing.JPanel();
111
        serviceAdvancedPane = new javax.swing.JPanel();
112
        remoteTab = new javax.swing.JPanel();
113
        remoteSplitPane = new javax.swing.JSplitPane();
114
        remoteTreePane = new javax.swing.JScrollPane();
115
        remoteTree = new javax.swing.JTree();
116
        remoteScrollPane = new javax.swing.JScrollPane();
117
        remotePane = new javax.swing.JPanel();
118
        remoteBasicPane = new javax.swing.JPanel();
119
        remoteAdvancedPane = new javax.swing.JPanel();
120
        buttonsPanel = new javax.swing.JPanel();
121
        showAdvanced = new javax.swing.JCheckBox();
122
        addButton = new org.gvsig.gui.beans.swing.JButton();
123
        prevButton = new org.gvsig.gui.beans.swing.JButton();
124
        nextButton = new org.gvsig.gui.beans.swing.JButton();
125

    
126
        setBorder(javax.swing.BorderFactory.createEmptyBorder(2, 2, 2, 2));
127
        setLayout(new java.awt.BorderLayout());
128

    
129
        serverPane.setLayout(new java.awt.BorderLayout());
130
        serverPane.add(serverBasicPane, java.awt.BorderLayout.CENTER);
131
        serverPane.add(serverAdvancedPane, java.awt.BorderLayout.SOUTH);
132

    
133
        serverTab.setViewportView(serverPane);
134

    
135
        mainTabPanel.addTab("server_tab", serverTab);
136

    
137
        servicePane.setLayout(new java.awt.BorderLayout());
138
        servicePane.add(serviceBasicPane, java.awt.BorderLayout.CENTER);
139
        servicePane.add(serviceAdvancedPane, java.awt.BorderLayout.SOUTH);
140

    
141
        serviceTab.setViewportView(servicePane);
142

    
143
        mainTabPanel.addTab("service_tab", serviceTab);
144

    
145
        remoteTab.setLayout(new java.awt.BorderLayout());
146

    
147
        remoteSplitPane.setDividerLocation(100);
148

    
149
        remoteTree.setMinimumSize(new java.awt.Dimension(50, 0));
150
        remoteTree.setRootVisible(false);
151
        remoteTreePane.setViewportView(remoteTree);
152

    
153
        remoteSplitPane.setLeftComponent(remoteTreePane);
154

    
155
        remotePane.setLayout(new java.awt.BorderLayout());
156
        remotePane.add(remoteBasicPane, java.awt.BorderLayout.CENTER);
157
        remotePane.add(remoteAdvancedPane, java.awt.BorderLayout.SOUTH);
158

    
159
        remoteScrollPane.setViewportView(remotePane);
160

    
161
        remoteSplitPane.setRightComponent(remoteScrollPane);
162

    
163
        remoteTab.add(remoteSplitPane, java.awt.BorderLayout.CENTER);
164

    
165
        mainTabPanel.addTab("remote_tab", remoteTab);
166

    
167
        add(mainTabPanel, java.awt.BorderLayout.CENTER);
168

    
169
        buttonsPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
170
        buttonsPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
171

    
172
        showAdvanced.setText("show_advanced");
173
        buttonsPanel.add(showAdvanced);
174

    
175
        addButton.setText("add_resource");
176
        buttonsPanel.add(addButton);
177

    
178
        prevButton.setText("prev");
179
        prevButton.setEnabled(false);
180
        buttonsPanel.add(prevButton);
181

    
182
        nextButton.setText("next");
183
        buttonsPanel.add(nextButton);
184

    
185
        add(buttonsPanel, java.awt.BorderLayout.SOUTH);
186
    }// </editor-fold>
187
    // Variables declaration - do not modify
188
    private org.gvsig.gui.beans.swing.JButton addButton;
189
    private javax.swing.JPanel buttonsPanel;
190
    private javax.swing.JTabbedPane mainTabPanel;
191
    private org.gvsig.gui.beans.swing.JButton nextButton;
192
    private org.gvsig.gui.beans.swing.JButton prevButton;
193
    private javax.swing.JPanel remoteAdvancedPane;
194
    private javax.swing.JPanel remoteBasicPane;
195
    private javax.swing.JPanel remotePane;
196
    private javax.swing.JScrollPane remoteScrollPane;
197
    private javax.swing.JSplitPane remoteSplitPane;
198
    private javax.swing.JPanel remoteTab;
199
    private javax.swing.JTree remoteTree;
200
    private javax.swing.JScrollPane remoteTreePane;
201
    private javax.swing.JPanel serverAdvancedPane;
202
    private javax.swing.JPanel serverBasicPane;
203
    private javax.swing.JPanel serverPane;
204
    private javax.swing.JScrollPane serverTab;
205
    private javax.swing.JPanel serviceAdvancedPane;
206
    private javax.swing.JPanel serviceBasicPane;
207
    private javax.swing.JPanel servicePane;
208
    private javax.swing.JScrollPane serviceTab;
209
    private javax.swing.JCheckBox showAdvanced;
210
    // End of variables declaration
211

    
212
        /**
213
     * Gets the publication, updates the model from the GUI
214
     */
215
        public Object getModel() {
216
                
217
                return publication;
218
        }
219
        /**
220
         * sets listeners for all components
221
         */
222
        public void setListener(EventListener listener) {
223
                //listener for tabs                
224
                mainTabPanel.addChangeListener(this);
225
                
226
                //listener for buttons
227
                addButton.addActionListener((ActionListener)listener);
228
                addButton.setActionCommand(PublishWizardController.ADD_RESOURCE_EVENT);
229
                
230
                nextButton.addActionListener(this);
231
                nextButton.setActionCommand(NEXT_PANEL_EVENT);
232
                prevButton.addActionListener(this);
233
                prevButton.setActionCommand(PREV_PANEL_EVENT);
234

    
235
                //listener for checkbox
236
                this.showAdvanced.addActionListener(this);
237
                this.showAdvanced.setActionCommand(ISADVANCED_EVENT);
238
                
239
                //listener for the tree
240
                remoteTree.addTreeSelectionListener((TreeSelectionListener) listener);
241

    
242
        }
243
        /**
244
         * TODO: I am not sure if this is the best location to do that
245
         * sets the model in each pluginpanel
246
         */
247
        public void setModel(Object entityModel) {
248
                this.publication = (Publication)entityModel;
249
                //initializes the tree
250
                Service service = publication.getServer().getService(0);
251
                TreeModel treemodel = new ServiceTreeModel(service);
252
                this.remoteTree.setModel(treemodel);                
253
        }
254
        
255
        /**
256
         * If you set true, you will be able to see the advanced panels
257
         * @param isAdvanced
258
         */
259
        public void setAdvanced(boolean isAdvanced) {                
260
                serverAdvancedPane.setVisible(isAdvanced);
261
                serviceAdvancedPane.setVisible(isAdvanced);
262
                remoteAdvancedPane.setVisible(isAdvanced);                
263
        }
264
        /**
265
         * sets the server basic panel
266
         * @param serverPanel
267
         */
268
        public void setServerBasicPanel(IPublishPluginPanel pluginPanel) {                
269
                serverPane.remove(serverBasicPane);
270
                this.serverBasicPane = (JPanel)pluginPanel;
271
                
272
                serverPane.add(serverBasicPane, java.awt.BorderLayout.NORTH);
273
        }
274
        public void setServerAdvancedPanel(IPublishPluginPanel pluginPanel) {                
275
                serverPane.remove(serverAdvancedPane);
276
                this.serverAdvancedPane = (JPanel)pluginPanel;
277
                serverPane.add(serverAdvancedPane, java.awt.BorderLayout.CENTER);
278
                setAdvanced(showAdvanced.isSelected());
279
        }
280
        public void setServiceBasicPanel(IPublishPluginPanel pluginPanel) {
281
                servicePane.remove(serviceBasicPane);
282
                this.serviceBasicPane=(JPanel)pluginPanel;
283
                servicePane.add(serviceBasicPane, java.awt.BorderLayout.NORTH);        
284
        }
285
        public void setServiceAdvancedPanel(IPublishPluginPanel pluginPanel) {
286
                servicePane.remove(serviceAdvancedPane);
287
                this.serviceAdvancedPane = (JPanel)pluginPanel;                
288
                servicePane.add(serviceAdvancedPane, java.awt.BorderLayout.CENTER);
289
                setAdvanced(showAdvanced.isSelected());
290
        }
291
        public void setRemoteResourceBasicPanel(IPublishPluginPanel pluginPanel) {
292
                remotePane.remove(remoteBasicPane);
293
                this.remoteBasicPane = (JPanel)pluginPanel;
294
        remotePane.add(remoteBasicPane, java.awt.BorderLayout.NORTH);
295
        //repaint container?
296
        remotePane.doLayout();
297
        }
298
        public void setRemoteResourceAdvancedPanel(IPublishPluginPanel pluginPanel) {
299
                remotePane.remove(remoteAdvancedPane);
300
                this.remoteAdvancedPane = (JPanel)pluginPanel;
301
        remotePane.add(remoteAdvancedPane, java.awt.BorderLayout.CENTER);
302
                setAdvanced(showAdvanced.isSelected());
303
        }
304
        public void actionPerformed(ActionEvent e) {
305
                //active advanced properties
306
                if (e.getActionCommand().equals(ISADVANCED_EVENT)){                        
307
                        if (showAdvanced.isSelected()){
308
                                setAdvanced(true);
309
                        }else{
310
                                setAdvanced(false);
311
                        }
312
                        return;
313
                }
314
                //click next button
315
                if (e.getActionCommand().equals(NEXT_PANEL_EVENT)){
316
                        int tab = mainTabPanel.getSelectedIndex();
317
                        if (tab < mainTabPanel.getTabCount()-1){
318
                                mainTabPanel.setSelectedIndex(tab+1);
319
                        }
320
                }
321
                //click prev button
322
                if (e.getActionCommand().equals(PREV_PANEL_EVENT)){
323
                        int tab = mainTabPanel.getSelectedIndex();
324
                        if (tab > 0){
325
                                mainTabPanel.setSelectedIndex(tab-1);
326
                        }
327
                }                
328
        }
329
        /**
330
         * I must get the model from the gui and change the tab
331
         */
332
        public void stateChanged(ChangeEvent e) {
333
                int tab = mainTabPanel.getSelectedIndex();
334
                if (tab==0){
335
                        prevButton.setEnabled(false);
336
                }else{ 
337
                        prevButton.setEnabled(true);
338
                }
339
                if (tab==2){
340
                        nextButton.setEnabled(false);
341
                        //if there isn't resource the addresource use case is called
342
                        if (publication.getServer().getService(0).getRemoteResourcesCount() == 0){
343
                                AddResourceController addResourceCtrl = new AddResourceController();
344
                                addResourceCtrl.setPublication(publication);
345
                                addResourceCtrl.showWindow();
346
                                mainTabPanel.setSelectedIndex(2);
347
                        }
348
                }else{
349
                        nextButton.setEnabled(true);
350
                }
351
                getModel();                                                                                        
352
        }
353

    
354
}