Revision 31277 branches/v2_0_0_prep/extensions/org.gvsig.annotation/src/main/java/org/gvsig/annotation/create/AnnotationCreateAction.java

View differences:

AnnotationCreateAction.java
44 44

  
45 45
import java.awt.Component;
46 46
import java.io.File;
47
import java.io.IOException;
47 48

  
48 49
import javax.swing.JFileChooser;
49 50
import javax.swing.JOptionPane;
......
57 58
import org.gvsig.annotation.AnnotationManager;
58 59
import org.gvsig.annotation.AnnotationPreferences;
59 60
import org.gvsig.app.gui.panels.annotation.ConfigureLabel;
61
import org.gvsig.fmap.dal.DALLocator;
62
import org.gvsig.fmap.dal.DataManager;
60 63
import org.gvsig.fmap.dal.exception.DataException;
61 64
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
65
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
66
import org.gvsig.fmap.dal.feature.FeatureSet;
62 67
import org.gvsig.fmap.dal.feature.FeatureStore;
68
import org.gvsig.fmap.dal.feature.FeatureType;
69
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
70
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
71
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters;
63 72
import org.gvsig.fmap.geom.exception.CreateGeometryException;
64 73
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
65 74
import org.gvsig.utils.SimpleFileFilter;
......
75 84
	private AnnotationPreferences preferences;
76 85
	private AnnotationManager annotationManager;
77 86
	private FLyrVect origLayer;
87
	private DataManager dataManager;
78 88

  
79 89
	/**
80 90
	 * 
......
87 97
        myWizardComponents = wizardComponents;
88 98
        preferences=AnnotationLocator.getAnnotationPreferences();
89 99
        annotationManager=AnnotationLocator.getAnnotationManager();
100
        if (dataManager==null)
101
			dataManager=DALLocator.getDataManager();
90 102
        origLayer = lyr;
103
        FeatureSet origFeatures;
104
		try {
105
			origFeatures = ((FeatureStore)lyr.getDataStore()).getFeatureSet();
106
			FeatureType type = origFeatures.getDefaultFeatureType();
107
			FeatureAttributeDescriptor[] fieldsNames = type.getAttributeDescriptors();
108
			allNames=new String[fieldsNames.length];
109
			for(int i=0;i<fieldsNames.length;i++){
110
				allNames[i]=fieldsNames[i].getName();
111
			}
112
		} catch (DataException e) {
113
			NotificationManager.addError(e);
114
		}		
91 115
    }
92 116

  
93 117
    /**
......
102 126
        AnnotationFieldSelectPanel panel1 = (AnnotationFieldSelectPanel) myWizardComponents.getWizardPanel(0);
103 127
        AnnotationConfigureLabelsPanel panel2 = (AnnotationConfigureLabelsPanel) myWizardComponents.getWizardPanel(1);
104 128

  
105
        if (!panel1.getField().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
129
        if (!panel1.getField().equals(AnnotationConfigureLabelsPanel.TEXT_FOR_NO_SELECTED_VALUE)) {
106 130
        	preferences.setMappedNumColumnText(getIndex(panel1.getField()));
107 131
        }
108
       
109 132
        
110 133
        if (!panel2.getAngleFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
111 134
         	preferences.setMappedColumnNumRotate(getIndex(panel2.getAngleFieldName()));
......
152 175
        }
153 176
        
154 177
        try {
155
        	//TODO We need pass the String path to the original file.
156
        	FeatureStore annotationStore = annotationManager.InitializeAnnotationStore(newFile, origLayer.getProjection());
157
        	annotationManager.create(origLayer.getFeatureStore(),annotationStore,panel1.getDuplicate());
178
        	//CRATE SHAPE NEW PARAMETERS AND DATA SERVER EXPLORER
179
			
180
			//Setting the New File Path.
181
            FilesystemServerExplorerParameters explorerParams=(FilesystemServerExplorerParameters) dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
182
     	    explorerParams.setRoot(newFile.getParent());
183
     	  
184
     		//Create new Shape file with the right fields
185
     	    FilesystemServerExplorer explorer = (FilesystemServerExplorer) dataManager.createServerExplorer(explorerParams);
186
     	    SHPNewStoreParameters newParams = (SHPNewStoreParameters) explorer.getAddParameters(newFile);
187
        	newParams.setSRS(origLayer.getFeatureStore().getDefaultFeatureType().getDefaultSRS());
188
        	String duplicate = null;
189
        	if (panel1.getDuplicate().compareTo(PluginServices.getText(this, "duplicate.none"))==0){
190
        		duplicate="duplicate.none";
191
        	}else if (panel1.getDuplicate().compareTo(PluginServices.getText(this, "centered"))==0){
192
        		duplicate="centered";
193
        	}
194
        	annotationManager.create(origLayer.getFeatureStore(), explorer, newParams, duplicate);
195
        	
196
        	// Creating .gva file for gvSIG annotation filter purposes.
197
    	   	File gvaFile=new File(newFile.getParent()+File.separatorChar+newFile.getName().substring(0, newFile.getName().length()-4)+".gva");
198
    	    if(!gvaFile.exists()){
199
    	    	gvaFile.createNewFile();
200
    	    }
201
    	    
158 202
		} catch (DataException e) {
159 203
        	// ERROR NOTIFICATION MANAGER
160 204
       		NotificationManager.addError(e);
......
164 208
		} catch (CreateGeometryException e) {
165 209
			// ERROR NOTIFICATION MANAGER
166 210
			NotificationManager.addError(e);
211
		} catch (IOException e) {
212
			// ERROR NOTIFICATION MANAGER
213
			NotificationManager.addError(e);
167 214
		}
168 215
        this.myWizardComponents.getCancelAction().performAction();
169 216
    }

Also available in: Unified diff