directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r651639 - in /directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations: META-INF/ src/main/java/org/apache/directory/studio/apacheds/experimentations/ src/main/java/org/apache/directory/studio/apacheds/experiment...
Date Fri, 25 Apr 2008 16:36:03 GMT
Author: pamarcelot
Date: Fri Apr 25 09:35:47 2008
New Revision: 651639

URL: http://svn.apache.org/viewvc?rev=651639&view=rev
Log:
o Added a wizard and action to create a new server instance.
o Added implementation for loading and writing the server instances files to disk.

Added:
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/NewServerInstanceAction.java
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/wizards/
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/wizards/NewServerInstanceWizard.java
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/wizards/NewServerInstanceWizardPage.java
Modified:
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/META-INF/MANIFEST.MF
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginConstants.java
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandler.java
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIO.java
    directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/views/ServersView.java

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/META-INF/MANIFEST.MF?rev=651639&r1=651638&r2=651639&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/META-INF/MANIFEST.MF
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/META-INF/MANIFEST.MF
Fri Apr 25 09:35:47 2008
@@ -16,4 +16,5 @@
 Bundle-ClassPath: lib/apacheds-main.jar,
  lib/log4j-1.2.14.jar,
  lib/slf4j-api-1.4.3.jar,
- lib/slf4j-log4j12-1.4.3.jar
+ lib/slf4j-log4j12-1.4.3.jar,
+ lib/dom4j-1.6.1.jar

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginConstants.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginConstants.java?rev=651639&r1=651638&r2=651639&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginConstants.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginConstants.java
Fri Apr 25 09:35:47 2008
@@ -28,6 +28,12 @@
  */
 public interface ApacheDsPluginConstants
 {
+    // -------
+    // ACTIONS
+    // -------
+    public static final String ACTION_NEW_SERVER_INSTANCE = "org.apache.directory.studio.apacheds.experimentations.actions.newServerInstanceAction";
+    
+    
     // -----------
     // PREFERENCES
     // -----------
@@ -55,4 +61,5 @@
     public static final String PREFS_COLORS_AND_FONTS_FATAL_FONT = "org.apache.directory.studio.apacheds.experimentations.prefs.colorAndFonts.fatalFont";
     /** The Preference ID for the Fatal Color setting */
     public static final String PREFS_COLORS_AND_FONTS_FATAL_COLOR = "org.apache.directory.studio.apacheds.experimentations.prefs.colorAndFonts.fatalColor";
+    
 }

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java?rev=651639&r1=651638&r2=651639&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/ApacheDsPluginUtils.java
Fri Apr 25 09:35:47 2008
@@ -225,7 +225,7 @@
 
             // Copying server.xml file
             File serverXmlFile = new File( confFolder, "server.xml" );
-            copyConfigurationFile( "", serverXmlFile );
+            copyConfigurationFile( "server.xml", serverXmlFile );
         }
         catch ( IOException e )
         {

Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/NewServerInstanceAction.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/NewServerInstanceAction.java?rev=651639&view=auto
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/NewServerInstanceAction.java
(added)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/actions/NewServerInstanceAction.java
Fri Apr 25 09:35:47 2008
@@ -0,0 +1,104 @@
+/*
+ *  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.experimentations.actions;
+
+
+import org.apache.directory.studio.apacheds.experimentations.ApacheDsPluginConstants;
+import org.apache.directory.studio.apacheds.experimentations.wizards.NewServerInstanceWizard;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class implements the new server instance action.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewServerInstanceAction extends Action implements IWorkbenchWindowActionDelegate
+{
+    /**
+     * Creates a new instance of NewServerInstanceAction.
+     */
+    public NewServerInstanceAction()
+    {
+        super( "New Server" );
+        setToolTipText( "New Server" );
+        setId( ApacheDsPluginConstants.ACTION_NEW_SERVER_INSTANCE );
+        setEnabled( true );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.action.Action#run()
+     */
+    public void run()
+    {
+        // Instantiates and initializes the wizard
+        NewServerInstanceWizard wizard = new NewServerInstanceWizard();
+        wizard.init( PlatformUI.getWorkbench(), StructuredSelection.EMPTY );
+        // Instantiates the wizard container with the wizard and opens it
+        WizardDialog dialog = new WizardDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
wizard );
+        dialog.create();
+        dialog.open();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+     */
+    public void run( IAction action )
+    {
+        run();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
+     */
+    public void dispose()
+    {
+        // Nothing to do
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
+     */
+    public void init( IWorkbenchWindow window )
+    {
+        // Nothing to do
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
org.eclipse.jface.viewers.ISelection)
+     */
+    public void selectionChanged( IAction action, ISelection selection )
+    {
+        // Nothing to do
+    }
+}

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java?rev=651639&r1=651638&r2=651639&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServerInstance.java
Fri Apr 25 09:35:47 2008
@@ -48,6 +48,21 @@
 
     /**
      * Creates a new instance of ApacheDsInstance.
+     * <p>
+     * An ID is automatically created.
+     *
+     * @param name
+     *      the name of the instance
+     */
+    public ServerInstance( String name )
+    {
+        this.name = name;
+        id = createId();
+    }
+
+
+    /**
+     * Creates a new instance of ApacheDsInstance.
      *
      * @param name
      *      the name of the instance

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandler.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandler.java?rev=651639&r1=651638&r2=651639&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandler.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandler.java
Fri Apr 25 09:35:47 2008
@@ -20,11 +20,21 @@
 package org.apache.directory.studio.apacheds.experimentations.model;
 
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.directory.studio.apacheds.experimentations.ApacheDsPlugin;
+import org.eclipse.core.runtime.IPath;
+
 
 /**
  * This class implements the servers handler.
@@ -57,10 +67,11 @@
      */
     private ServersHandler()
     {
-        // Initializing list and maps
+        // Initializing lists and maps
         serverInstancesList = new ArrayList<ServerInstance>();
         serverInstancesNameMap = new HashMap<String, ServerInstance>();
         serverInstancesIdMap = new HashMap<String, ServerInstance>();
+        listeners = new ArrayList<ServersHandlerListener>();
     }
 
 
@@ -72,12 +83,9 @@
      */
     public static ServersHandler getDefault()
     {
-        synchronized ( instance )
+        if ( instance == null )
         {
-            if ( instance == null )
-            {
-                instance = new ServersHandler();
-            }
+            instance = new ServersHandler();
         }
 
         return instance;
@@ -93,6 +101,8 @@
     public void addServerInstance( ServerInstance serverInstance )
     {
         addServerInstance( serverInstance, true );
+
+        saveServerInstancesToStore();
     }
 
 
@@ -109,6 +119,7 @@
     {
         if ( !serverInstancesList.contains( serverInstance ) )
         {
+            // Adding the server instance
             serverInstancesList.add( serverInstance );
             serverInstancesIdMap.put( serverInstance.getId(), serverInstance );
             serverInstancesNameMap.put( serverInstance.getName(), serverInstance );
@@ -134,6 +145,8 @@
     public void removeServerInstance( ServerInstance serverInstance )
     {
         removeServerInstance( serverInstance, true );
+
+        saveServerInstancesToStore();
     }
 
 
@@ -150,6 +163,7 @@
     {
         if ( serverInstancesList.contains( serverInstance ) )
         {
+            // Removing the server instance
             serverInstancesNameMap.remove( serverInstance.getName() );
             serverInstancesIdMap.remove( serverInstance.getId() );
             serverInstancesList.remove( serverInstance );
@@ -216,8 +230,30 @@
      */
     public void loadServerInstancesFromStore()
     {
-        // TODO Auto-generated method stub
+        File store = getServerInstancesStorePath().toFile();
 
+        if ( store.exists() )
+        {
+            try
+            {
+                InputStream inputStream = new FileInputStream( store );
+                List<ServerInstance> serverInstances = ServersHandlerIO.read( inputStream
);
+                for ( ServerInstance serverInstance : serverInstances )
+                {
+                    addServerInstance( serverInstance, false );
+                }
+            }
+            catch ( FileNotFoundException e )
+            {
+                // Will never occur as the store file exists
+            }
+            catch ( ServersHandlerIOException e )
+            {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+
+        }
     }
 
 
@@ -226,7 +262,42 @@
      */
     public void saveServerInstancesToStore()
     {
-        // TODO Auto-generated method stub
+        try
+        {
+            OutputStream outputStream = new FileOutputStream( getServerInstancesStorePath().toFile()
);
+            ServersHandlerIO.write( serverInstancesList, outputStream );
+        }
+        catch ( FileNotFoundException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        catch ( IOException e )
+        {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+
+    private IPath getServerInstancesStorePath()
+    {
+        return ApacheDsPlugin.getDefault().getStateLocation().append( "serverInstances.xml"
);
+    }
 
+
+    /**
+     * Indicates if the given is available (ie. not already taken by another 
+     * server instance).
+     *
+     * @param name
+     *      the name
+     * @return
+     *      <code>true</code> if the name is available, <code>false</code>
if
+     *      not
+     */
+    public boolean isNameAvailable( String name )
+    {
+        return !serverInstancesNameMap.containsKey( name );
     }
 }

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIO.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIO.java?rev=651639&r1=651638&r2=651639&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIO.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/model/ServersHandlerIO.java
Fri Apr 25 09:35:47 2008
@@ -23,7 +23,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;

Modified: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/views/ServersView.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/views/ServersView.java?rev=651639&r1=651638&r2=651639&view=diff
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/views/ServersView.java
(original)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/views/ServersView.java
Fri Apr 25 09:35:47 2008
@@ -20,11 +20,12 @@
 package org.apache.directory.studio.apacheds.experimentations.views;
 
 
+import org.apache.directory.studio.apacheds.experimentations.actions.NewServerInstanceAction;
+import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Table;
 import org.eclipse.ui.part.ViewPart;
 
 
@@ -44,6 +45,9 @@
     /** The table viewer */
     private TableViewer tableViewer;
 
+    // Actions
+    private NewServerInstanceAction newServerInstance;
+
 
     /* (non-Javadoc)
      * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
@@ -52,6 +56,9 @@
     {
         tableViewer = new TableViewer( parent );
         tableViewer.getTable().setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true
) );
+
+        initActions();
+        initToolbar();
     }
 
 
@@ -61,6 +68,25 @@
     public void setFocus()
     {
         tableViewer.getTable().setFocus();
+    }
+
+
+    /**
+     * Initializes the actions.
+     */
+    private void initActions()
+    {
+        newServerInstance = new NewServerInstanceAction();
+    }
+
+
+    /**
+     * Initializes the toolbar.
+     */
+    private void initToolbar()
+    {
+        IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
+        toolbar.add( newServerInstance );
     }
 
 

Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/wizards/NewServerInstanceWizard.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/wizards/NewServerInstanceWizard.java?rev=651639&view=auto
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/wizards/NewServerInstanceWizard.java
(added)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/wizards/NewServerInstanceWizard.java
Fri Apr 25 09:35:47 2008
@@ -0,0 +1,79 @@
+/*
+ *  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.experimentations.wizards;
+
+
+import org.apache.directory.studio.apacheds.experimentations.ApacheDsPluginUtils;
+import org.apache.directory.studio.apacheds.experimentations.model.ServerInstance;
+import org.apache.directory.studio.apacheds.experimentations.model.ServersHandler;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+
+
+/**
+ * This class implements the new server instance wizard.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewServerInstanceWizard extends Wizard implements INewWizard
+{
+    /** The wizard page */
+    private NewServerInstanceWizardPage page;
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#addPages()
+     */
+    public void addPages()
+    {
+        page = new NewServerInstanceWizardPage();
+        addPage( page );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#performFinish()
+     */
+    public boolean performFinish()
+    {
+        // Creating the new server instance
+        ServerInstance serverInstance = new ServerInstance( page.getServerInstanceName()
);
+
+        // Adding the new server instance to the servers handler
+        ServersHandler.getDefault().addServerInstance( serverInstance );
+
+        // Creating the complete folder structure for the new server instance
+        ApacheDsPluginUtils.createNewInstanceFolder( serverInstance.getId() );
+
+        return true;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+     */
+    public void init( IWorkbench workbench, IStructuredSelection selection )
+    {
+        setNeedsProgressMonitor( false );
+    }
+}

Added: directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/wizards/NewServerInstanceWizardPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/wizards/NewServerInstanceWizardPage.java?rev=651639&view=auto
==============================================================================
--- directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/wizards/NewServerInstanceWizardPage.java
(added)
+++ directory/sandbox/pamarcelot/studio-apacheds-plugin/studio-apacheds-experimentations/src/main/java/org/apache/directory/studio/apacheds/experimentations/wizards/NewServerInstanceWizardPage.java
Fri Apr 25 09:35:47 2008
@@ -0,0 +1,135 @@
+/*
+ *  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.experimentations.wizards;
+
+
+import org.apache.directory.studio.apacheds.experimentations.model.ServersHandler;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * This class implements the wizard page for the new server instance wizard.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class NewServerInstanceWizardPage extends WizardPage
+{
+    /** The servers handler */
+    private ServersHandler serversHandler;
+
+    // UI fields
+    private Text nameText;
+
+
+    /**
+     * Creates a new instance of NewServerInstanceWizardPage.
+     */
+    public NewServerInstanceWizardPage()
+    {
+        super( NewServerInstanceWizardPage.class.getCanonicalName() );
+        setTitle( "Create a Server" );
+        setDescription( "Please specify a name to create a new server." );
+        setPageComplete( false );
+        serversHandler = ServersHandler.getDefault();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+     */
+    public void createControl( Composite parent )
+    {
+        Composite composite = new Composite( parent, SWT.NONE );
+        composite.setLayout( new GridLayout( 2, false ) );
+
+        Label nameLabel = new Label( composite, SWT.NONE );
+        nameLabel.setText( "Name:" );
+        nameText = new Text( composite, SWT.BORDER );
+        nameText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+        nameText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                validate();
+            }
+        } );
+
+        setControl( composite );
+    }
+
+
+    /**
+     * Validates the page.
+     */
+    private void validate()
+    {
+        displayErrorMessage( null );
+
+        String name = nameText.getText();
+        if ( ( name != null ) )
+        {
+            if ( "".equals( name ) )
+            {
+                displayErrorMessage( "Enter a name for the server." );
+                return;
+            }
+            if ( !serversHandler.isNameAvailable( name ) )
+            {
+                displayErrorMessage( "A server with the same name already exists." );
+                return;
+            }
+        }
+    }
+
+
+    /**
+     * Displays an error message and set the page status as incomplete
+     * if the message is not null.
+     *
+     * @param message
+     *      the message to display
+     */
+    protected void displayErrorMessage( String message )
+    {
+        setErrorMessage( message );
+        setPageComplete( message == null );
+    }
+
+
+    /**
+     * Gets the name of the server instance.
+     *
+     * @return
+     *      the name of the server instance
+     */
+    public String getServerInstanceName()
+    {
+        return nameText.getText();
+    }
+}



Mime
View raw message