|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 package com.symbian.smt.gui.preferences; |
|
17 |
|
18 import org.eclipse.core.runtime.preferences.DefaultScope; |
|
19 import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
|
20 import org.eclipse.core.runtime.preferences.IScopeContext; |
|
21 import org.eclipse.core.runtime.preferences.InstanceScope; |
|
22 import org.eclipse.jface.preference.PreferencePage; |
|
23 import org.eclipse.jface.resource.ImageDescriptor; |
|
24 import org.eclipse.swt.SWT; |
|
25 import org.eclipse.swt.layout.FillLayout; |
|
26 import org.eclipse.swt.widgets.Composite; |
|
27 import org.eclipse.swt.widgets.Control; |
|
28 import org.eclipse.ui.IWorkbench; |
|
29 import org.eclipse.ui.IWorkbenchPreferencePage; |
|
30 |
|
31 import com.symbian.smt.gui.AbstractPersistentDataStore; |
|
32 import com.symbian.smt.gui.Activator; |
|
33 import com.symbian.smt.gui.PersistentDataStore; |
|
34 import com.symbian.smt.gui.smtwidgets.FilterWidget; |
|
35 |
|
36 public class FilterPreferences extends PreferencePage implements |
|
37 IWorkbenchPreferencePage { |
|
38 |
|
39 private FilterWidget filterWidget; |
|
40 private AbstractPersistentDataStore instanceStore; |
|
41 private AbstractPersistentDataStore defaultStore; |
|
42 |
|
43 public FilterPreferences() { |
|
44 } |
|
45 |
|
46 public FilterPreferences(String title) { |
|
47 super(title); |
|
48 } |
|
49 |
|
50 public FilterPreferences(String title, ImageDescriptor image) { |
|
51 super(title, image); |
|
52 } |
|
53 |
|
54 @Override |
|
55 protected Control createContents(Composite parent) { |
|
56 Composite composite = new Composite(parent, SWT.NONE); |
|
57 composite.setLayout(new FillLayout(SWT.VERTICAL)); |
|
58 |
|
59 filterWidget = new FilterWidget(composite, SWT.NONE); |
|
60 |
|
61 IScopeContext defaultScope = new DefaultScope(); |
|
62 IEclipsePreferences defaultNode = defaultScope |
|
63 .getNode(Activator.PLUGIN_ID); |
|
64 defaultStore = new PersistentDataStore(defaultNode); |
|
65 |
|
66 IScopeContext instanceScope = new InstanceScope(); |
|
67 IEclipsePreferences instanceNode = instanceScope |
|
68 .getNode(Activator.PLUGIN_ID); |
|
69 instanceStore = new PersistentDataStore(instanceNode, defaultNode); |
|
70 |
|
71 filterWidget.setFilterItems(instanceStore.getFilterHasItems()); |
|
72 |
|
73 composite.pack(); |
|
74 parent.pack(); |
|
75 |
|
76 return composite; |
|
77 } |
|
78 |
|
79 /* |
|
80 * Comma-separated list of filters to turn on when building the model. All |
|
81 * filters on an item must be present in this list in order for that item to |
|
82 * appear. Order does not matter |
|
83 */ |
|
84 public void init(IWorkbench workbench) { |
|
85 setPreferenceStore(Activator.getDefault().getPreferenceStore()); |
|
86 setDescription("List of filters to turn on when building the model. \n" |
|
87 + "All filters on an item must be present in this " |
|
88 + "list in order for that item to appear. \n" |
|
89 + "Order does not matter."); |
|
90 } |
|
91 |
|
92 public void performDefaults() { |
|
93 restoreDefaults(); |
|
94 } |
|
95 |
|
96 public boolean performOk() { |
|
97 storeValues(); |
|
98 return super.performOk(); |
|
99 } |
|
100 |
|
101 private void restoreDefaults() { |
|
102 filterWidget.setFilterItems(defaultStore.getFilterHasItems()); |
|
103 } |
|
104 |
|
105 private void storeValues() { |
|
106 instanceStore.setFilterHasItems(filterWidget.getFilterItems()); |
|
107 } |
|
108 } |