Changeset 8083

Show
Ignore:
Timestamp:
07/26/08 10:38:51 (5 years ago)
Author:
stedwar2
Message:

Added preference to use Python code from a specified external "tools" directory.

Location:
ossiedev/branches/jsnyder/ComponentProject/src/edu/vt/ossie
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • ossiedev/branches/jsnyder/ComponentProject/src/edu/vt/ossie/OWDPlugin.java

    r7811 r8083  
    6969    public static final String PREF_WAVE_AUTO_INSTALL = 
    7070        PLUGIN_ID + ".preferences.component.install.auto"; 
     71    public static final String PREF_USE_EXTERNAL_TOOLS_DIR = 
     72        PLUGIN_ID + ".preferences.use.external.tools.dir"; 
     73    public static final String PREF_EXTERNAL_TOOLS_DIR = 
     74        PLUGIN_ID + ".preferences.external.tools.dir"; 
    7175 
    7276 
     
    141145                { 
    142146                        Properties pythonParams = new Properties(); 
    143                         pythonParams.setProperty("python.path", 
     147            String wavedevBase = getWavedevBase(); 
     148            pythonParams.setProperty("python.path", 
    144149                            getPluginFolder() + "/PythonSrc" 
    145150                + System.getProperty("path.separator") 
    146151                + getPluginFolder() + "/PythonSrc/WaveDev/wavedev" 
    147152                + System.getProperty("path.separator") 
    148                 + getPluginFolder() 
     153                + wavedevBase 
    149154                + System.getProperty("path.separator") 
    150                 + getPluginFolder() + "/WaveDev/wavedev"); 
     155                + wavedevBase + "/WaveDev/wavedev"); 
    151156                        pythonParams.setProperty( 
    152157                            "python.home", getPluginFolder() + "/jython2.2.1"); 
     
    167172                    "import WaveDev\n" 
    168173                    + "WaveDev.__path__.append('" 
    169                     + getPluginFolder() + "/WaveDev')" 
     174                    + wavedevBase + "/WaveDev')" 
    170175                    // + "\nprint 'WaveDev.__path__ = ', WaveDev.__path__" 
    171176                    ); 
     
    173178                    "import WaveDev.wavedev\n" 
    174179                    + "WaveDev.wavedev.__path__.append('" 
    175                     + getPluginFolder() + "/WaveDev/wavedev')" 
     180                    + wavedevBase + "/WaveDev/wavedev')" 
    176181                    // + "\nprint 'WaveDev.wavedev.__path__ = ', " 
    177182                    // + "WaveDev.wavedev.__path__" 
     
    197202            OWDPlugin.getDefault().getString( 
    198203                OWDPlugin.PREF_OSSIE_DIR))); 
    199         mainFrame.setOssiePluginHome(new PyString(getPluginFolder())); 
     204        mainFrame.setOssiePluginHome(new PyString(getWavedevBase())); 
    200205        mainFrame.setIncludePath(new PyString( 
    201206            OWDPlugin.getDefault().getString( 
     
    578583 
    579584    // ---------------------------------------------------------- 
     585    private static String getWavedevBase() 
     586    { 
     587        String wavedevBase = getPluginFolder(); 
     588        if (getDefault() != null 
     589            && getDefault().getBoolean(PREF_USE_EXTERNAL_TOOLS_DIR)) 
     590        { 
     591            wavedevBase = getDefault().getString(PREF_EXTERNAL_TOOLS_DIR); 
     592            wavedevBase = wavedevBase.replace('\\', '/') 
     593                .replaceFirst("/$", ""); 
     594        } 
     595        return wavedevBase; 
     596    } 
     597 
     598 
     599    // ---------------------------------------------------------- 
    580600    private static class OutputForwarder 
    581601        extends Thread 
  • ossiedev/branches/jsnyder/ComponentProject/src/edu/vt/ossie/PreferenceInitializer.java

    r7690 r8083  
    2121        IPreferenceStore store = OWDPlugin.getDefault().getPreferenceStore(); 
    2222        store.setDefault(OWDPlugin.PREF_OSSIE_DIR, "/sdr/"); 
    23         store.setDefault(OWDPlugin.PREF_OSSIE_INCLUDE_PATH, "/usr/local/include/ossie/"); 
    24         store.setDefault(OWDPlugin.PREF_STANDARD_IDL_PATH, "/usr/local/include/standardinterfaces/"); 
    25         store.setDefault(OWDPlugin.PREF_CUSTOM_IDL_PATH, "/usr/local/include/custominterfaces/"); 
     23        store.setDefault( 
     24            OWDPlugin.PREF_OSSIE_INCLUDE_PATH, 
     25            "/usr/local/include/ossie/"); 
     26        store.setDefault( 
     27            OWDPlugin.PREF_STANDARD_IDL_PATH, 
     28            "/usr/local/include/standardinterfaces/"); 
     29        store.setDefault( 
     30            OWDPlugin.PREF_CUSTOM_IDL_PATH, 
     31            "/usr/local/include/custominterfaces/"); 
    2632        store.setDefault(OWDPlugin.PREF_COMP_AUTO_INSTALL, true); 
    27         store.setDefault(OWDPlugin.PREF_WAVE_AUTO_INSTALL, true); 
     33        store.setDefault(OWDPlugin.PREF_USE_EXTERNAL_TOOLS_DIR, false); 
     34        store.setDefault(OWDPlugin.PREF_EXTERNAL_TOOLS_DIR, ""); 
    2835    } 
    2936 
  • ossiedev/branches/jsnyder/ComponentProject/src/edu/vt/ossie/PreferencePage.java

    r7778 r8083  
    22 
    33import org.eclipse.jface.preference.BooleanFieldEditor; 
     4import org.eclipse.jface.preference.DirectoryFieldEditor; 
     5import org.eclipse.jface.preference.FieldEditor; 
    46import org.eclipse.jface.preference.FieldEditorPreferencePage; 
    57import org.eclipse.jface.preference.IPreferenceStore; 
    68import org.eclipse.jface.preference.StringFieldEditor; 
     9import org.eclipse.jface.util.PropertyChangeEvent; 
     10import org.eclipse.swt.layout.GridData; 
     11import org.eclipse.swt.widgets.Composite; 
     12import org.eclipse.swt.widgets.Label; 
    713import org.eclipse.ui.IWorkbench; 
    814import org.eclipse.ui.IWorkbenchPreferencePage; 
     15import quicktime.app.spaces.Space; 
    916 
    1017//------------------------------------------------------------------------- 
     
    4249    protected void createFieldEditors() 
    4350    { 
    44         addField(new StringFieldEditor( 
     51        addField(new LabelFieldEditor( 
     52            "Changes only affect new editors/windows.", 
     53            getFieldEditorParent())); 
     54        addField(new SpacerFieldEditor(getFieldEditorParent())); 
     55 
     56        addField(new DirectoryFieldEditor( 
    4557            OWDPlugin.PREF_OSSIE_DIR, 
    46             "OSSIE installation directory:", 
    47             getFieldEditorParent())); 
    48         addField(new StringFieldEditor( 
     58            "OSSIE install directory:", 
     59            getFieldEditorParent())); 
     60        addField(new DirectoryFieldEditor( 
    4961            OWDPlugin.PREF_OSSIE_INCLUDE_PATH, 
    5062            "OSSIE include path:", 
    5163            getFieldEditorParent())); 
    52         addField(new StringFieldEditor( 
     64        addField(new DirectoryFieldEditor( 
    5365            OWDPlugin.PREF_STANDARD_IDL_PATH, 
    5466            "Standard IDL path:", 
    5567            getFieldEditorParent())); 
    56         addField(new StringFieldEditor( 
     68        addField(new DirectoryFieldEditor( 
    5769            OWDPlugin.PREF_CUSTOM_IDL_PATH, 
    5870            "Custom IDL path:", 
     
    6779            + "install on build", 
    6880            getFieldEditorParent())); 
     81 
     82        addField(new SpacerFieldEditor(getFieldEditorParent())); 
     83        useToolsDir = new BooleanFieldEditor( 
     84            OWDPlugin.PREF_USE_EXTERNAL_TOOLS_DIR, 
     85            "Use WaveDev code from external tools directory", 
     86            getFieldEditorParent()); 
     87        addField(useToolsDir); 
     88        toolsDirParent = getFieldEditorParent(); 
     89        toolsDir = new DirectoryFieldEditor( 
     90            OWDPlugin.PREF_EXTERNAL_TOOLS_DIR, 
     91            "External tools directory:", 
     92            toolsDirParent); 
     93        addField(toolsDir); 
     94        if (!useToolsDir.getBooleanValue()) 
     95        { 
     96            toolsDir.setEnabled(false, toolsDirParent); 
     97        } 
    6998    } 
    7099 
     
    75104        // Nothing to do 
    76105    } 
     106 
    77107 
    78108    // ---------------------------------------------------------- 
     
    83113        return super.performOk(); 
    84114    } 
     115 
     116 
     117    // ---------------------------------------------------------- 
     118    @Override 
     119    public void propertyChange(PropertyChangeEvent event) 
     120    { 
     121        super.propertyChange(event); 
     122        if (event.getSource() == useToolsDir) 
     123        { 
     124            System.out.println("propertyChange() called. tools = " 
     125                + useToolsDir.getBooleanValue()); 
     126            toolsDir.setEnabled(useToolsDir.getBooleanValue(), toolsDirParent); 
     127            checkState(); 
     128        } 
     129        else if (event.getSource() == toolsDir) 
     130        { 
     131            System.out.println("propertyChange() for tools dir"); 
     132            String value = toolsDir.getStringValue(); 
     133            if (value != null) 
     134            { 
     135                value = value.replaceFirst( 
     136                    "(\\\\|/)WaveDev((\\\\|/)wavedev)?$", ""); 
     137                toolsDir.setStringValue(value); 
     138            } 
     139            checkState(); 
     140        } 
     141    } 
     142 
     143 
     144    // ---------------------------------------------------------- 
     145    @Override 
     146    protected void checkState() 
     147    { 
     148        super.checkState(); 
     149        if (useToolsDir != null && useToolsDir.getBooleanValue()) 
     150        { 
     151            String value = toolsDir.getStringValue(); 
     152            if (value == null || "".equals(value)) 
     153            { 
     154                setErrorMessage( 
     155                    "An external tools directory must be specified."); 
     156                setValid(false); 
     157            } 
     158            else 
     159            { 
     160                setErrorMessage(null); 
     161                setValid(true); 
     162            } 
     163        } 
     164        else 
     165        { 
     166            setValid(true); 
     167            setErrorMessage(null); 
     168        } 
     169    } 
     170 
     171 
     172    // ---------------------------------------------------------- 
     173    /** 
     174     * A field editor for displaying labels not associated with other widgets. 
     175     */ 
     176    private static class LabelFieldEditor 
     177        extends FieldEditor 
     178    { 
     179        // All labels can use the same preference name since they don't 
     180        // store any preference. 
     181        public LabelFieldEditor(String value, Composite parent) 
     182        { 
     183            super("label", value, parent); 
     184        } 
     185 
     186        // Adjusts the field editor to be displayed correctly 
     187        // for the given number of columns. 
     188        protected void adjustForNumColumns(int numColumns) 
     189        { 
     190            ((GridData) label.getLayoutData()).horizontalSpan = numColumns; 
     191        } 
     192 
     193        // Fills the field editor's controls into the given parent. 
     194        protected void doFillIntoGrid(Composite parent, int numColumns) 
     195        { 
     196            label = getLabelControl(parent); 
     197 
     198            GridData gridData = new GridData(); 
     199            gridData.horizontalSpan = numColumns; 
     200            gridData.horizontalAlignment = GridData.FILL; 
     201            gridData.grabExcessHorizontalSpace = false; 
     202            gridData.verticalAlignment = GridData.CENTER; 
     203            gridData.grabExcessVerticalSpace = false; 
     204 
     205            label.setLayoutData(gridData); 
     206        } 
     207 
     208        // Returns the number of controls in the field editor. 
     209        public int getNumberOfControls() 
     210        { 
     211            return 1; 
     212        } 
     213 
     214        // Labels do not persist any preferences, so these methods are empty. 
     215        protected void doLoad() {} 
     216        protected void doLoadDefault() {} 
     217        protected void doStore() {} 
     218 
     219        private Label label; 
     220    } 
     221 
     222 
     223    // ---------------------------------------------------------- 
     224    /** 
     225     * A field editor for adding space to a preference page. 
     226     */ 
     227    private static class SpacerFieldEditor 
     228        extends LabelFieldEditor 
     229    { 
     230        // Implemented as an empty label field editor. 
     231        public SpacerFieldEditor(Composite parent) 
     232        { 
     233            super("", parent); 
     234        } 
     235    } 
     236 
     237 
     238    //~ Instance/static variables ............................................. 
     239 
     240    private BooleanFieldEditor useToolsDir; 
     241    private DirectoryFieldEditor toolsDir; 
     242    private Composite toolsDirParent; 
    85243}