gov.redhawk.ide.dcd.internal.ui.handlers.LaunchDeviceManagerDialog.java Source code

Java tutorial

Introduction

Here is the source code for gov.redhawk.ide.dcd.internal.ui.handlers.LaunchDeviceManagerDialog.java

Source

/*******************************************************************************
 * This file is protected by Copyright. 
 * Please refer to the COPYRIGHT file distributed with this source distribution.
 *
 * This file is part of REDHAWK IDE.
 *
 * All rights reserved.  This program and the accompanying materials are made available under 
 * the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package gov.redhawk.ide.dcd.internal.ui.handlers;

import java.util.ArrayList;

import gov.redhawk.ide.sdr.ui.util.DebugLevel;
import gov.redhawk.ide.sdr.ui.util.DeviceManagerLaunchConfiguration;
import gov.redhawk.model.sca.provider.ScaItemProviderAdapterFactory;
import gov.redhawk.sca.ScaPlugin;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ListDialog;

public class LaunchDeviceManagerDialog extends ListDialog {
    private DeviceManagerLaunchConfiguration configuration = new DeviceManagerLaunchConfiguration();
    private DataBindingContext context = new DataBindingContext();

    public LaunchDeviceManagerDialog(Shell parent) {
        super(parent);

        setTitle("Launch Device Manager");
        setMessage("Select the Domain on which to launch the device manager(s):");

        final ScaItemProviderAdapterFactory factory = new ScaItemProviderAdapterFactory();
        setLabelProvider(new AdapterFactoryLabelProvider(factory));
        setContentProvider(new ArrayContentProvider());

        final ArrayList<Object> input = new ArrayList<Object>();
        input.addAll(ScaPlugin.getDefault().getDomainManagerRegistry(Display.getCurrent()).getDomains());
        final String defaultSelection = "<Default>";
        input.add(defaultSelection);
        super.setInput(input);
    }

    @Override
    public void setInput(Object input) {

    }

    @Override
    protected void createButtonsForButtonBar(Composite parent) {
        Label label = new Label(parent, SWT.NULL);
        label.setText("Debug Level: ");
        ComboViewer debugViewer = new ComboViewer(parent, SWT.READ_ONLY | SWT.SINGLE | SWT.DROP_DOWN | SWT.BORDER);
        debugViewer.setContentProvider(new ArrayContentProvider());
        debugViewer.setInput(DebugLevel.values());
        debugViewer.setSelection(new StructuredSelection(DebugLevel.Info));
        context.bindValue(ViewersObservables.observeSingleSelection(debugViewer),
                PojoObservables.observeValue(configuration, DeviceManagerLaunchConfiguration.PROP_DEBUG_LEVEL));

        label = new Label(parent, SWT.NULL);
        label.setText("Arguments: ");
        Text text = new Text(parent, SWT.BORDER);
        context.bindValue(SWTObservables.observeText(text, SWT.Modify),
                PojoObservables.observeValue(configuration, DeviceManagerLaunchConfiguration.PROP_ARGUMENTS));

        super.createButtonsForButtonBar(parent);
    }

    public DeviceManagerLaunchConfiguration getConfiguration() {
        return configuration;
    }
}