KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > ldifeditor > dialogs > preferences > LdifEditorPreferencePage


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.ldifeditor.dialogs.preferences;
22
23
24 import org.apache.directory.ldapstudio.browser.common.dialogs.preferences.TextFormatsPreferencePage;
25 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
26 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
27 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorActivator;
28 import org.apache.directory.ldapstudio.ldifeditor.LdifEditorConstants;
29 import org.eclipse.jface.preference.PreferencePage;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.events.SelectionAdapter;
32 import org.eclipse.swt.events.SelectionEvent;
33 import org.eclipse.swt.layout.GridData;
34 import org.eclipse.swt.layout.GridLayout;
35 import org.eclipse.swt.widgets.Button;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Control;
38 import org.eclipse.swt.widgets.Group;
39 import org.eclipse.swt.widgets.Label;
40 import org.eclipse.swt.widgets.Link;
41 import org.eclipse.ui.IWorkbench;
42 import org.eclipse.ui.IWorkbenchPreferencePage;
43 import org.eclipse.ui.dialogs.PreferencesUtil;
44
45
46 public class LdifEditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage
47 {
48
49     // private Button autoWrapButton;
50

51     private Button enableFoldingButton;
52
53     private Label initiallyFoldLabel;
54
55     private Button initiallyFoldCommentsButton;
56
57     private Button initiallyFoldRecordsButton;
58
59     private Button initiallyFoldWrappedLinesButton;
60
61     private Button useLdifDoubleClickButton;
62
63
64     public LdifEditorPreferencePage()
65     {
66         super( "LDIF Editor" );
67         super.setPreferenceStore( LdifEditorActivator.getDefault().getPreferenceStore() );
68     }
69
70
71     public void init( IWorkbench workbench )
72     {
73     }
74
75
76     protected Control createContents( Composite parent )
77     {
78         Composite composite = new Composite( parent, SWT.NONE );
79         GridLayout layout = new GridLayout( 1, false );
80         layout.marginWidth = 0;
81         layout.marginHeight = 0;
82         layout.marginLeft = 0;
83         layout.marginRight = 0;
84         layout.marginTop = 0;
85         layout.marginBottom = 0;
86         composite.setLayout( layout );
87         composite.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
88
89         String JavaDoc text = "See <a>Text Editors</a> for the general text editor preferences.";
90         Link link = BaseWidgetUtils.createLink( composite, text, 1 );
91         link.addSelectionListener( new SelectionAdapter()
92         {
93             public void widgetSelected( SelectionEvent e )
94             {
95                 PreferencesUtil.createPreferenceDialogOn( getShell(),
96                     "org.eclipse.ui.preferencePages.GeneralTextEditor", null, null ); //$NON-NLS-1$
97
}
98         } );
99         String JavaDoc text2 = "See <a>Text Formats</a> for LDIF format preferences.";
100         Link link2 = BaseWidgetUtils.createLink( composite, text2, 1 );
101         link2.addSelectionListener( new SelectionAdapter()
102         {
103             public void widgetSelected( SelectionEvent e )
104             {
105                 PreferencesUtil.createPreferenceDialogOn( getShell(), TextFormatsPreferencePage.class.getName(), null,
106                     null ); //$NON-NLS-1$
107
}
108         } );
109
110         BaseWidgetUtils.createSpacer( composite, 1 );
111         BaseWidgetUtils.createSpacer( composite, 1 );
112
113         Group foldGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ),
114             "Folding", 1 );
115
116         enableFoldingButton = BaseWidgetUtils.createCheckbox( foldGroup, "Enable Folding", 1 );
117         enableFoldingButton.setSelection( getPreferenceStore().getBoolean(
118             LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE ) );
119         enableFoldingButton.addSelectionListener( new SelectionAdapter()
120         {
121             public void widgetSelected( SelectionEvent e )
122             {
123                 checkEnabled();
124             }
125         } );
126
127         Composite initiallyFoldComposiste = BaseWidgetUtils.createColumnContainer( foldGroup, 4, 1 );
128         initiallyFoldLabel = BaseWidgetUtils.createLabel( initiallyFoldComposiste, "Initially fold:", 1 );
129         initiallyFoldCommentsButton = BaseWidgetUtils.createCheckbox( initiallyFoldComposiste, "Comments", 1 );
130         initiallyFoldCommentsButton.setSelection( getPreferenceStore().getBoolean(
131             LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS ) );
132         initiallyFoldRecordsButton = BaseWidgetUtils.createCheckbox( initiallyFoldComposiste, "Records", 1 );
133         initiallyFoldRecordsButton.setSelection( getPreferenceStore().getBoolean(
134             LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS ) );
135         initiallyFoldWrappedLinesButton = BaseWidgetUtils.createCheckbox( initiallyFoldComposiste, "Wrapped lines", 1 );
136         initiallyFoldWrappedLinesButton.setSelection( getPreferenceStore().getBoolean(
137             LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES ) );
138
139         BaseWidgetUtils.createSpacer( composite, 1 );
140
141         Group doubleClickGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ),
142             "Double Click Behaviour", 1 );
143         useLdifDoubleClickButton = BaseWidgetUtils.createCheckbox( doubleClickGroup,
144             "Select whole attribute or value on double click", 1 );
145         useLdifDoubleClickButton.setSelection( getPreferenceStore().getBoolean(
146             LdifEditorConstants.PREFERENCE_LDIFEDITOR_DOUBLECLICK_USELDIFDOUBLECLICK ) );
147
148         checkEnabled();
149
150         return composite;
151     }
152
153
154     private void checkEnabled()
155     {
156         initiallyFoldLabel.setEnabled( enableFoldingButton.getSelection() );
157         initiallyFoldCommentsButton.setEnabled( enableFoldingButton.getSelection() );
158         initiallyFoldRecordsButton.setEnabled( enableFoldingButton.getSelection() );
159         initiallyFoldWrappedLinesButton.setEnabled( enableFoldingButton.getSelection() );
160     }
161
162
163     public boolean performOk()
164     {
165         getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE,
166             this.enableFoldingButton.getSelection() );
167         getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS,
168             this.initiallyFoldCommentsButton.getSelection() );
169         getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS,
170             this.initiallyFoldRecordsButton.getSelection() );
171         getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES,
172             this.initiallyFoldWrappedLinesButton.getSelection() );
173
174         getPreferenceStore().setValue( LdifEditorConstants.PREFERENCE_LDIFEDITOR_DOUBLECLICK_USELDIFDOUBLECLICK,
175             this.useLdifDoubleClickButton.getSelection() );
176
177         BrowserCorePlugin.getDefault().savePluginPreferences();
178
179         return true;
180     }
181
182
183     protected void performDefaults()
184     {
185         enableFoldingButton.setSelection( getPreferenceStore().getDefaultBoolean(
186             LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_ENABLE ) );
187         initiallyFoldCommentsButton.setSelection( getPreferenceStore().getDefaultBoolean(
188             LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDCOMMENTS ) );
189         initiallyFoldRecordsButton.setSelection( getPreferenceStore().getDefaultBoolean(
190             LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDRECORDS ) );
191         initiallyFoldWrappedLinesButton.setSelection( getPreferenceStore().getDefaultBoolean(
192             LdifEditorConstants.PREFERENCE_LDIFEDITOR_FOLDING_INITIALLYFOLDWRAPPEDLINES ) );
193
194         useLdifDoubleClickButton.setSelection( getPreferenceStore().getDefaultBoolean(
195             LdifEditorConstants.PREFERENCE_LDIFEDITOR_DOUBLECLICK_USELDIFDOUBLECLICK ) );
196
197         super.performDefaults();
198
199         checkEnabled();
200     }
201
202 }
203
Popular Tags