Search in sources :

Example 1 with SLDEditorFile

use of com.sldeditor.datasource.SLDEditorFile in project sldeditor by robward-scisys.

the class ReloadManager method sldDataUpdated.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.datasource.SLDEditorDataUpdateInterface#sldDataUpdated(com.sldeditor.common.SLDDataInterface, boolean)
     */
@Override
public void sldDataUpdated(SLDDataInterface sldData, boolean dataEditedFlag) {
    Map<Path, Boolean> pathList = new HashMap<Path, Boolean>();
    if (sldData != null) {
        File sldFile = sldData.getSLDFile();
        if (sldFile != null) {
            pathList.put(sldFile.toPath(), fileSaved);
        }
        File sldEditorFile = sldData.getSldEditorFile();
        if (sldEditorFile != null) {
            pathList.put(sldEditorFile.toPath(), fileSaved);
        }
    }
    setCurrentLoadedFileList(pathList);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 2 with SLDEditorFile

use of com.sldeditor.datasource.SLDEditorFile in project sldeditor by robward-scisys.

the class SLDEditorFileTest method testSLDData.

/**
 * Test method for {@link com.sldeditor.datasource.SLDEditorFile#getSLDData()}. Test method for
 * {@link com.sldeditor.datasource.SLDEditorFile#fileOpenedSaved()}. Test method for
 * {@link com.sldeditor.datasource.SLDEditorFile#getSldEditorFile()}. Test method for
 * {@link com.sldeditor.datasource.SLDEditorFile#addSLDEditorFileUpdateListener(com.sldeditor.datasource.SLDEditorDataUpdateInterface)}.
 * Test method for {@link com.sldeditor.datasource.SLDEditorFile#renderSymbol()}. Test method
 * for
 * {@link com.sldeditor.datasource.SLDEditorFile#setSLDData(com.sldeditor.common.SLDDataInterface)}.
 * Test method for {@link com.sldeditor.datasource.SLDEditorFile#setSldFile(java.io.File)}. Test
 * method for {@link com.sldeditor.datasource.SLDEditorFile#getDataSource()}. Test method for
 * {@link com.sldeditor.datasource.SLDEditorFile#setDataSource(com.sldeditor.DataSourcePropertiesInterface)}.
 * Test method for
 * {@link com.sldeditor.datasource.SLDEditorFile#setSldEditorFile(java.io.File)}.
 */
@Test
public void testSLDData() {
    // Start with a blank canvas
    SLDEditorFile.destroyInstance();
    SelectedSymbol.destroyInstance();
    assertNull(SLDEditorFile.getInstance().getSLD());
    assertNull(SLDEditorFile.getInstance().getSLDData());
    assertNull(SLDEditorFile.getInstance().getSldEditorFile());
    assertNull(SLDEditorFile.getInstance().getDataSource());
    SLDEditorFile.getInstance().setDataSource(null);
    assertNull(SLDEditorFile.getInstance().getDataSource());
    SLDEditorFile.getInstance().setSldEditorFile(null);
    assertNull(SLDEditorFile.getInstance().getSldEditorFile());
    SLDEditorFile.getInstance().setSldFile(null);
    assertNull(SLDEditorFile.getInstance().getSLDData());
    SLDEditorFile.getInstance().setSLDData(null);
    assertNull(SLDEditorFile.getInstance().getSLDData());
    DummyDataUpdate dataUpdateListener = new DummyDataUpdate();
    SLDEditorFile.getInstance().addSLDEditorFileUpdateListener(dataUpdateListener);
    // Set SLDData
    StyleWrapper styleWrapper = new StyleWrapper("workspace", "style");
    SLDData sldData = new SLDData(styleWrapper, "contents");
    SLDEditorFile.getInstance().setSLDData(sldData);
    SLDEditorFile.getInstance().fileOpenedSaved();
    assertEquals(sldData, SLDEditorFile.getInstance().getSLDData());
    assertFalse(dataUpdateListener.dataEditedFlag);
    // Sld file
    File sldFile = new File("test.txt");
    SLDEditorFile.getInstance().setSldFile(sldFile);
    assertEquals(sldFile.getAbsolutePath(), SLDEditorFile.getInstance().getSLDData().getSLDFile().getAbsolutePath());
    assertFalse(dataUpdateListener.dataEditedFlag);
    // Sld editor file
    File sldEditorFile = new File("editor.file");
    SLDEditorFile.getInstance().setSldEditorFile(sldEditorFile);
    assertEquals(sldEditorFile.getAbsolutePath(), SLDEditorFile.getInstance().getSldEditorFile().getAbsolutePath());
    assertFalse(dataUpdateListener.dataEditedFlag);
    // Data source properties
    SLDEditorFile.getInstance().setDataSource(null);
    assertFalse(dataUpdateListener.dataEditedFlag);
    DataSourcePropertiesInterface noDataSource = DataSourceConnectorFactory.getNoDataSource();
    assertEquals(noDataSource.getDebugConnectionString(), SLDEditorFile.getInstance().getDataSource().getDebugConnectionString());
    assertFalse(dataUpdateListener.dataEditedFlag);
    DataSourcePropertiesInterface fileDSProperties = new DataSourceProperties(new DataSourceConnector());
    assertEquals(fileDSProperties.getDebugConnectionString(), SLDEditorFile.getInstance().getDataSource().getDebugConnectionString());
    assertFalse(dataUpdateListener.dataEditedFlag);
    // Render symbol
    SLDEditorFile.getInstance().renderSymbol();
    assertTrue(dataUpdateListener.dataEditedFlag);
    // File saved
    SLDEditorFile.getInstance().fileOpenedSaved();
    assertFalse(dataUpdateListener.dataEditedFlag);
    assertNull(SLDEditorFile.getInstance().getRuleRenderOptions());
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) DataSourceProperties(com.sldeditor.datasource.impl.DataSourceProperties) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) Test(org.junit.Test)

Example 3 with SLDEditorFile

use of com.sldeditor.datasource.SLDEditorFile in project sldeditor by robward-scisys.

the class SLDEditorMenus method createFileMenu.

/**
 * Creates the file menu.
 *
 * @param appPanel the app panel
 * @param menuBar the menu bar
 */
private void createFileMenu(JPanel appPanel, JMenuBar menuBar) {
    JMenu fileMenu = new JMenu(Localisation.getString(SLDEditorMenus.class, "file.menu"));
    menuBar.add(fileMenu);
    // New
    JMenuItem mntmNew = new JMenuItem(Localisation.getString(SLDEditorMenus.class, "file.menu.new"));
    mntmNew.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            application.chooseNewSLD();
        }
    });
    // Open
    JMenuItem menuOpenSLDEditorFile = new JMenuItem(Localisation.getString(SLDEditorMenus.class, "common.open"), KeyEvent.VK_O);
    menuOpenSLDEditorFile.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter(Localisation.getString(SLDEditorMenus.class, "file.files.filter") + " (*." + APPLICATION_FILE_EXTENSION + ")", APPLICATION_FILE_EXTENSION);
            fileChooser.setFileFilter(filter);
            File f = SLDEditorFile.getInstance().getSldEditorFile();
            if ((f != null) && f.exists()) {
                fileChooser.setSelectedFile(f);
            }
            int result = fileChooser.showOpenDialog(appPanel);
            if (result == JFileChooser.APPROVE_OPTION) {
                File selectedFile = fileChooser.getSelectedFile();
                try {
                    application.openFile(selectedFile.toURI().toURL());
                } catch (MalformedURLException e1) {
                    ConsoleManager.getInstance().exception(SLDEditorMenus.class, e1);
                }
                SLDEditorFile.getInstance().fileOpenedSaved();
            }
        }
    });
    // Save
    menuSaveSLDEditorFile = new JMenuItem(Localisation.getString(SLDEditorMenus.class, "common.save"), KeyEvent.VK_S);
    menuSaveSLDEditorFile.setEnabled(false);
    menuSaveSLDEditorFile.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            File sldEditorFile = SLDEditorFile.getInstance().getSldEditorFile();
            try {
                application.saveFile(sldEditorFile.toURI().toURL());
            } catch (MalformedURLException e1) {
                ConsoleManager.getInstance().exception(SLDEditorMenus.class, e1);
            }
            SLDEditorFile.getInstance().fileOpenedSaved();
        }
    });
    // Save as
    menuSaveAsSLDEditorFile = new JMenuItem(Localisation.getString(SLDEditorMenus.class, "common.saveas"), KeyEvent.VK_A);
    menuSaveAsSLDEditorFile.setEnabled(false);
    menuSaveAsSLDEditorFile.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser() {

                /**
                 * The Constant serialVersionUID.
                 */
                private static final long serialVersionUID = 1L;

                /*
                     * (non-Javadoc)
                     * 
                     * @see javax.swing.JFileChooser#approveSelection()
                     */
                @Override
                public void approveSelection() {
                    File f = getSelectedFile();
                    if (f.exists()) {
                        int result = JOptionPane.showConfirmDialog(this, Localisation.getString(SLDEditorMenus.class, "file.sldeditor.save.config.title"), Localisation.getString(SLDEditorMenus.class, "file.sldeditor.save.config.message"), JOptionPane.YES_NO_CANCEL_OPTION);
                        switch(result) {
                            case JOptionPane.YES_OPTION:
                                super.approveSelection();
                                return;
                            case JOptionPane.NO_OPTION:
                                return;
                            case JOptionPane.CLOSED_OPTION:
                                cancelSelection();
                                return;
                            case JOptionPane.CANCEL_OPTION:
                                cancelSelection();
                                return;
                            default:
                                break;
                        }
                    }
                    super.approveSelection();
                }
            };
            fileChooser.setDialogTitle(Localisation.getString(SLDEditorMenus.class, "file.sldeditor.save.dialog"));
            fileChooser.setAcceptAllFileFilterUsed(false);
            FileNameExtensionFilter filter = new FileNameExtensionFilter(Localisation.getString(SLDEditorMenus.class, "file.files.filter") + " (*." + APPLICATION_FILE_EXTENSION + ")", APPLICATION_FILE_EXTENSION);
            fileChooser.setFileFilter(filter);
            int userSelection = fileChooser.showSaveDialog(appPanel);
            if (userSelection == JFileChooser.APPROVE_OPTION) {
                File fileToSave = fileChooser.getSelectedFile();
                if (!fileChooser.getFileFilter().accept(fileToSave)) {
                    fileToSave = new File(fileToSave.getAbsolutePath() + "." + APPLICATION_FILE_EXTENSION);
                }
                try {
                    SLDEditorFile.getInstance().setSldEditorFile(fileToSave);
                    application.saveFile(fileToSave.toURI().toURL());
                } catch (MalformedURLException e1) {
                    ConsoleManager.getInstance().exception(SLDEditorMenus.class, e1);
                }
                SLDEditorFile.getInstance().fileOpenedSaved();
            }
        }
    });
    // Exit
    JMenuItem mntmExit = new JMenuItem(Localisation.getString(SLDEditorMenus.class, "file.menu.exit"));
    mntmExit.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            application.exitApplication();
        }
    });
    fileMenu.add(mntmNew);
    fileMenu.add(menuOpenSLDEditorFile);
    fileMenu.add(menuSaveSLDEditorFile);
    fileMenu.add(menuSaveAsSLDEditorFile);
    fileMenu.add(mntmExit);
}
Also used : MalformedURLException(java.net.MalformedURLException) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File) JMenu(javax.swing.JMenu)

Example 4 with SLDEditorFile

use of com.sldeditor.datasource.SLDEditorFile in project sldeditor by robward-scisys.

the class SLDEditor method populate.

/**
 * Populate the application with the SLD.
 *
 * @param sldData the sld data
 */
protected void populate(SLDDataInterface sldData) {
    String layerName = sldData.getLayerName();
    File sldEditorFile = sldData.getSldEditorFile();
    if (sldEditorFile != null) {
        ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(getClass(), "SLDEditor.loadedSLDEditorFile"), sldEditorFile.getAbsolutePath()));
    }
    ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(getClass(), "SLDEditor.loadedSLDFile"), layerName));
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    SelectedSymbol selectedSymbolInstance = SelectedSymbol.getInstance();
    selectedSymbolInstance.setSld(sld);
    selectedSymbolInstance.setFilename(layerName);
    selectedSymbolInstance.setName(layerName);
    SLDEditorFile.getInstance().setSLDData(sldData);
    // Reload data source if sticky flag is set
    boolean isDataSourceSticky = SLDEditorFile.getInstance().isStickyDataSource();
    DataSourcePropertiesInterface previousDataSource = dataSource.getDataConnectorProperties();
    dataSource.reset();
    if (isDataSourceSticky) {
        SLDEditorFile.getInstance().setDataSource(previousDataSource);
    }
    dataSource.connect(ExternalFilenames.removeSuffix(layerName), SLDEditorFile.getInstance(), CheckAttributeFactory.getCheckList());
    VendorOptionManager.getInstance().loadSLDFile(uiMgr, sld, sldData);
    LegendManager.getInstance().SLDLoaded(sldData.getLegendOptions());
    SLDEditorFile.getInstance().fileOpenedSaved();
}
Also used : SelectedSymbol(com.sldeditor.common.data.SelectedSymbol) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 5 with SLDEditorFile

use of com.sldeditor.datasource.SLDEditorFile in project sldeditor by robward-scisys.

the class VectorTool method setDataSource.

/**
 * Sets the data source.
 *
 * @param fileTreeNode the new data source
 */
protected void setDataSource(FileTreeNode fileTreeNode) {
    File vectorFile = fileTreeNode.getFile();
    ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(VectorTool.class, "VectorTool.setDataSource"), vectorFile.getAbsolutePath()));
    // Vector file
    DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
    DataSourcePropertiesInterface dsProperties = null;
    try {
        dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(vectorFile.toURI().toURL().toString()));
    } catch (MalformedURLException exceptionObj) {
        ConsoleManager.getInstance().exception(VectorTool.class, exceptionObj);
        return;
    }
    SLDEditorFile sldEditorFile = SLDEditorFile.getInstance();
    sldEditorFile.setDataSource(dsProperties);
    DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
    if (dataSource != null) {
        String dataSourceName = ExternalFilenames.removeSuffix(vectorFile.getName());
        dataSource.connect(dataSourceName, sldEditorFile, CheckAttributeFactory.getCheckList());
    }
}
Also used : DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) MalformedURLException(java.net.MalformedURLException) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Aggregations

SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)5 File (java.io.File)5 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)3 MalformedURLException (java.net.MalformedURLException)2 DataSourceConnectorInterface (com.sldeditor.common.DataSourceConnectorInterface)1 SLDData (com.sldeditor.common.data.SLDData)1 SelectedSymbol (com.sldeditor.common.data.SelectedSymbol)1 StyleWrapper (com.sldeditor.common.data.StyleWrapper)1 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)1 DataSourceConnector (com.sldeditor.datasource.connector.instance.DataSourceConnector)1 DataSourceProperties (com.sldeditor.datasource.impl.DataSourceProperties)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 JFileChooser (javax.swing.JFileChooser)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)1 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)1