⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchfieldaction.java

📁 基于Eclipse RCP开发的管理工具
💻 JAVA
字号:
 /*    * Copyright 2006 Marcel Schoffelmeer   *   * Licensed under the Apache License, Version 2.0 (the "License");   * you may not use this file except in compliance with the License.   * You may obtain a copy of the License at   *   *    http://www.apache.org/licenses/LICENSE-2.0   *      * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  */package com.s10r.manager.actions;import org.eclipse.jface.action.ControlContribution;import org.eclipse.swt.SWT;import org.eclipse.swt.events.FocusEvent;import org.eclipse.swt.events.FocusListener;import org.eclipse.swt.events.KeyEvent;import org.eclipse.swt.events.KeyListener;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Control;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.widgets.Text;import org.eclipse.ui.IEditorPart;import org.eclipse.ui.plugin.AbstractUIPlugin;import com.s10r.manager.Application;import com.s10r.manager.EntryEditor;public class SearchFieldAction extends ControlContribution{	private Text searchText;	private boolean initialField = true;		private IEditorPart activeEditorPart = null;	private Image image;	public SearchFieldAction(String id)	{		super(id);				image = AbstractUIPlugin.imageDescriptorFromPlugin(				Application.PLUGIN_ID, "icons/find.png").createImage();	}	@Override	protected Control createControl(Composite parent)	{		Composite panel = new Composite( parent, SWT.NONE );		GridLayout layout = new GridLayout();		layout.numColumns = 2;		// fill up the entire toolbar height (default is 5 which squashes the 		// controls.		layout.marginHeight = 0;		panel.setLayout(layout);						GridData data = new GridData(GridData.FILL, GridData.FILL, false, false);			Label imgLabel = new Label(panel, SWT.NONE);			imgLabel.setImage(image);		imgLabel.setLayoutData(data);		data = new GridData(GridData.FILL, SWT.FILL, true, true);		searchText = new Text(panel, SWT.BORDER);		searchText.setText("enter your search term here");		searchText.setLayoutData(data);		// searchText does not generate selection events here, so 		// try the focusListener instead		searchText.addFocusListener(new FocusListener()		{			public void focusGained(FocusEvent e)			{				if (initialField)				{					searchText.setText("");					initialField = false;				}			}			public void focusLost(FocusEvent e)			{				// no-op			}		});				searchText.addKeyListener(new KeyListener() {			public void keyPressed(KeyEvent e)			{			}			public void keyReleased(KeyEvent e)			{				// update the editor's filter to filter on items that match				// the text input in this field.								if (activeEditorPart != null && activeEditorPart instanceof EntryEditor)				{					((EntryEditor)activeEditorPart).setTableFilter(searchText.getText());				}			}});				return panel;	}	public void setActiveEditorPart(IEditorPart activeEditorPart)	{		this.activeEditorPart = activeEditorPart;			}		@Override	protected int computeWidth(Control control)	{		return 200;	}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -