Revision: 5474
http://sourceforge.net/p/jump-pilot/code/5474
Author: michaudm
Date: 2017-07-26 21:18:55 +0000 (Wed, 26 Jul 2017)
Log Message:
-----------
AutoAssignAttributePlugIn : accept boolean and long as target attributes
Modified Paths:
--------------
core/trunk/ChangeLog
core/trunk/src/org/openjump/core/ui/plugin/tools/AutoAssignAttributePlugIn.java
Modified: core/trunk/ChangeLog
===================================================================
--- core/trunk/ChangeLog 2017-07-26 14:09:43 UTC (rev 5473)
+++ core/trunk/ChangeLog 2017-07-26 21:18:55 UTC (rev 5474)
@@ -3,6 +3,9 @@
# 2. make sure that lines break at 80 chars for constricted display situations
#<-------------------------------- 80 chars
---------------------------------->#
+2017-07-26 mmichaud <[email protected]>
+ * AutoAssignAttributePlugIn : accept boolean and long as target attributes
+
2017-07-18 Nicolas Ribot <[email protected]>
* Network Properties translation files missing from previous commit
Modified:
core/trunk/src/org/openjump/core/ui/plugin/tools/AutoAssignAttributePlugIn.java
===================================================================
---
core/trunk/src/org/openjump/core/ui/plugin/tools/AutoAssignAttributePlugIn.java
2017-07-26 14:09:43 UTC (rev 5473)
+++
core/trunk/src/org/openjump/core/ui/plugin/tools/AutoAssignAttributePlugIn.java
2017-07-26 21:18:55 UTC (rev 5474)
@@ -97,7 +97,7 @@
private boolean assignFromSource = false;
private String sourceAttribute;
- private boolean assignValue = false;
+ private boolean assignValue = true;
private String textToAssign;
public void initialize(PlugInContext context) throws Exception {
@@ -167,8 +167,13 @@
final JComboBox targetAttributeComboBox =
dialog.addAttributeComboBox(TARGET_ATTRIBUTE_COMBO_BOX,
LAYER_COMBO_BOX,
- new AttributeTypeFilter(AttributeTypeFilter.DATE |
AttributeTypeFilter.STRING |
- AttributeTypeFilter.DOUBLE | AttributeTypeFilter.INTEGER),
"");
+ new AttributeTypeFilter(
+ AttributeTypeFilter.DATE |
+ AttributeTypeFilter.STRING |
+ AttributeTypeFilter.DOUBLE |
+ AttributeTypeFilter.INTEGER |
+ AttributeTypeFilter.LONG |
+ AttributeTypeFilter.BOOLEAN), "");
for (int i = 0 ; i < targetAttributeComboBox.getModel().getSize() ;
i++) {
Object item = targetAttributeComboBox.getModel().getElementAt(i);
@@ -177,13 +182,13 @@
// Auto-increment options
dialog.addSeparator();
- final JCheckBox autoIncCheckBox =
dialog.addCheckBox(AUTOINC_CHECK_BOX, autoIncrement);
+ final JRadioButton autoIncRB =
dialog.addRadioButton(AUTOINC_CHECK_BOX, "MODE", autoIncrement, null);
dialog.addTextField(AUTOINC_PATTERN_BOX, pattern, 4, null,
AUTOINC_DESCRIPTION_2);
dialog.addIntegerField(INC_VALUE_EDIT_BOX, 1, 4, "");
// From other attribute option
dialog.addSeparator();
- final JCheckBox fromSourceCheckBox =
dialog.addCheckBox(FROM_SOURCE_CHECK_BOX, assignFromSource);
+ final JRadioButton fromSourceRB =
dialog.addRadioButton(FROM_SOURCE_CHECK_BOX, "MODE", assignFromSource, null);
final JComboBox sourceAttributeComboBox =
dialog.addAttributeComboBox(SOURCE_COMBO_BOX, LAYER_COMBO_BOX,
AttributeTypeFilter.ALL_FILTER,
@@ -196,47 +201,68 @@
initEnableChecks(dialog);
dialog.addSeparator();
- final JCheckBox assignValueCheckBox =
dialog.addCheckBox(ASSIGN_VALUE_CHECK_BOX, assignValue);
+ final JRadioButton assignValueRB =
dialog.addRadioButton(ASSIGN_VALUE_CHECK_BOX, "MODE", assignValue, null);
dialog.addTextField(ASSIGN_VALUE_TEXT_BOX, "", 15, null, "");
updateControls(dialog);
-
- autoIncCheckBox.addActionListener(new ActionListener() {
+
+ targetAttributeComboBox.addActionListener(new ActionListener() {
+ @Override
public void actionPerformed(ActionEvent e) {
+ Layer layer = dialog.getLayer(LAYER_COMBO_BOX);
+ FeatureSchema schema =
layer.getFeatureCollectionWrapper().getFeatureSchema();
+ String attribute = dialog.getText(TARGET_ATTRIBUTE_COMBO_BOX);
+ if (schema.getAttributeType(attribute) ==
AttributeType.BOOLEAN && autoIncrement) {
+ assignValueRB.setSelected(true);
+ }
+ if (schema.getAttributeType(attribute) == AttributeType.DATE
&& autoIncrement) {
+ assignValueRB.setSelected(true);
+ }
updateControls(dialog);
}
});
- fromSourceCheckBox.addActionListener(new ActionListener() {
+
+ autoIncRB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateControls(dialog);
}
});
- assignValueCheckBox.addActionListener(new ActionListener() {
+ fromSourceRB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateControls(dialog);
}
});
+ assignValueRB.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ updateControls(dialog);
+ }
+ });
return dialog;
}
private void updateControls(MultiInputDialog dialog) {
- assignFromSource =
dialog.getCheckBox(FROM_SOURCE_CHECK_BOX).isSelected();
+ layer = dialog.getLayer(LAYER_COMBO_BOX);
+ FeatureSchema schema =
layer.getFeatureCollectionWrapper().getFeatureSchema();
+
+ targetAttribute = dialog.getText(TARGET_ATTRIBUTE_COMBO_BOX);
+ destinationAttributeType =
schema.getAttributeType(schema.getAttributeIndex(targetAttribute));
+
+ assignFromSource = dialog.getBoolean(FROM_SOURCE_CHECK_BOX);
autoIncrement = dialog.getBoolean(AUTOINC_CHECK_BOX);
assignValue = dialog.getBoolean(ASSIGN_VALUE_CHECK_BOX);
- layer = dialog.getLayer(LAYER_COMBO_BOX);
- FeatureSchema schema =
layer.getFeatureCollectionWrapper().getFeatureSchema();
+
boolean fromAttributeValid = schema.getAttributeCount() > 1;
- dialog.setFieldEnabled(AUTOINC_CHECK_BOX, !assignFromSource &&
!assignValue);
- dialog.setFieldEnabled(AUTOINC_PATTERN_BOX, autoIncrement &&
!assignFromSource && !assignValue);
- dialog.setFieldEnabled(INC_VALUE_EDIT_BOX, autoIncrement &&
!assignFromSource && !assignValue);
+ //dialog.setFieldEnabled(AUTOINC_CHECK_BOX, !assignFromSource &&
!assignValue);
+ dialog.setFieldEnabled(AUTOINC_PATTERN_BOX, autoIncrement);
+ dialog.setFieldEnabled(INC_VALUE_EDIT_BOX, autoIncrement);
- dialog.setFieldEnabled(FROM_SOURCE_CHECK_BOX, !autoIncrement &&
!assignValue && fromAttributeValid);
- dialog.setFieldEnabled(SOURCE_COMBO_BOX, assignFromSource &&
!autoIncrement && !assignValue && fromAttributeValid);
+ //dialog.setFieldEnabled(FROM_SOURCE_CHECK_BOX, !autoIncrement &&
!assignValue && fromAttributeValid);
+ dialog.setFieldEnabled(SOURCE_COMBO_BOX, assignFromSource);
- dialog.setFieldEnabled(ASSIGN_VALUE_CHECK_BOX, !assignFromSource &&
!autoIncrement);
- dialog.setFieldEnabled(ASSIGN_VALUE_TEXT_BOX, assignValue &&
!assignFromSource && !autoIncrement);
+ //dialog.setFieldEnabled(ASSIGN_VALUE_CHECK_BOX, !assignFromSource &&
!autoIncrement);
+ dialog.setFieldEnabled(ASSIGN_VALUE_TEXT_BOX, assignValue);
if (assignValue)
dialog.setSideBarDescription(ASSIGN_VALUE_DESCRIPTION);
else if (autoIncrement)
dialog.setSideBarDescription(AUTOINC_DESCRIPTION_1 + "\n\n" +
AUTOINC_DESCRIPTION_2);
@@ -317,7 +343,7 @@
});
put(AttributeType.BOOLEAN, new Converter() {
public Object convert(String d) {
- if (d==null) return null;
+ if (d==null || d.isEmpty()) return null;
try {
return Boolean.parseBoolean(d);
} catch(NumberFormatException nfe) {
@@ -389,7 +415,8 @@
else
s = pattern.replaceFirst(numeric, value);
} else if (assignFromSource) {
- s = feature.getAttribute(sourceAttribute).toString();
+ Object v = feature.getAttribute(sourceAttribute);
+ s = v == null ? null : v.toString();
} else {
s = textToAssign;
}
------------------------------------------------------------------------------
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