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 org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.events
.FocusEvent
;
14 import org
.eclipse
.swt
.events
.FocusListener
;
15 import org
.eclipse
.swt
.events
.KeyAdapter
;
16 import org
.eclipse
.swt
.events
.KeyEvent
;
17 import org
.eclipse
.swt
.events
.SelectionAdapter
;
18 import org
.eclipse
.swt
.events
.SelectionEvent
;
19 import org
.eclipse
.swt
.layout
.GridData
;
20 import org
.eclipse
.swt
.layout
.GridLayout
;
21 import org
.eclipse
.swt
.widgets
.Button
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Label
;
24 import org
.eclipse
.swt
.widgets
.Text
;
25 import org
.eclipse
.ui
.PlatformUI
;
26 import org
.eclipse
.ui
.swt
.IFocusService
;
28 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
29 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorQuery
;
30 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
31 import eu
.etaxonomy
.taxeditor
.model
.ColorResources
;
32 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
33 import eu
.etaxonomy
.taxeditor
.store
.SearchManager
;
42 public class BulkEditorSearchE4
{
44 private static final String SEARCH
= Messages
.BulkEditorSearchE4_SEARCH
;
46 private static final String DEFAULT_TEXT
= String
.format(Messages
.BulkEditorSearchE4_WILDCARD
, SearchManager
.WILDCARD
);
48 private final BulkEditorE4 editor
;
52 private Button button
;
55 public Object ORDER_BY
= new Object();
57 public BulkEditorSearchE4(BulkEditorE4 editor
, Composite parent
, int style
) {
60 createControl(parent
, style
);
64 * Creates the search control.
66 protected void createControl(Composite parent
, int style
) {
68 final Composite container
= new Composite(parent
, style
);
69 GridData gridData
= new GridData(SWT
.FILL
, SWT
.TOP
, true, false);
70 container
.setLayoutData(gridData
);
71 container
.setLayout(new GridLayout(5, false));
73 createSearchTextField(container
, SWT
.BORDER
| SWT
.SINGLE
| SWT
.FULL_SELECTION
);
75 button
= new Button(container
, SWT
.PUSH
);
76 button
.setText(SEARCH
);
77 button
.addSelectionListener(new SelectionAdapter() {
79 public void widgetSelected(SelectionEvent e
) {
84 registerAtFocusService();
88 * Handles focus changes for the textfield.
90 private void registerAtFocusService() {
91 IFocusService focusService
=
92 PlatformUI
.getWorkbench().getService(IFocusService
.class);
93 if (focusService
!= null) {
94 focusService
.addFocusTracker(text
, "bulkeditor.textControlId"); //$NON-NLS-1$
100 * Creates the search textfield.
102 private void createSearchTextField(Composite parent
, int style
) {
103 final Label label
= new Label(parent
, SWT
.NONE
);
104 label
.setText(Messages
.BulkEditorSearchE4_TITLE_CACHE
);
106 text
= new Text(parent
, style
);
107 text
.setText(DEFAULT_TEXT
);
108 text
.setForeground(ColorResources
.getColor(Resources
.SEARCH_VIEW_FOREGROUND
));
110 text
.addFocusListener(new FocusListener() {
113 public void focusGained(FocusEvent e
) {
114 text
.setForeground(ColorResources
.getColor(Resources
.SEARCH_VIEW_FOCUS
));
115 if (DEFAULT_TEXT
.equals(text
.getText())) {
116 text
.setText(""); //$NON-NLS-1$
121 public void focusLost(FocusEvent e
) {
122 if (CdmUtils
.isBlank(text
.getText())) {
123 text
.setForeground(ColorResources
.getColor(Resources
.SEARCH_VIEW_FOREGROUND
));
124 text
.setText(DEFAULT_TEXT
);
129 text
.addKeyListener(new KeyAdapter() {
131 public void keyReleased(KeyEvent e
) {
132 if (e
.keyCode
== SWT
.CR
) {
138 GridData gridData
= new GridData(SWT
.FILL
, SWT
.CENTER
, true, false);
139 text
.setLayoutData(gridData
);
145 * Shows the results of the search.
147 public void updateEditorInput() {
149 String searchString
= getSearchString().trim();
151 if(DEFAULT_TEXT
.equals(searchString
) || CdmUtils
.isBlank(searchString
)){
155 BulkEditorQuery query
= new BulkEditorQuery(searchString
);
156 editor
.performSearch(query
);
160 * Returns the current string in the search textfield.
161 * @return the content of the textfield
163 public String
getSearchString() {
164 return text
.getText().trim();
167 public void setFocus() {
168 if(text
!= null && ! text
.isDisposed()){