Search in sources :

Example 1 with VariableProvider

use of net.sourceforge.usbdm.deviceEditor.peripherals.VariableProvider in project usbdm-eclipse-plugins by podonoghue.

the class DeviceInfo method parse.

/**
 * Load hardware description from file
 *
 * @param hardwarePath  Path to load from
 *
 * @throws Exception
 */
private void parse(Path hardwarePath) throws Exception {
    System.err.println("DeviceInfo.parse(" + hardwarePath.toAbsolutePath() + ")");
    fHardwarePath = hardwarePath;
    String filename = fHardwarePath.getFileName().toString();
    if (filename.endsWith(HARDWARE_CSV_FILE_EXTENSION)) {
        ParseFamilyCSV parser = new ParseFamilyCSV(this);
        parser.parseFile(fHardwarePath);
    } else if ((filename.endsWith("xml")) || (filename.endsWith(HARDWARE_FILE_EXTENSION))) {
        ParseFamilyXML parser = new ParseFamilyXML();
        parser.parseFile(this, fHardwarePath);
        fVariableProvider = new VariableProvider("Common Settings", this) {

            // Add change lister to mark editor dirty
            @Override
            public void addVariable(Variable variable) {
                super.addVariable(variable);
                variable.addListener(DeviceInfo.this);
            }
        };
        fMenuData = ParseMenuXML.parseMenuFile("_common_settings", fVariableProvider);
        ArrayList<PeripheralWithState> peripheralWithStateList = new ArrayList<PeripheralWithState>();
        // Construct list of all PeripheralWithState
        for (String name : fPeripheralsMap.keySet()) {
            Peripheral p = fPeripheralsMap.get(name);
            if (p instanceof PeripheralWithState) {
                peripheralWithStateList.add((PeripheralWithState) fPeripheralsMap.get(name));
            }
        }
        // Sort in priority order
        Collections.sort(peripheralWithStateList, new Comparator<PeripheralWithState>() {

            @Override
            public int compare(PeripheralWithState o1, PeripheralWithState o2) {
                return o2.getPriority() - o1.getPriority();
            }
        });
        // Construct peripherals
        for (PeripheralWithState p : peripheralWithStateList) {
            if (p instanceof PeripheralWithState) {
                // System.err.println("Constructing " + p);
                ((PeripheralWithState) p).loadModels();
            }
        }
        for (PeripheralWithState p : peripheralWithStateList) {
            if (p instanceof PeripheralWithState) {
                p.instantiateAliases();
            }
        }
    } else {
        throw new Exception("Unexpected file type for " + hardwarePath);
    }
}
Also used : PeripheralWithState(net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState) ParseFamilyCSV(net.sourceforge.usbdm.deviceEditor.peripherals.ParseFamilyCSV) VariableProvider(net.sourceforge.usbdm.deviceEditor.peripherals.VariableProvider) ArrayList(java.util.ArrayList) ParseFamilyXML(net.sourceforge.usbdm.deviceEditor.xmlParser.ParseFamilyXML) CoreException(org.eclipse.core.runtime.CoreException) UsbdmException(net.sourceforge.usbdm.jni.UsbdmException) IOException(java.io.IOException) Comparator(java.util.Comparator)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 ParseFamilyCSV (net.sourceforge.usbdm.deviceEditor.peripherals.ParseFamilyCSV)1 PeripheralWithState (net.sourceforge.usbdm.deviceEditor.peripherals.PeripheralWithState)1 VariableProvider (net.sourceforge.usbdm.deviceEditor.peripherals.VariableProvider)1 ParseFamilyXML (net.sourceforge.usbdm.deviceEditor.xmlParser.ParseFamilyXML)1 UsbdmException (net.sourceforge.usbdm.jni.UsbdmException)1 CoreException (org.eclipse.core.runtime.CoreException)1