Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 36590 invoked from network); 9 Apr 2007 09:50:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Apr 2007 09:50:54 -0000 Received: (qmail 74712 invoked by uid 500); 9 Apr 2007 09:51:01 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 74662 invoked by uid 500); 9 Apr 2007 09:51:00 -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 74648 invoked by uid 99); 9 Apr 2007 09:51:00 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Apr 2007 02:51:00 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Apr 2007 02:50:51 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id CF8CF1A9850; Mon, 9 Apr 2007 02:50:04 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r526693 [6/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... Date: Mon, 09 Apr 2007 09:49:57 -0000 To: commits@directory.apache.org From: seelmann@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070409095004.CF8CF1A9850@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/BinaryAttributesAndSyntaxesPreferencePage.java URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/BinaryAttributesAndSyntaxesPreferencePage.java?view=auto&rev=526693 ============================================================================== --- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/BinaryAttributesAndSyntaxesPreferencePage.java (added) +++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/BinaryAttributesAndSyntaxesPreferencePage.java Mon Apr 9 02:49:48 2007 @@ -0,0 +1,538 @@ +/* + * 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.dialogs.preferences; + + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; +import org.apache.directory.ldapstudio.browser.core.ConnectionManager; +import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin; +import org.apache.directory.ldapstudio.browser.core.model.IConnection; +import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription; +import org.apache.directory.ldapstudio.browser.core.model.schema.BinaryAttribute; +import org.apache.directory.ldapstudio.browser.core.model.schema.BinarySyntax; +import org.apache.directory.ldapstudio.browser.core.model.schema.LdapSyntaxDescription; +import org.apache.directory.ldapstudio.browser.core.model.schema.Schema; + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + + +public class BinaryAttributesAndSyntaxesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage +{ + + private SortedMap attributeOid2AtdMap; + + private SortedMap attributeNames2AtdMap; + + private String[] attributeNamesAndOids; + + private SortedMap syntaxOid2LsdMap; + + private SortedMap syntaxDesc2LsdMap; + + private String[] syntaxOids; + + private List attributeList; + + private TableViewer attributeViewer; + + private Button attributeAddButton; + + private Button attributeEditButton; + + private Button attributeRemoveButton; + + private List syntaxList; + + private TableViewer syntaxViewer; + + private Button syntaxAddButton; + + private Button syntaxEditButton; + + private Button syntaxRemoveButton; + + + public BinaryAttributesAndSyntaxesPreferencePage() + { + super(); + super.setDescription( "Specify attributes to handle as binary:" ); + } + + + public void init( IWorkbench workbench ) + { + } + + + protected Control createContents( Composite parent ) + { + + Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); + composite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); + + // init available attribute types + this.attributeNames2AtdMap = new TreeMap(); + this.attributeOid2AtdMap = new TreeMap(); + ConnectionManager cm = BrowserCorePlugin.getDefault().getConnectionManager(); + IConnection[] connections = cm.getConnections(); + for ( int i = 0; i < connections.length; i++ ) + { + Schema schema = connections[i].getSchema(); + if ( schema != null ) + { + createAttributeMaps( schema ); + } + } + createAttributeMaps( Schema.DEFAULT_SCHEMA ); + this.attributeNamesAndOids = new String[this.attributeNames2AtdMap.size() + this.attributeOid2AtdMap.size()]; + System.arraycopy( this.attributeNames2AtdMap.keySet().toArray(), 0, this.attributeNamesAndOids, 0, + this.attributeNames2AtdMap.size() ); + System.arraycopy( this.attributeOid2AtdMap.keySet().toArray(), 0, this.attributeNamesAndOids, + this.attributeNames2AtdMap.size(), this.attributeOid2AtdMap.size() ); + + // init available syntaxes + this.syntaxOid2LsdMap = new TreeMap(); + this.syntaxDesc2LsdMap = new TreeMap(); + for ( int i = 0; i < connections.length; i++ ) + { + Schema schema = connections[i].getSchema(); + if ( schema != null ) + { + createSyntaxMaps( schema ); + } + } + createSyntaxMaps( Schema.DEFAULT_SCHEMA ); + this.syntaxOids = new String[this.syntaxOid2LsdMap.size()]; + System + .arraycopy( this.syntaxOid2LsdMap.keySet().toArray(), 0, this.syntaxOids, 0, this.syntaxOid2LsdMap.size() ); + + // create attribute contents + BaseWidgetUtils.createSpacer( composite, 1 ); + BaseWidgetUtils.createSpacer( composite, 1 ); + createAttributeContents( composite ); + attributeList = new ArrayList( Arrays.asList( BrowserCorePlugin.getDefault().getCorePreferences() + .getBinaryAttributes() ) ); + attributeViewer.setInput( this.attributeList ); + attributeViewer.getTable().getColumn( 0 ).pack(); + // attributeViewer.getTable().getColumn(1).pack(); + attributeViewer.getTable().pack(); + + // create syntax contents + BaseWidgetUtils.createSpacer( composite, 1 ); + BaseWidgetUtils.createSpacer( composite, 1 ); + createSyntaxContents( composite ); + syntaxList = new ArrayList( Arrays.asList( BrowserCorePlugin.getDefault().getCorePreferences() + .getBinarySyntaxes() ) ); + syntaxViewer.setInput( this.syntaxList ); + syntaxViewer.getTable().getColumn( 0 ).pack(); + // syntaxViewer.getTable().getColumn(1).pack(); + syntaxViewer.getTable().pack(); + + return composite; + } + + + private void createAttributeMaps( Schema schema ) + { + AttributeTypeDescription[] atds = schema.getAttributeTypeDescriptions(); + for ( int i = 0; i < atds.length; i++ ) + { + + attributeOid2AtdMap.put( atds[i].getNumericOID(), atds[i] ); + + String[] names = atds[i].getNames(); + for ( int j = 0; j < names.length; j++ ) + { + attributeNames2AtdMap.put( names[j], atds[i] ); + } + + } + } + + + private void createSyntaxMaps( Schema schema ) + { + LdapSyntaxDescription[] lsds = schema.getLdapSyntaxDescriptions(); + for ( int i = 0; i < lsds.length; i++ ) + { + + syntaxOid2LsdMap.put( lsds[i].getNumericOID(), lsds[i] ); + + if ( lsds[i].getDesc() != null ) + { + syntaxDesc2LsdMap.put( lsds[i].getDesc(), lsds[i] ); + } + + } + } + + + private void createAttributeContents( Composite parent ) + { + + BaseWidgetUtils.createLabel( parent, "Binary Attributes", 1 ); + + Composite composite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 ); + composite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); + Composite listComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); + listComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); + Composite buttonComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); + buttonComposite.setLayoutData( new GridData( GridData.VERTICAL_ALIGN_BEGINNING ) ); + + Table table = new Table( listComposite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION ); + GridData data = new GridData( GridData.FILL_BOTH ); + data.widthHint = 360; + data.heightHint = convertHeightInCharsToPixels( 10 ); + table.setLayoutData( data ); + table.setHeaderVisible( true ); + table.setLinesVisible( true ); + attributeViewer = new TableViewer( table ); + + TableColumn c1 = new TableColumn( table, SWT.NONE ); + c1.setText( "Attribute" ); + c1.setWidth( 300 ); + TableColumn c2 = new TableColumn( table, SWT.NONE ); + c2.setText( "Alias" ); + c2.setWidth( 60 ); + + attributeViewer.setColumnProperties( new String[] + { "Attribute" } ); + attributeViewer.setContentProvider( new ArrayContentProvider() ); + attributeViewer.setLabelProvider( new AttributeLabelProvider() ); + + attributeViewer.addDoubleClickListener( new IDoubleClickListener() + { + public void doubleClick( DoubleClickEvent event ) + { + editAttribute(); + } + } ); + + attributeAddButton = BaseWidgetUtils.createButton( buttonComposite, "Add...", 1 ); + attributeAddButton.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + addAttribute(); + } + } ); + attributeEditButton = BaseWidgetUtils.createButton( buttonComposite, "Edit...", 1 ); + attributeEditButton.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + editAttribute(); + } + } ); + attributeRemoveButton = BaseWidgetUtils.createButton( buttonComposite, "Remove", 1 ); + attributeRemoveButton.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + removeAttribute(); + } + } ); + + // c1.pack(); + // c2.pack(); + // table.pack(); + } + + + private void createSyntaxContents( Composite parent ) + { + + BaseWidgetUtils.createLabel( parent, "Binary Syntaxes", 1 ); + + Composite composite = BaseWidgetUtils.createColumnContainer( parent, 2, 1 ); + composite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); + Composite listComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); + listComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); + Composite buttonComposite = BaseWidgetUtils.createColumnContainer( composite, 1, 1 ); + buttonComposite.setLayoutData( new GridData( GridData.VERTICAL_ALIGN_BEGINNING ) ); + + Table table = new Table( listComposite, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION ); + GridData data = new GridData( GridData.FILL_BOTH ); + data.widthHint = 360; + data.heightHint = convertHeightInCharsToPixels( 10 ); + table.setLayoutData( data ); + table.setHeaderVisible( true ); + table.setLinesVisible( true ); + syntaxViewer = new TableViewer( table ); + + TableColumn c1 = new TableColumn( table, SWT.NONE ); + c1.setText( "Syntax" ); + c1.setWidth( 300 ); + TableColumn c2 = new TableColumn( table, SWT.NONE ); + c2.setText( "Desc" ); + c2.setWidth( 60 ); + + syntaxViewer.setColumnProperties( new String[] + { "Syntax" } ); + syntaxViewer.setContentProvider( new ArrayContentProvider() ); + syntaxViewer.setLabelProvider( new SyntaxLabelProvider() ); + + syntaxViewer.addDoubleClickListener( new IDoubleClickListener() + { + public void doubleClick( DoubleClickEvent event ) + { + editSyntax(); + } + } ); + + syntaxAddButton = BaseWidgetUtils.createButton( buttonComposite, "Add...", 1 ); + syntaxAddButton.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + addSyntax(); + } + } ); + syntaxEditButton = BaseWidgetUtils.createButton( buttonComposite, "Edit...", 1 ); + syntaxEditButton.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + editSyntax(); + } + } ); + syntaxRemoveButton = BaseWidgetUtils.createButton( buttonComposite, "Remove", 1 ); + syntaxRemoveButton.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + removeSyntax(); + } + } ); + + // c1.pack(); + // c2.pack(); + // table.pack(); + } + + + protected void addAttribute() + { + AttributeDialog dialog = new AttributeDialog( getShell(), null, this.attributeNamesAndOids ); + if ( dialog.open() == AttributeValueEditorDialog.OK ) + { + this.attributeList.add( dialog.getAttribute() ); + this.attributeViewer.refresh(); + } + } + + + protected void removeAttribute() + { + Object o = ( ( StructuredSelection ) this.attributeViewer.getSelection() ).getFirstElement(); + this.attributeList.remove( o ); + this.attributeViewer.refresh(); + } + + + protected void editAttribute() + { + StructuredSelection sel = ( StructuredSelection ) this.attributeViewer.getSelection(); + if ( !sel.isEmpty() ) + { + BinaryAttribute attribute = ( BinaryAttribute ) sel.getFirstElement(); + AttributeDialog dialog = new AttributeDialog( getShell(), attribute, this.attributeNamesAndOids ); + if ( dialog.open() == AttributeValueEditorDialog.OK ) + { + int index = this.attributeList.indexOf( attribute ); + this.attributeList.set( index, dialog.getAttribute() ); + this.attributeViewer.refresh(); + } + } + } + + + protected void addSyntax() + { + SyntaxDialog dialog = new SyntaxDialog( getShell(), null, this.syntaxOids ); + if ( dialog.open() == SyntaxValueEditorDialog.OK ) + { + this.syntaxList.add( dialog.getSyntax() ); + this.syntaxViewer.refresh(); + } + } + + + protected void removeSyntax() + { + Object o = ( ( StructuredSelection ) this.syntaxViewer.getSelection() ).getFirstElement(); + this.syntaxList.remove( o ); + this.syntaxViewer.refresh(); + } + + + protected void editSyntax() + { + StructuredSelection sel = ( StructuredSelection ) this.syntaxViewer.getSelection(); + if ( !sel.isEmpty() ) + { + BinarySyntax syntax = ( BinarySyntax ) sel.getFirstElement(); + SyntaxDialog dialog = new SyntaxDialog( getShell(), syntax, this.syntaxOids ); + if ( dialog.open() == SyntaxValueEditorDialog.OK ) + { + int index = this.syntaxList.indexOf( syntax ); + this.syntaxList.set( index, dialog.getSyntax() ); + this.syntaxViewer.refresh(); + } + } + } + + + public boolean performOk() + { + BinaryAttribute[] attributes = ( BinaryAttribute[] ) this.attributeList + .toArray( new BinaryAttribute[this.attributeList.size()] ); + BrowserCorePlugin.getDefault().getCorePreferences().setBinaryAttributes( attributes ); + + BinarySyntax[] syntaxes = ( BinarySyntax[] ) this.syntaxList.toArray( new BinarySyntax[this.syntaxList.size()] ); + BrowserCorePlugin.getDefault().getCorePreferences().setBinarySyntaxes( syntaxes ); + + return true; + } + + + protected void performDefaults() + { + this.attributeList.clear(); + this.attributeList.addAll( Arrays.asList( BrowserCorePlugin.getDefault().getCorePreferences() + .getDefaultBinaryAttributes() ) ); + this.attributeViewer.refresh(); + + this.syntaxList.clear(); + this.syntaxList.addAll( Arrays.asList( BrowserCorePlugin.getDefault().getCorePreferences() + .getDefaultBinarySyntaxes() ) ); + this.syntaxViewer.refresh(); + + super.performDefaults(); + } + + class AttributeLabelProvider extends LabelProvider implements ITableLabelProvider + { + public String getColumnText( Object obj, int index ) + { + if ( obj instanceof BinaryAttribute ) + { + BinaryAttribute attribute = ( BinaryAttribute ) obj; + if ( index == 0 ) + { + return attribute.getAttributeNumericOidOrName(); + } + else if ( index == 1 ) + { + if ( attribute.getAttributeNumericOidOrName() != null ) + { + if ( attributeNames2AtdMap.containsKey( attribute.getAttributeNumericOidOrName() ) ) + { + AttributeTypeDescription atd = ( AttributeTypeDescription ) attributeNames2AtdMap + .get( attribute.getAttributeNumericOidOrName() ); + String s = atd.getNumericOID(); + for ( int i = 0; i < atd.getNames().length; i++ ) + { + if ( !attribute.getAttributeNumericOidOrName().equals( atd.getNames()[i] ) ) + { + s += ", " + atd.getNames()[i]; + } + } + return s; + } + else if ( attributeOid2AtdMap.containsKey( attribute.getAttributeNumericOidOrName() ) ) + { + AttributeTypeDescription atd = ( AttributeTypeDescription ) attributeOid2AtdMap + .get( attribute.getAttributeNumericOidOrName() ); + return atd.toString(); + } + } + } + } + return null; + } + + + public Image getColumnImage( Object obj, int index ) + { + return null; + } + } + + class SyntaxLabelProvider extends LabelProvider implements ITableLabelProvider + { + public String getColumnText( Object obj, int index ) + { + if ( obj instanceof BinarySyntax ) + { + BinarySyntax syntax = ( BinarySyntax ) obj; + if ( index == 0 ) + { + return syntax.getSyntaxNumericOid(); + } + else if ( index == 1 ) + { + if ( syntax.getSyntaxNumericOid() != null ) + { + if ( syntaxOid2LsdMap.containsKey( syntax.getSyntaxNumericOid() ) ) + { + LdapSyntaxDescription lsd = ( LdapSyntaxDescription ) syntaxOid2LsdMap.get( syntax + .getSyntaxNumericOid() ); + return lsd.toString(); + } + } + } + } + return null; + } + + + public Image getColumnImage( Object obj, int index ) + { + return null; + } + } +} Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/BrowserPreferencePage.java URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/BrowserPreferencePage.java?view=auto&rev=526693 ============================================================================== --- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/BrowserPreferencePage.java (added) +++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/BrowserPreferencePage.java Mon Apr 9 02:49:48 2007 @@ -0,0 +1,350 @@ +/* + * 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.dialogs.preferences; + + +import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator; +import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants; +import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; +import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants; +import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin; +import org.eclipse.core.runtime.Preferences; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + + +public class BrowserPreferencePage extends PreferencePage implements IWorkbenchPreferencePage +{ + + private static final String DN = "DN"; + + private static final String RDN = "RDN"; + + private static final String RDN_VALUE = "RDN value"; + + private Combo entryLabelCombo; + + private Button entryAbbreviateButton; + + private Text entryAbbreviateMaxLengthText; + + private Combo searchResultLabelCombo; + + private Button searchResultAbbreviateButton; + + private Text searchResultAbbreviateMaxLengthText; + + private Button enableFoldingButton; + + private Label foldingSizeLabel; + + private Text foldingSizeText; + + private Button expandBaseEntriesButton;; + + private Button checkForChildrenButton; + + private Button showAliasAndReferralObjectsButton; + + private Button fetchSubentriesButton; + + + public BrowserPreferencePage() + { + super(); + super.setPreferenceStore( BrowserCommonActivator.getDefault().getPreferenceStore() ); + super.setDescription( "General settings for the LDAP browser view:" ); + } + + + public void init( IWorkbench workbench ) + { + } + + + protected Control createContents( Composite parent ) + { + + Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); + + BaseWidgetUtils.createSpacer( composite, 1 ); + BaseWidgetUtils.createSpacer( composite, 1 ); + Group entryLabelGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ), + "Entry label", 1 ); + + Composite entryLabelComposite = BaseWidgetUtils.createColumnContainer( entryLabelGroup, 3, 1 ); + BaseWidgetUtils.createLabel( entryLabelComposite, "Use ", 1 ); + entryLabelCombo = BaseWidgetUtils.createCombo( entryLabelComposite, new String[] + { DN, RDN, RDN_VALUE }, 0, 1 ); + entryLabelCombo.setLayoutData( new GridData() ); + entryLabelCombo + .select( getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL ) == BrowserCommonConstants.SHOW_RDN_VALUE ? 2 + : getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL ) == BrowserCommonConstants.SHOW_RDN ? 1 + : 0 ); + BaseWidgetUtils.createLabel( entryLabelComposite, " as entry label", 1 ); + + Composite entryAbbreviateComposite = BaseWidgetUtils.createColumnContainer( entryLabelGroup, 3, 1 ); + entryAbbreviateButton = BaseWidgetUtils.createCheckbox( entryAbbreviateComposite, "Limit label length to ", 1 ); + entryAbbreviateButton.setSelection( getPreferenceStore().getBoolean( + BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE ) ); + entryAbbreviateButton.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + updateEnabled(); + } + } ); + entryAbbreviateMaxLengthText = BaseWidgetUtils.createText( entryAbbreviateComposite, getPreferenceStore() + .getString( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH ), 3, 1 ); + entryAbbreviateMaxLengthText.setEnabled( entryAbbreviateButton.getSelection() ); + entryAbbreviateMaxLengthText.addVerifyListener( new VerifyListener() + { + public void verifyText( VerifyEvent e ) + { + if ( !e.text.matches( "[0-9]*" ) ) + { + e.doit = false; + } + if ( "".equals( entryAbbreviateMaxLengthText.getText() ) && e.text.matches( "[0]" ) ) + { + e.doit = false; + } + } + } ); + BaseWidgetUtils.createLabel( entryAbbreviateComposite, " characters", 1 ); + + BaseWidgetUtils.createSpacer( composite, 1 ); + BaseWidgetUtils.createSpacer( composite, 1 ); + Group searchResultLabelGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, + 1, 1 ), "Search result label", 1 ); + + Composite searchResultLabelComposite = BaseWidgetUtils.createColumnContainer( searchResultLabelGroup, 3, 1 ); + BaseWidgetUtils.createLabel( searchResultLabelComposite, "Use ", 1 ); + searchResultLabelCombo = BaseWidgetUtils.createCombo( searchResultLabelComposite, new String[] + { DN, RDN, RDN_VALUE }, 0, 1 ); + searchResultLabelCombo.setLayoutData( new GridData() ); + searchResultLabelCombo + .select( getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL ) == BrowserCommonConstants.SHOW_RDN_VALUE ? 2 + : getPreferenceStore().getInt( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL ) == BrowserCommonConstants.SHOW_RDN ? 1 + : 0 ); + BaseWidgetUtils.createLabel( searchResultLabelComposite, " as search result label", 1 ); + + Composite searchResultAbbreviateComposite = BaseWidgetUtils + .createColumnContainer( searchResultLabelGroup, 3, 1 ); + searchResultAbbreviateButton = BaseWidgetUtils.createCheckbox( searchResultAbbreviateComposite, + "Limit label length to ", 1 ); + searchResultAbbreviateButton.setSelection( getPreferenceStore().getBoolean( + BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE ) ); + searchResultAbbreviateButton.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + updateEnabled(); + } + } ); + searchResultAbbreviateMaxLengthText = BaseWidgetUtils + .createText( searchResultAbbreviateComposite, getPreferenceStore().getString( + BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH ), 3, 1 ); + searchResultAbbreviateMaxLengthText.setEnabled( searchResultAbbreviateButton.getSelection() ); + searchResultAbbreviateMaxLengthText.addVerifyListener( new VerifyListener() + { + public void verifyText( VerifyEvent e ) + { + if ( !e.text.matches( "[0-9]*" ) ) + { + e.doit = false; + } + if ( "".equals( searchResultAbbreviateMaxLengthText.getText() ) && e.text.matches( "[0]" ) ) + { + e.doit = false; + } + } + } ); + BaseWidgetUtils.createLabel( searchResultAbbreviateComposite, " characters", 1 ); + + BaseWidgetUtils.createSpacer( composite, 1 ); + BaseWidgetUtils.createSpacer( composite, 1 ); + Group foldingGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ), + "Folding", 1 ); + Composite pagingGroupComposite = BaseWidgetUtils.createColumnContainer( foldingGroup, 2, 1 ); + enableFoldingButton = BaseWidgetUtils.createCheckbox( pagingGroupComposite, "Enable folding", 2 ); + enableFoldingButton.setSelection( getPreferenceStore().getBoolean( + BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING ) ); + enableFoldingButton.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + updateEnabled(); + } + } ); + foldingSizeLabel = BaseWidgetUtils.createLabel( pagingGroupComposite, "Folding size: ", 1 ); + foldingSizeLabel.setEnabled( enableFoldingButton.getSelection() ); + foldingSizeText = BaseWidgetUtils.createText( pagingGroupComposite, getPreferenceStore().getString( + BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE ), 4, 1 ); + foldingSizeText.setEnabled( enableFoldingButton.getSelection() ); + foldingSizeText.addVerifyListener( new VerifyListener() + { + public void verifyText( VerifyEvent e ) + { + if ( !e.text.matches( "[0-9]*" ) ) + { + e.doit = false; + } + if ( "".equals( foldingSizeText.getText() ) && e.text.matches( "[0]" ) ) + { + e.doit = false; + } + } + } ); + + BaseWidgetUtils.createSpacer( composite, 1 ); + BaseWidgetUtils.createSpacer( composite, 1 ); + expandBaseEntriesButton = BaseWidgetUtils.createCheckbox( composite, + "Expand base entries when opening connection", 1 ); + expandBaseEntriesButton.setSelection( getPreferenceStore().getBoolean( + BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES ) ); + Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences(); + checkForChildrenButton = BaseWidgetUtils.createCheckbox( composite, "Check for children", 1 ); + checkForChildrenButton + .setSelection( coreStore.getBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN ) ); + showAliasAndReferralObjectsButton = BaseWidgetUtils.createCheckbox( composite, + "Show alias and referral objects", 1 ); + showAliasAndReferralObjectsButton.setSelection( coreStore + .getBoolean( BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ) ); + fetchSubentriesButton = BaseWidgetUtils.createCheckbox( composite, + "Fetch subentries (requires additional search request)", 1 ); + fetchSubentriesButton.setSelection( coreStore.getBoolean( BrowserCoreConstants.PREFERENCE_FETCH_SUBENTRIES ) ); + + updateEnabled(); + + applyDialogFont( composite ); + + return composite; + } + + + private void updateEnabled() + { + entryAbbreviateMaxLengthText.setEnabled( entryAbbreviateButton.getSelection() ); + searchResultAbbreviateMaxLengthText.setEnabled( searchResultAbbreviateButton.getSelection() ); + foldingSizeText.setEnabled( enableFoldingButton.getSelection() ); + foldingSizeLabel.setEnabled( enableFoldingButton.getSelection() ); + } + + + public boolean performOk() + { + + Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences(); + coreStore.setValue( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN, this.checkForChildrenButton + .getSelection() ); + coreStore.setValue( BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS, + this.showAliasAndReferralObjectsButton.getSelection() ); + coreStore + .setValue( BrowserCoreConstants.PREFERENCE_FETCH_SUBENTRIES, this.fetchSubentriesButton.getSelection() ); + BrowserCorePlugin.getDefault().savePluginPreferences(); + + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES, + this.expandBaseEntriesButton.getSelection() ); + + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING, + this.enableFoldingButton.getSelection() ); + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE, + this.foldingSizeText.getText().trim() ); + + getPreferenceStore().setValue( + BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL, + this.entryLabelCombo.getSelectionIndex() == 2 ? BrowserCommonConstants.SHOW_RDN_VALUE : this.entryLabelCombo + .getSelectionIndex() == 1 ? BrowserCommonConstants.SHOW_RDN : BrowserCommonConstants.SHOW_DN ); + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE, + this.entryAbbreviateButton.getSelection() ); + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH, + this.entryAbbreviateMaxLengthText.getText().trim() ); + + getPreferenceStore().setValue( + BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL, + this.searchResultLabelCombo.getSelectionIndex() == 2 ? BrowserCommonConstants.SHOW_RDN_VALUE + : this.searchResultLabelCombo.getSelectionIndex() == 1 ? BrowserCommonConstants.SHOW_RDN + : BrowserCommonConstants.SHOW_DN ); + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE, + this.searchResultAbbreviateButton.getSelection() ); + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH, + this.searchResultAbbreviateMaxLengthText.getText().trim() ); + + return true; + } + + + protected void performDefaults() + { + + entryLabelCombo + .select( getPreferenceStore().getDefaultInt( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL ) == BrowserCommonConstants.SHOW_RDN_VALUE ? 2 + : getPreferenceStore().getDefaultInt( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL ) == BrowserCommonConstants.SHOW_RDN ? 1 + : 0 ); + entryAbbreviateButton.setSelection( getPreferenceStore().getDefaultBoolean( + BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE ) ); + entryAbbreviateMaxLengthText.setText( getPreferenceStore().getDefaultString( + BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH ) ); + + searchResultLabelCombo + .select( getPreferenceStore().getDefaultInt( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL ) == BrowserCommonConstants.SHOW_RDN_VALUE ? 2 + : getPreferenceStore().getDefaultInt( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL ) == BrowserCommonConstants.SHOW_RDN ? 1 + : 0 ); + searchResultAbbreviateButton.setSelection( getPreferenceStore().getDefaultBoolean( + BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE ) ); + searchResultAbbreviateMaxLengthText.setText( getPreferenceStore().getDefaultString( + BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH ) ); + + enableFoldingButton.setSelection( getPreferenceStore().getDefaultBoolean( + BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING ) ); + foldingSizeText.setText( getPreferenceStore().getDefaultString( + BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE ) ); + + expandBaseEntriesButton.setSelection( getPreferenceStore().getDefaultBoolean( + BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES ) ); + Preferences coreStore = BrowserCorePlugin.getDefault().getPluginPreferences(); + checkForChildrenButton.setSelection( coreStore + .getDefaultBoolean( BrowserCoreConstants.PREFERENCE_CHECK_FOR_CHILDREN ) ); + showAliasAndReferralObjectsButton.setSelection( coreStore + .getDefaultBoolean( BrowserCoreConstants.PREFERENCE_SHOW_ALIAS_AND_REFERRAL_OBJECTS ) ); + fetchSubentriesButton.setSelection( coreStore + .getDefaultBoolean( BrowserCoreConstants.PREFERENCE_FETCH_SUBENTRIES ) ); + + updateEnabled(); + + super.performDefaults(); + } + +} Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/EntryEditorPreferencePage.java URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/EntryEditorPreferencePage.java?view=auto&rev=526693 ============================================================================== --- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/EntryEditorPreferencePage.java (added) +++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/EntryEditorPreferencePage.java Mon Apr 9 02:49:48 2007 @@ -0,0 +1,194 @@ +/* + * 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.dialogs.preferences; + + +import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator; +import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants; +import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + + +public class EntryEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage +{ + + private Button showObjectClassAttributeButton; + + private Button showMustAttributesButton; + + private Button showMayAttributesButton; + + private Button showOperationalAttributesButton; + + private Button enableFoldingButton; + + private Label foldingThresholdLabel; + + private Text foldingThresholdText; + + + public EntryEditorPreferencePage() + { + super(); + super.setPreferenceStore( BrowserCommonActivator.getDefault().getPreferenceStore() ); + super.setDescription( "General settings for the LDAP entry editor:" ); + } + + + public void init( IWorkbench workbench ) + { + } + + + protected Control createContents( Composite parent ) + { + + Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); + + BaseWidgetUtils.createSpacer( composite, 1 ); + BaseWidgetUtils.createSpacer( composite, 1 ); + Group visibleAttributesGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, + 1, 1 ), "Visible Attributes", 1 ); + Composite visibleAttributesComposite = BaseWidgetUtils.createColumnContainer( visibleAttributesGroup, 1, 1 ); + showObjectClassAttributeButton = BaseWidgetUtils.createCheckbox( visibleAttributesComposite, + "Show objectClass attribute", 1 ); + showObjectClassAttributeButton.setSelection( getPreferenceStore().getBoolean( + BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OBJECTCLASS_ATTRIBUTES ) ); + showMustAttributesButton = BaseWidgetUtils.createCheckbox( visibleAttributesComposite, "Show must attributes", + 1 ); + showMustAttributesButton.setSelection( getPreferenceStore().getBoolean( + BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MUST_ATTRIBUTES ) ); + showMayAttributesButton = BaseWidgetUtils.createCheckbox( visibleAttributesComposite, "Show may attributes", 1 ); + showMayAttributesButton.setSelection( getPreferenceStore().getBoolean( + BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MAY_ATTRIBUTES ) ); + showOperationalAttributesButton = BaseWidgetUtils.createCheckbox( visibleAttributesComposite, + "Show operational attributes", 1 ); + showOperationalAttributesButton.setSelection( getPreferenceStore().getBoolean( + BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES ) ); + + BaseWidgetUtils.createSpacer( composite, 1 ); + BaseWidgetUtils.createSpacer( composite, 1 ); + String foldingTooltip = "If an attribute has more than the specified number of values it will be folded to one line. You may expand and collapse the values."; + Group foldingGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ), + "Folding", 1 ); + Composite pagingGroupComposite = BaseWidgetUtils.createColumnContainer( foldingGroup, 2, 1 ); + enableFoldingButton = BaseWidgetUtils.createCheckbox( pagingGroupComposite, "Enable folding", 2 ); + enableFoldingButton.setToolTipText( foldingTooltip ); + enableFoldingButton.setSelection( getPreferenceStore().getBoolean( + BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING ) ); + enableFoldingButton.addSelectionListener( new SelectionAdapter() + { + public void widgetSelected( SelectionEvent e ) + { + updateEnabled(); + } + } ); + foldingThresholdLabel = BaseWidgetUtils.createLabel( pagingGroupComposite, "Folding threshold: ", 1 ); + foldingThresholdLabel.setToolTipText( foldingTooltip ); + foldingThresholdLabel.setEnabled( enableFoldingButton.getSelection() ); + foldingThresholdText = BaseWidgetUtils.createText( pagingGroupComposite, getPreferenceStore().getString( + BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD ), 4, 1 ); + foldingThresholdText.setToolTipText( foldingTooltip ); + foldingThresholdText.setEnabled( enableFoldingButton.getSelection() ); + foldingThresholdText.addVerifyListener( new VerifyListener() + { + public void verifyText( VerifyEvent e ) + { + if ( !e.text.matches( "[0-9]*" ) ) + { + e.doit = false; + } + if ( "".equals( foldingThresholdText.getText() ) && e.text.matches( "[0]" ) ) + { + e.doit = false; + } + } + } ); + + updateEnabled(); + + applyDialogFont( composite ); + + return composite; + } + + + private void updateEnabled() + { + foldingThresholdText.setEnabled( enableFoldingButton.getSelection() ); + foldingThresholdLabel.setEnabled( enableFoldingButton.getSelection() ); + } + + + public boolean performOk() + { + + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OBJECTCLASS_ATTRIBUTES, + this.showObjectClassAttributeButton.getSelection() ); + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MUST_ATTRIBUTES, + this.showMustAttributesButton.getSelection() ); + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MAY_ATTRIBUTES, + this.showMayAttributesButton.getSelection() ); + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES, + this.showOperationalAttributesButton.getSelection() ); + + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING, + this.enableFoldingButton.getSelection() ); + getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD, + this.foldingThresholdText.getText() ); + + return true; + } + + + protected void performDefaults() + { + + this.showObjectClassAttributeButton.setSelection( getPreferenceStore().getDefaultBoolean( + BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OBJECTCLASS_ATTRIBUTES ) ); + this.showMustAttributesButton.setSelection( getPreferenceStore().getDefaultBoolean( + BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MUST_ATTRIBUTES ) ); + this.showMayAttributesButton.setSelection( getPreferenceStore().getDefaultBoolean( + BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MAY_ATTRIBUTES ) ); + this.showOperationalAttributesButton.setSelection( getPreferenceStore().getDefaultBoolean( + BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES ) ); + + this.foldingThresholdText.setText( getPreferenceStore().getDefaultString( + BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD ) ); + + updateEnabled(); + + super.performDefaults(); + } + +} Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/MainPreferencePage.java URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/MainPreferencePage.java?view=auto&rev=526693 ============================================================================== --- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/MainPreferencePage.java (added) +++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/MainPreferencePage.java Mon Apr 9 02:49:48 2007 @@ -0,0 +1,250 @@ +/* + * 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.dialogs.preferences; + + +import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator; +import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants; +import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; +import org.eclipse.jface.preference.ColorSelector; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + + +public class MainPreferencePage extends PreferencePage implements IWorkbenchPreferencePage +{ + + private final String[] ERROR_TYPES = new String[] + { "Warnings:", "Errors:" }; + + private final String[] ERROR_FONT_CONSTANTS = new String[] + { BrowserCommonConstants.PREFERENCE_WARNING_FONT, BrowserCommonConstants.PREFERENCE_ERROR_FONT }; + + private final String[] ERROR_COLOR_CONSTANTS = new String[] + { BrowserCommonConstants.PREFERENCE_WARNING_COLOR, BrowserCommonConstants.PREFERENCE_ERROR_COLOR }; + + private Label[] errorTypeLabels = new Label[ERROR_TYPES.length]; + + private ColorSelector[] errorColorSelectors = new ColorSelector[ERROR_TYPES.length]; + + private Button[] errorBoldButtons = new Button[ERROR_TYPES.length]; + + private Button[] errorItalicButtons = new Button[ERROR_TYPES.length]; + + private Label quickfilterTypeLabel; + + private ColorSelector quickfilterForegroundColorSelector;; + + private ColorSelector quickfilterBackgroundColorSelector;; + + private Button quickfilterBoldButton; + + private Button quickfilterItalicButton; + + + public MainPreferencePage() + { + super( "LDAP" ); + super.setPreferenceStore( BrowserCommonActivator.getDefault().getPreferenceStore() ); + super.setDescription( "General settings for the LDAP plugin:" ); + } + + + public void init( IWorkbench workbench ) + { + } + + + protected Control createContents( Composite parent ) + { + + Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 ); + + BaseWidgetUtils.createSpacer( composite, 1 ); + BaseWidgetUtils.createSpacer( composite, 1 ); + Group errorGroup = BaseWidgetUtils.createGroup( composite, "Warning and Error Colors and Fonts", 1 ); + errorGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); + Composite errorComposite = BaseWidgetUtils.createColumnContainer( errorGroup, 4, 1 ); + for ( int i = 0; i < ERROR_TYPES.length; i++ ) + { + final int index = i; + + errorTypeLabels[i] = BaseWidgetUtils.createLabel( errorComposite, ERROR_TYPES[i], 1 ); + errorTypeLabels[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); + errorColorSelectors[i] = new ColorSelector( errorComposite ); + errorBoldButtons[i] = BaseWidgetUtils.createCheckbox( errorComposite, "Bold", 1 ); + errorItalicButtons[i] = BaseWidgetUtils.createCheckbox( errorComposite, "Italic", 1 ); + + FontData[] fontDatas = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() + .getPreferenceStore(), ERROR_FONT_CONSTANTS[i] ); + RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(), + ERROR_COLOR_CONSTANTS[i] ); + setErrors( index, fontDatas, rgb ); + } + + BaseWidgetUtils.createSpacer( composite, 1 ); + BaseWidgetUtils.createSpacer( composite, 1 ); + Group otherGroup = BaseWidgetUtils.createGroup( composite, "Quick Filter Colors and Fonts", 1 ); + otherGroup.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); + Composite otherComposite = BaseWidgetUtils.createColumnContainer( otherGroup, 4, 1 ); + quickfilterTypeLabel = BaseWidgetUtils.createLabel( otherComposite, "Quick Filter", 1 ); + quickfilterTypeLabel.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); + quickfilterForegroundColorSelector = new ColorSelector( otherComposite ); + quickfilterBoldButton = BaseWidgetUtils.createCheckbox( otherComposite, "Bold", 1 ); + quickfilterItalicButton = BaseWidgetUtils.createCheckbox( otherComposite, "Italic", 1 ); + Label quickfilterBgLabel = BaseWidgetUtils.createLabel( otherComposite, "Quick Filter Background", 1 ); + quickfilterBgLabel.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); + quickfilterBackgroundColorSelector = new ColorSelector( otherComposite ); + FontData[] qfFontDatas = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() + .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_QUICKFILTER_FONT ); + RGB qfBgRgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(), + BrowserCommonConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR ); + RGB qfFgRgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(), + BrowserCommonConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR ); + setQuickfilter( qfFontDatas, qfFgRgb, qfBgRgb ); + + return composite; + } + + + private void setErrors( int index, FontData[] fontDatas, RGB rgb ) + { + boolean bold = isBold( fontDatas ); + boolean italic = isItalic( fontDatas ); + errorColorSelectors[index].setColorValue( rgb ); + errorBoldButtons[index].setSelection( bold ); + errorItalicButtons[index].setSelection( italic ); + } + + + private void setQuickfilter( FontData[] fontDatas, RGB fgRgb, RGB bgRgb ) + { + boolean bold = isBold( fontDatas ); + boolean italic = isItalic( fontDatas ); + quickfilterBackgroundColorSelector.setColorValue( bgRgb ); + quickfilterForegroundColorSelector.setColorValue( fgRgb ); + quickfilterBoldButton.setSelection( bold ); + quickfilterItalicButton.setSelection( italic ); + } + + + protected void performDefaults() + { + for ( int i = 0; i < ERROR_TYPES.length; i++ ) + { + FontData[] fontDatas = PreferenceConverter.getDefaultFontDataArray( BrowserCommonActivator.getDefault() + .getPreferenceStore(), ERROR_FONT_CONSTANTS[i] ); + RGB rgb = PreferenceConverter.getDefaultColor( BrowserCommonActivator.getDefault().getPreferenceStore(), + ERROR_COLOR_CONSTANTS[i] ); + setErrors( i, fontDatas, rgb ); + } + + FontData[] qfFontDatas = PreferenceConverter.getDefaultFontDataArray( BrowserCommonActivator.getDefault() + .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_QUICKFILTER_FONT ); + RGB qfBgRgb = PreferenceConverter.getDefaultColor( BrowserCommonActivator.getDefault().getPreferenceStore(), + BrowserCommonConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR ); + RGB qfFgRgb = PreferenceConverter.getDefaultColor( BrowserCommonActivator.getDefault().getPreferenceStore(), + BrowserCommonConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR ); + setQuickfilter( qfFontDatas, qfFgRgb, qfBgRgb ); + + super.performDefaults(); + } + + + public boolean performOk() + { + for ( int i = 0; i < ERROR_TYPES.length; i++ ) + { + FontData[] fontDatas = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() + .getPreferenceStore(), ERROR_FONT_CONSTANTS[i] ); + setFontData( fontDatas, this.errorBoldButtons[i], this.errorBoldButtons[i] ); + RGB rgb = errorColorSelectors[i].getColorValue(); + PreferenceConverter.setValue( BrowserCommonActivator.getDefault().getPreferenceStore(), ERROR_FONT_CONSTANTS[i], + fontDatas ); + PreferenceConverter.setValue( BrowserCommonActivator.getDefault().getPreferenceStore(), ERROR_COLOR_CONSTANTS[i], + rgb ); + } + + FontData[] qfFontDatas = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() + .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_QUICKFILTER_FONT ); + setFontData( qfFontDatas, this.quickfilterBoldButton, this.quickfilterItalicButton ); + RGB qfBgRgb = quickfilterBackgroundColorSelector.getColorValue(); + RGB qfFgRgb = quickfilterForegroundColorSelector.getColorValue(); + PreferenceConverter.setValue( BrowserCommonActivator.getDefault().getPreferenceStore(), + BrowserCommonConstants.PREFERENCE_QUICKFILTER_FONT, qfFontDatas ); + PreferenceConverter.setValue( BrowserCommonActivator.getDefault().getPreferenceStore(), + BrowserCommonConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR, qfBgRgb ); + PreferenceConverter.setValue( BrowserCommonActivator.getDefault().getPreferenceStore(), + BrowserCommonConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR, qfFgRgb ); + + return true; + } + + + private void setFontData( FontData[] fontDatas, Button boldButton, Button italicButton ) + { + for ( int j = 0; j < fontDatas.length; j++ ) + { + int style = SWT.NORMAL; + if ( boldButton.getSelection() ) + style |= SWT.BOLD; + if ( italicButton.getSelection() ) + style |= SWT.ITALIC; + fontDatas[j].setStyle( style ); + } + } + + + private boolean isBold( FontData[] fontDatas ) + { + boolean bold = false; + for ( int j = 0; j < fontDatas.length; j++ ) + { + if ( ( fontDatas[j].getStyle() & SWT.BOLD ) != SWT.NORMAL ) + bold = true; + } + return bold; + } + + + private boolean isItalic( FontData[] fontDatas ) + { + boolean italic = false; + for ( int j = 0; j < fontDatas.length; j++ ) + { + if ( ( fontDatas[j].getStyle() & SWT.ITALIC ) != SWT.NORMAL ) + italic = true; + } + return italic; + } + +} Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/SyntaxDialog.java URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/SyntaxDialog.java?view=auto&rev=526693 ============================================================================== --- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/SyntaxDialog.java (added) +++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/SyntaxDialog.java Mon Apr 9 02:49:48 2007 @@ -0,0 +1,108 @@ +/* + * 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.dialogs.preferences; + + +import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; +import org.apache.directory.ldapstudio.browser.core.model.schema.BinarySyntax; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + + +public class SyntaxDialog extends Dialog +{ + + private BinarySyntax currentSyntax; + + private String[] syntaxOids; + + private BinarySyntax returnSyntax; + + private Combo oidCombo; + + + public SyntaxDialog( Shell parentShell, BinarySyntax currentSyntax, String[] syntaxOids ) + { + super( parentShell ); + this.currentSyntax = currentSyntax; + this.syntaxOids = syntaxOids; + + this.returnSyntax = null; + } + + + protected void configureShell( Shell newShell ) + { + super.configureShell( newShell ); + newShell.setText( "Select Syntax OID" ); + } + + + protected void okPressed() + { + this.returnSyntax = new BinarySyntax( oidCombo.getText() ); + super.okPressed(); + } + + + protected Control createDialogArea( Composite parent ) + { + + Composite composite = ( Composite ) super.createDialogArea( parent ); + + Composite c = BaseWidgetUtils.createColumnContainer( composite, 2, 1 ); + BaseWidgetUtils.createLabel( c, "Attribute Type or OID:", 1 ); + this.oidCombo = BaseWidgetUtils.createCombo( c, this.syntaxOids, -1, 1 ); + if ( this.currentSyntax != null ) + { + this.oidCombo.setText( currentSyntax.getSyntaxNumericOid() ); + } + this.oidCombo.addModifyListener( new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + validate(); + } + } ); + + return composite; + } + + + private void validate() + { + super.getButton( IDialogConstants.OK_ID ).setEnabled( !"".equals( this.oidCombo.getText() ) ); + } + + + public BinarySyntax getSyntax() + { + return returnSyntax; + } + +} Added: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/SyntaxValueEditorDialog.java URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/SyntaxValueEditorDialog.java?view=auto&rev=526693 ============================================================================== --- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/SyntaxValueEditorDialog.java (added) +++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/preferences/SyntaxValueEditorDialog.java Mon Apr 9 02:49:48 2007 @@ -0,0 +1,147 @@ +/* + * 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.dialogs.preferences; + + +import java.util.Iterator; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils; +import org.apache.directory.ldapstudio.browser.core.model.schema.SyntaxValueProviderRelation; +import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager.ValueEditorExtension; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + + +public class SyntaxValueEditorDialog extends Dialog +{ + + private SyntaxValueProviderRelation relation; + + private SortedMap class2ValueEditorProxyMap; + + private String[] syntaxOids; + + private SortedMap vpName2classMap; + + private SyntaxValueProviderRelation returnRelation; + + private Combo oidCombo; + + private Combo valueEditorCombo; + + + public SyntaxValueEditorDialog( Shell parentShell, SyntaxValueProviderRelation relation, + SortedMap class2ValueEditorProxyMap, String[] syntaxOids ) + { + super( parentShell ); + this.relation = relation; + this.class2ValueEditorProxyMap = class2ValueEditorProxyMap; + this.syntaxOids = syntaxOids; + + this.returnRelation = null; + + this.vpName2classMap = new TreeMap(); + for ( Iterator it = this.class2ValueEditorProxyMap.values().iterator(); it.hasNext(); ) + { + ValueEditorExtension vp = it.next(); + vpName2classMap.put( vp.name, vp.className ); + } + } + + + protected void configureShell( Shell newShell ) + { + super.configureShell( newShell ); + newShell.setText( "Attribute Value Editor" ); + } + + + protected void okPressed() + { + this.returnRelation = new SyntaxValueProviderRelation( this.oidCombo.getText(), ( String ) this.vpName2classMap + .get( this.valueEditorCombo.getText() ) ); + super.okPressed(); + } + + + protected Control createDialogArea( Composite parent ) + { + + Composite composite = ( Composite ) super.createDialogArea( parent ); + + Composite c = BaseWidgetUtils.createColumnContainer( composite, 2, 1 ); + BaseWidgetUtils.createLabel( c, "Syntax OID:", 1 ); + this.oidCombo = BaseWidgetUtils.createCombo( c, this.syntaxOids, -1, 1 ); + if ( this.relation != null && this.relation.getSyntaxOID() != null ) + { + this.oidCombo.setText( this.relation.getSyntaxOID() ); + } + this.oidCombo.addModifyListener( new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + validate(); + } + } ); + + BaseWidgetUtils.createLabel( c, "Value Editor:", 1 ); + this.valueEditorCombo = BaseWidgetUtils.createReadonlyCombo( c, vpName2classMap.keySet() + .toArray( new String[0] ), -1, 1 ); + if ( this.relation != null && this.relation.getValueProviderClassname() != null + && this.class2ValueEditorProxyMap.containsKey( this.relation.getValueProviderClassname() ) ) + { + this.valueEditorCombo.setText( ( this.class2ValueEditorProxyMap.get( this.relation + .getValueProviderClassname() ) ).name ); + } + this.valueEditorCombo.addModifyListener( new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + validate(); + } + } ); + + return composite; + } + + + private void validate() + { + super.getButton( IDialogConstants.OK_ID ).setEnabled( + !"".equals( this.valueEditorCombo.getText() ) && !"".equals( this.oidCombo.getText() ) ); + } + + + public SyntaxValueProviderRelation getRelation() + { + return returnRelation; + } + +}