Revision 3140

View differences:

org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/vectorediting/app/mainplugin/ServiceExtension.java
58 58

  
59 59
    @Override
60 60
    public boolean isEnabled() {
61
        IView view = getActiveView();
62
        EditingSwingManager swingManager = EditingSwingLocator.getSwingManager();
63
        if (view != null) {
64
            EditingContext editingContext = swingManager.getEditingContext(view.getMapControl());
65
            return !editingContext.isProcessing();
66
        }
61 67
        return this.isVisible();
62 68
    }
63 69

  
......
72 78
                    EditingSwingLocator.getSwingManager();
73 79
                EditingContext editingContext =
74 80
                    swingManager.getEditingContext(view.getMapControl());
81
                if( editingContext.isProcessing() ) {
82
                    return false;
83
                }
75 84
                return editingContext.isServiceCompatible(action);
76 85
            }
77 86
        }
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/vectorediting/app/mainplugin/EditingExtension.java
325 325
        if (view == null) {
326 326
            return false;
327 327
        }
328
        EditingSwingManager swingManager = EditingSwingLocator.getSwingManager();
329
        EditingContext editingContext = swingManager.getEditingContext(view.getMapControl());
330
        if( editingContext.isProcessing() ) {
331
            return false;
332
        }
333
        
328 334
        if ("start-editing".equals(action)) {
329 335
            List<FLyrVect> activeLayers = getActiveLayers(view, (FLyrVect layer) -> canBeEdited(layer));
330 336
            return !activeLayers.isEmpty();
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.spi/src/main/java/org/gvsig/vectorediting/lib/spi/AbstractEditingProvider.java
173 173
            List<Feature> features = new ArrayList<>();
174 174
            DisposableIterator it = selection.fastIterator();
175 175
            while (it.hasNext()) {
176
                if( status.isCancellationRequested() ) {
177
                    status.cancel();
178
                    return features;
179
                }
176 180
                Feature feature = (Feature) it.next();
177 181
                if( feature.getDefaultGeometry()==null ) {
178 182
                    continue;
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/EditingCompoundBehavior.java
24 24

  
25 25
package org.gvsig.vectorediting.swing.impl;
26 26

  
27
import java.awt.Cursor;
27 28
import java.awt.Image;
28 29
import java.awt.event.MouseEvent;
29 30
import java.awt.event.MouseWheelEvent;
......
38 39
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseWheelBehavior;
39 40
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior;
40 41
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener;
42
import org.gvsig.vectorediting.swing.api.EditingContext;
43
import org.gvsig.vectorediting.swing.api.EditingSwingLocator;
44
import org.gvsig.vectorediting.swing.api.EditingSwingManager;
41 45

  
42 46
public class EditingCompoundBehavior extends CompoundBehavior {
43 47

  
......
130 134

  
131 135
    @Override
132 136
    public Image getImageCursor() {
137
//        if( getEditingContext().isProcessing() ) {
138
//            return null; //Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
139
//        }
133 140
        switch (mode) {
134 141
        default:
135 142
        case EDITING:
......
138 145
            return this.selection.getImageCursor();
139 146
        }
140 147
    }
148
    
149
    private EditingContext getEditingContext() {
150
        EditingSwingManager swingManager = EditingSwingLocator.getSwingManager();
151
        EditingContext editingContext = swingManager.getEditingContext(this.getMapControl());
152
        return editingContext;
153
    }
141 154

  
142 155
    @Override
143 156
    public void mouseClicked(MouseEvent e) throws BehaviorException {
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingContext.java
26 26

  
27 27
import java.awt.BorderLayout;
28 28
import java.awt.Component;
29
import java.awt.Cursor;
29 30
import java.lang.ref.WeakReference;
30 31
import java.lang.reflect.InvocationTargetException;
31 32
import java.util.ArrayList;
......
144 145
    private Behavior[] defaultBehaviors;
145 146
    
146 147
    private Set<FLyrVect> layersSpatialCacheEnabled = new HashSet<>();
148
    
149
    private boolean processing;
147 150

  
148 151
    private final LayerListener layerListener = new LayerListener() {
149 152

  
......
288 291
        };
289 292

  
290 293
    public DefaultEditingContext(MapControl mapControl) {
291

  
294
        this.processing = false;
292 295
        this.mapControlReference = new WeakReference<>(mapControl);
293 296
        this.mapContextReference =
294 297
            new WeakReference<>(mapControl.getMapContext());
......
721 724

  
722 725
    @Override
723 726
    public void endEdition(FLyrVect layer) {
727
        if( this.isProcessing() ) {
728
            return;
729
        }
724 730
        if (layer.isEditing()) {
725 731
            EditingNotificationManager editingNotificationManager =
726 732
                DALSwingLocator.getEditingNotificationManager();
......
770 776
    }
771 777

  
772 778
    protected void finishService() {
779
        if (this.isProcessing()) {
780
            return;
781
        }
773 782
        EditingService lastService = serviceStack.pop();
774
        try {
783
        Thread task = new Thread(() -> {
784
            try {
785
                this.setMouseBusy(true);
786
                this.processing = true;
787
                try {
775 788

  
776
            if (!serviceStack.isEmpty()
777
                && getActiveService().next().getTypes().contains(TYPE.GEOMETRY)) {
778
                Geometry geometry = lastService.finish();
779
                lastService.setShowPreviewSymbol(true);
780
                if (geometry != null) {
781
                    getActiveService().setValue(geometry);
782
                }
783
            } else {
784
                lastService.finishAndStore();
785
                getMapControl().rePaintDirtyLayers();
786
                refreshMenusAndToolBars();
789
                    if (!serviceStack.isEmpty()
790
                            && getActiveService().next().getTypes().contains(TYPE.GEOMETRY)) {
791
                        Geometry geometry = lastService.finish();
792
                        lastService.setShowPreviewSymbol(true);
793
                        if (geometry != null) {
794
                            getActiveService().setValue(geometry);
795
                        }
796
                    } else {
797
                        lastService.finishAndStore();
798
                        getMapControl().rePaintDirtyLayers();
799
                        refreshMenusAndToolBars();
787 800

  
788
                I18nManager i18nManager = ToolsLocator.getI18nManager();
789
                showConsoleMessage("\n"
790
                    + i18nManager.getTranslation(lastService.getName()) + "# "
791
                    + i18nManager.getTranslation("finished") + "\n");
801
                        I18nManager i18nManager = ToolsLocator.getI18nManager();
802
                        showConsoleMessage("\n"
803
                                + i18nManager.getTranslation(lastService.getName()) + "# "
804
                                + i18nManager.getTranslation("finished") + "\n");
792 805
//                lastService.stop();
793
                setActiveService(lastService);
806
                        setActiveService(lastService);
794 807
//                lastService.start();
795
                lastService.restart();
796
                changeSelectedTool(getActiveService().getName());
797
            }
808
                        lastService.restart();
809
                        changeSelectedTool(getActiveService().getName());
810
                    }
798 811

  
799
        } catch (InvalidEntryException ex) {
800
            I18nManager i18nManager = ToolsLocator.getI18nManager();
801
            showConsoleMessage("\n"
802
                + i18nManager.getTranslation("invalid_option"));
803
            changeSelectedTool(getActiveService().getName());
804
        } catch (VectorEditingException ex) {
805
            LOGGER.info("Can't finish " + lastService.getName(), ex);
806
            cleanEditingContext();
807
            return;
808
        }
812
                } catch (InvalidEntryException ex) {
813
                    I18nManager i18nManager = ToolsLocator.getI18nManager();
814
                    showConsoleMessage("\n"
815
                            + i18nManager.getTranslation("invalid_option"));
816
                    changeSelectedTool(getActiveService().getName());
817
                } catch (VectorEditingException ex) {
818
                    LOGGER.info("Can't finish " + lastService.getName(), ex);
819
                    cleanEditingContext();
820
                    return;
821
                }
809 822

  
810
        nextParameter();
823
                doNextParameter();
824
            } finally {
825
                this.processing = false;
826
                this.setMouseBusy(false);
827
                refreshMenusAndToolBars();
828
            }
829
        }, "EditingContextFinishService");
830
        this.processing = true;
831
        this.setMouseBusy(true);
832
        task.start();
833
        refreshMenusAndToolBars();
811 834
    }
812 835

  
813 836
    public EditingService getActiveService() {
......
882 905

  
883 906
    
884 907
    public void nextParameter() {
908
        if( this.isProcessing() ) {
909
            return;
910
        }
911
        doNextParameter();
912
    }
913
    
914
    private void doNextParameter() {
885 915
        if ((getMapControl().getCurrentTool() != null)
886 916
            && !getMapControl().getCurrentTool().equals("VectorEditing")) {
887 917
            getMapControl().setTool("VectorEditing");
......
1071 1101

  
1072 1102
    protected void refreshMenusAndToolBars() {
1073 1103
        if (!SwingUtilities.isEventDispatchThread()) {
1074
            SwingUtilities.invokeLater(new Runnable() {
1075

  
1076
                @Override
1077
                public void run() {
1078
                    refreshMenusAndToolBars();
1079
                }
1080
            });
1104
            SwingUtilities.invokeLater(() -> { refreshMenusAndToolBars(); });
1081 1105
            return;
1082 1106
        }
1083 1107
        Notification notification = new BaseNotification(
......
1097 1121
    }
1098 1122

  
1099 1123
    private void setActiveService(EditingService service) {
1124
        if( this.isProcessing() ) {
1125
            return;
1126
        }
1100 1127
        serviceStack.add(service);
1101 1128
        notifyChangeSelectedTool();
1102 1129
    }
1103 1130

  
1104 1131
    private void setCompoundBehavior(EditingCompoundBehavior compoundBehavior) {
1132
        if( this.isProcessing() ) {
1133
            return;
1134
        }
1105 1135
        this.editingCompoundBehavior = compoundBehavior;
1106 1136
    }
1107 1137

  
1108 1138
    private void setCurrentLayer(FLyrVect layer) {
1109

  
1139
        if( this.isProcessing() ) {
1140
            return;
1141
        }
1110 1142
        if (this.currentLayer != layer) {
1111 1143
            this.currentLayer = layer;
1112 1144
            cleanEditingContext();
......
1116 1148

  
1117 1149
    @Override
1118 1150
    public void setMapControl(MapControl mapControl) {
1151
        if( this.isProcessing() ) {
1152
            return;
1153
        }
1119 1154

  
1120 1155
        this.mapControlReference = new WeakReference<>(mapControl);
1121 1156
        this.mapContextReference =
......
1178 1213
        this.textEntered(null);
1179 1214
    }
1180 1215
    
1181
    protected void selectedValue(Object value) {
1182
        EditingService activeService = getActiveService();
1183
        I18nManager i18nManager = ToolsLocator.getI18nManager();
1184
        
1185
        try {
1186
            activeService.setValue(value);
1187
        } catch (InvalidEntryException ex) {
1188
            showConsoleMessage("\n"
1189
                    + i18nManager.getTranslation("invalid_option"));
1190
        }
1191

  
1192
        activeService = getActiveService();
1193
        if (activeService != null) {
1194
            nextParameter();
1195
        } else {
1196
            cleanEditingContext();
1197
        }
1198

  
1199
    }
1216
//    protected void selectedValue(Object value) {
1217
//        EditingService activeService = getActiveService();
1218
//        I18nManager i18nManager = ToolsLocator.getI18nManager();
1219
//        
1220
//        try {
1221
//            activeService.setValue(value);
1222
//        } catch (InvalidEntryException ex) {
1223
//            showConsoleMessage("\n"
1224
//                    + i18nManager.getTranslation("invalid_option"));
1225
//        }
1226
//
1227
//        activeService = getActiveService();
1228
//        if (activeService != null) {
1229
//            nextParameter();
1230
//        } else {
1231
//            cleanEditingContext();
1232
//        }
1233
//
1234
//    }
1200 1235
    
1201 1236
    protected void textEntered(String response) {
1202
        FeatureStore featureStore = getCurrentLayer().getFeatureStore();
1203
        EditingService activeService = getActiveService();
1237
        if( this.isProcessing() ) {
1238
            return;
1239
        }
1240
        FeatureStore featureStore = getCurrentLayer().getFeatureStore();        
1204 1241
        if (response == null) {
1242
            EditingService activeService = getActiveService();
1205 1243
            if (activeService != null) {
1206 1244
                try {
1207 1245
                    activeService.stop();
......
1231 1269
                }
1232 1270
            }
1233 1271
        } else {
1272
            Thread task = new Thread(() -> {
1273
                try {
1274
                    this.setMouseBusy(true);
1275
                    this.processing = true;
1276
                    I18nManager i18nManager = ToolsLocator.getI18nManager();
1277
                    EditingService activeService = getActiveService();
1278
                    if (getCurrentParam() != null) {
1279
                        try {
1280
                            Object coercedValue = coerceInputParameter(getCurrentParam(), response);
1281
                            activeService.setValue(coercedValue);
1282
                        } catch (InvalidEntryException ex) {
1283
                            showConsoleMessage("\n"
1284
                                    + i18nManager.getTranslation("invalid_option"));
1285
                        }
1286
                    }
1234 1287

  
1235
            I18nManager i18nManager = ToolsLocator.getI18nManager();
1236
            if (getCurrentParam() != null) {
1237
                try {
1238
                    Object coercedValue = coerceInputParameter(getCurrentParam(), response);
1239
                    activeService.setValue(coercedValue);
1240
                } catch (InvalidEntryException ex) {
1241
                    showConsoleMessage("\n"
1242
                            + i18nManager.getTranslation("invalid_option"));
1288
                    activeService = getActiveService();
1289
                    if (activeService != null) {
1290
                        doNextParameter();
1291
                    } else {
1292
                        cleanEditingContext();
1293
                    }
1294
                } finally {
1295
                    this.processing = false;
1296
                    this.setMouseBusy(false);
1297
                    refreshMenusAndToolBars();
1243 1298
                }
1244
            }
1245

  
1246
            activeService = getActiveService();
1247
            if (activeService != null) {
1248
                nextParameter();
1249
            } else {
1250
                cleanEditingContext();
1251
            }
1299
            }, "EditingContextTextEntered");
1300
            this.processing = true;
1301
            this.setMouseBusy(true);
1302
            task.start();
1303
            refreshMenusAndToolBars();
1252 1304
        }
1253 1305
    }
1254 1306
    
......
1329 1381

  
1330 1382
    @Override
1331 1383
    public void setDefaultBehaviors(Behavior[] defaultBehaviors) {
1384
        if( this.isProcessing() ) {
1385
            return;
1386
        }
1332 1387
        this.defaultBehaviors = defaultBehaviors;
1333 1388
        try {
1334 1389
            addBehaviors(defaultBehaviors);
......
1345 1400

  
1346 1401
    @Override
1347 1402
    public void setValue(EditingServiceParameter parameter, Object value) throws InvalidEntryException {
1403
        if( this.isProcessing() ) {
1404
            return;
1405
        }
1348 1406
        if( value instanceof CharSequence){
1349 1407
            value = coerceInputParameter(parameter, value.toString());
1350 1408
        } else if( value instanceof Point) {
1351 1409
            contextSymbolTable.addPoint((Point) value);
1352 1410
        }
1353
        getActiveService().setValue(parameter, value);
1354
//        nextParameter();
1411
        Object v = value;
1412
        Thread task = new Thread(() -> {
1413
            try {
1414
                this.setMouseBusy(true);
1415
                this.processing = true;
1416
                getActiveService().setValue(parameter, v);
1417
//        doNextParameter();
1418
            } catch (InvalidEntryException ex) {
1419
                I18nManager i18nManager = ToolsLocator.getI18nManager();
1420
                showConsoleMessage("\n"+ i18nManager.getTranslation("invalid_option"));
1421
            } finally {
1422
                this.processing = false;
1423
                this.setMouseBusy(false);
1424
                refreshMenusAndToolBars();
1425
            }
1426
        }, "EditingContextSetValue");
1427
        this.processing = true;
1428
        this.setMouseBusy(true);
1429
        task.start();
1430
        refreshMenusAndToolBars();
1431
        
1432
        
1355 1433
    }
1356 1434

  
1357 1435
    public GeometryType getGeometryType() {
......
1373 1451
        return geomattr.getGeomType();
1374 1452
    }    
1375 1453
    
1454
    public boolean isProcessing() {
1455
        return this.processing;
1456
    }
1457
    
1458
    private Cursor lastNoBusyCursor = null;
1459
    
1460
    public void setMouseBusy(boolean busy) {
1461
        JComponent component = this.getMapControl();
1462
        if( busy ) {
1463
            if( lastNoBusyCursor==null ) {
1464
                this.lastNoBusyCursor = component.getCursor();
1465
            }
1466
            component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1467
        } else {
1468
            component.setCursor(lastNoBusyCursor);
1469
            lastNoBusyCursor = null;
1470
        }
1471
    }
1376 1472
}
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.api/src/main/java/org/gvsig/vectorediting/swing/api/EditingContext.java
128 128
    public void nextParameter();
129 129
    
130 130
    public void cancelActiveService();
131
    
132
    public boolean isProcessing();
131 133
}

Also available in: Unified diff