directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r556873 - in /directory/studio/trunk/studio-apacheds-schemaeditor: META-INF/ src/main/java/org/apache/directory/studio/apacheds/schemaeditor/ src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/
Date Tue, 17 Jul 2007 10:00:14 GMT
Author: pamarcelot
Date: Tue Jul 17 03:00:11 2007
New Revision: 556873

URL: http://svn.apache.org/viewvc?view=rev&rev=556873
Log:
Added Projects backup when starting up and shutting down the plugin.

Modified:
    directory/studio/trunk/studio-apacheds-schemaeditor/META-INF/MANIFEST.MF
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/Activator.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsImporter.java

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/META-INF/MANIFEST.MF?view=diff&rev=556873&r1=556872&r2=556873
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/META-INF/MANIFEST.MF (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/META-INF/MANIFEST.MF Tue Jul 17 03:00:11
2007
@@ -10,7 +10,8 @@
  org.apache.directory.studio.jars,
  org.eclipse.core.runtime,
  org.eclipse.ui.forms,
- org.eclipse.jface.text
+ org.eclipse.jface.text,
+ org.eclipse.core.runtime.compatibility
 Eclipse-LazyStart: true
 Bundle-ClassPath: .,
  lib/apacheds-core-plugin-1.5.0-SNAPSHOT.jar

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/Activator.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/Activator.java?view=diff&rev=556873&r1=556872&r2=556873
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/Activator.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/Activator.java
Tue Jul 17 03:00:11 2007
@@ -21,7 +21,9 @@
 
 
 import org.apache.directory.studio.apacheds.schemaeditor.controller.ProjectsHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.ProjectsHandlerListener;
 import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
 import org.apache.directory.studio.apacheds.schemaeditor.model.schemachecker.SchemaChecker;
 import org.apache.directory.studio.apacheds.schemaeditor.view.widget.SchemaCodeScanner;
 import org.apache.directory.studio.apacheds.schemaeditor.view.widget.SchemaTextAttributeProvider;
@@ -67,6 +69,30 @@
     {
         plugin = this;
         projectsHandler = ProjectsHandler.getInstance();
+        projectsHandler.addListener( new ProjectsHandlerListener()
+        {
+
+            public void openProjectChanged( Project oldProject, Project newProject )
+            {
+                // TODO Auto-generated method stub
+
+            }
+
+
+            public void projectAdded( Project project )
+            {
+                PluginUtils.saveProjects();
+
+            }
+
+
+            public void projectRemoved( Project project )
+            {
+                PluginUtils.saveProjects();
+
+            }
+
+        } );
 
         schemaHandler = SchemaHandler.getInstance();
         schemaChecker = new SchemaChecker();
@@ -81,9 +107,11 @@
     {
         super.start( context );
 
-        FakeLoader.loadSchemas(); // TODO Remove after testing
+        // Loading the projects
+        PluginUtils.loadProjects();
 
-        schemaChecker.enableModificationsListening();
+        //        FakeLoader.loadSchemas(); // TODO Remove after testing
+        //        schemaChecker.enableModificationsListening();
     }
 
 
@@ -93,7 +121,13 @@
      */
     public void stop( BundleContext context ) throws Exception
     {
+        System.out.println( "stop" );
+
+        // Saving the projects
+        PluginUtils.saveProjects();
+
         super.stop( context );
+        plugin = null;
     }
 
 

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java?view=diff&rev=556873&r1=556872&r2=556873
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java
Tue Jul 17 03:00:11 2007
@@ -20,8 +20,18 @@
 package org.apache.directory.studio.apacheds.schemaeditor;
 
 
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.directory.studio.apacheds.schemaeditor.controller.ProjectsHandler;
 import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl;
 import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.ProjectsExporter;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.ProjectsImportException;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.ProjectsImporter;
 
 
 /**
@@ -98,5 +108,68 @@
         clone.setMayNamesList( oc.getMayNamesList() );
 
         return clone;
+    }
+
+
+    /**
+     * Gets the Projects (where is store information about the loaded Projects).
+     *
+     * @return
+     *      the Projects File
+     */
+    private static File getProjectsFile()
+    {
+        return Activator.getDefault().getStateLocation().append( "projects.xml" ).toFile();
//$NON-NLS-1$
+    }
+
+
+    /**
+     * Loads the projects saved in the Projects File.
+     */
+    public static void loadProjects()
+    {
+        ProjectsHandler projectsHandler = Activator.getDefault().getProjectsHandler();
+        File projectsFile = getProjectsFile();
+
+        if ( projectsFile.exists() )
+        {
+            Project[] projects = null;
+            try
+            {
+                projects = ProjectsImporter.getProjects( projectsFile.getAbsolutePath() );
+            }
+            catch ( ProjectsImportException e )
+            {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+
+            for ( Project project : projects )
+            {
+                projectsHandler.addProject( project );
+            }
+        }
+    }
+
+
+    /**
+     * Saves the projects in the Projects File.
+     */
+    public static void saveProjects()
+    {
+        ProjectsHandler projectsHandler = Activator.getDefault().getProjectsHandler();
+        File projectsFile = getProjectsFile();
+
+        try
+        {
+            BufferedWriter buffWriter = new BufferedWriter( new FileWriter( projectsFile
) );
+            buffWriter.write( ProjectsExporter.toXml( projectsHandler.getProjects().toArray(
new Project[0] ) ) );
+            buffWriter.close();
+        }
+        catch ( IOException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
     }
 }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsImporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsImporter.java?view=diff&rev=556873&r1=556872&r2=556873
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsImporter.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsImporter.java
Tue Jul 17 03:00:11 2007
@@ -118,8 +118,9 @@
 
         for ( Iterator<?> i = rootElement.elementIterator( PROJECT_TAG ); i.hasNext();
)
         {
+            Element projectElement = ( Element ) i.next();
             Project project = new Project();
-            readProject( rootElement, project, path );
+            readProject( projectElement, project, path );
             projects.add( project );
         }
 



Mime
View raw message