3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.bulkeditor
;
13 import java
.util
.Comparator
;
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
.SelectionAdapter
;
21 import org
.eclipse
.swt
.events
.SelectionEvent
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.layout
.GridLayout
;
24 import org
.eclipse
.swt
.widgets
.Button
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
26 import org
.eclipse
.swt
.widgets
.Label
;
27 import org
.eclipse
.swt
.widgets
.Text
;
28 import org
.eclipse
.ui
.PlatformUI
;
29 import org
.eclipse
.ui
.swt
.IFocusService
;
31 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
32 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
33 import eu
.etaxonomy
.taxeditor
.store
.SearchManager
;
36 * <p>BulkEditorSearchComposite class.</p>
44 public class BulkEditorSearch
{
49 private static final String SEARCH
= "Search";
51 private static final String DEFAULT_TEXT
= String
.format("Use \'%s\' for wildcard searching", SearchManager
.WILDCARD
);
53 private final BulkEditor editor
;
56 private BulkEditorSortCombo sortCombo
;
58 private Button button
;
61 public Object ORDER_BY
= new Object();
64 * <p>Constructor for BulkEditorSearchComposite.</p>
66 * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
68 * @param editor a {@link org.eclipse.ui.IEditorPart} object.
70 public BulkEditorSearch(BulkEditor editor
, Composite parent
, int style
) {
73 createControl(parent
, style
);
77 * Creates the search control.
80 * <p>createControl</p>
82 protected void createControl(Composite parent
, int style
) {
84 final Composite container
= new Composite(parent
, style
);
85 GridData gridData
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false);
86 container
.setLayoutData(gridData
);
87 container
.setLayout(new GridLayout(5, false));
89 createSearchTextField(container
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.FULL_SELECTION
);
91 createSortCombo(container
, style
);
93 button
= new Button(container
, SWT
.PUSH
);
94 button
.setText(SEARCH
);
95 button
.addSelectionListener(new SelectionAdapter() {
97 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
100 public void widgetSelected(SelectionEvent e
) {
105 registerAtFocusService();
112 private void createSortCombo(Composite parent
, int style
) {
113 sortCombo
= new BulkEditorSortCombo(parent
, editor
.getEditorInput().getSortProviders());
118 * Handles focus changes for the textfield.
120 private void registerAtFocusService() {
121 IFocusService focusService
=
122 (IFocusService
) PlatformUI
.getWorkbench().getService(IFocusService
.class);
123 if (focusService
!= null) {
124 focusService
.addFocusTracker(text
, "bulkeditor.textControlId");
130 * Creates the search textfield.
132 private void createSearchTextField(Composite parent
, int style
) {
133 final Label label
= new Label(parent
, SWT
.NONE
);
134 label
.setText("Title Cache");
136 text
= new Text(parent
, style
);
137 text
.setText(DEFAULT_TEXT
);
138 text
.setForeground(BulkEditorUtil
.getColor(Resources
.SEARCH_VIEW_FOREGROUND
));
140 text
.addFocusListener(new FocusListener() {
142 public void focusGained(FocusEvent e
) {
143 text
.setForeground(BulkEditorUtil
.getColor(Resources
.SEARCH_VIEW_FOCUS
));
144 if (DEFAULT_TEXT
.equals(text
.getText())) {
149 public void focusLost(FocusEvent e
) {
150 if (CdmUtils
.isEmpty(text
.getText())) {
151 text
.setForeground(BulkEditorUtil
.getColor(Resources
.SEARCH_VIEW_FOREGROUND
));
152 text
.setText(DEFAULT_TEXT
);
157 text
.addKeyListener(new KeyAdapter() {
159 * @see org.eclipse.swt.events.KeyAdapter#keyReleased(org.eclipse.swt.events.KeyEvent)
162 public void keyReleased(KeyEvent e
) {
163 if (e
.keyCode
== SWT
.CR
) {
169 GridData gridData
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
170 text
.setLayoutData(gridData
);
175 * Shows the results of the search.
177 private void updateEditorInput() {
179 String searchString
= getSearchString().trim();
181 if(DEFAULT_TEXT
.equals(searchString
) || CdmUtils
.isEmpty(searchString
)){
185 BulkEditorQuery query
= new BulkEditorQuery(getSearchString(), getComparator());
186 editor
.performSearch(query
);
190 * Returns the current string in the search textfield.
191 * @return the content of the textfield
194 * <p>getSearchString</p>
196 * @return a {@link java.lang.String} object.
198 public String
getSearchString() {
199 return text
.getText().trim();
206 * <p>getComparator</p>
208 * @return a {@link java.util.Comparator} object.
210 public Comparator
getComparator() {
211 return sortCombo
.getSelection();
221 public void setFocus() {
222 if(text
!= null && ! text
.isDisposed()){