KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > BrowserCommonPreferencesInitializer


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;
22
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Collection JavaDoc;
26
27 import org.apache.directory.ldapstudio.browser.core.BrowserCoreConstants;
28 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeValueProviderRelation;
29 import org.apache.directory.ldapstudio.browser.core.model.schema.SyntaxValueProviderRelation;
30 import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager;
31 import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager.ValueEditorExtension;
32 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
33 import org.eclipse.jface.preference.IPreferenceStore;
34 import org.eclipse.jface.preference.PreferenceConverter;
35 import org.eclipse.swt.SWT;
36 import org.eclipse.swt.graphics.FontData;
37 import org.eclipse.swt.graphics.RGB;
38 import org.eclipse.swt.widgets.Display;
39
40
41 /**
42  * This class is used to set default preference values.
43  *
44  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
45  * @version $Rev$, $Date$
46  */

47 public class BrowserCommonPreferencesInitializer extends AbstractPreferenceInitializer
48 {
49     /**
50      * {@inheritDoc}
51      */

52     public void initializeDefaultPreferences()
53     {
54
55         IPreferenceStore store = BrowserCommonActivator.getDefault().getPreferenceStore();
56
57         // Common
58
store.setDefault( BrowserCommonConstants.PREFERENCE_COUNT_LIMIT, 1000 );
59         store.setDefault( BrowserCommonConstants.PREFERENCE_TIME_LIMIT, 0 );
60
61         // Colors and Fonts
62
RGB rgbBlack = Display.getDefault().getSystemColor( SWT.COLOR_BLACK ).getRGB();
63         RGB rgbRed = Display.getDefault().getSystemColor( SWT.COLOR_RED ).getRGB();
64         RGB rgbYellow = Display.getDefault().getSystemColor( SWT.COLOR_YELLOW ).getRGB();
65         FontData[] fontData = Display.getDefault().getSystemFont().getFontData();
66         FontData fontDataNormal = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.NORMAL );
67         FontData fontDataItalic = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.ITALIC );
68         FontData fontDataBold = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.BOLD );
69         FontData fontDataBoldItalic = new FontData( fontData[0].getName(), fontData[0].getHeight(), SWT.BOLD
70             | SWT.ITALIC );
71         // Attributes colors and fonts
72
PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_OBJECTCLASS_COLOR, rgbBlack );
73         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_OBJECTCLASS_FONT, fontDataBoldItalic );
74         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_COLOR, rgbBlack );
75         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_FONT, fontDataBold );
76         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_COLOR, rgbBlack );
77         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_FONT, fontDataNormal );
78         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_OPERATIONALATTRIBUTE_COLOR, rgbBlack );
79         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_OPERATIONALATTRIBUTE_FONT, fontDataItalic );
80         // Error/Warning colors and fonts
81
PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_WARNING_FONT, fontDataBoldItalic );
82         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_WARNING_COLOR, rgbYellow );
83         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_ERROR_FONT, fontDataBoldItalic );
84         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_ERROR_COLOR, rgbRed );
85         // Quick filter background colors and fonts
86
PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_QUICKFILTER_FONT, fontDataBold );
87         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_QUICKFILTER_BACKGROUND_COLOR, rgbYellow );
88         PreferenceConverter.setDefault( store, BrowserCommonConstants.PREFERENCE_QUICKFILTER_FOREGROUND_COLOR, rgbBlack );
89
90         // Attributes
91
store.setDefault( BrowserCommonConstants.PREFERENCE_SHOW_RAW_VALUES, false );
92
93         // Value Editors
94
Collection JavaDoc<AttributeValueProviderRelation> avprs = new ArrayList JavaDoc<AttributeValueProviderRelation>();
95         Collection JavaDoc<SyntaxValueProviderRelation> svprs = new ArrayList JavaDoc<SyntaxValueProviderRelation>();
96         Collection JavaDoc<ValueEditorExtension> valueEditorProxys = ValueEditorManager.getValueEditorProxys();
97         for ( ValueEditorExtension proxy : valueEditorProxys )
98         {
99             for ( String JavaDoc attributeType : proxy.attributeTypes )
100             {
101                 AttributeValueProviderRelation avpr = new AttributeValueProviderRelation( attributeType,
102                     proxy.className );
103                 avprs.add( avpr );
104             }
105             for ( String JavaDoc syntaxOid : proxy.syntaxOids )
106             {
107                 SyntaxValueProviderRelation svpr = new SyntaxValueProviderRelation( syntaxOid, proxy.className );
108                 svprs.add( svpr );
109             }
110         }
111         BrowserCommonActivator.getDefault().getValueEditorsPreferences().setDefaultAttributeValueProviderRelations(
112             avprs.toArray( new AttributeValueProviderRelation[0] ) );
113         BrowserCommonActivator.getDefault().getValueEditorsPreferences().setDefaultSyntaxValueProviderRelations(
114             svprs.toArray( new SyntaxValueProviderRelation[0] ) );
115
116         // Browser
117
store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_EXPAND_BASE_ENTRIES, false );
118         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENABLE_FOLDING, true );
119         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_FOLDING_SIZE, 100 );
120         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_LABEL, BrowserCommonConstants.SHOW_RDN );
121         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE, true );
122         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_ENTRY_ABBREVIATE_MAX_LENGTH, 50 );
123         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_LABEL, BrowserCommonConstants.SHOW_DN );
124         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE, true );
125         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SEARCH_RESULT_ABBREVIATE_MAX_LENGTH, 50 );
126         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIT, true );
127         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_SEARCHES, true );
128         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_BOOKMARKS, true );
129         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SHOW_DIRECTORY_META_ENTRIES, false );
130         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_BY, BrowserCoreConstants.SORT_BY_RDN_VALUE );
131         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_ORDER, BrowserCoreConstants.SORT_ORDER_ASCENDING );
132         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_SORT_LIMIT, 10000 );
133         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_LEAF_ENTRIES_FIRST, true );
134         store.setDefault( BrowserCommonConstants.PREFERENCE_BROWSER_META_ENTRIES_LAST, true );
135
136         // Entry Editor
137
store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_ENABLE_FOLDING, true );
138         store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_FOLDING_THRESHOLD, 10 );
139         store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OBJECTCLASS_ATTRIBUTES, true );
140         store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MUST_ATTRIBUTES, true );
141         store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_MAY_ATTRIBUTES, true );
142         store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_SHOW_OPERATIONAL_ATTRIBUTES, false );
143         store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OBJECTCLASS_AND_MUST_ATTRIBUTES_FIRST, true );
144         store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_OPERATIONAL_ATTRIBUTES_LAST, true );
145         store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_BY,
146             BrowserCoreConstants.SORT_BY_ATTRIBUTE_DESCRIPTION );
147         store.setDefault( BrowserCommonConstants.PREFERENCE_ENTRYEDITOR_DEFAULT_SORT_ORDER,
148             BrowserCoreConstants.SORT_ORDER_ASCENDING );
149
150         
151
152         // Text Format
153
store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_ATTRIBUTEDELIMITER, "\t" );
154         store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_VALUEDELIMITER, "|" );
155         store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_QUOTECHARACTER, "\"" );
156         store
157             .setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_LINESEPARATOR, BrowserCoreConstants.LINE_SEPARATOR );
158         store.setDefault( BrowserCommonConstants.PREFERENCE_FORMAT_TABLE_BINARYENCODING,
159             BrowserCoreConstants.BINARYENCODING_IGNORE );
160     }
161
162 }
163
Popular Tags