01: package net.refractions.udig.validation;
02:
03: import java.text.MessageFormat;
04:
05: import net.refractions.udig.project.ILayer;
06: import net.refractions.udig.project.command.MapCommand;
07: import net.refractions.udig.project.command.SelectionCommandFactory;
08: import net.refractions.udig.validation.internal.Messages;
09:
10: import org.eclipse.jface.dialogs.MessageDialog;
11: import org.eclipse.swt.widgets.Display;
12: import org.geotools.factory.FactoryConfigurationError;
13: import org.geotools.feature.Feature;
14: import org.geotools.filter.FidFilter;
15: import org.geotools.filter.FilterFactoryFinder;
16:
17: /**
18: * A utility class which provides a method to notify the user of the validation results, and a
19: * method selection features which failed the validation on the current layer.
20: * <p>
21: * </p>
22: *
23: * @author chorner
24: * @since 1.0.1
25: */
26: public class OpUtils {
27:
28: /**
29: * Notifies the user of the result of the validation. Currently, this method displays a crude
30: * pop-up window, but one day... it will populate the analysis window
31: *
32: * @param display
33: * @param evaluationObject
34: * @param results
35: */
36: public static void notifyUser(final Display display,
37: GenericValidationResults results) {
38: // display the results -- to be deleted soon
39: final StringBuffer buffer = new StringBuffer();
40: buffer
41: .append("Failures: " + results.failedFeatures.size() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
42: buffer
43: .append("Warnings: " + results.warningFeatures.size() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
44: for (int i = 0; (i < results.failedFeatures.size()) && (i < 8); i++) {
45: buffer
46: .append("error " + i + ": " + results.failureMessages.get(i) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
47: }
48: buffer.append("\n"); //$NON-NLS-1$
49: for (int i = 0; (i < results.validationList.size()) && (i < 10); i++) {
50: buffer.append(MessageFormat.format(
51: Messages.OpUtils_notifyResult, i,
52: results.validationList.get(i)));
53: }
54: display.asyncExec(new Runnable() {
55: public void run() {
56: MessageDialog.openInformation(display.getActiveShell(),
57: Messages.OpUtils_results, buffer.toString());
58: }
59: });
60: }
61:
62: /**
63: * Given a layer and validation result, this method creates a fid filter and selects the
64: * features in the current layer which failed the validation.
65: *
66: * @param layer
67: * @param results
68: * @throws FactoryConfigurationError
69: */
70: public static void setSelection(final ILayer layer,
71: GenericValidationResults results)
72: throws FactoryConfigurationError {
73: // generate a fid filter out of the invalid features
74: FidFilter fid = FilterFactoryFinder.createFilterFactory()
75: .createFidFilter();
76: for (Feature feature : results) {
77: fid.addFid(feature.getID());
78: }
79: // select the invalid features on the current layer
80: MapCommand selectionCommand = SelectionCommandFactory
81: .getInstance().createSelectCommand(layer, fid);
82: layer.getMap().sendCommandASync(selectionCommand);
83: }
84:
85: }
|