public static LayerManager getDefault() { if (layerManager == null) { layerManager = new LayerManager(); } return layerManager; }
@Override public void run() { // test! LayerManager.getDefault(); } }
protected LayerManager() { registerLayerEditors(); this.layerSourceDescriptors = lookupLayerSourceDescriptors(); }
public static void registerLayerEditorDescriptor(FileObject fileObject) throws Exception { Class<? extends LayerEditor> editorClass = getClassAttribute(fileObject, "editorClass", LayerEditor.class, false); Class<? extends ExtensionFactory> editorFactoryClass = getClassAttribute(fileObject, "editorFactoryClass", ExtensionFactory.class, false); Assert.argument(editorClass != null || editorFactoryClass != null, "Either 'editorClass' or 'editorFactoryClass' attributes must be given"); Class<? extends Layer> layerClass = getClassAttribute(fileObject, "layerClass", Layer.class, false); Class<? extends LayerType> layerTypeClass = getClassAttribute(fileObject, "layerTypeClass", LayerType.class, false); Assert.argument(layerClass != null || layerTypeClass != null, "Either 'layerClass' or 'layerTypeClass' attributes must be given"); if (layerClass != null) { ExtensionManager.getInstance().register(layerClass, createExtensionFactory(editorClass, editorFactoryClass)); } else { ExtensionManager.getInstance().register(layerTypeClass, createExtensionFactory(editorClass, editorFactoryClass)); } }
@Override public void actionPerformed(ActionEvent e) { LayerSourceAssistantPane pane = new LayerSourceAssistantPane(SwingUtilities.getWindowAncestor(control), "Add Layer"); final Map<String, LayerSourceDescriptor> layerSourceDescriptors1 = LayerManager.getDefault().getLayerSourceDescriptors(); final LayerSourceDescriptor[] layerSourceDescriptors2 = layerSourceDescriptors1.values().toArray(new LayerSourceDescriptor[layerSourceDescriptors1.size()]); pane.show(new SelectLayerSourceAssistantPage(layerSourceDescriptors2), screenBounds); screenBounds = pane.getWindow().getBounds(); } }
private static void registerLayerEditors() { FileObject[] files = FileUtil.getConfigFile("LayerEditors").getChildren(); //System.out.println("Files in SNAP/LayerEditors: " + Arrays.toString(files)); List<FileObject> orderedFiles = FileUtil.getOrder(Arrays.asList(files), true); for (FileObject file : orderedFiles) { try { registerLayerEditorDescriptor(file); LOG.info(String.format("New layer editor registered from layer.xml path '%s'", file.getPath())); } catch (Exception e) { LOG.log(Level.SEVERE, String.format("Failed to register layer editor from layer.xml path '%s'", file.getPath()), e); } } }
private static Map<String, LayerSourceDescriptor> lookupLayerSourceDescriptors() { Map<String, LayerSourceDescriptor> layerSourceDescriptors = new LinkedHashMap<>(); FileObject[] files = FileUtil.getConfigFile("LayerSources").getChildren(); //System.out.println("Files in SNAP/LayerSources: " + Arrays.toString(files)); List<FileObject> orderedFiles = FileUtil.getOrder(Arrays.asList(files), true); for (FileObject file : orderedFiles) { LayerSourceDescriptor layerSourceDescriptor = null; try { layerSourceDescriptor = createLayerSourceDescriptor(file); } catch (Exception e) { LOG.log(Level.SEVERE, String.format("Failed to create layer source from layer.xml path '%s'", file.getPath()), e); } if (layerSourceDescriptor != null) { layerSourceDescriptors.put(layerSourceDescriptor.getId(), layerSourceDescriptor); LOG.info(String.format("New layer source added from layer.xml path '%s': %s", file.getPath(), layerSourceDescriptor.getName())); } } return layerSourceDescriptors; }
public static DefaultLayerSourceDescriptor createLayerSourceDescriptor(FileObject fileObject) { String id = fileObject.getName(); String name = (String) fileObject.getAttribute("displayName"); String description = (String) fileObject.getAttribute("description"); Class<? extends LayerSource> layerSourceClass = getClassAttribute(fileObject, "layerSourceClass", LayerSource.class, false); String layerTypeClassName = (String) fileObject.getAttribute("layerTypeClass"); Assert.argument(name != null && !name.isEmpty(), "Missing attribute 'displayName'"); Assert.argument(layerSourceClass != null || layerTypeClassName != null, "Either attribute 'class' or 'layerType' must be provided"); if (layerSourceClass != null) { return new DefaultLayerSourceDescriptor(id, name, description, layerSourceClass); } else { return new DefaultLayerSourceDescriptor(id, name, description, layerTypeClassName); } }