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
.bulkeditor
.e4
;
12 import java
.util
.Comparator
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.events
.FocusEvent
;
16 import org
.eclipse
.swt
.events
.FocusListener
;
17 import org
.eclipse
.swt
.events
.KeyAdapter
;
18 import org
.eclipse
.swt
.events
.KeyEvent
;
19 import org
.eclipse
.swt
.events
.SelectionAdapter
;
20 import org
.eclipse
.swt
.events
.SelectionEvent
;
21 import org
.eclipse
.swt
.layout
.GridData
;
22 import org
.eclipse
.swt
.layout
.GridLayout
;
23 import org
.eclipse
.swt
.widgets
.Button
;
24 import org
.eclipse
.swt
.widgets
.Composite
;
25 import org
.eclipse
.swt
.widgets
.Label
;
26 import org
.eclipse
.swt
.widgets
.Text
;
27 import org
.eclipse
.ui
.PlatformUI
;
28 import org
.eclipse
.ui
.swt
.IFocusService
;
30 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
31 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorQuery
;
32 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorSortCombo
;
33 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
34 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
35 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
36 import eu
.etaxonomy
.taxeditor
.store
.SearchManager
;
45 public class BulkEditorSearchE4
{
47 private static final String SEARCH
= Messages
.BulkEditorSearchE4_SEARCH
;
49 private static final String DEFAULT_TEXT
= String
.format(Messages
.BulkEditorSearchE4_WILDCARD
, SearchManager
.WILDCARD
);
51 private final BulkEditorE4 editor
;
54 private BulkEditorSortCombo sortCombo
;
56 private Button button
;
59 public Object ORDER_BY
= new Object();
61 public BulkEditorSearchE4(BulkEditorE4 editor
, Composite parent
, int style
) {
64 createControl(parent
, style
);
68 * Creates the search control.
70 protected void createControl(Composite parent
, int style
) {
72 final Composite container
= new Composite(parent
, style
);
73 GridData gridData
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false);
74 container
.setLayoutData(gridData
);
75 container
.setLayout(new GridLayout(5, false));
77 createSearchTextField(container
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.FULL_SELECTION
);
79 createSortCombo(container
, style
);
81 button
= new Button(container
, SWT
.PUSH
);
82 button
.setText(SEARCH
);
83 button
.addSelectionListener(new SelectionAdapter() {
85 public void widgetSelected(SelectionEvent e
) {
90 registerAtFocusService();
93 private void createSortCombo(Composite parent
, int style
) {
94 sortCombo
= new BulkEditorSortCombo(parent
, editor
.getEditorInput().getSortProviders());
99 * Handles focus changes for the textfield.
101 private void registerAtFocusService() {
102 IFocusService focusService
=
103 PlatformUI
.getWorkbench().getService(IFocusService
.class);
104 if (focusService
!= null) {
105 focusService
.addFocusTracker(text
, "bulkeditor.textControlId"); //$NON-NLS-1$
111 * Creates the search textfield.
113 private void createSearchTextField(Composite parent
, int style
) {
114 final Label label
= new Label(parent
, SWT
.NONE
);
115 label
.setText(Messages
.BulkEditorSearchE4_TITLE_CACHE
);
117 text
= new Text(parent
, style
);
118 text
.setText(DEFAULT_TEXT
);
119 text
.setForeground(BulkEditorUtil
.getColor(Resources
.SEARCH_VIEW_FOREGROUND
));
121 text
.addFocusListener(new FocusListener() {
124 public void focusGained(FocusEvent e
) {
125 text
.setForeground(BulkEditorUtil
.getColor(Resources
.SEARCH_VIEW_FOCUS
));
126 if (DEFAULT_TEXT
.equals(text
.getText())) {
127 text
.setText(""); //$NON-NLS-1$
132 public void focusLost(FocusEvent e
) {
133 if (CdmUtils
.isEmpty(text
.getText())) {
134 text
.setForeground(BulkEditorUtil
.getColor(Resources
.SEARCH_VIEW_FOREGROUND
));
135 text
.setText(DEFAULT_TEXT
);
140 text
.addKeyListener(new KeyAdapter() {
142 public void keyReleased(KeyEvent e
) {
143 if (e
.keyCode
== SWT
.CR
) {
149 GridData gridData
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
150 text
.setLayoutData(gridData
);
155 * Shows the results of the search.
157 public void updateEditorInput() {
159 String searchString
= getSearchString().trim();
161 if(DEFAULT_TEXT
.equals(searchString
) || CdmUtils
.isBlank(searchString
)){
165 BulkEditorQuery query
= new BulkEditorQuery(searchString
, getComparator());
166 editor
.performSearch(query
);
170 * Returns the current string in the search textfield.
171 * @return the content of the textfield
173 public String
getSearchString() {
174 return text
.getText().trim();
177 public Comparator
getComparator() {
178 return sortCombo
.getSelection();
181 public void setFocus() {
182 if(text
!= null && ! text
.isDisposed()){