Search in sources :

Example 1 with PeripheralModel

use of net.sourceforge.usbdm.peripherals.model.PeripheralModel 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 PeripheralModel

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

the class UsbdmDevicePeripheralsView method createPartControl.

// /**
// * Provides the editor for the tree elements
// *
// * Does minor modifications to the default editor.
// */
// private class PeripheralsViewTextCellEditor extends TextCellEditor {
// 
// private int minHeight;
// 
// public PeripheralsViewTextCellEditor(Tree tree) {
// super(tree, SWT.BORDER);
// Text txt = (Text) getControl();
// 
// Font fnt = txt.getFont();
// FontData[] fontData = fnt.getFontData();
// if (fontData != null && fontData.length > 0) {
// minHeight = fontData[0].getHeight() + 10;
// }
// }
// 
// public LayoutData getLayoutData() {
// LayoutData data = super.getLayoutData();
// if (minHeight > 0)
// data.minimumHeight = minHeight;
// return data;
// }
// }
/**
 * Callback that creates the viewer and initialises it.
 *
 * The View consists of a tree and a information panel
 */
public void createPartControl(Composite parent) {
    // Create the manager and bind to main composite
    resManager = new LocalResourceManager(JFaceResources.getResources(), parent);
    parent.setLayoutData(new FillLayout());
    SashForm form = new SashForm(parent, SWT.VERTICAL);
    form.setLayout(new FillLayout());
    // Make sash visible
    form.setSashWidth(4);
    form.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GRAY));
    // =============================
    fPeripheralsTreeViewer = new CheckboxTreeViewer(form, SWT.MULTI | SWT.V_SCROLL | SWT.FULL_SELECTION);
    Tree tree = fPeripheralsTreeViewer.getTree();
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    ColumnViewerToolTipSupport.enableFor(fPeripheralsTreeViewer);
    // // Suppress tree expansion on double-click
    // // see http://www.eclipse.org/forums/index.php/t/257325/
    // peripheralsTreeViewer.getControl().addListener(SWT.MeasureItem, new Listener(){
    // @Override
    // public void handleEvent(Event event) {
    // }});
    fPeripheralsTreeViewer.setColumnProperties(fTreeProperties);
    fPeripheralsTreeViewer.setCellEditors(new CellEditor[] { null, new TextCellEditor(fPeripheralsTreeViewer.getTree()), null });
    // peripheralsTreeViewer.setCellEditors(new CellEditor[] { null, new PeripheralsViewTextCellEditor(peripheralsTreeViewer.getTree()), null });
    fPeripheralsTreeViewer.setCellModifier(new PeripheralsViewCellModifier(this));
    /*
       * Name column
       */
    TreeColumn column;
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultNameColumnWidth);
    column.setText("Name");
    // Add listener to column so peripherals are sorted by name when clicked
    column.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.PeripheralNameOrder));
        }
    });
    /*
       * Value column
       */
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultValueColumnWidth);
    column.setText("Value");
    column.setResizable(fDefaultValueColumnWidth != 0);
    /*
       * Field column
       */
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultFieldColumnWidth);
    column.setText("Field");
    column.setResizable(fDefaultFieldColumnWidth != 0);
    /*
       * Mode column
       */
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultModeWidth);
    column.setText("Mode");
    column.setResizable(fDefaultModeWidth != 0);
    /*
       * Location column
       */
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultLocationColumnWidth);
    column.setText("Location");
    column.setResizable(fDefaultLocationColumnWidth != 0);
    // Add listener to column so peripheral are sorted by address when clicked
    column.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.AddressOrder));
        }
    });
    /*
       * Description column
       */
    column = new TreeColumn(fPeripheralsTreeViewer.getTree(), SWT.NONE);
    column.setWidth(fDefaultDescriptionColumnWidth);
    column.setText("Description");
    column.setResizable(fDefaultDescriptionColumnWidth != 0);
    // Default to sorted by Peripheral name
    fPeripheralsTreeViewer.setComparator(new PeripheralsViewSorter(PeripheralsViewSorter.SortCriteria.PeripheralNameOrder));
    // Noting filtered
    fPeripheralsTreeViewer.addFilter(new PeripheralsViewFilter(PeripheralsViewFilter.SelectionCriteria.SelectAll));
    // Label provider
    fPeripheralsTreeViewer.setLabelProvider(new PeripheralsViewCellLabelProvider(this));
    // Content provider
    fPeripheralsTreeViewer.setContentProvider(new PeripheralsViewContentProvider(this));
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(fPeripheralsTreeViewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            // ||
            return (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION);
        // (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
        }
    };
    TreeViewerEditor.create(fPeripheralsTreeViewer, actSupport, TreeViewerEditor.DEFAULT);
    // Create the help context id for the viewer's control
    // PlatformUI.getWorkbench().getHelpSystem().setHelp(treeViewer.getControl(),
    // "usbdmMemory.viewer");
    // =============================
    fPeripheralsInformationPanel = new PeripheralsInformationPanel(form, SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY, this.fPeripheralsTreeViewer);
    form.setWeights(new int[] { 80, 20 });
    // Tree expansion/collapse
    fPeripheralsTreeViewer.addTreeListener(new ITreeViewerListener() {

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            Object element = event.getElement();
            // System.err.println("treeExpanded() => event.getElement().getClass() = " + element.getClass());
            if (element instanceof RegisterModel) {
                ((RegisterModel) element).update();
            }
            if (element instanceof PeripheralModel) {
                ((PeripheralModel) element).update();
            }
        }

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        }
    });
    // When user checks a checkbox in the tree, check all its children
    fPeripheralsTreeViewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            // peripheralsTreeViewer.expandToLevel(event.getElement(), 1);
            fPeripheralsTreeViewer.setSubtreeChecked(event.getElement(), event.getChecked());
        }
    });
    // Create the actions
    makeActions();
    // Add selected actions to context menu
    hookContextMenu();
    // Add selected actions to menu bar
    contributeToActionBars();
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) PeripheralModel(net.sourceforge.usbdm.peripherals.model.PeripheralModel) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent) RegisterModel(net.sourceforge.usbdm.peripherals.model.RegisterModel) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) FillLayout(org.eclipse.swt.layout.FillLayout) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) SashForm(org.eclipse.swt.custom.SashForm) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 3 with PeripheralModel

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

the class UsbdmDevicePeripheralsView method sessionSuspended.

/* (non-Javadoc)
    * @see net.sourceforge.usbdm.peripherals.view.GdbSessionListener#sessionSuspended(net.sourceforge.usbdm.peripherals.model.UsbdmDevicePeripheralsModel, net.sourceforge.usbdm.peripherals.view.GdbSessionListener.EventType)
    */
@Override
public void sessionSuspended(final UsbdmDevicePeripheralsModel model, GdbSessionListener.EventType reason) {
    if (model != null) {
        DeviceModel deviceModel = model.getModel();
        if (deviceModel != null) {
            // Set current register values as the 'reference' for changed values
            deviceModel.setChangeReference();
            // Set all registers as stale
            deviceModel.setNeedsUpdate(true);
        }
    }
    // System.err.println("UsbdmDevicePeripheralsView.SessionSuspend() - reason = " + reason);
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            if ((fPeripheralsTreeViewer == null) || fPeripheralsTreeViewer.getControl().isDisposed()) {
                // System.err.println("UsbdmDevicePeripheralsView.SessionTerminate() - no peripheral view or already disposed()");
                return;
            }
            if (peripheralsModel == null) {
                // System.err.println("UsbdmDevicePeripheralsView.sessionTerminated() - periperalsModel == null");
                return;
            }
            if (peripheralsModel != model) {
                // System.err.println("UsbdmDevicePeripheralsView.sessionTerminated() - periperalsModel != aPeriperalsModel");
                return;
            }
            Object[] visibleObjects = fPeripheralsTreeViewer.getExpandedElements();
            for (Object object : visibleObjects) {
                if (object instanceof PeripheralModel) {
                    ((PeripheralModel) object).forceUpdate();
                }
            }
        }
    });
}
Also used : DeviceModel(net.sourceforge.usbdm.peripherals.model.DeviceModel) PeripheralModel(net.sourceforge.usbdm.peripherals.model.PeripheralModel)

Aggregations

PeripheralModel (net.sourceforge.usbdm.peripherals.model.PeripheralModel)3 RegisterModel (net.sourceforge.usbdm.peripherals.model.RegisterModel)2 BaseModel (net.sourceforge.usbdm.peripherals.model.BaseModel)1 DeviceModel (net.sourceforge.usbdm.peripherals.model.DeviceModel)1 FieldModel (net.sourceforge.usbdm.peripherals.model.FieldModel)1 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)1 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)1 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 ColumnViewerEditorActivationEvent (org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent)1 ColumnViewerEditorActivationStrategy (org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)1 ITreeViewerListener (org.eclipse.jface.viewers.ITreeViewerListener)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 TreeExpansionEvent (org.eclipse.jface.viewers.TreeExpansionEvent)1 SashForm (org.eclipse.swt.custom.SashForm)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Tree (org.eclipse.swt.widgets.Tree)1