Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 3181 invoked from network); 12 Jan 2011 16:37:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 12 Jan 2011 16:37:50 -0000 Received: (qmail 76796 invoked by uid 500); 12 Jan 2011 16:37:50 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 76738 invoked by uid 500); 12 Jan 2011 16:37:48 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 76731 invoked by uid 99); 12 Jan 2011 16:37:48 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Jan 2011 16:37:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Jan 2011 16:37:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 05F5C23889D5; Wed, 12 Jan 2011 16:37:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1058223 - in /directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2: actions/ editor/ jobs/ Date: Wed, 12 Jan 2011 16:37:15 -0000 To: commits@directory.apache.org From: pamarcelot@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110112163716.05F5C23889D5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pamarcelot Date: Wed Jan 12 16:37:15 2011 New Revision: 1058223 URL: http://svn.apache.org/viewvc?rev=1058223&view=rev Log: Added implementation for the 'Export Configuration' action. "Save as" code is now shared between this action and the editor. Added: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorUtils.java Removed: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/actions/EditorAddPageAction.java 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/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/ServerConfigurationEditorPage.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/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=1058223&r1=1058222&r2=1058223&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 Wed Jan 12 16:37:15 2011 @@ -21,10 +21,17 @@ package org.apache.directory.studio.apacheds.configuration.v2.actions; +import java.lang.reflect.InvocationTargetException; + import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPlugin; import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPluginConstants; +import org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationEditor; +import org.apache.directory.studio.apacheds.configuration.v2.editor.ServerConfigurationEditorUtils; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.action.Action; +import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IEditorInput; /** @@ -34,6 +41,22 @@ import org.eclipse.jface.resource.ImageD */ public class EditorExportConfigurationAction extends Action { + /** The associated editor */ + private ServerConfigurationEditor editor; + + + /** + * Creates a new instance of EditorExportConfigurationAction. + * + * @param editor + * the associated editor + */ + public EditorExportConfigurationAction( ServerConfigurationEditor editor ) + { + this.editor = editor; + } + + /** * {@inheritDoc} */ @@ -58,5 +81,31 @@ public class EditorExportConfigurationAc */ public void run() { + try + { + editor.getSite().getWorkbenchWindow().run( false, false, new IRunnableWithProgress() + { + public void run( IProgressMonitor monitor ) throws InvocationTargetException, InterruptedException + { + try + { + // Saving the configuration as a new file and getting the associated new editor input + IEditorInput newInput = ServerConfigurationEditorUtils.doSaveAs( monitor, editor.getSite() + .getShell(), + editor.getEditorInput(), editor.getConfigWriter() ); + } + catch ( Exception e ) + { + // TODO handle the exception + } + } + } ); + } + catch ( Exception e ) + { + // TODO handle the exception + e.printStackTrace(); + } + } } 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=1058223&r1=1058222&r2=1058223&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 12 16:37:15 2011 @@ -21,10 +21,13 @@ package org.apache.directory.studio.apacheds.configuration.v2.actions; +import java.util.jar.JarFile; + import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPlugin; import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPluginConstants; import org.eclipse.jface.action.Action; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.dialogs.SaveAsDialog; /** @@ -58,5 +61,6 @@ public class EditorImportConfigurationAc */ public void run() { + } } 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=1058223&r1=1058222&r2=1058223&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 12 16:37:15 2011 @@ -38,28 +38,15 @@ import org.apache.directory.studio.apach import org.apache.directory.studio.common.core.jobs.StudioJob; import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress; -import org.apache.directory.studio.common.ui.CommonUIUtils; -import org.apache.directory.studio.common.ui.filesystem.PathEditorInput; import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; import org.apache.directory.studio.ldapbrowser.core.jobs.ExecuteLdifRunnable; import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IPathEditorInput; import org.eclipse.ui.PartInitException; -import org.eclipse.ui.dialogs.SaveAsDialog; import org.eclipse.ui.forms.editor.FormEditor; import org.eclipse.ui.part.FileEditorInput; @@ -89,6 +76,14 @@ public class ServerConfigurationEditor e super.init( site, input ); setPartName( input.getName() ); + // Checking if the input is a new server configuration file + if ( input instanceof NewServerConfigurationInput ) + { + // New server configuration file have a dirty state + // set to true since they are not saved yet + setDirty( true ); + } + readConfiguration(); } @@ -317,10 +312,8 @@ public class ServerConfigurationEditor e { try { - monitor - .beginTask( "Saving Server Configuration", IProgressMonitor.UNKNOWN ); - boolean success = doSaveAs( monitor ); - setDirty( !success ); + monitor.beginTask( "Saving Server Configuration", IProgressMonitor.UNKNOWN ); + doSaveAs( monitor ); monitor.done(); } catch ( Exception e ) @@ -347,124 +340,25 @@ public class ServerConfigurationEditor e */ private boolean doSaveAs( IProgressMonitor monitor ) throws Exception { - // detect IDE or RCP: - // check if perspective org.eclipse.ui.resourcePerspective is available - boolean isIDE = CommonUIUtils.isIDEEnvironment(); - - if ( isIDE ) - { - // Asking the user for the location where to 'save as' the file - SaveAsDialog dialog = new SaveAsDialog( getSite().getShell() ); - - IEditorInput input = getEditorInput(); - String inputClassName = input.getClass().getName(); - if ( input instanceof FileEditorInput ) - // FileEditorInput class is used when the file is opened - // from a project in the workspace. - { - dialog.setOriginalFile( ( ( FileEditorInput ) input ).getFile() ); - } - else if ( input instanceof IPathEditorInput ) - { - dialog.setOriginalFile( ResourcesPlugin.getWorkspace().getRoot() - .getFile( ( ( IPathEditorInput ) input ).getPath() ) ); - } - 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 - { - dialog.setOriginalFile( ResourcesPlugin.getWorkspace().getRoot() - .getFile( new Path( input.getToolTipText() ) ) ); - } - else - { - dialog.setOriginalName( "config.ldif" ); - } - - if ( dialog.open() != Dialog.OK ) - { - return false; - } - - // Getting if the resulting file - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile( dialog.getResult() ); - - // Creating the file if it does not exist - if ( !file.exists() ) - { - file.create( new ByteArrayInputStream( "".getBytes() ), true, null ); //$NON-NLS-1$ - } - - // Creating the new input for the editor - FileEditorInput fei = new FileEditorInput( file ); - - // Saving the file to disk - saveConfiguration( fei, monitor ); - - // Setting the new input to the editor - setInput( fei ); - } - else + // Saving the configuration as a new file and getting the associated new editor input + IEditorInput newInput = ServerConfigurationEditorUtils.doSaveAs( monitor, getSite().getShell(), + getEditorInput(), getConfigWriter() ); + + // Checking if the 'save as' is successful + boolean success = newInput != null; + if ( success ) { - Shell shell = getSite().getShell(); - boolean canOverwrite = false; - String path = null; - - while ( !canOverwrite ) - { - // Open FileDialog - FileDialog dialog = new FileDialog( shell, SWT.SAVE ); - path = dialog.open(); - if ( path == null ) - { - return false; - } - - // Check whether file exists and if so, confirm overwrite - final File externalFile = new File( path ); - if ( externalFile.exists() ) - { - String question = NLS.bind( - "The file \"{0}\" already exists. Do you want to replace the existing file?", path ); //$NON-NLS-1$ - 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(); - switch ( overwrite ) - { - case 0: // Yes - canOverwrite = true; - break; - case 1: // No - break; - case 2: // Cancel - default: - return false; - } - } - else - { - canOverwrite = true; - } - } - - // Saving the file to disk - saveConfiguration( path ); - - // Creating the new input for the editor - PathEditorInput newInput = new PathEditorInput( new Path( path ) ); - // Setting the new input to the editor setInput( newInput ); - } - // Updating the title and tooltip texts - setPartName( getEditorInput().getName() ); + // Resetting the dirty state of the editor + setDirty( false ); - return true; + // Updating the title and tooltip texts + setPartName( getEditorInput().getName() ); + } + + return success; } @@ -572,7 +466,7 @@ public class ServerConfigurationEditor e * the configuration writer * @throws Exception */ - private ConfigWriter getConfigWriter() throws Exception + public ConfigWriter getConfigWriter() throws Exception { return new ConfigWriter( ApacheDS2ConfigurationPlugin.getDefault().getSchemaManager(), configBean ); } Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorPage.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/ServerConfigurationEditorPage.java?rev=1058223&r1=1058222&r2=1058223&view=diff ============================================================================== --- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorPage.java (original) +++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorPage.java Wed Jan 12 16:37:15 2011 @@ -22,7 +22,6 @@ package org.apache.directory.studio.apac import org.apache.directory.server.config.beans.ConfigBean; import org.apache.directory.server.config.beans.DirectoryServiceBean; -import org.apache.directory.studio.apacheds.configuration.v2.actions.EditorAddPageAction; import org.apache.directory.studio.apacheds.configuration.v2.actions.EditorExportConfigurationAction; import org.apache.directory.studio.apacheds.configuration.v2.actions.EditorImportConfigurationAction; import org.eclipse.jface.action.IToolBarManager; @@ -166,16 +165,22 @@ public abstract class ServerConfiguratio IToolBarManager toolbarManager = form.getToolBarManager(); toolbarManager.add( new EditorImportConfigurationAction() ); toolbarManager.add( new Separator() ); - toolbarManager.add( new EditorExportConfigurationAction() ); - toolbarManager.add( new Separator() ); - toolbarManager.add( new EditorAddPageAction( ( ServerConfigurationEditor ) getEditor() ) ); - + toolbarManager.add( new EditorExportConfigurationAction( ( ServerConfigurationEditor ) getEditor() ) ); + toolbarManager.update( true ); createFormContent( parent, toolkit ); } + /** + * Subclasses must implement this method to create the content of their form. + * + * @param parent + * the parent element + * @param toolkit + * the form toolkit + */ protected abstract void createFormContent( Composite parent, FormToolkit toolkit ); Added: 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=1058223&view=auto ============================================================================== --- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorUtils.java (added) +++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ServerConfigurationEditorUtils.java Wed Jan 12 16:37:15 2011 @@ -0,0 +1,320 @@ +/* + * 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.editor; + + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.util.List; + +import org.apache.directory.server.config.ConfigWriter; +import org.apache.directory.server.config.ConfigurationException; +import org.apache.directory.shared.ldap.entry.DefaultEntry; +import org.apache.directory.shared.ldap.ldif.LdifEntry; +import org.apache.directory.shared.ldap.schema.SchemaManager; +import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPlugin; +import org.apache.directory.studio.apacheds.configuration.v2.jobs.EntryBasedConfigurationPartition; +import org.apache.directory.studio.apacheds.configuration.v2.jobs.PartitionsDiffComputer; +import org.apache.directory.studio.common.core.jobs.StudioProgressMonitor; +import org.apache.directory.studio.common.ui.CommonUIUtils; +import org.apache.directory.studio.common.ui.filesystem.PathEditorInput; +import org.apache.directory.studio.ldapbrowser.core.BrowserCorePlugin; +import org.apache.directory.studio.ldapbrowser.core.jobs.ExecuteLdifRunnable; +import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IPathEditorInput; +import org.eclipse.ui.dialogs.SaveAsDialog; +import org.eclipse.ui.part.FileEditorInput; + + +/** + * This class contains helpful methods for the Server Configuration Editor. + * + * @author Apache Directory Project + */ +public class ServerConfigurationEditorUtils +{ + /** + * Performs the "Save as..." action. + * + * @param monitor + * the monitor to use + * @throws Exception + */ + /** + * TODO doSaveAs. + * + * @param monitor + * @param shell + * @param input + * @param configWriter + * @return + * @throws Exception + */ + public static IEditorInput doSaveAs( IProgressMonitor monitor, Shell shell, IEditorInput input, + ConfigWriter configWriter ) + throws Exception + { + // detect IDE or RCP: + // check if perspective org.eclipse.ui.resourcePerspective is available + boolean isIDE = CommonUIUtils.isIDEEnvironment(); + + if ( isIDE ) + { + // Asking the user for the location where to 'save as' the file + SaveAsDialog dialog = new SaveAsDialog( shell ); + + String inputClassName = input.getClass().getName(); + if ( input instanceof FileEditorInput ) + // FileEditorInput class is used when the file is opened + // from a project in the workspace. + { + dialog.setOriginalFile( ( ( FileEditorInput ) input ).getFile() ); + } + else if ( input instanceof IPathEditorInput ) + { + dialog.setOriginalFile( ResourcesPlugin.getWorkspace().getRoot() + .getFile( ( ( IPathEditorInput ) input ).getPath() ) ); + } + 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 + { + dialog.setOriginalFile( ResourcesPlugin.getWorkspace().getRoot() + .getFile( new Path( input.getToolTipText() ) ) ); + } + else + { + dialog.setOriginalName( "config.ldif" ); + } + + if ( dialog.open() != Dialog.OK ) + { + return null; + } + + // Getting if the resulting file + IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile( dialog.getResult() ); + + // Creating the file if it does not exist + if ( !file.exists() ) + { + file.create( new ByteArrayInputStream( "".getBytes() ), true, null ); //$NON-NLS-1$ + } + + // Creating the new input for the editor + FileEditorInput fei = new FileEditorInput( file ); + + // Saving the file to disk + saveConfiguration( fei, configWriter, monitor ); + + return fei; + } + else + { + boolean canOverwrite = false; + String path = null; + + while ( !canOverwrite ) + { + // Open FileDialog + FileDialog dialog = new FileDialog( shell, SWT.SAVE ); + path = dialog.open(); + if ( path == null ) + { + return null; + } + + // Check whether file exists and if so, confirm overwrite + final File externalFile = new File( path ); + if ( externalFile.exists() ) + { + String question = NLS.bind( + "The file \"{0}\" already exists. Do you want to replace the existing file?", path ); //$NON-NLS-1$ + 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(); + switch ( overwrite ) + { + case 0: // Yes + canOverwrite = true; + break; + case 1: // No + break; + case 2: // Cancel + default: + return null; + } + } + else + { + canOverwrite = true; + } + } + + // Saving the file to disk + saveConfiguration( path, configWriter ); + + // Creating the new input for the editor + PathEditorInput newInput = new PathEditorInput( new Path( path ) ); + + return newInput; + } + } + + + /** + * Saves the configuration. + * + * @param input + * the file editor input + * @param configWriter + * the configuration writer + * @param monitor + * the monitor + * @throws Exception + */ + public static void saveConfiguration( FileEditorInput input, ConfigWriter configWriter, IProgressMonitor monitor ) + throws Exception + { + input.getFile().setContents( new ByteArrayInputStream( configWriter.writeToString().getBytes() ), true, + true, monitor ); + } + + + /** + * Saves the configuration. + * + * @param input + * the connection server configuration input + * @param configWriter + * the configuration writer + * @param monitor + * the monitor + * @return + * true if the operation is successful, + * false if not + * @throws ConfigurationException + * @throws Exception + */ + public static void saveConfiguration( ConnectionServerConfigurationInput input, ConfigWriter configWriter, + IProgressMonitor monitor ) + throws ConfigurationException, Exception + { + // Getting the original configuration partition + EntryBasedConfigurationPartition originalPartition = input.getOriginalPartition(); + + // Creating a new configuration partition + SchemaManager schemaManager = ApacheDS2ConfigurationPlugin.getDefault().getSchemaManager(); + EntryBasedConfigurationPartition newconfigurationPartition = new EntryBasedConfigurationPartition( + schemaManager ); + newconfigurationPartition.initialize(); + List convertedLdifEntries = configWriter.getConvertedLdifEntries(); + for ( LdifEntry ldifEntry : convertedLdifEntries ) + { + newconfigurationPartition.addEntry( new DefaultEntry( schemaManager, ldifEntry.getEntry() ) ); + } + + // Comparing both partitions to get the list of modifications to be applied + PartitionsDiffComputer partitionsDiffComputer = new PartitionsDiffComputer(); + partitionsDiffComputer.setOriginalPartition( originalPartition ); + partitionsDiffComputer.setDestinationPartition( newconfigurationPartition ); + List modificationsList = partitionsDiffComputer.computeModifications( new String[] + { "*" } ); + + System.out.println( modificationsList ); + + // Building the resulting LDIF + StringBuilder modificationsLdif = new StringBuilder(); + for ( LdifEntry ldifEntry : modificationsList ) + { + modificationsLdif.append( ldifEntry.toString() ); + } + + // Getting the browser connection associated with the + IBrowserConnection browserConnection = BrowserCorePlugin.getDefault().getConnectionManager() + .getBrowserConnection( input.getConnection() ); + + // Creating a StudioProgressMonitor to run the LDIF with + StudioProgressMonitor studioProgressMonitor = new StudioProgressMonitor( monitor ); + + // Updating the configuration with the resulting LDIF + ExecuteLdifRunnable.executeLdif( browserConnection, modificationsLdif.toString(), true, true, + studioProgressMonitor ); + + // Checking if there were errors during the execution of the LDIF + if ( studioProgressMonitor.errorsReported() ) + { + // TODO handle error + } + else + { + System.out.println( "swapping partition" ); + + // Swapping the new configuration partition + input.setOriginalPartition( newconfigurationPartition ); + } + } + + + /** + * Saves the configuration. + * + * @param file + * the file + * @param configWriter + * the configuration writer + * @throws Exception + */ + public static void saveConfiguration( File file, ConfigWriter configWriter ) throws Exception + { + configWriter.writeToFile( file ); + } + + + /** + * Saves the configuration. + * + * @param path + * the path + * @param configWriter + * the configuration writer + * @throws Exception + */ + public static void saveConfiguration( String path, ConfigWriter configWriter ) throws Exception + { + saveConfiguration( new File( path ), configWriter ); + } +} 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=1058223&r1=1058222&r2=1058223&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 12 16:37:15 2011 @@ -124,13 +124,14 @@ public class LoadConfigurationRunnable i if ( configBean != null ) { final ConfigBean finalConfigBean = configBean; + final IEditorInput finalInput = input; Display.getDefault().asyncExec( new Runnable() { public void run() - { - editor.configurationLoaded( finalConfigBean ); - } + { + editor.configurationLoaded( finalConfigBean ); + } } ); } }