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
.preference
.Resources
;
35 import eu
.etaxonomy
.taxeditor
.store
.SearchManager
;
44 public class BulkEditorSearchE4
{
46 private static final String SEARCH
= "Search";
48 private static final String DEFAULT_TEXT
= String
.format("Use \'%s\' for wildcard searching", SearchManager
.WILDCARD
);
50 private final BulkEditorE4 editor
;
53 private BulkEditorSortCombo sortCombo
;
55 private Button button
;
58 public Object ORDER_BY
= new Object();
60 public BulkEditorSearchE4(BulkEditorE4 editor
, Composite parent
, int style
) {
63 createControl(parent
, style
);
67 * Creates the search control.
69 protected void createControl(Composite parent
, int style
) {
71 final Composite container
= new Composite(parent
, style
);
72 GridData gridData
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false);
73 container
.setLayoutData(gridData
);
74 container
.setLayout(new GridLayout(5, false));
76 createSearchTextField(container
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.FULL_SELECTION
);
78 createSortCombo(container
, style
);
80 button
= new Button(container
, SWT
.PUSH
);
81 button
.setText(SEARCH
);
82 button
.addSelectionListener(new SelectionAdapter() {
84 public void widgetSelected(SelectionEvent e
) {
89 registerAtFocusService();
92 private void createSortCombo(Composite parent
, int style
) {
93 sortCombo
= new BulkEditorSortCombo(parent
, editor
.getEditorInput().getSortProviders());
98 * Handles focus changes for the textfield.
100 private void registerAtFocusService() {
101 IFocusService focusService
=
102 PlatformUI
.getWorkbench().getService(IFocusService
.class);
103 if (focusService
!= null) {
104 focusService
.addFocusTracker(text
, "bulkeditor.textControlId");
110 * Creates the search textfield.
112 private void createSearchTextField(Composite parent
, int style
) {
113 final Label label
= new Label(parent
, SWT
.NONE
);
114 label
.setText("Title Cache");
116 text
= new Text(parent
, style
);
117 text
.setText(DEFAULT_TEXT
);
118 text
.setForeground(BulkEditorUtil
.getColor(Resources
.SEARCH_VIEW_FOREGROUND
));
120 text
.addFocusListener(new FocusListener() {
123 public void focusGained(FocusEvent e
) {
124 text
.setForeground(BulkEditorUtil
.getColor(Resources
.SEARCH_VIEW_FOCUS
));
125 if (DEFAULT_TEXT
.equals(text
.getText())) {
131 public void focusLost(FocusEvent e
) {
132 if (CdmUtils
.isEmpty(text
.getText())) {
133 text
.setForeground(BulkEditorUtil
.getColor(Resources
.SEARCH_VIEW_FOREGROUND
));
134 text
.setText(DEFAULT_TEXT
);
139 text
.addKeyListener(new KeyAdapter() {
141 public void keyReleased(KeyEvent e
) {
142 if (e
.keyCode
== SWT
.CR
) {
148 GridData gridData
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
149 text
.setLayoutData(gridData
);
154 * Shows the results of the search.
156 public void updateEditorInput() {
158 String searchString
= getSearchString().trim();
160 if(DEFAULT_TEXT
.equals(searchString
) || CdmUtils
.isBlank(searchString
)){
164 BulkEditorQuery query
= new BulkEditorQuery(searchString
, getComparator());
165 editor
.performSearch(query
);
169 * Returns the current string in the search textfield.
170 * @return the content of the textfield
172 public String
getSearchString() {
173 return text
.getText().trim();
176 public Comparator
getComparator() {
177 return sortCombo
.getSelection();
180 public void setFocus() {
181 if(text
!= null && ! text
.isDisposed()){