Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c9557ab9fb28d962e543df213d83ce052b3cc342 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*******************************************************************************
 * Copyright (c) 2011, 2015 Wind River Systems, Inc. and others. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License 2.0 which accompanies this distribution, and is
 * available at https://www.eclipse.org/legal/epl-2.0/
 *
 * Contributors:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tcf.filesystem.ui.internal.search;

import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.tcf.te.tcf.filesystem.core.interfaces.runtime.IFSTreeNode;
import org.eclipse.tcf.te.tcf.filesystem.ui.nls.Messages;
import org.eclipse.tcf.te.ui.controls.BaseEditBrowseTextControl;
import org.eclipse.tcf.te.ui.interfaces.ISearchMatcher;
import org.eclipse.tcf.te.ui.search.TreeViewerSearchDialog;
import org.eclipse.tcf.te.ui.utils.AbstractSearchable;

/**
 * The searchable that provides a UI to collect and test
 * the general operations of a file search.
 */
public class FSGeneralSearchable extends AbstractSearchable {
	// The keys to access the options stored in the dialog settings.
	private static final String INCLUDE_HIDDEN = "FS.IncludeHidden"; //$NON-NLS-1$
	private static final String INCLUDE_SYSTEM = "FS.IncludeSystem"; //$NON-NLS-1$
	private static final String TARGET_NAME = "FS.TargetName"; //$NON-NLS-1$
	private static final String TARGET_TYPE = "FS.TargetType"; //$NON-NLS-1$
	private static final String MATCH_PRECISE = "FS.MatchPrecise"; //$NON-NLS-1$
	private static final String CASE_SENSITIVE = "FS.CaseSensitive"; //$NON-NLS-1$
	// The check option to define if system files should be searched.
	private Button fBtnSystem;
	// The check option to define if hidden files should be searched.
	private Button fBtnHidden;
	// The case sensitive check box.
	private Button fBtnCase;
	// The matching rule check box.
	private Button fBtnMatch;
	// The input field for searching conditions.
	private BaseEditBrowseTextControl fSearchField;
	// The current target names.
	private String fTargetName;
	// Whether it is case sensitive
	private boolean fCaseSensitive;
	// Whether it is precise matching.
	private boolean fMatchPrecise;
	// The flag if system files should be searched, default to true.
	private boolean fIncludeSystem = true;
	// The flag if hidden files should be searched, default to true.
	private boolean fIncludeHidden = true;
	// The types of target files.
	private Combo fCmbTypes;
	// The current selected target type index.
	private int fTargetType;
	// The root directory node.
	private IFSTreeNode rootNode;

	/**
	 * Constructor
	 *
	 * @param node the node whose sub tree will be searched.
	 */
	public FSGeneralSearchable(IFSTreeNode node) {
		rootNode = node;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.utils.AbstractSearchable#createCommonPart(org.eclipse.tcf.te.ui.search.TreeViewerSearchDialog, org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createCommonPart(TreeViewerSearchDialog dialog, Composite parent) {
		Composite composite = new Composite(parent, SWT.NONE);
		GridLayout glayout = new GridLayout(3, false);
		glayout.marginHeight = 0; glayout.marginWidth = 0;
		composite.setLayout(glayout);
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		// Searching field.
		Label label = new Label(composite, SWT.NONE);
		label.setText(Messages.FSGeneralSearchable_Find);

		fSearchField = new BaseEditBrowseTextControl(null);
		fSearchField.setIsGroup(false);
		fSearchField.setHasHistory(false);
		fSearchField.setHideBrowseButton(true);
		fSearchField.setParentControlIsInnerPanel(true);
		fSearchField.setupPanel(composite);
		fSearchField.setEditFieldValidator(new NameValidator());
		//fSearchField.setEditFieldValidator(new FolderValidator(this));
		Text text = (Text) fSearchField.getEditFieldControl();
		text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
		text.addModifyListener(new ModifyListener() {
			@Override
			public void modifyText(ModifyEvent e) {
				searchTextModified();
			}
		});

		SelectionListener l = new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				optionChecked(e);
			}
		};

		Group group = new Group(parent, SWT.NONE);
		group.setText(Messages.FSGeneralSearchable_GeneralOptionText);
		group.setLayout(new GridLayout());
		group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		Composite cmpType = new Composite(group, SWT.NONE);
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		cmpType.setLayoutData(data);
		cmpType.setLayout(new GridLayout(2, false));

		label = new Label(cmpType, SWT.NONE);
		label.setText(Messages.FSGeneralSearchable_FileType);

		// Search files only
		fCmbTypes = new Combo(cmpType, SWT.BORDER | SWT.READ_ONLY);
		fCmbTypes.setItems(new String[]{Messages.FSTreeNodeSearchable_FilesAndFolders, Messages.FSTreeNodeSearchable_FilesOnly, Messages.FSTreeNodeSearchable_FoldersOnly});
		fCmbTypes.setLayoutData(new GridData());
		fCmbTypes.addSelectionListener(l);

		Composite compOptions = new Composite(group, SWT.NONE);
		data = new GridData(GridData.FILL_HORIZONTAL);
		compOptions.setLayoutData(data);
		compOptions.setLayout(new GridLayout(3, true));

		// Case sensitive
		fBtnCase = new Button(compOptions, SWT.CHECK);
		fBtnCase.setText(Messages.TreeViewerSearchDialog_BtnCaseText);
		data = new GridData(GridData.FILL_HORIZONTAL);
		fBtnCase.setLayoutData(data);
		fBtnCase.addSelectionListener(l);

		// Matching precisely
		fBtnMatch = new Button(compOptions, SWT.CHECK);
		fBtnMatch.setText(Messages.TreeViewerSearchDialog_BtnPreciseText);
		data = new GridData(GridData.FILL_HORIZONTAL);
		fBtnMatch.setLayoutData(data);
		fBtnMatch.addSelectionListener(l);

		dialog.createSearchDirectionOptions(compOptions);

		// If the target is Windows platform, then add system/hidden options.
		if(rootNode.isWindowsNode()) {
			fBtnSystem = new Button(compOptions, SWT.CHECK);
			fBtnSystem.setText(Messages.FSGeneralSearchable_SearchSystemFiles);
			data = new GridData(GridData.FILL_HORIZONTAL);
			fBtnSystem.setLayoutData(data);
			fBtnSystem.addSelectionListener(l);

			fBtnHidden = new Button(compOptions, SWT.CHECK);
			fBtnHidden.setText(Messages.FSGeneralSearchable_SearchHiddenFiles);
			data = new GridData(GridData.FILL_HORIZONTAL);
			fBtnHidden.setLayoutData(data);
			fBtnHidden.addSelectionListener(l);
		}
	}

	/**
	 * The text for searching is modified.
	 */
	protected void searchTextModified() {
		fireOptionChanged();
		fTargetName = fSearchField.getEditFieldControlText().trim();
    }

	/**
	 * Handling the event that a button is selected and checked.
	 *
	 * @param e The selection event.
	 */
	protected void optionChecked(SelectionEvent e) {
		Object src = e.getSource();
		if (src == fBtnCase) {
			fCaseSensitive = fBtnCase.getSelection();
		}
		else if (src == fBtnMatch) {
			fMatchPrecise = fBtnMatch.getSelection();
		}
		else if (src == fCmbTypes) {
			fTargetType = fCmbTypes.getSelectionIndex();
		}
		else if (src == fBtnSystem) {
			fIncludeSystem = fBtnSystem.getSelection();
		}
		else if (src == fBtnHidden) {
			fIncludeHidden = fBtnHidden.getSelection();
		}
    }

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.utils.AbstractSearchable#restoreValues(org.eclipse.jface.dialogs.IDialogSettings)
	 */
	@Override
    public void restoreValues(IDialogSettings settings) {
		if(settings != null) {
			fCaseSensitive = settings.getBoolean(CASE_SENSITIVE);
			fBtnCase.setSelection(fCaseSensitive);
			fMatchPrecise = settings.getBoolean(MATCH_PRECISE);
			fBtnMatch.setSelection(fMatchPrecise);
			try {
				fTargetType = settings.getInt(TARGET_TYPE);
				fCmbTypes.select(fTargetType);
			}catch(NumberFormatException e) {
				fTargetType = 0;
			}
			fTargetName = settings.get(TARGET_NAME);
			if (fTargetName != null) {
				fSearchField.setEditFieldControlText(fTargetName);
			}
			if (rootNode.isWindowsNode()) {
				fIncludeSystem = settings.get(INCLUDE_SYSTEM) == null ? true : settings.getBoolean(INCLUDE_SYSTEM);
				fIncludeHidden = settings.get(INCLUDE_HIDDEN) == null ? true : settings.getBoolean(INCLUDE_HIDDEN);
			}
		}
		else {
			fCaseSensitive = false;
			fMatchPrecise = false;
			fTargetType = 0;
			fTargetName = null;
			if(rootNode.isWindowsNode()) {
				fIncludeHidden = true;
				fIncludeSystem = true;
			}
		}
		fBtnCase.setSelection(fCaseSensitive);
		fBtnMatch.setSelection(fMatchPrecise);
		fCmbTypes.select(fTargetType);
		if (fTargetName != null) {
			fSearchField.setEditFieldControlText(fTargetName);
		}
		if (rootNode.isWindowsNode()) {
			fBtnSystem.setSelection(fIncludeSystem);
			fBtnHidden.setSelection(fIncludeHidden);
		}
    }

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.utils.AbstractSearchable#persistValues(org.eclipse.jface.dialogs.IDialogSettings)
	 */
	@Override
    public void persistValues(IDialogSettings settings) {
		if(settings != null) {
			settings.put(CASE_SENSITIVE, fCaseSensitive);
			settings.put(MATCH_PRECISE, fMatchPrecise);
			settings.put(TARGET_TYPE, fTargetType);
			settings.put(TARGET_NAME, fTargetName);
			if(rootNode.isWindowsNode()) {
				settings.put(INCLUDE_SYSTEM, fIncludeSystem);
				settings.put(INCLUDE_HIDDEN, fIncludeHidden);
			}
		}
    }

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.interfaces.ISearchable#getMatcher()
	 */
	@Override
	public ISearchMatcher getMatcher() {
		return new FSTreeNodeMatcher(fCaseSensitive, fMatchPrecise, fTargetType, fTargetName, fIncludeSystem, fIncludeHidden);
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.utils.AbstractSearchable#isInputValid()
	 */
	@Override
	public boolean isInputValid() {
		return fSearchField.isValid();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.utils.AbstractSearchable#getPreferredSize()
	 */
	@Override
    public Point getPreferredSize() {
	    return new Point(470, rootNode.isWindowsNode() ? 240 : 220);
    }
}

Back to the top