1 |
364a9123
|
Patrick Plitzner
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
|
|
* European Distributed Institute of Taxonomy
|
4 |
|
|
* http://www.e-taxonomy.eu
|
5 |
|
|
*
|
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.
|
8 |
|
|
*/
|
9 |
|
|
|
10 |
|
|
package eu.etaxonomy.taxeditor.bulkeditor.e4;
|
11 |
|
|
|
12 |
ef7ec8ab
|
Patrick Plitzner
|
import java.io.File;
|
13 |
|
|
import java.io.FileInputStream;
|
14 |
|
|
import java.io.IOException;
|
15 |
|
|
import java.util.Properties;
|
16 |
|
|
|
17 |
|
|
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommand;
|
18 |
|
|
import org.eclipse.nebula.widgets.nattable.persistence.command.DisplayPersistenceDialogCommandHandler;
|
19 |
364a9123
|
Patrick Plitzner
|
import org.eclipse.swt.SWT;
|
20 |
|
|
import org.eclipse.swt.events.FocusEvent;
|
21 |
|
|
import org.eclipse.swt.events.FocusListener;
|
22 |
|
|
import org.eclipse.swt.events.KeyAdapter;
|
23 |
|
|
import org.eclipse.swt.events.KeyEvent;
|
24 |
|
|
import org.eclipse.swt.events.SelectionAdapter;
|
25 |
|
|
import org.eclipse.swt.events.SelectionEvent;
|
26 |
|
|
import org.eclipse.swt.layout.GridData;
|
27 |
|
|
import org.eclipse.swt.layout.GridLayout;
|
28 |
|
|
import org.eclipse.swt.widgets.Button;
|
29 |
|
|
import org.eclipse.swt.widgets.Composite;
|
30 |
|
|
import org.eclipse.swt.widgets.Label;
|
31 |
|
|
import org.eclipse.swt.widgets.Text;
|
32 |
|
|
import org.eclipse.ui.PlatformUI;
|
33 |
|
|
import org.eclipse.ui.swt.IFocusService;
|
34 |
|
|
|
35 |
|
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
36 |
|
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorQuery;
|
37 |
401bbfa3
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
38 |
9933241f
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.model.ColorResources;
|
39 |
ef7ec8ab
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
40 |
|
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
41 |
364a9123
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
42 |
|
|
import eu.etaxonomy.taxeditor.store.SearchManager;
|
43 |
ef7ec8ab
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
44 |
364a9123
|
Patrick Plitzner
|
|
45 |
|
|
/**
|
46 |
|
|
* @author p.ciardelli
|
47 |
|
|
* @author e.-m.lee
|
48 |
|
|
* @author n.hoffmann
|
49 |
|
|
* @created 17.08.2009
|
50 |
|
|
* @version 1.0
|
51 |
|
|
*/
|
52 |
|
|
public class BulkEditorSearchE4 {
|
53 |
|
|
|
54 |
401bbfa3
|
Patrick Plitzner
|
private static final String SEARCH = Messages.BulkEditorSearchE4_SEARCH;
|
55 |
364a9123
|
Patrick Plitzner
|
|
56 |
401bbfa3
|
Patrick Plitzner
|
private static final String DEFAULT_TEXT = String.format(Messages.BulkEditorSearchE4_WILDCARD, SearchManager.WILDCARD);
|
57 |
364a9123
|
Patrick Plitzner
|
|
58 |
96e043f8
|
Patrick Plitzner
|
private final BulkEditorE4Composite editor;
|
59 |
364a9123
|
Patrick Plitzner
|
|
60 |
ef7ec8ab
|
Patrick Plitzner
|
private DisplayPersistenceDialogCommandHandler displayPersistenceDialogCommandHandler;
|
61 |
|
|
|
62 |
|
|
private Properties natTableState;
|
63 |
|
|
|
64 |
364a9123
|
Patrick Plitzner
|
private Text text;
|
65 |
|
|
|
66 |
|
|
private Button button;
|
67 |
|
|
|
68 |
ef7ec8ab
|
Patrick Plitzner
|
private Button btnManageState;
|
69 |
|
|
|
70 |
364a9123
|
Patrick Plitzner
|
|
71 |
|
|
public Object ORDER_BY = new Object();
|
72 |
|
|
|
73 |
96e043f8
|
Patrick Plitzner
|
public BulkEditorSearchE4(BulkEditorE4Composite editor, Composite parent, int style) {
|
74 |
364a9123
|
Patrick Plitzner
|
this.editor = editor;
|
75 |
|
|
|
76 |
|
|
createControl(parent, style);
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Creates the search control.
|
81 |
|
|
*/
|
82 |
|
|
protected void createControl(Composite parent, int style) {
|
83 |
|
|
|
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));
|
88 |
|
|
|
89 |
|
|
createSearchTextField(container, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
|
90 |
|
|
|
91 |
|
|
button = new Button(container, SWT.PUSH);
|
92 |
|
|
button.setText(SEARCH);
|
93 |
|
|
button.addSelectionListener(new SelectionAdapter() {
|
94 |
|
|
@Override
|
95 |
|
|
public void widgetSelected(SelectionEvent e) {
|
96 |
|
|
updateEditorInput();
|
97 |
|
|
}
|
98 |
|
|
});
|
99 |
|
|
|
100 |
ef7ec8ab
|
Patrick Plitzner
|
/**
|
101 |
|
|
* Table state persistence
|
102 |
|
|
*/
|
103 |
|
|
natTableState = new Properties();
|
104 |
|
|
//load persisted state
|
105 |
|
|
File statePropertiesFile = getStatePropertiesFile();
|
106 |
|
|
FileInputStream inputStream;
|
107 |
|
|
try {
|
108 |
|
|
inputStream = new FileInputStream(statePropertiesFile);
|
109 |
|
|
natTableState.load(inputStream);
|
110 |
|
|
} catch (IOException e) {
|
111 |
|
|
MessagingUtils.info("No initial state properties file found for character matrix"); //$NON-NLS-1$
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
// add settings button
|
115 |
|
|
displayPersistenceDialogCommandHandler = new DisplayPersistenceDialogCommandHandler(natTableState, editor.getNatTable());
|
116 |
|
|
btnManageState = new Button(container, SWT.PUSH);
|
117 |
|
|
btnManageState.setImage(ImageResources.getImage(ImageResources.SETTINGS));
|
118 |
|
|
btnManageState.setToolTipText(Messages.BulkEditorSearchE4_TABLE_SETTINGS);
|
119 |
|
|
btnManageState.addSelectionListener(new SelectionAdapter() {
|
120 |
|
|
@Override
|
121 |
|
|
public void widgetSelected(SelectionEvent e) {
|
122 |
|
|
editor.getNatTable().doCommand(new DisplayPersistenceDialogCommand(editor.getNatTable()));
|
123 |
|
|
}
|
124 |
|
|
});
|
125 |
|
|
|
126 |
364a9123
|
Patrick Plitzner
|
registerAtFocusService();
|
127 |
|
|
}
|
128 |
|
|
|
129 |
ef7ec8ab
|
Patrick Plitzner
|
DisplayPersistenceDialogCommandHandler getDisplayPersistenceDialogCommandHandler() {
|
130 |
|
|
return displayPersistenceDialogCommandHandler;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
0dda9c8f
|
Patrick Plitzner
|
File getStatePropertiesFile() {
|
134 |
ef7ec8ab
|
Patrick Plitzner
|
return new File(WorkbenchUtility.getBaseLocation(), "bulkeditor_tablestate.properties"); //$NON-NLS-1$
|
135 |
|
|
}
|
136 |
|
|
|
137 |
0dda9c8f
|
Patrick Plitzner
|
Properties getNatTableState() {
|
138 |
|
|
return natTableState;
|
139 |
|
|
}
|
140 |
|
|
|
141 |
364a9123
|
Patrick Plitzner
|
/**
|
142 |
|
|
* Handles focus changes for the textfield.
|
143 |
|
|
*/
|
144 |
|
|
private void registerAtFocusService() {
|
145 |
|
|
IFocusService focusService =
|
146 |
|
|
PlatformUI.getWorkbench().getService(IFocusService.class);
|
147 |
|
|
if (focusService != null) {
|
148 |
401bbfa3
|
Patrick Plitzner
|
focusService.addFocusTracker(text, "bulkeditor.textControlId"); //$NON-NLS-1$
|
149 |
364a9123
|
Patrick Plitzner
|
}
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
/**
|
154 |
|
|
* Creates the search textfield.
|
155 |
|
|
*/
|
156 |
|
|
private void createSearchTextField(Composite parent, int style) {
|
157 |
|
|
final Label label = new Label(parent, SWT.NONE);
|
158 |
401bbfa3
|
Patrick Plitzner
|
label.setText(Messages.BulkEditorSearchE4_TITLE_CACHE);
|
159 |
364a9123
|
Patrick Plitzner
|
|
160 |
|
|
text = new Text(parent, style);
|
161 |
|
|
text.setText(DEFAULT_TEXT);
|
162 |
9933241f
|
Patrick Plitzner
|
text.setForeground(ColorResources.getColor(Resources.SEARCH_VIEW_FOREGROUND));
|
163 |
364a9123
|
Patrick Plitzner
|
|
164 |
|
|
text.addFocusListener(new FocusListener() {
|
165 |
|
|
|
166 |
|
|
@Override
|
167 |
|
|
public void focusGained(FocusEvent e) {
|
168 |
9933241f
|
Patrick Plitzner
|
text.setForeground(ColorResources.getColor(Resources.SEARCH_VIEW_FOCUS));
|
169 |
364a9123
|
Patrick Plitzner
|
if (DEFAULT_TEXT.equals(text.getText())) {
|
170 |
401bbfa3
|
Patrick Plitzner
|
text.setText(""); //$NON-NLS-1$
|
171 |
364a9123
|
Patrick Plitzner
|
}
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
@Override
|
175 |
|
|
public void focusLost(FocusEvent e) {
|
176 |
9933241f
|
Patrick Plitzner
|
if (CdmUtils.isBlank(text.getText())) {
|
177 |
|
|
text.setForeground(ColorResources.getColor(Resources.SEARCH_VIEW_FOREGROUND));
|
178 |
364a9123
|
Patrick Plitzner
|
text.setText(DEFAULT_TEXT);
|
179 |
|
|
}
|
180 |
|
|
}
|
181 |
|
|
});
|
182 |
|
|
|
183 |
|
|
text.addKeyListener(new KeyAdapter() {
|
184 |
|
|
@Override
|
185 |
|
|
public void keyReleased(KeyEvent e) {
|
186 |
|
|
if (e.keyCode == SWT.CR) {
|
187 |
|
|
updateEditorInput();
|
188 |
|
|
}
|
189 |
|
|
}
|
190 |
|
|
});
|
191 |
|
|
|
192 |
|
|
GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
|
193 |
|
|
text.setLayoutData(gridData);
|
194 |
84832a69
|
Katja Luther
|
text.setFocus();
|
195 |
364a9123
|
Patrick Plitzner
|
}
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
/**
|
199 |
|
|
* Shows the results of the search.
|
200 |
|
|
*/
|
201 |
|
|
public void updateEditorInput() {
|
202 |
|
|
|
203 |
|
|
String searchString = getSearchString().trim();
|
204 |
|
|
|
205 |
|
|
if(DEFAULT_TEXT.equals(searchString) || CdmUtils.isBlank(searchString)){
|
206 |
|
|
return;
|
207 |
|
|
}
|
208 |
|
|
|
209 |
a1b92e88
|
Patrick Plitzner
|
BulkEditorQuery query = new BulkEditorQuery(searchString);
|
210 |
364a9123
|
Patrick Plitzner
|
editor.performSearch(query);
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
/**
|
214 |
|
|
* Returns the current string in the search textfield.
|
215 |
|
|
* @return the content of the textfield
|
216 |
|
|
*/
|
217 |
|
|
public String getSearchString() {
|
218 |
|
|
return text.getText().trim();
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
public void setFocus() {
|
222 |
|
|
if(text != null && ! text.isDisposed()){
|
223 |
|
|
text.setFocus();
|
224 |
|
|
}
|
225 |
|
|
}
|
226 |
|
|
}
|