EMMA Coverage Report (generated Mon Sep 29 15:05:28 EDT 2008)
[all classes][org.eclipse.ui.internal.actions]

COVERAGE SUMMARY FOR SOURCE FILE [HelpSearchContributionItem.java]

nameclass, %method, %block, %line, %
HelpSearchContributionItem.java0%   (0/3)0%   (0/9)0%   (0/179)0%   (0/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class HelpSearchContributionItem0%   (0/1)0%   (0/5)0%   (0/136)0%   (0/36)
HelpSearchContributionItem (IWorkbenchWindow): void 0%   (0/1)0%   (0/5)0%   (0/2)
HelpSearchContributionItem (IWorkbenchWindow, String): void 0%   (0/1)0%   (0/12)0%   (0/5)
computeWidth (Control): int 0%   (0/1)0%   (0/7)0%   (0/1)
createControl (Composite): Control 0%   (0/1)0%   (0/43)0%   (0/10)
doSearch (String, boolean): void 0%   (0/1)0%   (0/69)0%   (0/18)
     
class HelpSearchContributionItem$10%   (0/1)0%   (0/2)0%   (0/19)0%   (0/5)
HelpSearchContributionItem$1 (HelpSearchContributionItem): void 0%   (0/1)0%   (0/6)0%   (0/2)
keyReleased (KeyEvent): void 0%   (0/1)0%   (0/13)0%   (0/3)
     
class HelpSearchContributionItem$20%   (0/1)0%   (0/2)0%   (0/24)0%   (0/6)
HelpSearchContributionItem$2 (HelpSearchContributionItem): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/18)0%   (0/4)

1/*******************************************************************************
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *     IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.ui.internal.actions;
12 
13import org.eclipse.core.runtime.Assert;
14import org.eclipse.jface.action.ControlContribution;
15import org.eclipse.swt.SWT;
16import org.eclipse.swt.events.KeyAdapter;
17import org.eclipse.swt.events.KeyEvent;
18import org.eclipse.swt.events.SelectionAdapter;
19import org.eclipse.swt.events.SelectionEvent;
20import org.eclipse.swt.widgets.Combo;
21import org.eclipse.swt.widgets.Composite;
22import org.eclipse.swt.widgets.Control;
23import org.eclipse.ui.IWorkbenchWindow;
24import org.eclipse.ui.internal.WorkbenchMessages;
25import org.eclipse.ui.internal.WorkbenchPlugin;
26 
27/**
28 * This is the contribution item that is used to add a help search field to
29 * the cool bar.
30 * 
31 * @since 3.1
32 */
33public class HelpSearchContributionItem extends ControlContribution {
34        private static final String ID = "org.eclipse.ui.helpSearch"; //$NON-NLS-1$
35        
36        private IWorkbenchWindow window;
37 
38        private Combo combo;
39 
40        private int MAX_ITEM_COUNT = 10;
41        
42        /**
43         * Creates the contribution item.
44         * 
45         * @param window the window
46         */
47        public HelpSearchContributionItem(IWorkbenchWindow window) {
48                this(window, ID);
49        }
50 
51        /**
52         * Creates the contribution item.
53         * 
54         * @param window the window
55         * @param id the contribution item id
56         */
57        public HelpSearchContributionItem(IWorkbenchWindow window, String id) {
58                super(id);
59        Assert.isNotNull(window);
60                this.window = window;
61        }
62 
63        /* (non-Javadoc)
64         * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
65         */
66        protected Control createControl(Composite parent) {
67                combo = new Combo(parent, SWT.NONE);
68                combo.setToolTipText(WorkbenchMessages.WorkbenchWindow_searchCombo_toolTip); 
69                String[] items = WorkbenchPlugin.getDefault().getDialogSettings()
70                                .getArray(ID);
71                if (items != null) {
72                        combo.setItems(items);
73                }
74                combo.setText(WorkbenchMessages.WorkbenchWindow_searchCombo_text); 
75                combo.addKeyListener(new KeyAdapter() {
76                        public void keyReleased(KeyEvent e) {
77                                if (e.character == SWT.CR) {
78                                        doSearch(combo.getText(), true);
79                                }
80                        }
81                });
82                combo.addSelectionListener(new SelectionAdapter() {
83                        public void widgetSelected(SelectionEvent e) {
84                                int index = combo.getSelectionIndex();
85                                if (index != -1) {
86                                        doSearch(combo.getItem(index), false);
87                                }
88                        }
89                });
90                return combo;
91        }
92 
93        /* (non-Javadoc)
94         * @see org.eclipse.jface.action.ControlContribution#computeWidth(org.eclipse.swt.widgets.Control)
95         */
96        protected int computeWidth(Control control) {
97                return control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x;
98        }
99 
100        private void doSearch(String phrase, boolean updateList) {
101                if (phrase.length() == 0) {
102            window.getWorkbench().getHelpSystem().displaySearch();
103                        return;
104                }
105                if (updateList) {
106                        boolean exists = false;
107                        for (int i = 0; i < combo.getItemCount(); i++) {
108                                String item = combo.getItem(i);
109                                if (item.equalsIgnoreCase(phrase)) {
110                                        exists = true;
111                                        break;
112                                }
113                        }
114                        if (!exists) {
115                                combo.add(phrase, 0);
116                                if (combo.getItemCount() > MAX_ITEM_COUNT) {
117                                        combo.remove(combo.getItemCount() - 1);
118                                }
119                                WorkbenchPlugin.getDefault().getDialogSettings().put(ID,
120                                                combo.getItems());
121                        }
122                }
123                window.getWorkbench().getHelpSystem().search(phrase);
124        }
125}

[all classes][org.eclipse.ui.internal.actions]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov