You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2007/07/11 18:11:42 UTC
svn commit: r555322 - in
/directory/studio/trunk/studio-apacheds-schemaeditor: ./
src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/
Author: pamarcelot
Date: Wed Jul 11 09:11:41 2007
New Revision: 555322
URL: http://svn.apache.org/viewvc?view=rev&rev=555322
Log:
Added a new Export wizard for schemas as OpenLdap files.
Added:
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizard.java
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizardPage.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/view/wizards/ExportSchemasAsXmlWizardPage.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=555322&r1=555321&r2=555322
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/plugin.xml Wed Jul 11 09:11:41 2007
@@ -105,7 +105,14 @@
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">
+ name="Export schemas as XML file(s)">
+ </wizard>
+ <wizard
+ category="org.apache.directory.studio.apacheds.schemaeditor.exportWizardCategory"
+ class="org.apache.directory.studio.apacheds.schemaeditor.view.wizards.ExportSchemasAsOpenLdapWizard"
+ icon="resources/icons/schemas_export.gif"
+ id="org.apache.directory.studio.apacheds.schemaeditor.wizards.ExportSchemasAsOpenLdapWizard"
+ name="Export schemas as OpenLdap files">
</wizard>
</extension>
</plugin>
Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizard.java?view=auto&rev=555322
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizard.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizard.java Wed Jul 11 09:11:41 2007
@@ -0,0 +1,120 @@
+/*
+ * 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 java.lang.reflect.InvocationTargetException;
+
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
+import org.apache.directory.studio.apacheds.schemaeditor.model.io.OpenLdapSchemaFileExporter;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+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 OpenLdap format.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExportSchemasAsOpenLdapWizard extends Wizard implements IExportWizard
+{
+ // The pages of the wizard
+ private ExportSchemasAsOpenLdapWizardPage page;
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#addPages()
+ */
+ public void addPages()
+ {
+ // Creating pages
+ page = new ExportSchemasAsOpenLdapWizardPage();
+
+ // Adding pages
+ addPage( page );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ public boolean performFinish()
+ {
+ final Schema[] selectedSchemas = page.getSelectedSchemas();
+
+ final String exportDirectory = page.getExportDirectory();
+ try
+ {
+ getContainer().run( true, true, new IRunnableWithProgress()
+ {
+ public void run( IProgressMonitor monitor )
+ {
+ monitor.beginTask( "Exporting schemas: ", selectedSchemas.length );
+ for ( Schema schema : selectedSchemas )
+ {
+ monitor.subTask( schema.getName() );
+
+ try
+ {
+ BufferedWriter buffWriter = new BufferedWriter( new FileWriter( exportDirectory + "/"
+ + schema.getName() + ".schema" ) );
+ buffWriter.write( OpenLdapSchemaFileExporter.toSourceCode( schema ) );
+ buffWriter.close();
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ monitor.worked( 1 );
+ }
+ monitor.done();
+ }
+ } );
+ }
+ catch ( InvocationTargetException e )
+ {
+ // Nothing to do (it will never occur)
+ }
+ catch ( InterruptedException e )
+ {
+ // Nothing to do.
+ }
+
+ 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( true );
+ }
+}
Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizardPage.java?view=auto&rev=555322
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizardPage.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsOpenLdapWizardPage.java Wed Jul 11 09:11:41 2007
@@ -0,0 +1,331 @@
+/*
+ * 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.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 ExportSchemasAsOpenLdapWizard.
+ * <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 ExportSchemasAsOpenLdapWizardPage extends WizardPage
+{
+ /** The SchemaHandler */
+ private SchemaHandler schemaHandler;
+
+ // UI Fields
+ private CheckboxTableViewer schemasTableViewer;
+ private Button schemasTableSelectAllButton;
+ private Button schemasTableDeselectAllButton;
+ private Label exportDirectoryLabel;
+ private Text exportDirectoryText;
+ private Button exportDirectoryButton;
+
+
+ /**
+ * Creates a new instance of ExportSchemasAsXmlWizardPage.
+ */
+ protected ExportSchemasAsOpenLdapWizardPage()
+ {
+ super( "ExportSchemasAsOpenLdapWizardPage" );
+ setTitle( "Export schemas as OpenLdap files" );
+ setDescription( "Please select the schemas to export as OpenLdap files." );
+ 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 = 125;
+ 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( 3, false ) );
+ exportDestinationGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+
+ exportDirectoryLabel = new Label( exportDestinationGroup, SWT.NONE );
+ exportDirectoryLabel.setText( "Directory:" );
+ exportDirectoryText = new Text( exportDestinationGroup, SWT.BORDER );
+ exportDirectoryText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+ exportDirectoryText.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ dialogChanged();
+ }
+ } );
+ exportDirectoryButton = new Button( exportDestinationGroup, SWT.PUSH );
+ exportDirectoryButton.setText( "Browse..." );
+ exportDirectoryButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ chooseExportDirectory();
+ dialogChanged();
+ }
+ } );
+
+ initFields();
+
+ setControl( composite );
+ }
+
+
+ /**
+ * Initializes the UI Fields.
+ */
+ private void initFields()
+ {
+ // Filling the Schemas table
+ schemasTableViewer.setInput( schemaHandler.getSchemas() );
+
+ displayErrorMessage( null );
+ setPageComplete( false );
+ }
+
+
+ /**
+ * 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 )
+ {
+ exportDirectoryText.setText( selectedDirectory );
+ }
+ }
+
+
+ /**
+ * 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 Directory
+ String directory = exportDirectoryText.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;
+ }
+ }
+
+ 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 export directory.
+ *
+ * @return
+ * the export directory
+ */
+ public String getExportDirectory()
+ {
+ return exportDirectoryText.getText();
+ }
+}
Modified: 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=diff&rev=555322&r1=555321&r2=555322
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java Wed Jul 11 09:11:41 2007
@@ -73,19 +73,17 @@
// UI Fields
private CheckboxTableViewer schemasTableViewer;
+ private Button schemasTableSelectAllButton;
+ private Button schemasTableDeselectAllButton;
private Button exportMultipleFilesRadio;
private Label exportMultipleFilesLabel;
private Text exportMultipleFilesText;
- private Button exportMultipleFilewButton;
+ private Button exportMultipleFilesButton;
private Button exportSingleFileRadio;
private Label exportSingleFileLabel;
private Text exportSingleFileText;
private Button exportSingleFileButton;
- private Button schemasTableSelectAllButton;
-
- private Button schemasTableDeselectAllButton;
-
/**
* Creates a new instance of ExportSchemasAsXmlWizardPage.
@@ -93,8 +91,8 @@
protected ExportSchemasAsXmlWizardPage()
{
super( "ExportSchemasAsXmlWizardPage" );
- setTitle( "Export schemas as XML" );
- setDescription( "Please select the schemas to export as XML." );
+ setTitle( "Export schemas as XML file(s)" );
+ setDescription( "Please select the schemas to export as XML file(s)." );
setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
PluginConstants.IMG_SCHEMAS_EXPORT_WIZARD ) );
schemaHandler = Activator.getDefault().getSchemaHandler();
@@ -123,7 +121,7 @@
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;
+ schemasTableViewerGridData.heightHint = 125;
schemasTableViewer.getTable().setLayoutData( schemasTableViewerGridData );
schemasTableViewer.setContentProvider( new ArrayContentProvider() );
schemasTableViewer.setLabelProvider( new LabelProvider()
@@ -219,9 +217,9 @@
dialogChanged();
}
} );
- exportMultipleFilewButton = new Button( exportDestinationGroup, SWT.PUSH );
- exportMultipleFilewButton.setText( "Browse..." );
- exportMultipleFilewButton.addSelectionListener( new SelectionAdapter()
+ exportMultipleFilesButton = new Button( exportDestinationGroup, SWT.PUSH );
+ exportMultipleFilesButton.setText( "Browse..." );
+ exportMultipleFilesButton.addSelectionListener( new SelectionAdapter()
{
public void widgetSelected( SelectionEvent e )
{
@@ -299,7 +297,7 @@
exportMultipleFilesRadio.setSelection( true );
exportMultipleFilesLabel.setEnabled( true );
exportMultipleFilesText.setEnabled( true );
- exportMultipleFilewButton.setEnabled( true );
+ exportMultipleFilesButton.setEnabled( true );
exportSingleFileRadio.setSelection( false );
exportSingleFileLabel.setEnabled( false );
@@ -316,7 +314,7 @@
exportMultipleFilesRadio.setSelection( false );
exportMultipleFilesLabel.setEnabled( false );
exportMultipleFilesText.setEnabled( false );
- exportMultipleFilewButton.setEnabled( false );
+ exportMultipleFilesButton.setEnabled( false );
exportSingleFileRadio.setSelection( true );
exportSingleFileLabel.setEnabled( true );