directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1060888 - in /directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2: actions/ editor/ jobs/
Date Wed, 19 Jan 2011 18:03:46 GMT
Author: pamarcelot
Date: Wed Jan 19 18:03:45 2011
New Revision: 1060888

URL: http://svn.apache.org/viewvc?rev=1060888&view=rev
Log:
Added a Runnable to save the configuration.
Fixed problems when the connection is no longer available when saving the modifications of
the configuration;

Added:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/SaveConfigurationRunnable.java
Modified:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorImportConfigurationAction.java
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditor.java
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorUtils.java
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorImportConfigurationAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorImportConfigurationAction.java?rev=1060888&r1=1060887&r2=1060888&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorImportConfigurationAction.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorImportConfigurationAction.java
Wed Jan 19 18:03:45 2011
@@ -55,6 +55,7 @@ import org.eclipse.ui.model.WorkbenchLab
 public class EditorImportConfigurationAction extends Action
 {
     private static final String DIALOG_TITLE = "Select Configuration File";
+
     /** The associated editor */
     private ServerConfigurationEditor editor;
 
@@ -184,7 +185,6 @@ public class EditorImportConfigurationAc
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
-
     }
 
 

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditor.java?rev=1060888&r1=1060887&r2=1060888&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditor.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditor.java
Wed Jan 19 18:03:45 2011
@@ -26,18 +26,18 @@ import org.apache.directory.server.confi
 import org.apache.directory.server.config.beans.ConfigBean;
 import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPlugin;
 import org.apache.directory.studio.apacheds.configuration.v2.jobs.LoadConfigurationRunnable;
+import org.apache.directory.studio.apacheds.configuration.v2.jobs.SaveConfigurationRunnable;
 import org.apache.directory.studio.common.core.jobs.StudioJob;
 import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.swt.custom.CTabFolder;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.IPathEditorInput;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.part.FileEditorInput;
 
 
 /**
@@ -145,69 +145,9 @@ public class ServerConfigurationEditor e
      */
     public void doSave( IProgressMonitor monitor )
     {
-        if ( dirty )
-        {
-            monitor.beginTask( "Saving the server configuration", IProgressMonitor.UNKNOWN
);
-
-            try
-            {
-                IEditorInput input = getEditorInput();
-                String inputClassName = input.getClass().getName();
-                boolean success = false;
-                if ( input instanceof FileEditorInput )
-                // FileEditorInput class is used when the file is opened
-                // from a project in the workspace.
-                {
-                    // Saving the ServerConfiguration to disk
-                    ServerConfigurationEditorUtils.saveConfiguration( ( FileEditorInput )
input, getConfigWriter(),
-                        monitor );
-                    success = true;
-                }
-                // If the input is a ConnectionServerConfigurationInput, then we 
-                // read the server configuration from the selected connection
-                if ( input instanceof ConnectionServerConfigurationInput )
-                {
-                    // Saving the ServerConfiguration to the connection
-                    ServerConfigurationEditorUtils.saveConfiguration( ( ConnectionServerConfigurationInput
) input,
-                        getConfigWriter(), monitor );
-                    success = true;
-                }
-                else if ( input instanceof IPathEditorInput )
-                {
-                    // Saving the ServerConfiguration to disk
-                    ServerConfigurationEditorUtils
-                        .saveConfiguration( ( ( IPathEditorInput ) input ).getPath().toFile(),
getConfigWriter() );
-                    success = true;
-                }
-                else if ( inputClassName.equals( "org.eclipse.ui.internal.editors.text.JavaFileEditorInput"
) //$NON-NLS-1$
-                    || inputClassName.equals( "org.eclipse.ui.ide.FileStoreEditorInput" )
) //$NON-NLS-1$
-                // The class 'org.eclipse.ui.internal.editors.text.JavaFileEditorInput'
-                // is used when opening a file from the menu File > Open... in Eclipse
3.2.x
-                // The class 'org.eclipse.ui.ide.FileStoreEditorInput' is used when
-                // opening a file from the menu File > Open... in Eclipse 3.3.x
-                {
-                    // Saving the ServerConfiguration to disk
-                    ServerConfigurationEditorUtils.saveConfiguration( input.getToolTipText(),
getConfigWriter() );
-                    success = true;
-                }
-                else if ( input instanceof NewServerConfigurationInput )
-                {
-                    // The 'ServerConfigurationEditorInput' class is used when a
-                    // new Server Configuration File is created.
-
-                    // We are saving this as if it is a "Save as..." action.
-                    success = doSaveAs( monitor );
-                }
-
-                setDirty( !success );
-                monitor.done();
-            }
-            catch ( Exception e )
-            {
-                // TODO
-                e.printStackTrace();
-            }
-        }
+        StudioJob<StudioRunnableWithProgress> job = new StudioJob<StudioRunnableWithProgress>(
+            new SaveConfigurationRunnable( this ) );
+        job.schedule();
     }
 
 
@@ -250,7 +190,7 @@ public class ServerConfigurationEditor e
      *      the monitor to use
      * @throws Exception
      */
-    private boolean doSaveAs( IProgressMonitor monitor ) throws Exception
+    public boolean doSaveAs( IProgressMonitor monitor ) throws Exception
     {
         // Saving the configuration as a new file and getting the associated new editor input
         IEditorInput newInput = ServerConfigurationEditorUtils.doSaveAs( monitor, getSite().getShell(),
@@ -301,7 +241,14 @@ public class ServerConfigurationEditor e
     public void setDirty( boolean dirty )
     {
         this.dirty = dirty;
-        firePropertyChange( PROP_DIRTY );
+
+        Display.getDefault().asyncExec( new Runnable()
+        {
+            public void run()
+            {
+                firePropertyChange( PROP_DIRTY );
+            }
+        } );
     }
 
 

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorUtils.java?rev=1060888&r1=1060887&r2=1060888&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorUtils.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorUtils.java
Wed Jan 19 18:03:45 2011
@@ -266,7 +266,7 @@ public class ServerConfigurationEditorUt
             .getBrowserConnection( input.getConnection() );
 
         // Creating a StudioProgressMonitor to run the LDIF with
-        StudioProgressMonitor studioProgressMonitor = new StudioProgressMonitor( monitor
);
+        StudioProgressMonitor studioProgressMonitor = new StudioProgressMonitor( new NullProgressMonitor()
);
 
         // Updating the configuration with the resulting LDIF
         ExecuteLdifRunnable.executeLdif( browserConnection, modificationsLdif.toString(),
true, true,
@@ -275,7 +275,7 @@ public class ServerConfigurationEditorUt
         // Checking if there were errors during the execution of the LDIF
         if ( studioProgressMonitor.errorsReported() )
         {
-            // TODO handle error
+            throw new Exception( "Changes could not be saved to the connection." );
         }
         else
         {

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java?rev=1060888&r1=1060887&r2=1060888&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/LoadConfigurationRunnable.java
Wed Jan 19 18:03:45 2011
@@ -37,6 +37,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.exception.LdapNoSuchObjectException;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
@@ -60,7 +61,7 @@ import org.eclipse.ui.part.FileEditorInp
 
 
 /**
- * This class implements a {@link Job} that is used to delete an LDAP Server.
+ * This class implements a {@link Job} that is used to load a server configuration.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
@@ -71,10 +72,10 @@ public class LoadConfigurationRunnable i
 
 
     /**
-     * Creates a new instance of StartLdapServerRunnable.
+     * Creates a new instance of LoadConfigurationRunnable.
      * 
-     * @param server
-     *            the LDAP Server
+     * @param editor
+     *            the editor
      */
     public LoadConfigurationRunnable( ServerConfigurationEditor editor )
     {
@@ -106,7 +107,7 @@ public class LoadConfigurationRunnable i
      */
     public String getName()
     {
-        return "Load configuration";
+        return "Load Configuration";
     }
 
 
@@ -135,7 +136,7 @@ public class LoadConfigurationRunnable i
         {
             // Reporting the error to the monitor
             monitor.reportError( e );
-            
+
             // Reporting the error to the editor
             final Exception exception = e;
             Display.getDefault().asyncExec( new Runnable()
@@ -310,7 +311,7 @@ public class LoadConfigurationRunnable i
             // Verifying we found the 'ou=config' base entry
             if ( configEntry == null )
             {
-                // TODO throw a new error
+                throw new LdapNoSuchObjectException( "Unable to find the 'ou=config' base
entry." );
             }
 
             // Creating a list to hold the entries that needs to be checked

Added: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/SaveConfigurationRunnable.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/SaveConfigurationRunnable.java?rev=1060888&view=auto
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/SaveConfigurationRunnable.java
(added)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/jobs/SaveConfigurationRunnable.java
Wed Jan 19 18:03:45 2011
@@ -0,0 +1,157 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.apacheds.configuration.v2.jobs;
+
+
+import org.apache.directory.studio.apacheds.configuration.v2.editor.ConnectionServerConfigurationInput;
+import org.apache.directory.studio.apacheds.configuration.v2.editor.NewServerConfigurationInput;
+import org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationEditor;
+import org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationEditorUtils;
+import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor;
+import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPathEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+
+
+/**
+ * This class implements a {@link Job} that is used to save a server configuration.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SaveConfigurationRunnable implements StudioRunnableWithProgress
+{
+    /** The associated editor */
+    private ServerConfigurationEditor editor;
+
+
+    /**
+     * Creates a new instance of SaveConfigurationRunnable.
+     * 
+     * @param editor
+     *            the editor
+     */
+    public SaveConfigurationRunnable( ServerConfigurationEditor editor )
+    {
+        super();
+        this.editor = editor;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getErrorMessage()
+    {
+        return "Unable to save the configuration.";
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Object[] getLockedObjects()
+    {
+        return new Object[0];
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getName()
+    {
+        return "Save Configuration";
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void run( StudioProgressMonitor monitor )
+    {
+        try
+        {
+            if ( editor.isDirty() )
+            {
+                monitor.beginTask( "Saving the server configuration", IProgressMonitor.UNKNOWN
);
+
+                IEditorInput input = editor.getEditorInput();
+                String inputClassName = input.getClass().getName();
+                boolean success = false;
+                if ( input instanceof FileEditorInput )
+                // FileEditorInput class is used when the file is opened
+                // from a project in the workspace.
+                {
+                    // Saving the ServerConfiguration to disk
+                    ServerConfigurationEditorUtils.saveConfiguration( ( FileEditorInput )
input,
+                        editor.getConfigWriter(),
+                        monitor );
+                    success = true;
+                }
+                // If the input is a ConnectionServerConfigurationInput, then we 
+                // read the server configuration from the selected connection
+                if ( input instanceof ConnectionServerConfigurationInput )
+                {
+                    // Saving the ServerConfiguration to the connection
+                    ServerConfigurationEditorUtils.saveConfiguration( ( ConnectionServerConfigurationInput
) input,
+                        editor.getConfigWriter(), monitor );
+                    success = true;
+                }
+                else if ( input instanceof IPathEditorInput )
+                {
+                    // Saving the ServerConfiguration to disk
+                    ServerConfigurationEditorUtils
+                        .saveConfiguration( ( ( IPathEditorInput ) input ).getPath().toFile(),
editor.getConfigWriter() );
+                    success = true;
+                }
+                else if ( inputClassName.equals( "org.eclipse.ui.internal.editors.text.JavaFileEditorInput"
) //$NON-NLS-1$
+                    || inputClassName.equals( "org.eclipse.ui.ide.FileStoreEditorInput" )
) //$NON-NLS-1$
+                // The class 'org.eclipse.ui.internal.editors.text.JavaFileEditorInput'
+                // is used when opening a file from the menu File > Open... in Eclipse
3.2.x
+                // The class 'org.eclipse.ui.ide.FileStoreEditorInput' is used when
+                // opening a file from the menu File > Open... in Eclipse 3.3.x
+                {
+                    // Saving the ServerConfiguration to disk
+                    ServerConfigurationEditorUtils.saveConfiguration( input.getToolTipText(),
editor.getConfigWriter() );
+                    success = true;
+                }
+                else if ( input instanceof NewServerConfigurationInput )
+                {
+                    // The 'ServerConfigurationEditorInput' class is used when a
+                    // new Server Configuration File is created.
+
+                    // We are saving this as if it is a "Save as..." action.
+                    success = editor.doSaveAs( monitor );
+                }
+
+                editor.setDirty( !success );
+            }
+        }
+        catch ( Exception e )
+        {
+            // Reporting the error to the monitor
+            monitor.reportError( e );
+        }
+    }
+}



Mime
View raw message