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/03 10:50:43 UTC
svn commit: r552744 - in
/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view:
dialogs/ wizards/
Author: pamarcelot
Date: Tue Jul 3 01:50:42 2007
New Revision: 552744
URL: http://svn.apache.org/viewvc?view=rev&rev=552744
Log:
Added the ObjectClassSelectionDialog.
Modified the NewObjectClassWizard with correct behavior.
Added:
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/ObjectClassSelectionDialog.java
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/ObjectClassSelectionDialogContentProvider.java
Modified:
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassContentWizardPage.java
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassGeneralPageWizardPage.java
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassMandatoryAttributesPage.java
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassOptionalAttributesPage.java
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassWizard.java
Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/ObjectClassSelectionDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/ObjectClassSelectionDialog.java?view=auto&rev=552744
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/ObjectClassSelectionDialog.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/ObjectClassSelectionDialog.java Tue Jul 3 01:50:42 2007
@@ -0,0 +1,232 @@
+/*
+ * 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.dialogs;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * This class is the Object Class Selection Dialog, that allows user to select an object class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ObjectClassSelectionDialog extends Dialog
+{
+ /** The selected object class */
+ private ObjectClassImpl selectedObjectClass;
+
+ /** The hidden Object Classes */
+ private List<ObjectClassImpl> hiddenObjectClasses;
+
+ // UI Fields
+ private Text searchText;
+ private Table objectClassesTable;
+ private TableViewer tableViewer;
+
+
+ /**
+ * Creates a new instance of ObjectClassSelectionDialog.
+ */
+ public ObjectClassSelectionDialog()
+ {
+ super( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() );
+ hiddenObjectClasses = new ArrayList<ObjectClassImpl>();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+ protected void configureShell( Shell newShell )
+ {
+ super.configureShell( newShell );
+ newShell.setText( "Object Class Selection" ); //$NON-NLS-1$
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createDialogArea( Composite parent )
+ {
+ Composite composite = new Composite( parent, SWT.NONE );
+ GridLayout layout = new GridLayout( 1, false );
+ composite.setLayout( layout );
+
+ Label chooseLabel = new Label( composite, SWT.NONE );
+ chooseLabel.setText( "Choose an object class" );
+ chooseLabel.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+
+ searchText = new Text( composite, SWT.BORDER );
+ searchText.setLayoutData( new GridData( GridData.FILL, SWT.NONE, true, false ) );
+ searchText.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ tableViewer.setInput( searchText.getText() );
+ objectClassesTable.select( 0 );
+ }
+ } );
+ searchText.addKeyListener( new KeyAdapter()
+ {
+ public void keyPressed( KeyEvent e )
+ {
+ if ( e.keyCode == SWT.ARROW_DOWN )
+ {
+ objectClassesTable.setFocus();
+ }
+ }
+ } );
+
+ Label matchingLabel = new Label( composite, SWT.NONE );
+ matchingLabel.setText( "Matching object class(es)" );
+ matchingLabel.setLayoutData( new GridData( GridData.FILL, SWT.None, true, false ) );
+
+ objectClassesTable = new Table( composite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
+ | SWT.FULL_SELECTION | SWT.HIDE_SELECTION );
+ GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true );
+ gridData.heightHint = 148;
+ gridData.minimumHeight = 148;
+ gridData.widthHint = 350;
+ gridData.minimumWidth = 350;
+ objectClassesTable.setLayoutData( gridData );
+ objectClassesTable.addMouseListener( new MouseAdapter()
+ {
+ public void mouseDoubleClick( MouseEvent e )
+ {
+ if ( objectClassesTable.getSelectionIndex() != -1 )
+ {
+ okPressed();
+ }
+ }
+ } );
+
+ tableViewer = new TableViewer( objectClassesTable );
+ tableViewer.setUseHashlookup( true );
+
+ tableViewer.setContentProvider( new ObjectClassSelectionDialogContentProvider( hiddenObjectClasses ) );
+ tableViewer.setLabelProvider( new LabelProvider() );
+
+ // We need to force the input to load the complete list of attribute types
+ tableViewer.setInput( "" ); //$NON-NLS-1$
+ // We also need to force the selection of the first row
+ objectClassesTable.select( 0 );
+
+ return composite;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ */
+ protected void createButtonsForButtonBar( Composite parent )
+ {
+ createButton( parent, IDialogConstants.OK_ID, "Add", true );
+ createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ */
+ protected void okPressed()
+ {
+ StructuredSelection selection = ( StructuredSelection ) tableViewer.getSelection();
+
+ if ( selection.isEmpty() )
+ {
+ MessageDialog.openError( getShell(), "Invalid Selection", "You have to choose an object class" );
+ return;
+ }
+ else
+ {
+ selectedObjectClass = ( ObjectClassImpl ) selection.getFirstElement();
+ }
+
+ super.okPressed();
+ }
+
+
+ /**
+ * Returns the selected Object Class.
+ *
+ * @return
+ * the selected Object Class
+ */
+ public ObjectClassImpl getSelectedObjectClass()
+ {
+ return selectedObjectClass;
+ }
+
+
+ /**
+ * Set the hidden Object Classes.
+ *
+ * @param list
+ * a list of Object Classes to hide
+ */
+ public void setHiddenObjectClasses( List<ObjectClassImpl> list )
+ {
+ hiddenObjectClasses = list;
+ }
+
+
+ /**
+ * Sets the hidden Object Classes.
+ *
+ * @param objectClasses
+ * an array of Object Classes to hide
+ */
+ public void setHiddenObjectClasses( ObjectClassImpl[] objectClasses )
+ {
+ for ( ObjectClassImpl objectClass : objectClasses )
+ {
+ hiddenObjectClasses.add( objectClass );
+ }
+ }
+}
Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/ObjectClassSelectionDialogContentProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/ObjectClassSelectionDialogContentProvider.java?view=auto&rev=552744
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/ObjectClassSelectionDialogContentProvider.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/dialogs/ObjectClassSelectionDialogContentProvider.java Tue Jul 3 01:50:42 2007
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.studio.apacheds.schemaeditor.view.dialogs;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaHandler;
+import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+
+/**
+ * This class is the Content Provider for the Object Class Selection Dialog.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ObjectClassSelectionDialogContentProvider implements IStructuredContentProvider
+{
+ /** The schema handler */
+ private SchemaHandler schemaHandler;
+
+ /** The hidden object classes */
+ private List<ObjectClassImpl> hiddenObjectClasses;
+
+
+ /**
+ * Creates a new instance of ObjectClassSelectionDialogContentProvider.
+ */
+ public ObjectClassSelectionDialogContentProvider( List<ObjectClassImpl> hiddenObjectClasses )
+ {
+ schemaHandler = Activator.getDefault().getSchemaHandler();
+ this.hiddenObjectClasses = hiddenObjectClasses;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public Object[] getElements( Object inputElement )
+ {
+ if ( inputElement instanceof String )
+ {
+ ArrayList<ObjectClassImpl> results = new ArrayList<ObjectClassImpl>();
+
+ String searchText = ( String ) inputElement;
+
+ String searchRegexp;
+ if ( searchText.length() == 0 )
+ {
+ searchRegexp = ".*"; //$NON-NLS-1$
+ }
+ else
+ {
+ searchRegexp = searchText + ".*"; //$NON-NLS-1$
+ }
+ Pattern pattern = Pattern.compile( searchRegexp, Pattern.CASE_INSENSITIVE );
+
+ List<ObjectClassImpl> ocList = schemaHandler.getObjectClasses();
+
+ // Sorting the list
+ Collections.sort( ocList, new Comparator<ObjectClassImpl>()
+ {
+ public int compare( ObjectClassImpl oc1, ObjectClassImpl oc2 )
+ {
+ if ( ( oc1.getNames() == null || oc1.getNames().length == 0 )
+ && ( oc2.getNames() == null || oc2.getNames().length == 0 ) )
+ {
+ return 0;
+ }
+ else if ( ( oc1.getNames() == null || oc1.getNames().length == 0 )
+ && ( oc2.getNames() != null && oc2.getNames().length > 0 ) )
+ {
+ return "".compareToIgnoreCase( oc2.getNames()[0] ); //$NON-NLS-1$
+ }
+ else if ( ( oc1.getNames() != null && oc1.getNames().length > 0 )
+ && ( oc2.getNames() == null || oc2.getNames().length == 0 ) )
+ {
+ return oc1.getNames()[0].compareToIgnoreCase( "" ); //$NON-NLS-1$
+ }
+ else
+ {
+ return oc1.getNames()[0].compareToIgnoreCase( oc2.getNames()[0] );
+ }
+ }
+ } );
+
+ // Searching for all matching elements
+ for ( ObjectClassImpl oc : ocList )
+ {
+ for ( String name : oc.getNames() )
+ {
+ Matcher m = pattern.matcher( name );
+ if ( m.matches() )
+ {
+ if ( !hiddenObjectClasses.contains( oc ) )
+ {
+ if ( !results.contains( oc ) )
+ {
+ results.add( oc );
+ }
+ }
+ break;
+ }
+ }
+ Matcher m = pattern.matcher( oc.getOid() );
+ if ( m.matches() )
+ {
+ if ( !hiddenObjectClasses.contains( oc ) )
+ {
+ if ( !results.contains( oc ) )
+ {
+ results.add( oc );
+ }
+ }
+ }
+ }
+
+ // Returns the results
+ return results.toArray();
+ }
+
+ // Default
+ return new Object[0];
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ public void dispose()
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged( Viewer viewer, Object oldInput, Object newInput )
+ {
+ }
+}
Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassContentWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassContentWizardPage.java?view=diff&rev=552744&r1=552743&r2=552744
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassContentWizardPage.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassContentWizardPage.java Tue Jul 3 01:50:42 2007
@@ -20,13 +20,25 @@
package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
import org.apache.directory.studio.apacheds.schemaeditor.Activator;
import org.apache.directory.studio.apacheds.schemaeditor.PluginConstants;
+import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.view.dialogs.ObjectClassSelectionDialog;
+import org.eclipse.jface.dialogs.Dialog;
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.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -48,6 +60,22 @@
*/
public class NewObjectClassContentWizardPage extends WizardPage
{
+ /** The superiors object classes */
+ private List<ObjectClassImpl> superiorsList;
+
+ /** The type of the object class */
+ private ObjectClassTypeEnum type = ObjectClassTypeEnum.STRUCTURAL;
+
+ // UI Fields
+ private TableViewer superiorsTableViewer;
+ private Button superiorsAddButton;
+ private Button superiorsRemoveButton;
+ private Button structuralRadio;
+ private Button abstractRadio;
+ private Button auxiliaryRadio;
+ private Button obsoleteCheckbox;
+
+
/**
* Creates a new instance of NewAttributeTypeContentWizardPage.
*/
@@ -58,6 +86,7 @@
setDescription( "Please enter the superiors, class type and properties for the object class." );
setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
PluginConstants.IMG_OBJECT_CLASS_NEW_WIZARD ) );
+ superiorsList = new ArrayList<ObjectClassImpl>();
}
@@ -81,15 +110,38 @@
GridData superiorsTableGridData = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 2 );
superiorsTableGridData.heightHint = 100;
superiorsTable.setLayoutData( superiorsTableGridData );
- TableViewer superiorsTableViewer = new TableViewer( superiorsTable );
+ superiorsTableViewer = new TableViewer( superiorsTable );
superiorsTableViewer.setLabelProvider( new LabelProvider() );
superiorsTableViewer.setContentProvider( new ArrayContentProvider() );
- Button superiorsAddButton = new Button( superiorsGroup, SWT.PUSH );
+ superiorsTableViewer.setInput( superiorsList );
+ superiorsTableViewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ superiorsRemoveButton.setEnabled( !event.getSelection().isEmpty() );
+ }
+ } );
+ superiorsAddButton = new Button( superiorsGroup, SWT.PUSH );
superiorsAddButton.setText( "Add..." );
superiorsAddButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) );
- Button superiorsRemoveButton = new Button( superiorsGroup, SWT.PUSH );
+ superiorsAddButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ addSuperiorObjectClass();
+ }
+ } );
+ superiorsRemoveButton = new Button( superiorsGroup, SWT.PUSH );
superiorsRemoveButton.setText( "Remove" );
superiorsRemoveButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) );
+ superiorsRemoveButton.setEnabled( false );
+ superiorsRemoveButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ removeSuperiorObjectClass();
+ }
+ } );
// Class Type Group
Group classTypeGroup = new Group( composite, SWT.NONE );
@@ -101,21 +153,43 @@
Label classTypeLable = new Label( classTypeGroup, SWT.NONE );
classTypeLable.setText( "Class Type:" );
new Label( classTypeGroup, SWT.NONE ).setText( " " );
- Button structuralRadio = new Button( classTypeGroup, SWT.RADIO );
+ structuralRadio = new Button( classTypeGroup, SWT.RADIO );
structuralRadio.setText( "Structural" );
GridData structuralRadioGridData = new GridData( SWT.LEFT, SWT.NONE, false, false );
structuralRadioGridData.widthHint = 115;
structuralRadio.setLayoutData( structuralRadioGridData );
- Button abstractRadio = new Button( classTypeGroup, SWT.RADIO );
+ structuralRadio.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ type = ObjectClassTypeEnum.STRUCTURAL;
+ }
+ } );
+ structuralRadio.setSelection( true );
+ abstractRadio = new Button( classTypeGroup, SWT.RADIO );
abstractRadio.setText( "Abstract" );
GridData abstractRadioGridData = new GridData( SWT.LEFT, SWT.NONE, false, false );
abstractRadioGridData.widthHint = 115;
abstractRadio.setLayoutData( structuralRadioGridData );
- Button auxiliaryRadio = new Button( classTypeGroup, SWT.RADIO );
+ abstractRadio.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ type = ObjectClassTypeEnum.ABSTRACT;
+ }
+ } );
+ auxiliaryRadio = new Button( classTypeGroup, SWT.RADIO );
auxiliaryRadio.setText( "Auxiliary" );
GridData auxiliaryRadioGridData = new GridData( SWT.LEFT, SWT.NONE, false, false );
auxiliaryRadioGridData.widthHint = 115;
auxiliaryRadio.setLayoutData( structuralRadioGridData );
+ auxiliaryRadio.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ type = ObjectClassTypeEnum.AUXILIARY;
+ }
+ } );
// Properties Group
Group propertiesGroup = new Group( composite, SWT.NONE );
@@ -124,10 +198,91 @@
propertiesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
// Obsolete
- new Label( composite, SWT.NONE );
- Button obsoleteCheckbox = new Button( propertiesGroup, SWT.CHECK );
+ obsoleteCheckbox = new Button( propertiesGroup, SWT.CHECK );
obsoleteCheckbox.setText( "Obsolete" );
setControl( composite );
+ }
+
+
+ /**
+ * This method is called when the "Add" button of the superiors
+ * table is selected.
+ */
+ private void addSuperiorObjectClass()
+ {
+ ObjectClassSelectionDialog dialog = new ObjectClassSelectionDialog();
+ dialog.setHiddenObjectClasses( superiorsList );
+ if ( dialog.open() == Dialog.OK )
+ {
+ superiorsList.add( dialog.getSelectedObjectClass() );
+ updateSuperiorsTable();
+ }
+ }
+
+
+ /**
+ * This method is called when the "Remove" button of the superiors
+ * table is selected.
+ */
+ private void removeSuperiorObjectClass()
+ {
+ StructuredSelection selection = ( StructuredSelection ) superiorsTableViewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ superiorsList.remove( selection.getFirstElement() );
+ updateSuperiorsTable();
+ }
+ }
+
+
+ /**
+ * Updates the superiors table
+ */
+ private void updateSuperiorsTable()
+ {
+ superiorsTableViewer.refresh();
+ }
+
+
+ /**
+ * Gets the value of the superiors.
+ *
+ * @return
+ * the value of the superiors
+ */
+ public String[] getSuperiorsNameValue()
+ {
+ List<String> names = new ArrayList<String>();
+ for ( ObjectClassImpl oc : superiorsList )
+ {
+ names.add( oc.getName() );
+ }
+
+ return names.toArray( new String[0] );
+ }
+
+
+ /**
+ * Gets the class type value.
+ *
+ * @return
+ * the class type value
+ */
+ public ObjectClassTypeEnum getClassTypeValue()
+ {
+ return type;
+ }
+
+
+ /**
+ * Gets the 'Obsolete' value.
+ *
+ * @return
+ * the 'Obsolete' value
+ */
+ public boolean getObsoleteValue()
+ {
+ return obsoleteCheckbox.getSelection();
}
}
Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassGeneralPageWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassGeneralPageWizardPage.java?view=diff&rev=552744&r1=552743&r2=552744
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassGeneralPageWizardPage.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassGeneralPageWizardPage.java Tue Jul 3 01:50:42 2007
@@ -20,13 +20,26 @@
package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
+import org.apache.directory.shared.asn1.primitives.OID;
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.apache.directory.studio.apacheds.schemaeditor.view.dialogs.EditAliasesDialog;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
+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.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.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -49,6 +62,20 @@
*/
public class NewObjectClassGeneralPageWizardPage extends WizardPage
{
+ /** The SchemaHandler */
+ private SchemaHandler schemaHandler;
+
+ /** The aliases */
+ private String[] aliases;
+
+ // UI fields
+ private ComboViewer schemaComboViewer;
+ private Text oidText;
+ private Text aliasesText;
+ private Button aliasesButton;
+ private Text descriptionText;
+
+
/**
* Creates a new instance of NewObjectClassGeneralPageWizardPage.
*/
@@ -59,6 +86,9 @@
setDescription( "Create a new object class." );
setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
PluginConstants.IMG_OBJECT_CLASS_NEW_WIZARD ) );
+
+ schemaHandler = Activator.getDefault().getSchemaHandler();
+ aliases = new String[0];
}
@@ -82,9 +112,34 @@
schemaLabel.setText( "Schema:" );
Combo schemaCombo = new Combo( schemaGroup, SWT.READ_ONLY );
schemaCombo.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
- ComboViewer schemaComboViewer = new ComboViewer( schemaCombo );
- schemaComboViewer.setLabelProvider( new LabelProvider() );
+ schemaComboViewer = new ComboViewer( schemaCombo );
schemaComboViewer.setContentProvider( new ArrayContentProvider() );
+ schemaComboViewer.setLabelProvider( new LabelProvider()
+ {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+ */
+ public String getText( Object element )
+ {
+ if ( element instanceof Schema )
+ {
+ return ( ( Schema ) element ).getName();
+ }
+
+ // Default
+ return super.getText( element );
+ }
+ } );
+ schemaComboViewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ */
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ dialogChanged();
+ }
+ } );
// Naming and Description Group
Group namingDescriptionGroup = new Group( composite, SWT.NONE );
@@ -95,26 +150,214 @@
// OID
Label oidLabel = new Label( namingDescriptionGroup, SWT.NONE );
oidLabel.setText( "OID:" );
- Text oidText = new Text( namingDescriptionGroup, SWT.BORDER );
+ oidText = new Text( namingDescriptionGroup, SWT.BORDER );
oidText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 ) );
+ oidText.addModifyListener( new ModifyListener()
+ {
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+ */
+ public void modifyText( ModifyEvent arg0 )
+ {
+ dialogChanged();
+ }
+ } );
// Aliases
Label aliasesLabel = new Label( namingDescriptionGroup, SWT.NONE );
aliasesLabel.setText( "Aliases:" );
- Text aliasesText = new Text( namingDescriptionGroup, SWT.BORDER );
+ aliasesText = new Text( namingDescriptionGroup, SWT.BORDER );
aliasesText.setEnabled( false );
aliasesText.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
- Button aliasesButton = new Button( namingDescriptionGroup, SWT.PUSH );
- aliasesButton.setText( "Edit" );
+ aliasesButton = new Button( namingDescriptionGroup, SWT.PUSH );
+ aliasesButton.setText( "Edit..." );
+ aliasesButton.addSelectionListener( new SelectionAdapter()
+ {
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ EditAliasesDialog dialog = new EditAliasesDialog( aliases );
+
+ if ( ( dialog.open() == Dialog.OK ) && ( dialog.isDirty() ) )
+ {
+ aliases = dialog.getAliases();
+ fillInAliasesLabel();
+ dialogChanged();
+ }
+ }
+ } );
// Description
Label descriptionLabel = new Label( namingDescriptionGroup, SWT.NONE );
descriptionLabel.setText( "Description:" );
- Text descriptionText = new Text( namingDescriptionGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL );
+ descriptionText = new Text( namingDescriptionGroup, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL );
GridData descriptionGridData = new GridData( SWT.FILL, SWT.NONE, true, false, 2, 1 );
descriptionGridData.heightHint = 67;
descriptionText.setLayoutData( descriptionGridData );
+ descriptionText.addModifyListener( new ModifyListener()
+ {
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+ */
+ public void modifyText( ModifyEvent arg0 )
+ {
+ dialogChanged();
+ }
+ } );
+
+ initFields();
setControl( composite );
+
+ displayErrorMessage( null );
+ setPageComplete( false );
+ }
+
+
+ /**
+ * Initializes the UI fields.
+ */
+ private void initFields()
+ {
+ schemaComboViewer.setInput( schemaHandler.getSchemas() );
+ }
+
+
+ /**
+ * This method is called when the user modifies something in the UI.
+ */
+ private void dialogChanged()
+ {
+ if ( schemaComboViewer.getSelection().isEmpty() )
+ {
+ displayErrorMessage( "A Schema must be specified." );
+ return;
+ }
+ else if ( oidText.getText().equals( "" ) )
+ {
+ displayErrorMessage( "An OID must be specified." );
+ return;
+ }
+ else if ( ( !oidText.getText().equals( "" ) ) && ( !OID.isOID( oidText.getText() ) ) )
+ {
+ displayErrorMessage( "Incorrect OID." );
+ return;
+ }
+ else if ( aliases.length == 0 )
+ {
+ displayWarningMessage( "The attribute type does not have any name. It is recommanded to add at least one name." );
+ 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 )
+ {
+ setMessage( null, DialogPage.WARNING );
+ setErrorMessage( message );
+ setPageComplete( message == null );
+ }
+
+
+ /**
+ * Displays a warning message and set the page status as complete.
+ *
+ * @param message
+ * the message to display
+ */
+ private void displayWarningMessage( String message )
+ {
+ setErrorMessage( null );
+ setMessage( message, DialogPage.WARNING );
+ setPageComplete( true );
+ }
+
+
+ /**
+ * Fills in the Aliases Label.
+ */
+ private void fillInAliasesLabel()
+ {
+ StringBuffer sb = new StringBuffer();
+ if ( aliases.length != 0 )
+ {
+ for ( String name : aliases )
+ {
+ sb.append( name );
+ sb.append( ", " );
+ }
+ sb.deleteCharAt( sb.length() - 1 );
+ sb.deleteCharAt( sb.length() - 1 );
+ }
+ aliasesText.setText( sb.toString() );
+ }
+
+
+ /**
+ * Get the name of the schema.
+ *
+ * @return
+ * the name of the schema
+ */
+ public String getSchemaValue()
+ {
+ StructuredSelection selection = ( StructuredSelection ) schemaComboViewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ Schema schema = ( Schema ) selection.getFirstElement();
+
+ return schema.getName();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
+ * Gets the value of the OID.
+ *
+ * @return
+ * the value of the OID
+ */
+ public String getOidValue()
+ {
+ return oidText.getText();
+ }
+
+
+ /**
+ * Gets the value of the aliases.
+ *
+ * @return
+ * the value of the aliases
+ */
+ public String[] getAliasesValue()
+ {
+ return aliases;
+ }
+
+
+ /**
+ * Gets the value of the description.
+ *
+ * @return
+ * the value of the description
+ */
+ public String getDescriptionValue()
+ {
+ return descriptionText.getText();
}
}
Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassMandatoryAttributesPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassMandatoryAttributesPage.java?view=diff&rev=552744&r1=552743&r2=552744
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassMandatoryAttributesPage.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassMandatoryAttributesPage.java Tue Jul 3 01:50:42 2007
@@ -20,13 +20,24 @@
package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
+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.model.AttributeTypeImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.view.dialogs.AttributeTypeSelectionDialog;
+import org.eclipse.jface.dialogs.Dialog;
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.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -46,6 +57,15 @@
*/
public class NewObjectClassMandatoryAttributesPage extends WizardPage
{
+ /** The mandatory attribute types list */
+ private List<AttributeTypeImpl> mandatoryAttributeTypesList;
+
+ // UI Fields
+ private TableViewer mandatoryAttributeTypesTableViewer;
+ private Button mandatoryAttributeTypesAddButton;
+ private Button mandatoryAttributeTypesRemoveButton;
+
+
/**
* Creates a new instance of NewObjectClassMandatoryAttributesPage.
*/
@@ -56,6 +76,7 @@
setDescription( "Please specify the mandatory attribute types for the object class." );
setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
PluginConstants.IMG_OBJECT_CLASS_NEW_WIZARD ) );
+ mandatoryAttributeTypesList = new ArrayList<AttributeTypeImpl>();
}
@@ -79,16 +100,113 @@
GridData mandatoryAttributeTypesTableGridData = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 2 );
mandatoryAttributeTypesTableGridData.heightHint = 100;
mandatoryAttributeTypesTable.setLayoutData( mandatoryAttributeTypesTableGridData );
- TableViewer mandatoryAttributeTypesTableViewer = new TableViewer( mandatoryAttributeTypesTable );
- mandatoryAttributeTypesTableViewer.setLabelProvider( new LabelProvider() );
+ mandatoryAttributeTypesTableViewer = new TableViewer( mandatoryAttributeTypesTable );
mandatoryAttributeTypesTableViewer.setContentProvider( new ArrayContentProvider() );
- Button mandatoryAttributeTypesAddButton = new Button( mandatoryAttributeTypesGroup, SWT.PUSH );
+ mandatoryAttributeTypesTableViewer.setLabelProvider( new LabelProvider() );
+ mandatoryAttributeTypesTableViewer.setInput( mandatoryAttributeTypesList );
+ mandatoryAttributeTypesTableViewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ mandatoryAttributeTypesRemoveButton.setEnabled( !event.getSelection().isEmpty() );
+ }
+ } );
+ mandatoryAttributeTypesAddButton = new Button( mandatoryAttributeTypesGroup, SWT.PUSH );
mandatoryAttributeTypesAddButton.setText( "Add..." );
mandatoryAttributeTypesAddButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) );
- Button mandatoryAttributeTypesRemoveButton = new Button( mandatoryAttributeTypesGroup, SWT.PUSH );
+ mandatoryAttributeTypesAddButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ addMandatoryAttributeType();
+ }
+ } );
+ mandatoryAttributeTypesRemoveButton = new Button( mandatoryAttributeTypesGroup, SWT.PUSH );
mandatoryAttributeTypesRemoveButton.setText( "Remove" );
mandatoryAttributeTypesRemoveButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) );
+ mandatoryAttributeTypesRemoveButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ removeMandatoryAttributeType();
+ }
+ } );
+ mandatoryAttributeTypesRemoveButton.setEnabled( false );
setControl( composite );
+ }
+
+
+ /**
+ * This method is called when the "Add" button of the mandatory
+ * attribute types table is selected.
+ */
+ private void addMandatoryAttributeType()
+ {
+ AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog();
+ List<AttributeTypeImpl> hiddenAttributes = new ArrayList<AttributeTypeImpl>();
+ List<AttributeTypeImpl> optionalAttributes = ( ( NewObjectClassWizard ) getWizard() )
+ .getOptionalAttributesPage().getOptionalAttributeTypes();
+ hiddenAttributes.addAll( optionalAttributes );
+ hiddenAttributes.addAll( mandatoryAttributeTypesList );
+ dialog.setHiddenAttributeTypes( hiddenAttributes );
+ if ( dialog.open() == Dialog.OK )
+ {
+ mandatoryAttributeTypesList.add( dialog.getSelectedAttributeType() );
+ updateMandatoryAttributeTypesTableTable();
+ }
+ }
+
+
+ /**
+ * This method is called when the "Remove" button of the mandatory
+ * attribute types table is selected.
+ */
+ private void removeMandatoryAttributeType()
+ {
+ StructuredSelection selection = ( StructuredSelection ) mandatoryAttributeTypesTableViewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ mandatoryAttributeTypesList.remove( selection.getFirstElement() );
+ updateMandatoryAttributeTypesTableTable();
+ }
+ }
+
+
+ /**
+ * Updates the mandatory attribute types table.
+ */
+ private void updateMandatoryAttributeTypesTableTable()
+ {
+ mandatoryAttributeTypesTableViewer.refresh();
+ }
+
+
+ /**
+ * Gets the mandatory attribute types.
+ *
+ * @return
+ * the mandatory attributes types
+ */
+ public List<AttributeTypeImpl> getMandatoryAttributeTypes()
+ {
+ return mandatoryAttributeTypesList;
+ }
+
+
+ /**
+ * Gets the names of the mandatory attribute types.
+ *
+ * @return
+ * the names of the mandatory attributes types
+ */
+ public String[] getMandatoryAttributeTypesNames()
+ {
+ List<String> names = new ArrayList<String>();
+ for ( AttributeTypeImpl at : mandatoryAttributeTypesList )
+ {
+ names.add( at.getName() );
+ }
+ return names.toArray( new String[0] );
}
}
Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassOptionalAttributesPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassOptionalAttributesPage.java?view=diff&rev=552744&r1=552743&r2=552744
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassOptionalAttributesPage.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassOptionalAttributesPage.java Tue Jul 3 01:50:42 2007
@@ -20,13 +20,24 @@
package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
+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.model.AttributeTypeImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.view.dialogs.AttributeTypeSelectionDialog;
+import org.eclipse.jface.dialogs.Dialog;
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.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -46,6 +57,15 @@
*/
public class NewObjectClassOptionalAttributesPage extends WizardPage
{
+ /** The optional attribute types list */
+ private List<AttributeTypeImpl> optionalAttributeTypesList;
+
+ // UI Fields
+ private TableViewer optionalAttributeTypesTableViewer;
+ private Button optionalAttributeTypesAddButton;
+ private Button optionalAttributeTypesRemoveButton;
+
+
/**
* Creates a new instance of NewObjectClassOptionalAttributesPage.
*/
@@ -56,6 +76,7 @@
setDescription( "Please specify the optional attribute types for the object class." );
setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
PluginConstants.IMG_OBJECT_CLASS_NEW_WIZARD ) );
+ optionalAttributeTypesList = new ArrayList<AttributeTypeImpl>();
}
@@ -79,16 +100,113 @@
GridData optionalAttributeTypesTableGridData = new GridData( SWT.FILL, SWT.FILL, true, true, 1, 2 );
optionalAttributeTypesTableGridData.heightHint = 100;
optionalAttributeTypesTable.setLayoutData( optionalAttributeTypesTableGridData );
- TableViewer optionalAttributeTypesTableViewer = new TableViewer( optionalAttributeTypesTable );
- optionalAttributeTypesTableViewer.setLabelProvider( new LabelProvider() );
+ optionalAttributeTypesTableViewer = new TableViewer( optionalAttributeTypesTable );
optionalAttributeTypesTableViewer.setContentProvider( new ArrayContentProvider() );
- Button optionalAttributeTypesAddButton = new Button( optionalAttributeTypesGroup, SWT.PUSH );
+ optionalAttributeTypesTableViewer.setLabelProvider( new LabelProvider() );
+ optionalAttributeTypesTableViewer.setInput( optionalAttributeTypesList );
+ optionalAttributeTypesTableViewer.addSelectionChangedListener( new ISelectionChangedListener()
+ {
+ public void selectionChanged( SelectionChangedEvent event )
+ {
+ optionalAttributeTypesRemoveButton.setEnabled( !event.getSelection().isEmpty() );
+ }
+ } );
+ optionalAttributeTypesAddButton = new Button( optionalAttributeTypesGroup, SWT.PUSH );
optionalAttributeTypesAddButton.setText( "Add..." );
optionalAttributeTypesAddButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) );
- Button optionalAttributeTypesRemoveButton = new Button( optionalAttributeTypesGroup, SWT.PUSH );
+ optionalAttributeTypesAddButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ addOptionalAttributeType();
+ }
+ } );
+ optionalAttributeTypesRemoveButton = new Button( optionalAttributeTypesGroup, SWT.PUSH );
optionalAttributeTypesRemoveButton.setText( "Remove" );
optionalAttributeTypesRemoveButton.setLayoutData( new GridData( SWT.FILL, SWT.NONE, false, false ) );
+ optionalAttributeTypesRemoveButton.addSelectionListener( new SelectionAdapter()
+ {
+ public void widgetSelected( SelectionEvent arg0 )
+ {
+ removeOptionalAttributeType();
+ }
+ } );
+ optionalAttributeTypesRemoveButton.setEnabled( false );
setControl( composite );
+ }
+
+
+ /**
+ * This method is called when the "Add" button of the optional
+ * attribute types table is selected.
+ */
+ private void addOptionalAttributeType()
+ {
+ AttributeTypeSelectionDialog dialog = new AttributeTypeSelectionDialog();
+ List<AttributeTypeImpl> hiddenAttributes = new ArrayList<AttributeTypeImpl>();
+ List<AttributeTypeImpl> mdndatoryAttributes = ( ( NewObjectClassWizard ) getWizard() )
+ .getMandatoryAttributesPage().getMandatoryAttributeTypes();
+ hiddenAttributes.addAll( mdndatoryAttributes );
+ hiddenAttributes.addAll( optionalAttributeTypesList );
+ dialog.setHiddenAttributeTypes( hiddenAttributes );
+ if ( dialog.open() == Dialog.OK )
+ {
+ optionalAttributeTypesList.add( dialog.getSelectedAttributeType() );
+ updateOptionalAttributeTypesTableTable();
+ }
+ }
+
+
+ /**
+ * This method is called when the "Remove" button of the optional
+ * attribute types table is selected.
+ */
+ private void removeOptionalAttributeType()
+ {
+ StructuredSelection selection = ( StructuredSelection ) optionalAttributeTypesTableViewer.getSelection();
+ if ( !selection.isEmpty() )
+ {
+ optionalAttributeTypesList.remove( selection.getFirstElement() );
+ updateOptionalAttributeTypesTableTable();
+ }
+ }
+
+
+ /**
+ * Updates the optional attribute types table.
+ */
+ private void updateOptionalAttributeTypesTableTable()
+ {
+ optionalAttributeTypesTableViewer.refresh();
+ }
+
+
+ /**
+ * Gets the optional attribute types.
+ *
+ * @return
+ * the optional attributes types
+ */
+ public List<AttributeTypeImpl> getOptionalAttributeTypes()
+ {
+ return optionalAttributeTypesList;
+ }
+
+
+ /**
+ * Gets the names of the optional attribute types.
+ *
+ * @return
+ * the names of the optional attributes types
+ */
+ public String[] getOptionalAttributeTypesNames()
+ {
+ List<String> names = new ArrayList<String>();
+ for ( AttributeTypeImpl at : optionalAttributeTypesList )
+ {
+ names.add( at.getName() );
+ }
+ return names.toArray( new String[0] );
}
}
Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassWizard.java?view=diff&rev=552744&r1=552743&r2=552744
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassWizard.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/NewObjectClassWizard.java Tue Jul 3 01:50:42 2007
@@ -20,9 +20,10 @@
package org.apache.directory.studio.apacheds.schemaeditor.view.wizards;
+import org.apache.directory.studio.apacheds.schemaeditor.Activator;
+import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
@@ -36,10 +37,10 @@
public class NewObjectClassWizard extends Wizard implements INewWizard
{
// The pages of the wizards
- private WizardPage generalPage;
- private WizardPage contentPage;
- private WizardPage mandatoryAttributesPage;
- private WizardPage optionalAttributesPage;
+ private NewObjectClassGeneralPageWizardPage generalPage;
+ private NewObjectClassContentWizardPage contentPage;
+ private NewObjectClassMandatoryAttributesPage mandatoryAttributesPage;
+ private NewObjectClassOptionalAttributesPage optionalAttributesPage;
/* (non-Javadoc)
@@ -66,7 +67,18 @@
*/
public boolean performFinish()
{
- // TODO Auto-generated method stub
+ ObjectClassImpl newOC = new ObjectClassImpl( generalPage.getOidValue() );
+ newOC.setSchema( generalPage.getSchemaValue() );
+ newOC.setNames( generalPage.getAliasesValue() );
+ newOC.setDescription( generalPage.getDescriptionValue() );
+ newOC.setSuperClassesNames( contentPage.getSuperiorsNameValue() );
+ newOC.setType( contentPage.getClassTypeValue() );
+ newOC.setObsolete( contentPage.getObsoleteValue() );
+ newOC.setMustNamesList( mandatoryAttributesPage.getMandatoryAttributeTypesNames() );
+ newOC.setMustNamesList( optionalAttributesPage.getOptionalAttributeTypesNames() );
+
+ Activator.getDefault().getSchemaHandler().addObjectClass( newOC );
+
return true;
}
@@ -77,5 +89,29 @@
public void init( IWorkbench workbench, IStructuredSelection selection )
{
// Nothing to do.
+ }
+
+
+ /**
+ * Gets the mandatory attributes page.
+ *
+ * @return
+ * the mandatory attributes page
+ */
+ public NewObjectClassMandatoryAttributesPage getMandatoryAttributesPage()
+ {
+ return mandatoryAttributesPage;
+ }
+
+
+ /**
+ * Gets the optional attributes page.
+ *
+ * @return
+ * the optional attributes page
+ */
+ public NewObjectClassOptionalAttributesPage getOptionalAttributesPage()
+ {
+ return optionalAttributesPage;
}
}