directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1061349 - in /directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2: actions/ editor/
Date Thu, 20 Jan 2011 15:41:35 GMT
Author: pamarcelot
Date: Thu Jan 20 15:41:34 2011
New Revision: 1061349

URL: http://svn.apache.org/viewvc?rev=1061349&view=rev
Log:
- Fixed a bug in the case of "saving as..." a new configuration file (UI thread issue).
- Renamed a method.

Modified:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorExportConfigurationAction.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

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorExportConfigurationAction.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/EditorExportConfigurationAction.java?rev=1061349&r1=1061348&r2=1061349&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorExportConfigurationAction.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorExportConfigurationAction.java
Thu Jan 20 15:41:34 2011
@@ -88,7 +88,7 @@ public class EditorExportConfigurationAc
                 {
                     try
                     {
-                        ServerConfigurationEditorUtils.doSaveAs( monitor, editor.getSite()
+                        ServerConfigurationEditorUtils.saveAs( monitor, editor.getSite()
                             .getShell(), editor.getEditorInput(), editor.getConfigWriter()
);
                     }
                     catch ( Exception e )

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=1061349&r1=1061348&r2=1061349&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
Thu Jan 20 15:41:34 2011
@@ -193,7 +193,7 @@ public class ServerConfigurationEditor e
     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(),
+        IEditorInput newInput = ServerConfigurationEditorUtils.saveAs( monitor, getSite().getShell(),
             getEditorInput(), getConfigWriter() );
 
         // Checking if the 'save as' is successful 

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=1061349&r1=1061348&r2=1061349&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
Thu Jan 20 15:41:34 2011
@@ -48,6 +48,7 @@ import org.eclipse.jface.dialogs.IDialog
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorInput;
@@ -78,7 +79,7 @@ public class ServerConfigurationEditorUt
      *      the new input for the editor
      * @throws Exception
      */
-    public static IEditorInput doSaveAs( IProgressMonitor monitor, Shell shell, IEditorInput
input,
+    public static IEditorInput saveAs( IProgressMonitor monitor, Shell shell, IEditorInput
input,
         ConfigWriter configWriter )
         throws Exception
     {
@@ -89,7 +90,7 @@ public class ServerConfigurationEditorUt
         if ( isIDE )
         {
             // Asking the user for the location where to 'save as' the file
-            SaveAsDialog dialog = new SaveAsDialog( shell );
+            final SaveAsDialog dialog = new SaveAsDialog( shell );
 
             String inputClassName = input.getClass().getName();
             if ( input instanceof FileEditorInput )
@@ -118,7 +119,8 @@ public class ServerConfigurationEditorUt
                 dialog.setOriginalName( "config.ldif" );
             }
 
-            if ( dialog.open() != Dialog.OK )
+            // Open the dialog
+            if ( openDialogInUIThread( dialog ) != Dialog.OK )
             {
                 return null;
             }
@@ -148,8 +150,8 @@ public class ServerConfigurationEditorUt
             while ( !canOverwrite )
             {
                 // Open FileDialog
-                FileDialog dialog = new FileDialog( shell, SWT.SAVE );
-                path = dialog.open();
+                final FileDialog dialog = new FileDialog( shell, SWT.SAVE );
+                path = openFileDialogInUIThread( dialog );
                 if ( path == null )
                 {
                     return null;
@@ -164,7 +166,7 @@ public class ServerConfigurationEditorUt
                     MessageDialog overwriteDialog = new MessageDialog( shell, "Question",
null, question, //$NON-NLS-1$
                         MessageDialog.QUESTION, new String[]
                             { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL
}, 0 );
-                    int overwrite = overwriteDialog.open();
+                    int overwrite = openDialogInUIThread( overwriteDialog );
                     switch ( overwrite )
                     {
                         case 0: // Yes
@@ -195,6 +197,94 @@ public class ServerConfigurationEditorUt
 
 
     /**
+     * Opens a {@link Dialog} in the UI thread.
+     *
+     * @param dialog
+     *      the dialog
+     * @return
+     *      the result of the dialog
+     */
+    private static int openDialogInUIThread( final Dialog dialog )
+    {
+        // Defining our own encapsulating class for the result
+        class DialogResult
+        {
+            private int result;
+
+
+            public int getResult()
+            {
+                return result;
+            }
+
+
+            public void setResult( int result )
+            {
+                this.result = result;
+            }
+        }
+
+        // Creating an object to hold the result
+        final DialogResult result = new DialogResult();
+
+        // Opening the dialog in the UI thread
+        Display.getDefault().syncExec( new Runnable()
+        {
+            public void run()
+            {
+                result.setResult( dialog.open() );
+            }
+        } );
+
+        return result.getResult();
+    }
+
+
+    /**
+     * Opens a {@link FileDialog} in the UI thread.
+     *
+     * @param dialog
+     *      the file dialog
+     * @return
+     *      the result of the dialog
+     */
+    private static String openFileDialogInUIThread( final FileDialog dialog )
+    {
+        // Defining our own encapsulating class for the result
+        class DialogResult
+        {
+            private String result;
+
+
+            public String getResult()
+            {
+                return result;
+            }
+
+
+            public void setResult( String result )
+            {
+                this.result = result;
+            }
+        }
+
+        // Creating an object to hold the result
+        final DialogResult result = new DialogResult();
+
+        // Opening the dialog in the UI thread
+        Display.getDefault().syncExec( new Runnable()
+        {
+            public void run()
+            {
+                result.setResult( dialog.open() );
+            }
+        } );
+
+        return result.getResult();
+    }
+
+
+    /**
      * Saves the configuration.
      *
      * @param input



Mime
View raw message