directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r514327 - in /directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui: widgets/ wizards/
Date Sun, 04 Mar 2007 02:11:56 GMT
Author: seelmann
Date: Sat Mar  3 18:11:55 2007
New Revision: 514327

URL: http://svn.apache.org/viewvc?view=rev&rev=514327
Log:
Improved new entry wizard:
o Added instant search to object class selection (DIRSTUDIO-55)
o Inherited object classes are added (DIRSTUDIO-56)
o Added content assist to RDN attribute type combo
o Value editor is started automatically if there is an empty value
o Improved focus settings

Added:
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/widgets/ListContentProposalProvider.java
Modified:
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/widgets/DnBuilderWidget.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryAttributesWizardPage.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryDnWizardPage.java
    directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryObjectclassWizardPage.java

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/widgets/DnBuilderWidget.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/widgets/DnBuilderWidget.java?view=diff&rev=514327&r1=514326&r2=514327
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/widgets/DnBuilderWidget.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/widgets/DnBuilderWidget.java
Sat Mar  3 18:11:55 2007
@@ -29,15 +29,23 @@
 import org.apache.directory.ldapstudio.browser.core.model.RDN;
 import org.apache.directory.ldapstudio.browser.core.model.RDNPart;
 import org.apache.directory.ldapstudio.browser.ui.widgets.search.EntryWidget;
+import org.eclipse.jface.fieldassist.ComboContentAdapter;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.DecoratedField;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.fieldassist.IControlCreator;
 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.layout.GridData;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Combo;
 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.Text;
@@ -132,6 +140,7 @@
                 RdnLine rdnLine = rdnLineList.get( i );
                 String oldName = rdnLine.rdnNameCombo.getText();
                 rdnLine.rdnNameCombo.setItems( attributeNames );
+                rdnLine.rdnNameCPA.setContentProposalProvider( new ListContentProposalProvider(
attributeNames ) );
                 if ( Arrays.asList( rdnLine.rdnNameCombo.getItems() ).contains( oldName )
)
                 {
                     rdnLine.rdnNameCombo.setText( oldName );
@@ -148,6 +157,7 @@
             if ( currentRdn == null || currentRdn.getParts().length == 0 )
             {
                 addRdnLine( rdnComposite, 0 );
+                rdnLineList.get( 0 ).rdnNameCombo.setFocus();
             }
             else
             {
@@ -159,7 +169,15 @@
                     rdnLineList.get( i ).rdnValueText.setText( parts[i].getUnencodedValue()
);
                     if ( i == 0 )
                     {
-                        rdnLineList.get( i ).rdnValueText.setFocus();
+                        if("".equals(rdnLineList.get( i ).rdnNameCombo))
+                        {
+                            rdnLineList.get( i ).rdnNameCombo.setFocus();
+                        }
+                        else
+                        {
+                            rdnLineList.get( i ).rdnValueText.selectAll();
+                            rdnLineList.get( i ).rdnValueText.setFocus();
+                        }
                     }
                 }
             }
@@ -385,7 +403,7 @@
                 String oldValue = oldRdnLine.rdnValueText.getText();
 
                 // delete old
-                oldRdnLine.rdnNameCombo.dispose();
+                oldRdnLine.rdnNameComboField.getLayoutControl().dispose();
                 oldRdnLine.rdnEqualsLabel.dispose();
                 oldRdnLine.rdnValueText.dispose();
                 oldRdnLine.rdnAddButton.dispose();
@@ -430,11 +448,30 @@
     {
         final RdnLine rdnLine = new RdnLine();
 
-        rdnLine.rdnNameCombo = new Combo( rdnComposite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER
);
+        final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
+            FieldDecorationRegistry.DEC_CONTENT_PROPOSAL );
+        rdnLine.rdnNameComboField = new DecoratedField( rdnComposite, SWT.NONE, new IControlCreator()
+        {
+            public Control createControl( Composite parent, int style )
+            {
+                Combo combo = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER );
+                GridData gd = new GridData();
+                gd.widthHint = 180;
+                combo.setLayoutData( gd );
+                combo.setVisibleItemCount( 20 );
+                return combo;
+            }
+        } );
+        rdnLine.rdnNameComboField.addFieldDecoration( fieldDecoration, SWT.TOP | SWT.LEFT,
true );
         GridData gd = new GridData();
         gd.widthHint = 180;
-        rdnLine.rdnNameCombo.setLayoutData( gd );
-        rdnLine.rdnNameCombo.setVisibleItemCount( 20 );
+        rdnLine.rdnNameComboField.getLayoutControl().setLayoutData( gd );
+        rdnLine.rdnNameCombo = ( Combo ) rdnLine.rdnNameComboField.getControl();
+
+        rdnLine.rdnNameCPA = new ContentProposalAdapter( rdnLine.rdnNameCombo, new ComboContentAdapter(),
+            new ListContentProposalProvider( attributeNames ), null, null );
+        rdnLine.rdnNameCPA.setFilterStyle( ContentProposalAdapter.FILTER_NONE );
+        rdnLine.rdnNameCPA.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE
);
 
         rdnLine.rdnEqualsLabel = new Label( rdnComposite, SWT.NONE );
         rdnLine.rdnEqualsLabel.setText( "=" );
@@ -471,7 +508,7 @@
 
         rdnLine.rdnDeleteButton = new Button( rdnComposite, SWT.PUSH );
         rdnLine.rdnDeleteButton.setText( "  \u2212  " ); // \u2013
-        rdnLine.rdnDeleteButton.addSelectionListener( new SelectionListener()
+        rdnLine.rdnDeleteButton.addSelectionListener( new SelectionAdapter()
         {
             public void widgetSelected( SelectionEvent e )
             {
@@ -488,11 +525,6 @@
 
                 validate();
             }
-
-
-            public void widgetDefaultSelected( SelectionEvent e )
-            {
-            }
         } );
 
         if ( attributeNames != null )
@@ -518,14 +550,17 @@
         RdnLine rdnLine = ( RdnLine ) rdnLineList.remove( index );
         if ( rdnLine != null )
         {
-            rdnLine.rdnNameCombo.dispose();
+            rdnLine.rdnNameComboField.getLayoutControl().dispose();
             rdnLine.rdnEqualsLabel.dispose();
             rdnLine.rdnValueText.dispose();
             rdnLine.rdnAddButton.dispose();
             rdnLine.rdnDeleteButton.dispose();
 
-            rdnComposite.layout( true, true );
-            shell.layout( true, true );
+            if ( !rdnComposite.isDisposed() )
+            {
+                rdnComposite.layout( true, true );
+                shell.layout( true, true );
+            }
         }
     }
 
@@ -536,7 +571,13 @@
     {
 
         /** The rdn name combo. */
+        public DecoratedField rdnNameComboField;
+
+        /** The rdn name combo. */
         public Combo rdnNameCombo;
+
+        /** The content proposal adapter */
+        public ContentProposalAdapter rdnNameCPA;
 
         /** The rdn value text. */
         public Text rdnValueText;

Added: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/widgets/ListContentProposalProvider.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/widgets/ListContentProposalProvider.java?view=auto&rev=514327
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/widgets/ListContentProposalProvider.java
(added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/widgets/ListContentProposalProvider.java
Sat Mar  3 18:11:55 2007
@@ -0,0 +1,112 @@
+package org.apache.directory.ldapstudio.browser.ui.widgets;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.jface.fieldassist.IContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+
+
+/**
+ * ListContentProposalProvider is a class designed to map a dynamic list of
+ * Strings to content proposals.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ListContentProposalProvider implements IContentProposalProvider
+{
+
+    /** The dynamic list of proposals */
+    private List<String> proposals;
+
+
+    /**
+     * Creates a new instance of ListContentProposalProvider.
+     *
+     * @param proposals the dynamic list of proposals
+     */
+    public ListContentProposalProvider( List<String> proposals )
+    {
+        setProposals( proposals );
+    }
+
+
+    /**
+     * Creates a new instance of ListContentProposalProvider.
+     *
+     * @param proposals the proposals
+     */
+    public ListContentProposalProvider( String[] proposals )
+    {
+        setProposals( new ArrayList<String>( Arrays.asList( proposals ) ) );
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public IContentProposal[] getProposals( String contents, int position )
+    {
+        String string = contents.substring( 0, position );
+
+        Collections.sort( proposals );
+
+        List<IContentProposal> proposalList = new ArrayList<IContentProposal>();
+        for ( int k = 0; k < proposals.size(); k++ )
+        {
+            final String proposal = proposals.get( k );
+            if ( proposal.toUpperCase().startsWith( string.toUpperCase() ) && !proposal.equalsIgnoreCase(
string )
+                && !"".equals( string ) )
+            {
+                IContentProposal p = new IContentProposal()
+                {
+                    public String getContent()
+                    {
+                        return proposal;
+                    }
+
+
+                    public String getDescription()
+                    {
+                        return proposal;
+                    }
+
+
+                    public String getLabel()
+                    {
+                        return proposal;
+                    }
+
+
+                    public int getCursorPosition()
+                    {
+                        return proposal.length();
+                    }
+                };
+                proposalList.add( p );
+            }
+        }
+        return proposalList.toArray( new IContentProposal[proposalList.size()] );
+    }
+
+
+    /**
+     * Sets the possible strings.
+     * 
+     * @param proposals the possible strings
+     */
+    public void setProposals( List<String> proposals )
+    {
+        if ( proposals == null )
+        {
+            proposals = new ArrayList<String>();
+        }
+
+        this.proposals = proposals;
+    }
+
+}

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryAttributesWizardPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryAttributesWizardPage.java?view=diff&rev=514327&r1=514326&r2=514327
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryAttributesWizardPage.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryAttributesWizardPage.java
Sat Mar  3 18:11:55 2007
@@ -35,7 +35,8 @@
 import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidgetActionGroup;
 import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidgetConfiguration;
 import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.EntryEditorWidgetUniversalListener;
-
+import org.apache.directory.ldapstudio.browser.ui.widgets.entryeditor.OpenDefaultEditorAction;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
@@ -95,6 +96,7 @@
         {
 
             DummyEntry newEntry = wizard.getNewEntry();
+            IValue editValue = null;
 
             try
             {
@@ -131,6 +133,11 @@
                         IAttribute att = new Attribute( newEntry, newMust[i] );
                         newEntry.addAttribute( att );
                         att.addEmptyValue();
+
+                        if ( editValue == null )
+                        {
+                            editValue = att.getValues()[0];
+                        }
                     }
                 }
             }
@@ -146,6 +153,20 @@
             this.mainWidget.getViewer().setInput( newEntry );
             this.mainWidget.getViewer().refresh();
             validate();
+
+            // set focus to the viewer
+            mainWidget.getViewer().getControl().setFocus();
+
+            // start editing
+            if ( editValue != null )
+            {
+                mainWidget.getViewer().setSelection( new StructuredSelection( editValue ),
true );
+                OpenDefaultEditorAction openDefaultEditorAction = actionGroup.getOpenDefaultEditorAction();
+                if ( openDefaultEditorAction.isEnabled() )
+                {
+                    openDefaultEditorAction.run();
+                }
+            }
         }
         else
         {

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryDnWizardPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryDnWizardPage.java?view=diff&rev=514327&r1=514326&r2=514327
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryDnWizardPage.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryDnWizardPage.java
Sat Mar  3 18:11:55 2007
@@ -42,7 +42,6 @@
 import org.apache.directory.ldapstudio.browser.ui.widgets.DnBuilderWidget;
 import org.apache.directory.ldapstudio.browser.ui.widgets.WidgetModifyEvent;
 import org.apache.directory.ldapstudio.browser.ui.widgets.WidgetModifyListener;
-
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.WizardPage;

Modified: directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryObjectclassWizardPage.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryObjectclassWizardPage.java?view=diff&rev=514327&r1=514326&r2=514327
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryObjectclassWizardPage.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-ui/src/main/java/org/apache/directory/ldapstudio/browser/ui/wizards/NewEntryObjectclassWizardPage.java
Sat Mar  3 18:11:55 2007
@@ -25,6 +25,7 @@
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.directory.ldapstudio.browser.core.events.EventRegistry;
 import org.apache.directory.ldapstudio.browser.core.internal.model.Attribute;
@@ -33,9 +34,14 @@
 import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
 import org.apache.directory.ldapstudio.browser.core.model.IValue;
 import org.apache.directory.ldapstudio.browser.core.model.ModelModificationException;
+import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription;
 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants;
 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin;
 import org.apache.directory.ldapstudio.browser.ui.widgets.BaseWidgetUtils;
+import org.eclipse.jface.fieldassist.DecoratedField;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.fieldassist.IControlCreator;
 import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
@@ -43,17 +49,24 @@
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
 import org.eclipse.jface.viewers.ViewerSorter;
 import org.eclipse.jface.wizard.IWizardPage;
 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;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
 
 
 public class NewEntryObjectclassWizardPage extends WizardPage
@@ -65,11 +78,13 @@
 
     private NewEntryWizard wizard;
 
-    private List availableObjectClasses;
+    private List<ObjectClassDescription> availableObjectClasses;
+
+    private Text availabeObjectClassesInstantSearch;
 
     private ListViewer availableObjectClassesViewer;
 
-    private List selectedObjectClasses;
+    private List<ObjectClassDescription> selectedObjectClasses;
 
     private ListViewer selectedObjectClassesViewer;
 
@@ -90,8 +105,8 @@
 
         this.wizard = wizard;
 
-        this.availableObjectClasses = new ArrayList();
-        this.selectedObjectClasses = new ArrayList();
+        this.availableObjectClasses = new ArrayList<ObjectClassDescription>();
+        this.selectedObjectClasses = new ArrayList<ObjectClassDescription>();
     }
 
 
@@ -117,19 +132,21 @@
         if ( wizard.getSelectedConnection() != null )
         {
             availableObjectClasses.addAll( Arrays.asList( wizard.getSelectedConnection().getSchema()
-                .getObjectClassDescriptionNames() ) );
-        }
+                .getObjectClassDescriptions() ) );
 
-        DummyEntry newEntry = wizard.getNewEntry();
-        IAttribute ocAttribute = newEntry.getAttribute( IAttribute.OBJECTCLASS_ATTRIBUTE
);
-        if ( ocAttribute != null )
-        {
-            String[] ocValues = ocAttribute.getStringValues();
-            for ( int i = 0; i < ocValues.length; i++ )
+            DummyEntry newEntry = wizard.getNewEntry();
+            IAttribute ocAttribute = newEntry.getAttribute( IAttribute.OBJECTCLASS_ATTRIBUTE
);
+            if ( ocAttribute != null )
             {
-                String oc = ocValues[i];
-                availableObjectClasses.remove( oc );
-                selectedObjectClasses.add( oc );
+                String[] ocValues = ocAttribute.getStringValues();
+                for ( int i = 0; i < ocValues.length; i++ )
+                {
+                    String ocValue = ocValues[i];
+                    ObjectClassDescription ocd = wizard.getSelectedConnection().getSchema().getObjectClassDescription(
+                        ocValue );
+                    availableObjectClasses.remove( ocd );
+                    selectedObjectClasses.add( ocd );
+                }
             }
         }
 
@@ -158,10 +175,10 @@
             {
                 ocAttribute.deleteValue( values[i] );
             }
-            for ( Iterator it = selectedObjectClasses.iterator(); it.hasNext(); )
+            for ( Iterator<ObjectClassDescription> it = selectedObjectClasses.iterator();
it.hasNext(); )
             {
-                Object oc = ( Object ) it.next();
-                ocAttribute.addValue( new Value( ocAttribute, oc ) );
+                ObjectClassDescription ocd = it.next();
+                ocAttribute.addValue( new Value( ocAttribute, ocd.getNames()[0] ) );
             }
 
         }
@@ -184,6 +201,7 @@
         {
             loadState();
             validate();
+            availabeObjectClassesInstantSearch.setFocus();
         }
     }
 
@@ -221,7 +239,43 @@
         Label selectedLabel = new Label( composite, SWT.NONE );
         selectedLabel.setText( "Selected object classes" );
 
-        availableObjectClassesViewer = new ListViewer( composite );
+        Composite availableObjectClassesComposite = BaseWidgetUtils.createColumnContainer(
composite, 1, 1 );
+
+        if ( FieldDecorationRegistry.getDefault().getFieldDecoration( getClass().getName()
) == null )
+        {
+            FieldDecoration dummy = FieldDecorationRegistry.getDefault().getFieldDecoration(
+                FieldDecorationRegistry.DEC_CONTENT_PROPOSAL );
+            FieldDecorationRegistry.getDefault().registerFieldDecoration( getClass().getName(),
+                "You may enter a filter to restrict the list below", dummy.getImage() );
+        }
+        final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
+            getClass().getName() );
+        final DecoratedField availabeObjectClassesInstantSearchField = new DecoratedField(
+            availableObjectClassesComposite, SWT.BORDER, new IControlCreator()
+            {
+                public Control createControl( Composite parent, int style )
+                {
+                    return BaseWidgetUtils.createText( parent, "", 1 );
+                }
+            } );
+        availabeObjectClassesInstantSearchField.addFieldDecoration( fieldDecoration, SWT.TOP
| SWT.LEFT, true );
+        availabeObjectClassesInstantSearchField.getLayoutControl().setLayoutData(
+            new GridData( SWT.FILL, SWT.CENTER, true, false ) );
+        availabeObjectClassesInstantSearch = ( Text ) availabeObjectClassesInstantSearchField.getControl();
+        availabeObjectClassesInstantSearch.addModifyListener( new ModifyListener()
+        {
+            public void modifyText( ModifyEvent e )
+            {
+                availableObjectClassesViewer.refresh();
+                if ( availableObjectClassesViewer.getList().getItemCount() == 1 )
+                {
+                    Object item = availableObjectClassesViewer.getElementAt( 0 );
+                    availableObjectClassesViewer.setSelection( new StructuredSelection( item
) );
+                }
+            }
+        } );
+
+        availableObjectClassesViewer = new ListViewer( availableObjectClassesComposite );
         GridData data = new GridData( GridData.FILL_BOTH );
         data.heightHint = SIZING_SELECTION_WIDGET_HEIGHT;
         data.widthHint = ( int ) ( SIZING_SELECTION_WIDGET_WIDTH * 0.4 );
@@ -229,6 +283,7 @@
         availableObjectClassesViewer.setContentProvider( new ArrayContentProvider() );
         availableObjectClassesViewer.setLabelProvider( new LabelProvider() );
         availableObjectClassesViewer.setSorter( new ViewerSorter() );
+        availableObjectClassesViewer.addFilter( new InstantSearchFilter( availabeObjectClassesInstantSearch
) );
         availableObjectClassesViewer.setInput( availableObjectClasses );
         availableObjectClassesViewer.addDoubleClickListener( new IDoubleClickListener()
         {
@@ -299,15 +354,32 @@
     private void add( ISelection iselection )
     {
         IStructuredSelection selection = ( IStructuredSelection ) iselection;
-        Iterator it = selection.iterator();
+        Iterator<ObjectClassDescription> it = selection.iterator();
         while ( it.hasNext() )
         {
-            Object oc = it.next();
-            availableObjectClasses.remove( oc );
-            selectedObjectClasses.add( oc );
-            availableObjectClassesViewer.refresh();
-            selectedObjectClassesViewer.refresh();
-            this.validate();
+            ObjectClassDescription ocd = it.next();
+            if ( availableObjectClasses.contains( ocd ) && !selectedObjectClasses.contains(
ocd ) )
+            {
+                availableObjectClasses.remove( ocd );
+                selectedObjectClasses.add( ocd );
+
+                // recursively add superior object classes
+                ObjectClassDescription[] superiorObjectClassDescriptions = ocd.getSuperiorObjectClassDescriptions();
+                if ( superiorObjectClassDescriptions.length > 0 )
+                {
+                    add( new StructuredSelection( superiorObjectClassDescriptions ) );
+                }
+            }
+        }
+
+        availableObjectClassesViewer.refresh();
+        selectedObjectClassesViewer.refresh();
+        this.validate();
+
+        if ( !"".equals( availabeObjectClassesInstantSearch.getText() ) )
+        {
+            availabeObjectClassesInstantSearch.setText( "" );
+            availabeObjectClassesInstantSearch.setFocus();
         }
     }
 
@@ -315,16 +387,27 @@
     private void remove( ISelection iselection )
     {
         IStructuredSelection selection = ( IStructuredSelection ) iselection;
-        Iterator it = selection.iterator();
+        Iterator<ObjectClassDescription> it = selection.iterator();
         while ( it.hasNext() )
         {
-            Object oc = it.next();
-            selectedObjectClasses.remove( oc );
-            availableObjectClasses.add( oc );
-            availableObjectClassesViewer.refresh();
-            selectedObjectClassesViewer.refresh();
-            this.validate();
+            ObjectClassDescription ocd = it.next();
+            if ( !availableObjectClasses.contains( ocd ) && selectedObjectClasses.contains(
ocd ) )
+            {
+                selectedObjectClasses.remove( ocd );
+                availableObjectClasses.add( ocd );
+
+                // recursively remove sub object classes
+                ObjectClassDescription[] subObjectClassDescriptions = ocd.getSubObjectClassDescriptions();
+                if ( subObjectClassDescriptions.length > 0 )
+                {
+                    remove( new StructuredSelection( subObjectClassDescriptions ) );
+                }
+            }
         }
+
+        availableObjectClassesViewer.refresh();
+        selectedObjectClassesViewer.refresh();
+        this.validate();
     }
 
 
@@ -333,4 +416,36 @@
 
     }
 
+    private class InstantSearchFilter extends ViewerFilter
+    {
+        private Text filterText;
+
+
+        private InstantSearchFilter( Text filterText )
+        {
+            this.filterText = filterText;
+        }
+
+
+        /**
+         * {@inheritDoc}
+         */
+        public boolean select( Viewer viewer, Object parentElement, Object element )
+        {
+            if ( element instanceof ObjectClassDescription )
+            {
+                ObjectClassDescription ocd = ( ObjectClassDescription ) element;
+                Set lowerCaseIdentifierSet = ocd.getLowerCaseIdentifierSet();
+                for ( Iterator<String> it = lowerCaseIdentifierSet.iterator(); it.hasNext();
)
+                {
+                    String s = it.next();
+                    if ( s.toLowerCase().startsWith( filterText.getText().toLowerCase() )
)
+                    {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+    }
 }



Mime
View raw message