diff options
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions')
20 files changed, 2016 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java new file mode 100644 index 0000000..dacd192 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseModel.java | |||
@@ -0,0 +1,123 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import java.io.IOException; | ||
14 | import java.io.InputStream; | ||
15 | import java.lang.reflect.InvocationTargetException; | ||
16 | |||
17 | import org.eclipse.core.runtime.IProgressMonitor; | ||
18 | import org.eclipse.core.runtime.SubProgressMonitor; | ||
19 | import org.eclipse.jface.operation.IRunnableWithProgress; | ||
20 | import org.eclipse.rse.core.model.IHost; | ||
21 | import org.yocto.remote.utils.RSEHelper; | ||
22 | import org.yocto.remote.utils.RemoteShellExec; | ||
23 | |||
24 | abstract public class BaseModel implements IRunnableWithProgress { | ||
25 | protected IHost host; | ||
26 | protected String taskName; | ||
27 | protected String localScript; | ||
28 | protected String remoteExec; | ||
29 | protected String localFile; | ||
30 | protected String remoteFile; | ||
31 | |||
32 | private static final int WORKLOAD = 100; | ||
33 | |||
34 | private static final int INIT_PERCENT = 5; | ||
35 | private static final int PRE_PROCESS_PERCENT = 30; | ||
36 | private static final int PROCESS_PERCENT = 30; | ||
37 | private static final int POST_PROCESS_PERCENT = 30; | ||
38 | private static final int CLEAN_PERCENT = 5; | ||
39 | |||
40 | private static final String RUN_MSG = "Running task: "; | ||
41 | private static final String INIT_MSG = "Initializing "; | ||
42 | private static final String PRE_PROCESS_MSG = "Preparing "; | ||
43 | private static final String PROCESS_MSG = "Processing "; | ||
44 | private static final String POST_PROCESS_MSG = "Finishing "; | ||
45 | private static final String CLEAN_MSG = "Cleaning "; | ||
46 | private static final String DOTS = "..."; | ||
47 | private static final String FAILED_ERR_MSG = " failed with exit code "; | ||
48 | |||
49 | public void preProcess(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException{ | ||
50 | //upload script to remote | ||
51 | try { | ||
52 | RSEHelper.putRemoteFileInPlugin(host, localScript, remoteExec, monitor); | ||
53 | }catch (InterruptedException e){ | ||
54 | throw e; | ||
55 | }catch (InvocationTargetException e) { | ||
56 | throw e; | ||
57 | }catch (Exception e) { | ||
58 | throw new InvocationTargetException(e, e.getMessage()); | ||
59 | } | ||
60 | } | ||
61 | public void postProcess(IProgressMonitor monitor) throws InvocationTargetException,InterruptedException{} | ||
62 | |||
63 | abstract public void process(IProgressMonitor monitor) throws InvocationTargetException,InterruptedException; | ||
64 | |||
65 | public BaseModel(IHost host, String taskName, String localScript, String remoteExec) { | ||
66 | this.host = host; | ||
67 | this.taskName = taskName; | ||
68 | this.localScript = localScript; | ||
69 | this.remoteExec = remoteExec; | ||
70 | } | ||
71 | protected void init(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { | ||
72 | } | ||
73 | |||
74 | protected void clean(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { | ||
75 | } | ||
76 | |||
77 | public void run(IProgressMonitor monitor) throws InvocationTargetException, | ||
78 | InterruptedException { | ||
79 | |||
80 | try { | ||
81 | monitor.beginTask(RUN_MSG + taskName, WORKLOAD); | ||
82 | |||
83 | monitor.subTask(INIT_MSG + taskName + DOTS); | ||
84 | init(new SubProgressMonitor(monitor, INIT_PERCENT)); | ||
85 | |||
86 | monitor.subTask(PRE_PROCESS_MSG + taskName + DOTS); | ||
87 | preProcess(new SubProgressMonitor(monitor, PRE_PROCESS_PERCENT)); | ||
88 | |||
89 | monitor.subTask(PROCESS_MSG + taskName + DOTS); | ||
90 | process(new SubProgressMonitor(monitor, PROCESS_PERCENT)); | ||
91 | |||
92 | monitor.subTask(POST_PROCESS_MSG + taskName + DOTS); | ||
93 | postProcess(new SubProgressMonitor(monitor, POST_PROCESS_PERCENT)); | ||
94 | } catch (InterruptedException e){ | ||
95 | throw new InterruptedException("User cancelled!"); | ||
96 | } catch (InvocationTargetException e) { | ||
97 | throw e; | ||
98 | } finally { | ||
99 | monitor.subTask(CLEAN_MSG + taskName + DOTS); | ||
100 | clean(new SubProgressMonitor(monitor, CLEAN_PERCENT)); | ||
101 | monitor.done(); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | protected void getDataFile(IProgressMonitor monitor) throws Exception { | ||
106 | RSEHelper.getRemoteFile( host, localFile, remoteFile, monitor); | ||
107 | } | ||
108 | protected void runRemoteShellExec(IProgressMonitor monitor, String args, boolean cancelable) throws Exception { | ||
109 | try { | ||
110 | RemoteShellExec exec = new RemoteShellExec(host, remoteExec); | ||
111 | exec.start(null, args, monitor); | ||
112 | monitor.worked(1); | ||
113 | checkTerminate(exec.getInputStream()); | ||
114 | int exit_code = exec.waitFor(cancelable ? monitor : null); | ||
115 | exec.terminate(); | ||
116 | if(exit_code != 0) | ||
117 | throw new Exception(taskName + FAILED_ERR_MSG + new Integer(exit_code).toString()); | ||
118 | } finally { | ||
119 | monitor.done(); | ||
120 | } | ||
121 | } | ||
122 | protected void checkTerminate(InputStream inputStream) throws IOException {} | ||
123 | } | ||
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..7845959 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/BaseSettingDialog.java | |||
@@ -0,0 +1,216 @@ | |||
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 | *******************************************************************************/ | ||
21 | |||
22 | package org.yocto.sdk.remotetools.actions; | ||
23 | |||
24 | import org.yocto.remote.utils.RSEHelper; | ||
25 | import org.yocto.sdk.remotetools.Messages; | ||
26 | import org.yocto.sdk.remotetools.SWTFactory; | ||
27 | import org.eclipse.jface.dialogs.Dialog; | ||
28 | import org.eclipse.jface.dialogs.IDialogConstants; | ||
29 | import org.eclipse.rse.core.model.IHost; | ||
30 | import org.eclipse.rse.ui.actions.SystemNewConnectionAction; | ||
31 | import org.eclipse.swt.SWT; | ||
32 | import org.eclipse.swt.events.ModifyEvent; | ||
33 | import org.eclipse.swt.events.ModifyListener; | ||
34 | import org.eclipse.swt.events.SelectionAdapter; | ||
35 | import org.eclipse.swt.events.SelectionEvent; | ||
36 | import org.eclipse.swt.layout.GridData; | ||
37 | import org.eclipse.swt.layout.GridLayout; | ||
38 | import org.eclipse.swt.widgets.Button; | ||
39 | import org.eclipse.swt.widgets.Combo; | ||
40 | import org.eclipse.swt.widgets.Composite; | ||
41 | import org.eclipse.swt.widgets.Control; | ||
42 | import org.eclipse.swt.widgets.Label; | ||
43 | import org.eclipse.swt.widgets.Shell; | ||
44 | |||
45 | public class BaseSettingDialog extends Dialog { | ||
46 | |||
47 | protected String title; | ||
48 | protected String curConn; //current rse connection name | ||
49 | protected IHost conn;//rse IHost | ||
50 | |||
51 | protected Button newRemoteConnectionButton; | ||
52 | protected Label connectionLabel; | ||
53 | protected Combo connectionCombo; | ||
54 | protected SystemNewConnectionAction action = null; | ||
55 | |||
56 | |||
57 | protected BaseSettingDialog(Shell parentShell,String title, String connection) { | ||
58 | super(parentShell); | ||
59 | this.title=title; | ||
60 | this.curConn=connection; | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | protected void configureShell(Shell newShell) { | ||
65 | super.configureShell(newShell); | ||
66 | newShell.setText(title); | ||
67 | } | ||
68 | |||
69 | @Override | ||
70 | protected Control createDialogArea(Composite parent) { | ||
71 | Composite comp = (Composite)super.createDialogArea(parent); | ||
72 | GridLayout topLayout = new GridLayout(); | ||
73 | comp.setLayout(topLayout); | ||
74 | |||
75 | /* The RSE Connection dropdown with New button. */ | ||
76 | SWTFactory.createVerticalSpacer(comp, 1); | ||
77 | createRemoteConnectionGroup(comp); | ||
78 | |||
79 | return comp; | ||
80 | } | ||
81 | |||
82 | |||
83 | @Override | ||
84 | protected void createButtonsForButtonBar(Composite parent) { | ||
85 | super.createButtonsForButtonBar(parent); | ||
86 | updateCurConn(); | ||
87 | } | ||
88 | |||
89 | protected void createRemoteConnectionGroup(Composite parent) { | ||
90 | Composite projComp = new Composite(parent, SWT.NONE); | ||
91 | GridLayout projLayout = new GridLayout(); | ||
92 | projLayout.numColumns = 6; | ||
93 | projLayout.marginHeight = 0; | ||
94 | projLayout.marginWidth = 0; | ||
95 | projComp.setLayout(projLayout); | ||
96 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
97 | projComp.setLayoutData(gd); | ||
98 | |||
99 | connectionLabel = new Label(projComp, SWT.NONE); | ||
100 | connectionLabel.setText(Messages.BaseSettingDialog_Connection); | ||
101 | gd = new GridData(); | ||
102 | gd.horizontalSpan = 1; | ||
103 | connectionLabel.setLayoutData(gd); | ||
104 | |||
105 | connectionCombo = new Combo(projComp, SWT.DROP_DOWN | SWT.READ_ONLY); | ||
106 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
107 | gd.horizontalSpan = 4; | ||
108 | connectionCombo.setLayoutData(gd); | ||
109 | connectionCombo.addModifyListener(new ModifyListener() { | ||
110 | |||
111 | public void modifyText(ModifyEvent e) { | ||
112 | //setDirty(true); | ||
113 | //updateLaunchConfigurationDialog(); | ||
114 | //useDefaultsFromConnection(); | ||
115 | updateCurConn(); | ||
116 | } | ||
117 | }); | ||
118 | |||
119 | newRemoteConnectionButton = SWTFactory.createPushButton(projComp, | ||
120 | Messages.BaseSettingDialog_New, null); | ||
121 | newRemoteConnectionButton.addSelectionListener(new SelectionAdapter() { | ||
122 | |||
123 | public void widgetSelected(SelectionEvent evt) { | ||
124 | handleNewRemoteConnectionSelected(); | ||
125 | //updateLaunchConfigurationDialog(); | ||
126 | updateConnectionPulldown(); | ||
127 | } | ||
128 | }); | ||
129 | gd = new GridData(); | ||
130 | gd.horizontalSpan = 1; | ||
131 | newRemoteConnectionButton.setLayoutData(gd); | ||
132 | |||
133 | updateConnectionPulldown(); | ||
134 | } | ||
135 | |||
136 | protected boolean updateOkButton() { | ||
137 | boolean ret=false; | ||
138 | Button button=getButton(IDialogConstants.OK_ID); | ||
139 | if(button!=null) | ||
140 | button.setEnabled(false); | ||
141 | IHost currentConnectionSelected = getCurrentConnection(); | ||
142 | if (currentConnectionSelected != null) { | ||
143 | if (RSEHelper.isHostViable(currentConnectionSelected) && button != null){ | ||
144 | button.setEnabled(true); | ||
145 | ret=true; | ||
146 | } | ||
147 | } | ||
148 | return ret; | ||
149 | } | ||
150 | |||
151 | protected void updateCurConn() { | ||
152 | IHost currentConnectionSelected = getCurrentConnection(); | ||
153 | if (currentConnectionSelected != null) { | ||
154 | if (RSEHelper.isHostViable(currentConnectionSelected)) | ||
155 | curConn=currentConnectionSelected.getAliasName(); | ||
156 | } | ||
157 | updateOkButton(); | ||
158 | } | ||
159 | |||
160 | protected IHost getCurrentConnection() { | ||
161 | int currentSelection = connectionCombo.getSelectionIndex(); | ||
162 | String remoteConnection = currentSelection >= 0 ? connectionCombo | ||
163 | .getItem(currentSelection) : null; | ||
164 | return RSEHelper.getRemoteConnectionByName(remoteConnection); | ||
165 | } | ||
166 | |||
167 | protected void handleNewRemoteConnectionSelected() { | ||
168 | if (action == null) { | ||
169 | action = new SystemNewConnectionAction(getShell(), | ||
170 | false, false, null); | ||
171 | } | ||
172 | |||
173 | try { | ||
174 | action.run(); | ||
175 | } catch (Exception e) { | ||
176 | // Ignore | ||
177 | } | ||
178 | } | ||
179 | |||
180 | protected void updateConnectionPulldown() { | ||
181 | int index=-1; | ||
182 | RSEHelper.waitForRSEInitCompletition(); | ||
183 | // already initialized | ||
184 | connectionCombo.removeAll(); | ||
185 | IHost[] connections = RSEHelper.getSuitableConnections(); | ||
186 | for (int i = 0; i < connections.length; i++) { | ||
187 | connectionCombo.add(connections[i].getAliasName()); | ||
188 | if(connections[i].getAliasName().equals(curConn)) | ||
189 | index=i; | ||
190 | } | ||
191 | |||
192 | if(index>=0) { | ||
193 | connectionCombo.select(index); | ||
194 | }else if (connections.length > 0) { | ||
195 | connectionCombo.select(connections.length - 1); | ||
196 | } | ||
197 | |||
198 | //TODO | ||
199 | //connectionCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT,true); | ||
200 | connectionCombo.pack(true); | ||
201 | connectionCombo.layout(); | ||
202 | connectionCombo.getParent().layout(); | ||
203 | |||
204 | updateCurConn(); | ||
205 | } | ||
206 | |||
207 | @Override | ||
208 | protected void okPressed() { | ||
209 | conn=getCurrentConnection(); | ||
210 | super.okPressed(); | ||
211 | } | ||
212 | |||
213 | public IHost getHost() { | ||
214 | return conn; | ||
215 | } | ||
216 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java new file mode 100644 index 0000000..231de77 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/DialogHandler.java | |||
@@ -0,0 +1,42 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2013 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import org.eclipse.core.commands.ExecutionEvent; | ||
14 | import org.eclipse.core.commands.ExecutionException; | ||
15 | import org.eclipse.rse.core.model.IHost; | ||
16 | import org.eclipse.ui.IWorkbenchWindow; | ||
17 | import org.eclipse.ui.handlers.HandlerUtil; | ||
18 | import org.yocto.remote.utils.TerminalHandler; | ||
19 | |||
20 | abstract public class DialogHandler extends TerminalHandler { | ||
21 | |||
22 | protected BaseSettingDialog setting; | ||
23 | |||
24 | abstract protected String getDialogTitle(); | ||
25 | |||
26 | protected void initialize(ExecutionEvent event) throws ExecutionException{ | ||
27 | IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); | ||
28 | shell = window.getShell(); | ||
29 | setting = new SimpleSettingDialog(shell, getDialogTitle(), getConnnectionName()); | ||
30 | } | ||
31 | |||
32 | @Override | ||
33 | public Object execute(ExecutionEvent event) throws ExecutionException { | ||
34 | initialize(event); | ||
35 | |||
36 | if(setting.open() == BaseSettingDialog.OK) { | ||
37 | IHost currentHost = setting.getHost(); | ||
38 | execute(currentHost); | ||
39 | } | ||
40 | return null; | ||
41 | } | ||
42 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/IBaseConstants.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/IBaseConstants.java new file mode 100644 index 0000000..d4bbe12 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/IBaseConstants.java | |||
@@ -0,0 +1,27 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | public interface IBaseConstants { | ||
14 | public static final String TCF_TYPE_ID="org.eclipse.tcf.rse.systemType";//$NON-NLS-1$ | ||
15 | |||
16 | public static final String QUALIFIER="org.yocto.sdk.remotetools";//$NON-NLS-1$ | ||
17 | |||
18 | public static final String CONNECTION_NAME_OPROFILE = QUALIFIER + "connection.oprofile"; //$NON-NLS-1$ | ||
19 | public static final String CONNECTION_NAME_UST = QUALIFIER + "connection.ust"; //$NON-NLS-1$ | ||
20 | public static final String CONNECTION_NAME_POWERTOP = QUALIFIER + "connection.powertop"; //$NON-NLS-1$ | ||
21 | public static final String CONNECTION_NAME_LATENCYTOP = QUALIFIER + "connection.latencytop"; //$NON-NLS-1$ | ||
22 | public static final String CONNECTION_NAME_PERF = QUALIFIER + "connection.perf"; //$NON-NLS-1$ | ||
23 | public static final String CONNECTION_NAME_SYSTEMTAP = QUALIFIER + "connection.systemtap"; //$NON-NLS-1$ | ||
24 | |||
25 | public static final String DIALOG_TITLE_LATENCYTOP = "Latencytop"; //$NON-NLS-1$ | ||
26 | public static final String DIALOG_TITLE_PERF = "Perf"; //$NON-NLS-1$ | ||
27 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/LatencytopHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/LatencytopHandler.java new file mode 100644 index 0000000..1088dee --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/LatencytopHandler.java | |||
@@ -0,0 +1,35 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | |||
14 | public class LatencytopHandler extends DialogHandler { | ||
15 | |||
16 | protected String changeTerm = "export TERM=xterm;"; | ||
17 | private static String initCmd="export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin; cd; sudo latencytop\r"; | ||
18 | |||
19 | @Override | ||
20 | protected String getInitCmd() { | ||
21 | return initCmd; | ||
22 | } | ||
23 | @Override | ||
24 | protected String changeTerm() { | ||
25 | return changeTerm; | ||
26 | } | ||
27 | @Override | ||
28 | protected String getConnnectionName() { | ||
29 | return IBaseConstants.CONNECTION_NAME_LATENCYTOP; | ||
30 | } | ||
31 | @Override | ||
32 | protected String getDialogTitle() { | ||
33 | return IBaseConstants.DIALOG_TITLE_LATENCYTOP; | ||
34 | } | ||
35 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileHandler.java new file mode 100644 index 0000000..980737f --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileHandler.java | |||
@@ -0,0 +1,55 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import org.eclipse.core.commands.AbstractHandler; | ||
14 | import org.eclipse.core.commands.ExecutionEvent; | ||
15 | import org.eclipse.core.commands.ExecutionException; | ||
16 | import org.eclipse.jface.dialogs.MessageDialog; | ||
17 | import org.eclipse.ui.IWorkbenchWindow; | ||
18 | import org.eclipse.ui.PlatformUI; | ||
19 | import org.eclipse.ui.handlers.HandlerUtil; | ||
20 | import org.eclipse.ui.progress.IProgressService; | ||
21 | |||
22 | public class OprofileHandler extends AbstractHandler { | ||
23 | |||
24 | public Object execute(ExecutionEvent event) throws ExecutionException { | ||
25 | |||
26 | if(OprofileModel.checkAvail()!=true) { | ||
27 | return null; | ||
28 | } | ||
29 | |||
30 | IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); | ||
31 | |||
32 | SimpleSettingDialog setting=new SimpleSettingDialog( | ||
33 | window.getShell(), | ||
34 | "Oprofile", | ||
35 | IBaseConstants.CONNECTION_NAME_OPROFILE | ||
36 | ); | ||
37 | |||
38 | if(setting.open()==BaseSettingDialog.OK) { | ||
39 | IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); | ||
40 | OprofileModel op=new OprofileModel(setting.getHost(),window); | ||
41 | try { | ||
42 | progressService.busyCursorWhile(op); | ||
43 | }catch (InterruptedException e) { | ||
44 | //user cancelled | ||
45 | }catch (Exception e) { | ||
46 | e.printStackTrace(); | ||
47 | MessageDialog.openError(window.getShell(), | ||
48 | "Oprofile", | ||
49 | (e.getCause() != null) ? e.getCause().getMessage() : e.getMessage()); | ||
50 | } | ||
51 | } | ||
52 | return null; | ||
53 | } | ||
54 | |||
55 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java new file mode 100644 index 0000000..7fbe7c6 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/OprofileModel.java | |||
@@ -0,0 +1,171 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import java.io.BufferedReader; | ||
14 | import java.io.File; | ||
15 | import java.io.FileReader; | ||
16 | import java.io.IOException; | ||
17 | import java.lang.reflect.InvocationTargetException; | ||
18 | |||
19 | import org.eclipse.core.runtime.IProgressMonitor; | ||
20 | import org.eclipse.core.runtime.SubProgressMonitor; | ||
21 | import org.eclipse.jface.preference.IPreferenceStore; | ||
22 | import org.eclipse.rse.core.model.IHost; | ||
23 | import org.eclipse.ui.IWorkbenchWindow; | ||
24 | import org.yocto.remote.utils.CommonHelper; | ||
25 | import org.yocto.sdk.ide.YoctoSDKPlugin; | ||
26 | import org.yocto.sdk.ide.preferences.PreferenceConstants; | ||
27 | import org.yocto.sdk.remotetools.LocalJob; | ||
28 | import org.yocto.sdk.remotetools.Messages; | ||
29 | |||
30 | public class OprofileModel extends BaseModel { | ||
31 | |||
32 | private static final String REMOTE_EXEC = "/tmp/yocto_tool.sh"; | ||
33 | private static final String LOCAL_SCRIPT = "resources/yocto_tool.sh"; | ||
34 | |||
35 | private static final String LOCAL_EXEC = "oprofile-viewer"; | ||
36 | |||
37 | private static final String TASK_NAME = "oprofile command"; | ||
38 | |||
39 | private IWorkbenchWindow window; | ||
40 | public OprofileModel(IHost host, IWorkbenchWindow window) { | ||
41 | super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); | ||
42 | this.window = window; | ||
43 | } | ||
44 | |||
45 | private void startServer(IProgressMonitor monitor) throws Exception { | ||
46 | String args="start -d oprofile-server"; | ||
47 | runRemoteShellExec(monitor, args, true); | ||
48 | } | ||
49 | |||
50 | private void stopServer(IProgressMonitor monitor) throws Exception { | ||
51 | String args = "stop -d oprofile-server"; | ||
52 | runRemoteShellExec(monitor, args, false); | ||
53 | } | ||
54 | |||
55 | private String getSearchPath() | ||
56 | { | ||
57 | try | ||
58 | { | ||
59 | String search=null; | ||
60 | IPreferenceStore store = YoctoSDKPlugin.getDefault().getPreferenceStore(); | ||
61 | String env_script=store.getString(PreferenceConstants.TOOLCHAIN_ROOT) + | ||
62 | "/" + | ||
63 | "environment-setup-" + | ||
64 | store.getString(PreferenceConstants.TOOLCHAIN_TRIPLET); | ||
65 | File file = new File(env_script); | ||
66 | |||
67 | if (file.exists()) { | ||
68 | BufferedReader input = new BufferedReader(new FileReader(file)); | ||
69 | |||
70 | try | ||
71 | { | ||
72 | String line = null; | ||
73 | |||
74 | while ((line = input.readLine()) != null) | ||
75 | { | ||
76 | if (!line.startsWith("export")) | ||
77 | continue; | ||
78 | String sKey = line.substring("export".length() + 1, line.indexOf('=')); | ||
79 | if(!sKey.equals("PATH")) | ||
80 | continue; | ||
81 | String sValue = line.substring(line.indexOf('=') + 1); | ||
82 | if (sValue.startsWith("\"") && sValue.endsWith("\"")) | ||
83 | sValue = sValue.substring(sValue.indexOf('"') + 1, sValue.lastIndexOf('"')); | ||
84 | /* If PATH ending with $PATH, we need to join with current system path */ | ||
85 | if (sKey.equalsIgnoreCase("PATH")) { | ||
86 | if (sValue.lastIndexOf("$PATH") >= 0) | ||
87 | sValue = sValue.substring(0, sValue.lastIndexOf("$PATH")) + System.getenv("PATH"); | ||
88 | } | ||
89 | search=sValue; | ||
90 | //System.out.printf("get env key %s value %s\n", sKey, sValue); | ||
91 | } | ||
92 | |||
93 | } | ||
94 | finally { | ||
95 | input.close(); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | return search; | ||
100 | |||
101 | } | ||
102 | catch (IOException e) | ||
103 | { | ||
104 | e.printStackTrace(); | ||
105 | return null; | ||
106 | } | ||
107 | |||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public void process(IProgressMonitor monitor) | ||
112 | throws InvocationTargetException, InterruptedException { | ||
113 | |||
114 | boolean stopServer=true; | ||
115 | |||
116 | try { | ||
117 | try { | ||
118 | monitor.beginTask("Starting oprofile", 100); | ||
119 | //start oprofile-server | ||
120 | monitor.subTask("Starting oprofile-server"); | ||
121 | startServer(new SubProgressMonitor(monitor,80)); | ||
122 | |||
123 | //start local oprofile-viewer | ||
124 | monitor.subTask("oprofile-viewer is running locally"); | ||
125 | String searchPath=getSearchPath(); | ||
126 | |||
127 | new LocalJob("oprofile-viewer", | ||
128 | (searchPath!=null) ? | ||
129 | new String[] {LOCAL_EXEC,"-h",host.getHostName(),"-s",searchPath} : | ||
130 | new String[] {LOCAL_EXEC,"-h",host.getHostName()}, | ||
131 | null, | ||
132 | null, | ||
133 | window).schedule(); | ||
134 | //we can't stop server because the oprofile-viewer is running asynchronously | ||
135 | stopServer=false; | ||
136 | |||
137 | }catch (InterruptedException e) { | ||
138 | throw e; | ||
139 | }finally { | ||
140 | //stop oprofile-server | ||
141 | if(stopServer) { | ||
142 | monitor.subTask("Stopping oprofile-viewer"); | ||
143 | stopServer(new SubProgressMonitor(monitor,30)); | ||
144 | } | ||
145 | } | ||
146 | }catch (InterruptedException e){ | ||
147 | throw e; | ||
148 | }catch (InvocationTargetException e) { | ||
149 | throw e; | ||
150 | }catch (Exception e){ | ||
151 | throw new InvocationTargetException(e, e.getMessage()); | ||
152 | }finally { | ||
153 | monitor.done(); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | static public boolean checkAvail() { | ||
158 | boolean ret=CommonHelper.isExecAvail(LOCAL_EXEC); | ||
159 | |||
160 | if(ret==false) { | ||
161 | CommonHelper.showErrorDialog("Oprofile", null,Messages.ErrorOprofileViewer); | ||
162 | }else { | ||
163 | ret=CommonHelper.isExecAvail("opreport"); | ||
164 | if(ret==false) { | ||
165 | CommonHelper.showErrorDialog("Oprofile", null,Messages.ErrorOprofile); | ||
166 | } | ||
167 | } | ||
168 | return ret; | ||
169 | } | ||
170 | |||
171 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PerfHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PerfHandler.java new file mode 100644 index 0000000..f3f9e49 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PerfHandler.java | |||
@@ -0,0 +1,30 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | |||
14 | public class PerfHandler extends DialogHandler { | ||
15 | |||
16 | private static String initCmd="cd; perf\r"; | ||
17 | |||
18 | @Override | ||
19 | protected String getInitCmd() { | ||
20 | return initCmd; | ||
21 | } | ||
22 | @Override | ||
23 | protected String getConnnectionName() { | ||
24 | return IBaseConstants.CONNECTION_NAME_PERF; | ||
25 | } | ||
26 | @Override | ||
27 | protected String getDialogTitle() { | ||
28 | return IBaseConstants.DIALOG_TITLE_PERF; | ||
29 | } | ||
30 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopHandler.java new file mode 100644 index 0000000..152f142 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopHandler.java | |||
@@ -0,0 +1,48 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import org.eclipse.core.commands.AbstractHandler; | ||
14 | import org.eclipse.core.commands.ExecutionEvent; | ||
15 | import org.eclipse.core.commands.ExecutionException; | ||
16 | import org.eclipse.jface.dialogs.MessageDialog; | ||
17 | import org.eclipse.ui.IWorkbenchWindow; | ||
18 | import org.eclipse.ui.PlatformUI; | ||
19 | import org.eclipse.ui.handlers.HandlerUtil; | ||
20 | import org.eclipse.ui.progress.IProgressService; | ||
21 | |||
22 | public class PowertopHandler extends AbstractHandler { | ||
23 | |||
24 | public Object execute(ExecutionEvent event) throws ExecutionException { | ||
25 | IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); | ||
26 | |||
27 | PowertopSettingDialog setting=new PowertopSettingDialog( | ||
28 | window.getShell() | ||
29 | ); | ||
30 | |||
31 | if(setting.open()==BaseSettingDialog.OK) { | ||
32 | IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); | ||
33 | PowertopModel op=new PowertopModel(setting.getHost(),setting.getTime(),setting.getShowPid(),window.getShell().getDisplay()); | ||
34 | try { | ||
35 | progressService.busyCursorWhile(op); | ||
36 | }catch (InterruptedException e) { | ||
37 | //user cancelled | ||
38 | }catch (Exception e) { | ||
39 | e.printStackTrace(); | ||
40 | MessageDialog.openError(window.getShell(), | ||
41 | "Powertop", | ||
42 | (e.getCause() != null) ? e.getCause().getMessage() : e.getMessage()); | ||
43 | } | ||
44 | } | ||
45 | return null; | ||
46 | } | ||
47 | |||
48 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java new file mode 100644 index 0000000..79bef61 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java | |||
@@ -0,0 +1,109 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import java.io.File; | ||
14 | import java.lang.reflect.InvocationTargetException; | ||
15 | import java.text.SimpleDateFormat; | ||
16 | import java.util.Calendar; | ||
17 | |||
18 | import org.eclipse.core.runtime.IProgressMonitor; | ||
19 | import org.eclipse.core.runtime.SubProgressMonitor; | ||
20 | import org.eclipse.rse.core.model.IHost; | ||
21 | import org.eclipse.swt.widgets.Display; | ||
22 | import org.eclipse.ui.IWorkbenchPage; | ||
23 | import org.eclipse.ui.PartInitException; | ||
24 | import org.eclipse.ui.PlatformUI; | ||
25 | import org.yocto.sdk.remotetools.views.BaseFileView; | ||
26 | |||
27 | public class PowertopModel extends BaseModel { | ||
28 | |||
29 | private static final String REMOTE_EXEC = "/tmp/yocto_tool.sh"; | ||
30 | private static final String LOCAL_SCRIPT = "resources/yocto_tool.sh"; | ||
31 | |||
32 | private static final String REMOTE_FILE_PREFIX = "/tmp/yocto-powertop-"; | ||
33 | private static final String LOCAL_FILE_SUFFIX = ".local"; | ||
34 | |||
35 | private static final String TASK_NAME = "powertop command"; | ||
36 | |||
37 | private Float time; | ||
38 | private boolean showpid; | ||
39 | Display display; | ||
40 | |||
41 | public PowertopModel(IHost host, Float time,boolean showpid,Display display) { | ||
42 | super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); | ||
43 | this.time=time; | ||
44 | this.showpid=showpid; | ||
45 | this.display=display; | ||
46 | } | ||
47 | |||
48 | @Override | ||
49 | public void postProcess(IProgressMonitor monitor) | ||
50 | throws InvocationTargetException, InterruptedException { | ||
51 | try { | ||
52 | new File(localFile).delete(); | ||
53 | }catch (Exception e) { | ||
54 | |||
55 | } | ||
56 | } | ||
57 | |||
58 | private void generateData(IProgressMonitor monitor) throws Exception { | ||
59 | String currentDate = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()).toString(); | ||
60 | remoteFile = new String(REMOTE_FILE_PREFIX + currentDate); | ||
61 | localFile = new String(remoteFile + LOCAL_FILE_SUFFIX); | ||
62 | |||
63 | String args = "start -l " + remoteFile + " powertop --debug --time " + time.toString(); | ||
64 | if(showpid) | ||
65 | args += " -p"; | ||
66 | runRemoteShellExec(monitor, args, true); | ||
67 | } | ||
68 | |||
69 | @Override | ||
70 | public void process(IProgressMonitor monitor) | ||
71 | throws InvocationTargetException, InterruptedException { | ||
72 | |||
73 | monitor.beginTask("Running powertop", 100); | ||
74 | try { | ||
75 | //running powertop | ||
76 | monitor.subTask("Generating powertop data file remotely"); | ||
77 | generateData(new SubProgressMonitor(monitor,30)); | ||
78 | //download datafile | ||
79 | monitor.subTask("Downloading powertop data file"); | ||
80 | getDataFile(new SubProgressMonitor(monitor,30)); | ||
81 | //show it in the powertop view | ||
82 | display.syncExec(new Runnable() { | ||
83 | public void run() { | ||
84 | BaseFileView view; | ||
85 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||
86 | try { | ||
87 | view=(BaseFileView) page.showView("org.yocto.sdk.remotetools.views.PowerTopView"); | ||
88 | }catch (PartInitException e) { | ||
89 | e.printStackTrace(); | ||
90 | return; | ||
91 | } | ||
92 | view.setInput(localFile); | ||
93 | page.bringToTop(view); | ||
94 | } | ||
95 | }); | ||
96 | |||
97 | }catch (InterruptedException e){ | ||
98 | throw e; | ||
99 | }catch (InvocationTargetException e) { | ||
100 | throw e; | ||
101 | }catch (Exception e){ | ||
102 | throw new InvocationTargetException(e, e.getMessage()); | ||
103 | }finally { | ||
104 | monitor.done(); | ||
105 | } | ||
106 | |||
107 | } | ||
108 | |||
109 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopSettingDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopSettingDialog.java new file mode 100644 index 0000000..bb41a4a --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopSettingDialog.java | |||
@@ -0,0 +1,131 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import org.eclipse.jface.dialogs.IDialogConstants; | ||
14 | import org.eclipse.jface.dialogs.IDialogSettings; | ||
15 | import org.eclipse.swt.SWT; | ||
16 | import org.eclipse.swt.events.ModifyEvent; | ||
17 | import org.eclipse.swt.events.ModifyListener; | ||
18 | import org.eclipse.swt.layout.GridData; | ||
19 | import org.eclipse.swt.layout.GridLayout; | ||
20 | import org.eclipse.swt.widgets.Button; | ||
21 | import org.eclipse.swt.widgets.Composite; | ||
22 | import org.eclipse.swt.widgets.Control; | ||
23 | import org.eclipse.swt.widgets.Label; | ||
24 | import org.eclipse.swt.widgets.Shell; | ||
25 | import org.eclipse.swt.widgets.Text; | ||
26 | import org.yocto.sdk.remotetools.Activator; | ||
27 | import org.yocto.sdk.remotetools.Messages; | ||
28 | import org.yocto.sdk.remotetools.SWTFactory; | ||
29 | |||
30 | public class PowertopSettingDialog extends BaseSettingDialog { | ||
31 | |||
32 | static protected String TITLE="Powertop"; | ||
33 | |||
34 | protected boolean showPid=false; | ||
35 | protected Float time; | ||
36 | protected Button showPidButton; | ||
37 | protected Text timeText; | ||
38 | |||
39 | protected PowertopSettingDialog(Shell parentShell, String title, String conn) { | ||
40 | super(parentShell,title,conn); | ||
41 | } | ||
42 | |||
43 | public PowertopSettingDialog(Shell parentShell) { | ||
44 | this(parentShell, | ||
45 | TITLE, | ||
46 | Activator.getDefault().getDialogSettings().get(IBaseConstants.CONNECTION_NAME_POWERTOP) | ||
47 | ); | ||
48 | } | ||
49 | |||
50 | public boolean getShowPid() { | ||
51 | return showPid; | ||
52 | } | ||
53 | |||
54 | public Float getTime() { | ||
55 | return time; | ||
56 | } | ||
57 | |||
58 | @Override | ||
59 | protected Control createDialogArea(Composite parent) { | ||
60 | Composite comp=(Composite)super.createDialogArea(parent); | ||
61 | GridLayout topLayout = new GridLayout(); | ||
62 | comp.setLayout(topLayout); | ||
63 | |||
64 | /*argument*/ | ||
65 | SWTFactory.createVerticalSpacer(comp, 1); | ||
66 | createInternal(comp); | ||
67 | |||
68 | updateOkButton(); | ||
69 | return comp; | ||
70 | } | ||
71 | |||
72 | protected void createInternal(Composite parent) | ||
73 | { | ||
74 | Composite projComp = new Composite(parent, SWT.NONE); | ||
75 | GridLayout projLayout = new GridLayout(); | ||
76 | projLayout.numColumns = 4; | ||
77 | projLayout.marginHeight = 0; | ||
78 | projLayout.marginWidth = 0; | ||
79 | projComp.setLayout(projLayout); | ||
80 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
81 | projComp.setLayoutData(gd); | ||
82 | |||
83 | Label label = new Label(projComp, SWT.NONE); | ||
84 | label.setText(Messages.Powertop_Time_Text); | ||
85 | gd = new GridData(); | ||
86 | gd.horizontalSpan = 1; | ||
87 | label.setLayoutData(gd); | ||
88 | |||
89 | timeText = new Text(projComp, SWT.SINGLE | SWT.BORDER); | ||
90 | timeText.setText("5"); | ||
91 | timeText.addModifyListener(new ModifyListener() { | ||
92 | public void modifyText(ModifyEvent e) { | ||
93 | updateOkButton(); | ||
94 | } | ||
95 | }); | ||
96 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
97 | gd.horizontalSpan = 3; | ||
98 | timeText.setLayoutData(gd); | ||
99 | } | ||
100 | |||
101 | @Override | ||
102 | protected boolean updateOkButton() { | ||
103 | boolean ret=super.updateOkButton(); | ||
104 | if(ret==true) { | ||
105 | try { | ||
106 | Float.valueOf(timeText.getText()); | ||
107 | }catch (Exception e) { | ||
108 | Button button=getButton(IDialogConstants.OK_ID); | ||
109 | if(button!=null) | ||
110 | button.setEnabled(false); | ||
111 | ret=false; | ||
112 | } | ||
113 | } | ||
114 | return ret; | ||
115 | } | ||
116 | |||
117 | @Override | ||
118 | protected void okPressed() { | ||
119 | IDialogSettings settings = Activator.getDefault().getDialogSettings(); | ||
120 | // store the value of the generate sections checkbox | ||
121 | if(getCurrentConnection()==null) { | ||
122 | settings.put(IBaseConstants.CONNECTION_NAME_POWERTOP, | ||
123 | (String)null); | ||
124 | }else { | ||
125 | settings.put(IBaseConstants.CONNECTION_NAME_POWERTOP, | ||
126 | getCurrentConnection().getAliasName()); | ||
127 | } | ||
128 | time=new Float(timeText.getText()); | ||
129 | super.okPressed(); | ||
130 | } | ||
131 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SimpleSettingDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SimpleSettingDialog.java new file mode 100644 index 0000000..140d892 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SimpleSettingDialog.java | |||
@@ -0,0 +1,54 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import org.yocto.sdk.remotetools.Activator; | ||
14 | import org.eclipse.jface.dialogs.IDialogSettings; | ||
15 | import org.eclipse.swt.widgets.Composite; | ||
16 | import org.eclipse.swt.widgets.Control; | ||
17 | import org.eclipse.swt.widgets.Shell; | ||
18 | |||
19 | public class SimpleSettingDialog extends BaseSettingDialog { | ||
20 | |||
21 | private final String connPropName; | ||
22 | /* | ||
23 | protected SimpleSettingDialog(Shell parentShell, String title, String conn) { | ||
24 | super(parentShell,title,conn); | ||
25 | } | ||
26 | */ | ||
27 | |||
28 | public SimpleSettingDialog(Shell parentShell, String title, String connPropertyName) { | ||
29 | super(parentShell, | ||
30 | title, | ||
31 | Activator.getDefault().getDialogSettings().get(connPropertyName) | ||
32 | ); | ||
33 | connPropName=connPropertyName; | ||
34 | } | ||
35 | |||
36 | @Override | ||
37 | protected Control createDialogArea(Composite parent) { | ||
38 | return super.createDialogArea(parent); | ||
39 | } | ||
40 | |||
41 | @Override | ||
42 | protected void okPressed() { | ||
43 | IDialogSettings settings = Activator.getDefault().getDialogSettings(); | ||
44 | // store the value of the generate sections checkbox | ||
45 | if(getCurrentConnection()==null) { | ||
46 | settings.put(connPropName, | ||
47 | (String)null); | ||
48 | }else { | ||
49 | settings.put(connPropName, | ||
50 | getCurrentConnection().getAliasName()); | ||
51 | } | ||
52 | super.okPressed(); | ||
53 | } | ||
54 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapHandler.java new file mode 100644 index 0000000..f5d34d8 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapHandler.java | |||
@@ -0,0 +1,70 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2011 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | import org.eclipse.core.commands.AbstractHandler; | ||
13 | import org.eclipse.core.commands.ExecutionEvent; | ||
14 | import org.eclipse.core.commands.ExecutionException; | ||
15 | import org.eclipse.jface.dialogs.MessageDialog; | ||
16 | import org.eclipse.swt.widgets.Shell; | ||
17 | import org.eclipse.ui.IWorkbenchWindow; | ||
18 | import org.eclipse.ui.PlatformUI; | ||
19 | import org.eclipse.ui.handlers.HandlerUtil; | ||
20 | import org.eclipse.ui.progress.IProgressService; | ||
21 | |||
22 | public class SystemtapHandler extends AbstractHandler { | ||
23 | protected SystemtapSettingDialog setting; | ||
24 | protected String changeTerm="export TERM=vt100;"; | ||
25 | protected IWorkbenchWindow window; | ||
26 | protected Shell shell; | ||
27 | |||
28 | public Object execute(ExecutionEvent event) throws ExecutionException { | ||
29 | |||
30 | this.window = HandlerUtil.getActiveWorkbenchWindowChecked(event); | ||
31 | shell = window.getShell(); | ||
32 | setting=new SystemtapSettingDialog( | ||
33 | shell, "Systemtap" | ||
34 | ); | ||
35 | |||
36 | |||
37 | if(setting.open() == BaseSettingDialog.OK) { | ||
38 | |||
39 | String metadata_location = ((SystemtapSettingDialog)setting).getMetadataLocation(); | ||
40 | String builddir_location = ((SystemtapSettingDialog)setting).getBuilddirLocation(); | ||
41 | String remote_host = ((SystemtapSettingDialog)setting).getRemoteHost(); | ||
42 | String user_id = ((SystemtapSettingDialog)setting).getUserID(); | ||
43 | String systemtap_script = ((SystemtapSettingDialog)setting).getSystemtapScript(); | ||
44 | String systemtap_args = ((SystemtapSettingDialog)setting).getSystemtapArgs(); | ||
45 | IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); | ||
46 | SystemtapModel op = new SystemtapModel(metadata_location, builddir_location, remote_host, user_id, systemtap_script, | ||
47 | systemtap_args,window.getShell().getDisplay()); | ||
48 | try { | ||
49 | progressService.busyCursorWhile(op); | ||
50 | }catch (InterruptedException e) { | ||
51 | //user cancelled | ||
52 | }catch (Exception e) { | ||
53 | e.printStackTrace(); | ||
54 | MessageDialog.openError(window.getShell(), | ||
55 | "Systemtap", | ||
56 | e.getMessage()); | ||
57 | } | ||
58 | } | ||
59 | return false; | ||
60 | } | ||
61 | |||
62 | protected void initialize(ExecutionEvent event) throws ExecutionException { | ||
63 | this.window = HandlerUtil.getActiveWorkbenchWindowChecked(event); | ||
64 | shell = window.getShell(); | ||
65 | setting=new SystemtapSettingDialog( | ||
66 | shell, "Systemtap" | ||
67 | ); | ||
68 | } | ||
69 | |||
70 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java new file mode 100644 index 0000000..bb2fa2d --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java | |||
@@ -0,0 +1,88 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import java.io.File; | ||
14 | import java.lang.reflect.InvocationTargetException; | ||
15 | |||
16 | import org.eclipse.core.runtime.IProgressMonitor; | ||
17 | import org.eclipse.swt.widgets.Display; | ||
18 | import org.eclipse.ui.console.ConsolePlugin; | ||
19 | import org.eclipse.ui.console.IConsole; | ||
20 | import org.eclipse.ui.console.IConsoleManager; | ||
21 | import org.eclipse.ui.console.MessageConsole; | ||
22 | import org.yocto.remote.utils.ShellSession; | ||
23 | |||
24 | public class SystemtapModel extends BaseModel { | ||
25 | protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env"; | ||
26 | protected static final String SYSTEMTAP_CONSOLE = "Systemtap Console"; | ||
27 | |||
28 | private static final String TASK_NAME = "systemtap command"; | ||
29 | |||
30 | protected MessageConsole sessionConsole; | ||
31 | private String metadata_location; | ||
32 | private String builddir_location; | ||
33 | private String remote_host; | ||
34 | private String user_id; | ||
35 | private String systemtap_script; | ||
36 | private String systemtap_args; | ||
37 | |||
38 | Display display; | ||
39 | |||
40 | public SystemtapModel(String metadata_location, String builddir_location, String remote_host, String user_id, String systemtap_script, String systemtap_args, Display display) { | ||
41 | super(null, TASK_NAME, "", ""); | ||
42 | this.metadata_location = metadata_location; | ||
43 | this.builddir_location = builddir_location; | ||
44 | this.remote_host = remote_host; | ||
45 | this.user_id = user_id; | ||
46 | this.systemtap_script = systemtap_script; | ||
47 | this.systemtap_args = systemtap_args; | ||
48 | this.display = display; | ||
49 | if (sessionConsole == null) { | ||
50 | IConsoleManager conMan = ConsolePlugin.getDefault().getConsoleManager(); | ||
51 | IConsole[] existing = conMan.getConsoles(); | ||
52 | for (int i = 0; i < existing.length; i++) | ||
53 | if (SYSTEMTAP_CONSOLE.equals(existing[i].getName())) { | ||
54 | sessionConsole = (MessageConsole) existing[i]; | ||
55 | break; | ||
56 | } | ||
57 | if (sessionConsole == null) { | ||
58 | sessionConsole = new MessageConsole(SYSTEMTAP_CONSOLE, null); | ||
59 | conMan.addConsoles(new IConsole[] { sessionConsole }); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | ConsolePlugin.getDefault().getConsoleManager().showConsoleView(sessionConsole); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public void preProcess(IProgressMonitor monitor) | ||
68 | throws InvocationTargetException, InterruptedException {} | ||
69 | |||
70 | @Override | ||
71 | public void process(IProgressMonitor monitor) | ||
72 | throws InvocationTargetException, InterruptedException { | ||
73 | try { | ||
74 | ShellSession shell = new ShellSession(ShellSession.SHELL_TYPE_BASH, | ||
75 | new File(this.metadata_location), new File(this.builddir_location), | ||
76 | DEFAULT_INIT_SCRIPT, sessionConsole.newOutputStream()); | ||
77 | boolean acceptedKey = shell.ensureKnownHostKey(user_id, remote_host); | ||
78 | if (acceptedKey) { | ||
79 | String crosstapCmd = "crosstap " + user_id + "@" + remote_host + " " + systemtap_script; | ||
80 | if (systemtap_args != null) | ||
81 | crosstapCmd = crosstapCmd + " " + systemtap_args; | ||
82 | shell.execute(crosstapCmd); | ||
83 | } | ||
84 | } catch (Exception e) { | ||
85 | throw new InvocationTargetException(e,e.getMessage()); | ||
86 | } | ||
87 | } | ||
88 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java new file mode 100644 index 0000000..760715c --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapSettingDialog.java | |||
@@ -0,0 +1,280 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import java.io.File; | ||
14 | |||
15 | import org.eclipse.jface.dialogs.Dialog; | ||
16 | import org.eclipse.jface.dialogs.IDialogSettings; | ||
17 | import org.eclipse.swt.SWT; | ||
18 | import org.eclipse.swt.events.SelectionAdapter; | ||
19 | import org.eclipse.swt.events.SelectionEvent; | ||
20 | import org.eclipse.swt.layout.GridData; | ||
21 | import org.eclipse.swt.layout.GridLayout; | ||
22 | import org.eclipse.swt.widgets.Button; | ||
23 | import org.eclipse.swt.widgets.Composite; | ||
24 | import org.eclipse.swt.widgets.Control; | ||
25 | import org.eclipse.swt.widgets.DirectoryDialog; | ||
26 | import org.eclipse.swt.widgets.FileDialog; | ||
27 | import org.eclipse.swt.widgets.Label; | ||
28 | import org.eclipse.swt.widgets.Shell; | ||
29 | import org.eclipse.swt.widgets.Text; | ||
30 | import org.yocto.remote.utils.CommonHelper; | ||
31 | import org.yocto.sdk.remotetools.Activator; | ||
32 | import org.yocto.sdk.remotetools.Messages; | ||
33 | import org.yocto.sdk.remotetools.SWTFactory; | ||
34 | |||
35 | public class SystemtapSettingDialog extends Dialog { | ||
36 | |||
37 | static protected String TITLE="Systemtap Crosstap"; | ||
38 | protected String title; | ||
39 | protected String metadata_location; | ||
40 | protected String builddir_location; | ||
41 | protected String systemtap_script; | ||
42 | protected String user_id; | ||
43 | protected String remote_host; | ||
44 | protected String systemtap_args; | ||
45 | protected boolean okPressed; | ||
46 | protected Button metadataLocationBtn; | ||
47 | protected Button builddirLocationBtn; | ||
48 | protected Button systemtapScriptBtn; | ||
49 | protected Text userIDText; | ||
50 | protected Text remoteHostText; | ||
51 | protected Text systemtapArgsText; | ||
52 | protected Text systemtapScriptText; | ||
53 | protected Text metadataLocationText; | ||
54 | protected Text builddirLocationText; | ||
55 | |||
56 | protected SystemtapSettingDialog(Shell parentShell, String title) { | ||
57 | super(parentShell); | ||
58 | this.title = title; | ||
59 | this.okPressed = false; | ||
60 | setShellStyle(getShellStyle() | SWT.RESIZE); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | protected void configureShell(Shell newShell) { | ||
65 | super.configureShell(newShell); | ||
66 | newShell.setText(title); | ||
67 | } | ||
68 | |||
69 | public boolean isOKPressed() { | ||
70 | return okPressed; | ||
71 | } | ||
72 | |||
73 | public String getSystemtapScript() { | ||
74 | return systemtap_script; | ||
75 | } | ||
76 | |||
77 | public String getMetadataLocation() { | ||
78 | return metadata_location; | ||
79 | } | ||
80 | |||
81 | public String getBuilddirLocation() { | ||
82 | return builddir_location; | ||
83 | } | ||
84 | |||
85 | public String getRemoteHost() { | ||
86 | return remote_host; | ||
87 | } | ||
88 | |||
89 | public String getUserID() { | ||
90 | return user_id; | ||
91 | } | ||
92 | |||
93 | public String getSystemtapArgs() { | ||
94 | return systemtap_args; | ||
95 | } | ||
96 | @Override | ||
97 | protected Control createDialogArea(Composite parent) { | ||
98 | Composite comp=(Composite)super.createDialogArea(parent); | ||
99 | GridLayout topLayout = new GridLayout(); | ||
100 | comp.setLayout(topLayout); | ||
101 | |||
102 | /*argument*/ | ||
103 | SWTFactory.createVerticalSpacer(comp, 1); | ||
104 | createInternal(comp); | ||
105 | |||
106 | return comp; | ||
107 | } | ||
108 | |||
109 | protected void createInternal(Composite parent) | ||
110 | { | ||
111 | Composite projComp = new Composite(parent, SWT.NONE); | ||
112 | GridLayout projLayout = new GridLayout(); | ||
113 | projLayout.numColumns = 2; | ||
114 | projLayout.marginHeight = 0; | ||
115 | projLayout.marginWidth = 0; | ||
116 | projComp.setLayout(projLayout); | ||
117 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
118 | projComp.setLayoutData(gd); | ||
119 | |||
120 | Label label = new Label(projComp, SWT.NONE); | ||
121 | label.setText(Messages.Metadata_Location); | ||
122 | Composite textContainer = new Composite(projComp, SWT.NONE); | ||
123 | textContainer.setLayout(new GridLayout(2, false)); | ||
124 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
125 | metadataLocationText = (Text)addTextControl(textContainer, metadata_location); | ||
126 | metadataLocationBtn = addDirSelectButton(textContainer, metadataLocationText); | ||
127 | |||
128 | label = new Label(projComp, SWT.NONE); | ||
129 | label.setText(Messages.Builddir_Location); | ||
130 | textContainer = new Composite(projComp, SWT.NONE); | ||
131 | textContainer.setLayout(new GridLayout(2, false)); | ||
132 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
133 | builddirLocationText = (Text)addTextControl(textContainer, builddir_location); | ||
134 | builddirLocationBtn = addDirSelectButton(textContainer, builddirLocationText); | ||
135 | |||
136 | label = new Label(projComp, SWT.NONE); | ||
137 | label.setText(Messages.User_ID); | ||
138 | userIDText = new Text(projComp, SWT.SINGLE | SWT.BORDER); | ||
139 | |||
140 | if(user_id!=null) | ||
141 | userIDText.setText(user_id); | ||
142 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
143 | gd.horizontalSpan = 1; | ||
144 | userIDText.setLayoutData(gd); | ||
145 | |||
146 | label = new Label(projComp, SWT.NONE); | ||
147 | label.setText(Messages.Remote_Host); | ||
148 | |||
149 | remoteHostText = new Text(projComp, SWT.SINGLE | SWT.BORDER); | ||
150 | if(remote_host != null) | ||
151 | remoteHostText.setText(remote_host); | ||
152 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
153 | gd.horizontalSpan = 1; | ||
154 | remoteHostText.setLayoutData(gd); | ||
155 | |||
156 | label = new Label(projComp, SWT.NONE); | ||
157 | label.setText(Messages.Systemtap_Script); | ||
158 | textContainer = new Composite(projComp, SWT.NONE); | ||
159 | textContainer.setLayout(new GridLayout(2, false)); | ||
160 | textContainer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
161 | systemtapScriptText = (Text)addTextControl(textContainer, systemtap_script); | ||
162 | systemtapScriptBtn = addFileSelectButton(textContainer, systemtapScriptText); | ||
163 | |||
164 | label = new Label(projComp, SWT.NONE); | ||
165 | label.setText(Messages.Systemtap_Args); | ||
166 | |||
167 | systemtapArgsText = new Text(projComp, SWT.SINGLE | SWT.BORDER); | ||
168 | if(systemtap_args != null) | ||
169 | systemtapArgsText.setText(systemtap_args); | ||
170 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
171 | gd.horizontalSpan = 1; | ||
172 | systemtapArgsText.setLayoutData(gd); | ||
173 | } | ||
174 | |||
175 | private Control addTextControl(final Composite parent, String value) { | ||
176 | final Text text; | ||
177 | |||
178 | text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER); | ||
179 | text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | ||
180 | if (value != null) | ||
181 | text.setText(value); | ||
182 | text.setSize(10, 150); | ||
183 | return (Control)text; | ||
184 | } | ||
185 | |||
186 | private Button addDirSelectButton(final Composite parent, final Text text) { | ||
187 | Button button = new Button(parent, SWT.PUSH | SWT.LEAD); | ||
188 | button.setText("Browse"); | ||
189 | button.addSelectionListener(new SelectionAdapter() { | ||
190 | @Override | ||
191 | public void widgetSelected(SelectionEvent event) { | ||
192 | String dirName; | ||
193 | |||
194 | dirName = new DirectoryDialog(parent.getShell()).open(); | ||
195 | if (dirName != null) { | ||
196 | text.setText(dirName); | ||
197 | } | ||
198 | } | ||
199 | }); | ||
200 | return button; | ||
201 | } | ||
202 | |||
203 | private Button addFileSelectButton(final Composite parent, final Text text) { | ||
204 | Button button = new Button(parent, SWT.PUSH | SWT.LEAD); | ||
205 | button.setText("Browse"); | ||
206 | button.addSelectionListener(new SelectionAdapter() { | ||
207 | @Override | ||
208 | public void widgetSelected(SelectionEvent event) { | ||
209 | String fileName; | ||
210 | |||
211 | fileName = new FileDialog(parent.getShell()).open(); | ||
212 | if (fileName != null) { | ||
213 | text.setText(fileName); | ||
214 | } | ||
215 | } | ||
216 | }); | ||
217 | return button; | ||
218 | } | ||
219 | |||
220 | @Override | ||
221 | protected void okPressed() { | ||
222 | IDialogSettings settings = Activator.getDefault().getDialogSettings(); | ||
223 | metadata_location = metadataLocationText.getText(); | ||
224 | if ( (metadata_location == null) || metadata_location.isEmpty()) { | ||
225 | CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify your metadata location!"); | ||
226 | return; | ||
227 | } | ||
228 | File metadata_dir = new File(metadata_location); | ||
229 | if (!metadata_dir.exists()) { | ||
230 | CommonHelper.showErrorDialog("SystemTap Error", null, "The specified metadata location does not exist!"); | ||
231 | return; | ||
232 | } | ||
233 | if (!metadata_dir.isDirectory()) { | ||
234 | CommonHelper.showErrorDialog("SystemTap Error", null, "The specified metadata location is not a directory!"); | ||
235 | return; | ||
236 | } | ||
237 | builddir_location = builddirLocationText.getText(); | ||
238 | if ( (builddir_location == null) || builddir_location.isEmpty()) { | ||
239 | CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify your builddir location!"); | ||
240 | return; | ||
241 | } | ||
242 | File builddir_dir = new File(builddir_location); | ||
243 | if (!builddir_dir.exists()) { | ||
244 | CommonHelper.showErrorDialog("SystemTap Error", null, "The specified builddir location does not exist!"); | ||
245 | } | ||
246 | if (!metadata_dir.isDirectory()) { | ||
247 | CommonHelper.showErrorDialog("SystemTap Error", null, "The specified builddir location is not a directory!"); | ||
248 | return; | ||
249 | } | ||
250 | user_id = userIDText.getText(); | ||
251 | if ( (user_id == null) || user_id.isEmpty()) { | ||
252 | CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify remote user id!"); | ||
253 | return; | ||
254 | } | ||
255 | |||
256 | remote_host = remoteHostText.getText(); | ||
257 | if ( (remote_host == null) || remote_host.isEmpty()) { | ||
258 | CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify remote host IP!"); | ||
259 | return; | ||
260 | } | ||
261 | |||
262 | systemtap_script = systemtapScriptText.getText(); | ||
263 | if ( (systemtap_script == null) || systemtap_script.isEmpty()) { | ||
264 | CommonHelper.showErrorDialog("SystemTap Error", null, "Please specify your systemtap script"); | ||
265 | return; | ||
266 | } | ||
267 | File script_file = new File(systemtap_script); | ||
268 | if (!script_file.exists()) { | ||
269 | CommonHelper.showErrorDialog("SystemTap Error", null, "The specified systemtap script does not exist!"); | ||
270 | return; | ||
271 | } | ||
272 | if (!script_file.isFile()) { | ||
273 | CommonHelper.showErrorDialog("SystemTap Error", null, "The specified systemtap script is not a file!"); | ||
274 | return; | ||
275 | } | ||
276 | systemtap_args = systemtapArgsText.getText(); | ||
277 | okPressed = true; | ||
278 | super.okPressed(); | ||
279 | } | ||
280 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Handler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Handler.java new file mode 100644 index 0000000..9e18097 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Handler.java | |||
@@ -0,0 +1,59 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import org.eclipse.core.commands.AbstractHandler; | ||
14 | import org.eclipse.core.commands.ExecutionEvent; | ||
15 | import org.eclipse.core.commands.ExecutionException; | ||
16 | import org.eclipse.jface.dialogs.MessageDialog; | ||
17 | import org.eclipse.ui.IWorkbenchWindow; | ||
18 | import org.eclipse.ui.PlatformUI; | ||
19 | import org.eclipse.ui.handlers.HandlerUtil; | ||
20 | import org.eclipse.ui.progress.IProgressService; | ||
21 | |||
22 | import org.yocto.sdk.remotetools.Messages; | ||
23 | |||
24 | public class Ust2Handler extends AbstractHandler { | ||
25 | |||
26 | public Object execute(ExecutionEvent event) throws ExecutionException { | ||
27 | |||
28 | //if(UstModel.checkAvail()!=true) { | ||
29 | // return null; | ||
30 | //} | ||
31 | |||
32 | IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); | ||
33 | |||
34 | Ust2SettingDialog setting=new Ust2SettingDialog( | ||
35 | window.getShell() | ||
36 | ); | ||
37 | |||
38 | if(setting.open()==BaseSettingDialog.OK) { | ||
39 | IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); | ||
40 | String project = setting.getProject(); | ||
41 | if (project == null) { | ||
42 | MessageDialog.openError(window.getShell(), "Lttng-ust", Messages.ErrorUstProject); | ||
43 | return null; | ||
44 | } | ||
45 | Ust2Model op=new Ust2Model(setting.getHost(),setting.getTrace(), project, window); | ||
46 | try { | ||
47 | progressService.busyCursorWhile(op); | ||
48 | }catch (InterruptedException e) { | ||
49 | //user cancelled | ||
50 | }catch (Exception e) { | ||
51 | e.printStackTrace(); | ||
52 | MessageDialog.openError(window.getShell(), | ||
53 | "Ust", | ||
54 | (e.getCause() != null) ? e.getCause().getMessage() : e.getMessage()); | ||
55 | } | ||
56 | } | ||
57 | return null; | ||
58 | } | ||
59 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java new file mode 100644 index 0000000..8dcc5b3 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2Model.java | |||
@@ -0,0 +1,166 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import java.io.BufferedReader; | ||
14 | import java.io.File; | ||
15 | import java.io.IOException; | ||
16 | import java.io.InputStream; | ||
17 | import java.io.InputStreamReader; | ||
18 | import java.lang.reflect.InvocationTargetException; | ||
19 | |||
20 | import org.eclipse.core.resources.IFolder; | ||
21 | import org.eclipse.core.resources.IProject; | ||
22 | import org.eclipse.core.resources.IResource; | ||
23 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
24 | import org.eclipse.core.resources.ResourcesPlugin; | ||
25 | import org.eclipse.core.runtime.IPath; | ||
26 | import org.eclipse.core.runtime.IProgressMonitor; | ||
27 | import org.eclipse.core.runtime.Path; | ||
28 | import org.eclipse.core.runtime.SubProgressMonitor; | ||
29 | import org.eclipse.rse.core.model.IHost; | ||
30 | import org.eclipse.ui.IWorkbenchWindow; | ||
31 | |||
32 | public class Ust2Model extends BaseModel { | ||
33 | |||
34 | private static final String REMOTE_EXEC = "/tmp/ust_tar.sh"; | ||
35 | private static final String LOCAL_SCRIPT = "resources/ust_tar.sh"; | ||
36 | |||
37 | private static final String LOCAL_FILE_SUFFIX = ".local.tar"; | ||
38 | private static final String REMOTE_FILE_SUFFIX = ".tar"; | ||
39 | private static final String LOCAL_EXEC = "lttv-gui"; | ||
40 | private static final String TRACE_FOLDER_NAME = "Traces"; | ||
41 | private static final String DATAFILE_PREFIX = "ustfile:"; | ||
42 | |||
43 | private static final String TASK_NAME = "ust2trace command"; | ||
44 | |||
45 | private String trace_loc; | ||
46 | |||
47 | private String prj_name; | ||
48 | |||
49 | private IWorkbenchWindow window; | ||
50 | |||
51 | public Ust2Model(IHost host, String trace, String project, IWorkbenchWindow window) { | ||
52 | super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); | ||
53 | trace_loc = trace; | ||
54 | |||
55 | prj_name = project; | ||
56 | this.window = window; | ||
57 | } | ||
58 | |||
59 | @Override | ||
60 | protected void checkTerminate(InputStream is) throws IOException { | ||
61 | String temp; | ||
62 | BufferedReader in = new BufferedReader(new InputStreamReader(is)); | ||
63 | while((temp = in.readLine())!=null) { | ||
64 | int idx = temp.indexOf(DATAFILE_PREFIX); | ||
65 | if(idx != -1) { | ||
66 | remoteFile = temp.substring(idx + DATAFILE_PREFIX.length()); | ||
67 | break; | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | |||
72 | private void generateData(IProgressMonitor monitor) throws Exception { | ||
73 | runRemoteShellExec(monitor, trace_loc, true); | ||
74 | if(remoteFile == null) | ||
75 | throw new Exception("Ust: null remote data file"); | ||
76 | if(remoteFile.endsWith(REMOTE_FILE_SUFFIX)==false) | ||
77 | throw new Exception("Wrong ust data file " + remoteFile); | ||
78 | |||
79 | localFile = new String(remoteFile.substring(0, remoteFile.length()-4) + LOCAL_FILE_SUFFIX); | ||
80 | } | ||
81 | |||
82 | private void importToProject(IProgressMonitor monitor) throws Exception { | ||
83 | ProcessBuilder pb = new ProcessBuilder("tar", "fx", localFile); | ||
84 | pb.directory(new File("/tmp")); | ||
85 | Process p=pb.start(); | ||
86 | if(p.waitFor()!=0) | ||
87 | throw new Exception("extract ust data files failed"); | ||
88 | |||
89 | String traceName = localFile.substring(0,localFile.length()-LOCAL_FILE_SUFFIX.length()); | ||
90 | |||
91 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
92 | IPath full_path = wsroot.getFullPath(); | ||
93 | IProject project = wsroot.getProject(prj_name); | ||
94 | IFolder traceFolder = project.getFolder(TRACE_FOLDER_NAME); | ||
95 | if (!traceFolder.exists()) { | ||
96 | throw new Exception("Can't find file trace folder in selected project."); | ||
97 | } | ||
98 | |||
99 | String trace_str = traceName.substring(0, traceName.indexOf('-')); | ||
100 | traceFolder.createLink(new Path(trace_str), IResource.REPLACE, monitor); | ||
101 | for (IResource resource:traceFolder.members()) { | ||
102 | String extension = resource.getFileExtension(); | ||
103 | if (extension != null) | ||
104 | continue; | ||
105 | else { | ||
106 | //traceFolder.setPersistentProperty(TmfCommonConstants.TRACETYPE, "org.eclipse.linuxtools.tmf.ui.type.ctf"); | ||
107 | //resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, "org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace"); | ||
108 | //traceFolder.setPersistentProperty(TmfCommonConstants.TRACEICON, "icons/obj16/garland16.png"); | ||
109 | //traceFolder.touch(null); | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | |||
114 | private String[] generateViewerParam() throws Exception { | ||
115 | String viewerParam=new String(LOCAL_EXEC); | ||
116 | int i; | ||
117 | |||
118 | ProcessBuilder pb = new ProcessBuilder("tar", "fx", localFile); | ||
119 | pb.directory(new File("/tmp")); | ||
120 | Process p=pb.start(); | ||
121 | if(p.waitFor()!=0) | ||
122 | throw new Exception("extract ust data files failed"); | ||
123 | File f=new File(localFile.substring(0,localFile.length()-LOCAL_FILE_SUFFIX.length())); | ||
124 | File []subdir=f.listFiles(); | ||
125 | |||
126 | for (i=0;i<subdir.length;i++) { | ||
127 | if(subdir[i].isDirectory()) { | ||
128 | viewerParam=viewerParam.concat(" -t " + subdir[i].getAbsolutePath()); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | return viewerParam.split(" "); | ||
133 | } | ||
134 | |||
135 | @Override | ||
136 | public void process(IProgressMonitor monitor) | ||
137 | throws InvocationTargetException, InterruptedException { | ||
138 | // TODO Auto-generated method stub | ||
139 | |||
140 | String datafile; | ||
141 | |||
142 | monitor.beginTask("Running ust", 100); | ||
143 | try { | ||
144 | //preparing remote trace | ||
145 | |||
146 | monitor.subTask("Preparing user space lttng data file remotely"); | ||
147 | generateData(new SubProgressMonitor(monitor,30)); | ||
148 | |||
149 | //download datafile to local | ||
150 | monitor.subTask("Downloading user space lttng data file"); | ||
151 | getDataFile(new SubProgressMonitor(monitor,30)); | ||
152 | |||
153 | //extract datafile and import to lttng project | ||
154 | importToProject(new SubProgressMonitor(monitor,30)); | ||
155 | |||
156 | }catch (InterruptedException e){ | ||
157 | throw e; | ||
158 | }catch (InvocationTargetException e) { | ||
159 | throw e; | ||
160 | }catch (Exception e){ | ||
161 | throw new InvocationTargetException(e, e.getMessage()); | ||
162 | }finally { | ||
163 | monitor.done(); | ||
164 | } | ||
165 | } | ||
166 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2SettingDialog.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2SettingDialog.java new file mode 100644 index 0000000..9fd7876 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/Ust2SettingDialog.java | |||
@@ -0,0 +1,104 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import org.yocto.sdk.remotetools.Activator; | ||
14 | import org.yocto.sdk.remotetools.Messages; | ||
15 | import org.eclipse.jface.dialogs.IDialogConstants; | ||
16 | import org.eclipse.swt.SWT; | ||
17 | import org.eclipse.swt.events.ModifyEvent; | ||
18 | import org.eclipse.swt.events.ModifyListener; | ||
19 | |||
20 | import org.eclipse.swt.layout.GridData; | ||
21 | import org.eclipse.swt.layout.GridLayout; | ||
22 | import org.eclipse.swt.widgets.Button; | ||
23 | |||
24 | import org.eclipse.swt.widgets.Composite; | ||
25 | |||
26 | import org.eclipse.swt.widgets.Label; | ||
27 | import org.eclipse.swt.widgets.Shell; | ||
28 | import org.eclipse.swt.widgets.Text; | ||
29 | |||
30 | |||
31 | public class Ust2SettingDialog extends UstSettingDialogBase { | ||
32 | |||
33 | static protected String TITLE="Lttng2.0 User Tracing Import"; | ||
34 | |||
35 | protected String trace; | ||
36 | protected Text traceText; | ||
37 | |||
38 | protected Ust2SettingDialog(Shell parentShell, String title, String conn) { | ||
39 | super(parentShell,title,conn); | ||
40 | } | ||
41 | |||
42 | public Ust2SettingDialog(Shell parentShell) { | ||
43 | this(parentShell, | ||
44 | TITLE, | ||
45 | Activator.getDefault().getDialogSettings().get(IBaseConstants.CONNECTION_NAME_UST) | ||
46 | ); | ||
47 | } | ||
48 | |||
49 | public String getTrace() { | ||
50 | return trace; | ||
51 | } | ||
52 | |||
53 | @Override | ||
54 | protected void okPressed() { | ||
55 | |||
56 | trace=traceText.getText(); | ||
57 | |||
58 | super.okPressed(); | ||
59 | } | ||
60 | |||
61 | protected void createArgument(Composite parent) | ||
62 | { | ||
63 | Composite projComp = new Composite(parent, SWT.NONE); | ||
64 | GridLayout projLayout = new GridLayout(); | ||
65 | projLayout.numColumns = 4; | ||
66 | projLayout.marginHeight = 0; | ||
67 | projLayout.marginWidth = 0; | ||
68 | projComp.setLayout(projLayout); | ||
69 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
70 | projComp.setLayoutData(gd); | ||
71 | |||
72 | Label label = new Label(projComp, SWT.NONE); | ||
73 | label.setText(Messages.Usttrace_Trace_Loc_Text); | ||
74 | gd = new GridData(); | ||
75 | gd.horizontalSpan = 4; | ||
76 | label.setLayoutData(gd); | ||
77 | |||
78 | traceText = new Text(projComp, SWT.SINGLE | SWT.BORDER); | ||
79 | traceText.addModifyListener(new ModifyListener() { | ||
80 | public void modifyText(ModifyEvent e) { | ||
81 | updateOkButton(); | ||
82 | } | ||
83 | }); | ||
84 | if(trace!=null) | ||
85 | traceText.setText(trace); | ||
86 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
87 | gd.horizontalSpan = 1; | ||
88 | traceText.setLayoutData(gd); | ||
89 | } | ||
90 | |||
91 | @Override | ||
92 | protected boolean updateOkButton() { | ||
93 | boolean ret=super.updateOkButton(); | ||
94 | if(ret==true) { | ||
95 | if(traceText.getText().isEmpty() || !traceText.getText().endsWith("/ust")) { | ||
96 | Button button=getButton(IDialogConstants.OK_ID); | ||
97 | if(button!=null) | ||
98 | button.setEnabled(false); | ||
99 | ret=false; | ||
100 | } | ||
101 | } | ||
102 | return ret; | ||
103 | } | ||
104 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstSettingDialogBase.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstSettingDialogBase.java new file mode 100644 index 0000000..70b0816 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstSettingDialogBase.java | |||
@@ -0,0 +1,170 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import org.yocto.sdk.remotetools.Activator; | ||
14 | import org.yocto.sdk.remotetools.Messages; | ||
15 | import org.yocto.sdk.remotetools.SWTFactory; | ||
16 | import org.eclipse.jface.dialogs.IDialogSettings; | ||
17 | import org.eclipse.swt.SWT; | ||
18 | import org.eclipse.swt.events.ModifyEvent; | ||
19 | import org.eclipse.swt.events.ModifyListener; | ||
20 | import org.eclipse.swt.layout.GridData; | ||
21 | import org.eclipse.swt.layout.GridLayout; | ||
22 | import org.eclipse.swt.widgets.Combo; | ||
23 | import org.eclipse.swt.widgets.Composite; | ||
24 | import org.eclipse.swt.widgets.Control; | ||
25 | import org.eclipse.swt.widgets.Label; | ||
26 | import org.eclipse.swt.widgets.Shell; | ||
27 | import org.eclipse.linuxtools.tmf.core.TmfProjectNature; | ||
28 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
29 | import org.eclipse.core.resources.ResourcesPlugin; | ||
30 | import org.eclipse.core.resources.IProject; | ||
31 | |||
32 | |||
33 | public class UstSettingDialogBase extends BaseSettingDialog { | ||
34 | protected Label projectLabel; | ||
35 | protected Combo projectCombo; | ||
36 | protected String curProject = null; | ||
37 | |||
38 | protected UstSettingDialogBase(Shell parentShell, String title, String conn) { | ||
39 | super(parentShell,title,conn); | ||
40 | } | ||
41 | |||
42 | public String getProject() { | ||
43 | return curProject; | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | protected void okPressed() { | ||
48 | IDialogSettings settings = Activator.getDefault().getDialogSettings(); | ||
49 | // store the value of the generate sections checkbox | ||
50 | if(getCurrentConnection()==null) { | ||
51 | settings.put(IBaseConstants.CONNECTION_NAME_UST, | ||
52 | (String)null); | ||
53 | }else { | ||
54 | settings.put(IBaseConstants.CONNECTION_NAME_UST, | ||
55 | getCurrentConnection().getAliasName()); | ||
56 | } | ||
57 | super.okPressed(); | ||
58 | } | ||
59 | |||
60 | @Override | ||
61 | protected Control createDialogArea(Composite parent) { | ||
62 | Composite comp=(Composite)super.createDialogArea(parent); | ||
63 | GridLayout topLayout = new GridLayout(); | ||
64 | comp.setLayout(topLayout); | ||
65 | |||
66 | /*argument*/ | ||
67 | SWTFactory.createVerticalSpacer(comp, 1); | ||
68 | createImportProjectGroup(comp); | ||
69 | createArgument(comp); | ||
70 | |||
71 | updateOkButton(); | ||
72 | return comp; | ||
73 | } | ||
74 | |||
75 | protected void createImportProjectGroup(Composite parent) { | ||
76 | Composite projComp = new Composite(parent, SWT.NONE); | ||
77 | GridLayout projLayout = new GridLayout(); | ||
78 | projLayout.numColumns = 6; | ||
79 | projLayout.marginHeight = 0; | ||
80 | projLayout.marginWidth = 0; | ||
81 | projComp.setLayout(projLayout); | ||
82 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
83 | projComp.setLayoutData(gd); | ||
84 | |||
85 | projectLabel = new Label(projComp, SWT.NONE); | ||
86 | projectLabel.setText(Messages.Import_to_Project); | ||
87 | gd = new GridData(); | ||
88 | gd.horizontalSpan = 1; | ||
89 | projectLabel.setLayoutData(gd); | ||
90 | |||
91 | projectCombo = new Combo(projComp, SWT.DROP_DOWN | SWT.READ_ONLY); | ||
92 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
93 | gd.horizontalSpan = 4; | ||
94 | projectCombo.setLayoutData(gd); | ||
95 | projectCombo.addModifyListener(new ModifyListener() { | ||
96 | |||
97 | public void modifyText(ModifyEvent e) { | ||
98 | updateCurProject(); | ||
99 | } | ||
100 | }); | ||
101 | |||
102 | updateProjectPulldown(); | ||
103 | } | ||
104 | |||
105 | protected void updateCurProject() { | ||
106 | IProject currentProjectSelected = getCurrentProject(); | ||
107 | |||
108 | if (currentProjectSelected != null) | ||
109 | curProject = currentProjectSelected.getName(); | ||
110 | |||
111 | updateOkButton(); | ||
112 | } | ||
113 | |||
114 | protected IProject getCurrentProject() { | ||
115 | if (projectCombo.getItemCount() == 0) | ||
116 | return null; | ||
117 | int currentSelection = projectCombo.getSelectionIndex(); | ||
118 | String importProject = currentSelection >= 0 ? projectCombo | ||
119 | .getItem(currentSelection) : null; | ||
120 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
121 | IProject project = wsroot.getProject(importProject); | ||
122 | return project; | ||
123 | } | ||
124 | |||
125 | protected void updateProjectPulldown() { | ||
126 | int index=-1; | ||
127 | |||
128 | projectCombo.removeAll(); | ||
129 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
130 | IProject[] projects = wsroot.getProjects(); | ||
131 | |||
132 | for (int i = 0; i < projects.length; ++i) { | ||
133 | try { | ||
134 | if (projects[i].isOpen() && projects[i].hasNature(TmfProjectNature.ID)) { | ||
135 | String projName = projects[i].getName(); | ||
136 | projectCombo.add(projName); | ||
137 | if (curProject != null) | ||
138 | if (projName.matches(curProject)) | ||
139 | index = i; | ||
140 | } | ||
141 | } catch (Exception e) { | ||
142 | // TODO Auto-generated catch block | ||
143 | e.printStackTrace(); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | if(index>=0) { | ||
148 | projectCombo.select(index); | ||
149 | }else if (projectCombo.getItemCount()> 0) { | ||
150 | projectCombo.select(projectCombo.getItemCount() - 1); | ||
151 | } | ||
152 | |||
153 | //TODO | ||
154 | //connectionCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT,true); | ||
155 | projectCombo.pack(true); | ||
156 | projectCombo.layout(); | ||
157 | projectCombo.getParent().layout(); | ||
158 | |||
159 | updateCurProject(); | ||
160 | } | ||
161 | protected void createArgument(Composite parent) | ||
162 | { | ||
163 | } | ||
164 | |||
165 | @Override | ||
166 | protected boolean updateOkButton() { | ||
167 | boolean ret=super.updateOkButton(); | ||
168 | return ret; | ||
169 | } | ||
170 | } | ||
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/YoctoBspHandler.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/YoctoBspHandler.java new file mode 100644 index 0000000..c97afb6 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/YoctoBspHandler.java | |||
@@ -0,0 +1,38 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
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 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import org.eclipse.core.commands.AbstractHandler; | ||
14 | import org.eclipse.core.commands.ExecutionEvent; | ||
15 | import org.eclipse.core.commands.ExecutionException; | ||
16 | import org.eclipse.jface.wizard.WizardDialog; | ||
17 | import org.eclipse.ui.IWorkbenchWindow; | ||
18 | import org.eclipse.ui.handlers.HandlerUtil; | ||
19 | |||
20 | import org.yocto.sdk.remotetools.wizards.bsp.YoctoBSPWizard; | ||
21 | |||
22 | public class YoctoBspHandler extends AbstractHandler { | ||
23 | |||
24 | public Object execute(ExecutionEvent event) throws ExecutionException { | ||
25 | |||
26 | IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); | ||
27 | // Instantiates and initializes the wizard | ||
28 | YoctoBSPWizard bspWizard = new YoctoBSPWizard(); | ||
29 | //bspWizard.init(window.getWorkbench(), (IStructuredSelection)selection); | ||
30 | // Instantiates the wizard container with the wizard and opens it | ||
31 | WizardDialog dialog = new WizardDialog(window.getShell(), bspWizard); | ||
32 | //dialog.create(); | ||
33 | dialog.open(); | ||
34 | //YoctoBspDialog setting=new YoctoBspDialog(window.getShell()); | ||
35 | //setting.open(); | ||
36 | return null; | ||
37 | } | ||
38 | } | ||