Changeset 3883


Ignore:
Timestamp:
Jul 28, 2008, 2:38:35 PM (12 years ago)
Author:
yura
Message:
  • New RfpPRojectPreferences.
Location:
devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/RfpEditor.java

    r3875 r3883  
    127127        if (input instanceof IFileEditorInput) {
    128128            IProject project = ((IFileEditorInput) input).getFile().getProject();
    129             stores.add(RfpUI.getProjectPropertiesStore(project));
     129            stores.add(RfpUI.getProjectPreferenceStore(project));
    130130        }
    131131
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/RfpUI.java

    r3879 r3883  
    11package org.refal.rfpdt.ui;
    2 
    3 import java.util.HashMap;
    42
    53import org.eclipse.core.resources.IProject;
     
    1311import org.eclipse.ui.IWorkbenchWindow;
    1412import org.eclipse.ui.plugin.AbstractUIPlugin;
    15 import org.eclipse.ui.preferences.ScopedPreferenceStore;
    16 import org.osgi.framework.BundleContext;
    1713import org.refal.rfpdt.core.RfpCore;
    1814import org.refal.rfpdt.editor.RfpPartitionScanner;
    19 import org.refal.rfpdt.ui.preferences.ProjectPropertiesStore;
    2015import org.refal.rfpdt.ui.preferences.RfpProjectPreferences;
    2116
     
    3227    // The shared instance
    3328    private static RfpUI plugin = null;
    34     private static HashMap<IProject, ProjectPropertiesStore> stores = null;
    3529    private static RfpPartitionScanner partitionScanner = null;
    3630
     
    6256    }
    6357
    64     /*
    65      * (non-Javadoc)
    66      *
    67      * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
    68      */
    69     public void start (BundleContext context) throws Exception {
    70         super.start(context);
    71         stores = new HashMap<IProject, ProjectPropertiesStore>();
    72     }
    73 
    74     /*
    75      * (non-Javadoc)
    76      *
    77      * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
    78      */
    79     public void stop (BundleContext context) throws Exception {
    80         for (ScopedPreferenceStore store : stores.values())
    81             store.save();
    82         stores = null;
    83         super.stop(context);
    84     }
     58    // public void start (BundleContext context) throws Exception {
     59    // super.start(context);
     60    // }
     61    //
     62    // public void stop (BundleContext context) throws Exception {
     63    // for (ScopedPreferenceStore store : stores.values())
     64    // store.save();
     65    // super.stop(context);
     66    // }
    8567
    8668    /**
     
    128110    }
    129111
    130     public static ProjectPropertiesStore getProjectPropertiesStore (IProject project) {
    131         if (stores == null)
    132             return null;
    133         ProjectPropertiesStore store = stores.get(project);
    134         if (store == null) {
    135             store = new ProjectPropertiesStore(project);
    136             stores.put(project, store);
    137         }
    138         return store;
    139     }
    140     public static RfpProjectPreferences getRfpProjectPreferences (IProject project, String qualifier) {
    141         return new RfpProjectPreferences(RfpCore.getRfpProject(project), qualifier);       
     112    public static RfpProjectPreferences getProjectPreferenceStore (IProject project) {
     113        return new RfpProjectPreferences(RfpCore.getRfpProject(project), PLUGIN_ID);       
    142114    }
    143115
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/preferences/CodeStylePreferencePage.java

    r3881 r3883  
    11package org.refal.rfpdt.ui.preferences;
    22
    3 import org.refal.rfpdt.ui.preferences.SyntaxColoringPreferencePage.ModifiableBooleanFieldEditor;
    4 import org.refal.rfpdt.ui.preferences.SyntaxColoringPreferencePage.ModifiableIntegerFieldEditor;
     3import org.eclipse.jface.preference.BooleanFieldEditor;
     4import org.eclipse.jface.preference.IntegerFieldEditor;
     5import org.eclipse.swt.SWT;
     6import org.eclipse.swt.layout.GridData;
     7import org.eclipse.swt.layout.GridLayout;
     8import org.eclipse.swt.widgets.Composite;
     9import org.eclipse.swt.widgets.Control;
     10import org.eclipse.swt.widgets.Group;
    511
    612public class CodeStylePreferencePage extends PropertiesAndPreferencePage {
    7     private ModifiableBooleanFieldEditor booleanFieldEditor;
    8     private ModifiableIntegerFieldEditor integerFieldEditor;
     13    private static String[] keys = new String[] { IPreferenceConstants.SPACES_FOR_TABS, IPreferenceConstants.TAB_WIDTH };
    914
    1015    protected String propertiesUrl () {
     
    1621    }
    1722
    18     protected void createFields () {
    19         booleanFieldEditor = new ModifiableBooleanFieldEditor(IPreferenceConstants.SPACES_FOR_TABS,
     23    protected String[] keys () {
     24        return keys;
     25    }
     26
     27    protected Control createFields (Composite parent) {
     28        Composite mainComposite = new Composite(parent, SWT.NONE);
     29        GridLayout layout = new GridLayout();
     30        layout.marginHeight = 0;
     31        layout.marginWidth = 0;
     32        mainComposite.setLayout(layout);
     33        mainComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
     34
     35        Group group = new Group(mainComposite, SWT.NONE);
     36        group.setText("Formatter settings");
     37        layout = new GridLayout();
     38        group.setLayout(layout);
     39        group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
     40
     41        Composite codeStyle = new Composite(group, SWT.NONE);
     42        codeStyle.setLayout(new GridLayout());
     43        codeStyle.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
     44
     45        BooleanFieldEditor booleanFieldEditor = new BooleanFieldEditor(IPreferenceConstants.SPACES_FOR_TABS,
    2046                "Use spaces instead of tabs for indentation", codeStyle);
    21         integerFieldEditor = new ModifiableIntegerFieldEditor(IPreferenceConstants.TAB_WIDTH, "Indentation size:",
    22                 codeStyle);
     47        IntegerFieldEditor integerFieldEditor = new IntegerFieldEditor(IPreferenceConstants.TAB_WIDTH,
     48                "Indentation size:", codeStyle);
    2349        integerFieldEditor.setValidRange(1, 16);
    2450        addField(booleanFieldEditor);
    2551        addField(integerFieldEditor);
    26     }
    2752
    28     protected void loadDefaults () {
    29         booleanFieldEditor.setBooleanValue(store.getBoolean(booleanFieldEditor.getPreferenceName()));
    30         integerFieldEditor.setIntValue(store.getInt(integerFieldEditor.getPreferenceName()));
     53        return mainComposite;
    3154    }
    3255}
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/preferences/CompilerPreferencePage.java

    r3881 r3883  
    11package org.refal.rfpdt.ui.preferences;
    22
    3 import org.refal.rfpdt.ui.preferences.SyntaxColoringPreferencePage.ModifiableBooleanFieldEditor;
     3import org.eclipse.jface.preference.BooleanFieldEditor;
     4import org.eclipse.swt.SWT;
     5import org.eclipse.swt.layout.GridData;
     6import org.eclipse.swt.layout.GridLayout;
     7import org.eclipse.swt.widgets.Composite;
     8import org.eclipse.swt.widgets.Control;
     9import org.eclipse.swt.widgets.Group;
    410
    511public class CompilerPreferencePage extends PropertiesAndPreferencePage {
    6     private ModifiableBooleanFieldEditor varNamesFieldEditor;
    7     private ModifiableBooleanFieldEditor lineNumbersFieldEditor;
    8     private ModifiableBooleanFieldEditor sourceFieldEditor;
     12    private static String[] keys = new String[] { IPreferenceConstants.COMPILER_ADD_VARIABLE_NAMES,
     13            IPreferenceConstants.COMPILER_ADD_LINE_NUMBERS, IPreferenceConstants.COMPILER_ADD_SOURCE };
    914
    1015    protected String propertiesUrl () {
     
    1621    }
    1722
    18     protected void createFields () {
    19         varNamesFieldEditor = new ModifiableBooleanFieldEditor(IPreferenceConstants.COMPILER_ADD_VARIABLE_NAMES,
     23    protected String[] keys () {
     24        return keys;
     25    }
     26
     27    protected Control createFields (Composite parent) {
     28        Composite mainComposite = new Composite(parent, SWT.NONE);
     29        GridLayout layout = new GridLayout();
     30        layout.marginHeight = 0;
     31        layout.marginWidth = 0;
     32        mainComposite.setLayout(layout);
     33        mainComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
     34
     35        Group group = new Group(mainComposite, SWT.NONE);
     36        group.setText("Compiler settings");
     37        layout = new GridLayout();
     38        group.setLayout(layout);
     39        group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
     40
     41        Composite codeStyle = new Composite(group, SWT.NONE);
     42        codeStyle.setLayout(new GridLayout());
     43        codeStyle.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
     44
     45        BooleanFieldEditor varNamesFieldEditor = new BooleanFieldEditor(
     46                IPreferenceConstants.COMPILER_ADD_VARIABLE_NAMES,
    2047                "Add variable attributes to generated class files (used by the debugger)", codeStyle);
    21         lineNumbersFieldEditor = new ModifiableBooleanFieldEditor(IPreferenceConstants.COMPILER_ADD_LINE_NUMBERS,
     48        BooleanFieldEditor lineNumbersFieldEditor = new BooleanFieldEditor(
     49                IPreferenceConstants.COMPILER_ADD_LINE_NUMBERS,
    2250                "Add line number to generated class files (used by the debugger)", codeStyle);
    23         sourceFieldEditor = new ModifiableBooleanFieldEditor(IPreferenceConstants.COMPILER_ADD_SOURCE,
     51        BooleanFieldEditor sourceFieldEditor = new BooleanFieldEditor(IPreferenceConstants.COMPILER_ADD_SOURCE,
    2452                "Add source file name to generated class files (used by the debugger)", codeStyle);
    2553        addField(varNamesFieldEditor);
    2654        addField(lineNumbersFieldEditor);
    2755        addField(sourceFieldEditor);
    28     }
    2956
    30     protected void loadDefaults () {
    31         varNamesFieldEditor.setBooleanValue(store.getBoolean(varNamesFieldEditor.getPreferenceName()));
    32         lineNumbersFieldEditor.setBooleanValue(store.getBoolean(lineNumbersFieldEditor.getPreferenceName()));
    33         sourceFieldEditor.setBooleanValue(store.getBoolean(sourceFieldEditor.getPreferenceName()));
     57        return mainComposite;
    3458    }
    3559}
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/preferences/PropertiesAndPreferencePage.java

    r3882 r3883  
    11package org.refal.rfpdt.ui.preferences;
    22
     3import java.io.IOException;
    34import java.util.ArrayList;
    45
     
    1213import org.eclipse.jface.dialogs.MessageDialog;
    1314import org.eclipse.jface.preference.FieldEditorPreferencePage;
    14 import org.eclipse.jface.preference.IPreferenceStore;
    1515import org.eclipse.jface.window.Window;
    1616import org.eclipse.swt.SWT;
     
    2121import org.eclipse.swt.layout.GridLayout;
    2222import org.eclipse.swt.widgets.Composite;
    23 import org.eclipse.swt.widgets.Group;
     23import org.eclipse.swt.widgets.Control;
    2424import org.eclipse.swt.widgets.Label;
    2525import org.eclipse.swt.widgets.Link;
     
    3939    private SelectionListener projectSpecificListner;
    4040    private ModifiableBooleanFieldEditor projectPropertiesField;
    41     private ControlEnableState fBlockEnableState;
    42 
    43     protected IPreferenceStore store;
    44     protected Composite codeStyle;
     41    private Control control;
     42    private ControlEnableState controlEnableState;
     43    private RfpProjectPreferences store;
    4544
    4645    public PropertiesAndPreferencePage () {
    4746        super(GRID);
    48         store = RfpUI.getPluginPreferenceStore();
    49         setPreferenceStore(store);
     47        setPreferenceStore(RfpUI.getPluginPreferenceStore());
    5048    }
    5149
     
    5452    protected abstract String preferenceUrl ();
    5553
    56     protected abstract void createFields ();
    57 
    58     protected abstract void loadDefaults ();
    59    
     54    protected abstract Control createFields (Composite parent);
     55
     56    protected abstract String[] keys ();
     57
    6058    private void enableFields () {
    61         if (fBlockEnableState != null) {
    62             fBlockEnableState.restore();
    63             fBlockEnableState= null;
     59        if (controlEnableState != null) {
     60            controlEnableState.restore();
     61            controlEnableState = null;
    6462        }
    6563    }
    6664
    6765    private void disableFields () {
    68         if (fBlockEnableState == null)
    69             fBlockEnableState= ControlEnableState.disable(getFieldEditorParent());
     66        if (controlEnableState == null)
     67            controlEnableState = ControlEnableState.disable(control);
    7068    }
    7169
    7270    protected void performDefaults () {
    7371        super.performDefaults();
    74         if (projectSpecificListner != null) {
     72        if (projectSpecificListner != null)
    7573            disableFields();
    76             loadDefaults();
    77         }
     74    }
     75
     76    public boolean performOk () {
     77        if (projectPropertiesField != null) {
     78            if (projectPropertiesField.getBooleanValue()) {
     79                store.init(keys());
     80                boolean res = super.performOk();
     81                try {
     82                    store.save();
     83                } catch (IOException e) {
     84                    RfpUI.log(e);
     85                }
     86                return res;
     87            } else {
     88                store.clear(keys());
     89                try {
     90                    store.save();
     91                } catch (IOException e) {
     92                    RfpUI.log(e);
     93                }
     94                return true;
     95            }
     96        } else
     97            return super.performOk();
    7898    }
    7999
     
    157177
    158178    public void createFieldEditors () {
    159         final Composite parent = getFieldEditorParent();
    160 
    161         Composite mainComposite = parent;//new Composite(parent, SWT.NONE);
    162         GridLayout layout = new GridLayout();
    163         layout.marginHeight = 0;
    164         layout.marginWidth = 0;
    165         mainComposite.setLayout(layout);
    166         mainComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    167 
    168         Group group = new Group(mainComposite, SWT.NONE);
    169         group.setText("Formatter settings");
    170         layout = new GridLayout();
    171         group.setLayout(layout);
    172         group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    173 
    174         codeStyle = new Composite(group, SWT.NONE);
    175         codeStyle.setLayout(new GridLayout());
    176         codeStyle.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    177 
    178         createFields();
    179 
     179        Composite parent = getFieldEditorParent();
     180        control = createFields(parent);
    180181        Dialog.applyDialogFont(parent);
    181182    }
     
    189190    public void setElement (IAdaptable element) {
    190191        project = (IProject) element.getAdapter(IResource.class);
    191         ProjectPropertiesStore projectStore = RfpUI.getProjectPropertiesStore(project);
    192         setPreferenceStore(projectStore);
     192        store = RfpUI.getProjectPreferenceStore(project);
     193        setPreferenceStore(store);
    193194    }
    194195
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/preferences/RfpProjectPreferences.java

    r3879 r3883  
    44
    55import org.eclipse.core.runtime.ListenerList;
    6 import org.eclipse.core.runtime.preferences.DefaultScope;
    76import org.eclipse.core.runtime.preferences.IEclipsePreferences;
    87import org.eclipse.jface.preference.IPersistentPreferenceStore;
     8import org.eclipse.jface.preference.IPreferenceStore;
    99import org.eclipse.jface.util.IPropertyChangeListener;
    1010import org.eclipse.jface.util.PropertyChangeEvent;
     
    1818    private final IEclipsePreferences.IPreferenceChangeListener preferenceListner;
    1919    private final ListenerList listeners;
    20     private final IEclipsePreferences defaultPref;
     20    private final IPreferenceStore defaultStore;
    2121
    2222    private void firePropertyChangeEvent (IEclipsePreferences.PreferenceChangeEvent event) {
     
    3939        };
    4040        listeners = new ListenerList(ListenerList.IDENTITY);
    41         defaultPref = new DefaultScope().getNode(qualifier);
     41        defaultStore = RfpUI.getPluginPreferenceStore();
    4242    }
    43    
     43
    4444    public void init (String[] keys) {
    4545        for (String key : keys)
    4646            setToDefault(key);
    47        
    4847    }
    4948
    50     public void clear () {
    51         try {
    52             preference.clear();
    53         } catch (BackingStoreException e) {
    54             RfpUI.log(e);
    55         }
     49    public void clear (String[] keys) {
     50        for (String key : keys)
     51            preference.remove(key);
    5652    }
    57    
     53
    5854    public void addPropertyChangeListener (IPropertyChangeListener listener) {
    5955        if (listeners.size() == 0)
     
    8076
    8177    public boolean getDefaultBoolean (String key) {
    82         return defaultPref.getBoolean(key, BOOLEAN_DEFAULT_DEFAULT);
     78        return defaultStore.getBoolean(key);
    8379    }
    8480
    8581    public double getDefaultDouble (String key) {
    86         return defaultPref.getDouble(key, DOUBLE_DEFAULT_DEFAULT);
     82        return defaultStore.getDouble(key);
    8783    }
    8884
    8985    public float getDefaultFloat (String key) {
    90         return defaultPref.getFloat(key, FLOAT_DEFAULT_DEFAULT);
     86        return defaultStore.getFloat(key);
    9187    }
    9288
    9389    public int getDefaultInt (String key) {
    94         return defaultPref.getInt(key, INT_DEFAULT_DEFAULT);
     90        return defaultStore.getInt(key);
    9591    }
    9692
    9793    public long getDefaultLong (String key) {
    98         return defaultPref.getLong(key, LONG_DEFAULT_DEFAULT);
     94        return defaultStore.getLong(key);
    9995    }
    10096
    10197    public String getDefaultString (String key) {
    102         return defaultPref.get(key, STRING_DEFAULT_DEFAULT);
     98        return defaultStore.getString(key);
    10399    }
    104100
     
    165161
    166162    public void setToDefault (String key) {
    167         preference.put(key, defaultPref.get(key, STRING_DEFAULT_DEFAULT));
     163        preference.put(key, defaultStore.getString(key));
    168164    }
    169165
     
    196192            preference.flush();
    197193        } catch (BackingStoreException e) {
    198             RfpUI.log(e);
     194            throw new IOException(e.getMessage());
    199195        }
    200196    }
Note: See TracChangeset for help on using the changeset viewer.