directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1049152 - in /directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2: editor/ServerConfigurationEditor.java jobs/LoadConfigurationRunnable.java
Date Tue, 14 Dec 2010 16:40:17 GMT
Author: pamarcelot
Date: Tue Dec 14 16:40:17 2010
New Revision: 1049152

URL: http://svn.apache.org/viewvc?rev=1049152&view=rev
Log:
Added support for other types of editor input.

Modified:
    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/jobs/LoadConfigurationRunnable.java

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=1049152&r1=1049151&r2=1049152&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
Tue Dec 14 16:40:17 2010
@@ -91,8 +91,6 @@ public class ServerConfigurationEditor e
      */
     private void readConfiguration()
     {
-        IEditorInput input = getEditorInput();
-
         // Creating and scheduling the job to load the configuration
         StudioJob<StudioRunnableWithProgress> job = new StudioJob<StudioRunnableWithProgress>(
             new LoadConfigurationRunnable( this ) );

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=1049152&r1=1049151&r2=1049152&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
Tue Dec 14 16:40:17 2010
@@ -21,21 +21,26 @@
 package org.apache.directory.studio.apacheds.configuration.v2.jobs;
 
 
-import java.util.List;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
 
 import org.apache.directory.server.config.ConfigPartitionReader;
 import org.apache.directory.server.config.ReadOnlyConfigurationPartition;
 import org.apache.directory.server.config.beans.ConfigBean;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
-import org.apache.directory.shared.ldap.util.LdapExceptionUtils;
 import org.apache.directory.studio.apacheds.configuration.v2.ApacheDS2ConfigurationPlugin;
 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.common.core.jobs.StudioProgressMonitor;
 import org.apache.directory.studio.common.core.jobs.StudioRunnableWithProgress;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPathEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
 
 
 /**
@@ -99,13 +104,7 @@ public class LoadConfigurationRunnable i
         ConfigBean configBean = null;
         try
         {
-            // If the input is a NewServerConfigurationInput, then we only 
-            // need to get the server configuration and return
-            if ( input instanceof NewServerConfigurationInput )
-            {
-                configBean = getNewDefaultConfiguration();
-            }
-
+            configBean = getConfiguration( input );
             if ( configBean != null )
             {
                 final ConfigBean finalConfigBean = configBean;
@@ -134,39 +133,69 @@ public class LoadConfigurationRunnable i
      *      a new default configuration
      * @throws Exception
      */
-    public ConfigBean getNewDefaultConfiguration() throws Exception
+    public ConfigBean getConfiguration( IEditorInput input ) throws Exception
     {
-        long t1 = System.currentTimeMillis();
-
+        // Getting the schema manager
         SchemaManager schemaManager = ApacheDS2ConfigurationPlugin.getDefault().getSchemaManager();
 
-        long t2 = System.currentTimeMillis();
-
-        System.out.println( "Time = " + ( t2 - t1 ) + "ms" );
-
-        List<Throwable> errors = schemaManager.getErrors();
-
-        if ( errors.size() != 0 )
+        // Getting an input stream to the configuration
+        InputStream is = getInputStream( input );
+        if ( is != null )
         {
-            throw new Exception( "Schema load failed : " + LdapExceptionUtils.printErrors(
errors ) );
+            // Creating a partition associated from the input stream
+            ReadOnlyConfigurationPartition configurationPartition = new ReadOnlyConfigurationPartition(
+                ApacheDS2ConfigurationPlugin.class.getResourceAsStream( "config.ldif" ),
schemaManager );
+            configurationPartition.initialize();
+
+            // Reading the configuration partition
+            ConfigPartitionReader cpReader = new ConfigPartitionReader( configurationPartition
);
+            return cpReader.readConfig();
         }
 
-        ReadOnlyConfigurationPartition configurationPartition = new ReadOnlyConfigurationPartition(
-            ApacheDS2ConfigurationPlugin.class.getResourceAsStream( "config.ldif" ), schemaManager
);
-        configurationPartition.initialize();
-
-        ConfigPartitionReader cpReader = new ConfigPartitionReader( configurationPartition
);
-
-        t1 = System.currentTimeMillis();
-
-        ConfigBean configBean = cpReader.readConfig();
-
-        t2 = System.currentTimeMillis();
+        return null;
+    }
 
-        System.out.println( "Time = " + ( t2 - t1 ) + "ms" );
 
-        //            System.out.println( configBean );
+    /**
+     * Gets an input stream from the editor input.
+     *
+     * @param input
+     *      the editor input
+     * @return
+     *      an input stream from the editor input, or <code>null</code>
+     * @throws CoreException
+     * @throws FileNotFoundException
+     */
+    private InputStream getInputStream( IEditorInput input ) throws CoreException, FileNotFoundException
+    {
+        String inputClassName = input.getClass().getName();
+        // If the input is a NewServerConfigurationInput, then we only 
+        // need to get the server configuration and return
+        if ( input instanceof NewServerConfigurationInput )
+        {
+            return ApacheDS2ConfigurationPlugin.class.getResourceAsStream( "config.ldif"
);
+        }
+        else if ( input instanceof FileEditorInput )
+        // The 'FileEditorInput' class is used when the file is opened
+        // from a project in the workspace.
+        {
+            return ( ( FileEditorInput ) input ).getFile().getContents();
+        }
+        else if ( input instanceof IPathEditorInput )
+        {
+            return new FileInputStream( new File( ( ( IPathEditorInput ) input ).getPath().toOSString()
) );
+        }
+        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
+        {
+            // We use the tooltip to get the full path of the file
+            return new FileInputStream( new File( input.getToolTipText() ) );
+        }
 
-        return configBean;
+        return null;
     }
 }



Mime
View raw message