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 org.eclipse.jface.dialogs.Dialog;
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.events.ModifyEvent;
020: import org.eclipse.swt.events.ModifyListener;
021: import org.eclipse.swt.events.SelectionEvent;
022: import org.eclipse.swt.events.SelectionListener;
023: import org.eclipse.swt.widgets.Combo;
024: import org.eclipse.swt.widgets.Composite;
025: import org.eclipse.swt.widgets.Control;
026: import org.eclipse.swt.widgets.Shell;
027: import org.geotools.feature.FeatureType;
028: import org.geotools.validation.FeatureValidation;
029: import org.geotools.validation.attributes.NullZeroValidation;
030:
031: /**
032: * Overrides the FeatureValidationOp abstract class to return NullZeroValidation()
033: * <p>
034: * </p>
035: *
036: * @author chorner
037: * @since 1.0.1
038: */
039: public class ValidateNullZero extends FeatureValidationOp {
040: /**public for testing purposes only*/
041: public String xPath;
042: public Combo combo;
043:
044: public FeatureValidation getValidator() {
045: if (xPath == null)
046: return null;
047: NullZeroValidation nullZero = new NullZeroValidation();
048: nullZero.setAttribute(xPath);
049: return nullZero;
050: }
051:
052: /**public for testing purposes only*/
053: public @Override
054: Dialog getDialog(Shell shell, final FeatureType featureType) {
055: if (featureType.getAttributeCount() == 0)
056: return null;
057: final Dialog dialog = new Dialog(shell) {
058:
059: @Override
060: protected Control createDialogArea(Composite parent) {
061: Composite composite = (Composite) super
062: .createDialogArea(parent);
063: combo = new Combo(composite, SWT.DEFAULT);
064: for (int i = 0; i < featureType.getAttributeCount(); i++) {
065: combo
066: .add(featureType.getAttributeType(i)
067: .getName());
068: }
069: combo.addModifyListener(new ModifyListener() {
070:
071: public void modifyText(ModifyEvent e) {
072: setXpath(combo);
073: }
074:
075: });
076: combo.addSelectionListener(new SelectionListener() {
077:
078: public void widgetSelected(SelectionEvent e) {
079: setXpath(combo);
080: }
081:
082: public void widgetDefaultSelected(SelectionEvent e) {
083: widgetSelected(e);
084: okPressed();
085: }
086:
087: });
088: combo.select(0);
089: xPath = featureType.getAttributeType(0).getName();
090: return composite;
091: }
092:
093: @Override
094: protected void okPressed() {
095: super .okPressed();
096: }
097: };
098: return dialog;
099: }
100:
101: /**public for testing purposes only*/
102: public void setXpath(final Combo combo) {
103: xPath = combo.getItem(combo.getSelectionIndex());
104: }
105: }
|