Merge "Issue #1464 fix spatial subset tab and modify area comp so it attempts to initialize to a valid state." into development

Former-commit-id: 888b839152d86c536b249e795666c596a213da86
This commit is contained in:
Richard Peter 2013-01-11 16:32:03 -06:00 committed by Gerrit Code Review
commit d2a1388b0e
2 changed files with 53 additions and 25 deletions

View file

@ -237,8 +237,21 @@ public class AreaComp extends Composite implements ISubset {
createControls();
if (regionRdo.getSelection()) {
regionCombo.select(regionCombo.getItemCount() - 1);
handleRegionSelection();
// Try to find the smallest region that intersects, assum regions
// are listed largest to smallest.
for (int i = regionCombo.getItemCount() - 1; i >= 0; i -= 1) {
regionCombo.select(i);
handleRegionSelection(false);
if (envelopeValid) {
break;
}
}
// if non of the predefined regions are valid default to the full
// envelope.
if (!envelopeValid) {
updateBounds(fullEnvelope);
setCustom();
}
} else if (manualRdo.getSelection()) {
updateBounds(subEnvelope);
}
@ -433,7 +446,7 @@ public class AreaComp extends Composite implements ISubset {
regionCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handleRegionSelection();
handleRegionSelection(true);
}
});
@ -555,7 +568,7 @@ public class AreaComp extends Composite implements ISubset {
regionCombo.setEnabled(flag);
selectCombo.setEnabled(flag);
if (flag) {
handleRegionSelection();
handleRegionSelection(true);
}
}
@ -602,12 +615,12 @@ public class AreaComp extends Composite implements ISubset {
REGION_GROUPS.PRE_DEFINED.getRegionGroup())) {
regionCombo.setItems(predefinedRegions);
regionCombo.select(0);
handleRegionSelection();
handleRegionSelection(true);
} else {
regionCombo.setItems(getUserRegions());
if (regionCombo.getItemCount() > 0) {
regionCombo.select(0);
handleRegionSelection();
handleRegionSelection(true);
}
}
}
@ -631,8 +644,11 @@ public class AreaComp extends Composite implements ISubset {
/**
* Region selection action handler
*
* @param verbose
* when true user is alerted to validation errors.
*/
private void handleRegionSelection() {
private void handleRegionSelection(boolean verbose) {
if (!regionRdo.getSelection()) {
return;
}
@ -676,11 +692,14 @@ public class AreaComp extends Composite implements ISubset {
ReferencedEnvelope intersection = MapUtil
.reprojectAndIntersect(regionEnvelope, fullEnvelope);
if (intersection == null || intersection.isEmpty()) {
StringBuilder errorText = new StringBuilder();
errorText.append(name);
errorText.append(" does not intersect the dataset area.");
DataDeliveryUtils.showMessage(getShell(), SWT.OK,
"Validation Error", errorText.toString());
if (verbose) {
StringBuilder errorText = new StringBuilder();
errorText.append(name);
errorText
.append(" does not intersect the dataset area.");
DataDeliveryUtils.showMessage(getShell(), SWT.OK,
"Validation Error", errorText.toString());
}
envelopeValid = false;
return;
}
@ -963,7 +982,7 @@ public class AreaComp extends Composite implements ISubset {
}
}
regionCombo.select(0);
handleRegionSelection();
handleRegionSelection(true);
}
}

View file

@ -251,20 +251,15 @@ public class SpatialSubsetTab extends SubsetTab implements IDataSize {
return;
}
if (this.areaComp.isEnvelopeValid()) {
ReferencedEnvelope envelope = this.areaComp.getEnvelope();
AreaXML area = new AreaXML();
area.setRegionName(saveName);
AreaXML area = getSaveInfo();
area.setEnvelope(envelope);
SubsetFileManager.getInstance()
.saveArea(area, this.areaComp.getShell());
SubsetFileManager.getInstance().saveArea(area,
this.areaComp.getShell());
// update the regionCombo
areaComp.showMyRegions(saveName);
// update the regionCombo
areaComp.showMyRegions(saveName);
}
}
/**
@ -305,7 +300,11 @@ public class SpatialSubsetTab extends SubsetTab implements IDataSize {
* @return The selected envelope
*/
public ReferencedEnvelope getEnvelope() {
return areaComp.getEnvelope();
if (useDataSetSize) {
return fullEnvelope;
} else {
return areaComp.getEnvelope();
}
}
/**
@ -346,8 +345,15 @@ public class SpatialSubsetTab extends SubsetTab implements IDataSize {
* @return AreaXML object populated with the save details
*/
public AreaXML getSaveInfo() {
ReferencedEnvelope envelope = null;
if(useDataSetSize){
envelope = fullEnvelope;
}else if(areaComp.isEnvelopeValid()){
areaComp.getEnvelope();
}
AreaXML area = new AreaXML();
ReferencedEnvelope envelope = areaComp.getEnvelope();
if (envelope != null) {
area.setEnvelope(envelope);
}
@ -366,6 +372,9 @@ public class SpatialSubsetTab extends SubsetTab implements IDataSize {
* @return true if tab is valid
*/
public boolean isValid() {
if (useDataSetSize) {
return true;
}
ReferencedEnvelope envelope = areaComp.getEnvelope();
if (envelope == null) {
return false;