Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3dfe739f6fef344be507c85ee14e060402bd201f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*******************************************************************************
 * Copyright (c) 2011 Wind River Systems, Inc. and others.
 * 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
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tm.internal.tcf.cdt.ui.launch;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.tm.internal.tcf.cdt.launch.ContextSelection;
import org.eclipse.tm.internal.tcf.cdt.ui.launch.PeerListControl.PeerInfo;
import org.eclipse.tm.internal.tcf.cdt.ui.launch.ProcessListControl.ProcessInfo;

/**
 * Dialog to select a peer and context.
 */
public class ProcessSelectionDialog extends Dialog {

    private ContextSelection fSelection;
    private ProcessListControl fContextList;

    protected ProcessSelectionDialog(IShellProvider parentShell) {
        super(parentShell);
    }

    public void setSelection(ContextSelection selection) {
        fSelection = selection;
    }

    public ContextSelection getSelection() {
        return fSelection;
    }

    @Override
    protected void configureShell(Shell newShell) {
        newShell.setText("Select Peer and Context");
        super.configureShell(newShell);
    }

    @Override
    protected Control createContents(Composite parent) {
        Control control = super.createContents(parent);
        updateButtonState();
        return control;
    }

    @Override
    protected Control createDialogArea(Composite parent) {
        Composite composite = (Composite) super.createDialogArea(parent);
        new Label(composite, SWT.NONE).setText("TCF Peers:");
        final PeerListControl peerList = new PeerListControl(composite);
        new Label(composite, SWT.NONE).setText("Contexts:");
        fContextList = new ProcessListControl(composite);
        peerList.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                ISelection selection = event.getSelection();
                if (selection instanceof IStructuredSelection) {
                    IStructuredSelection ss = (IStructuredSelection) selection;
                    Object element = ss.getFirstElement();
                    if (element instanceof PeerInfo) {
                        handlePeerSelected((PeerInfo) element);
                    }
                }
            }
        });
        fContextList.getTree().addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                ProcessInfo contextInfo = fContextList.findProcessInfo((TreeItem) e.item);
                if (contextInfo != null) {
                    handleContextSelected(contextInfo);
                }
            }
            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
                if (getButton(IDialogConstants.OK_ID).isEnabled()) {
                    buttonPressed(IDialogConstants.OK_ID);
                }
            }
        });
        if (fSelection.fContextId != null) {
            fContextList.selectContext(fSelection.fContextId);
        }
        return composite;
    }

    private void updateButtonState() {
        getButton(IDialogConstants.OK_ID).setEnabled(fSelection.fContextId != null);
    }

    protected void handleContextSelected(ProcessInfo contextInfo) {
        fSelection.fContextId = contextInfo.id;
        updateButtonState();
    }

    protected void handlePeerSelected(PeerInfo peerInfo) {
        fSelection.fPeerId = peerInfo.id;
        fContextList.setInput(peerInfo.peer);
    }

}

Back to the top