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 [1/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/...
Author: seelmann
Date: Thu May 31 14:50:07 2007
New Revision: 543272
URL: http://svn.apache.org/viewvc?view=rev&rev=543272
Log:
DIRSTUDIO-47:
- Added smart parenthesis handling: Left and right parenthesis are automaticaly added when typing the attribute name. Parenthesis are removed when deleting the last character inside them.
- Added proposals for attribute type, assertion type and object class
- Code cleanup and Javadoc
Added:
directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/atd.png (with props)
directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/mrd.png (with props)
directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/ocd.png (with props)
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/FilterWidgetAutoEditStrategyAdapter.java
Removed:
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/StyledTextContentAssistSubjectAdapter.java
Modified:
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/BrowserCommonConstants.java
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/FilterDialog.java
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterAutoEditStrategy.java
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterCharacterPairMatcher.java
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterContentAssistProcessor.java
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterDamagerRepairer.java
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterFormattingStrategy.java
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterReconcilingStrategy.java
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterSourceViewerConfiguration.java
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterTextHover.java
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/FilterWidget.java
directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/SearchPageWrapper.java
directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterParser.java
directory/ldapstudio/trunk/ldapstudio-browser-core/src/main/java/org/apache/directory/ldapstudio/browser/core/model/filter/parser/LdapFilterScanner.java
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/atd.png
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/atd.png?view=auto&rev=543272
==============================================================================
Binary file - no diff available.
Propchange: directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/atd.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/mrd.png
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/mrd.png?view=auto&rev=543272
==============================================================================
Binary file - no diff available.
Propchange: directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/mrd.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/ocd.png
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/ocd.png?view=auto&rev=543272
==============================================================================
Binary file - no diff available.
Propchange: directory/ldapstudio/trunk/ldapstudio-browser-common/resources/icons/ocd.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/BrowserCommonConstants.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/BrowserCommonConstants.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/BrowserCommonConstants.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/BrowserCommonConstants.java Thu May 31 14:50:07 2007
@@ -229,6 +229,13 @@
public static final String IMG_DELETE_ALL = "resources/icons/delete_all.gif";
+ public static final String IMG_ATD = "resources/icons/atd.png";
+
+ public static final String IMG_OCD = "resources/icons/ocd.png";
+
+ public static final String IMG_MRD = "resources/icons/mrd.png";
+
+
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/FilterDialog.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/FilterDialog.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/FilterDialog.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/FilterDialog.java Thu May 31 14:50:07 2007
@@ -123,7 +123,7 @@
// create and configure source viewer
sourceViewer = new SourceViewer( composite, new VerticalRuler( 0 ), SWT.H_SCROLL | SWT.V_SCROLL );
sourceViewer.getControl().setLayoutData( new GridData( GridData.FILL_BOTH ) );
- configuration = new FilterSourceViewerConfiguration( this.sourceViewer, this.parser, this.connection );
+ configuration = new FilterSourceViewerConfiguration( this.parser, this.connection );
sourceViewer.configure( configuration );
// set document
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterAutoEditStrategy.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterAutoEditStrategy.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterAutoEditStrategy.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterAutoEditStrategy.java Thu May 31 14:50:07 2007
@@ -21,152 +21,228 @@
package org.apache.directory.ldapstudio.browser.common.filtereditor;
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapAndFilterComponent;
import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilterComponent;
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapNotFilterComponent;
+import org.apache.directory.ldapstudio.browser.core.model.filter.LdapOrFilterComponent;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
-import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterToken;
-
-import org.eclipse.jface.text.DefaultAutoIndentStrategy;
+import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
import org.eclipse.jface.text.DocumentCommand;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.jface.text.source.SourceViewer;
-// TODO: Refactor Filter Editor
-public class FilterAutoEditStrategy extends DefaultAutoIndentStrategy implements IAutoEditStrategy
+/**
+ * The FilterAutoEditStrategy implements the IAutoEditStrategy for the filter editor widget.
+ * It provides smart parentesis handling when typing the filter.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class FilterAutoEditStrategy extends DefaultIndentLineAutoEditStrategy implements IAutoEditStrategy
{
+ /** The Constant INDENT_STRING. */
public static final String INDENT_STRING = " ";
+ /** The filter parser. */
private LdapFilterParser parser;
- private SourceViewer sourceViewer;
- private int autoRightParenthesisFilterOffset;
+ /**
+ * Creates a new instance of FilterAutoEditStrategy.
+ *
+ * @param parser the filter parser
+ */
+ public FilterAutoEditStrategy( LdapFilterParser parser )
+ {
+ this.init( parser );
+ }
- public FilterAutoEditStrategy( SourceViewer sourceViewer, LdapFilterParser parser )
+ /**
+ * Init.
+ *
+ * @param parser the parser
+ */
+ private void init( LdapFilterParser parser )
{
- super();
- this.sourceViewer = sourceViewer;
this.parser = parser;
- this.autoRightParenthesisFilterOffset = -1;
}
+ /**
+ * @see org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy#customizeDocumentCommand(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.DocumentCommand)
+ */
public void customizeDocumentCommand( IDocument d, DocumentCommand c )
{
+ super.customizeDocumentCommand( d, c );
+ AutoEditParameters aep = new AutoEditParameters( c.text, c.offset, c.length, c.caretOffset, c.shiftsCaret );
+ customizeAutoEditParameters( aep );
+ c.offset = aep.offset;
+ c.length = aep.length;
+ c.text = aep.text;
+ c.caretOffset = aep.caretOffset;
+ c.shiftsCaret = aep.shiftsCaret;
+ }
- LdapFilter filter = this.parser.getModel().getFilter( c.offset );
- // this.dumpDocumentCommand(c);
+ /**
+ * Customizes auto edit parameters.
+ *
+ * @param aep the auto edit parameters
+ */
+ public void customizeAutoEditParameters( AutoEditParameters aep )
+ {
+ LdapFilter filter = parser.getModel().getFilter( aep.offset );
+ //System.out.println(filter);
- if ( c.length == 0 && c.text != null )
+ if ( aep.length > 0 && ( aep.text == null || "".equals( aep.text ) ) )
{
- // new line
- if ( TextUtilities.endsWith( d.getLegalLineDelimiters(), c.text ) != -1 )
+ // delete surrounding parenthesis after deleting the last character
+ if ( filter.toString().length() - aep.length == 2 && filter.getStartToken() != null
+ && filter.getStopToken() != null
+ && aep.offset >= filter.getStartToken().getOffset() + filter.getStartToken().getLength()
+ && aep.offset + aep.length <= filter.getStopToken().getOffset() )
{
- super.customizeDocumentCommand( d, c );
- if ( filter != null && filter.getFilterComponent() != null )
+ aep.offset -= 1;
+ aep.length += 2;
+ aep.caretOffset = aep.offset;
+ aep.shiftsCaret = false;
+ }
+ }
+
+ if ( aep.length == 0 && aep.text != null && !"".equals( aep.text ) )
+ {
+ boolean isNewFilter = aep.text.equals( "(" );
+ boolean isSurroundNew = false;
+ boolean isSurroundNested = false;
+ boolean isSurroundBeforeOtherFilter = false;
+ boolean isSurroundAfterOtherFilter = false;
+ if ( aep.text.matches( "[a-zA-Z0-9-\\.&|!]+" ) && filter != null )
+ {
+ isSurroundNew = filter.getStartToken() == null && aep.offset == 0 && !aep.text.startsWith( "(" )
+ && !aep.text.endsWith( ")" );
+
+ if ( filter.getStartToken() != null
+ && filter.getFilterComponent() != null
+ && ( filter.getFilterComponent() instanceof LdapAndFilterComponent
+ || filter.getFilterComponent() instanceof LdapOrFilterComponent || filter.getFilterComponent() instanceof LdapNotFilterComponent ) )
{
- LdapFilterToken startToken = filter.getFilterComponent().getStartToken();
- if ( startToken != null
- && ( startToken.getType() == LdapFilterToken.AND || startToken.getType() == LdapFilterToken.OR ) )
+ LdapFilterComponent fc = filter.getFilterComponent();
+ LdapFilter[] filters = fc.getFilters();
+
+ if ( filters.length == 0 && aep.offset > fc.getStartToken().getOffset() )
+ {
+ // no nested filter yet
+ isSurroundNested = true;
+ }
+
+ if ( filters.length > 0 && aep.offset > fc.getStartToken().getOffset()
+ && aep.offset < filters[0].getStartToken().getOffset() )
{
+ // before first nested filter
+ isSurroundNested = true;
+ }
- if ( startToken.getOffset() == c.offset - 1 )
+ if ( filters.length > 0 && aep.offset > filters[filters.length - 1].getStopToken().getOffset()
+ && aep.offset <= filter.getStopToken().getOffset() )
+ {
+ // after last nested filter
+ isSurroundNested = true;
+ }
+
+ for ( int i = 0; i < filters.length; i++ )
+ {
+ if ( filters.length > i + 1 )
{
- c.text += INDENT_STRING;
- if ( filter.getStopToken() != null && filter.getStopToken().getOffset() == c.offset )
+ if ( aep.offset > filters[i].getStopToken().getOffset()
+ && aep.offset <= filters[i + 1].getStopToken().getOffset() )
{
- c.caretOffset = c.offset + c.text.length();
- c.shiftsCaret = false;
- c.text += "\n";
- super.customizeDocumentCommand( d, c );
+ // between nested filter
+ isSurroundNested = true;
}
}
}
}
- }
- // filter start/stop
- if ( c.text.equals( "(" ) )
- {
- c.text = "()";
- c.caretOffset = c.offset + 1;
- c.shiftsCaret = false;
- this.autoRightParenthesisFilterOffset = c.offset;
+ isSurroundBeforeOtherFilter = filter.getStartToken() != null
+ && aep.offset == filter.getStartToken().getOffset();
+
+ isSurroundAfterOtherFilter = filter.getStopToken() != null
+ && aep.offset == filter.getStopToken().getOffset()
+ && ( filter.getFilterComponent() instanceof LdapAndFilterComponent
+ || filter.getFilterComponent() instanceof LdapOrFilterComponent || filter.getFilterComponent() instanceof LdapNotFilterComponent );
}
- else if ( c.text.equals( ")" ) )
+
+ // add opening parenthesis '('
+ if ( isSurroundNew || isSurroundNested || isSurroundAfterOtherFilter || isSurroundBeforeOtherFilter )
{
- LdapFilter filter2 = this.parser.getModel().getFilter( this.autoRightParenthesisFilterOffset );
- if ( filter2 != null && filter2.getStopToken() != null
- && filter2.getStopToken().getOffset() == c.offset )
- {
- c.text = "";
- c.caretOffset = c.offset + 1;
- c.shiftsCaret = false;
- }
- this.autoRightParenthesisFilterOffset = -1;
+ aep.text = "(" + aep.text;
+ aep.caretOffset = aep.offset + aep.text.length();
+ aep.shiftsCaret = false;
}
- // tab to IDENT_STRING
- if ( c.text.equals( "\t" ) )
+ // add closing parenthesis ')'
+ if ( isNewFilter || isSurroundNew || isSurroundNested || isSurroundAfterOtherFilter
+ || isSurroundBeforeOtherFilter )
{
- c.text = INDENT_STRING;
+ aep.text = aep.text + ")";
+ aep.caretOffset = aep.offset + aep.text.length() - 1;
+ aep.shiftsCaret = false;
}
- // smart formatting
- if ( filter != null && filter.getStartToken() != null && filter.getFilterComponent() == null )
+ // translate tab to IDENT_STRING
+ if ( aep.text.equals( "\t" ) )
{
- if ( c.text.equals( "&" ) || c.text.equals( "|" ) )
- {
- if ( filter.getStartToken().getOffset() == c.offset - 1 )
- {
- c.text += "\n";
- super.customizeDocumentCommand( d, c );
- c.text += INDENT_STRING + "()";
- c.caretOffset = c.offset + c.text.length() - 1;
- c.shiftsCaret = false;
- if ( filter.getStopToken() != null && filter.getStopToken().getOffset() == c.offset )
- {
- c.text += "\n";
- super.customizeDocumentCommand( d, c );
- }
-
- }
- }
- else if ( c.text.equals( "!" ) )
- {
- if ( filter.getStartToken().getOffset() == c.offset - 1 )
- {
- c.text += "()";
- c.caretOffset = c.offset + c.text.length() - 1;
- c.shiftsCaret = false;
- }
- }
+ aep.text = INDENT_STRING;
}
-
}
}
-
- private void autoIndentAfterNewLine()
+ /**
+ * Helper class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+ public static class AutoEditParameters
{
- }
+ /** The text. */
+ public String text;
+ /** The offset. */
+ public int offset;
- private void dumpDocumentCommand( DocumentCommand command )
- {
- System.out.println( "----------------------------------" );
- System.out.println( " offset : " + command.offset );
- System.out.println( " length : " + command.length );
- System.out.println( " text : " + command.text );
- System.out.println( " caretoffset: " + command.caretOffset );
- System.out.println( " shiftsCaret: " + command.shiftsCaret );
- System.out.println( " doit : " + command.doit );
+ /** The length. */
+ public int length;
+ /** The caret offset. */
+ public int caretOffset;
+
+ /** The shifts caret flag. */
+ public boolean shiftsCaret;
+
+
+ /**
+ * Creates a new instance of AutoEditParameters.
+ *
+ * @param text the text
+ * @param offset the offset
+ * @param length the length
+ * @param caretOffset the caret offset
+ * @param shiftsCaret the shifts caret flag
+ */
+ public AutoEditParameters( String text, int offset, int length, int caretOffset, boolean shiftsCaret )
+ {
+ this.text = text;
+ this.offset = offset;
+ this.length = length;
+ this.caretOffset = caretOffset;
+ this.shiftsCaret = shiftsCaret;
+ }
}
+
}
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterCharacterPairMatcher.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterCharacterPairMatcher.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterCharacterPairMatcher.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterCharacterPairMatcher.java Thu May 31 14:50:07 2007
@@ -21,10 +21,8 @@
package org.apache.directory.ldapstudio.browser.common.filtereditor;
-// TODO: Refactor Filter Editor
import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
-
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
@@ -32,43 +30,62 @@
import org.eclipse.jface.text.source.ISourceViewer;
+/**
+ * The FilterCharacterPairMatcher implements the ICharacterPairMatcher interface
+ * to match the peer opening and closing parentesis.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class FilterCharacterPairMatcher implements ICharacterPairMatcher
{
- private ISourceViewer sourceViewer;
-
+ /** The filter parser. */
private LdapFilterParser parser;
+ /** The anchor. */
private int anchor;
+ /**
+ * Creates a new instance of FilterCharacterPairMatcher.
+ *
+ * @param sourceViewer the source viewer
+ * @param parser the filter parser
+ */
public FilterCharacterPairMatcher( ISourceViewer sourceViewer, LdapFilterParser parser )
{
- super();
- this.sourceViewer = sourceViewer;
this.parser = parser;
this.clear();
}
+ /**
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcher#dispose()
+ */
public void dispose()
{
}
+ /**
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcher#clear()
+ */
public void clear()
{
- this.anchor = LEFT;
+ anchor = LEFT;
}
+ /**
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcher#match(org.eclipse.jface.text.IDocument, int)
+ */
public IRegion match( IDocument document, int offset )
{
-
- LdapFilter model = this.parser.getModel();
+ LdapFilter model = parser.getModel();
if ( model != null )
{
- LdapFilter filter = this.parser.getModel().getFilter( offset - 1 );
+ LdapFilter filter = parser.getModel().getFilter( offset - 1 );
if ( filter != null && filter.getStartToken() != null && filter.getStopToken() != null )
{
@@ -78,13 +95,13 @@
if ( left == offset - 1 )
{
- this.anchor = LEFT;
+ anchor = LEFT;
IRegion region = new Region( left, right - left + 1 );
return region;
}
if ( right == offset - 1 )
{
- this.anchor = RIGHT;
+ anchor = RIGHT;
IRegion region = new Region( left, right - left + 1 );
return region;
}
@@ -95,9 +112,12 @@
}
+ /**
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcher#getAnchor()
+ */
public int getAnchor()
{
- return this.anchor;
+ return anchor;
}
}
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterContentAssistProcessor.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterContentAssistProcessor.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterContentAssistProcessor.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterContentAssistProcessor.java Thu May 31 14:50:07 2007
@@ -27,17 +27,22 @@
import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+import org.apache.directory.ldapstudio.browser.core.model.IAttribute;
import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilterItemComponent;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
-
-import org.eclipse.jface.contentassist.IContentAssistSubjectControl;
-import org.eclipse.jface.contentassist.ISubjectControlContentAssistProcessor;
+import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterToken;
+import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
+import org.eclipse.jface.fieldassist.IContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.CompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.templates.Template;
import org.eclipse.jface.text.templates.TemplateCompletionProcessor;
@@ -45,29 +50,48 @@
import org.eclipse.swt.graphics.Image;
-// TODO: Refactor Filter Editor
-public class FilterContentAssistProcessor extends TemplateCompletionProcessor implements
- ISubjectControlContentAssistProcessor
+/**
+ * The FilterContentAssistProcessor computes the content proposals for the filter editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class FilterContentAssistProcessor extends TemplateCompletionProcessor implements IContentAssistProcessor,
+ IContentProposalProvider
{
+ /** The parser. */
private LdapFilterParser parser;
+ /** The source viewer, may be null. */
private ISourceViewer sourceViewer;
+ /** The auto activation characters. */
private char[] autoActivationCharacters;
- private String[] possibleAttributeTypes;
+ /** The schema, used to retrieve attributeType and objectClass information. */
+ private Schema schema;
+ /**
+ * Creates a new instance of FilterContentAssistProcessor.
+ *
+ * @param parser the parser
+ */
public FilterContentAssistProcessor( LdapFilterParser parser )
{
this( null, parser );
}
+ /**
+ * Creates a new instance of FilterContentAssistProcessor.
+ *
+ * @param sourceViewer the source viewer
+ * @param parser the parser
+ */
public FilterContentAssistProcessor( ISourceViewer sourceViewer, LdapFilterParser parser )
{
- super();
this.parser = parser;
this.sourceViewer = sourceViewer;
@@ -85,47 +109,108 @@
}
- public void setPossibleAttributeTypes( String[] possibleAttributeTypes )
+ /**
+ * Sets the schema, used to retrieve attributeType and objectClass information.
+ *
+ * @param schema the schema
+ */
+ public void setSchema( Schema schema )
{
- Arrays.sort( possibleAttributeTypes );
- this.possibleAttributeTypes = possibleAttributeTypes;
+ this.schema = schema;
}
+ /**
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getCompletionProposalAutoActivationCharacters()
+ */
public char[] getCompletionProposalAutoActivationCharacters()
{
- return this.autoActivationCharacters;
+ return autoActivationCharacters;
}
+ /**
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
+ */
public ICompletionProposal[] computeCompletionProposals( ITextViewer viewer, int offset )
{
- return this.computeCompletionProposals( offset );
+ return computeCompletionProposals( offset );
}
- public ICompletionProposal[] computeCompletionProposals( IContentAssistSubjectControl contentAssistSubjectControl,
- int documentOffset )
- {
- String filter = contentAssistSubjectControl.getDocument().get();
- this.parser.parse( filter );
- return this.computeCompletionProposals( documentOffset );
- }
+ /**
+ * @see org.eclipse.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int)
+ */
+ public IContentProposal[] getProposals( final String contents, final int position )
+ {
+ parser.parse( contents );
+
+ ICompletionProposal[] oldProposals = computeCompletionProposals( position );
+ IContentProposal[] proposals = new IContentProposal[oldProposals.length];
+ for ( int i = 0; i < oldProposals.length; i++ )
+ {
+ final ICompletionProposal oldProposal = oldProposals[i];
+ final Document document = new Document( contents );
+ oldProposal.apply( document );
+ proposals[i] = new IContentProposal()
+ {
+ public String getContent()
+ {
+ return document.get();
+ }
- public IContextInformation[] computeContextInformation( IContentAssistSubjectControl contentAssistSubjectControl,
- int documentOffset )
- {
- return null;
+
+ public int getCursorPosition()
+ {
+ return oldProposal.getSelection( document ).x;
+ }
+
+
+ public String getDescription()
+ {
+ return oldProposal.getAdditionalProposalInfo();
+ }
+
+
+ public String getLabel()
+ {
+ return oldProposal.getDisplayString();
+ }
+
+
+ public String toString()
+ {
+ return getContent();
+ }
+ };
+ }
+
+ return proposals;
}
+ /**
+ * Computes completion proposals.
+ *
+ * @param offset the offset
+ *
+ * @return the matching completion proposals
+ */
private ICompletionProposal[] computeCompletionProposals( int offset )
{
- List proposalList = new ArrayList();
- LdapFilter filter = this.parser.getModel().getFilter( offset );
+ String[] possibleAttributeTypes = schema == null ? new String[0] : schema.getAttributeTypeDescriptionNames();
+ Arrays.sort( possibleAttributeTypes );
+ String[] possibleObjectClasses = schema == null ? new String[0] : schema.getObjectClassDescriptionNames();
+ Arrays.sort( possibleObjectClasses );
+
+ List<ICompletionProposal> proposalList = new ArrayList<ICompletionProposal>();
+ LdapFilter filter = parser.getModel().getFilter( offset );
if ( filter != null )
{
+ String attributeType = null;
+
+ // case 1: open curly started, show templates and all attribute types
if ( filter.getStartToken() != null && filter.getFilterComponent() == null )
{
@@ -138,41 +223,154 @@
}
}
- for ( int k = 0; k < this.possibleAttributeTypes.length; k++ )
+ for ( int k = 0; k < possibleAttributeTypes.length; k++ )
{
- ICompletionProposal proposal = new CompletionProposal( this.possibleAttributeTypes[k], offset, 0,
- this.possibleAttributeTypes[k].length() );
+ ICompletionProposal proposal = new CompletionProposal( possibleAttributeTypes[k], offset, 0,
+ possibleAttributeTypes[k].length(), getAttributeTypeImage(), null, null, schema
+ .getAttributeTypeDescription( possibleAttributeTypes[k] ).getLine().getUnfoldedValue() );
proposalList.add( proposal );
}
}
+
+ // case 2: editing attribute type: show matching attribute types
else if ( filter.getFilterComponent() instanceof LdapFilterItemComponent
&& filter.getFilterComponent().getStartToken().getOffset() <= offset
&& offset <= filter.getFilterComponent().getStartToken().getOffset()
+ filter.getFilterComponent().getStartToken().getLength() )
{
- // show matching attribute types
LdapFilterItemComponent fc = ( LdapFilterItemComponent ) filter.getFilterComponent();
- for ( int k = 0; k < this.possibleAttributeTypes.length; k++ )
+ for ( int k = 0; k < possibleAttributeTypes.length; k++ )
{
- if ( this.possibleAttributeTypes[k].startsWith( fc.getAttributeToken().getValue() ) )
+ if ( possibleAttributeTypes[k].equalsIgnoreCase( fc.getAttributeToken().getValue() ) )
+ {
+ }
+ else if ( possibleAttributeTypes[k].startsWith( fc.getAttributeToken().getValue() ) )
{
- ICompletionProposal proposal = new CompletionProposal( this.possibleAttributeTypes[k], fc
+ ICompletionProposal proposal = new CompletionProposal( possibleAttributeTypes[k], fc
.getAttributeToken().getOffset(), fc.getAttributeToken().getLength(),
- this.possibleAttributeTypes[k].length() );
+ possibleAttributeTypes[k].length(), getAttributeTypeImage(), null, null, schema
+ .getAttributeTypeDescription( possibleAttributeTypes[k] ).getLine().getUnfoldedValue() );
proposalList.add( proposal );
}
}
}
- else
+
+ if ( filter.getFilterComponent() instanceof LdapFilterItemComponent )
{
- // no proposals
+ LdapFilterItemComponent fc = ( LdapFilterItemComponent ) filter.getFilterComponent();
+ for ( int k = 0; k < possibleAttributeTypes.length; k++ )
+ {
+ if ( possibleAttributeTypes[k].equalsIgnoreCase( fc.getAttributeToken().getValue() ) )
+ {
+ attributeType = fc.getAttributeToken().getValue();
+ break;
+ }
+ }
+ }
+
+ // case 3: after attribte type: show possible assertion types
+ if ( attributeType != null && filter.getFilterComponent() instanceof LdapFilterItemComponent )
+ {
+ LdapFilterItemComponent fc = ( LdapFilterItemComponent ) filter.getFilterComponent();
+ if ( ( fc.getAttributeToken().getOffset() <= offset || fc.getFilterToken() != null )
+ && offset <= fc.getAttributeToken().getOffset() + fc.getAttributeToken().getLength()
+ + ( fc.getFilterToken() != null ? fc.getFilterToken().getLength() : 0 ) )
+ {
+ LdapFilterToken filterTypeToken = fc.getFilterToken();
+
+ // determine matching assertion types depending on the schema's attribute type description
+ List<String> possibleAssertionTypes = new ArrayList<String>( Arrays.asList( new String[]
+ { "=", "=*", "<=", ">=", "~=" } ) );
+ if ( schema != null )
+ {
+ if ( schema.getAttributeTypeDescription( attributeType )
+ .getEqualityMatchingRuleDescriptionOIDTransitive() == null )
+ {
+ possibleAssertionTypes.remove( "=" );
+ possibleAssertionTypes.remove( "~=" );
+ }
+ if ( schema.getAttributeTypeDescription( attributeType )
+ .getOrderingMatchingRuleDescriptionOIDTransitive() == null )
+ {
+ possibleAssertionTypes.remove( "<=" );
+ possibleAssertionTypes.remove( ">=" );
+ }
+ }
+ for ( String possibleAssertionType : possibleAssertionTypes )
+ {
+ if ( filterTypeToken == null
+ || !possibleAssertionType.equalsIgnoreCase( filterTypeToken.getValue() ) )
+ {
+ ICompletionProposal proposal = new CompletionProposal( possibleAssertionType, fc
+ .getAttributeToken().getOffset()
+ + fc.getAttributeToken().getLength(), filterTypeToken != null ? filterTypeToken
+ .getLength() : 0, possibleAssertionType.length(), null, null, null, null );
+ proposalList.add( proposal );
+ }
+ }
+ }
+ }
+
+ // case 4: editing objectClass attribute: show matching object classes
+ if ( attributeType != null && IAttribute.OBJECTCLASS_ATTRIBUTE.equalsIgnoreCase( attributeType )
+ && filter.getFilterComponent() instanceof LdapFilterItemComponent )
+ {
+ LdapFilterItemComponent fc = ( LdapFilterItemComponent ) filter.getFilterComponent();
+ if ( ( fc.getValueToken() != null && fc.getValueToken().getOffset() <= offset || fc.getFilterToken() != null )
+ && offset <= fc.getAttributeToken().getOffset() + fc.getAttributeToken().getLength()
+ + ( fc.getFilterToken() != null ? fc.getFilterToken().getLength() : 0 )
+ + ( fc.getValueToken() != null ? fc.getValueToken().getLength() : 0 ) )
+ {
+ LdapFilterToken valueToken = fc.getValueToken();
+ for ( int k = 0; k < possibleObjectClasses.length; k++ )
+ {
+ if ( fc.getValueToken() == null
+ || possibleObjectClasses[k].startsWith( fc.getValueToken().getValue() ) )
+ {
+ ICompletionProposal proposal = new CompletionProposal( possibleObjectClasses[k], fc
+ .getAttributeToken().getOffset()
+ + fc.getAttributeToken().getLength() + fc.getFilterToken().getLength(),
+ valueToken != null ? valueToken.getLength() : 0, possibleObjectClasses[k].length(),
+ getObjectClassImage(), null, null, schema.getObjectClassDescription(
+ possibleObjectClasses[k] ).getLine().getUnfoldedValue() );
+ proposalList.add( proposal );
+ }
+ }
+ }
}
}
- return ( ICompletionProposal[] ) proposalList.toArray( new ICompletionProposal[0] );
+ //System.out.println(proposalList);
+
+ return proposalList.toArray( new ICompletionProposal[0] );
}
+ /**
+ * Gets the attribute type image.
+ *
+ * @return the attribute type image
+ */
+ private Image getAttributeTypeImage()
+ {
+ return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ATD );
+ }
+
+
+ /**
+ * Gets the object class image.
+ *
+ * @return the object class image
+ */
+ private Image getObjectClassImage()
+ {
+ return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_OCD );
+ }
+
+
+ /**
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getTemplates(java.lang.String)
+ */
protected Template[] getTemplates( String contextTypeId )
{
Template[] templates = BrowserCommonActivator.getDefault().getFilterTemplateStore().getTemplates(
@@ -181,6 +379,9 @@
}
+ /**
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getContextType(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
+ */
protected TemplateContextType getContextType( ITextViewer viewer, IRegion region )
{
TemplateContextType contextType = BrowserCommonActivator.getDefault().getFilterTemplateContextTypeRegistry()
@@ -189,9 +390,48 @@
}
+ /**
+ * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getImage(org.eclipse.jface.text.templates.Template)
+ */
protected Image getImage( Template template )
{
return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_TEMPLATE );
+ }
+
+
+ /**
+ * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
+ */
+ public IContextInformation[] computeContextInformation( ITextViewer viewer, int documentOffset )
+ {
+ return null;
+ }
+
+
+ /**
+ * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
+ */
+ public char[] getContextInformationAutoActivationCharacters()
+ {
+ return null;
+ }
+
+
+ /**
+ * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
+ */
+ public String getErrorMessage()
+ {
+ return null;
+ }
+
+
+ /**
+ * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
+ */
+ public IContextInformationValidator getContextInformationValidator()
+ {
+ return null;
}
}
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterDamagerRepairer.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterDamagerRepairer.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterDamagerRepairer.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterDamagerRepairer.java Thu May 31 14:50:07 2007
@@ -24,7 +24,6 @@
import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterToken;
-
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
@@ -33,69 +32,85 @@
import org.eclipse.jface.text.TextPresentation;
import org.eclipse.jface.text.presentation.IPresentationDamager;
import org.eclipse.jface.text.presentation.IPresentationRepairer;
-import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.RGB;
+/**
+ * The FilterDamagerRepairer is used for syntax highlighting.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class FilterDamagerRepairer implements IPresentationDamager, IPresentationRepairer
{
private static final TextAttribute DEFAULT_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator.getDefault()
.getColor( new RGB( 0, 0, 0 ) ) );
- private static final TextAttribute AND_OR_NOT_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator.getDefault()
- .getColor( new RGB( 0, 127, 0 ) ), null, SWT.BOLD );
-
- private static final TextAttribute ATTRIBUTE_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator.getDefault()
- .getColor( new RGB( 127, 0, 85 ) ) );
+ private static final TextAttribute AND_OR_NOT_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator
+ .getDefault().getColor( new RGB( 0, 127, 0 ) ), null, SWT.BOLD );
- private static final TextAttribute FILTER_TYPE_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator.getDefault()
- .getColor( new RGB( 255, 0, 0 ) ), null, SWT.BOLD );
+ private static final TextAttribute ATTRIBUTE_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator
+ .getDefault().getColor( new RGB( 127, 0, 85 ) ) );
- private static final TextAttribute VALUE_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator.getDefault().getColor(
- new RGB( 0, 0, 127 ) ) );
+ private static final TextAttribute FILTER_TYPE_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator
+ .getDefault().getColor( new RGB( 255, 0, 0 ) ), null, SWT.BOLD );
- private static final TextAttribute PARENTHESIS_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator.getDefault()
- .getColor( new RGB( 0, 0, 0 ) ), null, SWT.BOLD );
+ private static final TextAttribute VALUE_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator.getDefault()
+ .getColor( new RGB( 0, 0, 127 ) ) );
- private SourceViewer sourceViewer;
+ private static final TextAttribute PARENTHESIS_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator
+ .getDefault().getColor( new RGB( 0, 0, 0 ) ), null, SWT.BOLD );
+ /** The filter parser. */
private LdapFilterParser parser;
+ /** The document. */
private IDocument document;
- public FilterDamagerRepairer( SourceViewer sourceViewer, LdapFilterParser parser )
+ /**
+ * Creates a new instance of FilterDamagerRepairer.
+ *
+ * @param parser the filter parser
+ */
+ public FilterDamagerRepairer( LdapFilterParser parser )
{
- super();
- this.sourceViewer = sourceViewer;
this.parser = parser;
this.document = null;
}
+ /**
+ * @see org.eclipse.jface.text.presentation.IPresentationDamager#setDocument(org.eclipse.jface.text.IDocument)
+ */
public void setDocument( IDocument document )
{
this.document = document;
}
+ /**
+ * @see org.eclipse.jface.text.presentation.IPresentationDamager#getDamageRegion(org.eclipse.jface.text.ITypedRegion, org.eclipse.jface.text.DocumentEvent, boolean)
+ */
public IRegion getDamageRegion( ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged )
{
return partition;
}
+ /**
+ * @see org.eclipse.jface.text.presentation.IPresentationRepairer#createPresentation(org.eclipse.jface.text.TextPresentation, org.eclipse.jface.text.ITypedRegion)
+ */
public void createPresentation( TextPresentation presentation, ITypedRegion damage )
{
-
// parse the filter
- this.parser.parse( this.document.get() );
+ parser.parse( this.document.get() );
// get tokens
- LdapFilterToken[] tokens = this.parser.getModel().getTokens();
+ LdapFilterToken[] tokens = parser.getModel().getTokens();
// syntax highlighting
for ( int i = 0; i < tokens.length; i++ )
@@ -128,10 +143,16 @@
this.addStyleRange( presentation, tokens[i], DEFAULT_TEXT_ATTRIBUTE );
}
}
-
}
+ /**
+ * Adds the style range.
+ *
+ * @param presentation the presentation
+ * @param textAttribute the text attribute
+ * @param token the token
+ */
private void addStyleRange( TextPresentation presentation, LdapFilterToken token, TextAttribute textAttribute )
{
StyleRange range = new StyleRange( token.getOffset(), token.getLength(), textAttribute.getForeground(),
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterFormattingStrategy.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterFormattingStrategy.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterFormattingStrategy.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterFormattingStrategy.java Thu May 31 14:50:07 2007
@@ -28,51 +28,80 @@
import org.apache.directory.ldapstudio.browser.core.model.filter.LdapNotFilterComponent;
import org.apache.directory.ldapstudio.browser.core.model.filter.LdapOrFilterComponent;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
-
import org.eclipse.jface.text.formatter.IFormattingStrategy;
-import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.text.source.ISourceViewer;
+/**
+ * The FilterFormattingStrategy is used to format the LDAP filter in the
+ * filter editor.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class FilterFormattingStrategy implements IFormattingStrategy
{
+ /** The filter parser. */
private LdapFilterParser parser;
- private SourceViewer sourceViewer;
+ /** The source viewer. */
+ private ISourceViewer sourceViewer;
- public FilterFormattingStrategy( SourceViewer sourceViewer, LdapFilterParser parser )
+ /**
+ * Creates a new instance of FilterFormattingStrategy.
+ *
+ * @param sourceViewer the source viewer
+ * @param parser the filter parser
+ */
+ public FilterFormattingStrategy( ISourceViewer sourceViewer, LdapFilterParser parser )
{
- super();
this.parser = parser;
this.sourceViewer = sourceViewer;
}
+ /**
+ * @see org.eclipse.jface.text.formatter.IFormattingStrategy#formatterStarts(java.lang.String)
+ */
public void formatterStarts( String initialIndentation )
{
}
+ /**
+ * @see org.eclipse.jface.text.formatter.IFormattingStrategy#format(java.lang.String, boolean, java.lang.String, int[])
+ */
public String format( String content, boolean isLineStart, String indentation, int[] positions )
{
// this.parser.parse(content);
- LdapFilter model = this.parser.getModel();
+ LdapFilter model = parser.getModel();
if ( model != null && model.isValid() )
{
- this.sourceViewer.getDocument().set( get( model, 0 ) );
+ sourceViewer.getDocument().set( getFormattedFilter( model, 0 ) );
}
return null;
}
- private String get( LdapFilter filter, int indent )
+ /**
+ * Gets the formatted string respresentation of the filter.
+ *
+ * @param filter the filter
+ * @param indent the indent
+ *
+ * @return the formatted string respresentation of the filter
+ */
+ private String getFormattedFilter( LdapFilter filter, int indent )
{
StringBuffer sb = new StringBuffer();
for ( int i = 0; i < indent; i++ )
+ {
sb.append( FilterAutoEditStrategy.INDENT_STRING );
+ }
LdapFilterComponent fc = filter.getFilterComponent();
if ( fc instanceof LdapFilterItemComponent )
@@ -86,12 +115,12 @@
if ( lnfc.getFilters().length > 0
&& lnfc.getFilters()[0].getFilterComponent() instanceof LdapFilterItemComponent )
{
- sb.append( get( ( lnfc ).getFilters()[0], 0 ) );
+ sb.append( getFormattedFilter( ( lnfc ).getFilters()[0], 0 ) );
}
else
{
sb.append( '\n' );
- sb.append( get( ( lnfc ).getFilters()[0], indent + 1 ) );
+ sb.append( getFormattedFilter( ( lnfc ).getFilters()[0], indent + 1 ) );
sb.append( '\n' );
for ( int i = 0; i < indent; i++ )
sb.append( FilterAutoEditStrategy.INDENT_STRING );
@@ -105,7 +134,7 @@
LdapFilter[] filters = ( ( LdapAndFilterComponent ) fc ).getFilters();
for ( int i = 0; i < filters.length; i++ )
{
- sb.append( get( filters[i], indent + 1 ) );
+ sb.append( getFormattedFilter( filters[i], indent + 1 ) );
sb.append( '\n' );
}
for ( int i = 0; i < indent; i++ )
@@ -119,7 +148,7 @@
LdapFilter[] filters = ( ( LdapOrFilterComponent ) fc ).getFilters();
for ( int i = 0; i < filters.length; i++ )
{
- sb.append( get( filters[i], indent + 1 ) );
+ sb.append( getFormattedFilter( filters[i], indent + 1 ) );
sb.append( '\n' );
}
for ( int i = 0; i < indent; i++ )
@@ -131,6 +160,9 @@
}
+ /**
+ * @see org.eclipse.jface.text.formatter.IFormattingStrategy#formatterStops()
+ */
public void formatterStops()
{
}
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterReconcilingStrategy.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterReconcilingStrategy.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterReconcilingStrategy.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterReconcilingStrategy.java Thu May 31 14:50:07 2007
@@ -28,7 +28,6 @@
import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterToken;
-
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.PaintManager;
@@ -40,88 +39,100 @@
import org.eclipse.jface.text.source.AnnotationPainter;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.IAnnotationModelExtension;
+import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.MatchingCharacterPainter;
-import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.swt.graphics.RGB;
+/**
+ * The FilterReconcilingStrategy is used to maintain the error annotations
+ * (red squirrels).
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class FilterReconcilingStrategy implements IReconcilingStrategy
{
- private SourceViewer sourceViewer;
+ /** The source viewer. */
+ private ISourceViewer sourceViewer;
+ /** The filter parser. */
private LdapFilterParser parser;
- private IDocument document;
-
+ /** The paint manager. */
private PaintManager paintManager;
- public FilterReconcilingStrategy( SourceViewer sourceViewer, LdapFilterParser parser )
+ /**
+ * Creates a new instance of FilterReconcilingStrategy.
+ *
+ * @param sourceViewer the source viewer
+ * @param parser the filter parser
+ */
+ public FilterReconcilingStrategy( ISourceViewer sourceViewer, LdapFilterParser parser )
{
- super();
this.sourceViewer = sourceViewer;
this.parser = parser;
- this.document = null;
this.paintManager = null;
}
+ /**
+ * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#setDocument(org.eclipse.jface.text.IDocument)
+ */
public void setDocument( IDocument document )
{
- this.document = document;
-
- if ( this.sourceViewer.getAnnotationModel() == null )
+ if ( sourceViewer.getAnnotationModel() == null )
{
IAnnotationModel model = new AnnotationModel();
- this.sourceViewer.setDocument( this.sourceViewer.getDocument(), model );
+ sourceViewer.setDocument( sourceViewer.getDocument(), model );
}
// add annotation painter
- if ( this.paintManager == null && this.sourceViewer.getAnnotationModel() instanceof IAnnotationModelExtension )
+ if ( paintManager == null && sourceViewer.getAnnotationModel() instanceof IAnnotationModelExtension )
{
- AnnotationPainter ap = new AnnotationPainter( this.sourceViewer, null );
+ AnnotationPainter ap = new AnnotationPainter( sourceViewer, null );
ap.addAnnotationType( "DEFAULT" );
ap.setAnnotationTypeColor( "DEFAULT", BrowserCommonActivator.getDefault().getColor( new RGB( 255, 0, 0 ) ) );
- this.sourceViewer.getAnnotationModel().addAnnotationModelListener( ap );
+ sourceViewer.getAnnotationModel().addAnnotationModelListener( ap );
- FilterCharacterPairMatcher cpm = new FilterCharacterPairMatcher( this.sourceViewer, this.parser );
- MatchingCharacterPainter mcp = new MatchingCharacterPainter( this.sourceViewer, cpm );
+ FilterCharacterPairMatcher cpm = new FilterCharacterPairMatcher( sourceViewer, parser );
+ MatchingCharacterPainter mcp = new MatchingCharacterPainter( sourceViewer, cpm );
mcp.setColor( BrowserCommonActivator.getDefault().getColor( new RGB( 159, 159, 159 ) ) );
- this.paintManager = new PaintManager( this.sourceViewer );
- this.paintManager.addPainter( ap );
- this.paintManager.addPainter( mcp );
+ paintManager = new PaintManager( sourceViewer );
+ paintManager.addPainter( ap );
+ paintManager.addPainter( mcp );
}
-
}
+ /**
+ * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
+ */
public void reconcile( DirtyRegion dirtyRegion, IRegion subRegion )
{
- this.reconcile( dirtyRegion );
+ reconcile( dirtyRegion );
}
+ /**
+ * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
+ */
public void reconcile( IRegion partition )
{
- /*
- * Display.getDefault().syncExec(new Runnable(){ public void run() {
- * if(sourceViewer.canDoOperation(SourceViewer.FORMAT)) {
- * sourceViewer.doOperation(SourceViewer.FORMAT); } } });
- */
-
- LdapFilterToken[] tokens = this.parser.getModel().getTokens();
+ LdapFilterToken[] tokens = parser.getModel().getTokens();
// annotations
- if ( this.sourceViewer.getAnnotationModel() instanceof IAnnotationModelExtension )
+ if ( sourceViewer.getAnnotationModel() instanceof IAnnotationModelExtension )
{
- ( ( IAnnotationModelExtension ) this.sourceViewer.getAnnotationModel() ).removeAllAnnotations();
+ ( ( IAnnotationModelExtension ) sourceViewer.getAnnotationModel() ).removeAllAnnotations();
- List positionList = new ArrayList();
+ List<Position> positionList = new ArrayList<Position>();
- LdapFilter[] invalidFilters = this.parser.getModel().getInvalidFilters();
+ LdapFilter[] invalidFilters = parser.getModel().getInvalidFilters();
for ( int i = 0; i < invalidFilters.length; i++ )
{
if ( invalidFilters[i].getStartToken() != null )
@@ -134,7 +145,7 @@
Annotation annotation = new Annotation( "DEFAULT", true, invalidFilters[i].toString() );
Position position = new Position( start, stop - start );
positionList.add( position );
- this.sourceViewer.getAnnotationModel().addAnnotation( annotation, position );
+ sourceViewer.getAnnotationModel().addAnnotation( annotation, position );
}
}
@@ -146,7 +157,7 @@
boolean overlaps = false;
for ( int k = 0; k < positionList.size(); k++ )
{
- Position pos = ( Position ) positionList.get( k );
+ Position pos = positionList.get( k );
if ( pos.overlapsWith( tokens[i].getOffset(), tokens[i].getLength() ) )
{
overlaps = true;
@@ -157,12 +168,11 @@
{
Annotation annotation = new Annotation( "DEFAULT", true, tokens[i].getValue() );
Position position = new Position( tokens[i].getOffset(), tokens[i].getLength() );
- this.sourceViewer.getAnnotationModel().addAnnotation( annotation, position );
+ sourceViewer.getAnnotationModel().addAnnotation( annotation, position );
}
}
}
}
-
}
}
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterSourceViewerConfiguration.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterSourceViewerConfiguration.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterSourceViewerConfiguration.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterSourceViewerConfiguration.java Thu May 31 14:50:07 2007
@@ -24,8 +24,7 @@
import org.apache.directory.ldapstudio.browser.common.widgets.DialogContentAssistant;
import org.apache.directory.ldapstudio.browser.core.model.IConnection;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
-
-import org.eclipse.jface.text.IAutoIndentStrategy;
+import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.contentassist.IContentAssistant;
@@ -36,149 +35,182 @@
import org.eclipse.jface.text.reconciler.IReconciler;
import org.eclipse.jface.text.reconciler.MonoReconciler;
import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
-// TODO: Refactor Filter Editor
+/**
+ * The FilterSourceViewerConfiguration implements the configuration of
+ * the source viewer.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class FilterSourceViewerConfiguration extends SourceViewerConfiguration
{
+ /** The current connection, used to retrieve schema information. */
private IConnection connection;
+ /** The filter parser. */
private LdapFilterParser parser;
- private SourceViewer sourceViewer;
-
- // Presentation Reconciler (syntax highlight)
+ /** The presentation reconciler, used for syntax highlighting. */
private PresentationReconciler presentationReconciler;
+ /** The damager repairer, used for syntax highlighting. */
private FilterDamagerRepairer damagerRepairer;
- // Asynchronous Reconciler (annotations)
+ /** The reconciler, used to maintain error annotations. */
private MonoReconciler reconciler;
+ /** The reconciling strategy, used to maintain error annotations. */
private FilterReconcilingStrategy reconcilingStrategy;
- // Hover
+ /** The text hover, used to display error message tooltips. */
private FilterTextHover textHover;
- // Auto Edit Strategy
- private FilterAutoEditStrategy autoEditStrategy;
+ /** The auto edit strategy, used for smart parentesis handling. */
+ private FilterAutoEditStrategy[] autoEditStrategies;
+ /** The formatter, used to format the filter. */
private ContentFormatter formatter;
+ /** The formatting strategy, used to format the filter. */
private FilterFormattingStrategy formattingStrategy;
- // Content Assistent
+ /** The content assistant, used for content proposals. */
private DialogContentAssistant contentAssistant;
+ /** The content assist processor, used for content proposals. */
private FilterContentAssistProcessor contentAssistProcessor;
- public FilterSourceViewerConfiguration( SourceViewer sourceViewer, LdapFilterParser parser, IConnection connection )
+ /**
+ * Creates a new instance of FilterSourceViewerConfiguration.
+ *
+ * @param parser the filer parser
+ * @param connection the connection
+ */
+ public FilterSourceViewerConfiguration( LdapFilterParser parser, IConnection connection )
{
- super();
- this.sourceViewer = sourceViewer;
this.parser = parser;
this.connection = connection;
}
+ /**
+ * Sets the connection.
+ *
+ * @param connection the connection
+ */
public void setConnection( IConnection connection )
{
this.connection = connection;
- this.contentAssistProcessor.setPossibleAttributeTypes( this.connection == null ? new String[0]
- : this.connection.getSchema().getAttributeTypeDescriptionNames() );
+ contentAssistProcessor.setSchema( connection == null ? null : connection.getSchema() );
}
+ /**
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer)
+ */
public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer )
{
- if ( this.damagerRepairer == null )
+ if ( damagerRepairer == null )
{
- this.damagerRepairer = new FilterDamagerRepairer( this.sourceViewer, this.parser );
+ damagerRepairer = new FilterDamagerRepairer( parser );
}
- if ( this.presentationReconciler == null )
+ if ( presentationReconciler == null )
{
- this.presentationReconciler = new PresentationReconciler();
- this.presentationReconciler.setDamager( this.damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
- this.presentationReconciler.setRepairer( this.damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
+ presentationReconciler = new PresentationReconciler();
+ presentationReconciler.setDamager( damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
+ presentationReconciler.setRepairer( damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
}
- return this.presentationReconciler;
+ return presentationReconciler;
}
+ /**
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getTextHover(org.eclipse.jface.text.source.ISourceViewer, java.lang.String)
+ */
public ITextHover getTextHover( ISourceViewer sourceViewer, String contentType )
{
- if ( this.textHover == null )
+ if ( textHover == null )
{
- this.textHover = new FilterTextHover( this.sourceViewer, this.parser );
+ textHover = new FilterTextHover( parser );
}
- return this.textHover;
+ return textHover;
}
+ /**
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer)
+ */
public IReconciler getReconciler( ISourceViewer sourceViewer )
{
- if ( this.reconcilingStrategy == null )
+ if ( reconcilingStrategy == null )
{
- this.reconcilingStrategy = new FilterReconcilingStrategy( this.sourceViewer, this.parser );
+ reconcilingStrategy = new FilterReconcilingStrategy( sourceViewer, parser );
}
- if ( this.reconciler == null )
+ if ( reconciler == null )
{
- this.reconciler = new MonoReconciler( this.reconcilingStrategy, false );
+ reconciler = new MonoReconciler( reconcilingStrategy, false );
}
- return this.reconciler;
+ return reconciler;
}
- public IAutoIndentStrategy getAutoIndentStrategy( ISourceViewer sourceViewer, String contentType )
+ /**
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer, java.lang.String)
+ */
+ public IAutoEditStrategy[] getAutoEditStrategies( ISourceViewer sourceViewer, String contentType )
{
- if ( this.autoEditStrategy == null )
+ if ( autoEditStrategies == null )
{
- this.autoEditStrategy = new FilterAutoEditStrategy( this.sourceViewer, this.parser );
+ autoEditStrategies = new FilterAutoEditStrategy[]
+ { new FilterAutoEditStrategy( parser ) };
}
- return this.autoEditStrategy;
+ return autoEditStrategies;
}
+ /**
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentFormatter(org.eclipse.jface.text.source.ISourceViewer)
+ */
public IContentFormatter getContentFormatter( ISourceViewer sourceViewer )
{
- if ( this.formattingStrategy == null )
+ if ( formattingStrategy == null )
{
- this.formattingStrategy = new FilterFormattingStrategy( this.sourceViewer, this.parser );
+ formattingStrategy = new FilterFormattingStrategy( sourceViewer, parser );
}
- if ( this.formatter == null )
+ if ( formatter == null )
{
- this.formatter = new ContentFormatter();
- this.formatter.enablePartitionAwareFormatting( false );
- this.formatter.setFormattingStrategy( this.formattingStrategy, IDocument.DEFAULT_CONTENT_TYPE );
+ formatter = new ContentFormatter();
+ formatter.enablePartitionAwareFormatting( false );
+ formatter.setFormattingStrategy( formattingStrategy, IDocument.DEFAULT_CONTENT_TYPE );
}
return formatter;
}
+ /**
+ * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(org.eclipse.jface.text.source.ISourceViewer)
+ */
public IContentAssistant getContentAssistant( ISourceViewer sourceViewer )
{
-
- if ( this.contentAssistProcessor == null )
+ if ( contentAssistProcessor == null )
{
- this.contentAssistProcessor = new FilterContentAssistProcessor( this.sourceViewer, this.parser );
- this.contentAssistProcessor.setPossibleAttributeTypes( this.connection == null ? new String[0]
- : this.connection.getSchema().getAttributeTypeDescriptionNames() );
- }
- if ( this.contentAssistant == null )
- {
- this.contentAssistant = new DialogContentAssistant();
- this.contentAssistant.enableAutoInsert( true );
- this.contentAssistant.setContentAssistProcessor( this.contentAssistProcessor,
- IDocument.DEFAULT_CONTENT_TYPE );
- this.contentAssistant.enableAutoActivation( true );
- this.contentAssistant.setAutoActivationDelay( 100 );
+ contentAssistProcessor = new FilterContentAssistProcessor( sourceViewer, parser );
+ contentAssistProcessor.setSchema( connection == null ? null : connection.getSchema() );
}
- return this.contentAssistant;
-
+ if ( contentAssistant == null )
+ {
+ contentAssistant = new DialogContentAssistant();
+ contentAssistant.enableAutoInsert( true );
+ contentAssistant.setContentAssistProcessor( contentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE );
+ contentAssistant.enableAutoActivation( true );
+ contentAssistant.setAutoActivationDelay( 100 );
+ }
+ return contentAssistant;
}
}
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterTextHover.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterTextHover.java?view=diff&rev=543272&r1=543271&r2=543272
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterTextHover.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterTextHover.java Thu May 31 14:50:07 2007
@@ -24,33 +24,42 @@
import org.apache.directory.ldapstudio.browser.core.model.filter.LdapFilter;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterToken;
-
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.source.ISourceViewer;
+/**
+ * The FilterTextHover is used to display error messages in a tooltip.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
public class FilterTextHover implements ITextHover
{
- private ISourceViewer sourceViewer;
-
+ /** The filter parser. */
private LdapFilterParser parser;
- public FilterTextHover( ISourceViewer sourceViewer, LdapFilterParser parser )
+ /**
+ * Creates a new instance of FilterTextHover.
+ *
+ * @param parser filter parser
+ */
+ public FilterTextHover( LdapFilterParser parser )
{
- super();
- this.sourceViewer = sourceViewer;
this.parser = parser;
}
+ /**
+ * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
+ */
public String getHoverInfo( ITextViewer textViewer, IRegion hoverRegion )
{
- LdapFilter[] invalidFilters = this.parser.getModel().getInvalidFilters();
+ LdapFilter[] invalidFilters = parser.getModel().getInvalidFilters();
for ( int i = 0; i < invalidFilters.length; i++ )
{
if ( invalidFilters[i].getStartToken() != null )
@@ -66,7 +75,7 @@
}
}
- LdapFilterToken[] tokens = this.parser.getModel().getTokens();
+ LdapFilterToken[] tokens = parser.getModel().getTokens();
for ( int i = 0; i < tokens.length; i++ )
{
if ( tokens[i].getType() == LdapFilterToken.ERROR )
@@ -84,6 +93,9 @@
}
+ /**
+ * @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int)
+ */
public IRegion getHoverRegion( ITextViewer textViewer, int offset )
{
return new Region( offset, 1 );
Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/FilterWidget.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/FilterWidget.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/FilterWidget.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/FilterWidget.java Thu May 31 14:50:07 2007
@@ -26,19 +26,24 @@
import org.apache.directory.ldapstudio.browser.common.filtereditor.FilterContentAssistProcessor;
import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
import org.apache.directory.ldapstudio.browser.common.widgets.BrowserWidget;
-import org.apache.directory.ldapstudio.browser.common.widgets.DialogContentAssistant;
import org.apache.directory.ldapstudio.browser.common.widgets.HistoryUtils;
import org.apache.directory.ldapstudio.browser.core.model.IConnection;
import org.apache.directory.ldapstudio.browser.core.model.filter.parser.LdapFilterParser;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.jface.bindings.keys.KeyStroke;
+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.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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;
/**
@@ -55,6 +60,12 @@
/** The filter combo. */
private Combo filterCombo;
+ /** The filter combo field. */
+ private DecoratedField filterComboField;
+
+ /** The filter content proposal adapter */
+ private ContentProposalAdapter filterCPA;
+
/** The button to open the filter editor. */
private Button filterEditorButton;
@@ -99,30 +110,36 @@
*/
public void createWidget( final Composite parent )
{
- // Combo
- filterCombo = BaseWidgetUtils.createCombo( parent, new String[0], -1, 1 );
- GridData gd = new GridData( GridData.FILL_HORIZONTAL );
- gd.horizontalSpan = 1;
- gd.widthHint = 200;
- filterCombo.setLayoutData( gd );
-
- filterCombo.addModifyListener( new ModifyListener()
+ // filter combo with field decoration
+ final FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(
+ FieldDecorationRegistry.DEC_CONTENT_PROPOSAL );
+ filterComboField = new DecoratedField( parent, SWT.NONE, new IControlCreator()
{
- public void modifyText( ModifyEvent e )
+ public Control createControl( Composite parent, int style )
{
- notifyListeners();
+ Combo combo = BaseWidgetUtils.createCombo( parent, new String[0], -1, 1 );
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = 1;
+ gd.widthHint = 200;
+ combo.setLayoutData( gd );
+ combo.setVisibleItemCount( 20 );
+ return combo;
}
} );
+ filterComboField.addFieldDecoration( fieldDecoration, SWT.TOP | SWT.LEFT, true );
+ filterComboField.getLayoutControl().setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
+ filterCombo = ( Combo ) filterComboField.getControl();
- // Content assist
+ // content proposal adapter
LdapFilterParser parser = new LdapFilterParser();
contentAssistProcessor = new FilterContentAssistProcessor( parser );
- DialogContentAssistant fca = new DialogContentAssistant();
- fca.enableAutoInsert( true );
- fca.enableAutoActivation( true );
- fca.setAutoActivationDelay( 100 );
- fca.setContentAssistProcessor( contentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE );
- fca.install( filterCombo );
+ filterCPA = new ContentProposalAdapter( filterCombo, new ComboContentAdapter(), contentAssistProcessor,
+ KeyStroke.getInstance( SWT.CTRL, ' ' ), null );
+ filterCPA.setFilterStyle( ContentProposalAdapter.FILTER_NONE );
+ filterCPA.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE );
+
+ // auto edit strategy
+ new FilterWidgetAutoEditStrategyAdapter( filterCombo, parser );
// Filter editor button
filterEditorButton = BaseWidgetUtils.createButton( parent, "F&ilter Editor...", 1 );
@@ -184,8 +201,8 @@
public void setConnection( IConnection connection )
{
this.connection = connection;
- contentAssistProcessor.setPossibleAttributeTypes( connection == null ? new String[0] : connection.getSchema()
- .getAttributeTypeDescriptionNames() );
+ contentAssistProcessor.setSchema( connection == null ? null : connection.getSchema() );
+ filterCPA.setAutoActivationCharacters( contentAssistProcessor.getCompletionProposalAutoActivationCharacters() );
}