View Javadoc

1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2006, Ontotext Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2006</p>
22   * <p>Company: Ontotext Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.grounding.sawsdl.preferences;
26  
27  import org.eclipse.jface.preference.ColorFieldEditor;
28  import org.eclipse.jface.preference.FieldEditorPreferencePage;
29  import org.eclipse.jface.preference.PreferenceConverter;
30  import org.eclipse.swt.graphics.RGB;
31  import org.eclipse.swt.layout.*;
32  import org.eclipse.ui.*;
33  import org.wsmostudio.grounding.sawsdl.ui.UiPlugin;
34  import org.wsmostudio.grounding.sawsdl.ui.text.IXMLColorConstants;
35  import org.wsmostudio.grounding.sawsdl.ui.text.SAWSDLTextEditor;
36  import org.wsmostudio.preferences.TextStyleFieldEditor;
37  
38  /***
39   * A preference page which defines different colors for the syntax highlighting in the
40   * SAWSDL Text editor.
41   *
42   * @author not attributable
43   * @version $Revision: 1216 $ $Date: 2007-07-02 16:12:08 +0300 $
44   */
45  
46  public class SAWSDLTextEditorColorsPage extends FieldEditorPreferencePage 
47  implements IWorkbenchPreferencePage {
48  
49      private static final String ATTR_VAL_COLOR_KEY = "$SAWSDLTextEditor$attrVal_color";
50      private static final String TEXT_COLOR_KEY = "$SAWSDLTextEditor$text_color";
51      private static final String TAG_COLOR_KEY = "$SAWSDLTextEditor$tag_color";
52      private static final String ATTRIBUTE_COLOR_KEY = "$SAWSDLTextEditor$attr_color";
53      private static final String SAWSDL_COLOR_KEY = "$SAWSDLTextEditor$wsdl_color";
54      private static final String SAWSDL_DATA_COLOR_KEY = "$SAWSDLTextEditor$wsdldata_color";
55      
56      static final String STYLE_SUFFIX = "_style";
57      
58      private ColorFieldEditor attrValsChooser,
59                               textChooser,
60                               tagsChooser,
61                               attributesChooser,
62                               sawsdlChooser,
63                               sawsdlDataChooser;
64      
65      public SAWSDLTextEditorColorsPage() {
66          super("SAWSDL Text Editor Syntax Coloring", FieldEditorPreferencePage.GRID);
67          setPreferenceStore(UiPlugin.getDefault().getPreferenceStore());
68          initColors();
69      }
70      
71      protected void createFieldEditors() {
72          
73          getFieldEditorParent().setLayout(new GridLayout(4, false));
74  
75          sawsdlChooser = new TextStyleFieldEditor(SAWSDL_COLOR_KEY, "SAWSDL Attributes : ", getFieldEditorParent());
76          addField(sawsdlChooser);
77  
78          sawsdlDataChooser = new TextStyleFieldEditor(SAWSDL_DATA_COLOR_KEY, "SAWSDL Content : ", getFieldEditorParent());
79          addField(sawsdlDataChooser);
80  
81          tagsChooser = new TextStyleFieldEditor(TAG_COLOR_KEY, "Tags : ", getFieldEditorParent());
82          addField(tagsChooser);
83  
84          attributesChooser = new TextStyleFieldEditor(ATTRIBUTE_COLOR_KEY, "Attributes : ", getFieldEditorParent());
85          addField(attributesChooser);
86  
87          attrValsChooser = new TextStyleFieldEditor(ATTR_VAL_COLOR_KEY, "Attribute Values : ", getFieldEditorParent());
88          addField(attrValsChooser);
89          
90          textChooser = new TextStyleFieldEditor(TEXT_COLOR_KEY, "Text content : ", getFieldEditorParent());
91          addField(textChooser);
92          
93      }
94      
95      
96      public void init(IWorkbench workbench) {
97      }
98      
99      public boolean performOk() {
100         boolean stat = super.performOk();
101         doUpdateOpenedEditors();
102         return stat;
103     }
104     
105 	protected void performDefaults() {
106         PreferenceConverter.setDefault(getPreferenceStore(), ATTR_VAL_COLOR_KEY, IXMLColorConstants.STRING);
107         PreferenceConverter.setDefault(getPreferenceStore(), TEXT_COLOR_KEY, IXMLColorConstants.DEFAULT);
108         PreferenceConverter.setDefault(getPreferenceStore(), TAG_COLOR_KEY, IXMLColorConstants.TAG);
109         PreferenceConverter.setDefault(getPreferenceStore(), ATTRIBUTE_COLOR_KEY, IXMLColorConstants.ATTRIBUTE);
110         PreferenceConverter.setDefault(getPreferenceStore(), SAWSDL_COLOR_KEY, IXMLColorConstants.SAWSDL);
111         PreferenceConverter.setDefault(getPreferenceStore(), SAWSDL_DATA_COLOR_KEY, IXMLColorConstants.SAWSDL_DATA);
112 
113         getPreferenceStore().setDefault(ATTR_VAL_COLOR_KEY + STYLE_SUFFIX, IXMLColorConstants.STRING_STYLE);
114         getPreferenceStore().setDefault(TEXT_COLOR_KEY + STYLE_SUFFIX, IXMLColorConstants.DEFAULT_STYLE);
115         getPreferenceStore().setDefault(TAG_COLOR_KEY + STYLE_SUFFIX, IXMLColorConstants.TAG_STYLE);
116         getPreferenceStore().setDefault(ATTRIBUTE_COLOR_KEY + STYLE_SUFFIX, IXMLColorConstants.ATTRIBUTE_STYLE);
117         getPreferenceStore().setDefault(SAWSDL_COLOR_KEY + STYLE_SUFFIX, IXMLColorConstants.SAWSDL_STYLE);
118         getPreferenceStore().setDefault(SAWSDL_DATA_COLOR_KEY + STYLE_SUFFIX, IXMLColorConstants.SAWSDL_DATA_STYLE);
119 
120         super.performDefaults();
121     }
122     
123     private void initColors() {
124         initColorEntry(ATTR_VAL_COLOR_KEY, IXMLColorConstants.STRING, IXMLColorConstants.STRING_STYLE);
125         initColorEntry(TEXT_COLOR_KEY, IXMLColorConstants.DEFAULT, IXMLColorConstants.DEFAULT_STYLE);
126         initColorEntry(TAG_COLOR_KEY, IXMLColorConstants.TAG, IXMLColorConstants.TAG_STYLE);
127         initColorEntry(ATTRIBUTE_COLOR_KEY, IXMLColorConstants.ATTRIBUTE, IXMLColorConstants.ATTRIBUTE_STYLE);
128         initColorEntry(SAWSDL_COLOR_KEY, IXMLColorConstants.SAWSDL, IXMLColorConstants.SAWSDL_STYLE);
129         initColorEntry(SAWSDL_DATA_COLOR_KEY, IXMLColorConstants.SAWSDL_DATA, IXMLColorConstants.SAWSDL_DATA_STYLE);
130     }
131     
132     private void doUpdateOpenedEditors() {
133 
134         IWorkbenchPage page = PlatformUI.getWorkbench()
135                                         .getActiveWorkbenchWindow()
136                                         .getActivePage();
137         if (page == null) {
138             return;
139         }
140         IEditorReference[] editors = page.getEditorReferences();
141         if (editors == null) {
142             return;
143         }
144         for(int i = 0; i < editors.length; i++) {
145             IEditorPart editor = editors[i].getEditor(true);
146             if (editor != null 
147                     && editor instanceof SAWSDLTextEditor) {
148                 ((SAWSDLTextEditor)editor).doUpdateView();
149             }
150         }
151     }
152     
153     private void initColorEntry(String key, RGB colorInfo, int style) {
154         if (getPreferenceStore().contains(key)) {
155             return;
156         }
157         PreferenceConverter.setValue(getPreferenceStore(), key, colorInfo);
158         PreferenceConverter.setDefault(getPreferenceStore(), key, colorInfo);
159         getPreferenceStore().setValue(key + STYLE_SUFFIX, style);
160         getPreferenceStore().setDefault(key + STYLE_SUFFIX, style);
161     }
162     
163     public void dispose() {
164         attrValsChooser.dispose();
165         textChooser.dispose();
166         tagsChooser.dispose();
167         attributesChooser.dispose(); 
168         sawsdlChooser.dispose(); 
169         sawsdlDataChooser.dispose(); 
170     }
171 
172     public static RGB getAttrValuesColor() {
173         if (false == UiPlugin.getDefault().getPreferenceStore().contains(ATTR_VAL_COLOR_KEY)) {
174             return IXMLColorConstants.STRING;
175         }
176         return PreferenceConverter.getColor(UiPlugin.getDefault().getPreferenceStore(), 
177                                             ATTR_VAL_COLOR_KEY);
178     }
179     public static int getAttrValuesStyle() {
180         if (false == UiPlugin.getDefault().getPreferenceStore().contains(
181                 ATTR_VAL_COLOR_KEY + STYLE_SUFFIX)) {
182             return IXMLColorConstants.STRING_STYLE;
183         }
184         return UiPlugin.getDefault().getPreferenceStore().getInt(
185                 ATTR_VAL_COLOR_KEY + STYLE_SUFFIX);
186     }
187 
188     
189     public static RGB getTextColor() {
190         if (false == UiPlugin.getDefault().getPreferenceStore().contains(TEXT_COLOR_KEY)) {
191             return IXMLColorConstants.DEFAULT;
192         }
193         return PreferenceConverter.getColor(UiPlugin.getDefault().getPreferenceStore(), 
194                                             TEXT_COLOR_KEY);
195     }
196     public static int getTextStyle() {
197         if (false == UiPlugin.getDefault().getPreferenceStore().contains(
198                 TEXT_COLOR_KEY + STYLE_SUFFIX)) {
199             return IXMLColorConstants.DEFAULT_STYLE;
200         }
201         return UiPlugin.getDefault().getPreferenceStore().getInt( 
202                 TEXT_COLOR_KEY + STYLE_SUFFIX);
203     }
204 
205     public static RGB getTagsColor() {
206         if (false == UiPlugin.getDefault().getPreferenceStore().contains(TAG_COLOR_KEY)) {
207             return IXMLColorConstants.TAG;
208         }
209         return PreferenceConverter.getColor(UiPlugin.getDefault().getPreferenceStore(), 
210                                             TAG_COLOR_KEY);
211     }
212     public static int getTagsStyle() {
213         if (false == UiPlugin.getDefault().getPreferenceStore().contains(
214                 TAG_COLOR_KEY + STYLE_SUFFIX)) {
215             return IXMLColorConstants.TAG_STYLE;
216         }
217         return UiPlugin.getDefault().getPreferenceStore().getInt( 
218                 TAG_COLOR_KEY + STYLE_SUFFIX);
219     }
220 
221     public static RGB getAttributesColor() {
222         if (false == UiPlugin.getDefault().getPreferenceStore().contains(ATTRIBUTE_COLOR_KEY)) {
223             return IXMLColorConstants.ATTRIBUTE;
224         }
225         return PreferenceConverter.getColor(UiPlugin.getDefault().getPreferenceStore(), 
226                 ATTRIBUTE_COLOR_KEY);
227     }
228     public static int getAttributesStyle() {
229         if (false == UiPlugin.getDefault().getPreferenceStore().contains(
230                 ATTRIBUTE_COLOR_KEY + STYLE_SUFFIX)) {
231             return IXMLColorConstants.ATTRIBUTE_STYLE;
232         }
233         return UiPlugin.getDefault().getPreferenceStore().getInt( 
234                 ATTRIBUTE_COLOR_KEY + STYLE_SUFFIX);
235     }
236 
237     public static RGB getSAWSDLColor() {
238         if (false == UiPlugin.getDefault().getPreferenceStore().contains(SAWSDL_COLOR_KEY)) {
239             return IXMLColorConstants.SAWSDL;
240         }
241         return PreferenceConverter.getColor(UiPlugin.getDefault().getPreferenceStore(), 
242                                             SAWSDL_COLOR_KEY);
243     }
244     public static int getSAWSDLStyle() {
245         if (false == UiPlugin.getDefault().getPreferenceStore().contains(
246                 SAWSDL_COLOR_KEY + STYLE_SUFFIX)) {
247             return IXMLColorConstants.SAWSDL_STYLE;
248         }
249         return UiPlugin.getDefault().getPreferenceStore().getInt( 
250                 SAWSDL_COLOR_KEY + STYLE_SUFFIX);
251     }
252     public static RGB getSAWSDLDataColor() {
253         if (false == UiPlugin.getDefault().getPreferenceStore().contains(SAWSDL_DATA_COLOR_KEY)) {
254             return IXMLColorConstants.SAWSDL_DATA;
255         }
256         return PreferenceConverter.getColor(UiPlugin.getDefault().getPreferenceStore(), 
257                                             SAWSDL_DATA_COLOR_KEY);
258     }
259     public static int getSAWSDLDataStyle() {
260         if (false == UiPlugin.getDefault().getPreferenceStore().contains(
261                 SAWSDL_DATA_COLOR_KEY + STYLE_SUFFIX)) {
262             return IXMLColorConstants.SAWSDL_DATA_STYLE;
263         }
264         return UiPlugin.getDefault().getPreferenceStore().getInt( 
265                 SAWSDL_DATA_COLOR_KEY + STYLE_SUFFIX);
266     }
267 
268 }
269 
270 /*
271  * $Log$
272  * Revision 1.2  2007/07/02 13:12:08  marin_dimitrov
273  * SA-WSDL --> SAWSDL
274  *
275  * Revision 1.1  2006/10/26 13:53:54  alex_simov
276  * SA-WSDL Text Editor preference page for colours & styles management added
277  *
278  */