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/04/09 11:49:57 UTC
svn commit: r526693 [8/17] - in
/directory/ldapstudio/trunk/ldapstudio-browser-common: ./ META-INF/
resources/ resources/icons/ resources/templates/ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/dir...
Added: 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=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterCharacterPairMatcher.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterCharacterPairMatcher.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,103 @@
+/*
+ * 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.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;
+import org.eclipse.jface.text.source.ICharacterPairMatcher;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+
+public class FilterCharacterPairMatcher implements ICharacterPairMatcher
+{
+
+ private ISourceViewer sourceViewer;
+
+ private LdapFilterParser parser;
+
+ private int anchor;
+
+
+ public FilterCharacterPairMatcher( ISourceViewer sourceViewer, LdapFilterParser parser )
+ {
+ super();
+ this.sourceViewer = sourceViewer;
+ this.parser = parser;
+ this.clear();
+ }
+
+
+ public void dispose()
+ {
+ }
+
+
+ public void clear()
+ {
+ this.anchor = LEFT;
+ }
+
+
+ public IRegion match( IDocument document, int offset )
+ {
+
+ LdapFilter model = this.parser.getModel();
+ if ( model != null )
+ {
+ LdapFilter filter = this.parser.getModel().getFilter( offset - 1 );
+
+ if ( filter != null && filter.getStartToken() != null && filter.getStopToken() != null )
+ {
+
+ int left = filter.getStartToken().getOffset();
+ int right = filter.getStopToken().getOffset();
+
+ if ( left == offset - 1 )
+ {
+ this.anchor = LEFT;
+ IRegion region = new Region( left, right - left + 1 );
+ return region;
+ }
+ if ( right == offset - 1 )
+ {
+ this.anchor = RIGHT;
+ IRegion region = new Region( left, right - left + 1 );
+ return region;
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+ public int getAnchor()
+ {
+ return this.anchor;
+ }
+
+}
Added: 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=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterContentAssistProcessor.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterContentAssistProcessor.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,197 @@
+/*
+ * 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.filtereditor;
+
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
+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.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.IContextInformation;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.templates.Template;
+import org.eclipse.jface.text.templates.TemplateCompletionProcessor;
+import org.eclipse.jface.text.templates.TemplateContextType;
+import org.eclipse.swt.graphics.Image;
+
+
+// TODO: Refactor Filter Editor
+public class FilterContentAssistProcessor extends TemplateCompletionProcessor implements
+ ISubjectControlContentAssistProcessor
+{
+
+ private LdapFilterParser parser;
+
+ private ISourceViewer sourceViewer;
+
+ private char[] autoActivationCharacters;
+
+ private String[] possibleAttributeTypes;
+
+
+ public FilterContentAssistProcessor( LdapFilterParser parser )
+ {
+ this( null, parser );
+ }
+
+
+ public FilterContentAssistProcessor( ISourceViewer sourceViewer, LdapFilterParser parser )
+ {
+ super();
+ this.parser = parser;
+ this.sourceViewer = sourceViewer;
+
+ this.autoActivationCharacters = new char[1 + 26 + 26];
+ this.autoActivationCharacters[0] = '(';
+ int i = 1;
+ for ( char c = 'a'; c <= 'z'; c++, i++ )
+ {
+ this.autoActivationCharacters[i] = c;
+ }
+ for ( char c = 'A'; c <= 'Z'; c++, i++ )
+ {
+ this.autoActivationCharacters[i] = c;
+ }
+ }
+
+
+ public void setPossibleAttributeTypes( String[] possibleAttributeTypes )
+ {
+ Arrays.sort( possibleAttributeTypes );
+ this.possibleAttributeTypes = possibleAttributeTypes;
+ }
+
+
+ public char[] getCompletionProposalAutoActivationCharacters()
+ {
+ return this.autoActivationCharacters;
+ }
+
+
+ public ICompletionProposal[] computeCompletionProposals( ITextViewer viewer, int offset )
+ {
+ return this.computeCompletionProposals( offset );
+ }
+
+
+ public ICompletionProposal[] computeCompletionProposals( IContentAssistSubjectControl contentAssistSubjectControl,
+ int documentOffset )
+ {
+ String filter = contentAssistSubjectControl.getDocument().get();
+ this.parser.parse( filter );
+ return this.computeCompletionProposals( documentOffset );
+ }
+
+
+ public IContextInformation[] computeContextInformation( IContentAssistSubjectControl contentAssistSubjectControl,
+ int documentOffset )
+ {
+ return null;
+ }
+
+
+ private ICompletionProposal[] computeCompletionProposals( int offset )
+ {
+ List proposalList = new ArrayList();
+ LdapFilter filter = this.parser.getModel().getFilter( offset );
+ if ( filter != null )
+ {
+ if ( filter.getStartToken() != null && filter.getFilterComponent() == null )
+ {
+
+ if ( sourceViewer != null )
+ {
+ ICompletionProposal[] templateProposals = super.computeCompletionProposals( sourceViewer, offset );
+ if ( templateProposals != null )
+ {
+ proposalList.addAll( Arrays.asList( templateProposals ) );
+ }
+ }
+
+ for ( int k = 0; k < this.possibleAttributeTypes.length; k++ )
+ {
+ ICompletionProposal proposal = new CompletionProposal( this.possibleAttributeTypes[k], offset, 0,
+ this.possibleAttributeTypes[k].length() );
+ proposalList.add( proposal );
+ }
+ }
+ 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++ )
+ {
+ if ( this.possibleAttributeTypes[k].startsWith( fc.getAttributeToken().getValue() ) )
+ {
+ ICompletionProposal proposal = new CompletionProposal( this.possibleAttributeTypes[k], fc
+ .getAttributeToken().getOffset(), fc.getAttributeToken().getLength(),
+ this.possibleAttributeTypes[k].length() );
+ proposalList.add( proposal );
+ }
+ }
+ }
+ else
+ {
+ // no proposals
+ }
+ }
+ return ( ICompletionProposal[] ) proposalList.toArray( new ICompletionProposal[0] );
+
+ }
+
+
+ protected Template[] getTemplates( String contextTypeId )
+ {
+ Template[] templates = BrowserCommonActivator.getDefault().getFilterTemplateStore().getTemplates(
+ BrowserCommonConstants.FILTER_TEMPLATE_ID );
+ return templates;
+ }
+
+
+ protected TemplateContextType getContextType( ITextViewer viewer, IRegion region )
+ {
+ TemplateContextType contextType = BrowserCommonActivator.getDefault().getFilterTemplateContextTypeRegistry()
+ .getContextType( BrowserCommonConstants.FILTER_TEMPLATE_ID );
+ return contextType;
+ }
+
+
+ protected Image getImage( Template template )
+ {
+ return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_TEMPLATE );
+ }
+
+}
Added: 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=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterDamagerRepairer.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterDamagerRepairer.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,142 @@
+/*
+ * 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.filtereditor;
+
+
+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;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.TextAttribute;
+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;
+
+
+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 FILTER_TYPE_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator.getDefault()
+ .getColor( new RGB( 255, 0, 0 ) ), null, SWT.BOLD );
+
+ private static final TextAttribute VALUE_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator.getDefault().getColor(
+ new RGB( 0, 0, 127 ) ) );
+
+ private static final TextAttribute PARENTHESIS_TEXT_ATTRIBUTE = new TextAttribute( BrowserCommonActivator.getDefault()
+ .getColor( new RGB( 0, 0, 0 ) ), null, SWT.BOLD );
+
+ private SourceViewer sourceViewer;
+
+ private LdapFilterParser parser;
+
+ private IDocument document;
+
+
+ public FilterDamagerRepairer( SourceViewer sourceViewer, LdapFilterParser parser )
+ {
+ super();
+ this.sourceViewer = sourceViewer;
+ this.parser = parser;
+ this.document = null;
+ }
+
+
+ public void setDocument( IDocument document )
+ {
+ this.document = document;
+ }
+
+
+ public IRegion getDamageRegion( ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged )
+ {
+ return partition;
+ }
+
+
+ public void createPresentation( TextPresentation presentation, ITypedRegion damage )
+ {
+
+ // parse the filter
+ this.parser.parse( this.document.get() );
+
+ // get tokens
+ LdapFilterToken[] tokens = this.parser.getModel().getTokens();
+
+ // syntax highlighting
+ for ( int i = 0; i < tokens.length; i++ )
+ {
+ switch ( tokens[i].getType() )
+ {
+ case LdapFilterToken.LPAR:
+ case LdapFilterToken.RPAR:
+ this.addStyleRange( presentation, tokens[i], PARENTHESIS_TEXT_ATTRIBUTE );
+ break;
+ case LdapFilterToken.AND:
+ case LdapFilterToken.OR:
+ case LdapFilterToken.NOT:
+ this.addStyleRange( presentation, tokens[i], AND_OR_NOT_TEXT_ATTRIBUTE );
+ break;
+ case LdapFilterToken.EQUAL:
+ case LdapFilterToken.GREATER:
+ case LdapFilterToken.LESS:
+ case LdapFilterToken.APROX:
+ case LdapFilterToken.PRESENT:
+ this.addStyleRange( presentation, tokens[i], FILTER_TYPE_TEXT_ATTRIBUTE );
+ break;
+ case LdapFilterToken.ATTRIBUTE:
+ this.addStyleRange( presentation, tokens[i], ATTRIBUTE_TEXT_ATTRIBUTE );
+ break;
+ case LdapFilterToken.VALUE:
+ this.addStyleRange( presentation, tokens[i], VALUE_TEXT_ATTRIBUTE );
+ break;
+ default:
+ this.addStyleRange( presentation, tokens[i], DEFAULT_TEXT_ATTRIBUTE );
+ }
+ }
+
+ }
+
+
+ private void addStyleRange( TextPresentation presentation, LdapFilterToken token, TextAttribute textAttribute )
+ {
+ StyleRange range = new StyleRange( token.getOffset(), token.getLength(), textAttribute.getForeground(),
+ textAttribute.getBackground(), textAttribute.getStyle() );
+ presentation.addStyleRange( range );
+ }
+
+}
Added: 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=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterFormattingStrategy.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterFormattingStrategy.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,138 @@
+/*
+ * 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.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.LdapFilterItemComponent;
+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;
+
+
+public class FilterFormattingStrategy implements IFormattingStrategy
+{
+
+ private LdapFilterParser parser;
+
+ private SourceViewer sourceViewer;
+
+
+ public FilterFormattingStrategy( SourceViewer sourceViewer, LdapFilterParser parser )
+ {
+ super();
+ this.parser = parser;
+ this.sourceViewer = sourceViewer;
+ }
+
+
+ public void formatterStarts( String initialIndentation )
+ {
+ }
+
+
+ public String format( String content, boolean isLineStart, String indentation, int[] positions )
+ {
+ // this.parser.parse(content);
+ LdapFilter model = this.parser.getModel();
+ if ( model != null && model.isValid() )
+ {
+ this.sourceViewer.getDocument().set( get( model, 0 ) );
+ }
+
+ return null;
+ }
+
+
+ private String get( 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 )
+ {
+ sb.append( '(' ).append( ( ( LdapFilterItemComponent ) fc ).toString() ).append( ')' );
+ }
+ else if ( fc instanceof LdapNotFilterComponent )
+ {
+ sb.append( "(!" );
+ LdapNotFilterComponent lnfc = ( LdapNotFilterComponent ) fc;
+ if ( lnfc.getFilters().length > 0
+ && lnfc.getFilters()[0].getFilterComponent() instanceof LdapFilterItemComponent )
+ {
+ sb.append( get( ( lnfc ).getFilters()[0], 0 ) );
+ }
+ else
+ {
+ sb.append( '\n' );
+ sb.append( get( ( lnfc ).getFilters()[0], indent + 1 ) );
+ sb.append( '\n' );
+ for ( int i = 0; i < indent; i++ )
+ sb.append( FilterAutoEditStrategy.INDENT_STRING );
+ }
+ sb.append( ')' );
+ }
+ else if ( fc instanceof LdapAndFilterComponent )
+ {
+ sb.append( "(&" );
+ sb.append( '\n' );
+ LdapFilter[] filters = ( ( LdapAndFilterComponent ) fc ).getFilters();
+ for ( int i = 0; i < filters.length; i++ )
+ {
+ sb.append( get( filters[i], indent + 1 ) );
+ sb.append( '\n' );
+ }
+ for ( int i = 0; i < indent; i++ )
+ sb.append( FilterAutoEditStrategy.INDENT_STRING );
+ sb.append( ')' );
+ }
+ else if ( fc instanceof LdapOrFilterComponent )
+ {
+ sb.append( "(|" );
+ sb.append( '\n' );
+ LdapFilter[] filters = ( ( LdapOrFilterComponent ) fc ).getFilters();
+ for ( int i = 0; i < filters.length; i++ )
+ {
+ sb.append( get( filters[i], indent + 1 ) );
+ sb.append( '\n' );
+ }
+ for ( int i = 0; i < indent; i++ )
+ sb.append( FilterAutoEditStrategy.INDENT_STRING );
+ sb.append( ')' );
+ }
+
+ return sb.toString();
+ }
+
+
+ public void formatterStops()
+ {
+ }
+
+}
Added: 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=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterReconcilingStrategy.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterReconcilingStrategy.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldapstudio.browser.common.filtereditor;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+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;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.AnnotationModel;
+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.MatchingCharacterPainter;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.swt.graphics.RGB;
+
+
+public class FilterReconcilingStrategy implements IReconcilingStrategy
+{
+
+ private SourceViewer sourceViewer;
+
+ private LdapFilterParser parser;
+
+ private IDocument document;
+
+ private PaintManager paintManager;
+
+
+ public FilterReconcilingStrategy( SourceViewer sourceViewer, LdapFilterParser parser )
+ {
+ super();
+ this.sourceViewer = sourceViewer;
+ this.parser = parser;
+ this.document = null;
+ this.paintManager = null;
+ }
+
+
+ public void setDocument( IDocument document )
+ {
+ this.document = document;
+
+ if ( this.sourceViewer.getAnnotationModel() == null )
+ {
+ IAnnotationModel model = new AnnotationModel();
+ this.sourceViewer.setDocument( this.sourceViewer.getDocument(), model );
+ }
+
+ // add annotation painter
+ if ( this.paintManager == null && this.sourceViewer.getAnnotationModel() instanceof IAnnotationModelExtension )
+ {
+ AnnotationPainter ap = new AnnotationPainter( this.sourceViewer, null );
+ ap.addAnnotationType( "DEFAULT" );
+ ap.setAnnotationTypeColor( "DEFAULT", BrowserCommonActivator.getDefault().getColor( new RGB( 255, 0, 0 ) ) );
+ this.sourceViewer.getAnnotationModel().addAnnotationModelListener( ap );
+
+ FilterCharacterPairMatcher cpm = new FilterCharacterPairMatcher( this.sourceViewer, this.parser );
+ MatchingCharacterPainter mcp = new MatchingCharacterPainter( this.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 );
+ }
+
+ }
+
+
+ public void reconcile( DirtyRegion dirtyRegion, IRegion subRegion )
+ {
+ this.reconcile( dirtyRegion );
+ }
+
+
+ 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();
+
+ // annotations
+ if ( this.sourceViewer.getAnnotationModel() instanceof IAnnotationModelExtension )
+ {
+ ( ( IAnnotationModelExtension ) this.sourceViewer.getAnnotationModel() ).removeAllAnnotations();
+
+ List positionList = new ArrayList();
+
+ LdapFilter[] invalidFilters = this.parser.getModel().getInvalidFilters();
+ for ( int i = 0; i < invalidFilters.length; i++ )
+ {
+ if ( invalidFilters[i].getStartToken() != null )
+ {
+ int start = invalidFilters[i].getStartToken().getOffset();
+ int stop = invalidFilters[i].getStopToken() != null ? invalidFilters[i].getStopToken().getOffset()
+ + invalidFilters[i].getStopToken().getLength() : start
+ + invalidFilters[i].getStartToken().getLength();
+
+ 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 );
+ }
+ }
+
+ for ( int i = 0; i < tokens.length; i++ )
+ {
+ if ( tokens[i].getType() == LdapFilterToken.ERROR )
+ {
+
+ boolean overlaps = false;
+ for ( int k = 0; k < positionList.size(); k++ )
+ {
+ Position pos = ( Position ) positionList.get( k );
+ if ( pos.overlapsWith( tokens[i].getOffset(), tokens[i].getLength() ) )
+ {
+ overlaps = true;
+ break;
+ }
+ }
+ if ( !overlaps )
+ {
+ 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 );
+ }
+ }
+ }
+ }
+
+ }
+
+}
Added: 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=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterSourceViewerConfiguration.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterSourceViewerConfiguration.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,184 @@
+/*
+ * 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.filtereditor;
+
+
+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.IDocument;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.formatter.ContentFormatter;
+import org.eclipse.jface.text.formatter.IContentFormatter;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+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
+public class FilterSourceViewerConfiguration extends SourceViewerConfiguration
+{
+
+ private IConnection connection;
+
+ private LdapFilterParser parser;
+
+ private SourceViewer sourceViewer;
+
+ // Presentation Reconciler (syntax highlight)
+ private PresentationReconciler presentationReconciler;
+
+ private FilterDamagerRepairer damagerRepairer;
+
+ // Asynchronous Reconciler (annotations)
+ private MonoReconciler reconciler;
+
+ private FilterReconcilingStrategy reconcilingStrategy;
+
+ // Hover
+ private FilterTextHover textHover;
+
+ // Auto Edit Strategy
+ private FilterAutoEditStrategy autoEditStrategy;
+
+ private ContentFormatter formatter;
+
+ private FilterFormattingStrategy formattingStrategy;
+
+ // Content Assistent
+ private DialogContentAssistant contentAssistant;
+
+ private FilterContentAssistProcessor contentAssistProcessor;
+
+
+ public FilterSourceViewerConfiguration( SourceViewer sourceViewer, LdapFilterParser parser, IConnection connection )
+ {
+ super();
+ this.sourceViewer = sourceViewer;
+ this.parser = parser;
+ this.connection = connection;
+ }
+
+
+ public void setConnection( IConnection connection )
+ {
+ this.connection = connection;
+ this.contentAssistProcessor.setPossibleAttributeTypes( this.connection == null ? new String[0]
+ : this.connection.getSchema().getAttributeTypeDescriptionNames() );
+ }
+
+
+ public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer )
+ {
+ if ( this.damagerRepairer == null )
+ {
+ this.damagerRepairer = new FilterDamagerRepairer( this.sourceViewer, this.parser );
+ }
+ if ( this.presentationReconciler == null )
+ {
+ this.presentationReconciler = new PresentationReconciler();
+ this.presentationReconciler.setDamager( this.damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
+ this.presentationReconciler.setRepairer( this.damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE );
+ }
+ return this.presentationReconciler;
+ }
+
+
+ public ITextHover getTextHover( ISourceViewer sourceViewer, String contentType )
+ {
+ if ( this.textHover == null )
+ {
+ this.textHover = new FilterTextHover( this.sourceViewer, this.parser );
+ }
+ return this.textHover;
+ }
+
+
+ public IReconciler getReconciler( ISourceViewer sourceViewer )
+ {
+ if ( this.reconcilingStrategy == null )
+ {
+ this.reconcilingStrategy = new FilterReconcilingStrategy( this.sourceViewer, this.parser );
+ }
+ if ( this.reconciler == null )
+ {
+ this.reconciler = new MonoReconciler( this.reconcilingStrategy, false );
+ }
+ return this.reconciler;
+ }
+
+
+ public IAutoIndentStrategy getAutoIndentStrategy( ISourceViewer sourceViewer, String contentType )
+ {
+ if ( this.autoEditStrategy == null )
+ {
+ this.autoEditStrategy = new FilterAutoEditStrategy( this.sourceViewer, this.parser );
+ }
+ return this.autoEditStrategy;
+ }
+
+
+ public IContentFormatter getContentFormatter( ISourceViewer sourceViewer )
+ {
+ if ( this.formattingStrategy == null )
+ {
+ this.formattingStrategy = new FilterFormattingStrategy( this.sourceViewer, this.parser );
+ }
+ if ( this.formatter == null )
+ {
+ this.formatter = new ContentFormatter();
+ this.formatter.enablePartitionAwareFormatting( false );
+ this.formatter.setFormattingStrategy( this.formattingStrategy, IDocument.DEFAULT_CONTENT_TYPE );
+ }
+ return formatter;
+ }
+
+
+ public IContentAssistant getContentAssistant( ISourceViewer sourceViewer )
+ {
+
+ if ( this.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 );
+ }
+ return this.contentAssistant;
+
+ }
+
+}
Added: 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=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterTextHover.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/FilterTextHover.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,92 @@
+/*
+ * 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.filtereditor;
+
+
+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;
+
+
+public class FilterTextHover implements ITextHover
+{
+
+ private ISourceViewer sourceViewer;
+
+ private LdapFilterParser parser;
+
+
+ public FilterTextHover( ISourceViewer sourceViewer, LdapFilterParser parser )
+ {
+ super();
+ this.sourceViewer = sourceViewer;
+ this.parser = parser;
+ }
+
+
+ public String getHoverInfo( ITextViewer textViewer, IRegion hoverRegion )
+ {
+ LdapFilter[] invalidFilters = this.parser.getModel().getInvalidFilters();
+ for ( int i = 0; i < invalidFilters.length; i++ )
+ {
+ if ( invalidFilters[i].getStartToken() != null )
+ {
+ int start = invalidFilters[i].getStartToken().getOffset();
+ int stop = invalidFilters[i].getStopToken() != null ? invalidFilters[i].getStopToken().getOffset()
+ + invalidFilters[i].getStopToken().getLength() : start
+ + invalidFilters[i].getStartToken().getLength();
+ if ( start <= hoverRegion.getOffset() && hoverRegion.getOffset() < stop )
+ {
+ return invalidFilters[i].getInvalidCause();
+ }
+ }
+ }
+
+ LdapFilterToken[] tokens = this.parser.getModel().getTokens();
+ for ( int i = 0; i < tokens.length; i++ )
+ {
+ if ( tokens[i].getType() == LdapFilterToken.ERROR )
+ {
+
+ int start = tokens[i].getOffset();
+ int stop = start + tokens[i].getLength();
+ if ( start <= hoverRegion.getOffset() && hoverRegion.getOffset() < stop )
+ {
+ return "Invalid characters";
+ }
+ }
+ }
+ return null;
+ }
+
+
+ public IRegion getHoverRegion( ITextViewer textViewer, int offset )
+ {
+ return new Region( offset, 1 );
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/StyledTextContentAssistSubjectAdapter.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/StyledTextContentAssistSubjectAdapter.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/StyledTextContentAssistSubjectAdapter.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/filtereditor/StyledTextContentAssistSubjectAdapter.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,141 @@
+/*
+ * 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.filtereditor;
+
+
+import java.util.HashMap;
+
+import org.eclipse.jface.contentassist.AbstractControlContentAssistSubjectAdapter;
+import org.eclipse.jface.text.Assert;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+
+
+public class StyledTextContentAssistSubjectAdapter extends AbstractControlContentAssistSubjectAdapter
+{
+
+ private StyledText styledText;
+
+ private ITextViewer viewer;
+
+ private HashMap modifyListeners;
+
+
+ public StyledTextContentAssistSubjectAdapter( ITextViewer viewer )
+ {
+ Assert.isNotNull( viewer );
+ this.styledText = viewer.getTextWidget();
+ this.viewer = viewer;
+ this.modifyListeners = new HashMap();
+ }
+
+
+ public Control getControl()
+ {
+ return styledText;
+ }
+
+
+ public int getLineHeight()
+ {
+ return styledText.getLineHeight();
+ }
+
+
+ public int getCaretOffset()
+ {
+ return styledText.getCaretOffset();
+ }
+
+
+ public Point getLocationAtOffset( int offset )
+ {
+ return styledText.getLocationAtOffset( offset );
+ }
+
+
+ public Point getWidgetSelectionRange()
+ {
+ return new Point( styledText.getSelection().x, Math.abs( styledText.getSelection().y
+ - styledText.getSelection().x ) );
+ }
+
+
+ public Point getSelectedRange()
+ {
+ return new Point( styledText.getSelection().x, Math.abs( styledText.getSelection().y
+ - styledText.getSelection().x ) );
+ }
+
+
+ public void setSelectedRange( int i, int j )
+ {
+ styledText.setSelection( new Point( i, i + j ) );
+ }
+
+
+ public void revealRange( int i, int j )
+ {
+ styledText.setSelection( new Point( i, i + j ) );
+ }
+
+
+ public IDocument getDocument()
+ {
+ return viewer.getDocument();
+ }
+
+
+ public boolean addSelectionListener( final SelectionListener selectionListener )
+ {
+ styledText.addSelectionListener( selectionListener );
+ Listener listener = new Listener()
+ {
+ public void handleEvent( Event e )
+ {
+ selectionListener.widgetSelected( new SelectionEvent( e ) );
+ }
+ };
+ styledText.addListener( SWT.Modify, listener );
+ modifyListeners.put( selectionListener, listener );
+ return true;
+ }
+
+
+ public void removeSelectionListener( SelectionListener selectionListener )
+ {
+ styledText.removeSelectionListener( selectionListener );
+ Object listener = modifyListeners.get( selectionListener );
+ if ( listener instanceof Listener )
+ {
+ styledText.removeListener( SWT.Modify, ( Listener ) listener );
+ }
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/jobs/RunnableContextJobAdapter.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/jobs/RunnableContextJobAdapter.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/jobs/RunnableContextJobAdapter.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/jobs/RunnableContextJobAdapter.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,111 @@
+/*
+ * 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.jobs;
+
+
+import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
+import org.apache.directory.ldapstudio.browser.core.jobs.AbstractEclipseJob;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.widgets.Display;
+
+
+/**
+ * This class provides some convinience methods to execute a job within
+ * an {@link IRunnableContext}.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class RunnableContextJobAdapter
+{
+
+ /**
+ * Executes the given job within a new {@link ProgressMonitorDialog}.
+ *
+ * @param job the job to execute
+ */
+ public static void execute( final AbstractEclipseJob job )
+ {
+ execute( job, null );
+ }
+
+
+ /**
+ * Executes the given job within the given runnable context and enabled error handling
+ *
+ * @param runnableContext the runnable context
+ * @param job the job to execute
+ */
+ public static void execute( final AbstractEclipseJob job, IRunnableContext runnableContext )
+ {
+ execute( job, runnableContext, true );
+ }
+
+
+ /**
+ * Executes the given job within the given runnable context.
+ *
+ * @param runnableContext the runnable context
+ * @param job the job to execute
+ * @param handleError true to handle errors
+ */
+ public static void execute( final AbstractEclipseJob job, IRunnableContext runnableContext, boolean handleError )
+ {
+
+ if ( runnableContext == null )
+ {
+ runnableContext = new ProgressMonitorDialog( Display.getDefault().getActiveShell() );
+ }
+
+ IRunnableWithProgress runnable = new IRunnableWithProgress()
+ {
+ public void run( IProgressMonitor ipm ) throws InterruptedException
+ {
+ job.setExternalProgressMonitor( ipm );
+ job.execute();
+ job.join();
+ }
+ };
+
+ try
+ {
+ runnableContext.run( true, true, runnable );
+ }
+ catch ( Exception ex )
+ {
+ BrowserCommonActivator.getDefault().getExceptionHandler().handleException(
+ new Status( IStatus.ERROR, BrowserCommonActivator.PLUGIN_ID, IStatus.ERROR, ex.getMessage(), ex ) );
+ }
+
+ if ( handleError && !job.getExternalResult().isOK() )
+ {
+ IStatus status = job.getExternalResult();
+ BrowserCommonActivator.getDefault().getExceptionHandler().handleException( status );
+ }
+
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BaseWidgetUtils.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BaseWidgetUtils.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BaseWidgetUtils.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BaseWidgetUtils.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,474 @@
+/*
+ * 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;
+
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Text;
+
+
+/**
+ * This class provides utility methods to create SWT widgets.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BaseWidgetUtils
+{
+
+ /**
+ * Creates a SWT {@link Group} under the given parent.
+ *
+ * @param parent the parent
+ * @param label the label of the group
+ * @param span the horizontal span
+ * @return the created group
+ */
+ public static Group createGroup( Composite parent, String label, int span )
+ {
+ Group group = new Group( parent, SWT.NONE );
+ GridData gd = new GridData( GridData.FILL_BOTH );
+ gd.horizontalSpan = span;
+ group.setLayoutData( gd );
+ group.setText( label );
+ group.setLayout( new GridLayout() );
+ return group;
+ }
+
+
+ /**
+ * Creates a SWT {@link Composite} under the given parent.
+ * A GridLayout with the given number of columns is used.
+ *
+ * @param parent the parent
+ * @param columnCount the number of columns
+ * @param span the horizontal span
+ * @return the created composite
+ */
+ public static Composite createColumnContainer( Composite parent, int columnCount, int span )
+ {
+ Composite container = new Composite( parent, SWT.NONE );
+ GridLayout gl = new GridLayout( columnCount, false );
+ gl.marginHeight = gl.marginWidth = 0;
+ container.setLayout( gl );
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = span;
+ container.setLayoutData( gd );
+ return container;
+ }
+
+
+ /**
+ * Creates a SWT {@link Label} under the given parent.
+ *
+ * @param parent the parent
+ * @param text the label's text
+ * @param span the horizontal span
+ * @return the created label
+ */
+ public static Label createLabel( Composite parent, String text, int span )
+ {
+ Label l = new Label( parent, SWT.NONE );
+ GridData gd = new GridData();
+ gd.horizontalSpan = span;
+ // gd.verticalAlignment = SWT.BEGINNING;
+ l.setLayoutData( gd );
+ l.setText( text );
+ return l;
+ }
+
+
+ /**
+ * Creates a SWT {@link Label} under the given parent.
+ * The label is created with the SWT.WRAP style to enable line wrapping.
+ *
+ * @param parent the parent
+ * @param text the label's text
+ * @param span the horizontal span
+ * @return the created label
+ */
+ public static Label createWrappedLabel( Composite parent, String text, int span )
+ {
+ Label l = new Label( parent, SWT.WRAP );
+ GridData gd = new GridData();
+ gd.horizontalSpan = span;
+ // gd.verticalAlignment = SWT.BEGINNING;
+ l.setLayoutData( gd );
+ l.setText( text );
+ return l;
+ }
+
+
+ /**
+ * Creates a SWT {@link Text} under the given parent.
+ * The created text control is modifyable.
+ *
+ * @param parent the parent
+ * @param text the initial text
+ * @param span the horizontal span
+ * @return the created text
+ */
+ public static Text createText( Composite parent, String text, int span )
+ {
+ Text t = new Text( parent, SWT.NONE | SWT.BORDER );
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = span;
+ t.setLayoutData( gd );
+ t.setText( text );
+ return t;
+ }
+
+
+ /**
+ * Creates a SWT {@link Text} under the given parent.
+ * The created text control is modifyable.
+ *
+ * @param parent the parent
+ * @param text the initial text
+ * @param textWidth the width of the text control
+ * @param span the horizontal span
+ * @return the created text
+ */
+ public static Text createText( Composite parent, String text, int textWidth, int span )
+ {
+ Text t = new Text( parent, SWT.NONE | SWT.BORDER );
+ GridData gd = new GridData();
+ gd.horizontalSpan = span;
+ gd.widthHint = 9 * textWidth;
+ t.setLayoutData( gd );
+ t.setText( text );
+ t.setTextLimit( textWidth );
+ return t;
+ }
+
+
+ /**
+ * Creates a SWT {@link Text} under the given parent.
+ * The created text control is created with the SWT.PASSWORD style.
+ *
+ * @param parent the parent
+ * @param text the initial text
+ * @param span the horizontal span
+ * @return the created text
+ */
+ public static Text createPasswordText( Composite parent, String text, int span )
+ {
+ Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.PASSWORD );
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = span;
+ t.setLayoutData( gd );
+ t.setText( text );
+ return t;
+ }
+
+
+ /**
+ * Creates a SWT {@link Text} under the given parent.
+ * The created text control is created with the SWT.PASSWORD and
+ * SWT.READ_ONLY style. So the created controls is not modifyable.
+ *
+ * @param parent the parent
+ * @param text the initial text
+ * @param span the horizontal span
+ * @return the created text
+ */
+ public static Text createReadonlyPasswordText( Composite parent, String text, int span )
+ {
+ Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.PASSWORD | SWT.READ_ONLY );
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = span;
+ t.setLayoutData( gd );
+ t.setEditable( false );
+ t.setBackground( parent.getBackground() );
+ t.setText( text );
+ return t;
+ }
+
+
+ /**
+ * Creates a SWT {@link Text} under the given parent.
+ * The created text control behaves like a label: it has no border,
+ * a grayed background and is not modifyable.
+ * But the text is selectable and could be copied.
+ *
+ * @param parent the parent
+ * @param text the initial text
+ * @param span the horizontal span
+ * @return the created text
+ */
+ public static Text createLabeledText( Composite parent, String text, int span )
+ {
+ Text t = new Text( parent, SWT.NONE );
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = span;
+ t.setLayoutData( gd );
+ t.setEditable( false );
+ t.setBackground( parent.getBackground() );
+ t.setText( text );
+ return t;
+ }
+
+
+ /**
+ * Creates a SWT {@link Text} under the given parent.
+ * The created text control behaves like a label: it has no border,
+ * a grayed background and is not modifyable.
+ * But the text is selectable and could be copied.
+ * The label is created with the SWT.WRAP style to enable line wrapping.
+ *
+ * @param parent the parent
+ * @param text the initial text
+ * @param span the horizontal span
+ * @return the created text
+ */
+ public static Text createWrappedLabeledText( Composite parent, String text, int span )
+ {
+ Text t = new Text( parent, SWT.WRAP );
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = span;
+ gd.widthHint = 10;
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = GridData.FILL;
+ t.setLayoutData( gd );
+ t.setEditable( false );
+ t.setBackground( parent.getBackground() );
+ t.setText( text );
+ return t;
+ }
+
+
+ /**
+ * Creates a SWT {@link Text} under the given parent.
+ * The text is not modifyable, but the text is selectable
+ * and could be copied.
+ *
+ * @param parent the parent
+ * @param text the initial text
+ * @param span the horizontal span
+ * @return the created text
+ */
+ public static Text createReadonlyText( Composite parent, String text, int span )
+ {
+ Text t = new Text( parent, SWT.NONE | SWT.BORDER | SWT.READ_ONLY );
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = span;
+ t.setLayoutData( gd );
+ t.setEditable( false );
+ t.setBackground( parent.getBackground() );
+ t.setText( text );
+ return t;
+ }
+
+
+ /**
+ * Creates a SWT {@link Combo} under the given parent.
+ * Beside the selection of an item it is also possible to type
+ * free text into the combo.
+ *
+ * @param parent the parent
+ * @param items the initial visible items
+ * @param selectedIndex the initial selected item, zero-based
+ * @param span the horizontal span
+ * @return the created combo
+ */
+ public static Combo createCombo( Composite parent, String[] items, int selectedIndex, int span )
+ {
+ Combo c = new Combo( parent, SWT.DROP_DOWN | SWT.BORDER );
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = span;
+ c.setLayoutData( gd );
+ c.setItems( items );
+ c.select( selectedIndex );
+ c.setVisibleItemCount( 20 );
+ return c;
+ }
+
+
+ /**
+ * Creates a SWT {@link Combo} under the given parent.
+ * It is not possible to type free text into the combo, only
+ * selection of predefined items is possible.
+ *
+ * @param parent the parent
+ * @param items the initial visible items
+ * @param selectedIndex the initial selected item, zero-based
+ * @param span the horizontal span
+ * @return the created combo
+ */
+ public static Combo createReadonlyCombo( Composite parent, String[] items, int selectedIndex, int span )
+ {
+ Combo c = new Combo( parent, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER );
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = span;
+ c.setLayoutData( gd );
+ // c.setBackground(parent.getBackground());
+ c.setItems( items );
+ c.select( selectedIndex );
+ c.setVisibleItemCount( 20 );
+ return c;
+ }
+
+
+ /**
+ * Creates a checkbox under the given parent.
+ *
+ * @param parent the parent
+ * @param text the label of the checkbox
+ * @param span the horizontal span
+ * @return the created checkbox
+ */
+ public static Button createCheckbox( Composite parent, String text, int span )
+ {
+ Button checkbox = new Button( parent, SWT.CHECK );
+ checkbox.setText( text );
+ GridData gd = new GridData();
+ gd.horizontalSpan = span;
+ checkbox.setLayoutData( gd );
+ return checkbox;
+ }
+
+
+ /**
+ * Creates a radio button under the given parent.
+ *
+ * @param parent the parent
+ * @param text the label of the radio button
+ * @param span the horizontal span
+ * @return the created radio button
+ */
+ public static Button createRadiobutton( Composite parent, String text, int span )
+ {
+ Button radio = new Button( parent, SWT.RADIO );
+ radio.setText( text );
+ GridData gd = new GridData();
+ gd.horizontalSpan = span;
+ radio.setLayoutData( gd );
+ return radio;
+ }
+
+
+ /**
+ * Creates a button under the given parent.
+ * The button width is set to the default width.
+ *
+ * @param parent the parent
+ * @param text the label of the button
+ * @param span the horizontal span
+ * @return the created button
+ */
+ public static Button createButton( Composite parent, String text, int span )
+ {
+ GC gc = new GC( parent );
+ gc.setFont( JFaceResources.getDialogFont() );
+ FontMetrics fontMetrics = gc.getFontMetrics();
+ gc.dispose();
+
+ Button button = new Button( parent, SWT.PUSH );
+ GridData gd = new GridData();
+ gd.widthHint = Dialog.convertHorizontalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH );
+ button.setLayoutData( gd );
+ button.setText( text );
+ return button;
+ }
+
+
+ /**
+ * Adds some space to indent radio buttons.
+ *
+ * @param parent the parent
+ * @param span the horizontal span
+ */
+ public static void createRadioIndent( Composite parent, int span )
+ {
+ Label l = new Label( parent, SWT.NONE );
+ GridData gd = new GridData();
+ gd.horizontalSpan = span;
+ gd.horizontalIndent = 22;
+ l.setLayoutData( gd );
+ }
+
+
+ /**
+ * Creates a spacer.
+ *
+ * @param parent the parent
+ * @param span the horizontal span
+ */
+ public static void createSpacer( Composite parent, int span )
+ {
+ Label l = new Label( parent, SWT.NONE );
+ // GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ GridData gd = new GridData();
+ gd.horizontalSpan = span;
+ gd.heightHint = 1;
+ l.setLayoutData( gd );
+ }
+
+
+ /**
+ * Creates a separator line.
+ *
+ * @param parent the parent
+ * @param span the horizontal span
+ */
+ public static void createSeparator( Composite parent, int span )
+ {
+ Label l = new Label( parent, SWT.SEPARATOR | SWT.HORIZONTAL );
+ GridData gd = new GridData( GridData.FILL_HORIZONTAL );
+ gd.horizontalSpan = span;
+ // gd.heightHint = 1;
+ l.setLayoutData( gd );
+ }
+
+
+ /**
+ * Creates a SWT {@link Link} under the given parent.
+ *
+ * @param parent the parent
+ * @param text the initial text
+ * @param span the horizontal span
+ * @return the created text
+ */
+ public static Link createLink( Composite parent, String text, int span )
+ {
+ Link link = new Link( parent, SWT.NONE );
+ link.setText( text );
+ GridData gd = new GridData( SWT.FILL, SWT.BEGINNING, true, false );
+ gd.horizontalSpan = span;
+ gd.widthHint = 150;
+ link.setLayoutData( gd );
+ return link;
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BinaryEncodingInput.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BinaryEncodingInput.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BinaryEncodingInput.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BinaryEncodingInput.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,103 @@
+/*
+ * 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;
+
+
+import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
+
+
+/**
+ * The BinaryEncodingInput is an OptionInput with fixed options.
+ * It is used to select the encoding of binary attributes. The default
+ * value is always {@link BrowserCoreConstants#BINARYENCODING_IGNORE}.
+ * The other options are always {@link BrowserCoreConstants#BINARYENCODING_IGNORE},
+ * {@link BrowserCoreConstants#BINARYENCODING_BASE64} and
+ * {@link BrowserCoreConstants#BINARYENCODING_HEX}. No custom input is allowed.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BinaryEncodingInput extends OptionsInput
+{
+
+ /**
+ * Creates a new instance of BinaryEncodingInput.
+ *
+ * @param initialRawValue the initial raw value
+ * @param asGroup the asGroup flag
+ */
+ public BinaryEncodingInput( String initialRawValue, boolean asGroup )
+ {
+ super( "Binary Encoding", getDefaultDisplayValue(), getDefaultRawValue(), getOtherDisplayValues(),
+ getOtherRawValues(), initialRawValue, asGroup, false );
+
+ }
+
+
+ /**
+ * Gets the default display value, always "Ignore".
+ *
+ * @return the default display value
+ */
+ private static String getDefaultDisplayValue()
+ {
+ return "Ignore";
+ }
+
+
+ /**
+ * Gets the default raw value, always
+ * {@link BrowserCoreConstants.BINARYENCODING_IGNORE}.
+ *
+ * @return the default raw value
+ */
+ private static String getDefaultRawValue()
+ {
+ return Integer.toString( BrowserCoreConstants.BINARYENCODING_IGNORE );
+ }
+
+
+ /**
+ * Gets the other display values.
+ *
+ * @return the other display values
+ */
+ private static String[] getOtherDisplayValues()
+ {
+ return new String[]
+ { "Ignore", "BASE-64", "HEX" };
+ }
+
+
+ /**
+ * Gets the other raw values.
+ *
+ * @return the other raw values
+ */
+ private static String[] getOtherRawValues()
+ {
+ return new String[]
+ { Integer.toString( BrowserCoreConstants.BINARYENCODING_IGNORE ),
+ Integer.toString( BrowserCoreConstants.BINARYENCODING_BASE64 ),
+ Integer.toString( BrowserCoreConstants.BINARYENCODING_HEX ) };
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BrowserWidget.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BrowserWidget.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BrowserWidget.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/BrowserWidget.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,91 @@
+/*
+ * 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;
+
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+/**
+ * Base class that provides support for {@link WidgetModifyListener}
+ * registration and notification.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public abstract class BrowserWidget
+{
+
+ /** The listener list */
+ protected List<WidgetModifyListener> modifyListenerList;
+
+
+ /**
+ * Creates a new instance of BrowserWidget.
+ */
+ protected BrowserWidget()
+ {
+ modifyListenerList = new ArrayList<WidgetModifyListener>( 3 );
+ }
+
+
+ /**
+ * Adds the widget modify listener.
+ *
+ * @param listener the listener
+ */
+ public void addWidgetModifyListener( WidgetModifyListener listener )
+ {
+ if ( !modifyListenerList.contains( listener ) )
+ {
+ modifyListenerList.add( listener );
+ }
+ }
+
+
+ /**
+ * Removes the widget modify listener.
+ *
+ * @param listener the listener
+ */
+ public void removeWidgetModifyListener( WidgetModifyListener listener )
+ {
+ if ( modifyListenerList.contains( listener ) )
+ modifyListenerList.remove( listener );
+ }
+
+
+ /**
+ * Notifies the listeners.
+ */
+ protected void notifyListeners()
+ {
+ WidgetModifyEvent event = new WidgetModifyEvent( this );
+ for ( Iterator<WidgetModifyListener> it = modifyListenerList.iterator(); it.hasNext(); )
+ {
+ WidgetModifyListener listener = it.next();
+ listener.widgetModified( event );
+ }
+ }
+
+}
Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/DialogContentAssistant.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/DialogContentAssistant.java?view=auto&rev=526693
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/DialogContentAssistant.java (added)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/DialogContentAssistant.java Mon Apr 9 02:49:48 2007
@@ -0,0 +1,220 @@
+/*
+ * 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;
+
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.jface.contentassist.ComboContentAssistSubjectAdapter;
+import org.eclipse.jface.contentassist.SubjectControlContentAssistant;
+import org.eclipse.jface.contentassist.TextContentAssistSubjectAdapter;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.IHandlerActivation;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+
+
+/**
+ * The DialogContentAssistant is used to provide content assist and
+ * a proposal popup within a SWT {@link Text}, {@link Combo} or
+ * {@link ITextViewer}.
+ *
+ * It provides a special handling of ESC keystrokes:
+ * When the proposal popup is shown ESC is catched and the popup is closed.
+ * This ensures that a dialog isn't closed on a ESC keystroke
+ * while the proposal popup is opened.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DialogContentAssistant extends SubjectControlContentAssistant implements FocusListener
+{
+
+ /** The control */
+ private Control control;
+
+ /** The handler activation. */
+ private IHandlerActivation handlerActivation;
+
+ /** The possible completions visible. */
+ private boolean possibleCompletionsVisible;
+
+
+ /**
+ * Creates a new instance of DialogContentAssistant.
+ */
+ public DialogContentAssistant()
+ {
+ this.possibleCompletionsVisible = false;
+ }
+
+
+ /**
+ * Installs content assist on the given text.
+ *
+ * @param text the text
+ */
+ public void install( Text text )
+ {
+ control = text;
+ control.addFocusListener( this );
+ super.install( new TextContentAssistSubjectAdapter( text ) );
+ }
+
+
+ /**
+ * Installs content assist on the given combo.
+ *
+ * @param combo the combo
+ */
+ public void install( Combo combo )
+ {
+ control = combo;
+ control.addFocusListener( this );
+ super.install( new ComboContentAssistSubjectAdapter( combo ) );
+ }
+
+
+ /**
+ * Installs content assist on the given text viewer.
+ *
+ * @param viewer the text viewer
+ */
+ public void install( ITextViewer viewer )
+ {
+ control = viewer.getTextWidget();
+ control.addFocusListener( this );
+
+ // stop traversal (ESC) if popup is shown
+ control.addTraverseListener( new TraverseListener()
+ {
+ public void keyTraversed( TraverseEvent e )
+ {
+ if ( possibleCompletionsVisible )
+ {
+ e.doit = false;
+ }
+ }
+ } );
+
+ super.install( viewer );
+ }
+
+
+ /**
+ * Uninstalls content assist on the control.
+ */
+ public void uninstall()
+ {
+ if ( handlerActivation != null )
+ {
+ IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter(
+ IHandlerService.class );
+ handlerService.deactivateHandler( handlerActivation );
+ handlerActivation = null;
+ }
+
+ if ( control != null )
+ {
+ control.removeFocusListener( this );
+ }
+
+ super.uninstall();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected Point restoreCompletionProposalPopupSize()
+ {
+ possibleCompletionsVisible = true;
+ return super.restoreCompletionProposalPopupSize();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public String showPossibleCompletions()
+ {
+ possibleCompletionsVisible = true;
+ return super.showPossibleCompletions();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void possibleCompletionsClosed()
+ {
+ possibleCompletionsVisible = false;
+ super.possibleCompletionsClosed();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void focusGained( FocusEvent e )
+ {
+ IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter(
+ IHandlerService.class );
+ if ( handlerService != null )
+ {
+ IHandler handler = new org.eclipse.core.commands.AbstractHandler()
+ {
+ public Object execute( ExecutionEvent event ) throws org.eclipse.core.commands.ExecutionException
+ {
+ showPossibleCompletions();
+ return null;
+ }
+ };
+ handlerActivation = handlerService.activateHandler(
+ ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, handler );
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void focusLost( FocusEvent e )
+ {
+ if ( handlerActivation != null )
+ {
+ IHandlerService handlerService = ( IHandlerService ) PlatformUI.getWorkbench().getAdapter(
+ IHandlerService.class );
+ handlerService.deactivateHandler( handlerActivation );
+ handlerActivation = null;
+ }
+ }
+
+}