Revision 4196

View differences:

org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.253/org.gvsig.vectorediting.app/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<groupId>org.gvsig</groupId>
6
	<artifactId>org.gvsig.vectorediting.app</artifactId>
7
	<packaging>pom</packaging>
8
	<version>1.0.253</version>
9
	<name>${project.artifactId}</name>
10
	<description>This plugin add to gvSIG a tool to show Vectorediting messages</description>
11
	<parent>
12
		<groupId>org.gvsig</groupId>
13
		<artifactId>org.gvsig.vectorediting</artifactId>
14
		<version>1.0.253</version>
15
	</parent>
16
	<dependencyManagement>
17
		<dependencies>
18
		
19
		</dependencies>
20
	</dependencyManagement>
21

  
22
	<modules>
23
		<module>org.gvsig.vectorediting.app.mainplugin</module>
24
	</modules>
25

  
26
</project>
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.253/org.gvsig.vectorediting.app/maven-howto.rst
1

  
2
==================================
3
Usefull maven "howtos" and FAQs
4
==================================
5

  
6
.. contents::
7

  
8
How to reduce the process of "install" to run as fast as possible.
9
-------------------------------------------------------------------
10

  
11
Can reduce install execution skiping test execution and compilation,
12
javadoc generation, test signature checking, license checking, and 
13
attach sources in jar.
14

  
15
  mvn  -Danimal.sniffer.skip=true -Dmaven.test.skip=true -Dsource.skip=true -DskipTests -Dmaven.javadoc.skip=true install
16

  
17
How to increment the build number of gvSIG plugins
18
----------------------------------------------------
19

  
20
To increase the build number of gvSIG plugins, yo can do:
21

  
22
  mvn -Dincrease-build-number process-sources
23
  
24
How to deploy a package of a gvSIG plugin
25
--------------------------------------------
26

  
27
Yo can deploy the package of a gvSIG plugin with:
28

  
29
  mvn -Ddeploy-package -Duser=USER -Dpassword=PASSWORD install
30

  
31
Notes:
32
- Require that the gvsig.package.info.poolURL property that this set to the correct value.
33
- The process uses WEBDAV to upload the packages, gvspkg and gvspki, and require 
34
  access to write in the location specified by gvsig.package.info.poolURL
35
- If "user" or "password" is not present, the process ask its each time it need.
36
- If folder specified in  gvsig.package.info.poolURL does not exist, the process try to create it.
37
- The process create a file "addon-request.txt" in the target with the information to 
38
  add to the ticket to request the update of the package in the main repository of
39
  packages of gvSIG.
40

  
41
How to skip attach sources in jar from command line
42
------------------------------------------------------
43

  
44
If in the project is enabled by default the generation of jar whith 
45
the sources of the project, you can disable this setting the property
46
"source.skip" to true in the command line::
47

  
48
    mvn -Dsource.skip=true  install
49

  
50
How to skip test compile from command line
51
--------------------------------------------
52

  
53
You can skip the compilation of test setting the propety "maven.test.skip" 
54
to true in the command line::
55

  
56
    mvn -Dmaven.test.skip=true  install
57

  
58

  
59
How to skip test execution from command line
60
----------------------------------------------
61

  
62
You can skip the tests execution setting the propety "skipTests" to true
63
in the command line::
64

  
65
    mvn -DskipTests install
66

  
67
How to skip javadoc generation from command line
68
--------------------------------------------------
69

  
70
You can skip the javadoc generation setting the property
71
"maven.javadoc.skip" to true in the command line::
72

  
73
    mvn -Dmaven.javadoc.skip=true  install
74

  
75
How to skip test signature cheks from command line
76
---------------------------------------------------
77

  
78
You can skip the signature check setting the property
79
"animal.sniffer.skip" to true in the command line::
80

  
81
    mvn -Danimal.sniffer.skip=true install
82

  
83
How to install a project without install submodules
84
----------------------------------------------------------
85

  
86
To install a project with submodules and only install the
87
parent project without submodules use the option "--non-recursive" ::
88

  
89
    mvn --non-recursive install
90

  
91
  
92
How to skip test compilation
93
--------------------------------
94

  
95
To configure a project to don't run the compilation
96
of test you can add to this pom the next configuration of
97
the plugin "maven-compiler-plugin"::
98

  
99
  <build>
100
    <plugins>
101
      ...
102
      <plugin>
103
        <!-- Skip compilation tests -->
104
        <groupId>org.apache.maven.plugins</groupId>
105
        <artifactId>maven-compiler-plugin</artifactId>
106
        <executions>
107
          <execution>
108
            <id>default-testCompile</id>
109
            <phase>process-test-sources</phase>
110
            <goals>
111
              <goal>testCompile</goal>
112
            </goals>
113
            <configuration>
114
              <skip>true</skip>
115
            </configuration>
116
          </execution>
117
        </executions>
118
      </plugin>
119
      ...
120
    </plugins>
121
  </build>
122

  
123
Skip test execution
124
----------------------
125

  
126
To configure a project to don't run the execution
127
of test you can add to this pom the next configuration of
128
the plugin "maven-surefire-plugin"::
129

  
130

  
131
  <build>
132
    <plugins>
133
      ...
134
      <plugin>
135
        <!-- Skip test execution -->
136
        <groupId>org.apache.maven.plugins</groupId>
137
        <artifactId>maven-surefire-plugin</artifactId>
138
        <configuration>
139
          <skipTests>true</skipTests>
140
        </configuration>
141
      </plugin>
142
      ...
143
    </plugins>
144
  </build>
145

  
146
Continue on test failure
147
-----------------------------
148

  
149
You can configure a project to continue on test execution 
150
failure. To do this add to the pom of the project the next 
151
configuration of plugin "maven-surefire-plugin" ::
152

  
153
  <build>
154
    <plugins>
155
      ...
156
      <plugin>
157
        <!-- Continue on test failure -->
158
        <groupId>org.apache.maven.plugins</groupId>
159
        <artifactId>maven-surefire-plugin</artifactId>
160
        <configuration>
161
          <testFailureIgnore>true</testFailureIgnore>
162
        </configuration>
163
      </plugin>
164
      ...
165
    </plugins>
166
  </build>
167

  
168

  
169
Set java compatibility
170
--------------------------
171

  
172
To set the compatibility with a java version  add to the 
173
pom of the project the next configuration of plugin 
174
"maven-compiler-plugin" ::
175

  
176
  <build>
177
    <plugins>
178
      ...
179
      <plugin>
180
          <!-- Set java compatibility -->
181
          <groupId>org.apache.maven.plugins</groupId>
182
          <artifactId>maven-compiler-plugin</artifactId>
183
          <configuration>
184
              <source>1.5</source>
185
              <target>1.5</target>
186
              <encoding>ISO-8859-1</encoding>
187
          </configuration>
188
      </plugin>
189
      ...
190
    </plugins>
191
  </build>
192

  
193
Packaging tests in jar
194
------------------------
195

  
196
Test classes do not packaging in jar by default.
197
To packing add to pom::
198

  
199
  <build>
200
    <plugins>
201
      ...
202
      <plugin>
203
        <!-- Packaging tests in jar -->
204
        <groupId>org.apache.maven.plugins</groupId>
205
        <artifactId>maven-jar-plugin</artifactId>
206
        <executions>
207
          <!-- Generates a jar file only with the test classes -->
208
          <execution>
209
            <goals>
210
              <goal>test-jar</goal>
211
            </goals>
212
            <configuration>
213
              <includes>
214
                <include>**/**</include>
215
              </includes>
216
            </configuration>
217
          </execution>
218
        </executions>
219
      </plugin> 
220
      ...
221
    </plugins>
222
  </build>
223

  
224
How to set a dependency with tests jar
225
-----------------------------------------
226

  
227
You can set a dependency with a test jar adding to
228
the declaration of the dependency the scope of
229
test and the type of "test-jar"::
230

  
231
  <dependency>
232
      <groupId>...</groupId>
233
      <artifactId>...</artifactId>
234
      <type>test-jar</type>
235
      <scope>test</scope>
236
  </dependency>
237

  
238
How use ant in maven
239
-------------------------
240

  
241
You can use ant embed in the pom of you project.
242
To do this use::
243

  
244
  <plugin>
245
    <artifactId>maven-antrun-plugin</artifactId>
246
    <version>1.7</version>
247
    <executions>
248
      <execution>
249
        <phase>generate-sources</phase>
250
        <configuration>
251
          <target>
252
            <echo>Hello world!</echo>
253
          </target>
254
        </configuration>
255
        <goals>
256
          <goal>run</goal>
257
        </goals>
258
      </execution>
259
    </executions>
260
  </plugin>
261

  
262
Fail when execute "mvn deploy" with "No connector available"
263
-------------------------------------------------------------
264

  
265
When execute a "mvn deploy" fail with the error::
266

  
267
  [INFO] ------------------------------------------------------------------------
268
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy 
269
    (default-deploy) on project org.gvsig.desktop: Failed to deploy artifacts/metadata: 
270
    No connector available to access repository gvsig-repository (dav:https://devel.gvsig.org/m2repo/j2se) 
271
    of type default using the available factories WagonRepositoryConnectorFactory -> [Help 1]
272
  [ERROR] 
273
  
274
This happens to be configured the webdav wagon as an extension in the section "build"::
275

  
276
  ...
277
  <build>
278
    <extensions>
279
        <extension>
280
            <groupId>org.apache.maven.wagon</groupId>
281
            <artifactId>wagon-webdav-jackrabbit</artifactId>
282
            <version>1.0-beta-7</version>
283
        </extension>
284
    </extensions>
285
  ...
286

  
287
Fail when execute "mvn release: prepare" with "svn command failed... Could not authenticate"
288
------------------------------------------------------------------------------------------------
289

  
290
When running "mvn release: prepare" updates poms, compiles, and then
291
fails with the following error ::
292

  
293
  [INFO] ------------------------------------------------------------------------
294
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.1:prepare 
295
    (default-cli) on project org.gvsig.desktop: Unable to commit files
296
  [ERROR] Provider message:
297
  [ERROR] The svn command failed.
298
  [ERROR] Command output:
299
  [ERROR] svn: Commit failed (details follow):
300
  [ERROR] svn: MKACTIVITY of '/svn/gvsig-desktop/!svn/act/931a27bc-57e8-45d9-adcd-5a2cf54a7045': 
301
    authorization failed: Could not authenticate to server: rejected Basic challenge (https://devel.gvsig.org)
302
  [ERROR] -> [Help 1]
303
  [ERROR] 
304
  [ERROR]
305

  
306
Apparently maven in linux system use the svn of system and if you're not
307
authenticated when trying to access to the repository, svn fails.
308

  
309
This is solved by executing a commit from the command line on
310
some file of the project (only if you have not enabled the option 
311
"store-passwords = no" in $ HOME / .subversion / config). For example, you 
312
can add or remove at the end of "pom.xml" a blank line and then run 
313
from the command line ::
314

  
315
  svn ci -m "" pom.xml
316
  
317
Another option that works on Windows in declaring the user and password in the command:
318

  
319
mvn release:prepare -Dusername=[username] -Dpassword=[password]
320

  
321

  
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.253/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/buildNumber.properties
1
#Wed Oct 18 20:29:39 CEST 2023
2
buildNumber=264
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.253/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/vectorediting/app/mainplugin/MultilayerFinishEditingPanel.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.vectorediting.app.mainplugin;
7

  
8
import java.awt.Dimension;
9
import java.awt.GridBagConstraints;
10
import java.awt.GridBagLayout;
11
import java.awt.Insets;
12
import java.awt.event.ActionEvent;
13
import java.awt.event.ItemEvent;
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.List;
17
import javax.swing.DefaultComboBoxModel;
18
import javax.swing.JButton;
19
import javax.swing.JComponent;
20
import javax.swing.JLabel;
21
import javax.swing.JPanel;
22
import javax.swing.JScrollPane;
23
import org.gvsig.andami.PluginServices;
24
import org.gvsig.export.ExportLocator;
25
import org.gvsig.export.ExportManager;
26
import org.gvsig.export.ExportProcess;
27
import org.gvsig.export.swing.ExportSwingLocator;
28
import org.gvsig.export.swing.ExportSwingManager;
29
import org.gvsig.export.swing.JExportProcessPanel;
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.mapcontext.MapContext;
32
import org.gvsig.fmap.mapcontext.layers.FLayer;
33
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.i18n.I18nManager;
36
import org.gvsig.tools.swing.api.Component;
37
import org.gvsig.tools.swing.api.DropDown;
38
import org.gvsig.tools.swing.api.ToolsSwingLocator;
39
import org.gvsig.tools.swing.api.ToolsSwingManager;
40
import org.gvsig.tools.swing.api.windowmanager.Dialog;
41
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
42
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2;
43
import org.gvsig.tools.util.LabeledValue;
44
import org.gvsig.tools.util.LabeledValueImpl;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

  
48
/**
49
 *
50
 * @author jovivas
51
 */
52
public class MultilayerFinishEditingPanel extends JPanel implements Component {
53
    
54
    private static final int OPTION_SAVE = 0;
55
    private static final int OPTION_DISMISS = 1;
56
    private static final int OPTION_CONTINUE = 2;
57
    private static final int OPTION_EXPORT = 3;
58
    
59
    private static final Logger LOGGER = LoggerFactory.getLogger(EditingExtension.class);
60
    private Dialog dialog;
61
    
62
    private static class Row {
63

  
64
        private final FLyrVect layer;
65
        private final DropDown dropDownOptions;
66
        private final JButton jButtonExport;
67
        private final LabeledValue[] options;
68

  
69
        I18nManager i18n = ToolsLocator.getI18nManager();
70
        private final JLabel dropDownComponent;
71
        private final MultilayerFinishEditingPanel panel;
72
//        private final JComboBox comboBoxComponent;
73

  
74
        @SuppressWarnings("OverridableMethodCallInConstructor")
75
        public Row(MultilayerFinishEditingPanel panel, FLyrVect layer) {
76
            this.layer = layer;
77
            this.panel = panel;
78

  
79
            options = new LabeledValue[]{
80
                new LabeledValueImpl(i18n.getTranslation("_save"),OPTION_SAVE),
81
                new LabeledValueImpl(i18n.getTranslation("_dismiss"), OPTION_DISMISS),
82
                new LabeledValueImpl(i18n.getTranslation("_continue"), OPTION_CONTINUE),
83
                new LabeledValueImpl(i18n.getTranslation("_export"), OPTION_EXPORT)};
84

  
85
            DefaultComboBoxModel modelJComboBoxOptions = new DefaultComboBoxModel();
86
            for (LabeledValue option : options) {
87
                modelJComboBoxOptions.addElement(option);
88
            }
89
            
90
            ToolsSwingManager toolSwingmanager = ToolsSwingLocator.getToolsSwingManager();
91
            this.dropDownComponent = new JLabel();
92
//            this.comboBoxComponent = new JComboBox();
93
            this.dropDownOptions = toolSwingmanager.createDropDown(dropDownComponent);
94
            this.dropDownOptions.setModel(modelJComboBoxOptions);
95
//            this.comboBoxComponent.setModel(modelJComboBoxOptions);
96
            if (this.allowSave()) {
97
                this.dropDownOptions.setSelectedIndex(OPTION_SAVE); 
98
            } else {
99
                this.dropDownOptions.setSelectedIndex(OPTION_EXPORT);                
100
            }
101
//            if (this.layer.getFeatureStore().allowWrite()) {
102
//                this.comboBoxComponent.setSelectedIndex(OPTION_SAVE); 
103
//            } else {
104
//                this.comboBoxComponent.setSelectedIndex(OPTION_EXPORT);                
105
//            }
106
            this.dropDownOptions.setVisibleDropdownArrow(true);
107

  
108
            this.jButtonExport = new JButton(i18n.getTranslation("_export"));
109
            
110
            this.jButtonExport.addActionListener((ActionEvent e) -> {
111
                WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
112
                ExportManager exportManager = ExportLocator.getManager();
113
                ExportSwingManager exportSwingManager = ExportSwingLocator.getSwingManager();
114
                ExportProcess process = exportManager.createProcess(layer.getFeatureStore());
115
                JExportProcessPanel panel1 = exportSwingManager.createJExportProcessPanel(process);
116
                windowManager.showWindow(panel1.asJComponent(), "_export", WindowManager.MODE.WINDOW);
117
                MultilayerFinishEditingPanel.Row.this.dropDownOptions.setSelectedIndex(OPTION_DISMISS);
118
                MultilayerFinishEditingPanel.Row.this.panel.updateEnableOkButton();
119
            });
120
            
121
            this.dropDownOptions.addItemListener((ItemEvent e) -> {
122
                panel.updateEnableOkButton();
123
            });
124
            
125
//            this.comboBoxComponent.addActionListener(new ActionListener() {
126
//                @Override
127
//                public void actionPerformed(ActionEvent e) {
128
//                    panel.updateEnableOkButton();
129
//                }
130
//            });  
131
        }
132

  
133
        public boolean allowSave() {
134
            return this.layer.getFeatureStore().allowWrite();
135
        }
136
        
137
        public FLyrVect getLayer() {
138
            return this.layer;
139
        }
140

  
141
        public JLabel getJLabel() {
142
            String layerName = this.layer.getName();
143
            JLabel layerNameJLabel = new JLabel(layerName);
144
            return layerNameJLabel;
145
        }
146

  
147
        public JComponent getJDropDown() {
148
            return this.dropDownOptions.asJComponent();
149
        }
150

  
151
        public JButton getJButton() {
152
            return this.jButtonExport;
153
        }
154

  
155
        public int getJComboBoxOption() {
156
            LabeledValue<Integer> optionSelected = (LabeledValue) this.dropDownOptions.getSelectedItem();
157
            return optionSelected.getValue();
158
        }
159
    }
160
    
161
    private final List<Row> rows;
162
    private final MapContext mapContext;
163

  
164
    public MultilayerFinishEditingPanel(MapContext mapContext) {
165
        this.rows = new ArrayList<>();
166
        this.mapContext = mapContext;
167
        this.initComponents();
168
    }
169

  
170
    private Row getRow(int rowIndex) {
171
        Row row = this.rows.get(rowIndex);
172
        return row;
173
    }
174

  
175
    public void addLayer(FLayer layer) {
176
        if (layer instanceof FLyrVect) {
177
            FLyrVect layerVect = (FLyrVect) layer;
178
            this.rows.add(new Row(this, layerVect));
179
        }
180
    }
181

  
182
    public void build() {
183
        this.removeAll();
184
        this.setLayout(new GridBagLayout());
185
        int rownum = 0;
186
        for (Row row : rows) {
187
            addComponent(rownum, 0, row.getJLabel());
188
            addComponent(rownum, 1, row.getJDropDown());
189
            addComponent(rownum, 2, row.getJButton());
190
            rownum++;
191
        }        
192
        GridBagConstraints c = new GridBagConstraints();
193
        c.fill = GridBagConstraints.BOTH;
194
        c.weighty = 0.9;
195
        c.weightx = 0.9;
196
        c.gridx = 1;
197
        c.gridy = rownum;
198
        this.add(new JLabel(""), c);
199
    }
200

  
201
    private void addComponent(int gridY, int gridX, JComponent component) {
202
        GridBagConstraints c = new GridBagConstraints();
203
        c.insets = new Insets(5, 5, 5, 5);
204
        c.fill = GridBagConstraints.HORIZONTAL;
205
        c.ipadx = 2;
206
        c.ipady = 2;
207
        c.gridx = gridX;
208
        c.gridy = gridY;
209
        this.add(component, c);
210
    }
211

  
212
    private void initComponents() {
213
        Iterator<FLayer> layers = mapContext.deepiterator();
214
        while (layers.hasNext()) {
215
            FLayer layer = layers.next();
216
            if (layer.isEditing()) {
217
                this.addLayer(layer);
218
            }
219
        }
220
        this.build();
221
    }
222

  
223
    private boolean checkExportLayers() {
224
        boolean exportLayer = false;
225
        for (int i = 0; i < this.rows.size(); i++) {
226
            Row row = this.getRow(i);
227
            if (row.getJComboBoxOption() == OPTION_EXPORT) {
228
                exportLayer = true;  
229
            }
230
        }
231
        return exportLayer;   
232
    }
233
    
234
    private void updateEnableOkButton(){
235
        if (this.dialog == null){
236
            return;
237
        }
238
        if (checkExportLayers()){
239
            dialog.setButtonEnabled(WindowManager_v2.BUTTON_OK, false);
240
        }else {
241
            dialog.setButtonEnabled(WindowManager_v2.BUTTON_OK, true);
242
        }
243
    }
244
    
245
    public void setDialog (Dialog dialog ){
246
        this.dialog=dialog;
247
        updateEnableOkButton();
248
    }
249
    
250
//    private boolean checkDismissLayers() {
251
//        boolean dismissLayer = false;
252
////        List dismissLayers = new ArrayList();
253
//        for (int i = 0; i < this.rows.size(); i++) {
254
//            Row row = this.getRow(i);
255
//            if (row.getJComboBoxOption() == OPTION_DISMISS) {
256
//                dismissLayer = true;
257
////                dismissLayers.add(row.getLayer().getName());  
258
//            }
259
//        }
260
////        if (dismissLayer) {
261
////            I18nManager i18n = ToolsLocator.getI18nManager();
262
////            StringBuilder message = new StringBuilder();
263
////            message.append(i18n.getTranslation("_The_following_layers_dismiss_the_changes"));
264
////            for (int i = 0; i < dismissLayers.size(); i++) {
265
////                message.append(dismissLayers.get(i));
266
////                message.append('\n');
267
////            }
268
////            String title = i18n.getTranslation("_Dismiss_information");
269
////            ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog(message.toString(),
270
////                    title,
271
////                    JOptionPane.OK_CANCEL_OPTION);   
272
////        }        
273
//        return dismissLayer;
274
//    }
275
    
276
    public void apply() {
277
        for (int i = 0; i < this.rows.size(); i++) {
278
            Row row = this.getRow(i);
279
            if (row.getJComboBoxOption() == OPTION_SAVE) {
280
                try {
281
                    row.getLayer().getFeatureStore().finishEditing();
282
                } catch (DataException ex) {
283
                LOGGER.error(PluginServices.getText(this, "Finish editing process has problems, save option"), ex);
284
                }
285
            } else if (row.getJComboBoxOption() == OPTION_DISMISS) {
286
                try {
287
                    row.getLayer().getFeatureStore().cancelEditing();
288
                } catch (DataException ex) {
289
                LOGGER.error(PluginServices.getText(this, "Finish editing process has problems, dismiss option"), ex);
290
                }
291
            }
292
        }
293
    }
294
    
295
    @Override
296
    public JComponent asJComponent() {
297
        ToolsSwingManager toolSwingmanager = ToolsSwingLocator.getToolsSwingManager();
298
        
299
        this.build();
300
        this.setPreferredSize(new Dimension(400, 200));
301
       
302
        JScrollPane scrollPanel = new JScrollPane();
303
        scrollPanel.setPreferredSize(new Dimension(420, 220));
304
        scrollPanel.setViewportView(this);
305
        
306
        toolSwingmanager.removeBorder(this);
307
        scrollPanel.setBorder(null);
308
        return scrollPanel;
309
    }
310
}
org.gvsig.vectorediting/tags/org.gvsig.vectorediting-1.0.253/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/vectorediting/app/mainplugin/EditingToolOptionsPanel.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.vectorediting.app.mainplugin;
7

  
8
import java.awt.BorderLayout;
9
import java.awt.FlowLayout;
10
import java.awt.GridBagConstraints;
11
import java.awt.GridBagLayout;
12
import java.awt.event.ActionEvent;
13
import java.awt.event.KeyEvent;
14
import java.awt.event.KeyListener;
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
import java.util.List;
18
import java.util.Map;
19
import java.util.Objects;
20
import javax.json.JsonObject;
21
import javax.json.JsonValue;
22
import javax.swing.ImageIcon;
23
import javax.swing.JButton;
24
import javax.swing.JLabel;
25
import javax.swing.JPanel;
26
import javax.swing.JTabbedPane;
27
import javax.swing.JTextField;
28
import javax.swing.SwingConstants;
29
import javax.swing.SwingUtilities;
30
import javax.swing.UIManager;
31
import org.apache.commons.lang.StringUtils;
32
import org.gvsig.featureform.swing.JFeatureForm;
33
import org.gvsig.fmap.dal.DALLocator;
34
import org.gvsig.fmap.dal.DataTypes;
35
import org.gvsig.fmap.dal.exception.DataException;
36
import org.gvsig.fmap.dal.feature.EditableFeature;
37
import org.gvsig.fmap.dal.feature.Feature;
38
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
39
import org.gvsig.fmap.dal.feature.FeatureStore;
40
import org.gvsig.fmap.dal.feature.FeatureType;
41
import org.gvsig.fmap.dal.feature.FeatureTypeDefinitionsManager;
42
import org.gvsig.fmap.dal.swing.DALSwingLocator;
43
import org.gvsig.fmap.dal.swing.DataSwingManager;
44
import org.gvsig.json.Json;
45
import org.gvsig.tools.ToolsLocator;
46
import org.gvsig.tools.bookmarksandhistory.Bookmarks;
47
import org.gvsig.tools.bookmarksandhistory.BookmarksAndHistoryManager;
48
import org.gvsig.tools.dynform.DynFormDefinition;
49
import org.gvsig.tools.dynform.DynFormFieldDefinition;
50
import org.gvsig.tools.dynform.DynFormLocator;
51
import org.gvsig.tools.dynform.DynFormManager;
52
import org.gvsig.tools.dynform.JDynForm;
53
import org.gvsig.tools.dynform.JDynFormField;
54
import org.gvsig.tools.dynobject.DynClass;
55
import org.gvsig.tools.dynobject.DynField_v2;
56
import org.gvsig.tools.dynobject.DynObjectValueItem;
57
import org.gvsig.tools.dynobject.DynStruct;
58
import org.gvsig.tools.dynobject.DynStruct_v2;
59
import org.gvsig.tools.dynobject.Tags;
60
import org.gvsig.tools.i18n.I18nManager;
61
import org.gvsig.tools.observer.Notification;
62
import org.gvsig.tools.observer.Observable;
63
import org.gvsig.tools.observer.Observer;
64
import org.gvsig.tools.persistence.PersistenceManager;
65
import org.gvsig.tools.persistence.Persistent;
66
import org.gvsig.tools.persistence.PersistentState;
67
import org.gvsig.tools.persistence.exception.PersistenceException;
68
import org.gvsig.tools.swing.api.ToolsSwingLocator;
69
import org.gvsig.tools.swing.api.ToolsSwingManager;
70
import org.gvsig.tools.swing.api.ToolsSwingUtils;
71
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_GETVALUE;
72
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_SETVALUE;
73
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController;
74
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController.BookmarkEvent;
75
import org.gvsig.vectorediting.app.mainplugin.dynformfield.point.JDynFormFieldPointFactory;
76
import org.gvsig.vectorediting.lib.api.EditingService;
77
import org.gvsig.vectorediting.lib.api.EditingServiceParameter;
78
import org.gvsig.vectorediting.lib.api.EditingServiceParameterOptions;
79
import org.gvsig.vectorediting.lib.api.EditingServiceParameterOptions.ParameterOption;
80
import org.gvsig.vectorediting.swing.api.EditingContext;
81
import org.slf4j.Logger;
82
import org.slf4j.LoggerFactory;
83

  
84
/**
85
 *
86
 * @author gvSIG Team
87
 */
88
@SuppressWarnings("UseSpecificCatch")
89
class EditingToolOptionsPanel extends JPanel {
90
    private static final Logger LOGGER = LoggerFactory.getLogger(EditingToolOptionsPanel.class);
91

  
92
    private static final String BOOKMARKSANDHISTORY_NAME = "EditingToolOptionsPanel";
93
    
94
    private final EditingContext editingContext;
95
    private EditingService service;
96
    private JDynForm form;
97
    private DynStruct_v2 definition;
98
    private final Observer contextObserver = (Observable observable, Object notification) -> {
99
        doContextChanged((Notification) notification);
100
    };
101
    private final Observer serviceObserver = (Observable observable, Object notification) -> {
102
        doServiceChanged((Notification) notification);
103
    };
104
    private JFeatureForm featureform;
105
    private JButton applyDefaultValuesButton;
106
    private ImageIcon confirmIcon;
107
    
108
    private static final Map<String, JsonObject> defaultValues = new HashMap<>();
109
    private JTabbedPane tab;
110
    private static int currentTab = 0;
111
    private JButton acceptOptionsButton;
112
    private JTextField txtBookmarkName;
113
    private KeyListener keylistener = new KeyListener() {
114
        @Override
115
        public void keyTyped(KeyEvent e) {
116
        }
117

  
118
        @Override
119
        public void keyPressed(KeyEvent e) {
120
            switch (e.getKeyCode()) {
121
                case KeyEvent.VK_DOWN:
122
                case KeyEvent.VK_UP:
123
                case KeyEvent.VK_LEFT:
124
                case KeyEvent.VK_RIGHT:
125
                case KeyEvent.VK_PAGE_DOWN:
126
                case KeyEvent.VK_PAGE_UP:
127
                    break;
128
                default:
129
                    e.consume();
130
            }
131
        }
132

  
133
        @Override
134
        public void keyReleased(KeyEvent e) {
135
        }
136
    };
137

  
138
    @SuppressWarnings(value = {"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})
139
    public EditingToolOptionsPanel(EditingContext editingContext) {
140
        this.setLayout(new BorderLayout());
141
        this.txtBookmarkName = new JTextField();
142
        this.txtBookmarkName.setBorder(null);
143
        this.txtBookmarkName.setBackground(UIManager.getColor(ToolsSwingManager.COLOR_PANEL_BACKGROUND));
144
        this.txtBookmarkName.addKeyListener(keylistener);
145
//        this.txtBookmarkName.setFocusable(false);
146
        this.editingContext = editingContext;
147
        this.editingContext.addObserver(this.contextObserver);
148
        EditingService activeService = editingContext.getActiveService();
149
        this.set(activeService);
150
        this.put(activeService);
151
        ToolsSwingUtils.ensureRowsCols(this, 20, 60,50,120);
152
        try {
153
            this.confirmIcon = ToolsSwingLocator.getIconThemeManager()
154
                    .getCurrent().get("common-applychanges");
155
        } catch(Exception ex) {
156
            
157
        }
158
    }
159

  
160
    private Bookmarks getBookmarks(FeatureStore store) {
161
        boolean useBookmarksByTable = true; // TODO: poner esto en preferencias de edicion.
162
        BookmarksAndHistoryManager manager = ToolsLocator.getBookmarksAndHistoryManager();
163
        
164
        if( useBookmarksByTable ) {
165
            return manager.getBookmarksGroup(BOOKMARKSANDHISTORY_NAME+"_"+store.getName());        
166
        } else {
167
            return manager.getBookmarksGroup(BOOKMARKSANDHISTORY_NAME);        
168
        }
169
        
170
    }
171
    
172
    private void set(EditingService service) {
173
        if(this.service == service && service != null) {
174
            return;
175
        }
176

  
177
        if (this.service != null) {
178
            this.service.deleteObserver(this.serviceObserver);
179
        }
180
        I18nManager i18n = ToolsLocator.getI18nManager();
181
        DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager();
182
        if(this.tab != null){
183
            currentTab = this.tab.getSelectedIndex();
184
        }
185
        if (service == null) {
186
            this.removeAll();
187
            this.tab = null;
188
            JLabel label = new JLabel(
189
                    "<html><center>" +
190
                    i18n.getTranslation("_Activate_an_editing_tool_to_see_your_options_here")+
191
                    "</center></html>"
192
            );
193
            label.setHorizontalAlignment(SwingConstants.CENTER);
194
            this.add(label, BorderLayout.CENTER);
195
        } else if( service != this.service ) {
196
            this.removeAll();
197
            this.tab = null;
198
            FeatureStore store = service.getStore();
199
            this.add(createHeader(store), BorderLayout.NORTH);
200

  
201
            this.tab = new JTabbedPane();
202
            tab.setTabPlacement(JTabbedPane.BOTTOM);
203
            tab.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
204
            
205
            this.add(tab, BorderLayout.CENTER);
206
            
207
            definition = this.getToolOptionsDefinition(service);
208
            if (definition != null) {
209
                DynFormManager dynFormManager = DynFormLocator.getDynFormManager();
210
                form = dynFormManager.createJDynForm(definition);
211

  
212
                JPanel optionsPanel = new JPanel();
213
                optionsPanel.setLayout(new BorderLayout());
214
                optionsPanel.add(form.asJComponent(), BorderLayout.CENTER);
215
                JButton cancelButton = new JButton(i18n.getTranslation("_Cancel"));
216
                cancelButton.addActionListener((e) -> {
217
                    editingContext.cancelActiveService();
218
                });
219
                this.acceptOptionsButton = new JButton(i18n.getTranslation("_Accept"));
220
                this.acceptOptionsButton.addActionListener((e) -> {
221
                    applyOptions();
222
                });
223
                JPanel buttonsPanel = new JPanel();
224
                buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 2, 0 ));
225
                buttonsPanel.add(this.acceptOptionsButton);
226
                buttonsPanel.add(cancelButton);
227
                optionsPanel.add(buttonsPanel, BorderLayout.PAGE_END);
228

  
229
                tab.add(i18n.getTranslation("_Options"), optionsPanel);
230

  
231
                this.form.addListener(new JDynForm.JDynFormListener() {
232
                    @Override
233
                    public void message(String message) {
234
                    }
235

  
236
                    @Override
237
                    public void fieldChanged(JDynFormField field) {
238
                        if (acceptOptionsButton != null) {
239
                            acceptOptionsButton.setIcon(confirmIcon);
240
                        }
241
                    }
242
                });
243
            }
244
            try {
245
                JsonObject xx = defaultValues.get(store.getFullName());
246
                EditableFeature f = service.getDefaultFeatureValues();
247
                if(xx != null){
248
                    f.copyFrom(xx);
249
                }
250
                DynFormDefinition formdef = this.createFormDefinition(service);
251
                this.featureform = dataSwingManager.createJFeatureForm(formdef);                
252
                this.featureform.getDynForm().setContext(dataSwingManager.createFeaturesFormContext(store));
253
                this.featureform.setFeature(f);
254
                JPanel valuesPanel = new JPanel();
255
                valuesPanel.setLayout(new BorderLayout());
256
                valuesPanel.add(featureform.asJComponent(), BorderLayout.CENTER);
257
                applyDefaultValuesButton = new JButton(i18n.getTranslation("_Apply"));
258
                applyDefaultValuesButton.addActionListener((e) -> { applyDefaultValues(); });
259
                JButton resetDefaultValuesButton = new JButton(i18n.getTranslation("_Reset"));
260
                resetDefaultValuesButton.addActionListener((e) -> {
261
                    resetDefaultValues();
262
                });
263
                
264
                Bookmarks bookmarks = this.getBookmarks(store);
265
                JButton bookmarksButton = new JButton("...");
266
                BookmarksController bookmarksController = ToolsSwingLocator.getToolsSwingManager().createBookmarksController(
267
                        bookmarks,
268
                        bookmarksButton
269
                );
270
                bookmarksController.addActionListener((ActionEvent e) -> {
271
                    EditableFeature feature;
272
                    BookmarkEvent<EditingToolOptionsDefaultValueBookmark> b = (BookmarkEvent<EditingToolOptionsDefaultValueBookmark>) e;
273
                    switch (b.getID()) {
274
                        case ID_GETVALUE:
275
                            EditingToolOptionsDefaultValueBookmark bookmark = new EditingToolOptionsDefaultValueBookmark();
276
                            bookmark.setDefaultValues(service.getDefaultFeatureValues());
277
                            b.setCurrentValue(bookmark);
278
                            break;
279
                        case ID_SETVALUE:
280
                            if (b.getCurrentValue() == null) {
281
                                return;
282
                            }
283
                            JsonObject bookmarkFeature = b.getCurrentValue().getDefaultValues();
284
                            feature = service.getDefaultFeatureValues();
285
                            feature.copyFrom(bookmarkFeature);
286
                            featureform.setFeature(feature);
287
                            applyDefaultValues();
288
                            txtBookmarkName.setText(b.getBookmark().getName());
289
                            txtBookmarkName.setCaretPosition(0);
290
                            break;
291
                    }
292
                });
293

  
294
                JPanel applyPanel = new JPanel();
295
                applyPanel.setLayout(new FlowLayout(FlowLayout.RIGHT,4,0));
296
                applyPanel.add(applyDefaultValuesButton);
297
                applyPanel.add(resetDefaultValuesButton);
298
                applyPanel.add(bookmarksButton);
299
                valuesPanel.add(applyPanel, BorderLayout.PAGE_END);
300
                
301
                tab.add(i18n.getTranslation("_Default_values"), valuesPanel );
302
                
303
                featureform.getDynForm().addListener(new JDynForm.JDynFormListener() {
304
                    @Override
305
                    public void message(String message) {
306
                    }
307

  
308
                    @Override
309
                    public void fieldChanged(JDynFormField field) {
310
                        if(applyDefaultValuesButton != null){
311
                            applyDefaultValuesButton.setIcon(confirmIcon);
312
                        }
313
                    }
314
                });
315
                
316
            } catch (Exception ex) {
317
                LOGGER.debug("Can't create panel",ex);
318
            }
319
            ToolsSwingUtils.ensureRowsCols(this, 8, 43, 25, 60);
320
            try {
321
                tab.setSelectedIndex(currentTab);
322
            } catch (Exception ex) {
323
                LOGGER.debug("Can't activate tab",ex);
324
            }
325
            service.addObserver(this.serviceObserver);
326
        }
327
        this.service = service;
328
    }
329

  
330
    private DynFormDefinition createFormDefinition(EditingService service) throws DataException {
331
        FeatureTypeDefinitionsManager featureTypeDefinitionsManager = DALLocator.getFeatureTypeDefinitionsManager();
332
        
333
        FeatureStore store = service.getStore();
334
        FeatureType featureType = store.getDefaultFeatureType();
335
        DynClass dynClass = featureTypeDefinitionsManager.get(store,featureType);
336
        DynFormDefinition formdef = DynFormLocator.getDynFormManager().createDefinition(dynClass);
337
        for (FeatureAttributeDescriptor attr : featureType) {
338
            if( attr.isPrimaryKey() || attr.isReadOnly() ) {
339
                formdef.remove(attr.getName());
340
            }
341
        }
342
        for (DynFormFieldDefinition fielddef : formdef) {
343
            if( fielddef.isMandatory() ) {
344
                fielddef.setMandatory(false);
345
                fielddef.setLabel("<html><b>"+fielddef.getLabel()+"</b></html>");
346
            }
347
        }
348
        return formdef;
349
    }
350
    
351
    private DynStruct_v2 getToolOptionsDefinition(EditingService service) {
352
        if (service == null) {
353
            return null;
354
        }
355
        DynStruct_v2 def = (DynStruct_v2) ToolsLocator.getDynObjectManager().createDynClass(
356
                service.getName(), null
357
        );
358
        I18nManager i18n = ToolsLocator.getI18nManager();
359
        DynField_v2 field;
360
        Tags tags;
361
        List<ServiceParameterField> params = this.getServiceParameters(service);
362
        for (ServiceParameterField param : params) {
363
            switch(param.getType()) {
364
                case POSITION:
365
                    field = (DynField_v2) def.addDynField(param.getFieldName(), DataTypes.GEOMETRY);
366
                    field.setLabel(i18n.getTranslation(param.getName()));
367
                    field.setDescription(i18n.getTranslation(param.getDescription()));
368
                    field.setDefaultFieldValue(param.getDefaultValue());
369
                    tags = field.getTags();
370
                    tags.set("EditingContext", this.editingContext);
371
                    tags.set("ParamType", param.getType());
372
                    field.setSubtype(JDynFormFieldPointFactory.NAME);
373
                    field.setMandatory(false);
374
                    break;
375
                case LIST_POSITIONS:
376
                    field = (DynField_v2) def.addDynField(param.getFieldName(), DataTypes.GEOMETRY);
377
                    field.setLabel(i18n.getTranslation(param.getName()));
378
                    field.setDescription(i18n.getTranslation(param.getDescription()));
379
                    field.setDefaultFieldValue(param.getDefaultValue());
380
                    tags = field.getTags();
381
                    tags.set("EditingContext", this.editingContext);
382
                    tags.set("ParamType", param.getType());
383
                    field.setSubtype(JDynFormFieldPointFactory.NAME);
384
                    field.setMandatory(false);
385
                    break;
386
                case VALUE:
387
                    field = (DynField_v2) def.addDynFieldDouble(param.getFieldName());
388
//                    field = (DynField_v2) def.addDynField(param.getFieldName(), param.getDataType());
389
                    if( param.isAditional() ) {
390
                        field.setLabel(i18n.getTranslation("_Value"));
391
                    } else {
392
                        field.setLabel(i18n.getTranslation(param.getName()));
393
                    }
394
                    tags = field.getTags();
395
                    tags.set("ParamType", param.getType());
396
                    field.setDescription(i18n.getTranslation(param.getDescription()));
397
                    field.setDefaultFieldValue(param.getDefaultValue());
398
                    field.setMandatory(false);
399
                    break;
400

  
401
                case DISTANCE:
402
                    field = (DynField_v2) def.addDynFieldDouble(param.getFieldName());
403
//                    field = (DynField_v2) def.addDynField(param.getFieldName(), param.getDataType());
404
                    if( param.isAditional() ) {
405
                        field.setLabel(i18n.getTranslation("_Distance"));
406
                    } else {
407
                        field.setLabel(i18n.getTranslation(param.getName()));
408
                    }
409
                    tags = field.getTags();
410
                    tags.set("ParamType", param.getType());
411
                    field.setDescription(i18n.getTranslation(param.getDescription()));
412
                    field.setDefaultFieldValue(param.getDefaultValue());
413
                    field.setMandatory(false);
414
                    break;
415

  
416
                case OPTION:
417
                    field = (DynField_v2) def.addDynField(param.getFieldName(), param.getDataType());
418
                    if( param.isAditional() ) {
419
                        field.setLabel(i18n.getTranslation("_Options"));
420
                    } else {
421
                        field.setLabel(i18n.getTranslation(param.getName()));
422
                    }
423
                    field.setDescription(i18n.getTranslation(param.getDescription()));
424
                    List<DynObjectValueItem> availableValues = new ArrayList<>();
425
                    availableValues.add(new DynObjectValueItem(null, " "));
426
                    if(param.getOptions() == null){
427
                        for (ParameterOption option : param.getOptions2()) {
428
                            Object value = option.getValue();
429
                            String label = i18n.getTranslation(option.getLabel());
430
                            availableValues.add(new DynObjectValueItem(value, label));
431
                        }
432
                    } else {
433
                        for (Map.Entry<String, String> option : param.getOptions().entrySet()) {
434
                            String value = option.getKey();
435
                            String label = i18n.getTranslation(option.getValue());
436
                            availableValues.add(new DynObjectValueItem(value, label));
437
                        }
438
                    }
439
                    tags = field.getTags();
440
                    tags.set("ParamType", param.getType());
441
                    field.setAvailableValues(availableValues);
442
                    field.setDefaultFieldValue(param.getDefaultValue());
443
                    field.setMandatory(false);
444
                    break;
445
                case GEOMETRY:
446
                case SELECTION:
447
                case CLIPBOARD:
448
                    break;
449
            }
450
        }
451
        return def;
452
    }
453

  
454
    private void clear() {
455
        this.form.clear();
456
    }
457

  
458
    private void put(EditingService service) {
459
        if(this.service != service || service == null) {
460
            return;
461
        }
462

  
463
        List<ServiceParameterField> params = this.getServiceParameters(service); 
464
        for (ServiceParameterField param : params) {
465
            if(param.getIgnoreCurrentValue()){
466
                this.form.setValue(
467
                        param.getFieldName(), 
468
                        null
469
                );
470
                
471
            } else {
472
                this.form.setValue(
473
                        param.getFieldName(), 
474
                        service.getValue(param.getParameters(),param.getType())
475
                );
476
            }
477
        }
478
    }
479

  
480
    private boolean ignore_events = false;
481
    private void doServiceChanged(Notification notification) {
482
        if( ignore_events ) {
483
            return;
484
        }
485
        try {
486
            ignore_events = true;
487
            switch (notification.getType()) {
488
                case EditingService.PARAMETER_CHANGED2_NOTIFICATION:
489
                case EditingService.PARAMETER_CHANGED1_NOTIFICATION:
490
                    this.put(this.editingContext.getActiveService());
491
                    break;
492
                case EditingService.ACTIVATE_NOTIFICATION:
493
                    this.set(this.editingContext.getActiveService());
494
                    this.put(this.editingContext.getActiveService());
495
                    break;
496
                case EditingService.START_NOTIFICATION:
497
    //                this.clear();
498
                    break;
499
            }
500
        } finally {
501
            ignore_events = false;
502
        }
503
    }
504

  
505
    private void doContextChanged(Notification notification) {
506
        if (ignore_events) {
507
            return;
508
        }
509
        try {
510
            ignore_events = true;
511
            switch (notification.getType()) {
512
                case EditingContext.CHANGE_SELECTED_TOOL_NOTIFICATION:
513
                    EditingService activeService = this.editingContext.getActiveService();
514
                    this.set(activeService);
515
                    if (activeService != null) {
516
                        this.put(activeService);
517
                    }
518
                    break;
519

  
520
            }
521
        } finally {
522
            ignore_events = false;
523
        }
524
    }
525

  
526
    public void applyDefaultValues() {
527
        I18nManager i18n = ToolsLocator.getI18nManager();
528
        EditableFeature feature = this.service.getDefaultFeatureValues();
529
        this.featureform.fetch(feature);
530
        this.applyDefaultValuesButton.setIcon(null);
531
        defaultValues.put(this.service.getStore().getFullName(), feature.toJson());
532
        this.txtBookmarkName.setText("");
533
    }
534
    
535
    public void resetDefaultValues() {
536
        try {
537
            FeatureStore store = this.service.getStore();
538
            EditableFeature resetValues = store.createNewFeature();
539
            EditableFeature feature = this.service.getDefaultFeatureValues();
540
            feature.copyFrom(resetValues);
541
            
542
            this.featureform.setFeature(feature);
543
            applyDefaultValuesButton.setIcon(null);
544
            defaultValues.put(this.service.getStore().getFullName(), feature.toJson());
545
            this.txtBookmarkName.setText("");
546
        } catch (Exception ex) {
547
            LOGGER.warn("Can't reset default values",ex);
548
        }
549
    }
550
    
551
    public void applyOptions() {
552
        boolean ignore_events_save = this.ignore_events;
553
        try {
554
            this.ignore_events = true;
555
            List<ServiceParameterField> params = this.getServiceParameters(service);
556
            for (ServiceParameterField param : params) {
557
                Object value = this.form.getValue(param.getFieldName());
558
                try {
559
                    editingContext.setValue(param.getParameters(), value, false);
560
                } catch (Throwable th) {
561
                    LOGGER.debug("Can't set service parameter '" + param.getName() + "' to '" + Objects.toString(value) + "'.", th);
562
                }
563
            }
564
            try {
565
                editingContext.nextParameter();
566
            } catch (Exception ex) {
567
                LOGGER.debug("Can't apply service parameters.", ex);
568
            }
569
            this.acceptOptionsButton.setIcon(null);
570
        } finally {
571
            this.ignore_events = ignore_events_save;
572
        }
573
        this.put(service);
574
    }
575
    
576
    private static class ServiceParameterField {
577
        private final EditingServiceParameter param;
578
        private final EditingServiceParameter.TYPE type;
579
        private final String fieldName;
580
        private final boolean aditional;
581
        private boolean ignoreCurrentValue;
582
        
583
        public ServiceParameterField(
584
            EditingServiceParameter param,
585
            EditingServiceParameter.TYPE type,
586
            String fieldName,
587
            boolean aditional
588
            ) {
589
            this.aditional = aditional;
590
            this.fieldName = fieldName;
591
            this.param = param;
592
            this.type = type;
593
            this.ignoreCurrentValue = false;
594
        }
595

  
596
        private EditingServiceParameter.TYPE getType() {
597
            return this.type;
598
        }
599

  
600
        private String getName() {
601
            return this.param.getName();
602
        }
603

  
604
        private int getDataType() {
605
            return this.param.getDataType();
606
        }
607

  
608
        private String getDescription() {
609
            return this.param.getDescription();
610
        }
611

  
612
        private String getFieldName() {
613
            return this.fieldName;
614
        }
615

  
616
        private Object getDefaultValue() {
617
            return this.param.getDefaultValue();
618
        }
619

  
620
        private Map<String, String> getOptions() {
621
            return this.param.getOptions();
622
        }
623

  
624
        private EditingServiceParameterOptions getOptions2() {
625
            return this.param.getOptions2();
626
        }
627

  
628
        private boolean isAditional() {
629
            return this.aditional;
630
        }
631

  
632
        private EditingServiceParameter getParameters() {
633
            return this.param;
634
        }
635

  
636
        public void setIgnoreCurrentValue(boolean ignoreCurrentValue) {
637
            this.ignoreCurrentValue = ignoreCurrentValue;
638
        }
639

  
640
        public boolean getIgnoreCurrentValue() {
641
            return this.ignoreCurrentValue;
642
        }
643
    }
644
    
645
    private List<ServiceParameterField> getServiceParameters(EditingService service) {
646
        List<ServiceParameterField>params = new ArrayList<>();
647
        EditingServiceParameter.TYPE paramTypesOrdered[] =  new EditingServiceParameter.TYPE[] {
648
            EditingServiceParameter.TYPE.POSITION, 
649
            EditingServiceParameter.TYPE.LIST_POSITIONS, 
650
            EditingServiceParameter.TYPE.VALUE, 
651
            EditingServiceParameter.TYPE.DISTANCE, 
652
            EditingServiceParameter.TYPE.OPTION, 
653
            EditingServiceParameter.TYPE.GEOMETRY, 
654
            EditingServiceParameter.TYPE.SELECTION, 
655
            EditingServiceParameter.TYPE.CLIPBOARD            
656
        };
657
        int n = 0;
658
        for (EditingServiceParameter param : service.getParameters()) {
659
            int count = 0;
660
            for (int ntype = 0; ntype < paramTypesOrdered.length; ntype++) {
661
                EditingServiceParameter.TYPE type = paramTypesOrdered[ntype];
662
                if( !param.getTypes().contains(type) ) {
663
                    continue;
664
                }
665
                switch(type) {
666
                    case POSITION:
667
                    case LIST_POSITIONS:
668
                    case DISTANCE:
669
                    case GEOMETRY:
670
                    case SELECTION:
671
                    case CLIPBOARD:
672
                        break;
673
                    case VALUE:
674
                    case OPTION:
675
                        String name = String.format("param%02d%02d", n, ntype);
676
                        ServiceParameterField serviceField = new ServiceParameterField(param, type, name, count>0);
677
                        if(param.getTypes().contains(EditingServiceParameter.TYPE.LIST_POSITIONS)){
678
                            //Ver la herramienta Polyline
679
                            serviceField.setIgnoreCurrentValue(true);
680
                        }
681
                        params.add(serviceField);
682
                        count++;
683
                        break;
684

  
685
                }
686
            }
687
            n++;
688
        }
689
        return params;
690
    }
691
    
692
    public static class EditingToolOptionsDefaultValueBookmark implements Persistent {
693
        
694
        private JsonObject values;
695
        private String label;
696
        
697
        public EditingToolOptionsDefaultValueBookmark() {
698
            
699
        }
700
        
701
        public JsonObject getDefaultValues() {
702
            return this.values;
703
        }
704
        
705
        public void setDefaultValues(Feature feature) {
706
            this.values = feature.toJson();
707
        }
708

  
709
        @Override
710
        public String toString() {
711
            try {
712
                StringBuilder buffer = new StringBuilder();
713
                boolean needcolon = false;
714
                for (JsonValue value : this.values.values()) {
715
                    if( value!=null ) {
716
                        String s = Json.toString(value);
717
                        if( StringUtils.isNotBlank(s) ) {
718
                            if( needcolon ) {
719
                                buffer.append(",");
720
                            } else {
721
                                needcolon = true;
722
                            }
723
                            buffer.append(s);
724
                        }
725
                    }
726
                }
727
                return buffer.toString();
728
            } catch(Exception ex) {
729
                return "default values";
730
            }
731
        }
732

  
733
        @Override
734
        public void saveToState(PersistentState state) throws PersistenceException {            
735
            state.set("values", Objects.toString(this.values,null));
736
        }
737

  
738
        @Override
739
        public void loadFromState(PersistentState state) throws PersistenceException {
740
            String json_s = state.getString("values");
741
            if( StringUtils.isBlank(json_s) ) {
742
                this.values = null;
743
            } else {
744
                try {
745
                    this.values = Json.createObject(json_s);
746
                } catch(Exception ex) {
747
                    LOGGER.warn("Can't restore default value from persistence", ex);
748
                }
749
            }
750
        }
751
    }
752
    
753
    public static void registerPersistence() {
754
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
755
        if (manager.getDefinition("EditingToolOptionsDefaultValueBookmark") == null) {
756
            DynStruct definition = manager.addDefinition(EditingToolOptionsDefaultValueBookmark.class,
757
                    "EditingToolOptionsDefaultValueBookmark", "EditingToolOptionsDefaultValueBookmark persistence definition", null, null);
758
            definition.addDynFieldString("values");
759
        }
760
    }
761
    
762
    public JPanel createHeader(FeatureStore store) {
763
        I18nManager i18n = ToolsLocator.getI18nManager();
764
        
765
        String s = i18n.getTranslation("_unknown");
766
        if( store != null ) {
767
            s = store.getName();
768
            FeatureType ft = store.getDefaultFeatureTypeQuietly();
769
            if( ft!=null ) {
770
                if( StringUtils.isNotBlank(ft.getLabel()) && !store.getName().equals(ft.getLabel()) )  {
771
                    s = ft.getLabel() + " ("+store.getName()+")";
772
                } 
773
            }
774
        }
775
        final String storelabel = s;
776
        
777
        final JTextField txtTable = new JTextField();
778
        final JTextField txtTool = new JTextField();
779

  
780
        JLabel lblTable = new JLabel(i18n.getTranslation("_Table")+ ": ");
781
        JLabel lblTool = new JLabel(i18n.getTranslation("_Tool")+ ": ");
782
        
783
        txtTable.setBorder(null);
784
        txtTable.setBackground(UIManager.getColor(ToolsSwingManager.COLOR_PANEL_BACKGROUND));
785
//        txtTable.setFocusable(false);
786

  
787
        txtTool.setBorder(null);
788
        txtTool.setBackground(UIManager.getColor(ToolsSwingManager.COLOR_PANEL_BACKGROUND));
789
//        txtTool.setFocusable(false);
790

  
791
        txtTable.addKeyListener(keylistener);
792
        txtTool.addKeyListener(keylistener);
793
        
794
        JPanel panel = new JPanel();
795
        panel.setLayout(new GridBagLayout());
796
        GridBagConstraints c = new GridBagConstraints();
797
        c.ipadx = 1;
798
        c.ipady = 1;
799
        c.fill = GridBagConstraints.HORIZONTAL;
800

  
801
        c.gridx = 0;
802
        c.gridy = 0;
803
        c.weightx = 0;
804
        panel.add(lblTable, c);
805
        c.gridx = 0;
806
        c.gridy = 1;
807
        c.weightx = 0;
808
        panel.add(lblTool, c);
809
        c.gridx = 1;
810
        c.gridy = 0;
811
        c.weightx = 1;
812
        panel.add(txtTable, c);
813
        c.gridx = 1;
814
        c.gridy = 1;
815
        c.weightx = 1;
816
        panel.add(txtTool, c);
817
        
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff