Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extPublish / src / org / gvsig / publish / gui / wizard / PublishWizardPanel.java @ 19900

History | View | Annotate | Download (12.1 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.JTree;
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.publish.IPublishPluginPanel;
54
import org.gvsig.publish.serversmodel.Publication;
55
import org.gvsig.publish.serversmodel.Service;
56
/**
57
 * Wizard for showing server properties. Useful when the server has only one service.  
58
 * 
59
 * @author jvhigon
60
 *
61
 */
62
public class PublishWizardPanel extends JPanel implements IPublishPluginPanel, ActionListener{
63
        /**
64
         * Generated versionUID
65
         */
66
        private static final long serialVersionUID = 8029981939846754399L;
67
        //Associations
68
        private Publication publication;
69
        
70
        //events
71
        private final String ISADVANCED_EVENT="isadvanced_event";
72
        private final String NEXT_PANEL_EVENT="next_panel_event";
73
        private final String PREV_PANEL_EVENT="prev_panel_event";
74
        
75
        //Constructor
76
        /**
77
         * Default constructor, initialize components and labels
78
         */
79
        public PublishWizardPanel() {                
80
                initComponents();        
81
                remoteSplitPane.setDividerLocation(0.5);                
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
        remoteTreePane.setViewportView(remoteTree);
151
        remoteTree.setRootVisible(false);
152
        remoteSplitPane.setLeftComponent(remoteTreePane);
153

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

    
158
        remoteScrollPane.setViewportView(remotePane);
159

    
160
        remoteSplitPane.setRightComponent(remoteScrollPane);
161

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

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

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

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

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

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

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

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

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

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

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

    
241
        }
242
        /**
243
         * TODO: I am not sure if this is the best location to do that
244
         * sets the model in each pluginpanel
245
         */
246
        public void setModel(Object entityModel) {
247
                this.publication = (Publication)entityModel;
248
                //initializes the tree
249
                Service service = publication.getServer().getService(0);
250
                TreeModel treemodel = new ServiceTreeModel(service);
251
                this.remoteTree.setModel(treemodel);        
252
                expandAll(remoteTree);
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
         * Enable/disable the previous button
331
         * @param enabled
332
         */
333
        public void setEnabledPrevButton(boolean enabled){
334
                prevButton.setEnabled(enabled);
335
        }
336
        /**
337
         * Enable/disable the next button
338
         * @param enabled
339
         */
340
        public void setEnabledNextButton(boolean enabled){
341
                nextButton.setEnabled(enabled);
342
        }
343
        /**
344
         * Select the tab to be focused
345
         * @param tab
346
         */
347
        public void setSelectedTab(int tab){
348
                mainTabPanel.setSelectedIndex(tab);
349
        }
350
        /**
351
         * 
352
         * @return the select tab
353
         */
354
        public int getSelectedTab(){
355
                return mainTabPanel.getSelectedIndex();
356
        }
357

    
358
        /**
359
         * Expands all tree nodes
360
         * 
361
         * @param tree
362
         */
363
        public void expandAll(JTree tree) {
364
            int row = 0;
365
            while (row < tree.getRowCount()) {
366
              tree.expandRow(row);
367
              row++;
368
              }
369
        }
370
   
371
}