use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class SLDEditor method saveFile.
/**
* Save file.
*
* @param urlToSave the url to save
*/
/*
* (non-Javadoc)
*
* @see com.sldeditor.SLDEditorInterface#saveFile(java.net.URL)
*/
@Override
public void saveFile(URL urlToSave) {
String sldContents = getSLDString();
SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
sldData.updateSLDContents(sldContents);
if (RelativePath.isLocalFile(urlToSave)) {
StyleWrapper style = null;
try {
File f = new File(urlToSave.toURI());
style = new StyleWrapper(f.getName());
} catch (URISyntaxException e) {
ConsoleManager.getInstance().exception(this, e);
}
sldData.updateStyleWrapper(style);
}
ReloadManager.getInstance().setFileSaved();
saveSLDData(sldData);
SLDEditorFile.getInstance().fileOpenedSaved();
UndoManager.getInstance().fileSaved();
}
use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class SLDEditor method reloadSLDFile.
/*
* (non-Javadoc)
*
* @see com.sldeditor.common.LoadSLDInterface#reloadSLDFile()
*/
@Override
public void reloadSLDFile() {
boolean reloadFile = true;
if (!underTestFlag) {
reloadFile = sldEditorDlg.reload(frame);
}
if (reloadFile) {
SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
if (sldData != null) {
URL url = sldData.getSLDURL();
if (url != null) {
List<SLDDataInterface> sldDataList = null;
for (ExtensionInterface extension : extensionList) {
if (sldDataList == null) {
sldDataList = extension.open(url);
}
}
if ((sldDataList != null) && !sldDataList.isEmpty()) {
SLDDataInterface firstObject = sldDataList.get(0);
populate(firstObject);
}
}
}
// Inform UndoManager that a new SLD file has been
// loaded and to clear undo history
UndoManager.getInstance().fileLoaded();
Controller.getInstance().setPopulating(true);
uiMgr.populateUI(1);
Controller.getInstance().setPopulating(false);
}
ReloadManager.getInstance().reset();
}
use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class SLDEditor method chooseNewSLD.
/**
* Choose new sld.
*/
@Override
public void chooseNewSLD() {
NewSLDPanel panel = new NewSLDPanel();
List<SLDDataInterface> newSLDList = panel.showDialog(Controller.getInstance().getFrame());
if (newSLDList != null) {
SelectedFiles selectedFiles = new SelectedFiles();
selectedFiles.setSldData(newSLDList);
if (loadSLDString(selectedFiles)) {
uiMgr.populateUI(1);
}
}
}
use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class MapBoxWriterImpl method encodeSLD.
/**
* Encode sld to a string.
*
* @param resourceLocator the resource locator
* @param sld the sld
* @return the MppBox string
*/
@Override
public String encodeSLD(URL resourceLocator, StyledLayerDescriptor sld) {
SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
if (sldData.getOriginalFormat() == SLDOutputFormatEnum.MAPBOX) {
File f = sldData.getSLDFile();
if ((cachedFile == null) || !cachedFile.equals(f)) {
cachedFile = f;
try {
StringBuilder data = new StringBuilder();
Stream<String> lines = Files.lines(f.toPath());
lines.forEach(line -> data.append(line).append("\n"));
lines.close();
cachedString = data.toString();
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
return cachedString;
}
return Localisation.getString(MapBoxWriterImpl.class, "MapBoxWriterImpl.notSupported");
}
use of com.sldeditor.common.SLDDataInterface in project sldeditor by robward-scisys.
the class CreateInternalDataSource method connect.
/**
* Creates the.
*
* @param typeName the type name
* @param geometryFieldName the geometry field name
* @param editorFile the editor file
* @return the list of datastores
*/
@Override
public List<DataSourceInfo> connect(String typeName, String geometryFieldName, SLDEditorFileInterface editorFile) {
List<DataSourceInfo> dataSourceInfoList = new ArrayList<DataSourceInfo>();
dataSourceInfoList.add(dsInfo);
dsInfo.reset();
if (editorFile != null) {
StyledLayerDescriptor sld = editorFile.getSLD();
determineGeometryType(sld);
ExtendedSimpleFeatureTypeBuilder b = new ExtendedSimpleFeatureTypeBuilder();
// set the name
typeName = INTERNAL_SCHEMA_NAME;
dsInfo.setTypeName(typeName);
b.setName(typeName);
String namespace = null;
b.setNamespaceURI(namespace);
// add a geometry property
// set crs first
b.setCRS(DefaultGeographicCRS.WGS84);
SLDDataInterface sldData = editorFile.getSLDData();
List<DataSourceAttributeData> fieldList = sldData.getFieldList();
// Set the geometry field by default
geometryField.reset();
if (geometryFieldName != null) {
geometryField.setGeometryFieldName(geometryFieldName);
}
List<AttributeDescriptor> attrDescList = new ArrayList<AttributeDescriptor>();
if ((fieldList == null) || fieldList.isEmpty()) {
// Read the fields from the SLD
ExtractAttributes extract = new ExtractAttributes();
extract.extractDefaultFields(sld);
fieldList = extract.getFields();
// Add non-geometry fields to the feature type builder
for (DataSourceAttributeData dsAttribute : fieldList) {
if (dsAttribute.getName() != null) {
b.add(dsAttribute.getName(), dsAttribute.getType());
}
}
List<String> geometryFields = extract.getGeometryFields();
for (String localGeometryFieldName : geometryFields) {
geometryField.setGeometryFieldName(localGeometryFieldName);
}
} else {
addFields(attrDescList, b, fieldList);
}
attrDescList.add(addGeometryField(b, geometryField.getGeometryFieldName()));
b.addAll(attrDescList);
// Store the fields
sldData.setFieldList(fieldList);
// Build the feature type
SimpleFeatureType schema = b.buildFeatureType();
dsInfo.setSchema(schema);
CreateSampleData sampleData = new CreateSampleData();
sampleData.create(schema, fieldList);
MemoryDataStore dataStore = sampleData.getDataStore();
dsInfo.setDataStore(dataStore);
dsInfo.populateFieldMap();
}
return dataSourceInfoList;
}
Aggregations