directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r556649 - in /directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor: controller/ model/io/ view/wizards/
Date Mon, 16 Jul 2007 15:34:10 GMT
Author: pamarcelot
Date: Mon Jul 16 08:34:06 2007
New Revision: 556649

URL: http://svn.apache.org/viewvc?view=rev&rev=556649
Log:
Fixed a bug in the ProjectImporter class which caused the imported project to have a name
of 'name' instead of its real name.
Implemented the import and export actions in the corresponding wizards.

Modified:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsViewController.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsExporter.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsImporter.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportProjectsWizard.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportProjectsWizardPage.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportProjectsWizard.java

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsViewController.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsViewController.java?view=diff&rev=556649&r1=556648&r2=556649
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsViewController.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/ProjectsViewController.java
Mon Jul 16 08:34:06 2007
@@ -44,6 +44,7 @@
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.swt.events.KeyAdapter;
 import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IWorkbenchActionConstants;
 
 
@@ -181,17 +182,32 @@
         {
             public void projectAdded( Project project )
             {
-                view.getViewer().refresh();
+                refreshProjectsViewer();
             }
 
 
             public void projectRemoved( Project project )
             {
-                view.getViewer().refresh();
+                refreshProjectsViewer();
             }
 
 
             public void openProjectChanged( Project oldProject, Project newProject )
+            {
+                refreshProjectsViewer();
+            }
+        } );
+    }
+
+
+    /**
+     * Refreshes the Projects Viewer
+     */
+    public void refreshProjectsViewer()
+    {
+        Display.getDefault().asyncExec( new Runnable()
+        {
+            public void run()
             {
                 view.getViewer().refresh();
             }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsExporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsExporter.java?view=diff&rev=556649&r1=556648&r2=556649
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsExporter.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsExporter.java
Mon Jul 16 08:34:06 2007
@@ -61,7 +61,7 @@
      * @return
      *      the corresponding code representation
      */
-    public static String toSourceCode( Project project )
+    public static String toXml( Project project )
     {
         // Creating the Document
         Document document = DocumentHelper.createDocument();
@@ -82,7 +82,7 @@
      * @return
      *      the corresponding code representation
      */
-    public static String toSourceCode( Project[] projects )
+    public static String toXml( Project[] projects )
     {
         // Creating the Document
         Document document = DocumentHelper.createDocument();

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=556649&r1=556648&r2=556649
==============================================================================
--- 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
Mon Jul 16 08:34:06 2007
@@ -58,7 +58,7 @@
      * @throws ProjectsImportException 
      *      if an error occurs when importing the project
      */
-    public Project getProject( String path ) throws ProjectsImportException
+    public static Project getProject( String path ) throws ProjectsImportException
     {
         Project project = new Project();
 
@@ -95,7 +95,7 @@
      * @throws ProjectsImportException 
      *      if an error occurs when importing the project
      */
-    public Project[] getProjects( String path ) throws ProjectsImportException
+    public static Project[] getProjects( String path ) throws ProjectsImportException
     {
         List<Project> projects = new ArrayList<Project>();
 
@@ -139,13 +139,13 @@
      * @throws ProjectsImportException 
      *      if an error occurs when importing the project
      */
-    private void readProject( Element element, Project project, String path ) throws ProjectsImportException
+    private static void readProject( Element element, Project project, String path ) throws
ProjectsImportException
     {
         // Name
         Attribute nameAttribute = element.attribute( NAME_TAG );
         if ( ( nameAttribute != null ) && ( !nameAttribute.getValue().equals( ""
) ) )
         {
-            project.setName( nameAttribute.getName() );
+            project.setName( nameAttribute.getValue() );
         }
 
         // Type

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportProjectsWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportProjectsWizard.java?view=diff&rev=556649&r1=556648&r2=556649
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportProjectsWizard.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportProjectsWizard.java
Mon Jul 16 08:34:06 2007
@@ -20,6 +20,15 @@
 package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
 
 
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.ProjectsExporter;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.ui.IExportWizard;
@@ -56,6 +65,46 @@
      */
     public boolean performFinish()
     {
+        final Project[] selectedProjects = page.getSelectedProjects();
+
+        final String exportDirectory = page.getExportDirectory();
+        try
+        {
+            getContainer().run( true, true, new IRunnableWithProgress()
+            {
+                public void run( IProgressMonitor monitor )
+                {
+                    monitor.beginTask( "Exporting project: ", selectedProjects.length );
+                    for ( Project project : selectedProjects )
+                    {
+                        monitor.subTask( project.getName() );
+
+                        try
+                        {
+                            BufferedWriter buffWriter = new BufferedWriter( new FileWriter(
exportDirectory + "/"
+                                + project.getName() + ".schemaproject" ) );
+                            buffWriter.write( ProjectsExporter.toXml( project ) );
+                            buffWriter.close();
+                        }
+                        catch ( IOException e )
+                        {
+                            // TODO Auto-generated catch block
+                            e.printStackTrace();
+                        }
+                        monitor.worked( 1 );
+                    }
+                    monitor.done();
+                }
+            } );
+        }
+        catch ( InvocationTargetException e )
+        {
+            // Nothing to do (it will never occur)
+        }
+        catch ( InterruptedException e )
+        {
+            // Nothing to do.
+        }
 
         return true;
     }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportProjectsWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportProjectsWizardPage.java?view=diff&rev=556649&r1=556648&r2=556649
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportProjectsWizardPage.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportProjectsWizardPage.java
Mon Jul 16 08:34:06 2007
@@ -27,7 +27,7 @@
 import org.apache.directory.studio.apacheds.schemaeditor.Activator;
 import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants;
 import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
-import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Project.ProjectType;
 import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.CheckStateChangedEvent;
 import org.eclipse.jface.viewers.CheckboxTableViewer;
@@ -115,9 +115,9 @@
         {
             public String getText( Object element )
             {
-                if ( element instanceof Schema )
+                if ( element instanceof Project )
                 {
-                    return ( ( Schema ) element ).getName();
+                    return ( ( Project ) element ).getName();
                 }
 
                 // Default
@@ -127,10 +127,18 @@
 
             public Image getImage( Object element )
             {
-                if ( element instanceof Schema )
+                if ( element instanceof Project )
                 {
-                    return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
-                        PluginConstants.IMG_PROJECT_OFFLINE_CLOSED ).createImage();
+                    ProjectType type = ( ( Project ) element ).getType();
+                    switch ( type )
+                    {
+                        case OFFLINE:
+                            return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+                                PluginConstants.IMG_PROJECT_OFFLINE_CLOSED ).createImage();
+                        case APACHE_DIRECTORY_SERVER:
+                            return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+                                PluginConstants.IMG_PROJECT_ADS_CLOSED ).createImage();
+                    }
                 }
 
                 // Default
@@ -213,7 +221,7 @@
     private void initFields()
     {
         // Filling the Schemas table
-//        schemaProjectsTableViewer.setInput( schemaHandler.getSchemas() );
+        projectsTableViewer.setInput( Activator.getDefault().getProjectsHandler().getProjects()
);
 
         displayErrorMessage( null );
         setPageComplete( false );

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportProjectsWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportProjectsWizard.java?view=diff&rev=556649&r1=556648&r2=556649
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportProjectsWizard.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ImportProjectsWizard.java
Mon Jul 16 08:34:06 2007
@@ -20,6 +20,16 @@
 package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
 
 
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.ProjectsHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.ProjectsImportException;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.ProjectsImporter;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.ui.IImportWizard;
@@ -37,6 +47,9 @@
     // The pages of the wizard
     private ImportProjectsWizardPage page;
 
+    /** The ProjectsHandler */
+    private ProjectsHandler projectsHandler;
+
 
     /* (non-Javadoc)
      * @see org.eclipse.jface.wizard.Wizard#addPages()
@@ -56,7 +69,45 @@
      */
     public boolean performFinish()
     {
-        
+        final File[] selectedProjectFiles = page.getSelectedProjectFiles();
+
+        try
+        {
+            getContainer().run( true, false, new IRunnableWithProgress()
+            {
+                public void run( IProgressMonitor monitor )
+                {
+                    monitor.beginTask( "Importing projects: ", selectedProjectFiles.length
);
+
+                    for ( File projectFile : selectedProjectFiles )
+                    {
+                        monitor.subTask( projectFile.getName() );
+                        try
+                        {
+                            Project project = ProjectsImporter.getProject( projectFile.getAbsolutePath()
);
+                            projectsHandler.addProject( project );
+                        }
+                        catch ( ProjectsImportException e )
+                        {
+                            // TODO Auto-generated catch block
+                            e.printStackTrace();
+                        }
+                        monitor.worked( 1 );
+                    }
+
+                    monitor.done();
+                }
+            } );
+        }
+        catch ( InvocationTargetException e )
+        {
+            // Nothing to do (it will never occur)
+            e.printStackTrace();
+        }
+        catch ( InterruptedException e )
+        {
+            // Nothing to do.
+        }
 
         return true;
     }
@@ -67,5 +118,8 @@
      */
     public void init( IWorkbench workbench, IStructuredSelection selection )
     {
+        setNeedsProgressMonitor( true );
+
+        projectsHandler = Activator.getDefault().getProjectsHandler();
     }
 }



Mime
View raw message