Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3f9c9dde840631701dab51834fa1af11a4ad9c2d (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*******************************************************************************
 * Copyright (c) 2011, 2012 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.tcf.te.tcf.ui.controls;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.tcf.te.tcf.core.interfaces.ITransportTypes;
import org.eclipse.tcf.te.tcf.ui.nls.Messages;
import org.eclipse.tcf.te.ui.controls.BaseEditBrowseTextControl;
import org.eclipse.tcf.te.ui.swt.SWTControlUtil;

/**
 * Transport type control implementation.
 */
public class TransportTypeControl extends BaseEditBrowseTextControl {

	private final static List<String> TRANSPORT_TYPES = Arrays.asList(new String[] {
																		ITransportTypes.TRANSPORT_TYPE_TCP,
																		ITransportTypes.TRANSPORT_TYPE_SSL,
																		ITransportTypes.TRANSPORT_TYPE_PIPE,
																		ITransportTypes.TRANSPORT_TYPE_CUSTOM
															});

	/**
	 * Constructor.
	 *
	 * @param parentPage The parent dialog page this control is embedded in.
	 *                   Might be <code>null</code> if the control is not associated with a page.
	 */
	public TransportTypeControl(IDialogPage parentPage) {
		super(parentPage);
		setIsGroup(false);
		setReadOnly(true);
		setHideBrowseButton(true);
		setEditFieldLabel(Messages.TransportTypeControl_label);
	}

	/**
	 * Returns the list of transport types supported by this control.
	 *
	 * @return The list of supported transport types.
	 */
	public String[] getTransportTypes() {
		return TRANSPORT_TYPES.toArray(new String[TRANSPORT_TYPES.size()]);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.controls.BaseEditBrowseTextControl#setupPanel(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void setupPanel(Composite parent) {
		super.setupPanel(parent);

		List<String> transportTypeLabels = new ArrayList<String>();
		for (String transportType : TRANSPORT_TYPES) {
			String label = getTransportTypeLabel(transportType);
			if (label != null) transportTypeLabels.add(label);
		}

		setEditFieldControlHistory(transportTypeLabels.toArray(new String[transportTypeLabels.size()]));
		SWTControlUtil.select(getEditFieldControl(), 0);
		SWTControlUtil.setEnabled(getEditFieldControl(), transportTypeLabels.size() > 1);
	}

	/**
	 * Returns the label of the given transport type.
	 *
	 * @param transportType The transport type. Must not be <code>null</code>.
	 * @return The corresponding label or <code>null</code> if the transport type is unknown.
	 */
	protected String getTransportTypeLabel(String transportType) {
		Assert.isNotNull(transportType);

		if (ITransportTypes.TRANSPORT_TYPE_TCP.equals(transportType)) return Messages.TransportTypeControl_tcpType_label;
		else if (ITransportTypes.TRANSPORT_TYPE_SSL.equals(transportType)) return Messages.TransportTypeControl_sslType_label;
		else if (ITransportTypes.TRANSPORT_TYPE_PIPE.equals(transportType)) return Messages.TransportTypeControl_pipeType_label;
		else if (ITransportTypes.TRANSPORT_TYPE_CUSTOM.equals(transportType)) return Messages.TransportTypeControl_customType_label;

		return null;
	}

	/**
	 * Returns the currently selected transport type.
	 *
	 * @return The currently selected transport type.
	 */
	public String getSelectedTransportType() {
		String type = getEditFieldControlText();

		if (Messages.TransportTypeControl_tcpType_label.equals(type)) type = ITransportTypes.TRANSPORT_TYPE_TCP;
		else if (Messages.TransportTypeControl_sslType_label.equals(type)) type = ITransportTypes.TRANSPORT_TYPE_SSL;
		else if (Messages.TransportTypeControl_pipeType_label.equals(type)) type = ITransportTypes.TRANSPORT_TYPE_PIPE;
		else if (Messages.TransportTypeControl_customType_label.equals(type)) type = ITransportTypes.TRANSPORT_TYPE_CUSTOM;

		return type;
	}

	/**
	 * Sets the selected transport type to the specified one.
	 *
	 * @param transportType The transport type. Must not be <code>null</code>.
	 */
	public void setSelectedTransportType(String transportType) {
		Assert.isNotNull(transportType);

		// Get the transport type label for given transport type
		String label = getTransportTypeLabel(transportType);
		int index = SWTControlUtil.indexOf(getEditFieldControl(), label);
		if (index != -1) SWTControlUtil.select(getEditFieldControl(), index);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.controls.BaseEditBrowseTextControl#doRestoreWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String)
	 */
	@Override
	public void doRestoreWidgetValues(IDialogSettings settings, String idPrefix) {
		// The widget is not user editable and the history is used
		// for presenting the available transport types. Neither save
		// or restore the history actively.
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.controls.BaseEditBrowseTextControl#doSaveWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String)
	 */
	@Override
	public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) {
		// The widget is not user editable and the history is used
		// for presenting the available transport types. Neither save
		// or restore the history actively.
	}
}

Back to the top