Just a small update on the patch because of a faulty German Umlaut in the translation.

Am 09.09.2013 01:26, schrieb Matthias Hinz:
Dear all,

I changed my solution according to the latest discussion and it works without obstacles, as far as I tested. Also there is a screenshot which asks if paths should be updated. For "no" the program works like before, for "yes" 'all' file path bellow the project directory will be rebased. It is possible to limit this action to missing resources. If one of the resources does not exist in its new location, the known filechooser dialog pops up.

I'm just a little unsure about the dialog text. Is it self-explaining? I added German translation as well. With the other languages I'm not yet firm enough :).

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;
@@ -64,21 +65,21 @@
         //First use StringWriter to make sure no errors occur before we touch 
the
         //original file -- we don't want to damage the original if an error 
occurs.
         //[Jon Aquino]
-       JInternalFrame taskWindow = frame.getActiveInternalFrame();
+        JInternalFrame taskWindow = frame.getActiveInternalFrame();
         task.setMaximized(taskWindow.isMaximum());
         if (taskWindow.isMaximum()) {  //save the rectangle that it would be 
restored to
-               Rectangle normalBounds = taskWindow.getNormalBounds();
-               task.setTaskWindowLocation(new 
Point(normalBounds.x,normalBounds.y));
-               task.setTaskWindowSize(new 
Dimension(normalBounds.width,normalBounds.height));
+            Rectangle normalBounds = taskWindow.getNormalBounds();
+            task.setTaskWindowLocation(new 
Point(normalBounds.x,normalBounds.y));
+            task.setTaskWindowSize(new 
Dimension(normalBounds.width,normalBounds.height));
         } else {
-               task.setTaskWindowLocation(taskWindow.getLocation());
-               task.setTaskWindowSize(taskWindow.getSize());
+            task.setTaskWindowLocation(taskWindow.getLocation());
+            task.setTaskWindowSize(taskWindow.getSize());
         }
         task.setSavedViewEnvelope(frame.getContext().getLayerViewPanel()
-               .getViewport().getEnvelopeInModelCoordinates());
-
+                .getViewport().getEnvelopeInModelCoordinates());
+        task.setProperty(new QName(Task.PROJECT_FILE_KEY), 
file.getAbsolutePath());
         StringWriter stringWriter = new StringWriter();
-
+       
         try {
             new Java2XML().write(task, "project", stringWriter);
         } finally {
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-bellow-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-bellow-the-project-folder
 = The project has been moved. Do you want to update paths bellow 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)
@@ -21,6 +21,7 @@
 import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
 import com.vividsolutions.jump.workbench.ui.plugin.WorkbenchContextReference;
 import com.vividsolutions.jump.workbench.ui.wizard.WizardDialog;
+
 import org.openjump.core.model.TaskEvent;
 import org.openjump.core.model.TaskListener;
 import org.openjump.core.ui.plugin.file.FindFile;
@@ -29,6 +30,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,8 +224,29 @@
     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-bellow-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 {                              
+    try {                
     List<Category> categories = sourceLayerManager.getCategories();
     for (Category sourceLayerCategory : categories) {
       newLayerManager.addCategory(sourceLayerCategory.getName());
@@ -242,6 +266,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 +294,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 +354,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

Reply via email to