+ *
+ *
+ * // Parent shell
+ * Shell sh = Display.getCurrent().getActiveShell()
+ *
+ * ComponentParentNode rootNode = view.getRootComponentNode();
+ * AppDepFindDialog dlg = new AppDepFindDialog(sh, rootNode);
+ * dlg.create();
+ * dlg.open();
+ *
+ *
+ *
+ *
+ * @see org.eclipse.jface.dialogs.Dialog
+ */
+public class AppDepFindDialog extends TrayDialog implements SelectionListener,
+ ModifyListener,
+ IAppDepSettingsChangedListener{
+ //
+ // Constants
+ //
+
+ /**
+ * Default width.
+ */
+ private static final int DEFAULT_WIDTH = 300;
+
+ /**
+ * Default height.
+ */
+ private static final int DEFAULT_HEIGHT = 50;
+
+ /**
+ * Default column count for grid layouts.
+ */
+ private final int DEFAULT_COLUMN_COUNT = 1;
+
+ /**
+ * Find button ID
+ */
+ private static final int FIND_BUTTON_ID = IDialogConstants.CLIENT_ID + 1;
+
+ /**
+ * 'Find Nex't button finding for next matching component.
+ */
+ private Button findNextButton;
+
+ /**
+ * Close button closes the dialog.
+ */
+ private Button closeButton;
+
+ /**
+ * Find string entering field.
+ */
+ private Text findStringTxtField;
+
+ /**
+ * Start node provider for the find. Needed because component
+ * tree can change while dialog is opened.
+ */
+ private final IFindStartNodeProvider startNodeProvider;
+
+ /**
+ * Reference to main view showing the actual data to find for.
+ */
+ private final MainView view;
+
+ /**
+ * List storing the latest find values. Set to null
+ * if there are no currently active find results.
+ */
+ private ListwidgetDefaultSelected
is typically called
+ // when ENTER is pressed in a single-line text.
+ if(findStringTxtField.getText().length() > 0){
+ // Searching only when there is valid search string
+ performFindNextRunnableWrapper();
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+ Widget w = e.widget;
+
+ if(w.equals(findNextButton)){
+ performFindNextRunnableWrapper();
+ }
+ else if(w.equals(closeButton)){
+ // Otherwise it must be Close button
+ // Stop listening setting changes...
+ currentSettings.removeSettingsListener(this);
+ // ... and closing the dialog
+ this.close();
+ }
+
+ }
+
+ /**
+ * Wraps find next functionality inside runnable for showing busy cursor.
+ */
+ private void performFindNextRunnableWrapper() {
+ Runnable findNextQueryRunnable = new Runnable(){
+ public void run(){
+ performFindNext();
+ }
+ };
+
+ // Showing busy cursor during operation
+ Display d = getShell().getDisplay();
+ BusyIndicator.showWhile(d, findNextQueryRunnable);
+ }
+
+ /**
+ * Performs the find next based on the current find context.
+ */
+ private void performFindNext() {
+
+ // Do we have existing find context?
+ if(foundComponentsList == null){
+ // No we do not have => making new find
+ String searchString = findStringTxtField.getText();
+ foundComponentsList = findComponents(startNodeProvider.getSearchStartNode(),
+ searchString);
+ // Did we found anything
+ if(foundComponentsList.size() == 0){
+ new AppDepMessageBox(Messages.getString("AppDepFindDialog.Cannot_Find_Components_FindDialog_InfoMsg") //$NON-NLS-1$
+ + " \"" + searchString + "\".", //$NON-NLS-1$ //$NON-NLS-2$
+ SWT.ICON_INFORMATION | SWT.OK).open();
+ resetFind();
+ return;
+ }
+ }
+
+ // Do we have ended our search?
+ if(foundComponentIndex == foundComponentsList.size()){
+ // End reached
+ AppDepMessageBox mbox = new AppDepMessageBox(Messages.getString("AppDepFindDialog.EndOfTreeReached_ContinueFromBeginningQuery_FindDialog_InfoQueryMsg"), SWT.ICON_INFORMATION | SWT.YES | SWT.NO); //$NON-NLS-1$
+ int response = mbox.open();
+ if(response == SWT.YES){
+ // Resettings the index => find starts from beginning
+ foundComponentIndex = 0;
+ findNextComponent();
+ }
+ }
+ else{
+ // End not reached => Activating next found component from component tree
+ findNextComponent();
+ }
+ }
+
+ /**
+ * Finds next component pointed by foundComponentIndex
and
+ * increments index count.
+ */
+ private void findNextComponent() {
+ view.activateTreeViewComponent(foundComponentsList.get(foundComponentIndex));
+ // Incrementing count
+ foundComponentIndex++;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
+ */
+ public void modifyText(ModifyEvent e) {
+
+ // Text field modification resets the current find
+ resetFind();
+
+ // Settings button statuses according the text field contents
+ if(findStringTxtField.getText().length() > 0){
+ findNextButton.setEnabled(true);
+ }else{
+ findNextButton.setEnabled(false);
+ }
+ }
+
+ /**
+ * Resets current find context.
+ */
+ private void resetFind(){
+ foundComponentsList = null;
+ foundComponentIndex = 0;
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.s60tools.appdep.core.IAppDepSettingsChangedListener#settingsChanged()
+ */
+ public void settingsChanged(boolean isTargetBuildChanged) {
+ // Resetting find context when settings have been changed
+ resetFind();
+ }
+
+ /**
+ * Finds the components for given search string.
+ * @param startNode Start node for the search.
+ * @param searchString String to search for
+ * @return List of component nodes matching to given search string
+ */
+ private List