|
1 /******************************************************************************* |
|
2 * Copyright (c) 2009 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "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 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 *******************************************************************************/ |
|
19 package org.symbian.tools.tmw.debug.ui; |
|
20 |
|
21 import java.io.File; |
|
22 |
|
23 import org.eclipse.jface.dialogs.MessageDialogWithToggle; |
|
24 import org.eclipse.jface.preference.DirectoryFieldEditor; |
|
25 import org.eclipse.jface.preference.FieldEditorPreferencePage; |
|
26 import org.eclipse.jface.preference.StringFieldEditor; |
|
27 import org.eclipse.swt.SWT; |
|
28 import org.eclipse.swt.layout.GridData; |
|
29 import org.eclipse.swt.widgets.Button; |
|
30 import org.eclipse.ui.IWorkbench; |
|
31 import org.eclipse.ui.IWorkbenchPreferencePage; |
|
32 import org.symbian.tools.tmw.debug.internal.Activator; |
|
33 import org.symbian.tools.tmw.debug.internal.ChromeDebugUtils; |
|
34 import org.symbian.tools.tmw.debug.internal.IConstants; |
|
35 |
|
36 public class DebugPreferencePage extends FieldEditorPreferencePage implements |
|
37 IWorkbenchPreferencePage { |
|
38 |
|
39 private Button check; |
|
40 |
|
41 public DebugPreferencePage() { |
|
42 super(GRID); |
|
43 setPreferenceStore(Activator.getDefault().getPreferenceStore()); |
|
44 setDescription("Mobile Web debugger settings"); |
|
45 } |
|
46 |
|
47 @Override |
|
48 protected void createFieldEditors() { |
|
49 DirectoryFieldEditor editor = new DirectoryFieldEditor(IConstants.PREF_NAME_CHROME_LOCATION, |
|
50 "Chrome Install Location:", |
|
51 getFieldEditorParent()) { |
|
52 @Override |
|
53 protected boolean doCheckState() { |
|
54 if (super.doCheckState()) { |
|
55 String message = validate(getStringValue()); |
|
56 setErrorMessage(message); |
|
57 return message == null; |
|
58 } else { |
|
59 return false; |
|
60 } |
|
61 } |
|
62 }; |
|
63 editor.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE); |
|
64 editor.setEmptyStringAllowed(false); |
|
65 addField(editor); |
|
66 |
|
67 check = new Button(getFieldEditorParent(), SWT.CHECK); |
|
68 check.setText("Show warning dialog when resources in the debugged project were changed"); |
|
69 check.setLayoutData(new GridData(GridData.BEGINNING, GridData.END, false, false, 3, 1)); |
|
70 |
|
71 check.setSelection(!MessageDialogWithToggle.ALWAYS.equals(getPreferenceStore().getString( |
|
72 IConstants.PREF_SHOW_RESOURCE_CHANGE_ERROR))); |
|
73 } |
|
74 |
|
75 |
|
76 protected String validate(String newValue) { |
|
77 String error = null; |
|
78 if (newValue == null || newValue.trim().length() == 0) { |
|
79 error = "Chrome install location is not specified"; |
|
80 } else if (!new File(newValue).exists()) { |
|
81 error = String.format("%s does not exist", newValue); |
|
82 } else if (ChromeDebugUtils.getExecutablePath(newValue) == null) { |
|
83 error = String.format("%s does not contain Chrome executable", newValue); |
|
84 } |
|
85 return error; |
|
86 } |
|
87 |
|
88 @Override |
|
89 protected void performDefaults() { |
|
90 super.performDefaults(); |
|
91 check.setSelection(false); |
|
92 } |
|
93 |
|
94 @Override |
|
95 public boolean performOk() { |
|
96 if (check.getSelection()) { |
|
97 getPreferenceStore().setToDefault(IConstants.PREF_SHOW_RESOURCE_CHANGE_ERROR); |
|
98 } else { |
|
99 getPreferenceStore().setValue(IConstants.PREF_SHOW_RESOURCE_CHANGE_ERROR, MessageDialogWithToggle.ALWAYS); |
|
100 } |
|
101 return super.performOk(); |
|
102 } |
|
103 |
|
104 public void init(IWorkbench workbench) { |
|
105 // Do nothing |
|
106 } |
|
107 } |