View Javadoc

1   /*
2    * $Id: OWLEditorPreferences.java,v 1.7 2005/05/31 19:37:20 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8    
9   package com.bbn.swede.editor;
10  
11  import org.eclipse.jface.preference.BooleanFieldEditor;
12  import org.eclipse.jface.preference.FieldEditor;
13  import org.eclipse.jface.preference.FieldEditorPreferencePage;
14  import org.eclipse.jface.preference.IntegerFieldEditor;
15  import org.eclipse.jface.preference.RadioGroupFieldEditor;
16  import org.eclipse.jface.util.PropertyChangeEvent;
17  import org.eclipse.swt.layout.GridData;
18  import org.eclipse.swt.layout.GridLayout;
19  import org.eclipse.swt.widgets.Composite;
20  import org.eclipse.swt.widgets.Control;
21  import org.eclipse.swt.widgets.Group;
22  import org.eclipse.ui.IWorkbench;
23  import org.eclipse.ui.IWorkbenchPreferencePage;
24  
25  /***
26   * Preference page for the OWL editor.  Provides content formatting options.
27   * @author aperezlo
28   */
29  public class OWLEditorPreferences extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
30  {
31     private IWorkbench _workbench;
32     
33     private RadioGroupFieldEditor _attributeSplitField;
34     private BooleanFieldEditor _alignWrappedAttr;
35     private BooleanFieldEditor _alignValuesAttr;
36     private Composite _alignValuesParent;
37     private Composite _alignWrappedParent;
38     
39     /***
40      * Creates the OWL editor preferences page.
41      */
42     public OWLEditorPreferences()
43     {
44        super(FieldEditorPreferencePage.FLAT);
45     }
46     
47     
48     /* (non-Javadoc)
49      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
50      */
51     public void init(IWorkbench workbench)
52     {
53        _workbench = workbench;
54        setPreferenceStore(EditorPlugin.getPlugin().getPreferenceStore());
55     }
56  
57     /*
58      *  (non-Javadoc)
59      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
60      */
61     protected Control createContents(Composite parent)
62     {
63        Control toReturn = super.createContents(parent);
64        return toReturn;
65     }
66     
67     /* (non-Javadoc)
68      * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
69      */
70     protected void createFieldEditors()
71     {
72        String[][] splitRadioBoxValues = {
73           {"Always", String.valueOf(EditorPlugin.SPLIT_ALWAYS)},
74           {"Never", String.valueOf(EditorPlugin.SPLIT_NEVER)},
75           {"Long lines only", String.valueOf(EditorPlugin.SPLIT_LONG)},
76        };
77        String[][] delimeterRadioBoxValues = { 
78           {"Double Quote (\")", "\""},
79           {"Single Quote (')", "'"},
80        };
81        
82        addField(new IntegerFieldEditor(EditorPlugin.PREFERENCE_TAB_WIDTH,
83           "Displayed Tab Width:", getFieldEditorParent()));
84        addField(new IntegerFieldEditor(
85           EditorPlugin.PREFERENCE_MAXIMUM_LINE_LENGTH, "Print Margin Column:",
86           getFieldEditorParent()));
87        addField(new BooleanFieldEditor(
88           EditorPlugin.PREFERENCE_SUBSTITUTE_SPACES, "Insert Spaces for Tabs",
89           getFieldEditorParent()));
90        addField(new RadioGroupFieldEditor(EditorPlugin.PREFERENCE_LITERAL_SPLIT,
91           "Split literals across multiple lines:", 1, splitRadioBoxValues,
92           getFieldEditorParent(), false));
93  
94        
95        Composite attributePanel = getFieldEditorParent();
96        attributePanel.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
97           | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
98        attributePanel.setLayout(new GridLayout());
99        
100       Group attributeGroup = new Group(attributePanel, attributePanel.getStyle());
101       attributeGroup.setText("Attributes:");
102       attributeGroup.setLayout(new GridLayout());
103       
104       addField(new RadioGroupFieldEditor(
105          EditorPlugin.PREFERENCE_ATTRIBUTE_DELIMITER, "Delimeter:", 1,
106          delimeterRadioBoxValues, attributeGroup, false));
107       _attributeSplitField = new RadioGroupFieldEditor(
108          EditorPlugin.PREFERENCE_ATTRIBUTE_SPLIT,
109          "Split attributes across multiple lines:", 1, splitRadioBoxValues,
110          attributeGroup);
111       _attributeSplitField.setIndent(1);
112       
113 //      _alignWrappedParent = getFieldEditorParent();
114       _alignWrappedParent = attributeGroup;
115       _alignWrappedAttr = new BooleanFieldEditor(
116          EditorPlugin.PREFERENCE_ATTRIBUTE_ALIGN,
117          "Align wrapped attributes with tag name", _alignWrappedParent);
118       
119       _alignValuesParent = getFieldEditorParent();
120       _alignValuesParent = attributeGroup;
121       _alignValuesAttr = new BooleanFieldEditor(
122          EditorPlugin.PREFERENCE_ATTRIBUTE_ALIGN_VALUE,
123          "Align attribute values", _alignValuesParent);
124       
125       addField(_attributeSplitField);
126       addField(_alignValuesAttr);
127       addField(_alignWrappedAttr);
128 
129       _alignWrappedAttr
130          .setEnabled(
131             EditorPlugin.getPlugin().getPreferenceStore().getInt(
132                EditorPlugin.PREFERENCE_ATTRIBUTE_SPLIT) != EditorPlugin.SPLIT_NEVER,
133             _alignWrappedParent);
134       _alignValuesAttr
135          .setEnabled(
136             EditorPlugin.getPlugin().getPreferenceStore().getInt(
137                EditorPlugin.PREFERENCE_ATTRIBUTE_SPLIT) != EditorPlugin.SPLIT_NEVER,
138             _alignValuesParent);
139    }
140 
141    /*
142     *  (non-Javadoc)
143     * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
144     */
145    public void propertyChange(PropertyChangeEvent event)
146    {
147       if(((FieldEditor)event.getSource()).getPreferenceName().equals("preference-attribute-split"))
148       {
149          _alignWrappedAttr.setEnabled(!((String)event.getNewValue())
150             .equals(String.valueOf(EditorPlugin.SPLIT_NEVER)),
151             _alignWrappedParent);
152          _alignValuesAttr.setEnabled(!((String)event.getNewValue())
153             .equals(String.valueOf(EditorPlugin.SPLIT_NEVER)),
154             _alignValuesParent);
155       }
156    }
157    
158 }