|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.s60tools.creator.editors; |
|
19 |
|
20 import org.eclipse.swt.events.SelectionEvent; |
|
21 import org.eclipse.swt.events.SelectionListener; |
|
22 |
|
23 import com.nokia.s60tools.creator.job.CreatorJobManager; |
|
24 import com.nokia.s60tools.creator.job.RunInDeviceJob; |
|
25 import com.nokia.s60tools.creator.preferences.CreatorPreferences; |
|
26 import com.nokia.s60tools.creator.util.CreatorEditorConsole; |
|
27 |
|
28 public class RunInDeviceSelectionListener implements SelectionListener { |
|
29 |
|
30 private static final String SYMBIAN_FILE_SEPARATOR = "\\"; |
|
31 private final String filePath; |
|
32 private final String fileName; |
|
33 |
|
34 public RunInDeviceSelectionListener(String fileName, String filePath){ |
|
35 this.fileName = fileName; |
|
36 this.filePath = filePath; |
|
37 } |
|
38 |
|
39 public void widgetDefaultSelected(SelectionEvent e) { |
|
40 } |
|
41 |
|
42 /* (non-Javadoc) |
|
43 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
|
44 */ |
|
45 public void widgetSelected(SelectionEvent e) { |
|
46 String targetFileNameAndPath = getTargetFilePath(); |
|
47 |
|
48 String jobName = "Executing script: '" +fileName +"' in device."; |
|
49 |
|
50 //Checking if job already running, not start if is |
|
51 boolean jobAllreadyRunning = CreatorJobManager.getInstance().isJobAlreadyRunning(RunInDeviceJob.class.getName()); |
|
52 if(!jobAllreadyRunning){ |
|
53 RunInDeviceJob job = new RunInDeviceJob(jobName, filePath, targetFileNameAndPath, fileName); |
|
54 job.schedule(); |
|
55 } |
|
56 //else printing message |
|
57 else{ |
|
58 CreatorEditorConsole.getInstance().println("Excecution of script: '" +fileName +"' already running, running scripts simultaneously not allowed.", CreatorEditorConsole.MSG_WARNING); |
|
59 } |
|
60 } |
|
61 |
|
62 /** |
|
63 * Get path for target file |
|
64 * @return path for target file |
|
65 */ |
|
66 private String getTargetFilePath() { |
|
67 //Getting folder from references and check if folder ends with symbian file separator |
|
68 //note File.separatorchar cannot be used! |
|
69 String targetFolder = CreatorPreferences.getDeviceSaveFolded(); |
|
70 if(!targetFolder.endsWith(SYMBIAN_FILE_SEPARATOR)){ |
|
71 targetFolder = targetFolder + SYMBIAN_FILE_SEPARATOR; |
|
72 } |
|
73 return targetFolder +fileName; |
|
74 } |
|
75 |
|
76 } |