You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/05/31 23:50:09 UTC
svn commit: r543272 [2/2] - in /directory/ldapstudio/trunk:
ldapstudio-browser-common/resources/icons/
ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/
ldapstudio-browser-common/src/main/java/org/apache/directory/...
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java?view=auto&rev=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java Thu May 31 14:50:07 2007
@@ -0,0 +1,175 @@
+/*
+ * 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.ldapstudio.browser.common.widgets.search;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.common.filtereditor.FilterAutoEditStrategy;
+import org.apache.directory.ldapstudio.browser.common.filtereditor.FilterAutoEditStrategy.AutoEditParameters;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Combo;
+
+
+/**
+ * The FilterWidgetAutoEditStrategyAdapter is used to integrate the {@link FilterAutoEditStrategy}
+ * into an combo field.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class FilterWidgetAutoEditStrategyAdapter
+{
+
+ /** The auto edit strategy. */
+ private FilterAutoEditStrategy autoEditStrategy;
+
+ /** The combo. */
+ private Combo combo;
+
+ /** The filter parser. */
+ private LdapFilterParser parser;
+
+ /** The old texts. */
+ private List<String> oldTexts;
+
+ /** The verify events. */
+ private List<VerifyEvent> verifyEvents;
+
+ /** The in apply combo customization flag. */
+ private boolean inApplyComboCustomization;
+
+
+ /**
+ * Creates a new instance of FilterWidgetAutoEditStrategyAdapter.
+ *
+ * @param combo the combo
+ * @param parser the filter parser
+ */
+ public FilterWidgetAutoEditStrategyAdapter( Combo combo, LdapFilterParser parser )
+ {
+ this.combo = combo;
+ this.parser = parser;
+
+ this.oldTexts = new ArrayList<String>();
+ this.verifyEvents = new ArrayList<VerifyEvent>();
+ this.inApplyComboCustomization = false;
+
+ this.autoEditStrategy = new FilterAutoEditStrategy( parser );
+ combo.addVerifyListener( new VerifyListener()
+ {
+ public void verifyText( VerifyEvent e )
+ {
+ prepareComboCustomization( e );
+ }
+ } );
+ combo.addModifyListener( new ModifyListener()
+ {
+ public void modifyText( ModifyEvent e )
+ {
+ applyComboCustomization( e );
+ }
+ } );
+ }
+
+
+ /**
+ * Prepares combo customization.
+ *
+ * @param e the verify event
+ */
+ public void prepareComboCustomization( VerifyEvent e )
+ {
+ //System.out.println(e);
+ if ( !inApplyComboCustomization )
+ {
+ String oldText = combo.getText();
+ parser.parse( oldText );
+
+ oldTexts.add( oldText );
+ verifyEvents.add( e );
+ }
+ }
+
+
+ /**
+ * Applies combo customization.
+ *
+ * @param e the modify event
+ */
+ public void applyComboCustomization( ModifyEvent e )
+ {
+ //System.out.println(e);
+ if ( !inApplyComboCustomization && !verifyEvents.isEmpty() )
+ {
+ String oldText = oldTexts.remove( 0 );
+ VerifyEvent verifyEvent = verifyEvents.remove( 0 );
+ inApplyComboCustomization = true;
+
+ // extract modification details
+ String text = verifyEvent.text;
+ int offset = verifyEvent.start <= verifyEvent.end ? verifyEvent.start : verifyEvent.end;
+ int length = verifyEvent.start <= verifyEvent.end ? verifyEvent.end - verifyEvent.start : verifyEvent.start
+ - verifyEvent.end;
+
+ // apply auto edit strategy
+ AutoEditParameters autoEditParameters = new AutoEditParameters( text, offset, length, -1, true );
+ autoEditStrategy.customizeAutoEditParameters( autoEditParameters );
+
+ // get current selection
+ Point oldSelection = combo.getSelection();
+
+ // compose new text
+ String newText = "";
+ newText += oldText.substring( 0, autoEditParameters.offset );
+ newText += autoEditParameters.text;
+ newText += oldText.substring( autoEditParameters.offset + autoEditParameters.length, oldText.length() );
+
+ // determine new cursor position
+ Point newSelection;
+ if ( autoEditParameters.caretOffset != -1 )
+ {
+ int x = autoEditParameters.caretOffset;
+ newSelection = new Point( x, x );
+ }
+ else
+ {
+ newSelection = new Point( oldSelection.x, oldSelection.y );
+ }
+
+ // set new text and cursor position
+ if ( verifyEvents.isEmpty() )
+ {
+ combo.setText( newText );
+ combo.setSelection( newSelection );
+ }
+
+ inApplyComboCustomization = false;
+ }
+
+ }
+}
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/SearchPageWrapper.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/SearchPageWrapper.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/SearchPageWrapper.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/SearchPageWrapper.java Thu May 31 14:50:07 2007
@@ -34,7 +34,6 @@
import org.apache.directory.ldapstudio.browser.core.model.DN;
import org.apache.directory.ldapstudio.browser.core.model.IConnection;
import org.apache.directory.ldapstudio.browser.core.model.ISearch;
-import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription;
import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaUtils;
import org.eclipse.swt.events.ModifyEvent;
@@ -133,9 +132,6 @@
/** The style. */
protected int style;
- /** The filter parser. */
- protected LdapFilterParser parser;
-
/** The search name label. */
protected Label searchNameLabel;
@@ -201,7 +197,6 @@
*/
public SearchPageWrapper( int style )
{
- this.parser = new LdapFilterParser();
this.style = style;
}
@@ -666,10 +661,9 @@
}
if ( filterWidget != null )
{
- parser.parse( filterWidget.getFilter() );
- if ( !parser.getModel().toString().equals( search.getFilter() ) )
+ if ( !filterWidget.getFilter().equals( search.getFilter() ) )
{
- search.getSearchParameter().setFilter( parser.getModel().toString() );
+ search.getSearchParameter().setFilter( filterWidget.getFilter() );
searchModified = true;
}
filterWidget.saveDialogSettings();
Modified: directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterParser.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterParser.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterParser.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterParser.java Thu May 31 14:50:07 2007
@@ -59,7 +59,7 @@
// reset state
this.filterStack = new Stack();
- this.scanner.setFilter( ldapFilter );
+ this.scanner.reset( ldapFilter );
this.model = new LdapFilter();
// handle error tokens before filter
@@ -210,14 +210,6 @@
{
filter.addOtherToken( new LdapFilterToken( LdapFilterToken.ERROR, token.getValue(), token.getOffset() ) );
}
- }
-
-
- public static void main( String[] args )
- {
- LdapFilterParser parser = new LdapFilterParser();
- parser.parse( "(sn" );
-
}
}
Modified: directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterScanner.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterScanner.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterScanner.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterScanner.java Thu May 31 14:50:07 2007
@@ -21,6 +21,13 @@
package org.apache.directory.ldapstudio.browser.core.model.filter.parser;
+/**
+ *
+ * TODO LdapFilterScanner.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class LdapFilterScanner
{
@@ -72,13 +79,19 @@
// value of the encoded character. The case of the two hexadecimal
// digits is not significant.
+ /** The filter to scan */
private String filter;
+ /** The current position */
private int pos;
+ /** The last token type. */
private int lastTokenType;
+ /**
+ * Creates a new instance of LdapFilterScanner.
+ */
public LdapFilterScanner()
{
super();
@@ -86,7 +99,13 @@
}
- public void setFilter( String filter )
+
+ /**
+ * Resets this scanner.
+ *
+ * @param filter the new filter to scan
+ */
+ public void reset( String filter )
{
this.filter = filter;
this.pos = -1;
@@ -94,12 +113,24 @@
}
+ /**
+ * Gets the character at the current position.
+ *
+ * @return the character at the current position
+ */
private char currentChar()
{
return 0 <= pos && pos < filter.length() ? filter.charAt( pos ) : '\u0000';
}
+
+ /**
+ * Increments the position counter and gets
+ * the character at that positon.
+ *
+ * @return the character at the next position
+ */
private char nextChar()
{
pos++;
@@ -107,6 +138,12 @@
}
+ /**
+ * Decrements the position counter and gets
+ * the character at that positon.
+ *
+ * @return the character at the previous position
+ */
private char prevChar()
{
pos--;