directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r661600 - in /directory/studio/branches/apacheds-plugin-branch/apacheds: ./ src/main/java/org/apache/directory/studio/apacheds/ src/main/java/org/apache/directory/studio/apacheds/actions/ src/main/java/org/apache/directory/studio/apacheds/j...
Date Fri, 30 May 2008 08:58:17 GMT
Author: pamarcelot
Date: Fri May 30 01:58:16 2008
New Revision: 661600

URL: http://svn.apache.org/viewvc?rev=661600&view=rev
Log:
o Added a Server Logs preference page.
o Updated the run action and launch job to get the logs level and pattern from the preference
store.
o Updated the StudioConsoleAppender to get the logs pattern from the preference store and
dynamically update itself whenever it the value changes.

Added:
    directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/ServerLogsPage.java
Modified:
    directory/studio/branches/apacheds-plugin-branch/apacheds/plugin.xml
    directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPluginConstants.java
    directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPluginUtils.java
    directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/PreferenceInitializer.java
    directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/StudioConsoleAppender.java
    directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/actions/RunAction.java
    directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/jobs/LaunchServerJob.java
    directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/ColorsAndFontsPage.java
    directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/MainPage.java

Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/plugin.xml
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/plugin.xml?rev=661600&r1=661599&r2=661600&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/plugin.xml (original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/plugin.xml Fri May 30 01:58:16
2008
@@ -14,6 +14,12 @@
             name="Colors and Fonts"
             category="org.apache.directory.studio.apacheds.prefs.MainPage">
       </page>
+      <page
+            class="org.apache.directory.studio.apacheds.prefs.ServerLogsPage"
+            id="org.apache.directory.studio.apacheds.ServerLogsPage"
+            name="Server Logs"
+            category="org.apache.directory.studio.apacheds.prefs.MainPage">
+      </page>
    </extension>
    <extension
          point="org.eclipse.core.runtime.preferences">

Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPluginConstants.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPluginConstants.java?rev=661600&r1=661599&r2=661600&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPluginConstants.java
(original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPluginConstants.java
Fri May 30 01:58:16 2008
@@ -64,28 +64,44 @@
     // -----------
     // PREFERENCES
     // -----------
-    /** The Preference ID for the Debug Font setting */
+    /** The Preference ID for the Colors and Font Debug Font setting */
     public static final String PREFS_COLORS_AND_FONTS_DEBUG_FONT = "org.apache.directory.studio.apacheds.prefs.colorAndFonts.debugFont";
-    /** The Preference ID for the Debug Color setting */
+    /** The Preference ID for the Colors and Font Debug Color setting */
     public static final String PREFS_COLORS_AND_FONTS_DEBUG_COLOR = "org.apache.directory.studio.apacheds.prefs.colorAndFonts.debugColor";
 
-    /** The Preference ID for the Info Font setting */
+    /** The Preference ID for the Colors and Font Info Font setting */
     public static final String PREFS_COLORS_AND_FONTS_INFO_FONT = "org.apache.directory.studio.apacheds.prefs.colorAndFonts.infoFont";
-    /** The Preference ID for the Info Color setting */
+    /** The Preference ID for the Colors and Font Info Color setting */
     public static final String PREFS_COLORS_AND_FONTS_INFO_COLOR = "org.apache.directory.studio.apacheds.prefs.colorAndFonts.infoColor";
 
-    /** The Preference ID for the Warn Font setting */
+    /** The Preference ID for the Colors and Font Warn Font setting */
     public static final String PREFS_COLORS_AND_FONTS_WARN_FONT = "org.apache.directory.studio.apacheds.prefs.colorAndFonts.warnFont";
-    /** The Preference ID for the Warn Color setting */
+    /** The Preference ID for the Colors and Font Warn Color setting */
     public static final String PREFS_COLORS_AND_FONTS_WARN_COLOR = "org.apache.directory.studio.apacheds.prefs.colorAndFonts.warnColor";
 
-    /** The Preference ID for the Error Font settings */
+    /** The Preference ID for the Colors and Font Error Font settings */
     public static final String PREFS_COLORS_AND_FONTS_ERROR_FONT = "org.apache.directory.studio.apacheds.prefs.colorAndFonts.errorFont";
-    /** The Preference ID for the Error Color setting */
+    /** The Preference ID for the Colors and Font Error Color setting */
     public static final String PREFS_COLORS_AND_FONTS_ERROR_COLOR = "org.apache.directory.studio.apacheds.prefs.colorAndFonts.errorColor";
 
-    /** The Preference ID for the Fatal Font setting */
+    /** The Preference ID for the Colors and Font Fatal Font setting */
     public static final String PREFS_COLORS_AND_FONTS_FATAL_FONT = "org.apache.directory.studio.apacheds.prefs.colorAndFonts.fatalFont";
-    /** The Preference ID for the Fatal Color setting */
+    /** The Preference ID for the Colors and Font Fatal Color setting */
     public static final String PREFS_COLORS_AND_FONTS_FATAL_COLOR = "org.apache.directory.studio.apacheds.prefs.colorAndFonts.fatalColor";
+
+    /** The Preference ID for the Servers Logs Level setting */
+    public static final String PREFS_SERVER_LOGS_LEVEL = "org.apache.directory.studio.apacheds.prefs.serverLogs.level";
+    /** The Preference ID for the Servers Logs Level Info value */
+    public static final String PREFS_SERVER_LOGS_LEVEL_INFO = "info";
+    /** The Preference ID for the Servers Logs Level Debug value */
+    public static final String PREFS_SERVER_LOGS_LEVEL_DEBUG = "debug";
+    /** The Preference ID for the Servers Logs Level Warn value */
+    public static final String PREFS_SERVER_LOGS_LEVEL_WARN = "warning";
+    /** The Preference ID for the Servers Logs Level Error value */
+    public static final String PREFS_SERVER_LOGS_LEVEL_ERROR = "error";
+    /** The Preference ID for the Servers Logs Level Fatal value */
+    public static final String PREFS_SERVER_LOGS_LEVEL_FATAL = "fatal";
+
+    /** The Preference ID for the Servers Logs Pattern setting */
+    public static final String PREFS_SERVER_LOGS_PATTERN = "org.apache.directory.studio.apacheds.prefs.serverLogs.pattern";
 }

Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPluginUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPluginUtils.java?rev=661600&r1=661599&r2=661600&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPluginUtils.java
(original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPluginUtils.java
Fri May 30 01:58:16 2008
@@ -226,7 +226,7 @@
 
             // Creating log4j.properties file
             File log4jPropertiesFile = new File( confFolder, "log4j.properties" );
-            createServersLog4jPropertiesFile( new FileOutputStream( log4jPropertiesFile ),
1024 ); // Setting 1024 as default port
+            createServersLog4jPropertiesFile( new FileOutputStream( log4jPropertiesFile ),
1024, getServerLogsLevel() ); // Setting 1024 as default port
 
             // Copying server.xml file
             File serverXmlFile = new File( confFolder, "server.xml" );
@@ -251,10 +251,13 @@
      *      the {@link OutputStream} to write to
      * @param port
      *      the port
+     * @param logsLevel
+     *      the logs level
      * @throws IOException
      *      if an error occurs when writing to the file
      */
-    public static void createServersLog4jPropertiesFile( OutputStream os, int port ) throws
IOException
+    public static void createServersLog4jPropertiesFile( OutputStream os, int port, String
logsLevel )
+        throws IOException
     {
         // Creating the file content in a StringBuffer
         StringBuffer sb = new StringBuffer();
@@ -274,7 +277,7 @@
         sb.append( "#    See the License for the specific language governing permissions
and" ).append( "\n" );
         sb.append( "#    limitations under the License." ).append( "\n" );
         sb.append( "#############################################################################"
).append( "\n" );
-        sb.append( "log4j.rootCategory=WARN, socketAppender" ).append( "\n" );
+        sb.append( "log4j.rootCategory=" + logsLevel + ", socketAppender" ).append( "\n"
);
         sb.append( "" ).append( "\n" );
         sb.append( "log4j.appender.socketAppender=org.apache.log4j.net.SocketAppender" ).append(
"\n" );
         sb.append( "log4j.appender.socketAppender.RemoteHost=localhost" ).append( "\n" );
@@ -379,4 +382,52 @@
             apacheDsserversFolder.mkdir();
         }
     }
+
+
+    /**
+     * Gets the server logs level.
+     *
+     * @return
+     *      the server logs level
+     */
+    public static String getServerLogsLevel()
+    {
+        String level = ApacheDsPlugin.getDefault().getPreferenceStore().getString(
+            ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL );
+        if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_INFO.equalsIgnoreCase( level
) )
+        {
+            return "INFO";
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_DEBUG.equalsIgnoreCase(
level ) )
+        {
+            return "DEBUG";
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_WARN.equalsIgnoreCase(
level ) )
+        {
+            return "WARN";
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_ERROR.equalsIgnoreCase(
level ) )
+        {
+            return "ERROR";
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_FATAL.equalsIgnoreCase(
level ) )
+        {
+            return "FATAL";
+        }
+
+        return "";
+    }
+
+
+    /**
+     * Gets the server logs pattern.
+     *
+     * @return
+     *      the server logs pattern
+     */
+    public static String getServerLogsPattern()
+    {
+        return ApacheDsPlugin.getDefault().getPreferenceStore().getString(
+            ApacheDsPluginConstants.PREFS_SERVER_LOGS_PATTERN );
+    }
 }

Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/PreferenceInitializer.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/PreferenceInitializer.java?rev=661600&r1=661599&r2=661600&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/PreferenceInitializer.java
(original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/PreferenceInitializer.java
Fri May 30 01:58:16 2008
@@ -58,20 +58,28 @@
         RGB rgbRed = new RGB( 255, 0, 0 );
         RGB rgbDarkRed = new RGB( 127, 0, 0 );
 
-        // Debug
-        PreferenceConverter.setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_DEBUG_FONT,
fontDataItalic );
+        // Colors and Font Debug
+        PreferenceConverter.setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_DEBUG_FONT,
+            fontDataItalic );
         PreferenceConverter.setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_DEBUG_COLOR,
rgbBlue );
-        // Info
-        PreferenceConverter.setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_INFO_FONT,
fontDataItalic );
+        // Colors and Font Info
+        PreferenceConverter
+            .setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_INFO_FONT,
fontDataItalic );
         PreferenceConverter.setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_INFO_COLOR,
rgbGreen );
-        // Warn
-        PreferenceConverter.setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_WARN_FONT,
fontDataNormal );
+        // Colors and Font Warn
+        PreferenceConverter
+            .setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_WARN_FONT,
fontDataNormal );
         PreferenceConverter.setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_WARN_COLOR,
rgbOrange );
-        // Error
+        // Colors and Font Error
         PreferenceConverter.setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_ERROR_FONT,
fontDataBold );
         PreferenceConverter.setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_ERROR_COLOR,
rgbRed );
-        // Fatal
+        // Colors and Font Fatal
         PreferenceConverter.setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_FATAL_FONT,
fontDataBold );
         PreferenceConverter.setDefault( store, ApacheDsPluginConstants.PREFS_COLORS_AND_FONTS_FATAL_COLOR,
rgbDarkRed );
+
+        // Server Logs
+        store.setDefault( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL,
+            ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_WARN );
+        store.setDefault( ApacheDsPluginConstants.PREFS_SERVER_LOGS_PATTERN, "[%d{HH:mm:ss}]
%p [%c] - %m%n" );
     }
 }

Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/StudioConsoleAppender.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/StudioConsoleAppender.java?rev=661600&r1=661599&r2=661600&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/StudioConsoleAppender.java
(original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/StudioConsoleAppender.java
Fri May 30 01:58:16 2008
@@ -25,6 +25,9 @@
 import org.apache.log4j.Level;
 import org.apache.log4j.PatternLayout;
 import org.apache.log4j.spi.LoggingEvent;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.widgets.Display;
 
 
 /**
@@ -45,7 +48,31 @@
     public StudioConsoleAppender()
     {
         super();
-        setLayout( new PatternLayout( "[%d{HH:mm:ss}] %p [%c] - %m%n" ) );
+        // We need to set the layout asynchronously to avoid UI thread exception
+        Display.getDefault().asyncExec( new Runnable()
+        {
+            public void run()
+            {
+                setLayout( new PatternLayout( ApacheDsPluginUtils.getServerLogsPattern()
) );
+            }
+        } );
+        ApacheDsPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( new IPropertyChangeListener()
+        {
+            public void propertyChange( PropertyChangeEvent event )
+            {
+                if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_PATTERN.equalsIgnoreCase(
event.getProperty() ) )
+                {
+                    // We need to set the layout asynchronously to avoid UI thread exception
+                    Display.getDefault().asyncExec( new Runnable()
+                    {
+                        public void run()
+                        {
+                            setLayout( new PatternLayout( ApacheDsPluginUtils.getServerLogsPattern()
) );
+                        }
+                    } );
+                }
+            }
+        } );
     }
 
 
@@ -91,8 +118,7 @@
      */
     public void close()
     {
-        // TODO Auto-generated method stub
-
+        // Nothing to do
     }
 
 
@@ -101,7 +127,6 @@
      */
     public boolean requiresLayout()
     {
-        // TODO Auto-generated method stub
         return false;
     }
 

Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/actions/RunAction.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/actions/RunAction.java?rev=661600&r1=661599&r2=661600&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/actions/RunAction.java
(original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/actions/RunAction.java
Fri May 30 01:58:16 2008
@@ -93,8 +93,8 @@
             try
             {
                 serverConfiguration = ( ServerConfigurationV152 ) serverXmlIOV152.parse(
new FileInputStream( new File(
-                    ApacheDsPluginUtils.getApacheDsServersFolder().append( server.getId()
).append( "conf" )
-                        .append( "server.xml" ).toOSString() ) ) );
+                    ApacheDsPluginUtils.getApacheDsServersFolder().append( server.getId()
).append( "conf" ).append(
+                        "server.xml" ).toOSString() ) ) );
             }
             catch ( FileNotFoundException e )
             {
@@ -153,6 +153,7 @@
 
             // Creating, setting and launching the launch job
             LaunchServerJob job = new LaunchServerJob( server, serverConfiguration );
+            job.setLogsLevel( ApacheDsPluginUtils.getServerLogsLevel() );
             server.setLaunchJob( job );
             job.schedule();
         }

Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/jobs/LaunchServerJob.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/jobs/LaunchServerJob.java?rev=661600&r1=661599&r2=661600&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/jobs/LaunchServerJob.java
(original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/jobs/LaunchServerJob.java
Fri May 30 01:58:16 2008
@@ -83,6 +83,9 @@
     /** The minimum port number for the socket server */
     private static final int MIN_PORT = 1024;
 
+    /** The log level */
+    private String logsLevel = "WARN";
+
 
     /**
      * Creates a new instance of LaunchServerJob.
@@ -356,7 +359,7 @@
         IPath confFolderPath = ApacheDsPluginUtils.getApacheDsServersFolder().append( server.getId()
).append( "conf" );
         File confFolder = new File( confFolderPath.toOSString() );
         ApacheDsPluginUtils.createServersLog4jPropertiesFile( new FileOutputStream( new File(
confFolder,
-            "log4j.properties" ) ), port );
+            "log4j.properties" ) ), port, logsLevel );
     }
 
 
@@ -478,4 +481,16 @@
     {
         return launch;
     }
+
+
+    /**
+     * Sets the logs level.
+     *
+     * @param logsLevel
+     *      the logs level
+     */
+    public void setLogsLevel( String logsLevel )
+    {
+        this.logsLevel = logsLevel;
+    }
 }

Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/ColorsAndFontsPage.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/ColorsAndFontsPage.java?rev=661600&r1=661599&r2=661600&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/ColorsAndFontsPage.java
(original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/ColorsAndFontsPage.java
Fri May 30 01:58:16 2008
@@ -41,7 +41,7 @@
 
 
 /**
- * This class implements the Preference main page for the Apache DS plugin.
+ * This class implements the Colors And Fonts preference page for the Apache DS plugin.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -67,13 +67,12 @@
 
 
     /**
-     * Creates a new instance of MainPage.
+     * Creates a new instance of ColorsAndFontsPage.
      */
     public ColorsAndFontsPage()
     {
         super( "Colors and Fonts" );
         setPreferenceStore( ApacheDsPlugin.getDefault().getPreferenceStore() );
-        setDescription( "Colors and Fonts settings for the Apache DS Plugin" );
     }
 
 

Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/MainPage.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/MainPage.java?rev=661600&r1=661599&r2=661600&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/MainPage.java
(original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/MainPage.java
Fri May 30 01:58:16 2008
@@ -32,7 +32,7 @@
 
 
 /**
- * This class implements the Preference main page for the Apache DS plugin.
+ * This class implements the Apache DS preference page for the Apache DS plugin.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$

Added: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/ServerLogsPage.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/ServerLogsPage.java?rev=661600&view=auto
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/ServerLogsPage.java
(added)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/prefs/ServerLogsPage.java
Fri May 30 01:58:16 2008
@@ -0,0 +1,294 @@
+/*
+ *  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.prefs;
+
+
+import org.apache.directory.studio.apacheds.ApacheDsPlugin;
+import org.apache.directory.studio.apacheds.ApacheDsPluginConstants;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.apache.log4j.spi.LoggingEvent;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+
+
+/**
+ * This class implements the Servers Logs preference page for the Apache DS plugin.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServerLogsPage extends PreferencePage implements IWorkbenchPreferencePage
+{
+    // UI fields
+    private Combo levelCombo;
+    private Text patternText;
+    private Label previewLabel;
+    private Group conversionPatternGroup;
+
+
+    /**
+     * Creates a new instance of ServerLogsPage.
+     */
+    public ServerLogsPage()
+    {
+        super( "Server Logs" );
+        setPreferenceStore( ApacheDsPlugin.getDefault().getPreferenceStore() );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+     */
+    protected Control createContents( Composite parent )
+    {
+        // Composite
+        Composite composite = new Composite( parent, SWT.NONE );
+        composite.setLayout( new GridLayout() );
+        composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+
+        // Colors And Fonts Link
+        Link colorsAndFontsLink = new Link( composite, SWT.NONE );
+        GridData gd = new GridData( SWT.FILL, SWT.BEGINNING, true, false );
+        gd.widthHint = 150;
+        colorsAndFontsLink.setLayoutData( gd );
+        colorsAndFontsLink
+            .setText( "Default colors and fonts settings can be configured on the <a>Colors
and Fonts</a> preference page." );
+        colorsAndFontsLink.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                PreferencesUtil.createPreferenceDialogOn( getShell(),
+                    "org.apache.directory.studio.apacheds.ColorsAndFontsPage", null, null
); //$NON-NLS-1$
+            }
+        } );
+
+        // Log Level Group
+        Group logLevelGroup = new Group( composite, SWT.NONE );
+        logLevelGroup.setText( "Log Level" );
+        logLevelGroup.setLayout( new GridLayout( 2, false ) );
+        logLevelGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Level Label
+        Label levelLabel = new Label( logLevelGroup, SWT.NONE );
+        levelLabel.setText( "Level:" );
+
+        //  Level Combo
+        levelCombo = new Combo( logLevelGroup, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.SIMPLE
);
+        levelCombo.add( "Info", 0 );
+        levelCombo.add( "Debug", 1 );
+        levelCombo.add( "Warning", 2 );
+        levelCombo.add( "Error", 3 );
+        levelCombo.add( "Fatal", 4 );
+
+        // Warning Label
+        new Label( logLevelGroup, SWT.NONE ); // Filler
+        Label warningLabel = new Label( logLevelGroup, SWT.WRAP );
+        warningLabel
+            .setText( "Warning: Setting the log level to 'Debug' or 'Info' can cause issues
and slow down the server." );
+        warningLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Conversion Pattern Group
+        conversionPatternGroup = new Group( composite, SWT.NONE );
+        conversionPatternGroup.setText( "Conversion Pattern" );
+        conversionPatternGroup.setLayout( new GridLayout( 2, false ) );
+        conversionPatternGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false
) );
+
+        // Pattern Label
+        Label patternLabel = new Label( conversionPatternGroup, SWT.NONE );
+        patternLabel.setText( "Pattern:" );
+
+        // Pattern Text
+        patternText = new Text( conversionPatternGroup, SWT.BORDER );
+        patternText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        patternText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                updatePreviewLabel();
+            }
+        } );
+
+        // Preview
+        Label label = new Label( conversionPatternGroup, SWT.NONE );
+        label.setText( "Preview:" );
+        previewLabel = new Label( conversionPatternGroup, SWT.NONE );
+        previewLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        initFromPreferences();
+
+        applyDialogFont( composite );
+        return composite;
+    }
+
+
+    /**
+     * Updates the preview label.
+     */
+    private void updatePreviewLabel()
+    {
+        LoggingEvent loggingEvent = new LoggingEvent( "CategoryClass", Logger.getLogger(
"logger" ), Level.INFO,
+            "Logging message", new Exception( "AnException" ) );
+        previewLabel.setText( new PatternLayout( patternText.getText() ).format( loggingEvent
) );
+    }
+
+
+    /**
+     * Initializes the UI fields from the preferences values.
+     */
+    private void initFromPreferences()
+    {
+        IPreferenceStore store = getPreferenceStore();
+
+        // Level
+        String level = store.getString( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL );
+        if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_INFO.equalsIgnoreCase( level
) )
+        {
+            levelCombo.select( 0 );
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_DEBUG.equalsIgnoreCase(
level ) )
+        {
+            levelCombo.select( 1 );
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_WARN.equalsIgnoreCase(
level ) )
+        {
+            levelCombo.select( 2 );
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_ERROR.equalsIgnoreCase(
level ) )
+        {
+            levelCombo.select( 3 );
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_FATAL.equalsIgnoreCase(
level ) )
+        {
+            levelCombo.select( 4 );
+        }
+
+        // Pattern
+        patternText.setText( store.getString( ApacheDsPluginConstants.PREFS_SERVER_LOGS_PATTERN
) );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
+     */
+    protected void performDefaults()
+    {
+        IPreferenceStore store = getPreferenceStore();
+
+        // Level
+        String level = store.getDefaultString( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL
);
+        if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_INFO.equalsIgnoreCase( level
) )
+        {
+            levelCombo.select( 0 );
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_DEBUG.equalsIgnoreCase(
level ) )
+        {
+            levelCombo.select( 1 );
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_WARN.equalsIgnoreCase(
level ) )
+        {
+            levelCombo.select( 2 );
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_ERROR.equalsIgnoreCase(
level ) )
+        {
+            levelCombo.select( 3 );
+        }
+        else if ( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_FATAL.equalsIgnoreCase(
level ) )
+        {
+            levelCombo.select( 4 );
+        }
+
+        // Pattern
+        patternText.setText( store.getDefaultString( ApacheDsPluginConstants.PREFS_SERVER_LOGS_PATTERN
) );
+
+        super.performDefaults();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.preference.PreferencePage#performOk()
+     */
+    public boolean performOk()
+    {
+        IPreferenceStore store = getPreferenceStore();
+
+        // Level
+        int level = levelCombo.getSelectionIndex();
+
+        store.getDefaultString( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL );
+        if ( level == 0 )
+        {
+            store.setValue( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL,
+                ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_INFO );
+        }
+        else if ( level == 1 )
+        {
+            store.setValue( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL,
+                ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_DEBUG );
+        }
+        else if ( level == 2 )
+        {
+            store.setValue( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL,
+                ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_WARN );
+        }
+        else if ( level == 3 )
+        {
+            store.setValue( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL,
+                ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_ERROR );
+        }
+        else if ( level == 4 )
+        {
+            store.setValue( ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL,
+                ApacheDsPluginConstants.PREFS_SERVER_LOGS_LEVEL_FATAL );
+        }
+
+        // Pattern
+        store.setValue( ApacheDsPluginConstants.PREFS_SERVER_LOGS_PATTERN, patternText.getText()
);
+
+        return super.performOk();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+     */
+    public void init( IWorkbench workbench )
+    {
+        // Nothing to do
+    }
+}



Mime
View raw message