use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class YSLDFileHandler method internalOpenFile.
/**
* Internal open file.
*
* @param f the file
* @param list the list
*/
private void internalOpenFile(File f, List<SLDDataInterface> list) {
if (f.isFile() && FileSystemUtils.isFileExtensionSupported(f, getFileExtensionList())) {
try {
String contents = readFile(f, Charset.defaultCharset());
StyledLayerDescriptor sld = Ysld.parse(contents);
// Convert YSLD to SLD string
if (sldWriter == null) {
sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
}
String sldContents = sldWriter.encodeSLD(null, sld);
SLDDataInterface sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
sldData.setSLDFile(f);
sldData.setReadOnly(false);
sldData.setOriginalFormat(SLDOutputFormatEnum.YSLD);
list.add(sldData);
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class GeoServerInput method populateWorkspaceList.
/**
* Populate workspace list.
*
* @param client the client
* @param parentMenu the parent menu
*/
private void populateWorkspaceList(GeoServerClientInterface client, JMenu parentMenu) {
for (String workspaceName : client.getWorkspaceList()) {
JMenuItem workspaceMenuItem = new JMenuItem(workspaceName);
workspaceMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
StyleWrapper styleWrapper = sldData.getStyle();
removeStyleFileExtension(styleWrapper);
styleWrapper.setWorkspace(workspaceName);
client.uploadSLD(styleWrapper, sldData.getSld());
client.refreshWorkspace(workspaceName);
}
});
parentMenu.add(workspaceMenuItem);
}
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class GeoServerInput method getSLDContents.
/*
* (non-Javadoc)
*
* @see com.sldeditor.extension.input.FileSystemInterface#getSLDContents(com.sldeditor.extension.input.NodeInterface)
*/
@Override
public SelectedFiles getSLDContents(NodeInterface node) {
if (node instanceof GeoServerStyleNode) {
GeoServerStyleNode styleNode = (GeoServerStyleNode) node;
GeoServerConnection connectionData = styleNode.getConnectionData();
GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(connectionData);
if (client != null) {
String sldContent = client.getStyle(styleNode.getStyle());
SLDDataInterface sldData = new SLDData(styleNode.getStyle(), sldContent);
sldData.setConnectionData(connectionData);
sldData.setReadOnly(false);
List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
sldDataList.add(sldData);
SelectedFiles selectedFiles = new SelectedFiles();
selectedFiles.setSldData(sldDataList);
selectedFiles.setDataSource(false);
selectedFiles.setConnectionData(connectionData);
return selectedFiles;
}
} else if (node instanceof GeoServerWorkspaceNode) {
GeoServerWorkspaceNode workspaceNode = (GeoServerWorkspaceNode) node;
GeoServerConnection connectionData = workspaceNode.getConnection();
GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(connectionData);
List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
if (workspaceNode.isStyle()) {
Map<String, List<StyleWrapper>> styleMap = getStyleMap(connectionData);
if ((client != null) && (styleMap != null)) {
for (StyleWrapper style : styleMap.get(workspaceNode.getWorkspaceName())) {
String sldContent = client.getStyle(style);
SLDDataInterface sldData = new SLDData(style, sldContent);
sldData.setConnectionData(connectionData);
sldData.setReadOnly(false);
sldDataList.add(sldData);
}
}
}
SelectedFiles selectedFiles = new SelectedFiles();
selectedFiles.setSldData(sldDataList);
selectedFiles.setDataSource(false);
selectedFiles.setConnectionData(connectionData);
return selectedFiles;
} else if (node instanceof GeoServerStyleHeadingNode) {
GeoServerStyleHeadingNode styleHeadingNode = (GeoServerStyleHeadingNode) node;
GeoServerConnection connectionData = styleHeadingNode.getConnection();
GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(connectionData);
List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
Map<String, List<StyleWrapper>> styleMap = getStyleMap(connectionData);
if ((client != null) && (styleMap != null)) {
for (String workspaceName : styleMap.keySet()) {
for (StyleWrapper style : styleMap.get(workspaceName)) {
String sldContent = client.getStyle(style);
SLDDataInterface sldData = new SLDData(style, sldContent);
sldData.setConnectionData(connectionData);
sldData.setReadOnly(false);
sldDataList.add(sldData);
}
}
}
SelectedFiles selectedFiles = new SelectedFiles();
selectedFiles.setSldData(sldDataList);
selectedFiles.setDataSource(false);
selectedFiles.setConnectionData(connectionData);
return selectedFiles;
} else if (node instanceof GeoServerNode) {
GeoServerNode geoServerNode = (GeoServerNode) node;
GeoServerConnection connectionData = geoServerNode.getConnection();
SelectedFiles selectedFiles = new SelectedFiles();
selectedFiles.setDataSource(false);
selectedFiles.setConnectionData(connectionData);
return selectedFiles;
}
return null;
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class GeoServerReadProgress method populateStyles.
/**
* Populate styles.
*
* @param connection the connection
* @param geoServerNode the geo server node
*/
private void populateStyles(GeoServerConnection connection, GeoServerNode geoServerNode) {
removeNode(geoServerNode, STYLES_NODE_TITLE);
GeoServerStyleHeadingNode styleNode = new GeoServerStyleHeadingNode(this.handler, connection, STYLES_NODE_TITLE);
geoServerNode.add(styleNode);
Map<String, List<StyleWrapper>> styleMap = geoServerStyleMap.get(connection);
for (String workspaceName : styleMap.keySet()) {
List<StyleWrapper> styleList = styleMap.get(workspaceName);
GeoServerWorkspaceNode workspaceNode = new GeoServerWorkspaceNode(this.handler, connection, workspaceName, true);
// It is key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
treeModel.insertNodeInto(workspaceNode, styleNode, styleNode.getChildCount());
for (StyleWrapper styleWrapper : styleList) {
GeoServerStyleNode childNode = new GeoServerStyleNode(this.handler, connection, styleWrapper);
// It is key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
treeModel.insertNodeInto(childNode, workspaceNode, workspaceNode.getChildCount());
}
}
}
use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.
the class GeoServerClient method parseLayerList.
/**
* Parses the layer list.
*
* @param reader the reader
* @param existingWorkspaceList the existing workspace list
* @param workspaceName the workspace name
*/
private void parseLayerList(GeoServerRESTReader reader, List<String> existingWorkspaceList, String workspaceName) {
Thread t1 = new Thread(new Runnable() {
public void run() {
List<String> workspaceList = null;
if (workspaceName == null) {
workspaceList = existingWorkspaceList;
// Add the default workspace last
workspaceList.add(null);
}
Map<String, List<GeoServerLayer>> layerMap = new LinkedHashMap<String, List<GeoServerLayer>>();
RESTLayerList layers = reader.getLayers();
int count = 1;
int total = layers.size();
for (NameLinkElem featureTypeName : layers) {
@SuppressWarnings("deprecation") RESTLayer layer = reader.getLayer(featureTypeName.getName());
if (layer != null) {
String layerName = layer.getName();
String workspace = null;
for (String workspaceNameToTest : workspaceList) {
if (reader.existsLayer(workspaceNameToTest, layerName, true)) {
if (workspaceNameToTest == null) {
workspace = DEFAULT_WORKSPACE_NAME;
} else {
workspace = workspaceNameToTest;
}
break;
}
}
GeoServerLayer geoServerlayer = new GeoServerLayer();
geoServerlayer.setLayerWorkspace(workspace);
geoServerlayer.setLayerName(layerName);
geoServerlayer.setConnection(connection);
StyleWrapper styleWrapper = new StyleWrapper();
styleWrapper.setStyle(layer.getDefaultStyle());
String styleWorkspace = layer.getDefaultStyleWorkspace();
styleWrapper.setWorkspace((styleWorkspace == null) ? DEFAULT_WORKSPACE_NAME : styleWorkspace);
geoServerlayer.setStyle(styleWrapper);
List<GeoServerLayer> layerList = layerMap.get(workspace);
if (layerList == null) {
layerList = new ArrayList<GeoServerLayer>();
layerMap.put(workspace, layerList);
}
layerList.add(geoServerlayer);
if (parentObj != null) {
parentObj.readLayersProgress(connection, count, total);
}
}
count++;
}
if (parentObj != null) {
parentObj.readLayersComplete(connection, layerMap);
}
}
});
t1.start();
}
Aggregations