|
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 package com.nokia.testfw.stf.scripteditor.preference; |
|
18 |
|
19 import org.eclipse.jface.preference.BooleanFieldEditor; |
|
20 import org.eclipse.jface.preference.FieldEditorPreferencePage; |
|
21 import org.eclipse.jface.preference.IntegerFieldEditor; |
|
22 import org.eclipse.jface.text.contentassist.ContentAssistant; |
|
23 import org.eclipse.ui.IEditorPart; |
|
24 import org.eclipse.ui.IWorkbench; |
|
25 import org.eclipse.ui.IWorkbenchPage; |
|
26 import org.eclipse.ui.IWorkbenchPreferencePage; |
|
27 import org.eclipse.ui.PlatformUI; |
|
28 |
|
29 import com.nokia.testfw.stf.scripteditor.Activator; |
|
30 import com.nokia.testfw.stf.scripteditor.editors.ScriptEditor; |
|
31 |
|
32 /** |
|
33 * @author xiaoma |
|
34 * |
|
35 */ |
|
36 public class ScriptEditorPreferencePage extends FieldEditorPreferencePage |
|
37 implements IWorkbenchPreferencePage { |
|
38 |
|
39 public BooleanFieldEditor enableAutoActivation; |
|
40 public IntegerFieldEditor activationDelay; |
|
41 |
|
42 public ScriptEditorPreferencePage() { |
|
43 super(GRID); |
|
44 setPreferenceStore(Activator.getDefault().getPreferenceStore()); |
|
45 setDescription("STF script editor preference"); |
|
46 } |
|
47 |
|
48 /* (non-Javadoc) |
|
49 * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors() |
|
50 */ |
|
51 @Override |
|
52 protected void createFieldEditors() { |
|
53 |
|
54 enableAutoActivation = new BooleanFieldEditor( |
|
55 PreferenceConstants.AUTO_ACTIVATION, |
|
56 "Enable auto activation", getFieldEditorParent()); |
|
57 |
|
58 activationDelay = new IntegerFieldEditor( |
|
59 PreferenceConstants.AUTO_ACTIVATION_DELAY, |
|
60 "Auto activation delay:", getFieldEditorParent()); |
|
61 |
|
62 addField(enableAutoActivation); |
|
63 addField(activationDelay); |
|
64 } |
|
65 |
|
66 /* (non-Javadoc) |
|
67 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) |
|
68 */ |
|
69 public void init(IWorkbench arg0) { |
|
70 } |
|
71 |
|
72 public boolean performOk() |
|
73 { |
|
74 |
|
75 boolean ret = super.performOk();; |
|
76 try { |
|
77 // update the editor if needed |
|
78 IWorkbench workbench = PlatformUI.getWorkbench(); |
|
79 if (workbench != null) { |
|
80 IWorkbenchPage page = workbench.getActiveWorkbenchWindow() |
|
81 .getActivePage(); |
|
82 IEditorPart editor = page.getActiveEditor(); |
|
83 if (editor != null && editor instanceof ScriptEditor) { |
|
84 ScriptEditor se = (ScriptEditor) editor; |
|
85 ContentAssistant assistant = (ContentAssistant) se |
|
86 .getConfiguration().getContentAssistant(); |
|
87 assistant.enableAutoActivation(enableAutoActivation |
|
88 .getBooleanValue()); |
|
89 assistant.setAutoActivationDelay(activationDelay |
|
90 .getIntValue()); |
|
91 } |
|
92 } |
|
93 } catch (Exception e) { |
|
94 e.printStackTrace(); |
|
95 } |
|
96 |
|
97 return ret; |
|
98 } |
|
99 |
|
100 } |