Search in sources :

Example 1 with IPeripheralDescriptionProvider

use of net.sourceforge.usbdm.peripheralDatabase.IPeripheralDescriptionProvider in project usbdm-eclipse-plugins by podonoghue.

the class DevicePeripheralSelectionDialogue method populateDeviceList.

/**
 * Populate device list based on currently selected provider
 */
void populateDeviceList() {
    // Clear existing device details
    comboManufacturerSelect.setToolTipText("No description");
    comboDeviceName.removeAll();
    String providerId = getProviderId();
    if (providerId == null) {
        return;
    }
    try {
        IPeripheralDescriptionProvider peripheralDescriptionProvider = devicePeriperalsProviderInterface.getProvider(providerId);
        comboManufacturerSelect.setToolTipText(peripheralDescriptionProvider.getDescription());
        Vector<String> deviceNames = peripheralDescriptionProvider.getDeviceNames();
        for (String s : deviceNames) {
            comboDeviceName.add(s);
        }
        comboDeviceName.select(0);
    } catch (Exception e) {
        System.err.println("DevicePeripheralSelectionDialogue.populateDeviceList()" + e.getMessage());
    }
}
Also used : IPeripheralDescriptionProvider(net.sourceforge.usbdm.peripheralDatabase.IPeripheralDescriptionProvider)

Example 2 with IPeripheralDescriptionProvider

use of net.sourceforge.usbdm.peripheralDatabase.IPeripheralDescriptionProvider in project usbdm-eclipse-plugins by podonoghue.

the class DevicePeripheralSelectionDialogue method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // Create the manager and bind to main composite
    resManager = new LocalResourceManager(JFaceResources.getResources(), parent);
    Composite container = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout(1, false);
    layout.marginRight = 5;
    layout.marginLeft = 5;
    container.setLayout(layout);
    /*
       * Create Internal group
       */
    grpInternal = new Group(container, SWT.NONE);
    grpInternal.setText("Internal SVD Files");
    grpInternal.setLayout(new GridLayout(3, false));
    grpInternal.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label label = new Label(grpInternal, SWT.NONE);
    // $NON-NLS-1$
    label.setText("Manufacturer:");
    comboManufacturerSelect = new Combo(grpInternal, SWT.BORDER | SWT.READ_ONLY);
    comboManufacturerSelect.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(grpInternal, SWT.NONE);
    providerIds = devicePeriperalsProviderInterface.getProviderIDs();
    for (String pd : providerIds) {
        comboManufacturerSelect.add(devicePeriperalsProviderInterface.getProviderName(pd));
    }
    comboManufacturerSelect.select(0);
    comboManufacturerSelect.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            manufacturerChanged();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    label = new Label(grpInternal, SWT.NONE);
    // $NON-NLS-1$
    label.setText("Target Device:");
    comboDeviceName = new Combo(grpInternal, SWT.BORDER | SWT.READ_ONLY);
    comboDeviceName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    populateDeviceList();
    comboDeviceName.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            // Selected device has changed
            updateSvdId();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    btnDeviceSelect = new Button(grpInternal, SWT.NONE);
    btnDeviceSelect.setText("Device...");
    btnDeviceSelect.setToolTipText("Select internal USBDM\ndevice by category");
    btnDeviceSelect.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            // Open dialogue to select device
            DeviceSelector ds = new DeviceSelector(getShell(), targetType, comboDeviceName.getText());
            if (ds.open() == Window.OK) {
                // Map device name to SVD file name
                String message = null;
                try {
                    IPeripheralDescriptionProvider provider = devicePeriperalsProviderInterface.getProvider(UsbdmPeripheralDescriptionProvider.ID);
                    String mappedName = provider.getMappedDeviceName(ds.getText());
                    if (mappedName == null) {
                        message = "Cannot locate SVD file for device";
                    } else {
                        // System.err.println("Mapped name = " + mappedName);
                        int providerIndex = providerIds.indexOf(UsbdmPeripheralDescriptionProvider.ID);
                        if (providerIndex < 0) {
                            providerIndex = 0;
                        }
                        comboManufacturerSelect.select(providerIndex);
                        populateDeviceList();
                        comboDeviceName.setText(mappedName);
                        updateSvdId();
                    }
                } catch (Exception e) {
                    message = "Cannot locate SVD for device\nReason " + e.getMessage();
                }
                if (message != null) {
                    MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.CANCEL);
                    messageBox.setText("Error");
                    messageBox.setMessage(message);
                    messageBox.open();
                }
            }
            validate();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    chkUseExternalSVDFile = new Button(container, SWT.CHECK);
    chkUseExternalSVDFile.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    chkUseExternalSVDFile.setText("Use external SVD file");
    chkUseExternalSVDFile.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateSvdId();
        }
    });
    /*
       * Create External group
       */
    grpExternal = new Group(container, SWT.NONE);
    grpExternal.setText("External SVD File");
    grpExternal.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    grpExternal.setLayout(new GridLayout(3, false));
    label = new Label(grpExternal, SWT.NONE);
    // $NON-NLS-1$
    label.setText("External File:");
    txtFilePath = new Text(grpExternal, SWT.BORDER | SWT.READ_ONLY);
    txtFilePath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    btnFileBrowse = new Button(grpExternal, SWT.PUSH);
    btnFileBrowse.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    btnFileBrowse.setText("Browse...");
    btnFileBrowse.setToolTipText("Select external file...");
    btnFileBrowse.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final String[] filterExts = { "*.svd;*.xml" };
            FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
            fd.setText("Locate SVD file describing device");
            fd.setFilterPath(txtFilePath.getText());
            fd.setFilterExtensions(filterExts);
            String directoryPath = fd.open();
            if (directoryPath != null) {
                txtFilePath.setText(directoryPath);
                updateSvdId();
            }
        }
    });
    setSvdIdentifier(fSvdIdentifier);
    return container;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) DeviceSelector(net.sourceforge.usbdm.deviceDatabase.ui.DeviceSelector) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) MessageBox(org.eclipse.swt.widgets.MessageBox) IPeripheralDescriptionProvider(net.sourceforge.usbdm.peripheralDatabase.IPeripheralDescriptionProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

IPeripheralDescriptionProvider (net.sourceforge.usbdm.peripheralDatabase.IPeripheralDescriptionProvider)2 DeviceSelector (net.sourceforge.usbdm.deviceDatabase.ui.DeviceSelector)1 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 Text (org.eclipse.swt.widgets.Text)1