📄 pagelistconfig.java
字号:
package com.tanghan.plugin.dbviews.extend;import java.util.ResourceBundle;import org.eclipse.ui.IWorkbench;import org.eclipse.jface.preference.IPreferenceStore;import org.eclipse.jface.preference.PreferencePage;import org.eclipse.ui.IWorkbenchPreferencePage;import org.eclipse.swt.widgets.*;import org.eclipse.swt.SWT;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import com.tanghan.plugin.TanghanPlugin;import com.tanghan.plugin.ITanghanConstants;/** * 配置类 * @author Jerry Tang * @see PreferencePage */public class PageListConfig extends PreferencePage implements IWorkbenchPreferencePage { /**资源文件*/ private static ResourceBundle res = TanghanPlugin.getDefault().getResourceBundle(); private Button showAllButton ; private Text pageListText; /** * TO DO: Implement the "PageListConfig" constructor. */ public PageListConfig() { } /** * TO DO: Implement "init". * @see PreferencePage#init */ public void init(IWorkbench workbench) { } /** * TO DO: Implement "createContents". * @see PreferencePage#createContents */ protected Control createContents(Composite parent) { Composite composite_textField = createComposite(parent, 2); createLabel(composite_textField, res.getString("Config.PageList.ShowAll")); showAllButton = createCheckBox(composite_textField,""); createLabel(composite_textField, res.getString("Config.PageList.List")); pageListText = createTextField(composite_textField,50); addListener(); initializeValues(); return new Composite(parent, SWT.NULL); } /**添加事件处理*/ private void addListener(){ showAllButton.addSelectionListener( new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ if(showAllButton.getSelection()){ pageListText.setEnabled(false); }else{ pageListText.setEnabled(true); } } } ); } /** * Creates composite control and sets the default layout data. * * @param parent the parent of the new composite * @param numColumns the number of columns for the new composite * @return the newly-created coposite */ private Composite createComposite(Composite parent, int numColumns) { Composite composite = new Composite(parent, SWT.NULL); //GridLayout GridLayout layout = new GridLayout(); layout.numColumns = numColumns; composite.setLayout(layout); //GridData GridData data = new GridData(); data.verticalAlignment = GridData.FILL; data.horizontalAlignment = GridData.FILL; composite.setLayoutData(data); return composite; } /** * Utility method that creates a label instance * and sets the default layout data. * * @param parent the parent for the new label * @param text the text for the new label * @return the new label */ private Label createLabel(Composite parent, String text) { Label label = new Label(parent, SWT.LEFT); label.setText(text); GridData data = new GridData(); //data.horizontalSpan = 2; data.horizontalAlignment = GridData.FILL; label.setLayoutData(data); return label; } /** * Create a text field specific for this application * * @param parent the parent of the new text field * @return the new text field */ private Text createTextField(Composite parent,int size) { Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);// text.addModifyListener(this); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; //data.grabExcessHorizontalSpace = true; data.verticalAlignment = GridData.CENTER; data.grabExcessVerticalSpace = false; data.widthHint = size; text.setLayoutData(data); return text; } /** * Creates an new checkbox instance and sets the default * layout data. * * @param group the composite in which to create the checkbox * @param label the string to set into the checkbox * @return the new checkbox */ private Button createCheckBox(Composite group, String label) { Button button = new Button(group, SWT.CHECK | SWT.LEFT); button.setText(label); GridData data = new GridData(); button.setLayoutData(data); return button; } /** * Initializes states of the controls from the preference store. */ private void initializeValues() { IPreferenceStore store = getPreferenceStore(); showAllButton.setSelection(store.getBoolean(ITanghanConstants.PAGELIST_SHOWALL)); pageListText.setText(store.getString(ITanghanConstants.PAGELIST_LIST)); if(showAllButton.getSelection()){ pageListText.setEnabled(false); }else{ pageListText.setEnabled(true); } } /** * Stores the values of the controls back to the preference store. */ private void storeValues() { IPreferenceStore store = getPreferenceStore(); store.setValue(ITanghanConstants.PAGELIST_SHOWALL, showAllButton.getSelection()); store.setValue(ITanghanConstants.PAGELIST_LIST, pageListText.getText()); } /* (non-Javadoc) * Method declared on PreferencePage */ protected void performDefaults() { super.performDefaults(); initializeValues(); } /* (non-Javadoc) * Method declared on PreferencePage */ public boolean performOk() { storeValues(); TanghanPlugin.getDefault().savePluginPreferences(); return true; } /** * The <code>ReadmePreferencePage</code> implementation of this * <code>PreferencePage</code> method * returns preference store that belongs to the our plugin. * This is important because we want to store * our preferences separately from the desktop. */ protected IPreferenceStore doGetPreferenceStore() { return TanghanPlugin.getDefault().getPreferenceStore(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -