You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by fe...@apache.org on 2007/11/05 15:32:32 UTC
svn commit: r592014 [4/6] - in /directory/sandbox/felixk:
studio-apacheds-configuration-feature/
studio-apacheds-configuration-feature/META-INF/
studio-apacheds-configuration-help/
studio-apacheds-configuration-help/META-INF/ studio-apacheds-configurat...
Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorDetailsPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorDetailsPage.java?rev=592014&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorDetailsPage.java (added)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorDetailsPage.java Mon Nov 5 06:32:20 2007
@@ -0,0 +1,263 @@
+/*
+ * 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.editor;
+
+
+import org.apache.directory.studio.apacheds.configuration.model.Interceptor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+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.Text;
+import org.eclipse.ui.forms.IDetailsPage;
+import org.eclipse.ui.forms.IFormPart;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.forms.widgets.TableWrapData;
+import org.eclipse.ui.forms.widgets.TableWrapLayout;
+
+
+/**
+ * This class represents the Details Page of the Server Configuration Editor for the Interceptor type
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class InterceptorDetailsPage implements IDetailsPage
+{
+ /** The associated Master Details Block */
+ private InterceptorsMasterDetailsBlock masterDetailsBlock;
+
+ /** The Managed Form */
+ private IManagedForm mform;
+
+ /** The input Interceptor */
+ private Interceptor input;
+
+ /** The dirty flag */
+ private boolean dirty = false;
+
+ // UI fields
+ private Text nameText;
+ private Text classText;
+
+ // Listeners
+ /** The Modify Listener for Text Widgets */
+ private ModifyListener textModifyListener = new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ masterDetailsBlock.setEditorDirty();
+ dirty = true;
+ }
+ };
+
+
+ /**
+ * Creates a new instance of InterceptorDetailsPage.
+ *
+ * @param imdb
+ * The associated Master Details Block
+ */
+ public InterceptorDetailsPage( InterceptorsMasterDetailsBlock imdb )
+ {
+ masterDetailsBlock = imdb;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ public void createContents( Composite parent )
+ {
+ FormToolkit toolkit = mform.getToolkit();
+ TableWrapLayout layout = new TableWrapLayout();
+ layout.topMargin = 5;
+ layout.leftMargin = 5;
+ layout.rightMargin = 2;
+ layout.bottomMargin = 2;
+ parent.setLayout( layout );
+
+ createDetailsSection( parent, toolkit );
+ }
+
+
+ /**
+ * Creates the Details Section
+ *
+ * @param parent
+ * the parent composite
+ * @param toolkit
+ * the toolkit to use
+ */
+ private void createDetailsSection( Composite parent, FormToolkit toolkit )
+ {
+ Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR );
+ section.marginWidth = 10;
+ section.setText( "Interceptor Details" ); //$NON-NLS-1$
+ section.setDescription( "Set the properties of the interceptor." ); //$NON-NLS-1$
+ TableWrapData td = new TableWrapData( TableWrapData.FILL, TableWrapData.TOP );
+ td.grabHorizontal = true;
+ section.setLayoutData( td );
+ Composite client = toolkit.createComposite( section );
+ toolkit.paintBordersFor( client );
+ GridLayout glayout = new GridLayout( 3, false );
+ client.setLayout( glayout );
+ section.setClient( client );
+
+ // Name
+ toolkit.createLabel( client, "Name:" );
+ nameText = toolkit.createText( client, "" );
+ nameText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
+
+ // Class
+ toolkit.createLabel( client, "Class:" );
+ classText = toolkit.createText( client, "" );
+ classText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
+ }
+
+
+ /**
+ * Adds listeners to UI fields.
+ */
+ private void addListeners()
+ {
+ nameText.addModifyListener( textModifyListener );
+ classText.addModifyListener( textModifyListener );
+ }
+
+
+ /**
+ * Removes listeners to UI fields.
+ */
+ private void removeListeners()
+ {
+ nameText.removeModifyListener( textModifyListener );
+ classText.removeModifyListener( textModifyListener );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IPartSelectionListener#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged( IFormPart part, ISelection selection )
+ {
+ IStructuredSelection ssel = ( IStructuredSelection ) selection;
+ if ( ssel.size() == 1 )
+ {
+ input = ( Interceptor ) ssel.getFirstElement();
+ }
+ else
+ {
+ input = null;
+ }
+ refresh();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#commit(boolean)
+ */
+ public void commit( boolean onSave )
+ {
+ if ( input != null )
+ {
+ input.setName( nameText.getText() );
+ input.setClassType( classText.getText() );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#dispose()
+ */
+ public void dispose()
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm)
+ */
+ public void initialize( IManagedForm form )
+ {
+ this.mform = form;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#isDirty()
+ */
+ public boolean isDirty()
+ {
+ return dirty;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#isStale()
+ */
+ public boolean isStale()
+ {
+ return false;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#refresh()
+ */
+ public void refresh()
+ {
+ removeListeners();
+
+ // Name
+ String name = input.getName();
+ nameText.setText( ( name == null ) ? "" : name );
+
+ // Class
+ String classType = input.getClassType();
+ classText.setText( ( classType == null ) ? "" : classType );
+
+ addListeners();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#setFocus()
+ */
+ public void setFocus()
+ {
+ nameText.setFocus();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#setFormInput(java.lang.Object)
+ */
+ public boolean setFormInput( Object input )
+ {
+ return false;
+ }
+}
Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorDetailsPage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorsMasterDetailsBlock.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorsMasterDetailsBlock.java?rev=592014&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorsMasterDetailsBlock.java (added)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorsMasterDetailsBlock.java Mon Nov 5 06:32:20 2007
@@ -0,0 +1,395 @@
+/*
+ * 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.editor;
+
+
+import java.util.List;
+
+import org.apache.directory.studio.apacheds.configuration.Activator;
+import org.apache.directory.studio.apacheds.configuration.PluginConstants;
+import org.apache.directory.studio.apacheds.configuration.model.Interceptor;
+import org.apache.directory.studio.apacheds.configuration.model.ServerConfiguration;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+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.Table;
+import org.eclipse.ui.forms.DetailsPart;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.MasterDetailsBlock;
+import org.eclipse.ui.forms.SectionPart;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class represents the Interceptors Master/Details Block used in the Interceptors Page.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class InterceptorsMasterDetailsBlock extends MasterDetailsBlock
+{
+ /** The associated page */
+ private FormPage page;
+
+ /** The input Server Configuration */
+ private ServerConfiguration serverConfiguration;
+
+ /** The Interceptors List */
+ private List<Interceptor> interceptors;
+
+ /** The Details Page */
+ private InterceptorDetailsPage detailsPage;
+
+ private static final String NEW_NAME = "New Interceptor ";
+
+ // UI Fields
+ private TableViewer viewer;
+ private Button addButton;
+ private Button deleteButton;
+ private Button upButton;
+ private Button downButton;
+
+
+ /**
+ * Creates a new instance of InterceptorsMasterDetailsBlock.
+ *
+ * @param page
+ */
+ public InterceptorsMasterDetailsBlock( FormPage page )
+ {
+ this.page = page;
+ serverConfiguration = ( ( ServerConfigurationEditorInput ) page.getEditorInput() ).getServerConfiguration();
+ interceptors = serverConfiguration.getInterceptors();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.MasterDetailsBlock#createMasterPart(org.eclipse.ui.forms.IManagedForm, org.eclipse.swt.widgets.Composite)
+ */
+ protected void createMasterPart( final IManagedForm managedForm, Composite parent )
+ {
+ FormToolkit toolkit = managedForm.getToolkit();
+
+ // Creating the Section
+ Section section = toolkit.createSection( parent, Section.TITLE_BAR | Section.DESCRIPTION );
+ section.setText( "All Interceptors" );
+ section
+ .setDescription( " Set the Interceptors used in the server. Use the \"Up\" and \"Down\" buttons to change the order." );
+ section.marginWidth = 10;
+ section.marginHeight = 5;
+ Composite client = toolkit.createComposite( section, SWT.WRAP );
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.makeColumnsEqualWidth = false;
+ layout.marginWidth = 2;
+ layout.marginHeight = 2;
+ client.setLayout( layout );
+ toolkit.paintBordersFor( client );
+ section.setClient( client );
+
+ // Creatig the Table and Table Viewer
+ Table table = toolkit.createTable( client, SWT.NULL );
+ GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 4 );
+ gd.heightHint = 20;
+ gd.widthHint = 100;
+ table.setLayoutData( gd );
+ final SectionPart spart = new SectionPart( section );
+ managedForm.addPart( spart );
+ viewer = new TableViewer( table );
+ viewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ managedForm.fireSelectionChanged( spart, event.getSelection() );
+ }
+ } );
+ viewer.setContentProvider( new ArrayContentProvider() );
+ viewer.setLabelProvider( new LabelProvider()
+ {
+ public Image getImage( Object element )
+ {
+ return AbstractUIPlugin
+ .imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_INTERCEPTOR ).createImage();
+ }
+ } );
+
+ // Creating the button(s)
+ addButton = toolkit.createButton( client, "Add...", SWT.PUSH ); //$NON-NLS-1$
+ addButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+
+ deleteButton = toolkit.createButton( client, "Delete", SWT.PUSH );
+ deleteButton.setEnabled( false );
+ deleteButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+
+ upButton = toolkit.createButton( client, "Up", SWT.PUSH );
+ upButton.setEnabled( false );
+ upButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+
+ downButton = toolkit.createButton( client, "Down", SWT.PUSH );
+ downButton.setEnabled( false );
+ downButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+
+ initFromInput();
+ addListeners();
+ }
+
+
+ /**
+ * Initializes the page with the Editor input.
+ */
+ private void initFromInput()
+ {
+ viewer.setInput( interceptors );
+ }
+
+
+ /**
+ * Add listeners to UI fields.
+ */
+ private void addListeners()
+ {
+ viewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ viewer.refresh();
+
+ deleteButton.setEnabled( !event.getSelection().isEmpty() );
+
+ enableDisableUpDownButtons();
+ }
+ } );
+
+ addButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ Interceptor newInterceptor = new Interceptor( getNewName() );
+ interceptors.add( newInterceptor );
+ viewer.refresh();
+ viewer.setSelection( new StructuredSelection( newInterceptor ) );
+ setEditorDirty();
+ }
+ } );
+
+ deleteButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ StructuredSelection selection = ( StructuredSelection ) viewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ Interceptor interceptor = ( Interceptor ) selection.getFirstElement();
+
+ interceptors.remove( interceptor );
+ viewer.refresh();
+ setEditorDirty();
+ }
+ }
+ } );
+
+ upButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ StructuredSelection selection = ( StructuredSelection ) viewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ Interceptor interceptor = ( Interceptor ) selection.getFirstElement();
+
+ int index = interceptors.indexOf( interceptor );
+ if ( index > 0 )
+ {
+ Interceptor interceptorBefore = interceptors.get( index - 1 );
+ if ( interceptorBefore != null )
+ {
+ interceptors.set( index - 1, interceptor );
+ interceptors.set( index, interceptorBefore );
+
+ viewer.refresh();
+ setEditorDirty();
+ enableDisableUpDownButtons();
+ }
+ }
+ }
+ }
+ } );
+
+ downButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ StructuredSelection selection = ( StructuredSelection ) viewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ Interceptor interceptor = ( Interceptor ) selection.getFirstElement();
+
+ int index = interceptors.indexOf( interceptor );
+ if ( index < ( interceptors.size() - 1 ) )
+ {
+ Interceptor interceptorAfter = interceptors.get( index + 1 );
+ if ( interceptorAfter != null )
+ {
+ interceptors.set( index + 1, interceptor );
+ interceptors.set( index, interceptorAfter );
+
+ viewer.refresh();
+ setEditorDirty();
+ enableDisableUpDownButtons();
+ }
+ }
+ }
+ }
+ } );
+ }
+
+
+ /**
+ * Gets a new Name for a new Extended Operation.
+ *
+ * @return
+ * a new Name for a new Extended Operation
+ */
+ private String getNewName()
+ {
+ int counter = 1;
+ String name = NEW_NAME;
+ boolean ok = false;
+
+ while ( !ok )
+ {
+ ok = true;
+ name = NEW_NAME + counter;
+
+ for ( Interceptor interceptor : interceptors )
+ {
+ if ( interceptor.getName().equalsIgnoreCase( name ) )
+ {
+ ok = false;
+ }
+ }
+
+ counter++;
+ }
+
+ return name;
+ }
+
+
+ /**
+ * Enables or Disables the Up and Down Buttons.
+ */
+ private void enableDisableUpDownButtons()
+ {
+ StructuredSelection selection = ( StructuredSelection ) viewer.getSelection();
+
+ upButton.setEnabled( !selection.isEmpty() );
+ downButton.setEnabled( !selection.isEmpty() );
+ if ( !selection.isEmpty() )
+ {
+ Interceptor interceptor = ( Interceptor ) selection.getFirstElement();
+ upButton.setEnabled( interceptors.indexOf( interceptor ) != 0 );
+ downButton.setEnabled( interceptors.indexOf( interceptor ) != ( interceptors.size() - 1 ) );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.MasterDetailsBlock#createToolBarActions(org.eclipse.ui.forms.IManagedForm)
+ */
+ protected void createToolBarActions( IManagedForm managedForm )
+ {
+ final ScrolledForm form = managedForm.getForm();
+
+ // Horizontal layout Action
+ Action horizontalAction = new Action( "Horizontal layout", Action.AS_RADIO_BUTTON ) { //$NON-NLS-1$
+ public void run()
+ {
+ sashForm.setOrientation( SWT.HORIZONTAL );
+ form.reflow( true );
+ }
+ };
+ horizontalAction.setChecked( true );
+ horizontalAction.setToolTipText( "Horizontal Orientation" ); //$NON-NLS-1$
+ horizontalAction.setImageDescriptor( Activator.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+ PluginConstants.IMG_HORIZONTAL_ORIENTATION ) );
+
+ // Vertical layout Action
+ Action verticalAction = new Action( "Vertical Orientation", Action.AS_RADIO_BUTTON ) { //$NON-NLS-1$
+ public void run()
+ {
+ sashForm.setOrientation( SWT.VERTICAL );
+ form.reflow( true );
+ }
+ };
+ verticalAction.setChecked( false );
+ verticalAction.setToolTipText( "Vertical Orientation" ); //$NON-NLS-1$
+ verticalAction.setImageDescriptor( Activator.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+ PluginConstants.IMG_VERTICAL_ORIENTATION ) );
+
+ form.getToolBarManager().add( horizontalAction );
+ form.getToolBarManager().add( verticalAction );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.MasterDetailsBlock#registerPages(org.eclipse.ui.forms.DetailsPart)
+ */
+ protected void registerPages( DetailsPart detailsPart )
+ {
+ detailsPage = new InterceptorDetailsPage( this );
+ detailsPart.registerPage( Interceptor.class, detailsPage );
+ }
+
+
+ /**
+ * Sets the Editor as dirty.
+ */
+ public void setEditorDirty()
+ {
+ ( ( ServerConfigurationEditor ) page.getEditor() ).setDirty( true );
+ }
+
+
+ /**
+ * Saves the necessary elements to the input model.
+ */
+ public void save()
+ {
+ detailsPage.commit( true );
+ viewer.setInput( interceptors );
+ }
+}
Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorsMasterDetailsBlock.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorsPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorsPage.java?rev=592014&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorsPage.java (added)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorsPage.java Mon Nov 5 06:32:20 2007
@@ -0,0 +1,81 @@
+/*
+ * 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.editor;
+
+
+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.ScrolledForm;
+
+
+/**
+ * This class represents the Interceptors Page of the Server Configuration Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class InterceptorsPage extends FormPage
+{
+ /** The Page ID*/
+ public static final String ID = ServerConfigurationEditor.ID + ".InterceptorsPage";
+
+ /** The Page Title */
+ private static final String TITLE = "Interceptors";
+
+ /** The Master/Details Block */
+ private InterceptorsMasterDetailsBlock masterDetailsBlock;
+
+
+ /**
+ * Creates a new instance of InterceptorsPage.
+ *
+ * @param editor
+ * the associated editor
+ */
+ public InterceptorsPage( FormEditor editor )
+ {
+ super( editor, ID, TITLE );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
+ */
+ protected void createFormContent( IManagedForm managedForm )
+ {
+ final ScrolledForm form = managedForm.getForm();
+ form.setText( "Interceptors" );
+ masterDetailsBlock = new InterceptorsMasterDetailsBlock( this );
+ masterDetailsBlock.createContent( managedForm );
+ }
+
+
+ /**
+ * Saves the necessary elements to the input model.
+ */
+ public void save()
+ {
+ if ( masterDetailsBlock != null )
+ {
+ masterDetailsBlock.save();
+ }
+ }
+}
Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/InterceptorsPage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionDetailsPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionDetailsPage.java?rev=592014&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionDetailsPage.java (added)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionDetailsPage.java Mon Nov 5 06:32:20 2007
@@ -0,0 +1,801 @@
+/*
+ * 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.editor;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+
+import org.apache.directory.studio.apacheds.configuration.dialogs.AttributeValueDialog;
+import org.apache.directory.studio.apacheds.configuration.dialogs.IndexedAttributeDialog;
+import org.apache.directory.studio.apacheds.configuration.model.IndexedAttribute;
+import org.apache.directory.studio.apacheds.configuration.model.Partition;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+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.events.SelectionListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+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.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.IDetailsPage;
+import org.eclipse.ui.forms.IFormPart;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.forms.widgets.TableWrapData;
+import org.eclipse.ui.forms.widgets.TableWrapLayout;
+
+
+/**
+ * This class represents the Details Page of the Server Configuration Editor for the Partition type
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PartitionDetailsPage implements IDetailsPage
+{
+ /** The associated Master Details Block */
+ private PartitionsMasterDetailsBlock masterDetailsBlock;
+
+ /** The Managed Form */
+ private IManagedForm mform;
+
+ /** The input Partition */
+ private Partition input;
+
+ /** The Context Entry */
+ private Attributes contextEntry;
+
+ /** The Indexed Attributes List */
+ private List<IndexedAttribute> indexedAttributes;
+
+ /** The dirty flag */
+ private boolean dirty = false;
+
+ // UI fields
+ private Text nameText;
+ private Text cacheSizeText;
+ private Text suffixText;
+ private Button enableOptimizerCheckbox;
+ private Button synchOnWriteCheckbox;
+ private Table contextEntryTable;
+ private TableViewer contextEntryTableViewer;
+ private Button contextEntryAddButton;
+ private Button contextEntryEditButton;
+ private Button contextEntryDeleteButton;
+ private TableViewer indexedAttributesTableViewer;
+ private Button indexedAttributeAddButton;
+ private Button indexedAttributeEditButton;
+ private Button indexedAttributeDeleteButton;
+
+ // Listeners
+ /** The Text Modify Listener */
+ private ModifyListener textModifyListener = new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ masterDetailsBlock.setEditorDirty();
+ dirty = true;
+ }
+ };
+
+ /** The Checkbox Selection Listener */
+ private SelectionListener checkboxSelectionListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ masterDetailsBlock.setEditorDirty();
+ dirty = true;
+ }
+ };
+
+ /** The Selection Changed Listener for the Context Entry Table Viewer */
+ private ISelectionChangedListener contextEntryTableViewerListener = new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ contextEntryEditButton.setEnabled( !event.getSelection().isEmpty() );
+ contextEntryDeleteButton.setEnabled( !event.getSelection().isEmpty() );
+ }
+ };
+
+ /** The Double Click Listener for the Indexed Attributes Table Viewer */
+ private IDoubleClickListener contextEntryTableViewerDoubleClickListener = new IDoubleClickListener()
+ {
+ public void doubleClick( DoubleClickEvent event )
+ {
+ editSelectedContextEntry();
+ }
+ };
+
+ /** The Listener for the Add button of the Context Entry Section */
+ private SelectionListener contextEntryAddButtonListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ AttributeValueDialog dialog = new AttributeValueDialog( new AttributeValueObject( "", "" ) );
+ if ( Dialog.OK == dialog.open() && dialog.isDirty() )
+ {
+ AttributeValueObject newAttributeValueObject = dialog.getAttributeValueObject();
+ Attribute attribute = contextEntry.get( newAttributeValueObject.getAttribute() );
+ if ( attribute != null )
+ {
+ attribute.add( newAttributeValueObject.getValue() );
+ }
+ else
+ {
+ contextEntry.put( new BasicAttribute( newAttributeValueObject.getAttribute(),
+ newAttributeValueObject.getValue() ) );
+ }
+
+ contextEntryTableViewer.refresh();
+ resizeContextEntryTableColumnsToFit();
+ masterDetailsBlock.setEditorDirty();
+ dirty = true;
+ }
+ }
+ };
+
+ /** The Listener for the Edit button of the Context Entry Section */
+ private SelectionListener contextEntryEditButtonListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ editSelectedContextEntry();
+ }
+ };
+
+ /** The Listener for the Delete button of the Context Entry Section */
+ private SelectionListener contextEntryDeleteButtonListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ StructuredSelection selection = ( StructuredSelection ) contextEntryTableViewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ AttributeValueObject attributeValueObject = ( AttributeValueObject ) selection.getFirstElement();
+
+ Attribute attribute = contextEntry.get( attributeValueObject.getAttribute() );
+ if ( attribute != null )
+ {
+ attribute.remove( attributeValueObject.getValue() );
+ contextEntryTableViewer.refresh();
+ resizeContextEntryTableColumnsToFit();
+ masterDetailsBlock.setEditorDirty();
+ dirty = true;
+ }
+ }
+ }
+ };
+
+ /** The Selection Changed Listener for the Indexed Attributes Table Viewer */
+ private ISelectionChangedListener indexedAttributesTableViewerListener = new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ indexedAttributeEditButton.setEnabled( !event.getSelection().isEmpty() );
+ indexedAttributeDeleteButton.setEnabled( !event.getSelection().isEmpty() );
+ }
+ };
+
+ /** The Double Click Listener for the Indexed Attributes Table Viewer */
+ private IDoubleClickListener indexedAttributesTableViewerDoubleClickListener = new IDoubleClickListener()
+ {
+ public void doubleClick( DoubleClickEvent event )
+ {
+ editSelectedIndexedAttribute();
+ }
+ };
+
+ /** The Listener for the Add button of the Indexed Attributes Section */
+ private SelectionListener indexedAttributeAddButtonListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ IndexedAttributeDialog dialog = new IndexedAttributeDialog( new IndexedAttribute( "", 0 ) );
+ if ( Dialog.OK == dialog.open() )
+ {
+ indexedAttributes.add( dialog.getIndexedAttribute() );
+ indexedAttributesTableViewer.refresh();
+ masterDetailsBlock.setEditorDirty();
+ dirty = true;
+ }
+ }
+ };
+
+ /** The Listener for the Edit button of the Indexed Attributes Section */
+ private SelectionListener indexedAttributeEditButtonListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ editSelectedIndexedAttribute();
+ }
+ };
+
+ /** The Listener for the Delete button of the Indexed Attributes Section */
+ private SelectionListener indexedAttributeDeleteButtonListener = new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ StructuredSelection selection = ( StructuredSelection ) indexedAttributesTableViewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ IndexedAttribute indexedAttribute = ( IndexedAttribute ) selection.getFirstElement();
+
+ indexedAttributes.remove( indexedAttribute );
+ indexedAttributesTableViewer.refresh();
+ masterDetailsBlock.setEditorDirty();
+ dirty = true;
+ }
+ }
+ };
+
+
+ /**
+ * Creates a new instance of PartitionDetailsPage.
+ *
+ * @param pmdb
+ * the associated Master Details Block
+ */
+ public PartitionDetailsPage( PartitionsMasterDetailsBlock pmdb )
+ {
+ masterDetailsBlock = pmdb;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ public void createContents( Composite parent )
+ {
+ FormToolkit toolkit = mform.getToolkit();
+ TableWrapLayout layout = new TableWrapLayout();
+ layout.topMargin = 5;
+ layout.leftMargin = 5;
+ layout.rightMargin = 2;
+ layout.bottomMargin = 2;
+ parent.setLayout( layout );
+
+ createDetailsSection( parent, toolkit );
+ createContextEntrySection( parent, toolkit );
+ createIndexedAttributesSection( parent, toolkit );
+ }
+
+
+ /**
+ * Creates the Details Section
+ *
+ * @param parent
+ * the parent composite
+ * @param toolkit
+ * the toolkit to use
+ */
+ private void createDetailsSection( Composite parent, FormToolkit toolkit )
+ {
+ Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR );
+ section.marginWidth = 10;
+ section.setText( "Partition Details" ); //$NON-NLS-1$
+ section.setDescription( "Set the properties of the partition." ); //$NON-NLS-1$
+ TableWrapData td = new TableWrapData( TableWrapData.FILL, TableWrapData.TOP );
+ td.grabHorizontal = true;
+ section.setLayoutData( td );
+ Composite client = toolkit.createComposite( section );
+ toolkit.paintBordersFor( client );
+ GridLayout glayout = new GridLayout( 3, false );
+ client.setLayout( glayout );
+ section.setClient( client );
+
+ // Name
+ toolkit.createLabel( client, "Name:" );
+ nameText = toolkit.createText( client, "" );
+ nameText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
+
+ // Cache Size
+ toolkit.createLabel( client, "Cache Size:" );
+ cacheSizeText = toolkit.createText( client, "" );
+ cacheSizeText.addVerifyListener( new VerifyListener()
+ {
+ public void verifyText( VerifyEvent e )
+ {
+ if ( !e.text.matches( "[0-9]*" ) ) //$NON-NLS-1$
+ {
+ e.doit = false;
+ }
+ }
+ } );
+ cacheSizeText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
+
+ // Suffix
+ toolkit.createLabel( client, "Suffix:" );
+ suffixText = toolkit.createText( client, "" );
+ suffixText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
+
+ // Enable Optimizer
+ enableOptimizerCheckbox = toolkit.createButton( client, "Enable optimizer", SWT.CHECK );
+ enableOptimizerCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 3, 1 ) );
+
+ // Synchronisation On Write
+ synchOnWriteCheckbox = toolkit.createButton( client, "Synchronization on write", SWT.CHECK );
+ synchOnWriteCheckbox.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 3, 1 ) );
+ }
+
+
+ /**
+ * Creates the Context Entry Section.
+ *
+ * @param parent
+ * the parent composite
+ * @param toolkit
+ * the toolkit to use
+ */
+ private void createContextEntrySection( Composite parent, FormToolkit toolkit )
+ {
+ Section section = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR );
+ section.marginWidth = 10;
+ section.setText( "Context Entry" ); //$NON-NLS-1$
+ section.setDescription( "Set the attribute/value pairs for the Context Entry of the partition." ); //$NON-NLS-1$
+ section.setLayoutData( new TableWrapData( TableWrapData.FILL ) );
+ Composite client = toolkit.createComposite( section );
+ toolkit.paintBordersFor( client );
+ client.setLayout( new GridLayout( 2, false ) );
+ section.setClient( client );
+
+ contextEntryTable = toolkit.createTable( client, SWT.NONE );
+ GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 3 );
+ gd.heightHint = 103;
+ contextEntryTable.setLayoutData( gd );
+ TableColumn idColumn = new TableColumn( contextEntryTable, SWT.LEFT, 0 );
+ idColumn.setText( "Attribute" );
+ idColumn.setWidth( 100 );
+ TableColumn valueColumn = new TableColumn( contextEntryTable, SWT.LEFT, 1 );
+ valueColumn.setText( "Value" );
+ valueColumn.setWidth( 100 );
+ contextEntryTable.setHeaderVisible( true );
+ contextEntryTableViewer = new TableViewer( contextEntryTable );
+ contextEntryTableViewer.setContentProvider( new IStructuredContentProvider()
+ {
+ public Object[] getElements( Object inputElement )
+ {
+ List<AttributeValueObject> elements = new ArrayList<AttributeValueObject>();
+
+ Attributes attributes = ( Attributes ) inputElement;
+
+ NamingEnumeration<? extends Attribute> ne = attributes.getAll();
+ while ( ne.hasMoreElements() )
+ {
+ Attribute attribute = ( Attribute ) ne.nextElement();
+ try
+ {
+ NamingEnumeration<?> values = attribute.getAll();
+ while ( values.hasMoreElements() )
+ {
+ elements.add( new AttributeValueObject( attribute.getID(), values.nextElement() ) );
+ }
+ }
+ catch ( NamingException e )
+ {
+ }
+ }
+
+ return elements.toArray();
+ }
+
+
+ public void dispose()
+ {
+ }
+
+
+ public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+ {
+ }
+ } );
+ contextEntryTableViewer.setLabelProvider( new ITableLabelProvider()
+ {
+ public String getColumnText( Object element, int columnIndex )
+ {
+ if ( element != null )
+ {
+ switch ( columnIndex )
+ {
+ case 0:
+ return ( ( AttributeValueObject ) element ).getAttribute();
+ case 1:
+ return ( ( AttributeValueObject ) element ).getValue().toString();
+ default:
+ break;
+ }
+ }
+
+ return null;
+ }
+
+
+ public Image getColumnImage( Object element, int columnIndex )
+ {
+ return null;
+ }
+
+
+ public void addListener( ILabelProviderListener listener )
+ {
+ }
+
+
+ public void dispose()
+ {
+ }
+
+
+ public boolean isLabelProperty( Object element, String property )
+ {
+ return false;
+ }
+
+
+ public void removeListener( ILabelProviderListener listener )
+ {
+ }
+ } );
+
+ GridData buttonsGD = new GridData( SWT.FILL, SWT.BEGINNING, false, false );
+ buttonsGD.widthHint = IDialogConstants.BUTTON_WIDTH;
+
+ contextEntryAddButton = toolkit.createButton( client, "Add...", SWT.PUSH );
+ contextEntryAddButton.setLayoutData( buttonsGD );
+
+ contextEntryEditButton = toolkit.createButton( client, "Edit...", SWT.PUSH );
+ contextEntryEditButton.setEnabled( false );
+ contextEntryEditButton.setLayoutData( buttonsGD );
+
+ contextEntryDeleteButton = toolkit.createButton( client, "Delete", SWT.PUSH );
+ contextEntryDeleteButton.setEnabled( false );
+ contextEntryDeleteButton.setLayoutData( buttonsGD );
+ }
+
+
+ /**
+ * Creates the Indexed Attributes Section
+ *
+ * @param parent
+ * the parent composite
+ * @param toolkit
+ * the toolkit to use
+ */
+ private void createIndexedAttributesSection( Composite parent, FormToolkit toolkit )
+ {
+ Section indexedAttributesSection = toolkit.createSection( parent, Section.DESCRIPTION | Section.TITLE_BAR );
+ indexedAttributesSection.marginWidth = 10;
+ indexedAttributesSection.setText( "Indexed Attributes" ); //$NON-NLS-1$
+ indexedAttributesSection.setDescription( "Set the indexed attributes of the partition." ); //$NON-NLS-1$
+ indexedAttributesSection.setLayoutData( new TableWrapData( TableWrapData.FILL ) );
+ Composite indexedAttributesClient = toolkit.createComposite( indexedAttributesSection );
+ toolkit.paintBordersFor( indexedAttributesClient );
+ indexedAttributesClient.setLayout( new GridLayout( 2, false ) );
+ indexedAttributesSection.setClient( indexedAttributesClient );
+
+ Table indexedAttributesTable = toolkit.createTable( indexedAttributesClient, SWT.NONE );
+ GridData gd = new GridData( SWT.FILL, SWT.NONE, true, false, 1, 3 );
+ gd.heightHint = 80;
+ indexedAttributesTable.setLayoutData( gd );
+ indexedAttributesTableViewer = new TableViewer( indexedAttributesTable );
+ indexedAttributesTableViewer.setContentProvider( new ArrayContentProvider() );
+ indexedAttributesTableViewer.setLabelProvider( new LabelProvider() );
+
+ GridData buttonsGD = new GridData( SWT.FILL, SWT.BEGINNING, false, false );
+ buttonsGD.widthHint = IDialogConstants.BUTTON_WIDTH;
+
+ indexedAttributeAddButton = toolkit.createButton( indexedAttributesClient, "Add...", SWT.PUSH );
+ indexedAttributeAddButton.setLayoutData( buttonsGD );
+
+ indexedAttributeEditButton = toolkit.createButton( indexedAttributesClient, "Edit...", SWT.PUSH );
+ indexedAttributeEditButton.setEnabled( false );
+ indexedAttributeEditButton.setLayoutData( buttonsGD );
+
+ indexedAttributeDeleteButton = toolkit.createButton( indexedAttributesClient, "Delete", SWT.PUSH );
+ indexedAttributeDeleteButton.setEnabled( false );
+ indexedAttributeDeleteButton.setLayoutData( buttonsGD );
+ }
+
+
+ /**
+ * Adds listeners to UI fields.
+ */
+ private void addListeners()
+ {
+ nameText.addModifyListener( textModifyListener );
+ cacheSizeText.addModifyListener( textModifyListener );
+ suffixText.addModifyListener( textModifyListener );
+ enableOptimizerCheckbox.addSelectionListener( checkboxSelectionListener );
+ synchOnWriteCheckbox.addSelectionListener( checkboxSelectionListener );
+
+ contextEntryTableViewer.addDoubleClickListener( contextEntryTableViewerDoubleClickListener );
+ contextEntryTableViewer.addSelectionChangedListener( contextEntryTableViewerListener );
+ contextEntryAddButton.addSelectionListener( contextEntryAddButtonListener );
+ contextEntryEditButton.addSelectionListener( contextEntryEditButtonListener );
+ contextEntryDeleteButton.addSelectionListener( contextEntryDeleteButtonListener );
+
+ indexedAttributesTableViewer.addSelectionChangedListener( indexedAttributesTableViewerListener );
+ indexedAttributesTableViewer.addDoubleClickListener( indexedAttributesTableViewerDoubleClickListener );
+ indexedAttributeAddButton.addSelectionListener( indexedAttributeAddButtonListener );
+ indexedAttributeEditButton.addSelectionListener( indexedAttributeEditButtonListener );
+ indexedAttributeDeleteButton.addSelectionListener( indexedAttributeDeleteButtonListener );
+ }
+
+
+ /**
+ * Removes listeners to UI fields.
+ */
+ private void removeListeners()
+ {
+ nameText.removeModifyListener( textModifyListener );
+ cacheSizeText.removeModifyListener( textModifyListener );
+ suffixText.removeModifyListener( textModifyListener );
+ enableOptimizerCheckbox.removeSelectionListener( checkboxSelectionListener );
+ synchOnWriteCheckbox.removeSelectionListener( checkboxSelectionListener );
+
+ contextEntryTableViewer.removeDoubleClickListener( contextEntryTableViewerDoubleClickListener );
+ contextEntryTableViewer.removeSelectionChangedListener( contextEntryTableViewerListener );
+ contextEntryAddButton.removeSelectionListener( contextEntryAddButtonListener );
+ contextEntryEditButton.removeSelectionListener( contextEntryEditButtonListener );
+ contextEntryDeleteButton.removeSelectionListener( contextEntryDeleteButtonListener );
+
+ indexedAttributesTableViewer.removeSelectionChangedListener( indexedAttributesTableViewerListener );
+ indexedAttributesTableViewer.removeDoubleClickListener( indexedAttributesTableViewerDoubleClickListener );
+ indexedAttributeAddButton.removeSelectionListener( indexedAttributeAddButtonListener );
+ indexedAttributeEditButton.removeSelectionListener( indexedAttributeEditButtonListener );
+ indexedAttributeDeleteButton.removeSelectionListener( indexedAttributeDeleteButtonListener );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IPartSelectionListener#selectionChanged(org.eclipse.ui.forms.IFormPart, org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged( IFormPart part, ISelection selection )
+ {
+ IStructuredSelection ssel = ( IStructuredSelection ) selection;
+ if ( ssel.size() == 1 )
+ {
+ input = ( Partition ) ssel.getFirstElement();
+ }
+ else
+ {
+ input = null;
+ }
+ refresh();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#commit(boolean)
+ */
+ public void commit( boolean onSave )
+ {
+ if ( input != null )
+ {
+ input.setName( nameText.getText() );
+ input.setCacheSize( Integer.parseInt( cacheSizeText.getText() ) );
+ input.setSuffix( suffixText.getText() );
+ input.setEnableOptimizer( enableOptimizerCheckbox.getSelection() );
+ input.setSynchronizationOnWrite( synchOnWriteCheckbox.getSelection() );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#dispose()
+ */
+ public void dispose()
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm)
+ */
+ public void initialize( IManagedForm form )
+ {
+ this.mform = form;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#isDirty()
+ */
+ public boolean isDirty()
+ {
+ return dirty;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#isStale()
+ */
+ public boolean isStale()
+ {
+ return false;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#refresh()
+ */
+ public void refresh()
+ {
+ removeListeners();
+
+ // Name
+ String name = input.getName();
+ nameText.setText( ( name == null ) ? "" : name );
+
+ // Cache Size
+ cacheSizeText.setText( "" + input.getCacheSize() );
+
+ // Suffix
+ String suffix = input.getSuffix();
+ suffixText.setText( ( suffix == null ) ? "" : suffix );
+
+ // Enable Optimizer
+ enableOptimizerCheckbox.setSelection( input.isEnableOptimizer() );
+
+ // Synchronization on write
+ synchOnWriteCheckbox.setSelection( input.isSynchronizationOnWrite() );
+
+ // Context Entry
+ contextEntry = input.getContextEntry();
+ contextEntryTableViewer.setInput( contextEntry );
+ resizeContextEntryTableColumnsToFit();
+
+ // Indexed Attributes
+ indexedAttributes = input.getIndexedAttributes();
+ indexedAttributesTableViewer.setInput( indexedAttributes );
+
+ addListeners();
+ }
+
+
+ /**
+ * Resizes the columns to fit the size of the cells.
+ */
+ private void resizeContextEntryTableColumnsToFit()
+ {
+ // Resizing the first column
+ contextEntryTable.getColumn( 0 ).pack();
+ // Adding a little space to the first column
+ contextEntryTable.getColumn( 0 ).setWidth( contextEntryTable.getColumn( 0 ).getWidth() + 5 );
+ // Resizing the second column
+ contextEntryTable.getColumn( 1 ).pack();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#setFocus()
+ */
+ public void setFocus()
+ {
+ nameText.setFocus();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.IFormPart#setFormInput(java.lang.Object)
+ */
+ public boolean setFormInput( Object input )
+ {
+ return false;
+ }
+
+
+ /**
+ * Opens an Indexed Attribute Dialog with the selected Indexed Attribute in the
+ * Indexed Attributes Table Viewer.
+ */
+ private void editSelectedIndexedAttribute()
+ {
+ StructuredSelection selection = ( StructuredSelection ) indexedAttributesTableViewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ IndexedAttribute indexedAttribute = ( IndexedAttribute ) selection.getFirstElement();
+
+ IndexedAttributeDialog dialog = new IndexedAttributeDialog( indexedAttribute );
+ if ( Dialog.OK == dialog.open() && dialog.isDirty() )
+ {
+ indexedAttributesTableViewer.refresh();
+ masterDetailsBlock.setEditorDirty();
+ dirty = true;
+ }
+ }
+ }
+
+
+ /**
+ * Opens a Context Entry Dialog with the selected Attribute Value Object in the
+ * Context Entry Table Viewer.
+ */
+ private void editSelectedContextEntry()
+ {
+ StructuredSelection selection = ( StructuredSelection ) contextEntryTableViewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ AttributeValueObject attributeValueObject = ( AttributeValueObject ) selection.getFirstElement();
+
+ String oldId = attributeValueObject.getAttribute();
+ Object oldValue = attributeValueObject.getValue();
+
+ AttributeValueDialog dialog = new AttributeValueDialog( attributeValueObject );
+ if ( Dialog.OK == dialog.open() && dialog.isDirty() )
+ {
+ Attribute attribute = contextEntry.get( oldId );
+ if ( attribute != null )
+ {
+ attribute.remove( oldValue );
+ }
+
+ AttributeValueObject newAttributeValueObject = dialog.getAttributeValueObject();
+ attribute = contextEntry.get( newAttributeValueObject.getAttribute() );
+ if ( attribute != null )
+ {
+ attribute.add( newAttributeValueObject.getValue() );
+ }
+ else
+ {
+ contextEntry.put( new BasicAttribute( newAttributeValueObject.getAttribute(),
+ newAttributeValueObject.getValue() ) );
+ }
+
+ contextEntryTableViewer.refresh();
+ resizeContextEntryTableColumnsToFit();
+ masterDetailsBlock.setEditorDirty();
+ dirty = true;
+ }
+ }
+ }
+}
Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionDetailsPage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionsMasterDetailsBlock.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionsMasterDetailsBlock.java?rev=592014&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionsMasterDetailsBlock.java (added)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionsMasterDetailsBlock.java Mon Nov 5 06:32:20 2007
@@ -0,0 +1,323 @@
+/*
+ * 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.editor;
+
+
+import java.util.List;
+
+import org.apache.directory.studio.apacheds.configuration.Activator;
+import org.apache.directory.studio.apacheds.configuration.PluginConstants;
+import org.apache.directory.studio.apacheds.configuration.model.Partition;
+import org.apache.directory.studio.apacheds.configuration.model.ServerConfiguration;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+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.Table;
+import org.eclipse.ui.forms.DetailsPart;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.MasterDetailsBlock;
+import org.eclipse.ui.forms.SectionPart;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class represents the Partitions Master/Details Block used in the Partitions Page.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PartitionsMasterDetailsBlock extends MasterDetailsBlock
+{
+ /** The associated page */
+ private FormPage page;
+
+ /** The input Server Configuration */
+ private ServerConfiguration serverConfiguration;
+
+ /** The Interceptors List */
+ private List<Partition> partitions;
+
+ /** The Details Page */
+ private PartitionDetailsPage detailsPage;
+
+ private static final String NEW_NAME = "New Partition ";
+
+ // UI Fields
+ private TableViewer viewer;
+ private Button addButton;
+ private Button deleteButton;
+
+
+ /**
+ * Creates a new instance of PartitionsMasterDetailsBlock.
+ *
+ * @param page
+ * the associated page
+ */
+ public PartitionsMasterDetailsBlock( FormPage page )
+ {
+ this.page = page;
+ serverConfiguration = ( ( ServerConfigurationEditorInput ) page.getEditorInput() ).getServerConfiguration();
+ partitions = serverConfiguration.getPartitions();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.MasterDetailsBlock#createMasterPart(org.eclipse.ui.forms.IManagedForm, org.eclipse.swt.widgets.Composite)
+ */
+ protected void createMasterPart( final IManagedForm managedForm, Composite parent )
+ {
+ FormToolkit toolkit = managedForm.getToolkit();
+
+ // Creating the Section
+ Section section = toolkit.createSection( parent, Section.TITLE_BAR );
+ section.setText( "All Partitions" );
+ section.marginWidth = 10;
+ section.marginHeight = 5;
+ Composite client = toolkit.createComposite( section, SWT.WRAP );
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.makeColumnsEqualWidth = false;
+ layout.marginWidth = 2;
+ layout.marginHeight = 2;
+ client.setLayout( layout );
+ toolkit.paintBordersFor( client );
+ section.setClient( client );
+
+ // Creatig the Table and Table Viewer
+ Table table = toolkit.createTable( client, SWT.NULL );
+ GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 2 );
+ gd.heightHint = 20;
+ gd.widthHint = 100;
+ table.setLayoutData( gd );
+ final SectionPart spart = new SectionPart( section );
+ managedForm.addPart( spart );
+ viewer = new TableViewer( table );
+ viewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ managedForm.fireSelectionChanged( spart, event.getSelection() );
+ }
+ } );
+ viewer.setContentProvider( new ArrayContentProvider() );
+ viewer.setLabelProvider( new LabelProvider()
+ {
+ public Image getImage( Object element )
+ {
+
+ return AbstractUIPlugin.imageDescriptorFromPlugin(
+ Activator.PLUGIN_ID,
+ ( ( Partition ) element ).isSystemPartition() ? PluginConstants.IMG_PARTITION_SYSTEM
+ : PluginConstants.IMG_PARTITION ).createImage();
+ }
+ } );
+
+ // Creating the button(s)
+ addButton = toolkit.createButton( client, "Add...", SWT.PUSH ); //$NON-NLS-1$
+ addButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+
+ deleteButton = toolkit.createButton( client, "Delete", SWT.PUSH );
+ deleteButton.setEnabled( false );
+ deleteButton.setLayoutData( new GridData( SWT.FILL, SWT.BEGINNING, false, false ) );
+
+ initFromInput();
+ addListeners();
+ }
+
+
+ /**
+ * Initializes the page with the Editor input.
+ */
+ private void initFromInput()
+ {
+ viewer.setInput( partitions );
+ }
+
+
+ /**
+ * Add listeners to UI fields.
+ */
+ private void addListeners()
+ {
+ viewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ viewer.refresh();
+
+ deleteButton.setEnabled( !event.getSelection().isEmpty() );
+ StructuredSelection selection = ( StructuredSelection ) viewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ Partition partition = ( Partition ) selection.getFirstElement();
+ if ( partition.isSystemPartition() )
+ {
+ deleteButton.setEnabled( false );
+ }
+ }
+ }
+ } );
+
+ addButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ Partition newPartition = new Partition( getNewName() );
+ partitions.add( newPartition );
+ viewer.refresh();
+ viewer.setSelection( new StructuredSelection( newPartition ) );
+ setEditorDirty();
+ }
+ } );
+
+ deleteButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent e )
+ {
+ StructuredSelection selection = ( StructuredSelection ) viewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ Partition partition = ( Partition ) selection.getFirstElement();
+ if ( !partition.isSystemPartition() )
+ {
+ partitions.remove( partition );
+ viewer.refresh();
+ setEditorDirty();
+ }
+ }
+ }
+ } );
+ }
+
+
+ /**
+ * Gets a new Name for a new Extended Operation.
+ *
+ * @return
+ * a new Name for a new Extended Operation
+ */
+ private String getNewName()
+ {
+ int counter = 1;
+ String name = NEW_NAME;
+ boolean ok = false;
+
+ while ( !ok )
+ {
+ ok = true;
+ name = NEW_NAME + counter;
+
+ for ( Partition partition : partitions )
+ {
+ if ( partition.getName().equalsIgnoreCase( name ) )
+ {
+ ok = false;
+ }
+ }
+ counter++;
+ }
+
+ return name;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.MasterDetailsBlock#createToolBarActions(org.eclipse.ui.forms.IManagedForm)
+ */
+ protected void createToolBarActions( IManagedForm managedForm )
+ {
+ final ScrolledForm form = managedForm.getForm();
+
+ // Horizontal layout Action
+ Action horizontalAction = new Action( "Horizontal layout", Action.AS_RADIO_BUTTON ) { //$NON-NLS-1$
+ public void run()
+ {
+ sashForm.setOrientation( SWT.HORIZONTAL );
+ form.reflow( true );
+ }
+ };
+ horizontalAction.setChecked( true );
+ horizontalAction.setToolTipText( "Horizontal Orientation" ); //$NON-NLS-1$
+ horizontalAction.setImageDescriptor( Activator.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+ PluginConstants.IMG_HORIZONTAL_ORIENTATION ) );
+
+ // Vertical layout Action
+ Action verticalAction = new Action( "Vertical Orientation", Action.AS_RADIO_BUTTON ) { //$NON-NLS-1$
+ public void run()
+ {
+ sashForm.setOrientation( SWT.VERTICAL );
+ form.reflow( true );
+ }
+ };
+ verticalAction.setChecked( false );
+ verticalAction.setToolTipText( "Vertical Orientation" ); //$NON-NLS-1$
+ verticalAction.setImageDescriptor( Activator.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
+ PluginConstants.IMG_VERTICAL_ORIENTATION ) );
+
+ form.getToolBarManager().add( horizontalAction );
+ form.getToolBarManager().add( verticalAction );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.MasterDetailsBlock#registerPages(org.eclipse.ui.forms.DetailsPart)
+ */
+ protected void registerPages( DetailsPart detailsPart )
+ {
+ detailsPage = new PartitionDetailsPage( this );
+ detailsPart.registerPage( Partition.class, detailsPage );
+ }
+
+
+ /**
+ * Sets the Editor as dirty.
+ */
+ public void setEditorDirty()
+ {
+ ( ( ServerConfigurationEditor ) page.getEditor() ).setDirty( true );
+ }
+
+
+ /**
+ * Saves the necessary elements to the input model.
+ */
+ public void save()
+ {
+ detailsPage.commit( true );
+ viewer.setInput( partitions );
+ }
+}
Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionsMasterDetailsBlock.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionsPage.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionsPage.java?rev=592014&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionsPage.java (added)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionsPage.java Mon Nov 5 06:32:20 2007
@@ -0,0 +1,81 @@
+/*
+ * 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.editor;
+
+
+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.ScrolledForm;
+
+
+/**
+ * This class represents the Partitions Page of the Server Configuration Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class PartitionsPage extends FormPage
+{
+ /** The Page ID*/
+ public static final String ID = ServerConfigurationEditor.ID + ".PartitionsPage";
+
+ /** The Page Title */
+ private static final String TITLE = "Partitions";
+
+ /** The Master/Details block */
+ private PartitionsMasterDetailsBlock masterDetailsBlock;
+
+
+ /**
+ * Creates a new instance of PartitionsPage.
+ *
+ * @param editor
+ * the associated editor
+ */
+ public PartitionsPage( FormEditor editor )
+ {
+ super( editor, ID, TITLE );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
+ */
+ protected void createFormContent( IManagedForm managedForm )
+ {
+ ScrolledForm form = managedForm.getForm();
+ form.setText( "Partitions" );
+ masterDetailsBlock = new PartitionsMasterDetailsBlock( this );
+ masterDetailsBlock.createContent( managedForm );
+ }
+
+
+ /**
+ * Saves the necessary elements to the input model.
+ */
+ public void save()
+ {
+ if ( masterDetailsBlock != null )
+ {
+ masterDetailsBlock.save();
+ }
+ }
+}
Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/PartitionsPage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java?rev=592014&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java (added)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java Mon Nov 5 06:32:20 2007
@@ -0,0 +1,205 @@
+/*
+ * 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.editor;
+
+
+import org.apache.directory.studio.apacheds.configuration.Activator;
+import org.apache.directory.studio.apacheds.configuration.model.ServerConfiguration;
+import org.apache.directory.studio.apacheds.configuration.model.ServerConfigurationWriter;
+import org.apache.directory.studio.apacheds.configuration.model.ServerConfigurationWriterException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.editor.FormEditor;
+
+
+/**
+ * This class implements the Server Configuration Editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServerConfigurationEditor extends FormEditor
+{
+ /** The Editor ID */
+ public static final String ID = "org.apache.directory.studio.apacheds.configuration.editor";
+
+ /** The editor input */
+ private IEditorInput input;
+
+ /** The Server Configuration */
+ private ServerConfiguration serverConfiguration;
+
+ /** The dirty flag */
+ private boolean dirty = false;
+
+ // The Pages
+ private GeneralPage generalPage;
+ private PartitionsPage partitionsPage;
+ private InterceptorsPage interceptorsPage;
+ private ExtendedOperationsPage extendedOperationsPage;
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.editor.FormEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
+ */
+ public void init( IEditorSite site, IEditorInput input ) throws PartInitException
+ {
+ super.init( site, input );
+ this.input = input;
+ setPartName( input.getName() );
+ serverConfiguration = ( ( ServerConfigurationEditorInput ) input ).getServerConfiguration();
+ dirty = serverConfiguration.getPath() == null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
+ */
+ protected void addPages()
+ {
+ try
+ {
+ generalPage = new GeneralPage( this );
+ addPage( generalPage );
+
+ partitionsPage = new PartitionsPage( this );
+ addPage( partitionsPage );
+
+ interceptorsPage = new InterceptorsPage( this );
+ addPage( interceptorsPage );
+
+ extendedOperationsPage = new ExtendedOperationsPage( this );
+ addPage( extendedOperationsPage );
+ }
+ catch ( PartInitException e )
+ {
+ Activator.getDefault().getLog().log(
+ new Status( Status.ERROR, Activator.PLUGIN_ID, Status.OK, e.getMessage(), e.getCause() ) );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void doSave( IProgressMonitor monitor )
+ {
+ monitor.beginTask( "Saving the Server Configuration", 5 );
+ generalPage.save();
+ monitor.worked( 1 );
+ partitionsPage.save();
+ monitor.worked( 1 );
+ interceptorsPage.save();
+ monitor.worked( 1 );
+ extendedOperationsPage.save();
+ monitor.worked( 1 );
+
+ // Checking if the ServerConfiguration is already existing or if it's a new file.
+ if ( serverConfiguration.getPath() == null )
+ {
+ FileDialog fd = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE );
+ fd.setText( "Select a file" );
+ fd.setFilterExtensions( new String[]
+ { "*.xml", "*.*" } );
+ fd.setFilterNames( new String[]
+ { "XML files", "All files" } );
+ String selectedFile = fd.open();
+ // selected == null if 'cancel' has been pushed
+ if ( selectedFile == null || "".equals( selectedFile ) )
+ {
+ monitor.setCanceled( true );
+ return;
+ }
+
+ // TODO Add the overwrite code...
+
+ serverConfiguration.setPath( selectedFile );
+ setTitleToolTip( input.getToolTipText() );
+ }
+
+ // Saving the ServerConfiguration to disk
+ try
+ {
+ ServerConfigurationWriter writer = new ServerConfigurationWriter();
+ writer.write( serverConfiguration );
+ }
+ catch ( ServerConfigurationWriterException e )
+ {
+ MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ SWT.OK | SWT.ICON_ERROR );
+ messageBox.setText( "Error!" );
+ messageBox.setMessage( "An error occurred when writing the file to disk." + "\n" + e.getMessage() );
+ messageBox.open();
+ setDirty( true );
+ monitor.done();
+ return;
+ }
+
+ monitor.worked( 1 );
+ setDirty( false );
+ monitor.done();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.EditorPart#doSaveAs()
+ */
+ public void doSaveAs()
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
+ */
+ public boolean isSaveAsAllowed()
+ {
+ return false;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.forms.editor.FormEditor#isDirty()
+ */
+ public boolean isDirty()
+ {
+ return dirty;
+ }
+
+
+ /**
+ * Sets the dirty state of the editor.
+ *
+ * @param dirty
+ * the new dirty
+ */
+ public void setDirty( boolean dirty )
+ {
+ this.dirty = dirty;
+ editorDirtyStateChanged();
+ }
+}
Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditorInput.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditorInput.java?rev=592014&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditorInput.java (added)
+++ directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditorInput.java Mon Nov 5 06:32:20 2007
@@ -0,0 +1,150 @@
+/*
+ * 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.editor;
+
+
+import org.apache.directory.studio.apacheds.configuration.model.ServerConfiguration;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+
+/**
+ * This class represents the Server Configuration Editor Input.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServerConfigurationEditorInput implements IEditorInput
+{
+ /** The Server Configuration */
+ private ServerConfiguration serverConfiguration;
+
+
+ /**
+ * Creates a new instance of ServerConfigurationEditorInput.
+ *
+ * @param serverConfiguration
+ * the Server Configuration
+ */
+ public ServerConfigurationEditorInput( ServerConfiguration serverConfiguration )
+ {
+ this.serverConfiguration = serverConfiguration;
+ }
+
+
+ /**
+ * Gets the Server Configuration
+ *
+ * @return
+ * the Server Configuration
+ */
+ public ServerConfiguration getServerConfiguration()
+ {
+ return serverConfiguration;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IEditorInput#getToolTipText()
+ */
+ public String getToolTipText()
+ {
+ String path = serverConfiguration.getPath();
+ if ( path == null )
+ {
+ return "New Configuration File";
+ }
+ else
+ {
+ return path;
+ }
+
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IEditorInput#getName()
+ */
+ public String getName()
+ {
+ return "Apache DS Configuration";
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IEditorInput#exists()
+ */
+ public boolean exists()
+ {
+ return ( serverConfiguration != null );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
+ */
+ public ImageDescriptor getImageDescriptor()
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IEditorInput#getPersistable()
+ */
+ public IPersistableElement getPersistable()
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter( Class adapter )
+ {
+ return null;
+ }
+
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals( Object obj )
+ {
+ if ( obj instanceof ServerConfigurationEditorInput )
+ {
+ ServerConfigurationEditorInput input = ( ServerConfigurationEditorInput ) obj;
+
+ if ( input.exists() && exists() )
+ {
+ String inputPath = input.getServerConfiguration().getPath();
+ String myPath = getServerConfiguration().getPath();
+
+ if ( inputPath != null && myPath != null )
+ {
+ return inputPath.equals( myPath );
+ }
+ }
+ }
+ return false;
+ }
+}
Propchange: directory/sandbox/felixk/studio-apacheds-configuration/src/main/java/org/apache/directory/studio/apacheds/configuration/editor/ServerConfigurationEditorInput.java
------------------------------------------------------------------------------
svn:eol-style = native