Hi Ede, well, i corrected both of your points, so here is another update :)I wasn't aware this reformatting would disturb reviewing, so I changed that back. Originally I was replacing some taps with white spaces where it was not even. Effectively I changed only two lines in AbstractSaveProjectPlugin. Btw. it is possible to ignore withespaces when comparing in Eclipse, but I see your point...
@Peppe Thanks for your feedback! I will consider your points in my further works. Cheers, Matthias
Index: src/com/vividsolutions/jump/workbench/ui/plugin/AbstractSaveProjectPlugIn.java =================================================================== --- src/com/vividsolutions/jump/workbench/ui/plugin/AbstractSaveProjectPlugIn.java (revision 3701) +++ src/com/vividsolutions/jump/workbench/ui/plugin/AbstractSaveProjectPlugIn.java (working copy) @@ -42,6 +42,7 @@ import java.util.Iterator; import javax.swing.JInternalFrame; +import javax.xml.namespace.QName; import com.vividsolutions.jump.I18N; import com.vividsolutions.jump.util.FileUtil; @@ -76,7 +77,8 @@ } task.setSavedViewEnvelope(frame.getContext().getLayerViewPanel() .getViewport().getEnvelopeInModelCoordinates()); - + task.setProperty(new QName(Task.PROJECT_FILE_KEY), file.getAbsolutePath()); + StringWriter stringWriter = new StringWriter(); try { Index: src/com/vividsolutions/jump/workbench/model/Task.java =================================================================== --- src/com/vividsolutions/jump/workbench/model/Task.java (revision 3701) +++ src/com/vividsolutions/jump/workbench/model/Task.java (working copy) @@ -66,6 +66,12 @@ /** The map of task properties. */ private Map<QName, Object> properties = new HashMap<QName, Object>(); + + /** + * Project File property, + * Used to determine whether a project file has been moved away from its original location + */ + public static final String PROJECT_FILE_KEY = "Project File"; // No parameters so it can be created by Java2XML. public Task() { Index: src/language/jump_de.properties =================================================================== --- src/language/jump_de.properties (revision 3701) +++ src/language/jump_de.properties (working copy) @@ -1797,6 +1797,8 @@ ui.plugin.MoveLayerablePlugIn.layer-is-already-at-the-top = Ebene ist bereits ganz oben ui.plugin.MoveLayerablePlugIn.move-layer-down = Ebene herunter schieben ui.plugin.MoveLayerablePlugIn.move-layer-up = Ebene hoch schieben +ui.plugin.OpenProjectPlugIn.The-project-has-been-moved-Do-you-want-to-update-paths-below-the-project-folder = Das Projekt wurde verschoben. M\u00F6chten sie Dateipfade innerhalb der Projektordners aktualisieren? +ui.plugin.OpenProjectPlugIn.Only-for-missing-resources = Nur bei fehlenden Dateien ui.plugin.OpenProjectPlugIn.At-least-one-file-in-the-task-could-not-be-found = Mindestens eine Datei des Projektes wurde nicht gefunden. ui.plugin.OpenProjectPlugIn.Do-you-want-to-locate-it-and-continue-loading-the-task = Wollen sie die Datei-Position eingeben und das Projekt laden? ui.plugin.OpenProjectPlugIn.creating-objects = Objekte werden gebildet Index: src/language/jump.properties =================================================================== --- src/language/jump.properties (revision 3701) +++ src/language/jump.properties (working copy) @@ -1812,6 +1812,8 @@ ui.plugin.MoveLayerablePlugIn.layer-is-already-at-the-top = Layer is already at the top ui.plugin.MoveLayerablePlugIn.move-layer-down = Move Layer Down ui.plugin.MoveLayerablePlugIn.move-layer-up = Move Layer Up +ui.plugin.OpenProjectPlugIn.The-project-has-been-moved-Do-you-want-to-update-paths-below-the-project-folder = The project has been moved. Do you want to update paths below the project folder? +ui.plugin.OpenProjectPlugIn.Only-for-missing-resources = Only for missing resources ui.plugin.OpenProjectPlugIn.At-least-one-file-in-the-task-could-not-be-found = At least one file in the project could not be found. ui.plugin.OpenProjectPlugIn.Do-you-want-to-locate-it-and-continue-loading-the-task = Do you want to locate it and continue loading the project? ui.plugin.OpenProjectPlugIn.creating-objects = Creating objects Index: src/org/openjump/core/ui/plugin/file/open/OpenProjectWizard.java =================================================================== --- src/org/openjump/core/ui/plugin/file/open/OpenProjectWizard.java (revision 3701) +++ src/org/openjump/core/ui/plugin/file/open/OpenProjectWizard.java (working copy) @@ -29,6 +29,8 @@ import org.openjump.core.ui.swing.wizard.AbstractWizardGroup; import javax.swing.*; +import javax.xml.namespace.QName; + import java.awt.*; import java.io.File; import java.io.FileNotFoundException; @@ -221,6 +223,27 @@ WorkbenchFrame workbenchFrame = workbench.getFrame(); FindFile findFile = new FindFile(workbenchFrame); boolean displayDialog = true; + + String oldProjectPath = sourceTask.getProperty(new QName(Task.PROJECT_FILE_KEY)); + boolean updateResources = false; + boolean updateOnlyMissingResources = false; + File oldProjectFile = null; + if(oldProjectPath != null && !oldProjectPath.equals("")){ + oldProjectFile = new File(oldProjectPath); + if(!oldProjectFile.equals(newTask.getProjectFile())){ + JCheckBox checkbox = new JCheckBox(I18N.get("ui.plugin.OpenProjectPlugIn.Only-for-missing-resources")); + String message = I18N.get("ui.plugin.OpenProjectPlugIn." + + "The-project-has-been-moved-Do-you-want-to-update-paths-below-the-project-folder"); + Object[] params = {message, checkbox}; + int answer = JOptionPane.showConfirmDialog(workbenchFrame, + params, "OpenJUMP", JOptionPane.YES_NO_OPTION); + if(answer == JOptionPane.YES_OPTION){ + updateResources = true; + if(checkbox.isSelected()) + updateOnlyMissingResources = true; + } + } + } try { List<Category> categories = sourceLayerManager.getCategories(); @@ -242,6 +265,13 @@ if (layerable instanceof Layer) { Layer layer = (Layer)layerable; + File layerFile = getLayerFileProperty(layer); + if(!updateOnlyMissingResources || !layerFile.exists()){ + if(updateResources && layerFile != null && isLocatedBellow(oldProjectFile.getParentFile(), layerFile)) { + File newLayerFile = updateResourcePath(oldProjectFile, newTask.getProjectFile(), layerFile); + setLayerFileProperty(layer, newLayerFile); + } + } try { load(layer, registry, monitor); } catch (FileNotFoundException ex) { @@ -263,7 +293,7 @@ DataSourceQuery dataSourceQuery = layer.getDataSourceQuery(); DataSource dataSource = dataSourceQuery.getDataSource(); Map properties = dataSource.getProperties(); - String fname = properties.get("File").toString(); + String fname = properties.get(DataSource.FILE_KEY).toString(); String filename = findFile.getFileName(fname); if (filename.length() > 0) { // set the new source for this layer @@ -323,5 +353,45 @@ connection.close(); } } + + + private File updateResourcePath(File oldProjectFile, File newProjectFile, File layerFile) { + String oldParent = oldProjectFile.getParentFile().getAbsolutePath(); + String newParent = newProjectFile.getParentFile().getAbsolutePath(); + String child = layerFile.getAbsolutePath(); + String relativePath = child.substring(oldParent.length()+1); + return new File(newParent, relativePath); + } + + private boolean isLocatedBellow(File parentDir, File layerFile) { + if(layerFile == null) + return false; + for (File layerParent = layerFile.getParentFile(); layerParent != null; layerParent = layerParent.getParentFile()) { + if(layerParent.equals(parentDir)) + return true; + } + + return false; + } + + private File getLayerFileProperty(Layer layer) { + DataSourceQuery dataSourceQuery = layer.getDataSourceQuery(); + DataSource dataSource = dataSourceQuery.getDataSource(); + Map properties = dataSource.getProperties(); + Object property = properties.get(DataSource.FILE_KEY); + if(property == null || property.toString().equals("")) + return null; + File layerFile = new File(property.toString()); + return layerFile; + } + + private void setLayerFileProperty(Layer layer, File file) { + DataSourceQuery dataSourceQuery = layer.getDataSourceQuery(); + DataSource dataSource = dataSourceQuery.getDataSource(); + Map properties = dataSource.getProperties(); + properties.put(DataSource.FILE_KEY, file.getAbsolutePath()); + } + + }
------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel