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/08/20 14:29:13 UTC
svn commit: r567667 - in
/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views:
SearchView.java SearchViewLabelProvider.java
Author: pamarcelot
Date: Mon Aug 20 05:29:12 2007
New Revision: 567667
URL: http://svn.apache.org/viewvc?rev=567667&view=rev
Log:
Added implementation for the search feature.
Improved appearance of the Search composite.
Added a dedicated Label provider for the SearchView.
Added:
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SearchViewLabelProvider.java
Modified:
directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SearchView.java
Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SearchView.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SearchView.java?rev=567667&r1=567666&r2=567667&view=diff
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SearchView.java (original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SearchView.java Mon Aug 20 05:29:12 2007
@@ -24,16 +24,19 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.regex.Pattern;
import org.apache.directory.shared.ldap.schema.SchemaObject;
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.controller.SearchViewController;
+import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
import org.apache.directory.studio.apacheds.schemaeditor.view.search.SearchPage;
import org.apache.directory.studio.apacheds.schemaeditor.view.search.SearchPage.SearchScopeEnum;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
@@ -52,7 +55,6 @@
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
@@ -75,13 +77,6 @@
/** The current Search String */
private String searchString;
- /** The Type column */
- private final String TYPE_COLUMN = "Type";
- /** The Name column*/
- private final String NAME_COLUMN = "Name";
- /** The Schema column */
- private final String SCHEMA_COLUMN = "Schema";
-
// UI fields
private Text searchField;
private Button searchButton;
@@ -170,6 +165,7 @@
// Search Label
Label searchFieldLabel = new Label( searchFieldInnerComposite, SWT.NONE );
searchFieldLabel.setText( "Search:" );
+ searchFieldLabel.setLayoutData( new GridData( SWT.NONE, SWT.CENTER, false, false ) );
// Search Text Field
searchField = new Text( searchFieldInnerComposite, SWT.BORDER );
@@ -177,7 +173,7 @@
{
searchField.setText( searchString );
}
- searchField.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) );
+ searchField.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
searchField.addModifyListener( new ModifyListener()
{
public void modifyText( ModifyEvent e )
@@ -189,7 +185,7 @@
{
public void keyReleased( KeyEvent e )
{
- if ( e.keyCode == 13 ) // TODO replace with the correct key
+ if ( e.keyCode == 13 ) // TODO replace with the correct key and add the other enter key...
{
search();
}
@@ -215,6 +211,7 @@
menu.setVisible( true );
}
} );
+ scopeToolBar.setLayoutData( new GridData( SWT.NONE, SWT.CENTER, false, false ) );
// Search Button
searchButton = new Button( searchFieldInnerComposite, SWT.PUSH | SWT.DOWN );
@@ -229,6 +226,7 @@
search();
}
} );
+ searchButton.setLayoutData( new GridData( SWT.NONE, SWT.CENTER, false, false ) );
// Separator Label
separatorLabel = new Label( searchFieldComposite, SWT.SEPARATOR | SWT.HORIZONTAL );
@@ -396,36 +394,16 @@
*/
private void createTableViewer()
{
+ // Creating the TableViewer
resultsTable = new Table( parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION
| SWT.HIDE_SELECTION );
-
GridData gridData = new GridData( SWT.FILL, SWT.FILL, true, true );
resultsTable.setLayoutData( gridData );
-
- resultsTable.setLinesVisible( false );
- resultsTable.setHeaderVisible( true );
-
- // 1st column with image
- TableColumn column = new TableColumn( resultsTable, SWT.CENTER, 0 );
- column.setText( TYPE_COLUMN );
- column.setWidth( 40 );
-
- // 2nd column with name
- column = new TableColumn( resultsTable, SWT.LEFT, 1 );
- column.setText( NAME_COLUMN );
- column.setWidth( 400 );
-
- // 3rd column with element defining schema
- column = new TableColumn( resultsTable, SWT.LEFT, 2 );
- column.setText( SCHEMA_COLUMN );
- column.setWidth( 100 );
+ resultsTable.setLinesVisible( true );
// Creating the TableViewer
resultsTableViewer = new TableViewer( resultsTable );
- // resultsTableViewer.setUseHashlookup( true );
- resultsTableViewer.setColumnProperties( new String[]
- { TYPE_COLUMN, NAME_COLUMN, SCHEMA_COLUMN } );
- resultsTableViewer.setLabelProvider( new LabelProvider() );
+ resultsTableViewer.setLabelProvider( new SearchViewLabelProvider() );
resultsTableViewer.setContentProvider( new ArrayContentProvider() );
}
@@ -630,6 +608,7 @@
List<SchemaObject> results = search( searchString, scope );
setSearchResultsLabel( searchString, results.size() );
+ resultsTableViewer.setInput( results );
}
@@ -643,7 +622,201 @@
*/
private List<SchemaObject> search( String searchString, SearchScopeEnum[] scope )
{
- return new ArrayList<SchemaObject>();
+ List<SchemaObject> searchResults = new ArrayList<SchemaObject>();
+
+ if ( searchString != null )
+ {
+ Pattern pattern = Pattern.compile( ".*" + searchString + ".*", Pattern.CASE_INSENSITIVE );
+
+ SchemaHandler schemaHandler = Activator.getDefault().getSchemaHandler();
+ if ( schemaHandler != null )
+ {
+ List<SearchScopeEnum> searchScope = new ArrayList<SearchScopeEnum>( Arrays.asList( scope ) );
+
+ // Looping on attribute types
+ List<AttributeTypeImpl> attributeTypes = schemaHandler.getAttributeTypes();
+ for ( AttributeTypeImpl at : attributeTypes )
+ {
+ // Aliases
+ if ( searchScope.contains( SearchScopeEnum.ALIASES ) )
+ {
+ if ( checkArray( pattern, at.getNames() ) )
+ {
+ searchResults.add( at );
+ continue;
+ }
+ }
+
+ // OID
+ if ( searchScope.contains( SearchScopeEnum.OID ) )
+ {
+ if ( checkString( pattern, at.getOid() ) )
+ {
+ searchResults.add( at );
+ continue;
+ }
+ }
+
+ // Description
+ if ( searchScope.contains( SearchScopeEnum.DESCRIPTION ) )
+ {
+ if ( checkString( pattern, at.getDescription() ) )
+ {
+ searchResults.add( at );
+ continue;
+ }
+ }
+
+ // Superior
+ if ( searchScope.contains( SearchScopeEnum.SUPERIOR ) )
+ {
+ if ( checkString( pattern, at.getSuperiorName() ) )
+ {
+ searchResults.add( at );
+ continue;
+ }
+ }
+
+ // Syntax
+ if ( searchScope.contains( SearchScopeEnum.SYNTAX ) )
+ {
+ if ( checkString( pattern, at.getSyntaxOid() ) )
+ {
+ searchResults.add( at );
+ continue;
+ }
+ }
+
+ // Matching Rules
+ if ( searchScope.contains( SearchScopeEnum.MATCHING_RULES ) )
+ {
+ // Equality
+ if ( checkString( pattern, at.getEqualityName() ) )
+ {
+ searchResults.add( at );
+ continue;
+ }
+
+ // Ordering
+ if ( checkString( pattern, at.getOrderingName() ) )
+ {
+ searchResults.add( at );
+ continue;
+ }
+
+ // Substring
+ if ( checkString( pattern, at.getSubstrName() ) )
+ {
+ searchResults.add( at );
+ continue;
+ }
+ }
+ }
+
+ // Looping on object classes
+ List<ObjectClassImpl> objectClasses = schemaHandler.getObjectClasses();
+ for ( ObjectClassImpl oc : objectClasses )
+ {
+ // Aliases
+ if ( searchScope.contains( SearchScopeEnum.ALIASES ) )
+ {
+ if ( checkArray( pattern, oc.getNames() ) )
+ {
+ searchResults.add( oc );
+ continue;
+ }
+ }
+
+ // OID
+ if ( searchScope.contains( SearchScopeEnum.OID ) )
+ {
+ if ( checkString( pattern, oc.getOid() ) )
+ {
+ searchResults.add( oc );
+ continue;
+ }
+ }
+
+ // Description
+ if ( searchScope.contains( SearchScopeEnum.DESCRIPTION ) )
+ {
+ if ( checkString( pattern, oc.getDescription() ) )
+ {
+ searchResults.add( oc );
+ continue;
+ }
+ }
+
+ // Superiors
+ if ( searchScope.contains( SearchScopeEnum.SUPERIORS ) )
+ {
+ if ( checkArray( pattern, oc.getSuperClassesNames() ) )
+ {
+ searchResults.add( oc );
+ continue;
+ }
+ }
+
+ // Mandatory Attributes
+ if ( searchScope.contains( SearchScopeEnum.MANDATORY_ATTRIBUTES ) )
+ {
+ if ( checkArray( pattern, oc.getMustNamesList() ) )
+ {
+ searchResults.add( oc );
+ continue;
+ }
+ }
+
+ // Optional Attributes
+ if ( searchScope.contains( SearchScopeEnum.OPTIONAL_ATTRIBUTES ) )
+ {
+ if ( checkArray( pattern, oc.getMayNamesList() ) )
+ {
+ searchResults.add( oc );
+ continue;
+ }
+ }
+ }
+ }
+ }
+
+ return searchResults;
+ }
+
+
+ /**
+ * Check an array with the given pattern.
+ *
+ * @param pattern
+ * the Regex pattern
+ * @param array
+ * the array
+ * @return
+ * true if the pattern matches one of the aliases, false, if not.
+ */
+ private boolean checkArray( Pattern pattern, String[] array )
+ {
+ if ( array != null )
+ {
+ for ( String string : array )
+ {
+ return pattern.matcher( string ).matches();
+
+ }
+ }
+
+ return false;
+ }
+
+
+ private boolean checkString( Pattern pattern, String string )
+ {
+ if ( string != null )
+ {
+ return pattern.matcher( string ).matches();
+ }
+
+ return false;
}
Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SearchViewLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SearchViewLabelProvider.java?rev=567667&view=auto
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SearchViewLabelProvider.java (added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/views/SearchViewLabelProvider.java Mon Aug 20 05:29:12 2007
@@ -0,0 +1,290 @@
+/*
+ * 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.views;
+
+
+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.model.ObjectClassImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.view.ViewUtils;
+import org.apache.directory.studio.apacheds.schemaeditor.view.wrappers.Folder;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+
+/**
+ * This class implements the LabelProvider for the SearchView.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SearchViewLabelProvider extends LabelProvider
+{
+ private static final String NONE = "(None)";
+
+ /** The preferences store */
+ private IPreferenceStore store;
+
+
+ /**
+ * Creates a new instance of DifferencesWidgetSchemaLabelProvider.
+ */
+ public SearchViewLabelProvider()
+ {
+ store = Activator.getDefault().getPreferenceStore();
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+ */
+ public String getText( Object element )
+ {
+ String label = ""; //$NON-NLS-1$
+
+ int labelValue = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_LABEL );
+ boolean abbreviate = store.getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE );
+ int abbreviateMaxLength = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_ABBREVIATE_MAX_LENGTH );
+ boolean secondaryLabelDisplay = store.getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_DISPLAY );
+ int secondaryLabelValue = store.getInt( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL );
+ boolean secondaryLabelAbbreviate = store
+ .getBoolean( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE );
+ int secondaryLabelAbbreviateMaxLength = store
+ .getInt( PluginConstants.PREFS_SCHEMA_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH );
+
+ if ( element instanceof AttributeTypeImpl )
+ {
+ AttributeTypeImpl at = ( AttributeTypeImpl ) element;
+
+ // Label
+ if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME )
+ {
+ String[] names = at.getNames();
+ if ( ( names != null ) && ( names.length > 0 ) )
+ {
+ label = names[0];
+ }
+ else
+ {
+ label = NONE;
+ }
+ }
+ else if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES )
+ {
+ String[] names = at.getNames();
+ if ( ( names != null ) && ( names.length > 0 ) )
+ {
+ label = ViewUtils.concateAliases( names );
+ }
+ else
+ {
+ label = NONE;
+ }
+ }
+ else if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID )
+ {
+ label = at.getOid();
+ }
+ else
+ // Default
+ {
+ String[] names = at.getNames();
+ if ( ( names != null ) && ( names.length > 0 ) )
+ {
+ label = names[0];
+ }
+ else
+ {
+ label = NONE;
+ }
+ }
+
+ // Abbreviate
+ if ( abbreviate && ( abbreviateMaxLength < label.length() ) )
+ {
+ label = label.substring( 0, abbreviateMaxLength ) + "..."; //$NON-NLS-1$
+ }
+ }
+ else if ( element instanceof ObjectClassImpl )
+ {
+ ObjectClassImpl oc = ( ObjectClassImpl ) element;
+
+ // Label
+ if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME )
+ {
+ String[] names = oc.getNames();
+ if ( ( names != null ) && ( names.length > 0 ) )
+ {
+ label = names[0];
+ }
+ else
+ {
+ label = NONE;
+ }
+ }
+ else if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES )
+ {
+ String[] names = oc.getNames();
+ if ( ( names != null ) && ( names.length > 0 ) )
+ {
+ label = ViewUtils.concateAliases( names );
+ }
+ else
+ {
+ label = NONE;
+ }
+ }
+ else if ( labelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID )
+ {
+ label = oc.getOid();
+ }
+ else
+ // Default
+ {
+ String[] names = oc.getNames();
+ if ( ( names != null ) && ( names.length > 0 ) )
+ {
+ label = names[0];
+ }
+ else
+ {
+ label = NONE;
+ }
+ }
+
+ // Abbreviate
+ if ( abbreviate && ( abbreviateMaxLength < label.length() ) )
+ {
+ label = label.substring( 0, abbreviateMaxLength ) + "..."; //$NON-NLS-1$
+ }
+ }
+ else if ( element instanceof Folder )
+ {
+ Folder folder = ( Folder ) element;
+
+ return folder.getName() + " (" + folder.getChildren().size() + ")";
+ }
+
+ // Secondary Label
+ if ( secondaryLabelDisplay )
+ {
+ String secondaryLabel = ""; //$NON-NLS-1$
+ if ( element instanceof AttributeTypeImpl )
+ {
+ AttributeTypeImpl at = ( AttributeTypeImpl ) element;
+
+ if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME )
+ {
+ String[] names = at.getNames();
+ if ( ( names != null ) && ( names.length > 0 ) )
+ {
+ secondaryLabel = names[0];
+ }
+ else
+ {
+ secondaryLabel = NONE;
+ }
+ }
+ else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES )
+ {
+ String[] names = at.getNames();
+ if ( ( names != null ) && ( names.length > 0 ) )
+ {
+ secondaryLabel = ViewUtils.concateAliases( names );
+ }
+ else
+ {
+ secondaryLabel = NONE;
+ }
+ }
+ else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID )
+ {
+ secondaryLabel = at.getOid();
+ }
+ }
+ else if ( element instanceof ObjectClassImpl )
+ {
+ ObjectClassImpl oc = ( ObjectClassImpl ) element;
+
+ if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_FIRST_NAME )
+ {
+ String[] names = oc.getNames();
+ if ( ( names != null ) && ( names.length > 0 ) )
+ {
+ secondaryLabel = names[0];
+ }
+ else
+ {
+ secondaryLabel = NONE;
+ }
+ }
+ else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_ALL_ALIASES )
+ {
+ String[] names = oc.getNames();
+ if ( ( names != null ) && ( names.length > 0 ) )
+ {
+ secondaryLabel = ViewUtils.concateAliases( names );
+ }
+ else
+ {
+ secondaryLabel = NONE;
+ }
+ }
+ else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_VIEW_LABEL_OID )
+ {
+ secondaryLabel = oc.getOid();
+ }
+ }
+
+ if ( secondaryLabelAbbreviate && ( secondaryLabelAbbreviateMaxLength < secondaryLabel.length() ) )
+ {
+ secondaryLabel = secondaryLabel.substring( 0, secondaryLabelAbbreviateMaxLength ) + "..."; //$NON-NLS-1$
+ }
+
+ label += " [" + secondaryLabel + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return label;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
+ */
+ public Image getImage( Object element )
+ {
+ if ( element instanceof AttributeTypeImpl )
+ {
+ return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_ATTRIBUTE_TYPE )
+ .createImage();
+ }
+ else if ( element instanceof ObjectClassImpl )
+ {
+ return AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_OBJECT_CLASS )
+ .createImage();
+ }
+
+ // Default
+ return null;
+ }
+}