Revision: 5915
http://sourceforge.net/p/jump-pilot/code/5915
Author: michaudm
Date: 2018-08-18 10:03:14 +0000 (Sat, 18 Aug 2018)
Log Message:
-----------
Add GenerateUniqueRandomIdPlugIn
Modified Paths:
--------------
core/trunk/scripts/default-plugins.xml
core/trunk/src/language/jump.properties
core/trunk/src/language/jump_cz.properties
core/trunk/src/language/jump_de.properties
core/trunk/src/language/jump_es.properties
core/trunk/src/language/jump_fi.properties
core/trunk/src/language/jump_fr.properties
core/trunk/src/language/jump_hu.properties
core/trunk/src/language/jump_it.properties
core/trunk/src/language/jump_ja_JP.properties
core/trunk/src/language/jump_ml.properties
core/trunk/src/language/jump_pt.properties
core/trunk/src/language/jump_pt_BR.properties
core/trunk/src/language/jump_ta_IN.properties
core/trunk/src/language/jump_te.properties
core/trunk/src/language/jump_zh_CN.properties
core/trunk/src/language/jump_zh_HK.properties
Added Paths:
-----------
core/trunk/src/org/openjump/core/ui/plugin/tools/GenerateUniqueRandomIdPlugIn.java
Modified: core/trunk/scripts/default-plugins.xml
===================================================================
--- core/trunk/scripts/default-plugins.xml 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/scripts/default-plugins.xml 2018-08-18 10:03:14 UTC (rev
5915)
@@ -831,6 +831,9 @@
org.openjump.core.ui.plugin.tools.GenerateRandomStringPlugIn
</plug-in>
<plug-in>
+ org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn
+ </plug-in>
+ <plug-in>
de.fho.jump.pirol.plugins.EditAttributeByFormula.EditAttributeByFormulaPlugIn
</plug-in>
<plug-in>
Modified: core/trunk/src/language/jump.properties
===================================================================
--- core/trunk/src/language/jump.properties 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/src/language/jump.properties 2018-08-18 10:03:14 UTC (rev
5915)
@@ -1472,7 +1472,7 @@
org.openjump.core.ui.plugin.tools.GenerateRandomNumberPlugIn.min-value = Min
Value
org.openjump.core.ui.plugin.tools.GenerateRandomNumberPlugIn.max-value = Max
Value
org.openjump.core.ui.plugin.tools.GenerateRandomNumberPlugIn.no-editable-layer-with-numeric-attribute
= No editable layer with numeric attribute
-org.openjump.core.ui.plugin.tools.GenerateRandomStringPlugIn = #T:Generate
random string values
+org.openjump.core.ui.plugin.tools.GenerateRandomStringPlugIn = Generate random
string values
org.openjump.core.ui.plugin.tools.GenerateRandomStringPlugIn.min-length = Min
Length
org.openjump.core.ui.plugin.tools.GenerateRandomStringPlugIn.min-length-tooltip
= Min length of the generated string
org.openjump.core.ui.plugin.tools.GenerateRandomStringPlugIn.max-length = Max
Length
@@ -1487,6 +1487,7 @@
org.openjump.core.ui.plugin.tools.GenerateRandomStringPlugIn.no-editable-layer-with-string-attribute
= No editable layer with string attribute
org.openjump.core.ui.plugin.tools.GenerateRandomStringPlugIn.non-empty-attribute
= Attribute is not empty
org.openjump.core.ui.plugin.tools.GenerateRandomStringPlugIn.overwrite-prompt
= Do you want to overwrite existing values ?
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn = Generate
unique random identifier
org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.Join-Attributes-Spatially
= Join Attributes Spatially
org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.Joins-attributes-of-source-layer-according-to-a-spatial-and-a-statistic-criterion
= Joins attributes of source layer according to a spatial and a statistical
criterion.
org.openjump.core.ui.plugin.tools.JoinAttributesSpatiallyPlugIn.buffer-radius
= buffer radius
Modified: core/trunk/src/language/jump_cz.properties
===================================================================
--- core/trunk/src/language/jump_cz.properties 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/src/language/jump_cz.properties 2018-08-18 10:03:14 UTC (rev
5915)
@@ -2906,4 +2906,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_de.properties
===================================================================
--- core/trunk/src/language/jump_de.properties 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/src/language/jump_de.properties 2018-08-18 10:03:14 UTC (rev
5915)
@@ -2898,4 +2898,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_es.properties
===================================================================
--- core/trunk/src/language/jump_es.properties 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/src/language/jump_es.properties 2018-08-18 10:03:14 UTC (rev
5915)
@@ -2877,4 +2877,5 @@
ui.GenericNames.uphill=velocidad de subida
ui.GenericNames.downhill=velocidad de descenso
ui.GenericNames.select-layers=Seleccionar las capas
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=Ctrl/Shift
y click con el rat\xF2n para seleccionar mas capas
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=Ctrl/Shift
y click con el rat\xF2n para seleccionar mas capas
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_fi.properties
===================================================================
--- core/trunk/src/language/jump_fi.properties 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/src/language/jump_fi.properties 2018-08-18 10:03:14 UTC (rev
5915)
@@ -2875,4 +2875,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_fr.properties
===================================================================
--- core/trunk/src/language/jump_fr.properties 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/src/language/jump_fr.properties 2018-08-18 10:03:14 UTC (rev
5915)
@@ -2907,4 +2907,5 @@
ui.GenericNames.uphill = vitesse \xE0 la mont\xE9e
ui.GenericNames.downhill = vitesse \xE0 la descente
ui.GenericNames.select-layers = Choisissez les couches
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers
= Utilisez les touches Ctrl/Shift avec la souris pour s\xE9lectionner d'autres
couches
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers
= Utilisez les touches Ctrl/Shift avec la souris pour s\xE9lectionner d'autres
couches
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=G\xE9n\xE9rer
un identifiant al\xE9atoire unique
\ No newline at end of file
Modified: core/trunk/src/language/jump_hu.properties
===================================================================
--- core/trunk/src/language/jump_hu.properties 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/src/language/jump_hu.properties 2018-08-18 10:03:14 UTC (rev
5915)
@@ -2894,4 +2894,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_it.properties
===================================================================
--- core/trunk/src/language/jump_it.properties 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/src/language/jump_it.properties 2018-08-18 10:03:14 UTC (rev
5915)
@@ -2879,4 +2879,5 @@
ui.GenericNames.uphill=velocit\xE0 in salita
ui.GenericNames.downhill=velocit\xE0 in discesa
ui.GenericNames.select-layers=Seleziona i livelli
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=Ctrl/Shift
e click con il mouse per selezionare pi\xF9 livelli
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=Ctrl/Shift
e click con il mouse per selezionare pi\xF9 livelli
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_ja_JP.properties
===================================================================
--- core/trunk/src/language/jump_ja_JP.properties 2018-08-17 14:44:52 UTC
(rev 5914)
+++ core/trunk/src/language/jump_ja_JP.properties 2018-08-18 10:03:14 UTC
(rev 5915)
@@ -2900,4 +2900,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_ml.properties
===================================================================
--- core/trunk/src/language/jump_ml.properties 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/src/language/jump_ml.properties 2018-08-18 10:03:14 UTC (rev
5915)
@@ -3675,4 +3675,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_pt.properties
===================================================================
--- core/trunk/src/language/jump_pt.properties 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/src/language/jump_pt.properties 2018-08-18 10:03:14 UTC (rev
5915)
@@ -2899,4 +2899,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_pt_BR.properties
===================================================================
--- core/trunk/src/language/jump_pt_BR.properties 2018-08-17 14:44:52 UTC
(rev 5914)
+++ core/trunk/src/language/jump_pt_BR.properties 2018-08-18 10:03:14 UTC
(rev 5915)
@@ -2899,4 +2899,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_ta_IN.properties
===================================================================
--- core/trunk/src/language/jump_ta_IN.properties 2018-08-17 14:44:52 UTC
(rev 5914)
+++ core/trunk/src/language/jump_ta_IN.properties 2018-08-18 10:03:14 UTC
(rev 5915)
@@ -2898,4 +2898,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_te.properties
===================================================================
--- core/trunk/src/language/jump_te.properties 2018-08-17 14:44:52 UTC (rev
5914)
+++ core/trunk/src/language/jump_te.properties 2018-08-18 10:03:14 UTC (rev
5915)
@@ -3405,4 +3405,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_zh_CN.properties
===================================================================
--- core/trunk/src/language/jump_zh_CN.properties 2018-08-17 14:44:52 UTC
(rev 5914)
+++ core/trunk/src/language/jump_zh_CN.properties 2018-08-18 10:03:14 UTC
(rev 5915)
@@ -3062,4 +3062,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Modified: core/trunk/src/language/jump_zh_HK.properties
===================================================================
--- core/trunk/src/language/jump_zh_HK.properties 2018-08-17 14:44:52 UTC
(rev 5914)
+++ core/trunk/src/language/jump_zh_HK.properties 2018-08-18 10:03:14 UTC
(rev 5915)
@@ -3061,4 +3061,5 @@
ui.GenericNames.uphill=\#T\:uphill speed
ui.GenericNames.downhill=\#T\:downhill speed
ui.GenericNames.select-layers=\#T\:Select layers
-org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
\ No newline at end of file
+org.openjump.core.ui.plugin.raster.DEMStatisticsPlugIn.select-multiple-layers=\#T\:Ctrl/Shift
and mouse click to select more layers
+org.openjump.core.ui.plugin.tools.GenerateUniqueRandomIdPlugIn=#T:Generate
unique random identifier
\ No newline at end of file
Added:
core/trunk/src/org/openjump/core/ui/plugin/tools/GenerateUniqueRandomIdPlugIn.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/tools/GenerateUniqueRandomIdPlugIn.java
(rev 0)
+++
core/trunk/src/org/openjump/core/ui/plugin/tools/GenerateUniqueRandomIdPlugIn.java
2018-08-18 10:03:14 UTC (rev 5915)
@@ -0,0 +1,190 @@
+package org.openjump.core.ui.plugin.tools;
+
+import com.vividsolutions.jump.I18N;
+import com.vividsolutions.jump.feature.AttributeType;
+import com.vividsolutions.jump.feature.Feature;
+import com.vividsolutions.jump.feature.FeatureSchema;
+import com.vividsolutions.jump.workbench.WorkbenchContext;
+import com.vividsolutions.jump.workbench.model.FeatureEventType;
+import com.vividsolutions.jump.workbench.model.Layer;
+import com.vividsolutions.jump.workbench.model.UndoableCommand;
+import com.vividsolutions.jump.workbench.plugin.EnableCheck;
+import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
+import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
+import com.vividsolutions.jump.workbench.plugin.PlugInContext;
+import com.vividsolutions.jump.workbench.ui.*;
+import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller;
+import org.openjump.core.ui.plugin.AbstractUiPlugIn;
+
+import javax.swing.*;
+import java.awt.*;
+import java.util.*;
+import java.util.concurrent.ThreadLocalRandom;
+
+public class GenerateUniqueRandomIdPlugIn extends AbstractUiPlugIn {
+
+ private static String LAYER =
I18N.get("ui.GenericNames.select-layer");
+ private static String ATTRIBUTE =
I18N.get("ui.GenericNames.select-attribute");
+ private static String RANDOM =
I18N.get("org.openjump.core.ui.plugin.tools.GenerateRandom");
+
+ private static String NO_CANDIDATE =
I18N.get("org.openjump.core.ui.plugin.tools.GenerateRandomNumberPlugIn.no-editable-layer-with-numeric-attribute");
+ private static String NON_EMPTY_ATT =
I18N.get("org.openjump.core.ui.plugin.tools.GenerateRandomStringPlugIn.non-empty-attribute");
+ private static String OVERWRITE_PROMPT =
I18N.get("org.openjump.core.ui.plugin.tools.GenerateRandomStringPlugIn.overwrite-prompt");
+
+ private Layer layer;
+ private String attribute;
+
+ public void initialize(PlugInContext context) throws Exception {
+
+ FeatureInstaller featureInstaller = new
FeatureInstaller(context.getWorkbenchContext());
+ featureInstaller.addMainMenuPlugin(
+ this,
+ new String[] {MenuNames.TOOLS, MenuNames.TOOLS_EDIT_ATTRIBUTES,
RANDOM},
+ getName() + "...", false, null,
+ createEnableCheck(context.getWorkbenchContext()));
+ }
+
+ public static MultiEnableCheck createEnableCheck(final WorkbenchContext
workbenchContext) {
+ EnableCheckFactory checkFactory = new EnableCheckFactory(workbenchContext);
+ return new MultiEnableCheck()
+ .add(checkFactory.createAtLeastNLayersMustExistCheck(1))
+ .add(checkFactory.createAtLeastNLayersMustBeEditableCheck(1))
+ .add(new EnableCheck() {
+ @Override
+ public String check(JComponent component) {
+ if (AttributeTypeFilter.NUMSTRING_FILTER.filter(
+
workbenchContext.getLayerManager().getEditableLayers()).size() == 0) {
+ return NO_CANDIDATE;
+ }
+ return null;
+ }
+ });
+ }
+
+ public boolean execute(PlugInContext context) throws Exception{
+ this.reportNothingToUndoYet(context);
+
+ MultiInputDialog dialog = new MultiInputDialog(
+ context.getWorkbenchFrame(), getName(), true);
+ setDialogValues(dialog, context);
+ GUIUtil.centreOnWindow(dialog);
+ dialog.setVisible(true);
+ if (! dialog.wasOKPressed()) { return false; }
+ getDialogValues(dialog);
+ boolean empty = checkAttributeEmpty();
+ if (!empty) {
+ JLabel label = new JLabel();
+ label.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
+ label.setText("<html><body>" + NON_EMPTY_ATT + "<br/>" +
OVERWRITE_PROMPT + "</body></html>");
+ OKCancelDialog okCancelDialog = new OKCancelDialog(dialog,
NON_EMPTY_ATT, true,
+ label,
+ new OKCancelDialog.Validator() {
+ @Override
+ public String validateInput(Component component) {
+ return null;
+ }
+ });
+ okCancelDialog.setVisible(true);
+ if (!okCancelDialog.wasOKPressed()) {
+ return false;
+ }
+ }
+ computeRandomUniqueValues(context);
+ return true;
+ }
+
+ private boolean checkAttributeEmpty() {
+ for (Feature f : layer.getFeatureCollectionWrapper().getFeatures()) {
+ if (f.getAttribute(attribute) != null) return false;
+ }
+ return true;
+ }
+
+ private void computeRandomUniqueValues(PlugInContext context) {
+ FeatureSchema schema =
layer.getFeatureCollectionWrapper().getFeatureSchema();
+ AttributeType type = schema.getAttributeType(attribute);
+ final Collection<Feature> oldFeatures = new ArrayList<>();
+ final Collection<Feature> newFeatures = new ArrayList<>();
+ reportNothingToUndoYet(context);
+ int fcSize = layer.getFeatureCollectionWrapper().getFeatures().size();
+ Number[] numbers = new Number[fcSize];
+ for (int i = 1 ; i <= numbers.length ; i++) {
+ numbers[i-1] = i;
+ }
+ numbers = shuffle(numbers);
+ int index = 0;
+ String format = "%0" + ((int)Math.log10(fcSize)+1) + "d";
+ for (Feature f : layer.getFeatureCollectionWrapper().getFeatures()) {
+ oldFeatures.add(f.clone(true, true));
+ f = f.clone(true, true);
+ Number value = numbers[index++];
+ if (type == AttributeType.DOUBLE) {
+ f.setAttribute(attribute, value.doubleValue());
+ } else if (type == AttributeType.INTEGER) {
+ f.setAttribute(attribute, value.intValue());
+ } else if (type == AttributeType.LONG) {
+ f.setAttribute(attribute, value.longValue());
+ } else if (type == AttributeType.STRING) {
+ f.setAttribute(attribute, String.format(format, value));
+ }
+ newFeatures.add(f);
+ }
+ context.getLayerManager().getUndoableEditReceiver().startReceiving();
+ try {
+ UndoableCommand command =
+ new
UndoableCommand(I18N.get(AutoAssignAttributePlugIn.class.getName())) {
+
+ public void execute() {
+ Iterator<Feature> newFeatIterator = newFeatures.iterator();
+ for (Feature f :
layer.getFeatureCollectionWrapper().getFeatures()) {
+ f.setAttribute(attribute,
newFeatIterator.next().getAttribute(attribute));
+ }
+ layer.getLayerManager().fireFeaturesAttChanged(newFeatures,
+ FeatureEventType.ATTRIBUTES_MODIFIED, layer,
oldFeatures);
+ }
+
+ public void unexecute() {
+ Iterator<Feature> oldFeatIterator = oldFeatures.iterator();
+ for (Feature f :
layer.getFeatureCollectionWrapper().getFeatures()) {
+ f.setAttribute(attribute,
oldFeatIterator.next().getAttribute(attribute));
+ }
+ layer.getLayerManager().fireFeaturesAttChanged(
+ layer.getFeatureCollectionWrapper().getFeatures(),
+ FeatureEventType.ATTRIBUTES_MODIFIED, layer,
newFeatures);
+ }
+ };
+ command.execute();
+
layer.getLayerManager().getUndoableEditReceiver().receive(command.toUndoableEdit());
+ } finally {
+ layer.getLayerManager().getUndoableEditReceiver().stopReceiving();
+ }
+ }
+
+ // Implementing Fisher-Yates shuffle as described in
+ // https://stackoverflow.com/questions/1519736/random-shuffling-of-an-array
+ private Number[] shuffle(Number[] array) {
+ // If running on Java 6 or older, use `new Random()` on RHS here
+ Random rnd = ThreadLocalRandom.current();
+ for (int i = array.length - 1; i > 0; i--)
+ {
+ int index = rnd.nextInt(i + 1);
+ // Simple swap
+ Number a = array[index];
+ array[index] = array[i];
+ array[i] = a;
+ }
+ return array;
+ }
+
+ private void setDialogValues(MultiInputDialog dialog, PlugInContext context)
{
+ layer = context.getLayerableNamePanel().chooseEditableLayer();
+ dialog.addLayerComboBox(LAYER, layer, null,
+
AttributeTypeFilter.NUMSTRING_FILTER.filter(context.getLayerManager().getEditableLayers()));
+ dialog.addAttributeComboBox(ATTRIBUTE, LAYER,
AttributeTypeFilter.NUMSTRING_FILTER, null);
+ }
+
+ private void getDialogValues(MultiInputDialog dialog) {
+ layer = dialog.getLayer(LAYER);
+ attribute = dialog.getText(ATTRIBUTE);
+ }
+}
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel