Eclipse plug-in development learning note "7"---add preferences
First, we create a new plug-in project, Open the Plugin.xml file Select the Extensions tab, add a org.eclipse.ui.preferencePages extension point, and add a page as shown in the figure, and note that the category of the second page is the ID of the first page.
Right-click the SRC folder to create a new class, create 2 classes for Page1,page2, inherit the Preferencepage class, and implement the Iworkbenchpreferencepage interface.
/**
*
* Page1
*
*/
Package addpreferencepage.pages;
Import Org.eclipse.jface.preference.PreferencePage;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.layout.FillLayout;
Import Org.eclipse.swt.widgets.Composite;
Import Org.eclipse.swt.widgets.Control;
Import Org.eclipse.swt.widgets.Label;
Import Org.eclipse.ui.IWorkbench;
Import Org.eclipse.ui.IWorkbenchPreferencePage;
public class Page1 extends Preferencepage implements Iworkbenchpreferencepage {
@Override
public void Init (Iworkbench workbench) {}
@Override
Protected Control createcontents (Composite parent) {
Composite topcom = new Composite (parent, SWT. NONE);
Topcom.setlayout (New Filllayout ());
New Label (topcom, SWT. NONE). SetText ("Welcome to the Custom preferences!) ");
return topcom;
}
}
/**
*
* Page2
*
*/
Package addpreferencepage.pages;
Import Org.eclipse.jface.preference.PreferencePage;
Import Org.eclipse.swt.SWT;
Import Org.eclipse.swt.layout.FillLayout;
Import Org.eclipse.swt.widgets.Composite;
Import Org.eclipse.swt.widgets.Control;
Import Org.eclipse.swt.widgets.Label;
Import Org.eclipse.ui.IWorkbench;
Import Org.eclipse.ui.IWorkbenchPreferencePage;
public class Page2 extends Preferencepage implements Iworkbenchpreferencepage {
@Override
public void Init (Iworkbench workbench) {}
@Override
Protected Control createcontents (Composite parent) {
Composite topcom = new Composite (parent, SWT. NONE);
Topcom.setlayout (New Filllayout ());
New Label (topcom, SWT. NONE). SetText ("Sub-option! ");
return topcom;
}
}
Click Run, Effect
Eclipse plug-in development learning note "7"---add preferences