0
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 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.appdep.ui.dialogs;
|
|
20 |
|
|
21 |
import org.eclipse.jface.dialogs.Dialog;
|
|
22 |
import org.eclipse.jface.dialogs.IDialogConstants;
|
|
23 |
import org.eclipse.jface.preference.IPreferenceNode;
|
|
24 |
import org.eclipse.jface.preference.IPreferencePage;
|
|
25 |
import org.eclipse.jface.preference.PreferenceDialog;
|
|
26 |
import org.eclipse.jface.preference.PreferenceManager;
|
|
27 |
import org.eclipse.jface.preference.PreferenceNode;
|
|
28 |
import org.eclipse.jface.window.IShellProvider;
|
|
29 |
import org.eclipse.swt.SWT;
|
|
30 |
import org.eclipse.swt.events.SelectionAdapter;
|
|
31 |
import org.eclipse.swt.events.SelectionEvent;
|
|
32 |
import org.eclipse.swt.events.SelectionListener;
|
|
33 |
import org.eclipse.swt.graphics.Rectangle;
|
|
34 |
import org.eclipse.swt.layout.GridData;
|
|
35 |
import org.eclipse.swt.layout.GridLayout;
|
|
36 |
import org.eclipse.swt.widgets.Button;
|
|
37 |
import org.eclipse.swt.widgets.Composite;
|
|
38 |
import org.eclipse.swt.widgets.Control;
|
|
39 |
import org.eclipse.swt.widgets.Label;
|
|
40 |
import org.eclipse.swt.widgets.Link;
|
|
41 |
import org.eclipse.swt.widgets.List;
|
|
42 |
import org.eclipse.swt.widgets.Shell;
|
|
43 |
|
|
44 |
import com.nokia.s60tools.appdep.AppDepHelpContextIDs;
|
|
45 |
import com.nokia.s60tools.appdep.plugin.AppDepPlugin;
|
|
46 |
import com.nokia.s60tools.appdep.resources.Messages;
|
|
47 |
import com.nokia.s60tools.appdep.ui.preferences.DEPreferencePage;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Dialog for selecting real implementation of selected generic component
|
|
51 |
* @see org.eclipse.jface.dialogs.Dialog
|
|
52 |
*/
|
|
53 |
public class LocateComponentDialog extends Dialog {
|
|
54 |
|
|
55 |
|
|
56 |
/**
|
|
57 |
* List box dialog text control for showing the content.
|
|
58 |
*/
|
|
59 |
private List componentsList = null;
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Components to be shown in the dialog.
|
|
63 |
*/
|
|
64 |
private String[] components = null;
|
|
65 |
|
|
66 |
/**
|
|
67 |
* Index of the selection.
|
|
68 |
*/
|
|
69 |
private int selectionIndex;
|
|
70 |
|
|
71 |
// Fixed Width and height parameters to set UI components
|
|
72 |
// precisely
|
|
73 |
private static final int COMPONENT_LIST_ITEMS_HEIGHT_HINT = 8;
|
|
74 |
public static final int COMPONENT_LIST_WIDTH = 300;
|
|
75 |
|
|
76 |
/**
|
|
77 |
* Generic component.
|
|
78 |
*/
|
|
79 |
private String componentName = null;
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Constructor
|
|
83 |
* @param parentShell Parent shell
|
|
84 |
* @param components Component array.
|
|
85 |
* @param componentName Name of the generic component.
|
|
86 |
*/
|
|
87 |
public LocateComponentDialog(Shell parentShell, String[] components, String componentName) {
|
|
88 |
super(parentShell);
|
|
89 |
this.components = components;
|
|
90 |
this.componentName = componentName;
|
|
91 |
}
|
|
92 |
|
|
93 |
/**
|
|
94 |
* Constructor
|
|
95 |
* @param parentShell Parent shell.
|
|
96 |
*/
|
|
97 |
@SuppressWarnings("unused")
|
|
98 |
private LocateComponentDialog(Shell parentShell) {
|
|
99 |
super(parentShell);
|
|
100 |
}
|
|
101 |
|
|
102 |
/**
|
|
103 |
* Constructor
|
|
104 |
* @param parentShell Parent shell provider.
|
|
105 |
*/
|
|
106 |
@SuppressWarnings("unused")
|
|
107 |
private LocateComponentDialog(IShellProvider parentShell) {
|
|
108 |
super(parentShell);
|
|
109 |
}
|
|
110 |
|
|
111 |
/* (non-Javadoc)
|
|
112 |
* @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
|
|
113 |
*/
|
|
114 |
protected void createButtonsForButtonBar(Composite parent) {
|
|
115 |
// Creating just OK button
|
|
116 |
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
|
|
117 |
true);
|
|
118 |
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL,
|
|
119 |
true);
|
|
120 |
Button ok = getButton(IDialogConstants.OK_ID);
|
|
121 |
ok.setEnabled(false);
|
|
122 |
|
|
123 |
}
|
|
124 |
|
|
125 |
/* (non-Javadoc)
|
|
126 |
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
|
|
127 |
*/
|
|
128 |
protected void configureShell(Shell shell) {
|
|
129 |
super.configureShell(shell);
|
|
130 |
shell.setText( Messages.getString("LocateComponentDialog.Shell_Txt") );//$NON-NLS-1$
|
|
131 |
}
|
|
132 |
|
|
133 |
/* (non-Javadoc)
|
|
134 |
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
|
|
135 |
*/
|
|
136 |
protected Control createDialogArea(Composite parent) {
|
|
137 |
|
|
138 |
Composite dialogAreaComposite = (Composite) super.createDialogArea(parent);
|
|
139 |
|
|
140 |
//Label
|
|
141 |
Label label = new Label(dialogAreaComposite,SWT.HORIZONTAL);
|
|
142 |
label.setText(Messages.getString("LocateComponentDialog.Label_Txt") +" " +componentName); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
143 |
|
|
144 |
//Layout data for the component list
|
|
145 |
final int cols = 1;
|
|
146 |
GridLayout gdl = new GridLayout(cols, false);
|
|
147 |
GridData gd = new GridData(GridData.FILL_BOTH);
|
|
148 |
|
|
149 |
dialogAreaComposite.setLayout(gdl);
|
|
150 |
dialogAreaComposite.setLayoutData(gd);
|
|
151 |
|
|
152 |
GridData gd2 = new GridData(GridData.FILL_BOTH);
|
|
153 |
|
|
154 |
dialogAreaComposite.setLayoutData(gd2);
|
|
155 |
|
|
156 |
//Controls for the component list
|
|
157 |
final int listBoxStyleBits = SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL;
|
|
158 |
componentsList = new List(dialogAreaComposite,listBoxStyleBits);
|
|
159 |
int listHeight = componentsList.getItemHeight() * COMPONENT_LIST_ITEMS_HEIGHT_HINT;
|
|
160 |
Rectangle trim = componentsList.computeTrim(0, 0, 0, listHeight);
|
|
161 |
GridData listData = new GridData(COMPONENT_LIST_WIDTH, SWT.DEFAULT);
|
|
162 |
listData.horizontalAlignment = GridData.FILL;
|
|
163 |
listData.grabExcessHorizontalSpace = true;
|
|
164 |
listData.verticalAlignment = GridData.FILL;
|
|
165 |
listData.grabExcessVerticalSpace = true;
|
|
166 |
listData.heightHint = trim.height;
|
|
167 |
|
|
168 |
listData.heightHint = trim.height;
|
|
169 |
componentsList.setLayoutData(listData);
|
|
170 |
if(components != null){
|
|
171 |
componentsList.setItems(components);
|
|
172 |
}
|
|
173 |
|
|
174 |
// Adding selection listener for the component list
|
|
175 |
componentsList.addSelectionListener(new SelectionListener(){
|
|
176 |
|
|
177 |
public void widgetDefaultSelected(SelectionEvent e) {
|
|
178 |
//Not needed
|
|
179 |
}
|
|
180 |
|
|
181 |
public void widgetSelected(SelectionEvent e) {
|
|
182 |
selectionIndex = componentsList.getSelectionIndex();
|
|
183 |
if(selectionIndex != -1){
|
|
184 |
setOKEnabled();
|
|
185 |
}
|
|
186 |
}
|
|
187 |
});
|
|
188 |
|
|
189 |
//Button for opening preferences page
|
|
190 |
Link openPreferencePageLink = new Link(dialogAreaComposite, SWT.NULL);
|
|
191 |
openPreferencePageLink.setText("<a>" + Messages.getString("LocateComponentDialog.Link_Txt") +"</a>");//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
192 |
openPreferencePageLink.setToolTipText(Messages.getString("LocateComponentDialog.Link_ToolTip_Txt"));//$NON-NLS-1$
|
|
193 |
GridData btnData = new GridData();
|
|
194 |
openPreferencePageLink.setLayoutData(btnData);
|
|
195 |
|
|
196 |
//listener for the add button
|
|
197 |
openPreferencePageLink.addSelectionListener(new SelectionAdapter() {
|
|
198 |
public void widgetSelected(SelectionEvent event) {
|
|
199 |
openPreferencePage();
|
|
200 |
}
|
|
201 |
});
|
|
202 |
|
|
203 |
// Setting context help IDs
|
|
204 |
AppDepPlugin.setContextSensitiveHelpID(dialogAreaComposite, AppDepHelpContextIDs.APPDEP_LOCATE_COMPONENT_DIALOG);
|
|
205 |
|
|
206 |
return dialogAreaComposite;
|
|
207 |
}
|
|
208 |
|
|
209 |
/**
|
|
210 |
* Sets OK button enabled
|
|
211 |
*/
|
|
212 |
private void setOKEnabled(){
|
|
213 |
Button ok = getButton(IDialogConstants.OK_ID);
|
|
214 |
ok.setEnabled(true);
|
|
215 |
}
|
|
216 |
|
|
217 |
/**
|
|
218 |
* Opens Component prefix search order preference page.
|
|
219 |
*/
|
|
220 |
private void openPreferencePage(){
|
|
221 |
IPreferencePage page = new DEPreferencePage();
|
|
222 |
PreferenceManager mgr = new PreferenceManager();
|
|
223 |
IPreferenceNode node = new PreferenceNode("1", page);//$NON-NLS-1$
|
|
224 |
mgr.addToRoot(node);
|
|
225 |
PreferenceDialog dialog = new PreferenceDialog(getShell(), mgr);
|
|
226 |
dialog.create();
|
|
227 |
dialog.setMessage(page.getTitle());
|
|
228 |
dialog.open();
|
|
229 |
}
|
|
230 |
|
|
231 |
/* (non-Javadoc)
|
|
232 |
* @see org.eclipse.jface.window.Window#open()
|
|
233 |
*/
|
|
234 |
public int open(){
|
|
235 |
selectionIndex=-1;
|
|
236 |
return super.open();
|
|
237 |
}
|
|
238 |
|
|
239 |
/**
|
|
240 |
* Get selection index from the concrete component list.
|
|
241 |
* @return index of selected component or -1 if not selected
|
|
242 |
*/
|
|
243 |
public int getSelectionIndex(){
|
|
244 |
return selectionIndex;
|
|
245 |
}
|
|
246 |
|
|
247 |
}
|