Revision 38705 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/StartEditing.java

View differences:

StartEditing.java
56 56
	/**
57 57
	 * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
58 58
	 */
59
	public void execute(String actionCommand) {
60
	    
61
		org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
62
		.getActiveWindow();
59
    public void execute(String actionCommand) {
63 60

  
64
		if (f instanceof DefaultViewPanel) {
65
			DefaultViewPanel vista = (DefaultViewPanel) f;
61
        if (actionCommand.compareTo("layer-start-editing") == 0) {
66 62

  
67
			MapControl mapControl = vista.getMapControl();
68
			ViewDocument model = vista.getModel();
69
			FLayer[] actives = model.getMapContext().getLayers().getActives();
63
            org.gvsig.andami.ui.mdiManager.IWindow f =
64
                PluginServices.getMDIManager().getActiveWindow();
70 65

  
71
			// boolean bEditingStarted = false;
72
			if (actives.length == 1 &&	actives[0] instanceof FLyrVect) {
66
            if (f instanceof DefaultViewPanel) {
67
                DefaultViewPanel vista = (DefaultViewPanel) f;
73 68

  
74
			    FLyrVect lv = (FLyrVect) actives[0];
75
			    
76
			    if (!lv.getFeatureStore().getTransforms().isEmpty()) {
77
			        
78
			        // cannot edit transformed
79
                    JOptionPane.showMessageDialog(
80
                        (Component) f,
81
                        Messages.get("_Cannot_start_edition_in_transformed_layer")
82
                        + ": '" + lv.getName() + "'",
83
                        PluginServices.getText(this, "warning_title"),
84
                        JOptionPane.INFORMATION_MESSAGE);
85
	                 return;
86
			    }
69
                MapControl mapControl = vista.getMapControl();
70
                ViewDocument model = vista.getModel();
71
                FLayer[] actives =
72
                    model.getMapContext().getLayers().getActives();
87 73

  
88
			    CADExtension.initFocus();
89
				vista.showConsole();
90
				EditionManager editionManager=CADExtension.getEditionManager();
91
				editionManager.setMapControl(mapControl);
92
				/*
93
				 * for (int j = 0; j < i; j++) {
94
				 * layers.getLayer(j).setVisible(false); }
95
				 */
74
                if (actives.length == 1 && actives[0] instanceof FLyrVect) {
96 75

  
97
				// lv.setVisible(true);
98
				lv.addLayerListener(editionManager);
99
				try {
100
					// ILegend legendOriginal=lv.getLegend().cloneLegend();
76
                    FLyrVect lv = (FLyrVect) actives[0];
101 77

  
102
					if (!lv.isWritable())
103
					{
104
						JOptionPane.showMessageDialog(
105
								(Component) f,
106
								PluginServices.getText(this, "this_layer_is_not_self_editable"),
107
								PluginServices.getText(this, "warning_title"),
108
								JOptionPane.WARNING_MESSAGE);
109
					}
78
                    if (!lv.getFeatureStore().getTransforms().isEmpty()) {
110 79

  
111
					lv.setEditing(true);
112
//					FeatureType featureType=lv.getFeatureStore().getDefaultFeatureType();
113
//					featureType.getRules().clear();
114
//					if (lv.getShapeType()==Geometry.TYPES.SURFACE){
115
//						FeatureRule rulePol = new FeatureRulePolygon("PolygonRule", "Sentido correcto de un pol?gono");
116
//						featureType.addRule(rulePol);
117
//					}
80
                        // cannot edit transformed
81
                        JOptionPane
82
                            .showMessageDialog(
83
                                (Component) f,
84
                                Messages
85
                                    .get("_Cannot_start_edition_in_transformed_layer")
86
                                    + ": '" + lv.getName() + "'",
87
                                PluginServices.getText(this, "warning_title"),
88
                                JOptionPane.INFORMATION_MESSAGE);
89
                        return;
90
                    }
118 91

  
119
//					if (!(lv.getSource().getDriver() instanceof IndexedShpDriver)){
120
//						VectorialLayerEdited vle=(VectorialLayerEdited)editionManager.getLayerEdited(lv);
121
//						vle.setLegend(legendOriginal);
122
//					}
123
					lv.getFeatureStore().addObserver(mapControl);
124
//					vea.getCommandRecord().addCommandListener(mapControl);
125
					// Si existe una tabla asociada a esta capa se cambia su
126
					// modelo por el VectorialEditableAdapter.
127
					ProjectExtension pe = (ProjectExtension) PluginServices
128
					.getExtension(ProjectExtension.class);
92
                    CADExtension.initFocus();
93
                    vista.showConsole();
94
                    EditionManager editionManager =
95
                        CADExtension.getEditionManager();
96
                    editionManager.setMapControl(mapControl);
129 97

  
130
					startCommandsApplicable(vista,lv);
131
					vista.repaintMap();
98
                    lv.addLayerListener(editionManager);
99
                    try {
100
                        if (!lv.isWritable()) {
101
                            JOptionPane.showMessageDialog((Component) f,
102
                                PluginServices.getText(this,
103
                                    "this_layer_is_not_self_editable"),
104
                                PluginServices.getText(this, "warning_title"),
105
                                JOptionPane.WARNING_MESSAGE);
106
                        }
107
                        lv.setEditing(true);
108
                        lv.getFeatureStore().addObserver(mapControl);
109
                        startCommandsApplicable(vista, lv);
110
                        vista.repaintMap();
132 111

  
133
				} catch (StartEditionLayerException e) {
134
				    
135
				    logger.info("Error while starting edition: " + e.getMessage(), e);
112
                    } catch (StartEditionLayerException e) {
136 113

  
137
				    ApplicationLocator.getManager().message(
138
				        Messages.get("_Unable_to_start_edition_in_layer") + ": " + lv.getName(),
139
				        JOptionPane.ERROR_MESSAGE);
140
				    
141
					// NotificationManager.addError(e.getMessage(),e);
142
//				} catch (ReadException e) {
143
//					NotificationManager.addError(e.getMessage(),e);
144
//				} catch (DataException e) {
145
//					NotificationManager.addError(e.getMessage(),e);
146
				}
114
                        logger.info(
115
                            "Error while starting edition: " + e.getMessage(),
116
                            e);
147 117

  
148
//				return;
149
			}
150
		}
118
                        ApplicationLocator.getManager().message(
119
                            Messages.get("_Unable_to_start_edition_in_layer")
120
                                + ": " + lv.getName(),
121
                            JOptionPane.ERROR_MESSAGE);
122
                    }
123
                }
124
            }
125
        }
126
    }
151 127

  
152
		/*
153
		 * PluginServices.getMDIManager().setWaitCursor(); try { if
154
		 * (((FLyrVect) capa).getSource().getDriver().getClass() ==
155
		 * DXFCadDriver.class) { if (JOptionPane.showConfirmDialog(
156
		 * (Component) PluginServices.getMainFrame(), "Todas las geometr?as
157
		 * del formato DXF no se pueden editar, de momento podemos editar:
158
		 * Line, Point, Polyline, Arc, Circle y Ellipse. \n El resto de
159
		 * geometr?as se perder?n con la edici?n. \n ?Desea continuar?") ==
160
		 * JOptionPane.YES_OPTION) { capa.startEdition();
161
		 * vista.getMapControl().setCadTool("selection"); } else { } } else {
162
		 * capa.startEdition();
163
		 * vista.getMapControl().setCadTool("selection"); } } catch
164
		 * (EditionException e) { // TODO Auto-generated catch block
165
		 * e.printStackTrace(); }
166
		 * PluginServices.getMDIManager().restoreCursor();
167
		 */
168
		// vista.getMapControl().drawMap(false);
169
	}
170

  
171 128
//	 private void registerKeyStrokes() {
172 129
//		 JComponent theComponent = vista.getConsolePanel().getTxt();
173 130
//

Also available in: Unified diff