directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1060493 - in /directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2: editor/ jobs/
Date Tue, 18 Jan 2011 18:05:25 GMT
Author: pamarcelot
Date: Tue Jan 18 18:05:24 2011
New Revision: 1060493

URL: http://svn.apache.org/viewvc?rev=1060493&view=rev
Log:
Added an Error Page which replaces the Loading Page in case of error.
The Tab Folder is now hidden when there's only one Page in the Form Editor.

Added:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ErrorPage.java
Modified:
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LoadingPage.java
    directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/OverviewPage.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/jobs/LoadConfigurationRunnable.java

Added: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ErrorPage.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/ErrorPage.java?rev=1060493&view=auto
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ErrorPage.java
(added)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/ErrorPage.java
Tue Jan 18 18:05:24 2011
@@ -0,0 +1,168 @@
+/*
+ *  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.PrintWriter;
+import java.io.StringWriter;
+
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+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.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+
+/**
+ * This class represents the Error Page of the Server Configuration Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ErrorPage extends FormPage
+{
+    /** The Page ID*/
+    public static final String ID = ErrorPage.class.getName();
+
+    /** The Page Title */
+    private static final String TITLE = "Error opening the editor";
+
+    private static final String DETAILS_CLOSED = NLS.bind( "{0} >>", "Details" );
+    private static final String DETAILS_OPEN = NLS.bind( "<< {0}", "Details" );
+
+    /** The exception */
+    private Exception exception;
+
+    /** The flag indicating that the details are shown */
+    private boolean detailsShown = false;
+
+    // UI Controls
+    private FormToolkit toolkit;
+    private Composite parent;
+    private Button detailsButton;
+
+    private Text detailsText;
+
+
+    /**
+     * Creates a new instance of ErrorPage.
+     *
+     * @param editor
+     *      the associated editor
+     */
+    public ErrorPage( FormEditor editor, Exception exception )
+    {
+        super( editor, ID, TITLE );
+        this.exception = exception;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void createFormContent( IManagedForm managedForm )
+    {
+        ScrolledForm form = managedForm.getForm();
+        form.setText( "Error opening the editor" );
+        form.setImage( Display.getCurrent().getSystemImage( SWT.ICON_ERROR ) );
+
+        parent = form.getBody();
+        GridLayout gl = new GridLayout( 2, false );
+        gl.marginHeight = 10;
+        gl.marginWidth = 10;
+        parent.setLayout( gl );
+        parent.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
+
+        toolkit = managedForm.getToolkit();
+        toolkit.decorateFormHeading( form.getForm() );
+
+        // Error Label
+        Label errorLabel = toolkit.createLabel( parent,
+            NLS.bind( "Could not open the editor: {0}", exception.getMessage() ) );
+        errorLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Details Button
+        detailsButton = new Button( parent, SWT.PUSH );
+        detailsButton.setText( DETAILS_CLOSED );
+        detailsButton.setLayoutData( new GridData( SWT.RIGHT, SWT.NONE, false, false ) );
+        detailsButton.addSelectionListener( new SelectionAdapter()
+        {
+            @Override
+            public void widgetSelected( SelectionEvent e )
+            {
+                showOrHideDetailsView();
+            }
+        } );
+    }
+
+
+    /**
+     * Shows or hides the details view.
+     */
+    private void showOrHideDetailsView()
+    {
+        if ( detailsShown )
+        {
+            detailsButton.setText( DETAILS_CLOSED );
+
+            detailsText.dispose();
+        }
+        else
+        {
+            detailsButton.setText( DETAILS_OPEN );
+
+            detailsText = toolkit.createText( parent, getStackTrace( exception ), SWT.H_SCROLL
| SWT.V_SCROLL );
+            detailsText.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true, 2, 1
) );
+        }
+
+        parent.layout( true, true );
+
+        detailsShown = !detailsShown;
+    }
+
+
+    /**
+     * Gets the stackTrace of the given exception as a string.
+     *
+     * @param e
+     *      the exception
+     * @return
+     *      the stackTrace of the given exception as a string
+     */
+    private String getStackTrace( Exception e )
+    {
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter( sw, true );
+        e.printStackTrace( pw );
+        pw.flush();
+        sw.flush();
+        return sw.toString();
+    }
+}

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LoadingPage.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/LoadingPage.java?rev=1060493&r1=1060492&r2=1060493&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LoadingPage.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/LoadingPage.java
Tue Jan 18 18:05:24 2011
@@ -34,7 +34,7 @@ import org.eclipse.ui.forms.widgets.Scro
 
 
 /**
- * This class represents the General Page of the Server Configuration Editor.
+ * This class represents the Loading Page of the Server Configuration Editor.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */

Modified: directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/OverviewPage.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/OverviewPage.java?rev=1060493&r1=1060492&r2=1060493&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/OverviewPage.java
(original)
+++ directory/studio/trunk/plugins/apacheds.configuration.v2/src/main/java/org/apache/directory/studio/apacheds/configuration/v2/editor/OverviewPage.java
Tue Jan 18 18:05:24 2011
@@ -62,7 +62,7 @@ public class OverviewPage extends Server
     /** The Page Title */
     private static final String TITLE = "Overview";
 
-    // UI Fields
+    // UI Controls
     private Button enableLdapCheckbox;
     private Text ldapPortText;
     private Button enableLdapsCheckbox;

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=1060493&r1=1060492&r2=1060493&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 Jan 18 18:05:24 2011
@@ -43,6 +43,8 @@ import org.apache.directory.studio.ldapb
 import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection;
 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.ui.IEditorInput;
 import org.eclipse.ui.IEditorSite;
 import org.eclipse.ui.IPathEditorInput;
@@ -123,6 +125,31 @@ public class ServerConfigurationEditor e
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
+
+        showOrHideTabFolder();
+    }
+
+
+    /**
+     * Shows or hides the tab folder depending on
+     * the number of pages.
+     */
+    private void showOrHideTabFolder()
+    {
+        Composite container = getContainer();
+        if ( container instanceof CTabFolder )
+        {
+            CTabFolder folder = ( CTabFolder ) container;
+            if ( getPageCount() == 1 )
+            {
+                folder.setTabHeight( 0 );
+            }
+            else
+            {
+                folder.setTabHeight( -1 );
+            }
+            folder.layout( true, true );
+        }
     }
 
 
@@ -445,7 +472,8 @@ public class ServerConfigurationEditor e
 
 
     /**
-     * This method is called by the job responsible for loading the configuration.
+     * This method is called by the job responsible for loading the 
+     * configuration when it has been fully and correctly loaded.
      *
      * @param configBean
      *      the loaded configuration bean
@@ -459,6 +487,23 @@ public class ServerConfigurationEditor e
 
 
     /**
+     * This method is called by the job responsible for loading the
+     * configuration when it failed to load it.
+     *
+     * @param exception
+     *      the exception
+     */
+    public void configurationLoadFailed( Exception exception )
+    {
+        // Overriding the default dirty setting 
+        // (especially in the case of a new configuration file)
+        setDirty( false );
+
+        hideLoadingPageAndDisplayErrorPage( exception );
+    }
+
+
+    /**
      * Hides the loading page and displays the standard configuration pages.
      */
     private void hideLoadingPageAndDisplayConfigPages()
@@ -488,6 +533,37 @@ public class ServerConfigurationEditor e
 
         // Activating the first page
         setActivePage( 0 );
+
+        showOrHideTabFolder();
+    }
+
+
+    /**
+     * Hides the loading page and displays the error page.
+     *
+     * @param exception
+     *      the exception
+     */
+    private void hideLoadingPageAndDisplayErrorPage( Exception exception )
+    {
+        // Removing the loading page
+        removePage( 0 );
+
+        // Adding the error page
+        try
+        {
+            addPage( new ErrorPage( this, exception ) );
+        }
+        catch ( PartInitException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        // Activating the first page
+        setActivePage( 0 );
+
+        showOrHideTabFolder();
     }
 
 

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=1060493&r1=1060492&r2=1060493&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 Jan 18 18:05:24 2011
@@ -133,8 +133,15 @@ public class LoadConfigurationRunnable i
         }
         catch ( Exception e )
         {
-            // Reporting the error to the monitor
-            monitor.reportError( e );
+            // Reporting the error to the editor
+            final Exception exception = e;
+            Display.getDefault().asyncExec( new Runnable()
+            {
+                public void run()
+            {
+                editor.configurationLoadFailed( exception );
+            }
+            } );
         }
     }
 



Mime
View raw message