Revision 332

View differences:

org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.10/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/StepIdentification.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.educa.portableview.swing.impl.editor;
23

  
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27

  
28
import javax.swing.JComponent;
29
import javax.swing.JLabel;
30
import javax.swing.JPanel;
31
import javax.swing.JScrollPane;
32
import javax.swing.JTextArea;
33
import javax.swing.JTextField;
34

  
35
import org.apache.commons.lang3.StringUtils;
36

  
37
import org.gvsig.educa.portableview.compilation.PortableViewCompilation;
38
import org.gvsig.educa.portableview.compilation.PortableViewCompilationInformation;
39
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
40
import org.gvsig.educa.portableview.swing.PortableViewSwingManager;
41
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
42
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
43

  
44
/**
45
 *
46
 * {@link DefaultPortableViewCompilationEditor} step which allows set/modify
47
 * information data of the compilation
48
 *
49
 * @author gvSIG Team
50
 * @version $Id$
51
 *
52
 */
53
public class StepIdentification extends JPanel implements OptionPanel {
54

  
55
    /**
56
     *
57
     */
58
    private static final long serialVersionUID = 5061121028061557890L;
59

  
60
    private static final GridBagConstraints LABEL_CONSTRAINT =
61
        new GridBagConstraints(GridBagConstraints.RELATIVE,
62
            GridBagConstraints.RELATIVE, 1, 1, 0, 0, GridBagConstraints.WEST,
63
            GridBagConstraints.NONE, new Insets(4, 4, 4, 10), 2, 2);
64

  
65
    private static final GridBagConstraints LARGE_LABEL_CONSTRAINT =
66
        new GridBagConstraints(GridBagConstraints.RELATIVE,
67
            GridBagConstraints.RELATIVE, 1, 3, 0, 0, GridBagConstraints.WEST,
68
            GridBagConstraints.NONE, new Insets(4, 4, 4, 10), 2, 2);
69

  
70
    private static final GridBagConstraints FIELD_CONSTRAINT =
71
        new GridBagConstraints(GridBagConstraints.RELATIVE,
72
            GridBagConstraints.RELATIVE, GridBagConstraints.REMAINDER, 1, 1, 0,
73
            GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(
74
                4, 4, 4, 10), 2, 2);
75

  
76
    private static final GridBagConstraints LARGE_FIELD_CONSTRAINT =
77
        new GridBagConstraints(GridBagConstraints.RELATIVE,
78
            GridBagConstraints.RELATIVE, GridBagConstraints.REMAINDER, 3, 1, 1,
79
            GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(4, 4,
80
                4, 10), 2, 2);
81

  
82
    private final PortableViewCompilation compilation;
83

  
84
    private final PortableViewSwingManager swingManager;
85

  
86
    @SuppressWarnings("unused")
87
    private final DefaultPortableViewCompilationEditor editor;
88

  
89
    private JTextField txtId;
90

  
91
    private JTextField txtName;
92

  
93
    private JTextField txtVersion;
94

  
95
    private JTextArea txtDescription;
96

  
97
    private boolean allowChangeId;
98

  
99
    /**
100
     * @param defaultPortableViewCompilationEditor
101
     * @param allowChangeId
102
     */
103
    public StepIdentification(
104
        DefaultPortableViewCompilationEditor defaultPortableViewCompilationEditor,
105
        boolean allowChangeId) {
106
        swingManager = PortableViewSwingLocator.getSwingManager();
107
        this.editor = defaultPortableViewCompilationEditor;
108
        this.compilation = defaultPortableViewCompilationEditor.getCompilation();
109
        this.allowChangeId = allowChangeId;
110
        initializeUI();
111
    }
112

  
113
    /**
114
     * Initialize UI components
115
     */
116
    private void initializeUI() {
117
        setLayout(new GridBagLayout());
118

  
119
        // Create input widgets
120
        txtId = new JTextField();
121
        txtId.setEditable(allowChangeId);
122
        txtName = new JTextField();
123
        txtVersion = new JTextField();
124
        txtDescription = new JTextArea();
125
        JScrollPane scrDescription = new JScrollPane(txtDescription);
126

  
127
        // Add components
128
        addField("portable_view_id", txtId, false);
129
        addField("portable_view_name", txtName, false);
130
        addField("portable_view_version", txtVersion, false);
131
        addField("portable_view_description", scrDescription, true);
132
    }
133

  
134
    /**
135
     * Add field to form
136
     *
137
     * @param key
138
     *            translation key for field name
139
     * @param component
140
     *            file input component
141
     * @param large
142
     *            if field is large
143
     */
144
    private void addField(String key, JComponent component, boolean large) {
145
        GridBagConstraints gbc = LABEL_CONSTRAINT;
146
        if (large) {
147
            gbc = LARGE_LABEL_CONSTRAINT;
148
        }
149
        add(new JLabel(swingManager.getTranslation(key)), gbc.clone());
150
        gbc = FIELD_CONSTRAINT;
151
        if (large) {
152
            gbc = LARGE_FIELD_CONSTRAINT;
153
        }
154
        add(component, gbc.clone());
155
    }
156

  
157
    /** {@inheridDoc} */
158
    public String getPanelTitle() {
159
        return swingManager.getTranslation("portable_view_information");
160
    }
161

  
162
    /** {@inheridDoc} */
163
    public void nextPanel() throws NotContinueWizardException {
164
        if (StringUtils.isBlank(txtId.getText())) {
165
            throw new NotContinueWizardException(
166
                swingManager.getTranslation("missing_id_value"), txtId, true);
167
        }
168
        if (StringUtils.isBlank(txtName.getText())) {
169
            throw new NotContinueWizardException(
170
                swingManager.getTranslation("missing_name_value"), txtName,
171
                true);
172
        }
173
        if (StringUtils.isBlank(txtVersion.getText())) {
174
            txtVersion.setText("1");
175
        }
176
        if (!StringUtils.isNumeric(txtVersion.getText())) {
177
            throw new NotContinueWizardException(
178
                swingManager.getTranslation("version_must_be_a_integer"),
179
                txtName, true);
180
        }
181
        PortableViewCompilationInformation info = compilation.getInformation();
182
        if (allowChangeId) {
183
            info.setId(StringUtils.trim(txtId.getText()));
184
        }
185
        info.setName(StringUtils.trim(txtName.getText()));
186
        info.setVersion(Integer.parseInt(StringUtils.trim(txtVersion.getText())));
187
        info.setDescription(StringUtils.trim(txtDescription.getText()));
188
    }
189

  
190
    /** {@inheridDoc} */
191
    public void lastPanel() {
192
        // TODO Auto-generated method stub
193

  
194
    }
195

  
196
    /** {@inheridDoc} */
197
    public void updatePanel() {
198
        PortableViewCompilationInformation info = compilation.getInformation();
199
        txtId.setText(info.getId());
200
        txtName.setText(info.getName());
201
        txtVersion.setText(String.valueOf(info.getVersion()));
202
        txtDescription.setText(info.getDescription());
203
    }
204

  
205
    /** {@inheridDoc} */
206
    public JPanel getJPanel() {
207
        return this;
208
    }
209

  
210
    /**
211
     * Informs if all data of the panel is ok
212
     *
213
     * @return
214
     */
215
    public boolean isPanelDataOk() {
216
        try {
217
            nextPanel();
218
        } catch (NotContinueWizardException ex) {
219
            return false;
220
        }
221
        return true;
222
    }
223

  
224
    public boolean isAllowChangeId() {
225
        return allowChangeId;
226
    }
227

  
228
    public void allowChangeId(boolean allow) {
229
        this.allowChangeId = allow;
230
        if (txtId != null) {
231
            txtId.setEnabled(allow);
232
        }
233

  
234
    }
235

  
236
}
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.10/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/addlayer/StoreParametersCellEditor.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.educa.portableview.swing.impl.editor.addlayer;
23

  
24
import java.awt.Component;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30

  
31
import javax.swing.AbstractCellEditor;
32
import javax.swing.JButton;
33
import javax.swing.JPanel;
34
import javax.swing.JTable;
35
import javax.swing.table.TableCellEditor;
36

  
37
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
38
import org.gvsig.educa.portableview.swing.PortableViewSwingManager;
39
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE;
40

  
41
/**
42
 * <p>
43
 * Store Parameters Table cell editor for
44
 * {@link DefaultPortableViewAddLayerComponent} sources list
45
 * </p>
46
 * <p>
47
 * Shows store parameter description (delegates on
48
 * {@link StoreParametersCellRenderer}) and a button which shows a dialog (
49
 * {@link StoreParametersEditor}) to modify the values.
50
 * </p>
51
 *
52
 * @author gvSIG Team
53
 * @version $Id$
54
 *
55
 */
56
public class StoreParametersCellEditor extends AbstractCellEditor implements
57
    ActionListener, TableCellEditor {
58

  
59
    /**
60
     *
61
     */
62
    private static final long serialVersionUID = -6112666198058347246L;
63

  
64
    private final PortableViewSwingManager swingManager;
65

  
66
    private final JPanel panel;
67
    private final StoreParametersCellRenderer renderer;
68
    private final JButton button;
69

  
70
    private final GridBagConstraints constrainLabel;
71
    private final GridBagConstraints constrainButton;
72

  
73
    /**
74
     *
75
     */
76
    public StoreParametersCellEditor() {
77
        swingManager = PortableViewSwingLocator.getSwingManager();
78
        panel = new JPanel(new GridBagLayout());
79
        renderer = new StoreParametersCellRenderer();
80
        this.button = new JButton("...");
81
        this.button.addActionListener(this);
82
        constrainLabel = new GridBagConstraints();
83
        constrainLabel.gridx = 0;
84
        constrainLabel.gridy = 0;
85
        constrainLabel.fill = GridBagConstraints.BOTH;
86
        constrainLabel.weightx = 1;
87
        constrainLabel.weighty = 1;
88
        constrainLabel.ipadx = 0;
89
        constrainLabel.ipady = 0;
90
        constrainLabel.insets = new Insets(0, 0, 0, 0);
91

  
92
        constrainButton = new GridBagConstraints();
93
        constrainButton.gridx = 1;
94
        constrainButton.gridy = 0;
95
        constrainButton.fill = GridBagConstraints.VERTICAL;
96
        constrainButton.weightx = 0;
97
        constrainButton.weighty = 1;
98
        constrainButton.insets = constrainLabel.insets;
99

  
100
    }
101

  
102
    public Object getCellEditorValue() {
103
        return renderer.getValue();
104
    }
105

  
106
    public void actionPerformed(ActionEvent e) {
107
        Object source = e.getSource();
108
        if (source == button) {
109
            showPropertiesPanel(renderer.getValue());
110
        }
111

  
112
    }
113

  
114
    /**
115
     * @param value
116
     */
117
    private void showPropertiesPanel(Object value) {
118
        swingManager.getWindowManager().showWindow(
119
            new StoreParametersEditor(renderer.getValue()),
120
            swingManager.getTranslation("edit_source_properties"), MODE.DIALOG);
121

  
122
    }
123

  
124
    public Component getTableCellEditorComponent(JTable table, Object value,
125
        boolean isSelected, int row, int column) {
126
        panel.removeAll();
127
        panel.add(renderer.getTableCellRendererComponent(table, value,
128
            isSelected, true, row, column), constrainLabel);
129
        panel.add(button, constrainButton);
130
        return panel;
131
    }
132

  
133
}
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.10/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/addlayer/StoreParametersCellRenderer.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.educa.portableview.swing.impl.editor.addlayer;
23

  
24
import java.awt.Color;
25

  
26
import javax.swing.table.DefaultTableCellRenderer;
27

  
28
import org.gvsig.fmap.dal.DataStoreParameters;
29

  
30
/**
31
 * <p>
32
 * Store Parameters Table cell renderer for
33
 * {@link DefaultPortableViewAddLayerComponent} sources list
34
 * </p>
35
 * <p>
36
 * Shows store parameter description.
37
 * </p>
38
 *
39
 * @author gvSIG Team
40
 * @version $Id$
41
 *
42
 */
43
public class StoreParametersCellRenderer extends DefaultTableCellRenderer {
44

  
45
    /**
46
     *
47
     */
48
    private static final long serialVersionUID = -2287544105907864898L;
49
    private DataStoreParameters value;
50

  
51
    public String format(DataStoreParameters storeParameters) {
52
        return String.format("[%1$6s] %2s", storeParameters.getDataStoreName(),
53
            storeParameters.getDescription());
54
    }
55

  
56
    @Override
57
    protected void setValue(Object value) {
58
        this.value = (DataStoreParameters) value;
59
        if (this.value != null) {
60
            setText(format(this.value));
61
            if (!this.value.isValid()) {
62
                setBackground(Color.red);
63
                setOpaque(true);
64
            } else {
65
                setOpaque(false);
66
            }
67

  
68
        } else {
69
            setText("");
70
        }
71
    }
72

  
73
    /**
74
     * @return the value
75
     */
76
    public DataStoreParameters getValue() {
77
        return value;
78
    }
79

  
80
}
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.10/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/addlayer/StoreParametersEditor.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.educa.portableview.swing.impl.editor.addlayer;
23

  
24
import java.awt.BorderLayout;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27

  
28
import javax.swing.Box;
29
import javax.swing.BoxLayout;
30
import javax.swing.JButton;
31
import javax.swing.JPanel;
32

  
33
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
34
import org.gvsig.educa.portableview.swing.PortableViewSwingManager;
35
import org.gvsig.fmap.dal.DataStoreParameters;
36
import org.gvsig.tools.dynform.DynFormLocator;
37
import org.gvsig.tools.dynform.DynFormManager;
38
import org.gvsig.tools.dynform.JDynForm;
39
import org.gvsig.tools.exception.BaseException;
40
import org.gvsig.tools.swing.api.ToolsSwingLocator;
41
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
42

  
43
/**
44
 * <p>
45
 * Dialog to edit Data Store parameters (used by
46
 * {@link StoreParametersCellEditor})
47
 * </p>
48
 * <p>
49
 * Uses {@link DynObjectSwingManager} to generate components
50
 * </p>
51
 *
52
 * @author gvSIG Team
53
 * @version $Id$
54
 *
55
 */
56
public class StoreParametersEditor extends JPanel implements ActionListener {
57

  
58
    /**
59
     *
60
     */
61
    private static final long serialVersionUID = -3044289357512879309L;
62

  
63
    private final PortableViewSwingManager swingManager;
64
    private final UsabilitySwingManager usabManager;
65

  
66
    private final DynFormManager dynSwingManager;
67
    private JDynForm propertyEditor;
68
    private DataStoreParameters parameters;
69

  
70
    private JButton botAccept;
71

  
72
    private JButton botCancel;
73

  
74
    /**
75
     *
76
     */
77
    public StoreParametersEditor(DataStoreParameters parameters) {
78
        super();
79
        dynSwingManager = DynFormLocator.getDynFormManager();
80
        swingManager = PortableViewSwingLocator.getSwingManager();
81
        usabManager = ToolsSwingLocator.getUsabilitySwingManager();
82

  
83
        // create property editor component
84
        try {
85
        	this.parameters = parameters;
86
        	propertyEditor = dynSwingManager.createJDynForm(parameters);
87
        } catch (BaseException ex) {
88
            // TODO
89
            return;
90
        }
91
        setLayout(new BorderLayout(10, 10));
92
        add(propertyEditor.asJComponent(), BorderLayout.CENTER);
93

  
94
        // Create panel for commands
95
        JPanel commandsPanel = new JPanel();
96
        commandsPanel.setLayout(new BoxLayout(commandsPanel, BoxLayout.X_AXIS));
97
        commandsPanel.add(Box.createHorizontalGlue());
98
        botAccept =
99
            usabManager.createJButton(swingManager.getTranslation("accept"));
100
        botAccept.addActionListener(this);
101

  
102
        botCancel =
103
            usabManager.createJButton(swingManager.getTranslation("cancel"));
104
        botCancel.addActionListener(this);
105

  
106
        commandsPanel.add(botAccept);
107
        commandsPanel.add(Box.createHorizontalStrut(10));
108
        commandsPanel.add(botCancel);
109
        commandsPanel.add(Box.createHorizontalStrut(5));
110
        add(commandsPanel, BorderLayout.SOUTH);
111
    }
112

  
113
    public void actionPerformed(ActionEvent e) {
114
        Object source = e.getSource();
115
        if (source == botCancel) {
116
            close();
117
            return;
118
        }
119
        if (source == botAccept) {
120
        	propertyEditor.getValues(parameters);
121
            // TODO validate... but before solve CRS problem
122
            close();
123
            return;
124
        }
125
    }
126

  
127
    /**
128
     * close dialog
129
     */
130
    private void close() {
131
        setVisible(false);
132
    }
133
}
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.10/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/addlayer/DataStoreTableModel.java
1
package org.gvsig.educa.portableview.swing.impl.editor.addlayer;
2

  
3
import java.util.List;
4

  
5
import javax.swing.table.DefaultTableModel;
6

  
7
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
8
import org.gvsig.educa.portableview.swing.PortableViewSwingManager;
9
import org.gvsig.fmap.dal.DataStoreParameters;
10

  
11
/**
12
 * <p>
13
 * Table model for list {@link DataStoreParameters}
14
 * </p>
15
 *
16
 * <p>
17
 * This stores parameters, selection and layer names
18
 * </p>
19
 *
20
 * @author gvSIG Team
21
 * @version $Id$
22
 *
23
 */
24
class DataStoreTableModel extends DefaultTableModel {
25

  
26
    /**
27
     *
28
     */
29
    private static final long serialVersionUID = -6742064202466924241L;
30

  
31
    private final PortableViewSwingManager swingManager;
32

  
33
    private List<DataStoreParameters> parameters;
34

  
35
    private boolean[] selecteds;
36
    private String[] names;
37

  
38
    /**
39
     *
40
     */
41
    public DataStoreTableModel() {
42
        swingManager = PortableViewSwingLocator.getSwingManager();
43
    }
44

  
45
    /**
46
     * Sets store parameters to use
47
     *
48
     * @param storeParameters
49
     */
50
    public void setStoreParameters(List<DataStoreParameters> storeParameters) {
51
        this.parameters = storeParameters;
52
        this.selecteds = new boolean[storeParameters.size()];
53
        this.names = new String[storeParameters.size()];
54
        fireTableDataChanged();
55
    }
56

  
57
    /**
58
     * Gets parameters of the row
59
     *
60
     * @param i
61
     *            row
62
     *
63
     * @return
64
     */
65
    public DataStoreParameters getStoreParameters(int i) {
66
        return parameters.get(i);
67
    }
68

  
69
    /**
70
     * Gets selected name for StoreParameters
71
     *
72
     * @param i
73
     *            row
74
     * @return
75
     */
76
    public String getName(int i) {
77
        return names[i];
78
    }
79

  
80
    /**
81
     * Informs if StoreParameters is selected to add
82
     *
83
     * @param i
84
     *            row
85
     * @return
86
     */
87
    public boolean isSelected(int i) {
88
        if (selecteds == null) {
89
            return false;
90
        }
91
        return selecteds[i];
92
    }
93

  
94
    @Override
95
    public int getRowCount() {
96
        if (selecteds == null) {
97
            return 0;
98
        }
99
        return selecteds.length;
100
    }
101

  
102
    @Override
103
    public int getColumnCount() {
104
        return 3;
105
    }
106

  
107
    @Override
108
    public Class<?> getColumnClass(int columnIndex) {
109
        switch (columnIndex) {
110
        case 0:
111
            return Boolean.class;
112
        case 2:
113
            return DataStoreParameters.class;
114
        default:
115
            return String.class;
116
        }
117
    }
118

  
119
    @Override
120
    public String getColumnName(int column) {
121
        switch (column) {
122
        case 0:
123
            return swingManager.getTranslation("add");
124
        case 1:
125
            return swingManager.getTranslation("name");
126
        case 2:
127
            return swingManager.getTranslation("parameters");
128
        default:
129
            return "";
130

  
131
        }
132
    }
133

  
134
    /**
135
     * Cells editables: {selection} {parameters} and {name (if it's selected)}
136
     */
137
    @Override
138
    public boolean isCellEditable(int row, int column) {
139
        switch (column) {
140
        case 0:
141
        case 2:
142
            return true;
143
        case 1:
144
            // name is editable only if this layer is selected to add
145
            return selecteds[row];
146

  
147
        default:
148
            return false;
149
        }
150
    }
151

  
152
    @Override
153
    public Object getValueAt(int row, int column) {
154
        switch (column) {
155
        case 0:
156
            return selecteds[row];
157
        case 1:
158
            return names[row];
159
        case 2:
160
            return parameters.get(row);
161

  
162
        default:
163
            throw new IllegalArgumentException();
164
        }
165
    }
166

  
167
    @Override
168
    public void setValueAt(Object aValue, int row, int column) {
169
        switch (column) {
170
        case 0:
171
            selecteds[row] = (Boolean) aValue;
172
            break;
173
        case 1:
174
            names[row] = (String) aValue;
175
            break;
176
        case 2:
177
            break;
178
        default:
179
            // Nothing to do
180
            throw new IllegalArgumentException();
181
        }
182
    }
183

  
184
    /**
185
     * Cleans all data
186
     */
187
    public void clean() {
188
        parameters = null;
189
        selecteds = null;
190
        names = null;
191
        fireTableDataChanged();
192
    }
193

  
194
}
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.10/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/addlayer/DefaultPortableViewAddLayerComponent.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.educa.portableview.swing.impl.editor.addlayer;
23

  
24
import java.awt.BorderLayout;
25
import java.awt.Component;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.GridLayout;
29
import java.awt.Insets;
30
import java.awt.event.ActionEvent;
31
import java.awt.event.ActionListener;
32
import java.util.List;
33

  
34
import javax.swing.BorderFactory;
35
import javax.swing.Box;
36
import javax.swing.BoxLayout;
37
import javax.swing.JButton;
38
import javax.swing.JComboBox;
39
import javax.swing.JComponent;
40
import javax.swing.JLabel;
41
import javax.swing.JPanel;
42
import javax.swing.JScrollPane;
43

  
44
import org.cresques.cts.IProjection;
45

  
46
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
47
import org.gvsig.educa.portableview.swing.PortableViewSwingManager;
48
import org.gvsig.educa.portableview.swing.PortableViewWindowManager.MESSAGE_DIALOG_TYPE;
49
import org.gvsig.educa.portableview.swing.editor.PortableViewAddLayerComponent;
50
import org.gvsig.fmap.crs.CRSFactory;
51
import org.gvsig.fmap.dal.DALLocator;
52
import org.gvsig.fmap.dal.DataManager;
53
import org.gvsig.fmap.dal.DataServerExplorer;
54
import org.gvsig.fmap.dal.DataServerExplorerParameters;
55
import org.gvsig.fmap.dal.DataStoreParameters;
56
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
57
import org.gvsig.fmap.mapcontext.MapContextLocator;
58
import org.gvsig.fmap.mapcontext.MapContextManager;
59
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
60
import org.gvsig.fmap.mapcontext.layers.FLayer;
61
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection;
62
import org.gvsig.tools.dynform.DynFormLocator;
63
import org.gvsig.tools.dynform.DynFormManager;
64
import org.gvsig.tools.dynform.JDynForm;
65
import org.gvsig.tools.dynobject.DynField;
66
import org.gvsig.tools.exception.BaseException;
67
import org.gvsig.tools.swing.api.ToolsSwingLocator;
68
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
69
import org.gvsig.utils.swing.jtable.JTable;
70

  
71
/**
72
 * <p>
73
 * Default implementation of {@link PortableViewAddLayerComponent}
74
 * </p>
75
 * <p>
76
 * Creates a panel with 3 sections:
77
 * <ol>
78
 * <li><i>Data Explorer type</i>: Data explorer type to use</li>
79
 * <li><i>Data Explorer Parameters</i>: Parameters to use for locate data
80
 * sources</li>
81
 * <li><i>Source list</i>: Sources found in this explorer parameters</li>
82
 * </ol>
83
 * </p>
84
 * <p>
85
 * User can selected the explorer to use and its parameters to locate sources
86
 * for layers.
87
 * </p>
88
 * <p>
89
 * In source list, user can select sources to add as layer, set the layer name
90
 * and configure source parameters
91
 * </p>
92
 *
93
 * @author gvSIG Team
94
 * @version $Id$
95
 *
96
 */
97
public class DefaultPortableViewAddLayerComponent extends JPanel implements
98
    PortableViewAddLayerComponent, ActionListener {
99

  
100
    private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory
101
        .getLogger(DefaultPortableViewAddLayerComponent.class);
102

  
103
    /**
104
     * Default CRS to use.
105
     *
106
     * TODO improve this configuration
107
     */
108
    private static IProjection DEFAULT_CRS = null;
109

  
110
    private final PortableViewSwingManager swingManager;
111
    private final DataManager dataManager;
112
    private final DynFormManager dynSwingManager;
113
    private final UsabilitySwingManager usabManager;
114
    private final MapContextManager mapContextManager;
115

  
116
    /**
117
     * flag to identify if UI is initialized o not
118
     */
119
    private boolean initilalized;
120

  
121
    /**
122
     * Combo to select Explorer type
123
     */
124
    private JComboBox cmbExplorer;
125

  
126
    /**
127
     * Name of current explorer type
128
     */
129
    private String curExplorerProvider;
130

  
131
    /**
132
     * Panel for explorer type widgets
133
     */
134
    private JPanel explorerContainer;
135

  
136
    /**
137
     * Panel for explorer parameters widgets
138
     */
139
    private JPanel explorerParamContainer;
140

  
141
    /**
142
     * Panel for list sources widgets
143
     */
144
    private JPanel storeParamContainer;
145

  
146
    /**
147
     * widget to modify explorer parameters
148
     */
149
    private JDynForm explorerParameters;
150

  
151
    /**
152
     * Current explorer's parameters
153
     */
154
    private DataServerExplorerParameters curExplorerParameters;
155

  
156
    /**
157
     * Panel for action buttons
158
     */
159
    private JPanel commandsContainer;
160

  
161
    /**
162
     * {@link LayerCollection} where add user selection
163
     */
164
    private LayerCollection whereAddLayers;
165

  
166
    /**
167
     * Panel to contains action for explorer
168
     */
169
    private JPanel explorerCommandsContanier;
170

  
171
    /**
172
     * Button to list sources from explorer
173
     */
174
    private JButton botList;
175

  
176
    /**
177
     * Button to add current add layers from the source selection
178
     */
179
    private JButton botAddLayers;
180

  
181
    /**
182
     * Button to close this window without perform any action
183
     */
184
    private JButton botCancel;
185

  
186
    /**
187
     * Table to show the located sources
188
     */
189
    private JTable listTable;
190

  
191
    /**
192
     * TableModel of the located sources' table
193
     */
194
    private DataStoreTableModel listTableModel;
195

  
196
    /**
197
     *
198
     */
199
    private static final long serialVersionUID = -6384480877337043703L;
200

  
201
    public DefaultPortableViewAddLayerComponent() {
202
        dataManager = DALLocator.getDataManager();
203
        dynSwingManager = DynFormLocator.getDynFormManager();
204
        usabManager = ToolsSwingLocator.getUsabilitySwingManager();
205
        swingManager = PortableViewSwingLocator.getSwingManager();
206
        mapContextManager = MapContextLocator.getMapContextManager();
207

  
208
        // TODO improve this
209
        if (DEFAULT_CRS == null) {
210
            DEFAULT_CRS = CRSFactory.getCRS("EPSG:23030");
211
        }
212

  
213
        initilalized = false;
214
    }
215

  
216
    /**
217
     * Initialize UI components
218
     */
219
    private void intitalizeUI() {
220
        if (initilalized) {
221
            return;
222
        }
223
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
224

  
225
        // Select explorer container
226
        addExplorerPanel();
227

  
228
        // Explorer parameters container
229
        addExplorerParametersPanel();
230

  
231
        // Source Parameters panel
232
        addStoreParametersPanel();
233

  
234
        // Commands panel
235
        addCommandsPanel();
236

  
237
        // Updates parameters panel with initial explorer selection
238
        if (cmbExplorer.getSelectedIndex() >= 0) {
239
            explorerSelected((String) cmbExplorer.getSelectedItem());
240
        }
241

  
242
        initilalized = true;
243
    }
244

  
245
    /**
246
     * {@inheridDoc}
247
     * <p>
248
     * <i>overwritten to add padding between components</i>
249
     * </p>
250
     */
251
    @Override
252
    public Component add(Component comp) {
253
        super.add(Box.createVerticalStrut(5));
254
        Component ret = super.add(comp);
255
        super.add(Box.createVerticalStrut(5));
256
        return ret;
257
    }
258

  
259
    /**
260
     * Adds Explorer type panel
261
     */
262
    @SuppressWarnings("unchecked")
263
    private void addExplorerPanel() {
264
        explorerContainer = new JPanel(new GridBagLayout());
265
        GridBagConstraints gbc;
266

  
267
        gbc = new GridBagConstraints();
268
        gbc.fill = GridBagConstraints.NONE;
269
        gbc.insets = new Insets(5, 5, 5, 5);
270
        explorerContainer.add(
271
            new JLabel(swingManager.getTranslation("explorer")), gbc);
272
        cmbExplorer =
273
            new JComboBox(dataManager.getExplorerProviders().toArray(
274
                new String[0]));
275

  
276
        gbc = new GridBagConstraints();
277
        gbc.fill = GridBagConstraints.HORIZONTAL;
278
        gbc.weightx = 1;
279
        gbc.weighty = 0;
280
        gbc.insets = new Insets(5, 5, 5, 5);
281

  
282
        explorerContainer.add(cmbExplorer, gbc);
283

  
284
        cmbExplorer.addActionListener(this);
285
        add(explorerContainer);
286
    }
287

  
288
    /**
289
     * adds Explorer parameters panel
290
     */
291
    private void addExplorerParametersPanel() {
292
        explorerParamContainer = new JPanel();
293
        explorerParamContainer.setBorder(BorderFactory
294
            .createTitledBorder(swingManager
295
                .getTranslation("explorer_parameters")));
296
        explorerParamContainer.setLayout(new BorderLayout(10, 10));
297

  
298
        explorerCommandsContanier = new JPanel();
299
        explorerCommandsContanier.setLayout(new BoxLayout(
300
            explorerCommandsContanier, BoxLayout.X_AXIS));
301
        explorerCommandsContanier.add(Box.createHorizontalGlue());
302

  
303
        botList =
304
            usabManager.createJButton(swingManager
305
                .getTranslation("list_sources"));
306
        botList.addActionListener(this);
307
        explorerCommandsContanier.add(botList);
308
        explorerParamContainer.add(explorerCommandsContanier,
309
            BorderLayout.SOUTH);
310
        add(explorerParamContainer);
311
    }
312

  
313
    /**
314
     * Adds the panel with Store parameters table
315
     */
316
    private void addStoreParametersPanel() {
317
        storeParamContainer = new JPanel(new GridLayout(1, 1, 10, 10));
318
        storeParamContainer.setBorder(BorderFactory
319
            .createTitledBorder(swingManager
320
                .getTranslation("source_parameters")));
321
        listTable = new JTable();
322

  
323
        listTableModel = new DataStoreTableModel();
324
        listTable.setModel(listTableModel);
325
        listTable.setDefaultRenderer(DataStoreParameters.class,
326
            new StoreParametersCellRenderer());
327
        listTable.setDefaultEditor(DataStoreParameters.class,
328
            new StoreParametersCellEditor());
329
        listTable.getColumnModel().getColumn(0).setMinWidth(30);
330
        listTable.getColumnModel().getColumn(0).setMaxWidth(60);
331

  
332
        storeParamContainer.add(new JScrollPane(listTable));
333
        add(storeParamContainer);
334
    }
335

  
336
    /**
337
     * Add panel with the dialog's commands
338
     */
339
    private void addCommandsPanel() {
340
        botAddLayers =
341
            usabManager
342
                .createJButton(swingManager.getTranslation("add_layers"));
343
        botCancel =
344
            usabManager.createJButton(swingManager.getTranslation("cancel"));
345

  
346
        botAddLayers.addActionListener(this);
347
        botCancel.addActionListener(this);
348

  
349
        commandsContainer = new JPanel();
350
        commandsContainer.setLayout(new BoxLayout(commandsContainer,
351
            BoxLayout.X_AXIS));
352

  
353
        commandsContainer.add(Box.createHorizontalGlue());
354
        commandsContainer.add(botAddLayers);
355
        commandsContainer.add(Box.createHorizontalStrut(10));
356
        commandsContainer.add(botCancel);
357
        commandsContainer.add(Box.createHorizontalStrut(5));
358

  
359
        add(commandsContainer);
360
    }
361

  
362
    /** {@inheridDoc} */
363
    public JComponent getSwingComponent() {
364
        intitalizeUI();
365
        return this;
366
    }
367

  
368
    /** {@inheridDoc} */
369
    public void actionPerformed(ActionEvent e) {
370
        Object source = e.getSource();
371
        if (source == cmbExplorer) {
372
            explorerSelected((String) cmbExplorer.getSelectedItem());
373
            return;
374
        }
375
        if (source == botList) {
376
            loadStoreList();
377
            return;
378
        }
379
        if (source == botAddLayers) {
380
            createAndAddLayers();
381
            return;
382
        }
383
        if (source == botCancel) {
384
            close();
385
        }
386
    }
387

  
388
    /**
389
     * Loads store parameters from explorer into table
390
     */
391
    @SuppressWarnings("unchecked")
392
    private void loadStoreList() {
393
        try {
394
            curExplorerParameters.validate();
395
        } catch (ValidateDataParametersException ex1) {
396
            swingManager.getWindowManager().showMessageDialog(
397
                swingManager.getTranslation("list_data_explorer"),
398
                swingManager.getTranslation("explorer_parameters_not_valid"),
399
                MESSAGE_DIALOG_TYPE.WARNING);
400
            LOG.warn("Explorer parameters not valid", ex1);
401
        }
402
        @SuppressWarnings("rawtypes")
403
        List sourceList;
404
        try {
405
            DataServerExplorer explorer =
406
                dataManager.openServerExplorer(curExplorerProvider,
407
                    curExplorerParameters);
408
            sourceList = explorer.list();
409
        } catch (Exception ex) {
410
            swingManager.getWindowManager().showMessageDialog(
411
                swingManager.getTranslation("list_data_explorer"),
412
                swingManager.getTranslation("problems_opening_explorer"),
413
                MESSAGE_DIALOG_TYPE.ERROR);
414
            LOG.error("Problem opening explorer", ex);
415
            return;
416
        }
417
        listTableModel.setStoreParameters(sourceList);
418
    }
419

  
420
    /**
421
     * Close this panel
422
     */
423
    private void close() {
424
        setVisible(false);
425
    }
426

  
427
    /**
428
     * Creates and adds all selected layers from table
429
     */
430
    private void createAndAddLayers() {
431

  
432
        // Assure editing values are updated
433
        if (listTable.isEditing()) {
434
            listTable.getCellEditor().stopCellEditing();
435
        }
436

  
437
        // Assure it's set where to add layers
438
        if (whereAddLayers == null) {
439
            throw new IllegalStateException(
440
                "Missing layers instance where add layer to");
441
        }
442
        boolean added = false;
443

  
444
        FLayer layer;
445
        DataStoreParameters parameters;
446
        for (int i = 0; i < listTableModel.getRowCount(); i++) {
447
            if (!listTableModel.isSelected(i)) {
448
                continue;
449
            }
450
            parameters = listTableModel.getStoreParameters(i);
451
            loadCRS(parameters);
452
            try {
453
                layer =
454
                    mapContextManager.createLayer(listTableModel.getName(i),
455
                        parameters);
456
                whereAddLayers.addLayer(layer);
457
            } catch (LoadLayerException ex) {
458
                swingManager.getWindowManager().showMessageDialog(
459
                    "adding_layers", "Problem_adding_layers",
460
                    MESSAGE_DIALOG_TYPE.ERROR);
461
                LOG.error("Error adding layer", ex);
462
                return;
463
            }
464
            added = true;
465
        }
466

  
467
        if (!added) {
468
            swingManager.getWindowManager().showMessageDialog(
469
                getSwingComponent(), swingManager.getTranslation("add_layers"),
470
                swingManager.getTranslation("no_layers_to_add"),
471
                MESSAGE_DIALOG_TYPE.INFO);
472
            LOG.info("No layers to add");
473
            return;
474
        }
475
        close();
476
    }
477

  
478
    /**
479
     * Assures that CRS value is set in a Store Parameter, else it will set with
480
     * {@link #DEFAULT_CRS} value.
481
     *
482
     * @param parameters
483
     */
484
    private void loadCRS(DataStoreParameters parameters) {
485
        DynField[] fields = parameters.getDynClass().getDeclaredDynFields();
486
        for (DynField field : fields) {
487
            if (field.getType() == org.cresques.DataTypes.CRS) {
488
                if (field.isMandatory()
489
                    && parameters.getDynValue(field.getName()) == null) {
490
                    // Set default CRS
491
                    parameters.setDynValue(field.getName(), DEFAULT_CRS);
492
                }
493
            }
494
        }
495
    }
496

  
497
    /**
498
     * <p>
499
     * Sets explorer type selection
500
     * </p>
501
     *
502
     * @param selectedItem
503
     */
504
    private void explorerSelected(String selected) {
505
        if (selected != curExplorerProvider && curExplorerProvider != null) {
506
            // explorer change, so clear all forms
507
            curExplorerParameters = null;
508
            explorerParamContainer.remove(explorerParameters.asJComponent());
509
            explorerParameters = null;
510
            listTableModel.clean();
511
        }
512
        curExplorerProvider = selected;
513
        try {
514
            curExplorerParameters =
515
                dataManager.createServerExplorerParameters(curExplorerProvider);
516
            if (explorerParameters == null) {
517
                explorerParameters =
518
                		dynSwingManager.createJDynForm(curExplorerParameters);
519
                explorerParamContainer.add(explorerParameters.asJComponent(),
520
                    BorderLayout.CENTER);
521
                // explorerParamContainer.invalidate();
522
                explorerParamContainer.doLayout();
523
                doLayout();
524
            } else {
525
            	explorerParameters.setValues(curExplorerParameters);
526
            }
527
        } catch (BaseException ex) {
528
            LOG.error("Problem creating provider parameters form", ex);
529
            return;
530
        }
531
    }
532

  
533
    /** {@inheridDoc} */
534
    public void addToLayers(LayerCollection whereAddLayers) {
535
        this.whereAddLayers = whereAddLayers;
536
    }
537
}
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.10/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/StepValidation.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.educa.portableview.swing.impl.editor;
23

  
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.util.ArrayList;
30
import java.util.List;
31

  
32
import javax.swing.JButton;
33
import javax.swing.JPanel;
34
import javax.swing.JTextArea;
35

  
36
import org.apache.commons.lang3.StringUtils;
37

  
38
import org.gvsig.educa.portableview.compilation.CompilationValidationMessage;
39
import org.gvsig.educa.portableview.compilation.PortableViewCompilation;
40
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
41
import org.gvsig.educa.portableview.swing.PortableViewSwingManager;
42
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
43
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
44
import org.gvsig.tools.swing.api.ToolsSwingLocator;
45
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
46

  
47
/**
48
 * {@link DefaultPortableViewCompilationEditor} step which validates all
49
 * compilation data
50
 *
51
 * @author gvSIG Team
52
 * @version $Id$
53
 *
54
 */
55
public class StepValidation extends JPanel implements OptionPanel,
56
    ActionListener {
57

  
58
    /**
59
     *
60
     */
61
    private static final long serialVersionUID = -3800934676707399083L;
62

  
63
    private final PortableViewCompilation compilation;
64

  
65
    private final PortableViewSwingManager swingManager;
66

  
67
    private final UsabilitySwingManager usabManager;
68

  
69
    private final DefaultPortableViewCompilationEditor editor;
70

  
71
    private JTextArea txtMessages;
72

  
73
    private JButton botClean;
74

  
75
    private JButton botValidate;
76

  
77
    /**
78
     * @param compilation
79
     */
80
    public StepValidation(
81
        DefaultPortableViewCompilationEditor defaultPortableViewCompilationEditor) {
82
        swingManager = PortableViewSwingLocator.getSwingManager();
83
        usabManager = ToolsSwingLocator.getUsabilitySwingManager();
84

  
85
        editor = defaultPortableViewCompilationEditor;
86
        this.compilation = editor.getCompilation();
87

  
88
        initializeUI();
89
    }
90

  
91
    /**
92
     *
93
     */
94
    private void initializeUI() {
95
        setLayout(new GridBagLayout());
96

  
97
        GridBagConstraints gbc;
98

  
99
        Insets insets = new Insets(5, 10, 5, 10);
100

  
101
        gbc = new GridBagConstraints();
102
        gbc.gridheight = 3;
103
        gbc.gridwidth = 4;
104
        gbc.fill = GridBagConstraints.BOTH;
105
        gbc.weightx = 1;
106
        gbc.weighty = 1;
107
        gbc.insets = insets;
108
        txtMessages = new JTextArea();
109
        txtMessages.setEnabled(false);
110
        add(txtMessages, gbc);
111

  
112
        gbc = new GridBagConstraints();
113
        gbc.gridx = 2;
114
        gbc.gridy = 4;
115
        gbc.gridheight = 1;
116
        gbc.gridwidth = 1;
117
        gbc.insets = insets;
118
        gbc.fill = GridBagConstraints.NONE;
119
        gbc.weightx = 0;
120
        gbc.weighty = 0;
121
        botClean =
122
            usabManager.createJButton(swingManager
123
                .getTranslation("clean_messages"));
124
        botClean.addActionListener(this);
125
        add(botClean, gbc);
126

  
127
        gbc = (GridBagConstraints) gbc.clone();
128
        gbc.gridx++;
129

  
130
        botValidate =
131
            usabManager.createJButton(swingManager.getTranslation("validate"));
132
        botValidate.addActionListener(this);
133
        add(botValidate, gbc);
134

  
135
    }
136

  
137
    public String getPanelTitle() {
138
        return swingManager.getTranslation("portable_view_validation");
139
    }
140

  
141
    public void nextPanel() throws NotContinueWizardException {
142
        if (!isValidCompilation(true)) {
143
            throw new NotContinueWizardException(
144
                swingManager.getTranslation("compilation_not_valid"), this,
145
                true);
146
        }
147
    }
148

  
149
    /**
150
     * @return
151
     */
152
    private boolean isValidCompilation(boolean updateUI) {
153
        List<CompilationValidationMessage> messages =
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff