0
|
1 |
/*
|
|
2 |
* Copyright (c) 2006 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 |
|
|
19 |
package com.nokia.s60tools.apiquery.ui.views.main.search;
|
|
20 |
|
|
21 |
import java.util.Collection;
|
|
22 |
import java.util.HashMap;
|
|
23 |
import java.util.Map;
|
|
24 |
import java.util.Set;
|
|
25 |
|
|
26 |
import org.eclipse.swt.SWT;
|
|
27 |
import org.eclipse.swt.layout.GridData;
|
|
28 |
import org.eclipse.swt.layout.GridLayout;
|
|
29 |
import org.eclipse.swt.widgets.Button;
|
|
30 |
import org.eclipse.swt.widgets.Composite;
|
|
31 |
import org.eclipse.swt.widgets.Group;
|
|
32 |
import org.eclipse.swt.widgets.Layout;
|
|
33 |
import org.eclipse.ui.PlatformUI;
|
|
34 |
|
|
35 |
import com.nokia.s60tools.apiquery.APIQueryHelpContextIDs;
|
|
36 |
import com.nokia.s60tools.apiquery.settings.IUserSettingsListener;
|
|
37 |
import com.nokia.s60tools.apiquery.settings.UserSettings;
|
|
38 |
import com.nokia.s60tools.apiquery.shared.datatypes.APIQueryParameters;
|
|
39 |
import com.nokia.s60tools.apiquery.shared.resources.Messages;
|
|
40 |
import com.nokia.s60tools.apiquery.shared.searchmethod.ISearchMethodExtension;
|
|
41 |
import com.nokia.s60tools.apiquery.shared.searchmethod.ISearchMethodExtensionInfo;
|
|
42 |
import com.nokia.s60tools.apiquery.shared.searchmethod.ui.AbstractUiFractionComposite;
|
|
43 |
import com.nokia.s60tools.apiquery.shared.searchmethodregistry.SearchMethodExtensionRegistry;
|
|
44 |
import com.nokia.s60tools.util.debug.DbgUtility;
|
|
45 |
|
|
46 |
/**
|
|
47 |
* UI composite that shows the search type selections in Search tab.
|
|
48 |
*
|
|
49 |
*/
|
|
50 |
class QueryTypeSelectionComposite extends AbstractUiFractionComposite implements IUserSettingsListener{
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Amount of columns in the used grid layout.
|
|
54 |
*/
|
|
55 |
private final int COLUMN_COUNT = 3;
|
|
56 |
private Group queryTypeSelectionGroup;
|
|
57 |
private Map<Integer, Button> queryTypeBtnMap;
|
|
58 |
|
|
59 |
/**
|
|
60 |
* Constructor.
|
|
61 |
* @param parentComposite Parent composite for the created composite.
|
|
62 |
*/
|
|
63 |
public QueryTypeSelectionComposite(Composite parentComposite) {
|
|
64 |
super(parentComposite);
|
|
65 |
}
|
|
66 |
|
|
67 |
/* (non-Javadoc)
|
|
68 |
* @see com.nokia.s60tools.apiquery.ui.views.main.AbstractTabComposite#createLayout()
|
|
69 |
*/
|
|
70 |
protected Layout createLayout() {
|
|
71 |
return new GridLayout(COLUMN_COUNT, false);
|
|
72 |
}
|
|
73 |
|
|
74 |
/* (non-Javadoc)
|
|
75 |
* @see com.nokia.s60tools.apiquery.ui.views.main.AbstractTabComposite#createLayoutData()
|
|
76 |
*/
|
|
77 |
protected Object createLayoutData(){
|
|
78 |
return new GridData(GridData.FILL_HORIZONTAL);
|
|
79 |
}
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Set context sensitive help ids to components that can have focus
|
|
83 |
*
|
|
84 |
*/
|
|
85 |
private void setContextSensitiveHelpIds(Button btn){
|
|
86 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(btn,
|
|
87 |
APIQueryHelpContextIDs.API_QUERY_HELP_SEARCH_TAB);
|
|
88 |
}
|
|
89 |
|
|
90 |
/* (non-Javadoc)
|
|
91 |
* @see com.nokia.s60tools.apiquery.ui.views.main.AbstractTabComposite#createControls()
|
|
92 |
*/
|
|
93 |
protected void createControls() {
|
|
94 |
DbgUtility.println(DbgUtility.PRIORITY_OPERATION, "-- createControls() --> " + getClass().getName()); //$NON-NLS-1$
|
|
95 |
|
|
96 |
queryTypeSelectionGroup = new Group(this, SWT.SHADOW_NONE);
|
|
97 |
queryTypeSelectionGroup.setText(Messages.getString("QueryTypeSelectionComposite.Query_By_Msg")); //$NON-NLS-1$
|
|
98 |
|
|
99 |
GridLayout gdl2 = new GridLayout(COLUMN_COUNT, false);
|
|
100 |
GridData gd2 = new GridData(GridData.FILL_HORIZONTAL);
|
|
101 |
|
|
102 |
queryTypeSelectionGroup.setLayout(gdl2);
|
|
103 |
queryTypeSelectionGroup.setLayoutData(gd2);
|
|
104 |
|
|
105 |
// Adding different query types
|
|
106 |
Integer[] queryTypesArr = APIQueryParameters.getQueryTypes();
|
|
107 |
int queryTypeCnt = queryTypesArr.length;
|
|
108 |
|
|
109 |
// Query buttons are store into an internal array for later reference
|
|
110 |
queryTypeBtnMap = new HashMap<Integer, Button>(queryTypeCnt);
|
|
111 |
|
|
112 |
for (Integer queryType : queryTypesArr) {
|
|
113 |
String desc = APIQueryParameters.getDescriptionForQueryType(queryType);
|
|
114 |
Button queryBtn = new Button(queryTypeSelectionGroup, SWT.RADIO);
|
|
115 |
queryBtn.setText(desc);
|
|
116 |
queryBtn.setSelection(false);
|
|
117 |
// Storing to Button array for later reference
|
|
118 |
queryTypeBtnMap.put(queryType, queryBtn);
|
|
119 |
setContextSensitiveHelpIds(queryBtn);
|
|
120 |
}
|
|
121 |
|
|
122 |
// Checking the statuses supported query types for currently
|
|
123 |
// selected search method.
|
|
124 |
checkSupportedQueryTypesAndUpdateUi();
|
|
125 |
|
|
126 |
// Starting to listen user settings change events
|
|
127 |
UserSettings.getInstance().addUserSettingListener(this);
|
|
128 |
}
|
|
129 |
|
|
130 |
/**
|
|
131 |
* Checks the statuses of currently supported query types and updates UI.
|
|
132 |
*/
|
|
133 |
private void checkSupportedQueryTypesAndUpdateUi() {
|
|
134 |
try {
|
|
135 |
// Setting enable and disable statuses for query types
|
|
136 |
ISearchMethodExtensionInfo currSelExtInfo = UserSettings.getInstance().getCurrentlySelectedSearchMethodInfo();
|
|
137 |
String id = currSelExtInfo.getId();
|
|
138 |
ISearchMethodExtension currSelExt = SearchMethodExtensionRegistry.getInstance().getById(id);
|
|
139 |
|
|
140 |
Set<Integer> queryTypesSet = queryTypeBtnMap.keySet();
|
|
141 |
for (Integer qType : queryTypesSet) {
|
|
142 |
Button btn = queryTypeBtnMap.get(qType);
|
|
143 |
boolean isSupported = currSelExt.isSupportedQueryType(qType);
|
|
144 |
btn.setSelection(false);
|
|
145 |
btn.setEnabled(isSupported);
|
|
146 |
}
|
|
147 |
|
|
148 |
// Setting default query type that should be supported by all extensions.
|
|
149 |
// and therefore is always enabled and set as default selection.
|
|
150 |
// It is on the responsibility of extension developer to make
|
|
151 |
// sure that the default query type is supported.
|
|
152 |
int defaultQueryType = APIQueryParameters.getDefaultQueryType();
|
|
153 |
Button defQueryTypeBtn = queryTypeBtnMap.get(defaultQueryType);
|
|
154 |
defQueryTypeBtn.setEnabled(true);
|
|
155 |
defQueryTypeBtn.setSelection(true);
|
|
156 |
|
|
157 |
} catch (Exception e) {
|
|
158 |
e.printStackTrace();
|
|
159 |
}
|
|
160 |
}
|
|
161 |
|
|
162 |
/**
|
|
163 |
* Gets query type for the currently selected query type.
|
|
164 |
* @return Returns query type for the currently selected query type.
|
|
165 |
*/
|
|
166 |
public int getSelectedQueryType(){
|
|
167 |
Set<Integer> queryTypeSet = queryTypeBtnMap.keySet();
|
|
168 |
for (Integer queryType : queryTypeSet) {
|
|
169 |
Button btn = queryTypeBtnMap.get(queryType);
|
|
170 |
if(btn.getSelection()){
|
|
171 |
// This query type was selected
|
|
172 |
return queryType;
|
|
173 |
}
|
|
174 |
}
|
|
175 |
// We should never get into here
|
|
176 |
throw new RuntimeException(Messages.getString("QueryTypeSelectionComposite.Query_Type_Was_Not_Selected_Msg")); //$NON-NLS-1$
|
|
177 |
}
|
|
178 |
|
|
179 |
/* (non-Javadoc)
|
|
180 |
* @see com.nokia.s60tools.apiquery.settings.IUserSettingsListener#userSettingsChanged()
|
|
181 |
*/
|
|
182 |
public void userSettingsChanged() {
|
|
183 |
// Settings have changed which might mean that
|
|
184 |
// the user has changed the currently used query type.
|
|
185 |
checkSupportedQueryTypesAndUpdateUi();
|
|
186 |
}
|
|
187 |
|
|
188 |
/* (non-Javadoc)
|
|
189 |
* @see org.eclipse.swt.widgets.Widget#dispose()
|
|
190 |
*/
|
|
191 |
public void dispose(){
|
|
192 |
super.dispose();
|
|
193 |
DbgUtility.println(DbgUtility.PRIORITY_OPERATION, "-- Dispose() --> " + getClass().getName()); //$NON-NLS-1$
|
|
194 |
queryTypeSelectionGroup.dispose();
|
|
195 |
Collection<Button> buttonsColl = queryTypeBtnMap.values();
|
|
196 |
for (Button btn : buttonsColl) {
|
|
197 |
btn.dispose();
|
|
198 |
}
|
|
199 |
queryTypeBtnMap.clear();
|
|
200 |
// Stopping the event listening
|
|
201 |
UserSettings.getInstance().removeUserSettingListener(this);
|
|
202 |
}
|
|
203 |
|
|
204 |
/**
|
|
205 |
* Sets the query type if it is allowed for
|
|
206 |
* the currently selected search method.
|
|
207 |
* @param queryType Query type to be set.
|
|
208 |
*/
|
|
209 |
public void setQueryType(int queryType) {
|
|
210 |
String errMsg = null;
|
|
211 |
Button btn = queryTypeBtnMap.get(queryType);
|
|
212 |
if(btn != null){
|
|
213 |
if(btn.isEnabled()){
|
|
214 |
deselectAllTypes();
|
|
215 |
btn.setSelection(true);
|
|
216 |
return;
|
|
217 |
}
|
|
218 |
else{
|
|
219 |
errMsg = Messages.getString("QueryTypeSelectionComposite.Not_Supported_ErrMsg"); //$NON-NLS-1$
|
|
220 |
}
|
|
221 |
}
|
|
222 |
else{
|
|
223 |
errMsg = Messages.getString("QueryTypeSelectionComposite.Query_Type_Not_Available_ErrMsg"); //$NON-NLS-1$
|
|
224 |
}
|
|
225 |
// We get here only if something fails
|
|
226 |
throw new IllegalArgumentException(errMsg);
|
|
227 |
}
|
|
228 |
|
|
229 |
/**
|
|
230 |
* Clears all the query type selections.
|
|
231 |
*/
|
|
232 |
private void deselectAllTypes() {
|
|
233 |
for (Button btn : queryTypeBtnMap.values()) {
|
|
234 |
btn.setSelection(false);
|
|
235 |
}
|
|
236 |
}
|
|
237 |
}
|