directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r555288 - in /directory/studio/trunk/studio-apacheds-schemaeditor: ./ resources/icons/ src/main/java/org/apache/directory/studio/apacheds/schemaeditor/ src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/ src/...
Date Wed, 11 Jul 2007 14:41:26 GMT
Author: pamarcelot
Date: Wed Jul 11 07:41:24 2007
New Revision: 555288

URL: http://svn.apache.org/viewvc?view=rev&rev=555288
Log:
Added a new Export wizard for schemas as XML files.

Added:
    directory/studio/trunk/studio-apacheds-schemaeditor/resources/icons/schemas_export.gif
  (with props)
    directory/studio/trunk/studio-apacheds-schemaeditor/resources/icons/schemas_export_wizard.png
  (with props)
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java
Modified:
    directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginConstants.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/ConnectAction.java

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml?view=diff&rev=555288&r1=555287&r2=555288
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml Wed Jul 11 07:41:24 2007
@@ -94,4 +94,18 @@
 		id="org.apache.directory.studio.apacheds.schemaeditor.view.schemaformeditor"
 		name="Schema Editor"/>
 </extension>
+ <extension
+       point="org.eclipse.ui.exportWizards">
+    <category
+          id="org.apache.directory.studio.apacheds.schemaeditor.exportWizardCategory"
+          name="Apache DS Schema Editor">
+    </category>
+    <wizard
+          category="org.apache.directory.studio.apacheds.schemaeditor.exportWizardCategory"
+          class="org.apache.directory.studio.apacheds.schemaeditor.view.wizards.ExportSchemasAsXmlWizard"
+          icon="resources/icons/schemas_export.gif"
+          id="org.apache.directory.studio.apacheds.schemaeditor.wizards.ExportSchemasAsXmlWizard"
+          name="Export schemas as XML">
+    </wizard>
+ </extension>
 </plugin>

Added: directory/studio/trunk/studio-apacheds-schemaeditor/resources/icons/schemas_export.gif
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/resources/icons/schemas_export.gif?view=auto&rev=555288
==============================================================================
Binary file - no diff available.

Propchange: directory/studio/trunk/studio-apacheds-schemaeditor/resources/icons/schemas_export.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: directory/studio/trunk/studio-apacheds-schemaeditor/resources/icons/schemas_export_wizard.png
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/resources/icons/schemas_export_wizard.png?view=auto&rev=555288
==============================================================================
Binary file - no diff available.

Propchange: directory/studio/trunk/studio-apacheds-schemaeditor/resources/icons/schemas_export_wizard.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginConstants.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginConstants.java?view=diff&rev=555288&r1=555287&r2=555288
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginConstants.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginConstants.java
Wed Jul 11 07:41:24 2007
@@ -47,6 +47,7 @@
     public static final String IMG_PROBLEMS_GROUP = "resources/icons/problems_group.gif";
     public static final String IMG_PROBLEMS_WARNING = "resources/icons/problems_warning.gif";
     public static final String IMG_SCHEMA = "resources/icons/schema.gif";
+    public static final String IMG_SCHEMAS_EXPORT_WIZARD = "resources/icons/schemas_export_wizard.png";
     public static final String IMG_TOOLBAR_MENU = "resources/icons/toolbar_menu.gif";
 
     // Commands

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/ConnectAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/ConnectAction.java?view=diff&rev=555288&r1=555287&r2=555288
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/ConnectAction.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/controller/actions/ConnectAction.java
Wed Jul 11 07:41:24 2007
@@ -29,6 +29,7 @@
 import org.apache.directory.studio.apacheds.schemaeditor.SchemaImporter;
 import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
 import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
+import org.apache.directory.studio.apacheds.schemaeditor.model.schemachecker.SchemaChecker;
 import org.apache.directory.studio.apacheds.schemaeditor.view.views.SchemaView;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
@@ -48,7 +49,8 @@
 {
     /** The associated View */
     private SchemaView view;
-    
+
+
     /**
      * Creates a new instance of ConnectAction.
      *
@@ -101,13 +103,16 @@
     {
         try
         {
-            SchemaHandler schemaHandler = SchemaHandler.getInstance();
+            SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler();
+            SchemaChecker schemaChecker = Activator.getDefault().getSchemaChecker();
             SchemaImporter schemaImporter = new SchemaImporter();
+            schemaChecker.disableModificationsListening();
             List<Schema> schemas = schemaImporter.getServerSchema();
             for ( Schema schema : schemas )
             {
                 schemaHandler.addSchema( schema );
             }
+            schemaChecker.enableModificationsListening();
             view.reloadViewer();
         }
         catch ( NamingException e )

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java?view=auto&rev=555288
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java
(added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java
Wed Jul 11 07:41:24 2007
@@ -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.schemaeditor.view.wizards;
+
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.XMLSchemaFileExporter;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IExportWizard;
+import org.eclipse.ui.IWorkbench;
+
+
+/**
+ * This class represents the wizard to export schemas as XML.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExportSchemasAsXmlWizard extends Wizard implements IExportWizard
+{
+    // The pages of the wizard
+    private ExportSchemasAsXmlWizardPage page;
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#addPages()
+     */
+    public void addPages()
+    {
+        // Creating pages
+        page = new ExportSchemasAsXmlWizardPage();
+
+        // Adding pages
+        addPage( page );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#performFinish()
+     */
+    public boolean performFinish()
+    {
+        Schema[] selectedSchemas = page.getSelectedSchemas();
+
+        int exportType = page.getExportType();
+        if ( exportType == ExportSchemasAsXmlWizardPage.EXPORT_MULTIPLE_FILES )
+        {
+            String exportDirectory = page.getExportDirectory();
+
+            for ( Schema schema : selectedSchemas )
+            {
+                try
+                {
+                    BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportDirectory
+ "/"
+                        + schema.getName() + ".xml" ) );
+                    buffWriter.write( XMLSchemaFileExporter.toSourceCode( schema ) );
+                    buffWriter.close();
+                }
+                catch ( IOException e )
+                {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+        }
+        else if ( exportType == ExportSchemasAsXmlWizardPage.EXPORT_SINGLE_FILE )
+        {
+
+        }
+
+        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 )
+    {
+        // Nothing to do
+    }
+}

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java?view=auto&rev=555288
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java
(added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java
Wed Jul 11 07:41:24 2007
@@ -0,0 +1,510 @@
+/*
+ *  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.schemaeditor.view.wizards;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.LabelProvider;
+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.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+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.DirectoryDialog;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class represents the WizardPage of the ExportSchemasAsXmlWizard.
+ * <p>
+ * It is used to let the user enter the informations about the
+ * schemas he wants to export and where to export.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExportSchemasAsXmlWizardPage extends WizardPage
+{
+    /** The SchemaHandler */
+    private SchemaHandler schemaHandler;
+
+    public static final int EXPORT_MULTIPLE_FILES = 0;
+    public static final int EXPORT_SINGLE_FILE = 1;
+
+    // UI Fields
+    private CheckboxTableViewer schemasTableViewer;
+    private Button exportMultipleFilesRadio;
+    private Label exportMultipleFilesLabel;
+    private Text exportMultipleFilesText;
+    private Button exportMultipleFilewButton;
+    private Button exportSingleFileRadio;
+    private Label exportSingleFileLabel;
+    private Text exportSingleFileText;
+    private Button exportSingleFileButton;
+
+    private Button schemasTableSelectAllButton;
+
+    private Button schemasTableDeselectAllButton;
+
+
+    /**
+     * Creates a new instance of ExportSchemasAsXmlWizardPage.
+     */
+    protected ExportSchemasAsXmlWizardPage()
+    {
+        super( "ExportSchemasAsXmlWizardPage" );
+        setTitle( "Export schemas as XML" );
+        setDescription( "Please select the schemas to export as XML." );
+        setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+            PluginConstants.IMG_SCHEMAS_EXPORT_WIZARD ) );
+        schemaHandler = Activator.getDefault().getSchemaHandler();
+    }
+
+
+    /* (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.NULL );
+        GridLayout layout = new GridLayout();
+        composite.setLayout( layout );
+
+        // Schemas Group
+        Group schemasGroup = new Group( composite, SWT.NONE );
+        schemasGroup.setText( "Schemas" );
+        schemasGroup.setLayout( new GridLayout( 2, false ) );
+        schemasGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+        // Schemas TableViewer
+        Label schemasLabel = new Label( schemasGroup, SWT.NONE );
+        schemasLabel.setText( "Select the schemas to export:" );
+        schemasLabel.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 )
);
+        schemasTableViewer = new CheckboxTableViewer( new Table( schemasGroup, SWT.BORDER
| SWT.CHECK
+            | SWT.FULL_SELECTION ) );
+        GridData schemasTableViewerGridData = new GridData( SWT.FILL, SWT.NONE, true, false,
1, 2 );
+        schemasTableViewerGridData.heightHint = 100;
+        schemasTableViewer.getTable().setLayoutData( schemasTableViewerGridData );
+        schemasTableViewer.setContentProvider( new ArrayContentProvider() );
+        schemasTableViewer.setLabelProvider( new LabelProvider()
+        {
+            public String getText( Object element )
+            {
+                if ( element instanceof Schema )
+                {
+                    return ( ( Schema ) element ).getName();
+                }
+
+                // Default
+                return super.getText( element );
+            }
+
+
+            public Image getImage( Object element )
+            {
+                if ( element instanceof Schema )
+                {
+                    return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
PluginConstants.IMG_SCHEMA )
+                        .createImage();
+                }
+
+                // Default
+                return super.getImage( element );
+            }
+        } );
+        schemasTableViewer.addCheckStateListener( new ICheckStateListener()
+        {
+            /**
+             * Notifies of a change to the checked state of an element.
+             *
+             * @param event
+             *      event object describing the change
+             */
+            public void checkStateChanged( CheckStateChangedEvent event )
+            {
+                dialogChanged();
+            }
+        } );
+        schemasTableSelectAllButton = new Button( schemasGroup, SWT.PUSH );
+        schemasTableSelectAllButton.setText( "Select All" );
+        schemasTableSelectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING,
false, false ) );
+        schemasTableSelectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemasTableViewer.setAllChecked( true );
+                dialogChanged();
+            }
+        } );
+        schemasTableDeselectAllButton = new Button( schemasGroup, SWT.PUSH );
+        schemasTableDeselectAllButton.setText( "Deselect All" );
+        schemasTableDeselectAllButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING,
false, false ) );
+        schemasTableDeselectAllButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                schemasTableViewer.setAllChecked( false );
+                dialogChanged();
+            }
+        } );
+
+        // Export Destination Group
+        Group exportDestinationGroup = new Group( composite, SWT.NULL );
+        exportDestinationGroup.setText( "Export Destination" );
+        exportDestinationGroup.setLayout( new GridLayout( 4, false ) );
+        exportDestinationGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false
) );
+
+        // Export Multiple Files
+        exportMultipleFilesRadio = new Button( exportDestinationGroup, SWT.RADIO );
+        exportMultipleFilesRadio.setText( "Export each schema as a separate file." );
+        exportMultipleFilesRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false,
4, 1 ) );
+        exportMultipleFilesRadio.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                exportMultipleFilesSelected();
+                dialogChanged();
+            }
+        } );
+        Label exportMultipleFilesFiller = new Label( exportDestinationGroup, SWT.NONE );
+        exportMultipleFilesFiller.setText( "    " );
+        exportMultipleFilesLabel = new Label( exportDestinationGroup, SWT.NONE );
+        exportMultipleFilesLabel.setText( "Directory:" );
+        exportMultipleFilesText = new Text( exportDestinationGroup, SWT.BORDER );
+        exportMultipleFilesText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false
) );
+        exportMultipleFilesText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                dialogChanged();
+            }
+        } );
+        exportMultipleFilewButton = new Button( exportDestinationGroup, SWT.PUSH );
+        exportMultipleFilewButton.setText( "Browse..." );
+        exportMultipleFilewButton.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                chooseExportDirectory();
+                dialogChanged();
+            }
+        } );
+
+        // Export Single File
+        exportSingleFileRadio = new Button( exportDestinationGroup, SWT.RADIO );
+        exportSingleFileRadio.setText( "Export the schemas as a single file." );
+        exportSingleFileRadio.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false,
4, 1 ) );
+        exportSingleFileRadio.addSelectionListener( new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                exportSingleFileSelected();
+                dialogChanged();
+            }
+        } );
+        Label exportSingleFileFiller = new Label( exportDestinationGroup, SWT.NONE );
+        exportSingleFileFiller.setText( "    " );
+        exportSingleFileLabel = new Label( exportDestinationGroup, SWT.NONE );
+        exportSingleFileLabel.setText( "Export File:" );
+        exportSingleFileText = new Text( exportDestinationGroup, SWT.BORDER );
+        exportSingleFileText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false
) );
+        exportSingleFileText.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                dialogChanged();
+            }
+        } );
+        exportSingleFileButton = new Button( exportDestinationGroup, SWT.PUSH );
+        exportSingleFileButton.setText( "Browse..." );
+        exportSingleFileButton.addSelectionListener( new SelectionAdapter()
+        {
+            /* (non-Javadoc)
+             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+             */
+            public void widgetSelected( SelectionEvent e )
+            {
+                chooseExportFile();
+                dialogChanged();
+            }
+        } );
+
+        initFields();
+
+        setControl( composite );
+    }
+
+
+    /**
+     * Initializes the UI Fields.
+     */
+    private void initFields()
+    {
+        // Filling the Schemas table
+        schemasTableViewer.setInput( schemaHandler.getSchemas() );
+
+        // Selecting the Multiple Files choice
+        exportMultipleFilesSelected();
+
+        displayErrorMessage( null );
+        setPageComplete( false );
+    }
+
+
+    /**
+     * This method is called when the exportMultipleFiles radio button is selected.
+     */
+    private void exportMultipleFilesSelected()
+    {
+        exportMultipleFilesRadio.setSelection( true );
+        exportMultipleFilesLabel.setEnabled( true );
+        exportMultipleFilesText.setEnabled( true );
+        exportMultipleFilewButton.setEnabled( true );
+
+        exportSingleFileRadio.setSelection( false );
+        exportSingleFileLabel.setEnabled( false );
+        exportSingleFileText.setEnabled( false );
+        exportSingleFileButton.setEnabled( false );
+    }
+
+
+    /**
+     * This method is called when the exportSingleFile radio button is selected.
+     */
+    private void exportSingleFileSelected()
+    {
+        exportMultipleFilesRadio.setSelection( false );
+        exportMultipleFilesLabel.setEnabled( false );
+        exportMultipleFilesText.setEnabled( false );
+        exportMultipleFilewButton.setEnabled( false );
+
+        exportSingleFileRadio.setSelection( true );
+        exportSingleFileLabel.setEnabled( true );
+        exportSingleFileText.setEnabled( true );
+        exportSingleFileButton.setEnabled( true );
+    }
+
+
+    /**
+     * This method is called when the exportMultipleFiles 'browse' button is selected.
+     */
+    private void chooseExportDirectory()
+    {
+        DirectoryDialog dialog = new DirectoryDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()
);
+        dialog.setText( "Choose Folder" );
+        dialog.setMessage( "Select the folder in which export the files." );
+
+        String selectedDirectory = dialog.open();
+        if ( selectedDirectory != null )
+        {
+            exportMultipleFilesText.setText( selectedDirectory );
+        }
+    }
+
+
+    /**
+     * This method is called when the exportSingleFile 'browse' button is selected.
+     */
+    private void chooseExportFile()
+    {
+        FileDialog dialog = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()
);
+        dialog.setText( "Select File" );
+        dialog.setFilterExtensions( new String[]
+            { "*.xml", "*" } );
+        dialog.setFilterNames( new String[]
+            { "XML Files", "All Files" } );
+        dialog.setFilterPath( exportSingleFileText.getText() );
+
+        String selectedFile = dialog.open();
+        if ( selectedFile != null )
+        {
+            exportSingleFileText.setText( selectedFile );
+        }
+    }
+
+
+    /**
+     * This method is called when the user modifies something in the UI.
+     */
+    private void dialogChanged()
+    {
+        // Schemas table
+        if ( schemasTableViewer.getCheckedElements().length == 0 )
+        {
+            displayErrorMessage( "One or several schemas must be selected." );
+            return;
+        }
+
+        // Export option
+        if ( exportMultipleFilesRadio.getSelection() )
+        {
+            String directory = exportMultipleFilesText.getText();
+            if ( ( directory == null ) || ( directory.equals( "" ) ) )
+            {
+                displayErrorMessage( "A directory must be selected." );
+                return;
+            }
+            else
+            {
+                File directoryFile = new File( directory );
+                if ( !directoryFile.exists() )
+                {
+                    displayErrorMessage( "The selected directory does not exist." );
+                    return;
+                }
+                else if ( !directoryFile.isDirectory() )
+                {
+                    displayErrorMessage( "The selected directory is not a directory." );
+                    return;
+                }
+                else if ( !directoryFile.canWrite() )
+                {
+                    displayErrorMessage( "The selected directory is not writable." );
+                    return;
+                }
+            }
+        }
+        else if ( exportSingleFileRadio.getSelection() )
+        {
+            String exportFile = exportSingleFileText.getText();
+            if ( ( exportFile == null ) || ( exportFile.equals( "" ) ) )
+            {
+                displayErrorMessage( "A file must be selected." );
+                return;
+            }
+            else
+            {
+                File file = new File( exportFile );
+                if ( !file.getParentFile().canWrite() )
+                {
+                    displayErrorMessage( "The selected file is not writable." );
+                    return;
+                }
+            }
+        }
+
+        displayErrorMessage( null );
+    }
+
+
+    /**
+     * Displays an error message and set the page status as incomplete
+     * if the message is not null.
+     *
+     * @param message
+     *      the message to display
+     */
+    private void displayErrorMessage( String message )
+    {
+        setErrorMessage( message );
+        setPageComplete( message == null );
+    }
+
+
+    /**
+     * Gets the selected schemas.
+     *
+     * @return
+     *      the selected schemas
+     */
+    public Schema[] getSelectedSchemas()
+    {
+        Object[] selectedSchemas = schemasTableViewer.getCheckedElements();
+
+        List<Schema> schemas = new ArrayList<Schema>();
+        for ( Object schema : selectedSchemas )
+        {
+            schemas.add( ( Schema ) schema );
+        }
+
+        return schemas.toArray( new Schema[0] );
+    }
+
+
+    /**
+     * Gets the type of export.
+     * <p>
+     * Values can either EXPORT_MULTIPLE_FILES or EXPORT_SINGLE_FILE.
+     * 
+     * @return
+     *      the type of export
+     */
+    public int getExportType()
+    {
+        if ( exportMultipleFilesRadio.getSelection() )
+        {
+            return EXPORT_MULTIPLE_FILES;
+        }
+        else if ( exportSingleFileRadio.getSelection() )
+        {
+            return EXPORT_SINGLE_FILE;
+        }
+
+        // Default 
+        return EXPORT_MULTIPLE_FILES;
+    }
+
+
+    /**
+     * Gets the export directory.
+     *
+     * @return
+     *      the export directory
+     */
+    public String getExportDirectory()
+    {
+        return exportMultipleFilesText.getText();
+    }
+
+
+    /**
+     * Gets the export file.
+     *
+     * @return
+     *      the export file
+     */
+    public String getExportFile()
+    {
+        return exportSingleFileText.getText();
+    }
+}



Mime
View raw message