Search in sources :

Example 1 with BaseModel

use of net.sourceforge.usbdm.peripherals.model.BaseModel in project usbdm-eclipse-plugins by podonoghue.

the class PeripheralsInformationPanel method selectionChanged.

/**
 * Handles changes in selection of peripheral, register or field in tree view
 *
 * Updates description in infoPanel
 * Attaches change listener to selected element
 *
 * @param event
 */
public void selectionChanged(SelectionChangedEvent event) {
    Object source = event.getSource();
    // System.err.println("PeripheralsInformationPanel.selectionChanged(), source = " + source.getClass());
    if (source == fPeripheralsTreeViewer) {
        ITreeSelection selection = (ITreeSelection) fPeripheralsTreeViewer.getSelection();
        Object uModel = selection.getFirstElement();
        // Detach from current peripheral
        if (fPeripheralModel != null) {
            fPeripheralModel.removeListener(this);
            fPeripheralModel = null;
        }
        if ((uModel == null) || !(uModel instanceof BaseModel)) {
            fCurrentModel = null;
            updateContent();
            return;
        }
        // Save model element to get values/description from
        fCurrentModel = (BaseModel) uModel;
        // Find peripheral that owns selected model
        BaseModel model = fCurrentModel;
        if (model instanceof FieldModel) {
            // System.err.println("PeripheralsInformationPanel.selectionChanged(), traversing field = " + model);
            model = model.getParent();
        }
        if (model instanceof RegisterModel) {
            // System.err.println("PeripheralsInformationPanel.selectionChanged(), traversing register = " + model);
            model = model.getParent();
        }
        if (model instanceof PeripheralModel) {
            // Attach listener to peripheral
            fPeripheralModel = (PeripheralModel) model;
            fPeripheralModel.addListener(this);
        // System.err.println("PeripheralsInformationPanel.selectionChanged(), listening to = " + model);
        }
        // else {
        // System.err.println("PeripheralsInformationPanel.selectionChanged(), ignoring = " + model);
        // System.err.println("PeripheralsInformationPanel.selectionChanged(), ignoring = " + model.getClass());
        // }
        updateContent();
    }
}
Also used : RegisterModel(net.sourceforge.usbdm.peripherals.model.RegisterModel) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) BaseModel(net.sourceforge.usbdm.peripherals.model.BaseModel) PeripheralModel(net.sourceforge.usbdm.peripherals.model.PeripheralModel) FieldModel(net.sourceforge.usbdm.peripherals.model.FieldModel)

Example 2 with BaseModel

use of net.sourceforge.usbdm.peripherals.model.BaseModel in project usbdm-eclipse-plugins by podonoghue.

the class PeripheralsViewSorter method compare.

@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    BaseModel element1 = (BaseModel) e1;
    BaseModel element2 = (BaseModel) e2;
    int diff = 0;
    // Fields - sort by bitOffset then name
    if (e1 instanceof FieldModel) {
        diff = ((FieldModel) e2).getBitOffset() - ((FieldModel) e1).getBitOffset();
        if (diff != 0) {
            return diff;
        }
        diff = ((FieldModel) e2).getBitWidth() - ((FieldModel) e1).getBitWidth();
        if (diff != 0) {
            return diff;
        }
        diff = element1.getName().compareTo(element2.getName());
        return diff;
    }
    // Registers sorted by address then name
    if ((e1 instanceof RegisterModel) || (e1 instanceof ClusterModel)) {
        if (element1.getAddress() > element2.getAddress()) {
            diff = 1;
        } else if (element1.getAddress() < element2.getAddress()) {
            diff = -1;
        } else {
            diff = element1.getName().compareTo(element2.getName());
        }
        return diff;
    }
    // Sort criteria affects how peripherals are sorted only
    switch(criteria) {
        case PeripheralNameOrder:
            // Sort by name then address (unlikely!)
            diff = element1.getName().compareTo(element2.getName());
            if (diff == 0) {
                if (element1.getAddress() > element2.getAddress()) {
                    diff = 1;
                } else if (element1.getAddress() < element2.getAddress()) {
                    diff = -1;
                } else {
                    diff = element1.getName().compareTo(element2.getName());
                }
            }
            break;
        case AddressOrder:
            // Sort by address then name
            if (element1.getAddress() > element2.getAddress()) {
                diff = 1;
            } else if (element1.getAddress() < element2.getAddress()) {
                diff = -1;
            } else {
                diff = element1.getName().compareTo(element2.getName());
            }
            break;
    }
    return diff;
}
Also used : RegisterModel(net.sourceforge.usbdm.peripherals.model.RegisterModel) ClusterModel(net.sourceforge.usbdm.peripherals.model.ClusterModel) BaseModel(net.sourceforge.usbdm.peripherals.model.BaseModel) FieldModel(net.sourceforge.usbdm.peripherals.model.FieldModel)

Aggregations

BaseModel (net.sourceforge.usbdm.peripherals.model.BaseModel)2 FieldModel (net.sourceforge.usbdm.peripherals.model.FieldModel)2 RegisterModel (net.sourceforge.usbdm.peripherals.model.RegisterModel)2 ClusterModel (net.sourceforge.usbdm.peripherals.model.ClusterModel)1 PeripheralModel (net.sourceforge.usbdm.peripherals.model.PeripheralModel)1 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)1