Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 77D88173EE for ; Thu, 2 Apr 2015 16:14:43 +0000 (UTC) Received: (qmail 50526 invoked by uid 500); 2 Apr 2015 16:14:30 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 50459 invoked by uid 500); 2 Apr 2015 16:14:30 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 50261 invoked by uid 99); 2 Apr 2015 16:14:30 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Apr 2015 16:14:30 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 35EF2AC09E8 for ; Thu, 2 Apr 2015 16:14:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1670931 [4/8] - in /directory/studio/trunk: features/openldap.feature/ plugins/ plugins/openldap.acl.editor/ plugins/openldap.acl.editor/resources/ plugins/openldap.acl.editor/resources/icons/ plugins/openldap.acl.editor/resources/template... Date: Thu, 02 Apr 2015 16:14:28 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150402161430.35EF2AC09E8@hades.apache.org> Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclFormattingStrategy.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclFormattingStrategy.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclFormattingStrategy.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclFormattingStrategy.java Thu Apr 2 16:14:26 2015 @@ -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.studio.openldap.config.acl.sourceeditor; + + +import org.apache.directory.studio.ldapbrowser.core.BrowserCoreConstants; +import org.eclipse.jface.text.formatter.IFormattingStrategy; +import org.eclipse.jface.text.source.ISourceViewer; + + +/** + * This class implements the formatting strategy for the OpenLDAP ACL Editor. + *
    + *
  • New line before the "by" keyword + *
+ */ +public class OpenLdapAclFormattingStrategy implements IFormattingStrategy +{ + /** The Constant NEWLINE. */ + public static final String NEWLINE = BrowserCoreConstants.LINE_SEPARATOR; + + /** The source viewer. */ + private ISourceViewer sourceViewer; + + + /** + * Creates a new instance of OpenLdapAclFormattingStrategy. + * + * @param sourceViewer the source viewer + */ + public OpenLdapAclFormattingStrategy( ISourceViewer sourceViewer ) + { + this.sourceViewer = sourceViewer; + } + + + /** + * {@inheritDoc} + */ + public String format( String content, boolean isLineStart, String indentation, int[] positions ) + { + String oldContent = sourceViewer.getDocument().get(); + String newContent = internFormat( oldContent ); + sourceViewer.getDocument().set( newContent ); + + return null; + } + + + /** + * {@inheritDoc} + */ + public void formatterStarts( String initialIndentation ) + { + } + + + /** + * {@inheritDoc} + */ + public void formatterStops() + { + } + + + private String internFormat( String content ) + { + StringBuffer sb = new StringBuffer(); + + // Flag to track if we are within a quoted string + boolean inQuotedString = false; + + // Flag to track if a new line was started + boolean newLineStarted = true; + + // Char index + int i = 0; + + int contentLength = content.length(); + while ( i < contentLength ) + { + char currentChar = content.charAt( i ); + + // Tracking quotes + if ( currentChar == '"' ) + { + inQuotedString = !inQuotedString; + } + else if ( newLineStarted && ( ( currentChar == '\n' ) || ( currentChar == '\r' ) ) ) + { + // Compress multiple newlines + i++; + continue; + } + + // Checking if we're not in a quoted text + if ( !inQuotedString ) + { + // Getting the next char (if available) + char nextChar = 0; + if ( ( i + 1 ) < contentLength ) + { + nextChar = content.charAt( i + 1 ); + } + + // Checking if we have the "by" keyword + if ( ( !newLineStarted ) && ( currentChar == 'b' ) && ( nextChar == 'y' ) ) + { + sb.append( NEWLINE ); + newLineStarted = true; + } + else + { + // Tracking new line + newLineStarted = ( ( currentChar == '\n' ) || ( currentChar == '\r' ) ); + } + } + + sb.append( currentChar ); + i++; + } + + return sb.toString(); + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclSourceViewerConfiguration.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclSourceViewerConfiguration.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclSourceViewerConfiguration.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclSourceViewerConfiguration.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.sourceeditor; + + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +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.formatter.IFormattingStrategy; +import org.eclipse.jface.text.presentation.IPresentationReconciler; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; + +import org.apache.directory.studio.openldap.config.acl.OpenLdapAclEditorPlugin; + + +/** + * This class enables the features of the editor (Syntax coloring, code completion, etc.) + * + * @author Apache Directory Project + */ +public class OpenLdapAclSourceViewerConfiguration extends SourceViewerConfiguration +{ + /** + * {@inheritDoc} + */ + public IPresentationReconciler getPresentationReconciler( ISourceViewer sourceViewer ) + { + PresentationReconciler reconciler = new PresentationReconciler(); + reconciler.setDocumentPartitioning( getConfiguredDocumentPartitioning( sourceViewer ) ); + + // Creating the damager/repairer for code + DefaultDamagerRepairer dr = new DefaultDamagerRepairer( OpenLdapAclEditorPlugin.getDefault() + .getCodeScanner() ); + reconciler.setDamager( dr, IDocument.DEFAULT_CONTENT_TYPE ); + reconciler.setRepairer( dr, IDocument.DEFAULT_CONTENT_TYPE ); + + return reconciler; + } + + + /** + * {@inheritDoc} + */ + public IContentAssistant getContentAssistant( ISourceViewer sourceViewer ) + { + // ContentAssistant assistant = new ContentAssistant(); + ContentAssistant assistant = new DialogContentAssistant(); + IContentAssistProcessor aciContentAssistProcessor = new OpenLdapContentAssistProcessor(); + + assistant.setContentAssistProcessor( aciContentAssistProcessor, IDocument.DEFAULT_CONTENT_TYPE ); + assistant.enableAutoActivation( true ); + assistant.setAutoActivationDelay( 500 ); + assistant.setProposalPopupOrientation( IContentAssistant.PROPOSAL_STACKED ); + assistant.setContextInformationPopupOrientation( IContentAssistant.CONTEXT_INFO_ABOVE ); + + return assistant; + } + + + /** + * {@inheritDoc} + */ + public IContentFormatter getContentFormatter( ISourceViewer sourceViewer ) + { + ContentFormatter formatter = new ContentFormatter(); + IFormattingStrategy formattingStrategy = new OpenLdapAclFormattingStrategy( sourceViewer ); + formatter.enablePartitionAwareFormatting( false ); + formatter.setFormattingStrategy( formattingStrategy, IDocument.DEFAULT_CONTENT_TYPE ); + return formatter; + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclTextAttributeProvider.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclTextAttributeProvider.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclTextAttributeProvider.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapAclTextAttributeProvider.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.sourceeditor; + + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + + +/** + * This class provides the TextAttributes elements for each kind of attribute + * + * @author Apache Directory Project + */ +public class OpenLdapAclTextAttributeProvider +{ + public static final String DEFAULT_ATTRIBUTE = "__pos_acl_default_attribute"; //$NON-NLS-1$ + public static final String KEYWORD_ATTRIBUTE = "__pos_acl_keyword_attribute"; //$NON-NLS-1$ + public static final String STRING_ATTRIBUTE = "__pos_acl_string_attribute"; //$NON-NLS-1$ + + private Map attributes = new HashMap(); + + + /** + * Creates a new instance of AciTextAttributeProvider. + */ + public OpenLdapAclTextAttributeProvider() + { + attributes.put( DEFAULT_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0, 0, 0 ) ) ) ); + + attributes.put( KEYWORD_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 127, 0, 85 ) ), + null, SWT.BOLD ) ); + + attributes.put( STRING_ATTRIBUTE, new TextAttribute( new Color( Display.getCurrent(), new RGB( 0, 0, 255 ) ) ) ); + } + + + /** + * Gets the correct TextAttribute for the given type + * + * @param type + * the type of element + * @return + * the correct TextAttribute for the given type + */ + public TextAttribute getAttribute( String type ) + { + TextAttribute attr = ( TextAttribute ) attributes.get( type ); + if ( attr == null ) + { + attr = ( TextAttribute ) attributes.get( DEFAULT_ATTRIBUTE ); + } + return attr; + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapContentAssistProcessor.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapContentAssistProcessor.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapContentAssistProcessor.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/OpenLdapContentAssistProcessor.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.sourceeditor; + + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.contentassist.IContextInformation; +import org.eclipse.jface.text.contentassist.IContextInformationValidator; +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; + +import org.apache.directory.studio.openldap.config.acl.OpenLdapAclEditorPlugin; +import org.apache.directory.studio.openldap.config.acl.OpenLdapAclEditorPluginConstants; + + +/** + * This class implements the Content Assist Processor for ACI Item + * + * @author Apache Directory Project + */ +public class OpenLdapContentAssistProcessor extends TemplateCompletionProcessor +{ + /** + * {@inheritDoc} + */ + public ICompletionProposal[] computeCompletionProposals( ITextViewer viewer, int offset ) + { + List proposalList = new ArrayList(); + + // Add context dependend template proposals + ICompletionProposal[] templateProposals = super.computeCompletionProposals( viewer, offset ); + if ( templateProposals != null ) + { + proposalList.addAll( Arrays.asList( templateProposals ) ); + } + + return ( ICompletionProposal[] ) proposalList.toArray( new ICompletionProposal[0] ); + } + + + /** + * {@inheritDoc} + */ + public IContextInformation[] computeContextInformation( ITextViewer viewer, int offset ) + { + return null; + } + + + /** + * {@inheritDoc} + */ + public char[] getCompletionProposalAutoActivationCharacters() + { + + char[] chars = new char[52]; + for ( int i = 0; i < 26; i++ ) + { + chars[i] = ( char ) ( 'a' + i ); + } + for ( int i = 0; i < 26; i++ ) + { + chars[i + 26] = ( char ) ( 'A' + i ); + } + + return chars; + } + + + /** + * {@inheritDoc} + */ + public char[] getContextInformationAutoActivationCharacters() + { + return null; + } + + + /** + * {@inheritDoc} + */ + public IContextInformationValidator getContextInformationValidator() + { + return null; + } + + + /** + * {@inheritDoc} + */ + public String getErrorMessage() + { + return null; + } + + + /** + * {@inheritDoc} + */ + protected TemplateContextType getContextType( ITextViewer viewer, IRegion region ) + { + return OpenLdapAclEditorPlugin.getDefault().getTemplateContextTypeRegistry().getContextType( + OpenLdapAclEditorPluginConstants.TEMPLATE_ID ); + } + + + /** + * {@inheritDoc} + */ + protected Image getImage( Template template ) + { + return null; + } + + + /** + * {@inheritDoc} + */ + protected Template[] getTemplates( String contextTypeId ) + { + return OpenLdapAclEditorPlugin.getDefault().getTemplateStore().getTemplates( contextTypeId ); + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/StarRule.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/StarRule.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/StarRule.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/sourceeditor/StarRule.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.directory.studio.openldap.config.acl.sourceeditor; + + +import org.eclipse.jface.text.rules.ICharacterScanner; +import org.eclipse.jface.text.rules.IToken; +import org.eclipse.jface.text.rules.Token; + + +/** + * Rule to detect a "dn[.type[,modifier]]=" clause. + */ +public class StarRule extends AbstractRule +{ + + + /** + * Creates a new instance of StarRule. + * + * @param token the associated token + */ + public StarRule( IToken token ) + { + super( token ); + } + + + /** + * {@inheritDoc} + */ + public IToken evaluate( ICharacterScanner scanner, boolean resume ) + { + // Looking for '*' + if ( matchChar( scanner, '*' ) ) + { + // Token evaluation complete + return token; + } + else + { + // Not what was expected + return Token.UNDEFINED; + } + } + + + /** + * {@inheritDoc} + */ + public IToken evaluate( ICharacterScanner scanner ) + { + return this.evaluate( scanner, false ); + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AclWhoClauseSsfValuesEnum.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AclWhoClauseSsfValuesEnum.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AclWhoClauseSsfValuesEnum.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AclWhoClauseSsfValuesEnum.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.widgets; + + +public enum AclWhoClauseSsfValuesEnum +{ + ANY, + FORTY, + FIFTY_SIX, + SIXTY_FOUR, + ONE_TWENTY_HEIGHT, + ONE_SIXTY_FOUR, + TWO_FIFTY_SIX, + CUSTOM +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributeTypeContentProposal.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributeTypeContentProposal.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributeTypeContentProposal.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributeTypeContentProposal.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.widgets; + + +public class AttributeTypeContentProposal extends AttributesWidgetContentProposal +{ + public AttributeTypeContentProposal( String content ) + { + super( content ); + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidget.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidget.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidget.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidget.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,288 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.widgets; + + +import java.util.ArrayList; +import java.util.List; + +import org.apache.directory.studio.common.ui.HistoryUtils; +import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; +import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator; +import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants; +import org.apache.directory.studio.ldapbrowser.common.widgets.BrowserWidget; +import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; +import org.eclipse.jface.bindings.keys.KeyStroke; +import org.eclipse.jface.fieldassist.ComboContentAdapter; +import org.eclipse.jface.fieldassist.ContentProposalAdapter; +import org.eclipse.jface.fieldassist.IContentProposal; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; + +import org.apache.directory.studio.openldap.config.acl.OpenLdapAclEditorPlugin; +import org.apache.directory.studio.openldap.config.acl.OpenLdapAclEditorPluginConstants; + + +public class AttributesWidget extends BrowserWidget +{ + /** The initial attributes. */ + private String[] initialAttributes; + + /** The attributes combo */ + private Combo attributesCombo; + + /** The proposal provider */ + private AttributesWidgetContentProposalProvider proposalProvider; + + /** The proposal adapter*/ + private ContentProposalAdapter proposalAdapter; + + /** The label provider for the proposal adapter */ + private LabelProvider labelProvider = new LabelProvider() + { + public String getText( Object element ) + { + if ( element instanceof IContentProposal ) + { + IContentProposal proposal = ( IContentProposal ) element; + return proposal.getLabel() == null ? proposal.getContent() : proposal.getLabel(); + } + + return super.getText( element ); + }; + + + public Image getImage( Object element ) + { + if ( element instanceof AttributeTypeContentProposal ) + { + return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_ATD ); + } + else if ( element instanceof ObjectClassContentProposal ) + { + return BrowserCommonActivator.getDefault().getImage( BrowserCommonConstants.IMG_OCD ); + } + else if ( element instanceof KeywordContentProposal ) + { + return OpenLdapAclEditorPlugin.getDefault().getImage( OpenLdapAclEditorPluginConstants.IMG_KEYWORD ); + } + + return super.getImage( element ); + } + }; + + /** The verify listener which doesn't allow white spaces*/ + private VerifyListener verifyListener = new VerifyListener() + { + public void verifyText( VerifyEvent e ) + { + // Not allowing white spaces + if ( Character.isWhitespace( e.character ) ) + { + e.doit = false; + } + } + }; + + /** The modify listener */ + private ModifyListener modifyListener = new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + notifyListeners(); + } + }; + + + /** + * Creates the widget. + * + * @param parent the parent + */ + public void createWidget( Composite parent ) + { + // Combo + attributesCombo = BaseWidgetUtils.createCombo( parent, new String[0], -1, 1 ); + GridData gd = new GridData( GridData.FILL_HORIZONTAL ); + gd.horizontalSpan = 1; + gd.widthHint = 200; + attributesCombo.setLayoutData( gd ); + attributesCombo.addVerifyListener( verifyListener ); + + // Content assist + proposalProvider = new AttributesWidgetContentProposalProvider(); + proposalAdapter = new ContentProposalAdapter( attributesCombo, new ComboContentAdapter(), + proposalProvider, KeyStroke.getInstance( SWT.CTRL, SWT.SPACE ), new char[0] ); + proposalProvider.setProposalAdapter( proposalAdapter ); + proposalAdapter.setLabelProvider( labelProvider ); + + // History + String[] history = HistoryUtils.load( OpenLdapAclEditorPlugin.getDefault().getDialogSettings(), + OpenLdapAclEditorPluginConstants.DIALOGSETTING_KEY_ATTRIBUTES_HISTORY ); + for ( int i = 0; i < history.length; i++ ) + { + history[i] = history[i]; + } + attributesCombo.setItems( history ); + attributesCombo.setText( arrayToString( initialAttributes ) ); + attributesCombo.addModifyListener( modifyListener ); + } + + + /** + * Sets the initial attributes. + * + * @param initialAttributes the initial attributes + */ + public void setInitialAttributes( String[] initialAttributes ) + { + this.initialAttributes = initialAttributes; + attributesCombo.setText( arrayToString( initialAttributes ) ); + } + + + /** + * @param browserConnection the browser connection to set + */ + public void setBrowserConnection( IBrowserConnection browserConnection ) + { + proposalProvider.setBrowserConnection( browserConnection ); + } + + + /** + * Sets the enabled state of the widget. + * + * @param b true to enable the widget, false to disable the widget + */ + public void setEnabled( boolean b ) + { + attributesCombo.setEnabled( b ); + } + + + /** + * Gets the attributes. + * + * @return the attributes + */ + public String[] getAttributes() + { + String s = attributesCombo.getText(); + return stringToArray( s ); + } + + + /** + * Saves widget settings. + */ + public void saveWidgetSettings() + { + HistoryUtils.save( OpenLdapAclEditorPlugin.getDefault().getDialogSettings(), + OpenLdapAclEditorPluginConstants.DIALOGSETTING_KEY_ATTRIBUTES_HISTORY, + arrayToString( getAttributes() ) ); + } + + + /** + * Splits the given string into an array. Only the following + * characters are kept, all other are used to split the string + * and are truncated: + *
  • a-z + *
  • A-Z + *
  • 0-9 + *
  • - + *
  • . + *
  • ; + *
  • _ + *
  • * + *
  • + + *
  • @ + *
  • ! + * + * @param s the string to split + * + * @return the array with the splitted string, or null + */ + public static String[] stringToArray( String s ) + { + if ( s == null ) + { + return null; + } + else + { + List attributeList = new ArrayList(); + + StringBuffer temp = new StringBuffer(); + for ( int i = 0; i < s.length(); i++ ) + { + char c = s.charAt( i ); + + if ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || ( c >= '0' && c <= '9' ) || c == '-' + || c == '.' || c == ';' || c == '_' || c == '*' || c == '+' || c == '@' || c == '!' ) + { + temp.append( c ); + } + else + { + if ( temp.length() > 0 ) + { + attributeList.add( temp.toString() ); + temp = new StringBuffer(); + } + } + } + if ( temp.length() > 0 ) + { + attributeList.add( temp.toString() ); + } + + return ( String[] ) attributeList.toArray( new String[attributeList.size()] ); + } + } + + + public static String arrayToString( String[] array ) + { + if ( array == null || array.length == 0 ) + { + return ""; + } + else + { + StringBuffer sb = new StringBuffer( array[0] ); + for ( int i = 1; i < array.length; i++ ) + { + sb.append( "," ); + sb.append( array[i] ); + } + return sb.toString(); + } + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposal.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposal.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposal.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposal.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.widgets; + + +import org.eclipse.jface.fieldassist.ContentProposal; + + +/** + * An abstract content proposal for the attributes widget. + */ +public abstract class AttributesWidgetContentProposal extends ContentProposal +{ + /** The start position */ + private int startPosition = 0; + + + /** + * Creates a new instance of AttributeWidgetContentProposal. + * + * @param content the String representing the content. Should not be null. + */ + public AttributesWidgetContentProposal( String content ) + { + super( content ); + } + + + /** + * @return the startPosition + */ + public int getStartPosition() + { + return startPosition; + } + + + /** + * @param startPosition the startPosition to set + */ + public void setStartPosition( int startPosition ) + { + this.startPosition = startPosition; + } + + + /** + * {@inheritDoc} + */ + public String getContent() + { + String content = super.getContent(); + if ( content != null ) + { + return content.substring( startPosition ); + } + + return null; + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposalProvider.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposalProvider.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposalProvider.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/AttributesWidgetContentProposalProvider.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,268 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.widgets; + + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.apache.directory.studio.ldapbrowser.core.model.IBrowserConnection; +import org.apache.directory.studio.ldapbrowser.core.model.schema.SchemaUtils; +import org.eclipse.jface.fieldassist.ContentProposalAdapter; +import org.eclipse.jface.fieldassist.IContentProposal; +import org.eclipse.jface.fieldassist.IContentProposalProvider; + + +public class AttributesWidgetContentProposalProvider implements IContentProposalProvider +{ + /** The content proposal adapter */ + private ContentProposalAdapter proposalAdapter; + + /** The browser connection */ + private IBrowserConnection browserConnection; + + /** The proposals */ + private List proposals; + + + public AttributesWidgetContentProposalProvider() + { + // Initializing the proposals list + proposals = new ArrayList(); + + // Building the proposals list + buildProposals(); + } + + + public IContentProposal[] getProposals( String contents, int position ) + { + String value = getCurrentValue( contents, position ); + + List matchingProposals = new ArrayList(); + for ( AttributesWidgetContentProposal proposal : proposals ) + { + if ( proposal.getLabel().toUpperCase().startsWith( value.toUpperCase() ) ) + { + matchingProposals.add( proposal ); + proposal.setStartPosition( value.length() ); + } + } + + return matchingProposals.toArray( new AttributesWidgetContentProposal[0] ); + } + + + /** + * {@inheritDoc} + */ + public char[] getAutoActivationCharacters() + { + return new char[0]; + } + + + /** + * Gets the current value. + * + * @param contents the contents + * @param position the position + * @return the current value + */ + private String getCurrentValue( String contents, int position ) + { + int start = 0; + + for ( int i = position - 1; i >= 0; i-- ) + { + char c = contents.charAt( i ); + if ( c == ',' || Character.isWhitespace( c ) ) + { + start = i + 1; + break; + } + } + + return contents.substring( start, position ); + } + + + /** + * Builds the proposals list + */ + private void buildProposals() + { + // Reseting previous proposals + proposals.clear(); + + // Adding proposals + addKeywordProposals(); + addConnectionProposals(); + + // Sorting the proposals + sortProposals(); + + // Setting auto-activation characters + setAutoActivationChars(); + } + + + /** + * Sets the auto-activation characters + */ + private void setAutoActivationChars() + { + if ( proposalAdapter != null ) + { + Set characterSet = new HashSet(); + for ( IContentProposal proposal : proposals ) + { + String string = proposal.getLabel(); + for ( int k = 0; k < string.length(); k++ ) + { + char ch = string.charAt( k ); + characterSet.add( Character.toLowerCase( ch ) ); + characterSet.add( Character.toUpperCase( ch ) ); + } + } + + char[] autoActivationCharacters = new char[characterSet.size() + 1]; + autoActivationCharacters[0] = ','; + int i = 1; + for ( Iterator it = characterSet.iterator(); it.hasNext(); ) + { + Character ch = it.next(); + autoActivationCharacters[i] = ch.charValue(); + i++; + } + + proposalAdapter.setAutoActivationCharacters( autoActivationCharacters ); + } + } + + + /** + * Adding the keyword proposals + */ + private void addKeywordProposals() + { + proposals.add( new KeywordContentProposal( "entry" ) ); + proposals.add( new KeywordContentProposal( "children" ) ); + } + + + /** + * Adding the connection proposals (attribute types and object classes). + */ + private void addConnectionProposals() + { + if ( browserConnection != null ) + { + // Attribute types + Collection atNames = SchemaUtils.getNames( browserConnection.getSchema().getAttributeTypeDescriptions() ); + for ( String atName : atNames ) + { + proposals.add( new AttributeTypeContentProposal( atName ) ); + } + + // Object classes + Collection ocNames = SchemaUtils.getNames( browserConnection.getSchema().getObjectClassDescriptions() ); + for ( String ocName : ocNames ) + { + proposals.add( new ObjectClassContentProposal( "@" + ocName ) ); + proposals.add( new ObjectClassContentProposal( "!" + ocName ) ); + } + } + } + + + /** + * Sorts the proposals. + */ + private void sortProposals() + { + Comparator comparator = new Comparator() + { + public int compare( AttributesWidgetContentProposal o1, AttributesWidgetContentProposal o2 ) + { + if ( ( o1 instanceof KeywordContentProposal ) && !( o2 instanceof KeywordContentProposal ) ) + { + return -2; + } + else if ( !( o1 instanceof KeywordContentProposal ) && ( o2 instanceof KeywordContentProposal ) ) + { + return 2; + } + + else if ( ( o1 instanceof AttributeTypeContentProposal ) + && !( o2 instanceof AttributeTypeContentProposal ) ) + { + return -3; + } + else if ( !( o1 instanceof AttributeTypeContentProposal ) + && ( o2 instanceof AttributeTypeContentProposal ) ) + { + return 3; + } + + else if ( ( o1 instanceof ObjectClassContentProposal ) + && !( o2 instanceof ObjectClassContentProposal ) ) + { + return -3; + } + else if ( !( o1 instanceof ObjectClassContentProposal ) + && ( o2 instanceof ObjectClassContentProposal ) ) + { + return 3; + } + + return o1.getLabel().compareToIgnoreCase( o2.getLabel() ); + } + }; + Collections.sort( proposals, comparator ); + } + + + /** + * @param browserConnection the browser connection to set + */ + public void setBrowserConnection( IBrowserConnection browserConnection ) + { + this.browserConnection = browserConnection; + + // Re-building proposals + buildProposals(); + } + + + /** + * @param proposalAdapter the proposalAdapter to set + */ + public void setProposalAdapter( ContentProposalAdapter proposalAdapter ) + { + this.proposalAdapter = proposalAdapter; + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/KeywordContentProposal.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/KeywordContentProposal.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/KeywordContentProposal.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/KeywordContentProposal.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.widgets; + + +/** + * A content proposal for a keyword. + */ +public class KeywordContentProposal extends AttributesWidgetContentProposal +{ + public KeywordContentProposal( String content ) + { + super( content ); + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/ObjectClassContentProposal.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/ObjectClassContentProposal.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/ObjectClassContentProposal.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/ObjectClassContentProposal.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.widgets; + + +/** + * A content proposal for an object class. + */ +public class ObjectClassContentProposal extends AttributesWidgetContentProposal +{ + public ObjectClassContentProposal( String content ) + { + super( content ); + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclSourceEditorComposite.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclSourceEditorComposite.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclSourceEditorComposite.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclSourceEditorComposite.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.widgets; + + +import java.text.ParseException; + +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; + +import org.apache.directory.studio.openldap.config.acl.OpenLdapAclValueWithContext; +import org.apache.directory.studio.openldap.config.acl.model.AclItem; +import org.apache.directory.studio.openldap.config.acl.model.OpenLdapAclParser; +import org.apache.directory.studio.openldap.config.acl.sourceeditor.OpenLdapAclSourceViewerConfiguration; + + +/** + * This composite contains the source editor. + * + * @author Apache Directory Project + */ +public class OpenLdapAclSourceEditorComposite extends Composite +{ + + /** The source editor */ + private SourceViewer sourceEditor; + + /** The source editor configuration. */ + private SourceViewerConfiguration configuration; + + + /** + * Creates a new instance of ACIItemSourceEditorComposite. + * + * @param parent + * @param style + */ + public OpenLdapAclSourceEditorComposite( Composite parent, int style ) + { + super( parent, style ); + setLayout( new FillLayout() ); + + createSourceEditor(); + } + + + /** + * Creates and configures the source editor. + * + */ + private void createSourceEditor() + { + // create source editor + sourceEditor = new SourceViewer( this, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL ); + + // setup basic configuration + configuration = new OpenLdapAclSourceViewerConfiguration(); + sourceEditor.configure( configuration ); + + // set text font + Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT ); + sourceEditor.getTextWidget().setFont( font ); + + // setup document + IDocument document = new Document(); + sourceEditor.setDocument( document ); + } + + + /** + * Sets the input to the source editor. + * A syntax check is performed before setting the input, an + * invalid syntax causes a ParseException. + * + * @param input the valid string representation of the ACI item + * @throws ParseException it the syntax check fails. + */ + public void setInput( String input ) throws ParseException + { + OpenLdapAclParser parser = new OpenLdapAclParser(); + parser.parse( input ); + + forceSetInput( input ); + } + + + /** + * Set the input to the source editor without a syntax check. + * + * @param input The string representation of the ACI item, may be invalid + */ + public void forceSetInput( String input ) + { + sourceEditor.getDocument().set( input ); + + // format + IRegion region = new Region( 0, sourceEditor.getDocument().getLength() ); + configuration.getContentFormatter( sourceEditor ).format( sourceEditor.getDocument(), region ); + } + + + /** + * Returns the string representation of the ACI item. + * A syntax check is performed before returning the input, an + * invalid syntax causes a ParseException. + * + * @return the valid string representation of the ACI item + * @throws ParseException it the syntax check fails. + */ + public String getInput() throws ParseException + { + String input = forceGetInput(); + + // strip new lines + input = input.replaceAll( "\\n", " " ); //$NON-NLS-1$ //$NON-NLS-2$ + input = input.replaceAll( "\\r", " " ); //$NON-NLS-1$ //$NON-NLS-2$ + + OpenLdapAclParser parser = new OpenLdapAclParser(); + AclItem aclItem = parser.parse( input ); + + String acl = ""; + if ( aclItem != null ) + { + acl = aclItem.toString(); + } + return acl; + } + + + /** + * Returns the string representation of the ACI item without syntax check. + * In other words only the text in the source editor is returned. + * + * @return the string representation of the ACI item, may be invalid + */ + public String forceGetInput() + { + return sourceEditor.getDocument().get(); + } + + + /** + * Sets the context. + * + * @param context the context + */ + public void setContext( OpenLdapAclValueWithContext context ) + { + } + + + /** + * Formats the content. + */ + public void format() + { + IRegion region = new Region( 0, sourceEditor.getDocument().getLength() ); + configuration.getContentFormatter( sourceEditor ).format( sourceEditor.getDocument(), region ); + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclTabFolderComposite.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclTabFolderComposite.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclTabFolderComposite.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclTabFolderComposite.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,318 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.widgets; + + +import java.text.ParseException; +import java.util.Arrays; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; + +import org.apache.directory.studio.openldap.config.acl.OpenLdapAclValueWithContext; +import org.apache.directory.studio.openldap.config.acl.model.AclItem; +import org.apache.directory.studio.openldap.config.acl.model.AclWhatClause; +import org.apache.directory.studio.openldap.config.acl.model.AclWhatClauseStar; +import org.apache.directory.studio.openldap.config.acl.model.AclWhoClause; +import org.apache.directory.studio.openldap.config.acl.model.AclWhoClauseStar; + + +/** + * This composite contains the tabs with visual and source editor. + * It also manages the synchronization between these two tabs. + * + * + * @author Apache Directory Project + */ +public class OpenLdapAclTabFolderComposite extends Composite +{ + /** The index of the visual tab */ + public static final int VISUAL_TAB_INDEX = 0; + + /** The index of the source tab */ + public static final int SOURCE_TAB_INDEX = 1; + + /** The tab folder */ + private TabFolder tabFolder; + + /** The visual tab */ + private TabItem visualTab; + + /** The inner container of the visual tab */ + private Composite visualContainer; + + /** The visual editor composite */ + private OpenLdapAclVisualEditorComposite visualComposite; + + /** Tehe source tab */ + private TabItem sourceTab; + + /** The inner container of the visual tab */ + private Composite sourceContainer; + + /** The source editor composite */ + private OpenLdapAclSourceEditorComposite sourceComposite; + + + /** + * Creates a new instance of TabFolderComposite. + * + * @param parent + * @param style + */ + public OpenLdapAclTabFolderComposite( Composite parent, int style ) + { + super( parent, style ); + GridLayout layout = new GridLayout(); + layout.marginWidth = 0; + layout.marginHeight = 0; + setLayout( layout ); + + createTabFolder(); + + createVisualTab(); + + createSourceTab(); + + initListeners(); + } + + + /** + * Initializes the listeners. + * + */ + private void initListeners() + { + tabFolder.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + tabSelected(); + } + } ); + } + + + /** + * Creates the source tab and configures the source editor. + * + */ + private void createSourceTab() + { + // create inner container + sourceContainer = new Composite( tabFolder, SWT.BORDER ); + sourceContainer.setLayout( new FillLayout() ); + + // create source editor + sourceComposite = new OpenLdapAclSourceEditorComposite( sourceContainer, SWT.NONE ); + + // create tab + sourceTab = new TabItem( tabFolder, SWT.NONE, SOURCE_TAB_INDEX ); + sourceTab.setText( "Source" ); + sourceTab.setControl( sourceContainer ); + } + + + /** + * Creates the visual tab and the GUI editor. + * + */ + private void createVisualTab() + { + // create inner container + visualContainer = new Composite( tabFolder, SWT.NONE ); + visualContainer.setLayout( new GridLayout() ); + visualContainer.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); + + // create the visual ACIItem composite + visualComposite = new OpenLdapAclVisualEditorComposite( visualContainer, SWT.NONE ); + visualComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); + + // create tab + visualTab = new TabItem( tabFolder, SWT.NONE, VISUAL_TAB_INDEX ); + visualTab.setText( "Visual Editor" ); + visualTab.setControl( visualContainer ); + } + + + /** + * Creates the tab folder and the listeners. + * + */ + private void createTabFolder() + { + tabFolder = new TabFolder( this, SWT.TOP ); + tabFolder.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); + } + + + /** + * Called, when a tab is selected. This method manages the synchronization + * between visual and source editor. + */ + private void tabSelected() + { + int index = tabFolder.getSelectionIndex(); + + if ( index == SOURCE_TAB_INDEX ) + { + // switched to source tab: serialize visual and set to source + // on parse error: print message and return to visual tab + // try + // { + // String input = visualComposite.getInput(); + // sourceComposite.setInput( input ); + // } + // catch ( ParseException pe ) + // { + // IStatus status = new Status( IStatus.ERROR, ACIITemConstants.PLUGIN_ID, 1, Messages + // .getString( "ACIItemTabFolderComposite.error.onVisualEditor" ), pe ); //$NON-NLS-1$ + // ErrorDialog.openError( getShell(), + // Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); //$NON-NLS-1$ + // tabFolder.setSelection( VISUAL_TAB_INDEX ); + // } + } + else if ( index == VISUAL_TAB_INDEX ) + { + // switched to visual tab: parse source and populate to visual + // on parse error: print message and return to source tab + // try + // { + // String input = sourceComposite.getInput(); + // visualComposite.setInput( input ); + // } + // catch ( ParseException pe ) + // { + // IStatus status = new Status( IStatus.ERROR, ACIITemConstants.PLUGIN_ID, 1, Messages + // .getString( "ACIItemTabFolderComposite.error.onSourceEditor" ), pe ); //$NON-NLS-1$ + // ErrorDialog.openError( getShell(), + // Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); //$NON-NLS-1$ + // tabFolder.setSelection( SOURCE_TAB_INDEX ); + // } + } + } + + + /** + * Sets the input to both the source editor and to the visual editor. + * If the syntax is invalid the source editor is activated. + * + * @param input The string representation of the ACI item + */ + public void setInput( String input ) + { + // Checking if the input is null or empty + if ( ( input == null ) || ( "".equals( input ) ) ) + { + // Creating a default ACL instead + AclItem defaultAcl = new AclItem( new AclWhatClause( new AclWhatClauseStar() ), + Arrays.asList( new AclWhoClause[] + { new AclWhoClauseStar() } ) ); + + // Assiging the default ACL as input + input = defaultAcl.toString(); + } + + // Setting the input to the source editor + sourceComposite.forceSetInput( input ); + + // Setting the input to the visual editor, on parse error switch to source editor + try + { + visualComposite.setInput( input ); + } + catch ( ParseException e ) + { + // IStatus status = new Status( IStatus.ERROR, ACIITemConstants.PLUGIN_ID, 1, Messages + // .getString( "ACIItemTabFolderComposite.error.onInput" ), pe ); //$NON-NLS-1$ + // ErrorDialog.openError( getShell(), + // Messages.getString( "ACIItemTabFolderComposite.error.title" ), null, status ); //$NON-NLS-1$ + // + tabFolder.setSelection( SOURCE_TAB_INDEX ); + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + /** + * Returns the string representation of the ACI item. + * A syntax check is performed before returning the input, an + * invalid syntax causes a ParseException. + * + * @return the valid string representation of the ACI item + * @throws ParseException it the syntax check fails. + */ + public String getInput() throws ParseException + { + int index = tabFolder.getSelectionIndex(); + if ( index == VISUAL_TAB_INDEX ) + { + String input = visualComposite.getInput(); + return input; + } + else + { + String input = sourceComposite.getInput(); + return input; + } + } + + + /** + * Sets the context. + * + * @param context the context + */ + public void setContext( OpenLdapAclValueWithContext context ) + { + sourceComposite.setContext( context ); + visualComposite.setContext( context ); + } + + + /** + * Formats the content. + */ + public void format() + { + if ( tabFolder.getSelectionIndex() == SOURCE_TAB_INDEX ) + { + sourceComposite.format(); + } + } + + + /** + * Saves widget settings. + */ + public void saveWidgetSettings() + { + visualComposite.saveWidgetSettings(); + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclVisualEditorComposite.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclVisualEditorComposite.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclVisualEditorComposite.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclVisualEditorComposite.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.widgets; + + +import java.text.ParseException; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; + +import org.apache.directory.studio.openldap.config.acl.OpenLdapAclValueWithContext; +import org.apache.directory.studio.openldap.config.acl.model.AclItem; +import org.apache.directory.studio.openldap.config.acl.model.AclWhatClause; +import org.apache.directory.studio.openldap.config.acl.model.AclWhatClauseStar; +import org.apache.directory.studio.openldap.config.acl.model.OpenLdapAclParser; + + +/** + * This is the main widget of the OpenLDAP ACL visual editor. + *

    + * It extends ScrolledComposite. + */ +public class OpenLdapAclVisualEditorComposite extends ScrolledComposite +{ + private OpenLdapAclVisualEditorComposite instance; + + /** The ACL */ + private AclItem acl; + + // UI widgets + private OpenLdapAclWhatClauseWidget whatClauseWidget; + private OpenLdapAclWhoClausesBuilderWidget whoClausesBuilderWidget; + + + /** + * Creates a new instance of OpenLdapAclVisualEditorComposite. + * + * @param parent a widget which will be the parent of the new instance (cannot be null) + * @param style the style of widget to construct + */ + public OpenLdapAclVisualEditorComposite( Composite parent, int style ) + { + super( parent, style | SWT.H_SCROLL | SWT.V_SCROLL ); + + // Creating the composite + Composite composite = new Composite( this, SWT.NONE ); + composite.setLayout( new GridLayout() ); + composite.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); + + // Creating the widgets + createWhatClauseWidget( composite ); + createWhoClausesWidget( composite ); + + // Configuring the composite + setContent( composite ); + setExpandHorizontal( true ); + setExpandVertical( true ); + setMinSize( composite.computeSize( SWT.DEFAULT, SWT.DEFAULT ) ); + + instance = this; + } + + + /** + * Creates the "What" clause widget. + * + * @param parent the parent composite + */ + private void createWhatClauseWidget( Composite parent ) + { + whatClauseWidget = new OpenLdapAclWhatClauseWidget( this ); + whatClauseWidget.create( parent ); + } + + + /** + * Creates the "Who" clauses widget. + * + * @param parent the parent composite + */ + private void createWhoClausesWidget( Composite parent ) + { + whoClausesBuilderWidget = new OpenLdapAclWhoClausesBuilderWidget( this ); + whoClausesBuilderWidget.create( parent ); + } + + + /** + * Sets the input. The given ACI Item string is parsed and + * populated to the GUI elements. + * + * + * @param input The string representation of the ACI item + * @throws ParseException if the syntax is invalid + */ + public void setInput( String input ) throws ParseException + { + // Reseting the previous input + acl = null; + + // Parsing the input string + OpenLdapAclParser parser = new OpenLdapAclParser(); + acl = parser.parse( input ); + + // Setting the input ACL to the widgets + whatClauseWidget.setInput( acl.getWhatClause() ); + whoClausesBuilderWidget.setInput( acl.getWhoClauses() ); + } + + + /** + * Returns the string representation of the ACI item as defined in GUI. + * + * + * @return the string representation of the ACI item + * @throws ParseException if the syntax is invalid + */ + public String getInput() throws ParseException + { + AclItem aclItem = new AclItem( whatClauseWidget.getClause(), whoClausesBuilderWidget.getClauses() ); + return aclItem.toString(); + } + + + /** + * Sets the context. + * + * @param context the context + */ + public void setContext( OpenLdapAclValueWithContext context ) + { + whatClauseWidget.setContext( context ); + whoClausesBuilderWidget.setContext( context ); + } + + + /** + * Saves widget settings. + */ + public void saveWidgetSettings() + { + whatClauseWidget.saveWidgetSettings(); + } +} Added: directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclWhatClauseWidget.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclWhatClauseWidget.java?rev=1670931&view=auto ============================================================================== --- directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclWhatClauseWidget.java (added) +++ directory/studio/trunk/plugins/openldap.acl.editor/src/main/java/org/apache/directory/studio/openldap/config/acl/widgets/OpenLdapAclWhatClauseWidget.java Thu Apr 2 16:14:26 2015 @@ -0,0 +1,347 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.studio.openldap.config.acl.widgets; + + +import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils; +import org.apache.directory.studio.ldapbrowser.common.widgets.BrowserWidget; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; + +import org.apache.directory.studio.openldap.config.acl.OpenLdapAclValueWithContext; +import org.apache.directory.studio.openldap.config.acl.model.AclWhatClause; +import org.apache.directory.studio.openldap.config.acl.model.AclWhatClauseAttributes; +import org.apache.directory.studio.openldap.config.acl.model.AclWhatClauseDn; +import org.apache.directory.studio.openldap.config.acl.model.AclWhatClauseFilter; +import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhatClauseAttributesComposite; +import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhatClauseDnComposite; +import org.apache.directory.studio.openldap.config.acl.widgets.composites.WhatClauseFilterComposite; + + +public class OpenLdapAclWhatClauseWidget extends BrowserWidget +{ + /** The visual editor composite */ + private OpenLdapAclVisualEditorComposite visualEditorComposite; + + /** The context */ + private OpenLdapAclValueWithContext context; + + /** The what clause */ + private AclWhatClause clause; + + // UI widgets + private Composite composite; + private Button dnCheckbox; + private Composite dnComposite; + private Composite dnSubComposite; + private Button filterCheckbox; + private Composite filterComposite; + private Composite filterSubComposite; + private Button attributesCheckbox; + private Composite attributesComposite; + private Composite attributesSubComposite; + + // Listeners + private SelectionAdapter dnCheckboxListener = new SelectionAdapter() + { + public void widgetSelected( org.eclipse.swt.events.SelectionEvent e ) + { + if ( dnCheckbox.getSelection() ) + { + createDnComposite(); + } + else + { + disposeComposite( dnSubComposite ); + } + + // Refreshing the layout of the whole composite + visualEditorComposite.layout( true, true ); + } + }; + private SelectionAdapter filterCheckboxListener = new SelectionAdapter() + { + public void widgetSelected( org.eclipse.swt.events.SelectionEvent e ) + { + if ( filterCheckbox.getSelection() ) + { + createFilterComposite(); + } + else + { + disposeComposite( filterSubComposite ); + } + + // Refreshing the layout of the whole composite + visualEditorComposite.layout( true, true ); + } + }; + private SelectionAdapter attributesCheckboxListener = new SelectionAdapter() + { + public void widgetSelected( org.eclipse.swt.events.SelectionEvent e ) + { + if ( attributesCheckbox.getSelection() ) + { + createAttributesComposite(); + } + else + { + disposeComposite( attributesSubComposite ); + } + + // Refreshing the layout of the whole composite + visualEditorComposite.layout( true, true ); + } + }; + + private WhatClauseAttributesComposite attributesClauseComposite; + + private WhatClauseFilterComposite filterClauseComposite; + + private WhatClauseDnComposite dnClauseComposite; + + + /** + * Creates a new instance of OpenLdapAclWhatClauseWidget. + * + * @param visualEditorComposite the visual editor composite + */ + public OpenLdapAclWhatClauseWidget( OpenLdapAclVisualEditorComposite visualEditorComposite ) + { + this.visualEditorComposite = visualEditorComposite; + } + + + public void create( Composite parent ) + { + // Creating the widget base composite + composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); + + // Creating the what group + Group whatGroup = BaseWidgetUtils.createGroup( parent, "Acces to \"What\"", 1 ); + whatGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); + + // DN + dnCheckbox = BaseWidgetUtils.createCheckbox( whatGroup, "DN", 1 ); + dnComposite = BaseWidgetUtils.createColumnContainer( whatGroup, 1, 1 ); + + // Filter + filterCheckbox = BaseWidgetUtils.createCheckbox( whatGroup, "Filter", 1 ); + filterComposite = BaseWidgetUtils.createColumnContainer( whatGroup, 1, 1 ); + + // Attributes + attributesCheckbox = BaseWidgetUtils.createCheckbox( whatGroup, "Attributes", 1 ); + attributesComposite = BaseWidgetUtils.createColumnContainer( whatGroup, 1, 1 ); + + // Adding the listeners to the UI widgets + addListeners(); + } + + + /** + * Creates the DN composite. + */ + private void createDnComposite() + { + Group dnGroup = BaseWidgetUtils.createGroup( dnComposite, "", 1 ); + dnGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); + dnSubComposite = dnGroup; + + dnClauseComposite = new WhatClauseDnComposite( visualEditorComposite ); + dnClauseComposite.createComposite( dnGroup ); + + if ( clause.getDnClause() != null ) + { + dnClauseComposite.setClause( clause.getDnClause() ); + } + + if ( context != null ) + { + dnClauseComposite.setConnection( context.getConnection() ); + } + } + + + /** + * Creates the filter composite. + */ + private void createFilterComposite() + { + Group filterGroup = BaseWidgetUtils.createGroup( filterComposite, "", 1 ); + filterGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); + filterSubComposite = filterGroup; + + filterClauseComposite = new WhatClauseFilterComposite( visualEditorComposite ); + filterClauseComposite.createComposite( filterGroup ); + + if ( clause.getFilterClause() != null ) + { + filterClauseComposite.setClause( clause.getFilterClause() ); + } + + if ( context != null ) + { + filterClauseComposite.setConnection( context.getConnection() ); + } + } + + + /** + * Creates the attributes composite. + */ + private void createAttributesComposite() + { + Group attributesGroup = BaseWidgetUtils.createGroup( attributesComposite, "", 1 ); + attributesGroup.setLayoutData( new GridData( SWT.FILL, SWT.NONE, true, false ) ); + attributesSubComposite = attributesGroup; + + attributesClauseComposite = new WhatClauseAttributesComposite( visualEditorComposite ); + attributesClauseComposite.createComposite( attributesGroup ); + + if ( clause.getAttributesClause() != null ) + { + attributesClauseComposite.setClause( clause.getAttributesClause() ); + } + + if ( context != null ) + { + attributesClauseComposite.setConnection( context.getConnection() ); + } + } + + + /** + * Disposes the given composite. + * + * @param composite the composite + */ + private void disposeComposite( Composite composite ) + { + if ( ( composite != null ) && ( !composite.isDisposed() ) ) + { + composite.dispose(); + } + } + + + /** + * Adds the listeners to the UI widgets. + */ + private void addListeners() + { + dnCheckbox.addSelectionListener( dnCheckboxListener ); + filterCheckbox.addSelectionListener( filterCheckboxListener ); + attributesCheckbox.addSelectionListener( attributesCheckboxListener ); + } + + + /** + * Sets the input. + * + * @param clause the what clause + */ + public void setInput( AclWhatClause clause ) + { + this.clause = clause; + + if ( clause != null ) + { + // DN clause + AclWhatClauseDn dnClause = clause.getDnClause(); + if ( dnClause != null ) + { + dnCheckbox.setSelection( true ); + createDnComposite(); + } + + // Filter clause + AclWhatClauseFilter filterClause = clause.getFilterClause(); + if ( filterClause != null ) + { + filterCheckbox.setSelection( true ); + createFilterComposite(); + } + + // Attributes clause + AclWhatClauseAttributes attributesClause = clause.getAttributesClause(); + if ( attributesClause != null ) + { + attributesCheckbox.setSelection( true ); + createAttributesComposite(); + } + } + } + + + /** + * Sets the context. + * + * @param context the context + */ + public void setContext( OpenLdapAclValueWithContext context ) + { + this.context = context; + + if ( attributesClauseComposite != null ) + { + attributesClauseComposite.setConnection( context.getConnection() ); + } + } + + + /** + * Gets the what clause. + * + * @return the what clause + */ + public AclWhatClause getClause() + { + return clause; + } + + + /** + * Disposes all created SWT widgets. + */ + public void dispose() + { + // Composite + if ( ( composite != null ) && ( !composite.isDisposed() ) ) + { + composite.dispose(); + } + } + + + /** + * Saves widget settings. + */ + public void saveWidgetSettings() + { + if ( attributesClauseComposite != null ) + { + attributesClauseComposite.saveWidgetSettings(); + } + } +}