001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.validation;
016:
017: import java.net.URI;
018: import java.util.HashMap;
019: import java.util.Map;
020:
021: import net.refractions.udig.project.ILayer;
022: import net.refractions.udig.ui.PlatformGIS;
023: import net.refractions.udig.ui.operations.IOp;
024:
025: import org.eclipse.core.runtime.IProgressMonitor;
026: import org.eclipse.jface.dialogs.Dialog;
027: import org.eclipse.swt.widgets.Display;
028: import org.eclipse.swt.widgets.Shell;
029: import org.geotools.data.FeatureSource;
030: import org.geotools.feature.FeatureType;
031: import org.geotools.validation.IntegrityValidation;
032:
033: import com.vividsolutions.jts.geom.Envelope;
034:
035: /**
036: * An abstract class for integrity validation which uses org.geotools.validation
037: * <p>
038: *
039: * </p>
040: * @author chorner
041: * @since 1.0.1
042: */
043: public abstract class IntegrityValidationOp implements IOp {
044: public GenericValidationResults genericResults; //for testing
045:
046: /**
047: *
048: *
049: * @param layer
050: * @return the appropriate integrity validator
051: */
052: abstract IntegrityValidation getValidator(ILayer[] layer);
053:
054: /**
055: *
056: * @see net.refractions.udig.ui.operations.IOp#op(org.eclipse.swt.widgets.Display, java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
057: */
058: public void op(final Display display, Object target,
059: IProgressMonitor monitor) throws Exception {
060: // define the ILayer array
061: final ILayer[] layer;
062: if (target.getClass().isArray()) {
063: layer = (ILayer[]) target;
064: } else {
065: layer = new ILayer[1];
066: layer[0] = (ILayer) target;
067: }
068: //construct the hashmap and run the validation
069: Envelope envelope = layer[0].getMap().getViewportModel()
070: .getBounds();
071: FeatureSource source;
072: URI nameSpace;
073: String typeName;
074: Map<String, FeatureSource> map = new HashMap<String, FeatureSource>();
075: for (int i = 0; i < layer.length; i++) {
076: nameSpace = layer[i].getSchema().getNamespace();
077: typeName = layer[i].getSchema().getTypeName();
078: source = layer[i].getResource(FeatureSource.class, monitor);
079: //map = dataStoreID:typeName
080: map.put(nameSpace.toString() + ":" + typeName, source); //$NON-NLS-1$
081: }
082:
083: GenericValidationResults results = new GenericValidationResults();
084: genericResults = results;
085:
086: PlatformGIS.syncInDisplayThread(new Runnable() {
087:
088: public void run() {
089: Dialog dialog = getDialog(display.getActiveShell(),
090: layer[0].getSchema());
091: if (dialog != null) {
092: dialog.open();
093: }
094: }
095:
096: });
097:
098: final IntegrityValidation integrityValidation = getValidator(layer);
099: if (integrityValidation == null)
100: return;
101:
102: integrityValidation.validate(map, envelope, results);
103:
104: OpUtils.setSelection(layer[0], results);
105: OpUtils.notifyUser(display, results);
106:
107: monitor.internalWorked(1);
108: monitor.done();
109: }
110:
111: protected Dialog getDialog(Shell shell, FeatureType featureType) {
112: return null;
113: }
114:
115: }
|