2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.navigation
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.jface
.action
.IMenuManager
;
14 import org
.eclipse
.jface
.action
.IToolBarManager
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.events
.FocusEvent
;
17 import org
.eclipse
.swt
.events
.FocusListener
;
18 import org
.eclipse
.swt
.events
.KeyAdapter
;
19 import org
.eclipse
.swt
.events
.KeyEvent
;
20 import org
.eclipse
.swt
.events
.MouseAdapter
;
21 import org
.eclipse
.swt
.events
.MouseEvent
;
22 import org
.eclipse
.swt
.layout
.FillLayout
;
23 import org
.eclipse
.swt
.layout
.GridData
;
24 import org
.eclipse
.swt
.layout
.GridLayout
;
25 import org
.eclipse
.swt
.widgets
.Button
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Display
;
28 import org
.eclipse
.swt
.widgets
.Label
;
29 import org
.eclipse
.swt
.widgets
.Text
;
30 import org
.eclipse
.ui
.part
.ViewPart
;
32 import com
.swtdesigner
.SWTResourceManager
;
34 import eu
.etaxonomy
.taxeditor
.controller
.SearchController
;
35 import eu
.etaxonomy
.taxeditor
.model
.CdmUtil
;
38 * The left navigation pane.
44 public class SearchView
extends ViewPart
{
45 private static final Logger logger
= Logger
.getLogger(SearchView
.class);
47 private Text searchText
;
48 private Composite searchComposite
= null;
49 public static final String ID
= "eu.etaxonomy.taxeditor.navigation.searchview"; //$NON-NLS-1$
51 private Label noResultsLabel
;
53 private Button searchButton
;
56 * Create contents of the view part
60 public void createPartControl(Composite parent
) {
62 parent
.setLayout(new FillLayout());
64 searchComposite
= new Composite(parent
, SWT
.NONE
);
65 searchComposite
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
66 final GridLayout gridLayout
= new GridLayout();
67 gridLayout
.numColumns
= 2;
68 searchComposite
.setLayout(gridLayout
);
70 searchText
= new Text(searchComposite
, SWT
.BORDER
);
71 searchText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
72 searchText
.setForeground(SWTResourceManager
.getColor(192, 192, 192));
73 searchText
.setText("Use \"*\" for wildcard searching");
74 final GridData gd_useForText
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
75 searchText
.setLayoutData(gd_useForText
);
76 searchText
.addFocusListener(new FocusListener() {
78 public void focusGained(FocusEvent e
) {
79 searchText
.setForeground(SWTResourceManager
.getColor(0,0,0));
80 searchText
.setText("");
83 public void focusLost(FocusEvent e
) {
84 if (searchText
.getText() == "") {
85 searchText
.setForeground(SWTResourceManager
.getColor(192, 192, 192));
86 searchText
.setText("Use \"*\" for wildcard searching");
90 searchText
.addKeyListener(new KeyAdapter() {
91 public void keyReleased(KeyEvent e
) {
94 populateSearchResults();
96 setSearchButtonEnabled();
101 searchButton
= new Button(searchComposite
, SWT
.NONE
);
102 searchButton
.setText("Search");
103 searchButton
.setEnabled(false);
104 searchButton
.addMouseListener(new MouseAdapter() {
106 // Populate search results resultsTable after clicking button
107 public void mouseUp(MouseEvent e
) {
108 populateSearchResults();
112 noResultsLabel
= new Label(searchComposite
, SWT
.NONE
);
113 noResultsLabel
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 2, 1));
114 noResultsLabel
.setText("0 results found.");
115 noResultsLabel
.setVisible(false);
116 noResultsLabel
.setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
118 // TEMPORARY PENDING IMPLEMENTATION - Disable visible fields
119 // searchButton.setEnabled(false);
126 protected void setSearchButtonEnabled() {
127 if (searchText
.getText().length() == 0) {
128 searchButton
.setEnabled(false);
130 searchButton
.setEnabled(true);
134 protected void populateSearchResults() {
135 // UiUtil.openSearchResultsView(null);
137 noResultsLabel
.setVisible(false);
138 if (searchText
.getText().length() > 0) {
140 // Query CDM with search text
141 SearchResult searchResult
= CdmUtil
.searchTaxaByName(searchText
.getText());
142 searchResult
.setSearchString(searchText
.getText());
143 // List<TaxonNameBase> results = CdmUtil.searchNameString(searchText.getText());
145 // If there are results, open a view in the center pane
146 if (searchResult
.size() > 0) {
147 SearchController
.openSearchResultsView(searchResult
);
150 // Display "no results found" message
151 logger
.warn("no results found");
152 // noResultsLabel.setText("No results found for '" + searchText.getText() + "'");
153 noResultsLabel
.setVisible(true);
158 private void createActions() {
159 // Create the actions
163 * Initialize the toolbar
165 private void initializeToolBar() {
166 IToolBarManager toolbarManager
= getViewSite().getActionBars()
167 .getToolBarManager();
171 * Initialize the menu
173 private void initializeMenu() {
174 IMenuManager menuManager
= getViewSite().getActionBars()
179 public void setFocus() {