Ignore:
Timestamp:
03/07/06 11:38:07 (19 years ago)
Author:
boris
Message:
  • added 'custon omc-path setting'
  • redone the modelica preference page a bit
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/org.modelica.mdt.ui/src/org/modelica/mdt/ui/preferences/ModelicaPreferencePage.java

    r388 r396  
    4242package org.modelica.mdt.ui.preferences;
    4343
    44 import org.eclipse.jface.preference.BooleanFieldEditor;
    45 import org.eclipse.jface.preference.FieldEditorPreferencePage;
     44import org.eclipse.jface.preference.IPreferenceStore;
     45import org.eclipse.jface.preference.PreferencePage;
     46import org.eclipse.swt.SWT;
     47import org.eclipse.swt.events.SelectionAdapter;
     48import org.eclipse.swt.events.SelectionEvent;
     49import org.eclipse.swt.layout.GridData;
     50import org.eclipse.swt.layout.GridLayout;
     51import org.eclipse.swt.widgets.Button;
     52import org.eclipse.swt.widgets.Composite;
     53import org.eclipse.swt.widgets.Control;
     54import org.eclipse.swt.widgets.FileDialog;
     55import org.eclipse.swt.widgets.Group;
     56import org.eclipse.swt.widgets.Label;
     57import org.eclipse.swt.widgets.Text;
    4658import org.eclipse.ui.IWorkbench;
    4759import org.eclipse.ui.IWorkbenchPreferencePage;
     
    5365 * configuring MDT.
    5466 */
    55 public class ModelicaPreferencePage extends FieldEditorPreferencePage
    56     implements IWorkbenchPreferencePage {
    57 
    58     public ModelicaPreferencePage()
    59     {
    60         super(GRID);
     67public class ModelicaPreferencePage extends PreferencePage
     68    implements IWorkbenchPreferencePage
     69{
     70
     71    private Button displayCompErrors;
     72    private Button useStandardOmcPath;
     73    private Button useCustomOmcPath;
     74    private Text customOmcPath;
     75    private Button browseButton;
     76   
     77    @Override
     78    protected Control createContents(Composite grandParent)
     79    {
     80        Composite parent = new Composite(grandParent, SWT.NULL);
     81
     82        /* Create a data that takes up the extra space in the dialog */
     83        GridData data = new GridData(GridData.FILL_HORIZONTAL);
     84        data.grabExcessHorizontalSpace = true;
     85        parent.setLayoutData(data);
     86
     87        GridLayout layout = new GridLayout();
     88        parent.setLayout(layout);           
     89
     90        /* page 'title' */
     91        Label label = new Label(parent, SWT.NONE);
     92        label.setText("Settings for Modelica development:");
     93       
     94        /*
     95         * 'error reportting settings' group
     96         */
     97       
     98        /* dummy label for space */
     99        new Label(parent, SWT.NONE);
     100       
     101        Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
     102        group.setText("Error reporting settings");
     103       
     104        data = new GridData(GridData.FILL_HORIZONTAL);
     105        data.grabExcessHorizontalSpace = true;
     106        group.setLayoutData(data);
     107       
     108        layout = new GridLayout();
     109        group.setLayout(layout);
     110
     111        displayCompErrors = new Button(group, SWT.CHECK);
     112        displayCompErrors.setText("Display internal &compatibility errors");
     113
     114        data = new GridData(GridData.FILL_HORIZONTAL);
     115        data.grabExcessHorizontalSpace = true;
     116        displayCompErrors.setLayoutData(data);
     117       
     118        displayCompErrors.setSelection(PreferenceManager.getDisplayCompErrors());
     119       
     120        /*
     121         * 'OMC path' group
     122         */
     123       
     124        /* dummy label for space */
     125        new Label(parent, SWT.NONE);
     126       
     127        group = new Group(parent, SWT.SHADOW_ETCHED_IN);
     128        group.setText("OpenModelica Compiler (OMC) Path");
     129       
     130        data = new GridData(GridData.FILL_HORIZONTAL);
     131        data.grabExcessHorizontalSpace = true;
     132        group.setLayoutData(data);
     133       
     134        layout = new GridLayout();
     135        layout.numColumns = 2;
     136        group.setLayout(layout);
     137       
     138        /* use standard path option */
     139        useStandardOmcPath = new Button(group, SWT.RADIO);
     140        useStandardOmcPath.setText("use OPENMODELICAHOME environment variable");
     141
     142        data = new GridData(GridData.FILL_HORIZONTAL);
     143        data.grabExcessHorizontalSpace = true;
     144        data.horizontalSpan = 2;
     145        useStandardOmcPath.setLayoutData(data);
     146       
     147        useStandardOmcPath.setSelection(PreferenceManager.getUseStandardOmcPath());
     148               
     149        /* use custom path option */
     150        useCustomOmcPath = new Button(group, SWT.RADIO);
     151        useCustomOmcPath.setText("use custom path:");
     152
     153        useCustomOmcPath.setSelection(!PreferenceManager.getUseStandardOmcPath());
     154               
     155        data = new GridData(GridData.FILL_HORIZONTAL);     
     156        data.grabExcessHorizontalSpace = true;
     157        data.horizontalSpan = 2;
     158        useCustomOmcPath.setLayoutData(data);
     159       
     160        customOmcPath = new Text(group, SWT.SINGLE | SWT.BORDER | SWT.LEFT);
     161        data = new GridData(GridData.HORIZONTAL_ALIGN_FILL |
     162                    GridData.GRAB_HORIZONTAL);
     163        customOmcPath.setLayoutData(data);
     164
     165        customOmcPath.setText(PreferenceManager.getCustomOmcPath());
     166        customOmcPath.setEnabled(useCustomOmcPath.getSelection());
     167       
     168        browseButton = new Button(group, SWT.PUSH);
     169        browseButton.setText("Browse...");
     170                   
     171        data = new GridData();
     172        data.horizontalAlignment = GridData.END;
     173        browseButton.setLayoutData(data);
     174       
     175        browseButton.setEnabled(useCustomOmcPath.getSelection());
     176
     177        /* setup the interactive widget business logic, yeah, multitiers application baby ! */
     178        useCustomOmcPath.addSelectionListener(new SelectionAdapter()
     179                {
     180                    public void widgetSelected(SelectionEvent e)
     181                    {
     182                        customOmcPath.setEnabled(true);
     183                        browseButton.setEnabled(true);
     184                    }
     185                });
     186
     187        useStandardOmcPath.addSelectionListener(new SelectionAdapter()
     188                {
     189                    public void widgetSelected(SelectionEvent e)
     190                    {
     191                        customOmcPath.setEnabled(false);
     192                        browseButton.setEnabled(false);
     193                    }
     194                });
     195
     196        browseButton.addSelectionListener(new SelectionAdapter()
     197                {
     198                    public void widgetSelected(SelectionEvent e)
     199                    {
     200                        FileDialog dialog = new FileDialog(getShell());
     201                        dialog.setText("pick OMC binary");
     202                        String res = dialog.open();
     203                       
     204                        if (res != null)
     205                        {
     206                            customOmcPath.setText(res);
     207                        }
     208                    }
     209                });
     210       
     211       
     212        return parent;
     213    }
     214   
     215    public void init(IWorkbench workbench)
     216    {
    61217        setPreferenceStore(CorePlugin.getDefault().getPreferenceStore());
    62         setDescription("Settings for Modelica development:");
    63     }
    64    
    65     public void createFieldEditors()
    66     {
    67         /* the 'toggle compatibility errors' switch */
    68         addField(
    69             new BooleanFieldEditor(
    70                 PreferenceManager.DISPLAY_COMPATIBILTY_ERRORS,
    71                 "Display internal &compatibility errors",
    72                 getFieldEditorParent()));
    73     }
    74    
    75     public void init(IWorkbench workbench)
    76     {
    77         /* NOP */
     218    }
     219   
     220    protected void performDefaults()
     221    {
     222        IPreferenceStore store = getPreferenceStore();
     223        /*
     224         * reset widgets to default settings
     225         */
     226        displayCompErrors.setSelection
     227            (store.getDefaultBoolean(PreferenceManager.DISPLAY_COMPATIBILTY_ERRORS));
     228        useStandardOmcPath.setSelection
     229            (store.getDefaultBoolean(PreferenceManager.USE_STANDARD_OMC_PATH));
     230        useCustomOmcPath.setSelection
     231            (!store.getDefaultBoolean(PreferenceManager.USE_STANDARD_OMC_PATH));
     232        customOmcPath.setEnabled(useCustomOmcPath.getSelection());
     233        browseButton.setEnabled(useCustomOmcPath.getSelection());
     234        customOmcPath.setText(store.getDefaultString(PreferenceManager.CUSTOM_OMC_PATH));
     235
     236    }
     237
     238   
     239    public boolean performOk()
     240    {
     241        /*
     242         * save settings to the store
     243         */
     244        IPreferenceStore store = getPreferenceStore();
     245       
     246        store.setValue(PreferenceManager.DISPLAY_COMPATIBILTY_ERRORS,
     247                displayCompErrors.getSelection());
     248        store.setValue(PreferenceManager.USE_STANDARD_OMC_PATH,
     249                useStandardOmcPath.getSelection());
     250        store.setValue(PreferenceManager.CUSTOM_OMC_PATH,
     251                customOmcPath.getText());
     252
     253        return true;
    78254    }
    79255}
Note: See TracChangeset for help on using the changeset viewer.