diff options
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java')
-rw-r--r-- | plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java new file mode 100644 index 0000000..cd58b73 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java | |||
@@ -0,0 +1,217 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2006, 2010 PalmSource, Inc. and others. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Ewa Matejska (PalmSource) - initial API and implementation | ||
10 | * Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry | ||
11 | * Martin Oberhuber (Wind River) - [196934] hide disabled system types in remotecdt combo | ||
12 | * Yu-Fen Kuo (MontaVista) - [190613] Fix NPE in Remotecdt when RSEUIPlugin has not been loaded | ||
13 | * Martin Oberhuber (Wind River) - [cleanup] Avoid using SystemStartHere in production code | ||
14 | * Johann Draschwandtner (Wind River) - [231827][remotecdt]Auto-compute default for Remote path | ||
15 | * Johann Draschwandtner (Wind River) - [233057][remotecdt]Fix button enablement | ||
16 | * Anna Dushistova (MontaVista) - [181517][usability] Specify commands to be run before remote application launch | ||
17 | * Anna Dushistova (MontaVista) - [223728] [remotecdt] connection combo is not populated until RSE is activated | ||
18 | * Anna Dushistova (MontaVista) - [267951] [remotecdt] Support systemTypes without files subsystem | ||
19 | * Lianhao Lu (Intel) - Modified for internal use | ||
20 | * Ioana Grigoropol (Intel) - Adapt class for remote support | ||
21 | *******************************************************************************/ | ||
22 | |||
23 | package org.yocto.sdk.remotetools.actions; | ||
24 | |||
25 | import org.yocto.remote.utils.RemoteHelper; | ||
26 | import org.yocto.sdk.remotetools.Messages; | ||
27 | import org.yocto.sdk.remotetools.SWTFactory; | ||
28 | import org.eclipse.jface.dialogs.Dialog; | ||
29 | import org.eclipse.jface.dialogs.IDialogConstants; | ||
30 | import org.eclipse.rse.core.model.IHost; | ||
31 | import org.eclipse.rse.ui.actions.SystemNewConnectionAction; | ||
32 | import org.eclipse.swt.SWT; | ||
33 | import org.eclipse.swt.events.ModifyEvent; | ||
34 | import org.eclipse.swt.events.ModifyListener; | ||
35 | import org.eclipse.swt.events.SelectionAdapter; | ||
36 | import org.eclipse.swt.events.SelectionEvent; | ||
37 | import org.eclipse.swt.layout.GridData; | ||
38 | import org.eclipse.swt.layout.GridLayout; | ||
39 | import org.eclipse.swt.widgets.Button; | ||
40 | import org.eclipse.swt.widgets.Combo; | ||
41 | import org.eclipse.swt.widgets.Composite; | ||
42 | import org.eclipse.swt.widgets.Control; | ||
43 | import org.eclipse.swt.widgets.Label; | ||
44 | import org.eclipse.swt.widgets.Shell; | ||
45 | |||
46 | public class BaseSettingDialog extends Dialog { | ||
47 | |||
48 | protected String title; | ||
49 | protected String curConn; //current rse connection name | ||
50 | protected IHost conn;//rse IHost | ||
51 | |||
52 | protected Button newRemoteConnectionButton; | ||
53 | protected Label connectionLabel; | ||
54 | protected Combo connectionCombo; | ||
55 | protected SystemNewConnectionAction action = null; | ||
56 | |||
57 | |||
58 | protected BaseSettingDialog(Shell parentShell,String title, String connection) { | ||
59 | super(parentShell); | ||
60 | this.title=title; | ||
61 | this.curConn=connection; | ||
62 | } | ||
63 | |||
64 | @Override | ||
65 | protected void configureShell(Shell newShell) { | ||
66 | super.configureShell(newShell); | ||
67 | newShell.setText(title); | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | protected Control createDialogArea(Composite parent) { | ||
72 | Composite comp = (Composite)super.createDialogArea(parent); | ||
73 | GridLayout topLayout = new GridLayout(); | ||
74 | comp.setLayout(topLayout); | ||
75 | |||
76 | /* The RSE Connection dropdown with New button. */ | ||
77 | SWTFactory.createVerticalSpacer(comp, 1); | ||
78 | createRemoteConnectionGroup(comp); | ||
79 | |||
80 | return comp; | ||
81 | } | ||
82 | |||
83 | |||
84 | @Override | ||
85 | protected void createButtonsForButtonBar(Composite parent) { | ||
86 | super.createButtonsForButtonBar(parent); | ||
87 | updateCurConn(); | ||
88 | } | ||
89 | |||
90 | protected void createRemoteConnectionGroup(Composite parent) { | ||
91 | Composite projComp = new Composite(parent, SWT.NONE); | ||
92 | GridLayout projLayout = new GridLayout(); | ||
93 | projLayout.numColumns = 6; | ||
94 | projLayout.marginHeight = 0; | ||
95 | projLayout.marginWidth = 0; | ||
96 | projComp.setLayout(projLayout); | ||
97 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
98 | projComp.setLayoutData(gd); | ||
99 | |||
100 | connectionLabel = new Label(projComp, SWT.NONE); | ||
101 | connectionLabel.setText(Messages.BaseSettingDialog_Connection); | ||
102 | gd = new GridData(); | ||
103 | gd.horizontalSpan = 1; | ||
104 | connectionLabel.setLayoutData(gd); | ||
105 | |||
106 | connectionCombo = new Combo(projComp, SWT.DROP_DOWN | SWT.READ_ONLY); | ||
107 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
108 | gd.horizontalSpan = 4; | ||
109 | connectionCombo.setLayoutData(gd); | ||
110 | connectionCombo.addModifyListener(new ModifyListener() { | ||
111 | |||
112 | public void modifyText(ModifyEvent e) { | ||
113 | //setDirty(true); | ||
114 | //updateLaunchConfigurationDialog(); | ||
115 | //useDefaultsFromConnection(); | ||
116 | updateCurConn(); | ||
117 | } | ||
118 | }); | ||
119 | |||
120 | newRemoteConnectionButton = SWTFactory.createPushButton(projComp, | ||
121 | Messages.BaseSettingDialog_New, null); | ||
122 | newRemoteConnectionButton.addSelectionListener(new SelectionAdapter() { | ||
123 | |||
124 | public void widgetSelected(SelectionEvent evt) { | ||
125 | handleNewRemoteConnectionSelected(); | ||
126 | //updateLaunchConfigurationDialog(); | ||
127 | updateConnectionPulldown(); | ||
128 | } | ||
129 | }); | ||
130 | gd = new GridData(); | ||
131 | gd.horizontalSpan = 1; | ||
132 | newRemoteConnectionButton.setLayoutData(gd); | ||
133 | |||
134 | updateConnectionPulldown(); | ||
135 | } | ||
136 | |||
137 | protected boolean updateOkButton() { | ||
138 | boolean ret=false; | ||
139 | Button button=getButton(IDialogConstants.OK_ID); | ||
140 | if(button!=null) | ||
141 | button.setEnabled(false); | ||
142 | IHost currentConnectionSelected = getCurrentConnection(); | ||
143 | if (currentConnectionSelected != null) { | ||
144 | if (RemoteHelper.isHostViable(currentConnectionSelected) && button != null){ | ||
145 | button.setEnabled(true); | ||
146 | ret=true; | ||
147 | } | ||
148 | } | ||
149 | return ret; | ||
150 | } | ||
151 | |||
152 | protected void updateCurConn() { | ||
153 | IHost currentConnectionSelected = getCurrentConnection(); | ||
154 | if (currentConnectionSelected != null) { | ||
155 | if (RemoteHelper.isHostViable(currentConnectionSelected)) | ||
156 | curConn=currentConnectionSelected.getAliasName(); | ||
157 | } | ||
158 | updateOkButton(); | ||
159 | } | ||
160 | |||
161 | protected IHost getCurrentConnection() { | ||
162 | int currentSelection = connectionCombo.getSelectionIndex(); | ||
163 | String remoteConnection = currentSelection >= 0 ? connectionCombo | ||
164 | .getItem(currentSelection) : null; | ||
165 | return RemoteHelper.getRemoteConnectionByName(remoteConnection); | ||
166 | } | ||
167 | |||
168 | protected void handleNewRemoteConnectionSelected() { | ||
169 | if (action == null) { | ||
170 | action = new SystemNewConnectionAction(getShell(), | ||
171 | false, false, null); | ||
172 | } | ||
173 | |||
174 | try { | ||
175 | action.run(); | ||
176 | } catch (Exception e) { | ||
177 | // Ignore | ||
178 | } | ||
179 | } | ||
180 | |||
181 | protected void updateConnectionPulldown() { | ||
182 | int index=-1; | ||
183 | RemoteHelper.waitForRSEInitCompletition(); | ||
184 | // already initialized | ||
185 | connectionCombo.removeAll(); | ||
186 | IHost[] connections = RemoteHelper.getSuitableConnections(); | ||
187 | for (int i = 0; i < connections.length; i++) { | ||
188 | connectionCombo.add(connections[i].getAliasName()); | ||
189 | if(connections[i].getAliasName().equals(curConn)) | ||
190 | index=i; | ||
191 | } | ||
192 | |||
193 | if(index>=0) { | ||
194 | connectionCombo.select(index); | ||
195 | }else if (connections.length > 0) { | ||
196 | connectionCombo.select(connections.length - 1); | ||
197 | } | ||
198 | |||
199 | //TODO | ||
200 | //connectionCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT,true); | ||
201 | connectionCombo.pack(true); | ||
202 | connectionCombo.layout(); | ||
203 | connectionCombo.getParent().layout(); | ||
204 | |||
205 | updateCurConn(); | ||
206 | } | ||
207 | |||
208 | @Override | ||
209 | protected void okPressed() { | ||
210 | conn=getCurrentConnection(); | ||
211 | super.okPressed(); | ||
212 | } | ||
213 | |||
214 | public IHost getHost() { | ||
215 | return conn; | ||
216 | } | ||
217 | } | ||