KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > dialogs > preferences > EntryEditorPreferencePage


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.browser.common.dialogs.preferences;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants;
26 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
27 import org.eclipse.jface.preference.PreferencePage;
28 import org.eclipse.swt.events.SelectionAdapter;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.events.VerifyEvent;
31 import org.eclipse.swt.events.VerifyListener;
32 import org.eclipse.swt.widgets.Button;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Control;
35 import org.eclipse.swt.widgets.Group;
36 import org.eclipse.swt.widgets.Label;
37 import org.eclipse.swt.widgets.Text;
38 import org.eclipse.ui.IWorkbench;
39 import org.eclipse.ui.IWorkbenchPreferencePage;
40
41
42 public class EntryEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
43 {
44
45     private Button showObjectClassAttributeButton;
46
47     private Button showMustAttributesButton;
48
49     private Button showMayAttributesButton;
50
51     private Button showOperationalAttributesButton;
52
53     private Button enableFoldingButton;
54
55     private Label foldingThresholdLabel;
56
57     private Text foldingThresholdText;
58
59
60     public EntryEditorPreferencePage()
61     {
62         super();
63         super.setPreferenceStore( BrowserCommonActivator.getDefault().getPreferenceStore() );
64         super.setDescription( "General settings for the LDAP entry editor:" );
65     }
66
67
68     public void init( IWorkbench workbench )
69     {
70     }
71
72
73     protected Control createContents( Composite parent )
74     {
75
76         Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
77
78         BaseWidgetUtils.createSpacer( composite, 1 );
79         BaseWidgetUtils.createSpacer( composite, 1 );
80         Group visibleAttributesGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite,
81             1, 1 ), "Visible Attributes", 1 );
82         Composite visibleAttributesComposite = BaseWidgetUtils.createColumnContainer( visibleAttributesGroup, 1, 1 );
83         showObjectClassAttributeButton = BaseWidgetUtils.createCheckbox( visibleAttributesComposite,
84             "Show objectClass attribute", 1 );
85         showObjectClassAttributeButton.setSelection( getPreferenceStore().getBoolean(
86             BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OBJECTCLASS_ATTRIBUTES ) );
87         showMustAttributesButton = BaseWidgetUtils.createCheckbox( visibleAttributesComposite, "Show must attributes",
88             1 );
89         showMustAttributesButton.setSelection( getPreferenceStore().getBoolean(
90             BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MUST_ATTRIBUTES ) );
91         showMayAttributesButton = BaseWidgetUtils.createCheckbox( visibleAttributesComposite, "Show may attributes", 1 );
92         showMayAttributesButton.setSelection( getPreferenceStore().getBoolean(
93             BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MAY_ATTRIBUTES ) );
94         showOperationalAttributesButton = BaseWidgetUtils.createCheckbox( visibleAttributesComposite,
95             "Show operational attributes", 1 );
96         showOperationalAttributesButton.setSelection( getPreferenceStore().getBoolean(
97             BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES ) );
98
99         BaseWidgetUtils.createSpacer( composite, 1 );
100         BaseWidgetUtils.createSpacer( composite, 1 );
101         String JavaDoc 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.";
102         Group foldingGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ),
103             "Folding", 1 );
104         Composite pagingGroupComposite = BaseWidgetUtils.createColumnContainer( foldingGroup, 2, 1 );
105         enableFoldingButton = BaseWidgetUtils.createCheckbox( pagingGroupComposite, "Enable folding", 2 );
106         enableFoldingButton.setToolTipText( foldingTooltip );
107         enableFoldingButton.setSelection( getPreferenceStore().getBoolean(
108             BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING ) );
109         enableFoldingButton.addSelectionListener( new SelectionAdapter()
110         {
111             public void widgetSelected( SelectionEvent e )
112             {
113                 updateEnabled();
114             }
115         } );
116         foldingThresholdLabel = BaseWidgetUtils.createLabel( pagingGroupComposite, "Folding threshold: ", 1 );
117         foldingThresholdLabel.setToolTipText( foldingTooltip );
118         foldingThresholdLabel.setEnabled( enableFoldingButton.getSelection() );
119         foldingThresholdText = BaseWidgetUtils.createText( pagingGroupComposite, getPreferenceStore().getString(
120             BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD ), 4, 1 );
121         foldingThresholdText.setToolTipText( foldingTooltip );
122         foldingThresholdText.setEnabled( enableFoldingButton.getSelection() );
123         foldingThresholdText.addVerifyListener( new VerifyListener()
124         {
125             public void verifyText( VerifyEvent e )
126             {
127                 if ( !e.text.matches( "[0-9]*" ) )
128                 {
129                     e.doit = false;
130                 }
131                 if ( "".equals( foldingThresholdText.getText() ) && e.text.matches( "[0]" ) )
132                 {
133                     e.doit = false;
134                 }
135             }
136         } );
137
138         updateEnabled();
139
140         applyDialogFont( composite );
141
142         return composite;
143     }
144
145
146     private void updateEnabled()
147     {
148         foldingThresholdText.setEnabled( enableFoldingButton.getSelection() );
149         foldingThresholdLabel.setEnabled( enableFoldingButton.getSelection() );
150     }
151
152
153     public boolean performOk()
154     {
155
156         getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OBJECTCLASS_ATTRIBUTES,
157             this.showObjectClassAttributeButton.getSelection() );
158         getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MUST_ATTRIBUTES,
159             this.showMustAttributesButton.getSelection() );
160         getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MAY_ATTRIBUTES,
161             this.showMayAttributesButton.getSelection() );
162         getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES,
163             this.showOperationalAttributesButton.getSelection() );
164
165         getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING,
166             this.enableFoldingButton.getSelection() );
167         getPreferenceStore().setValue( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD,
168             this.foldingThresholdText.getText() );
169
170         return true;
171     }
172
173
174     protected void performDefaults()
175     {
176
177         this.showObjectClassAttributeButton.setSelection( getPreferenceStore().getDefaultBoolean(
178             BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OBJECTCLASS_ATTRIBUTES ) );
179         this.showMustAttributesButton.setSelection( getPreferenceStore().getDefaultBoolean(
180             BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MUST_ATTRIBUTES ) );
181         this.showMayAttributesButton.setSelection( getPreferenceStore().getDefaultBoolean(
182             BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MAY_ATTRIBUTES ) );
183         this.showOperationalAttributesButton.setSelection( getPreferenceStore().getDefaultBoolean(
184             BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES ) );
185
186         this.foldingThresholdText.setText( getPreferenceStore().getDefaultString(
187             BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD ) );
188
189         updateEnabled();
190
191         super.performDefaults();
192     }
193
194 }
195
Popular Tags