Tech-Today
Create a new eclipse-rcp preference page by code when a listener is invoked
Objective:
-To create an eclipse-rcp preference page without using the preference extension, all is done in code. This is done by creating a customized button with a SelectionListener, and eventually that action will call a customized preference page.
How to do:
1.) create a new eclipse-rcp application with a view
2.) add a button in the view's createControl method
-this button should have a SelectionListener attached which will be called onclick
public void createPartControl(Composite parent) {
Button b = new Button(parent, SWT.NONE);
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
//create an instance of the custom MyPreference class
IPreferencePage page = new MyPreference();
page.setTitle("Custom Configurations");
//create a new PreferenceNode that will appear in the Preference window
PreferenceNode node = new PreferenceNode("1", page);
PreferenceManager pm = new PreferenceManager();
pm.addToRoot(node); //add the node in the PreferenceManager
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
//instantiate the PreferenceDialog
PreferenceDialog pd = new PreferenceDialog(shell, pm);
//this line is important, it tell's the PreferenceDialog on what store to used
pd.setPreferenceStore(Activator.getDefault().getPreferenceStore());
pd.create();
pd.open();
}
);
}
MyPreference class
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.irri.cril.jicis.administrator.Activator;
public class MyPreference extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
public MyPreference() {
super(GRID);
}
@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setDescription("Custom Configuration");
}
@Override
protected void createFieldEditors() {
//FieldEditor types FieldEditor fields here
addField(new StringFieldEditor("NAME", "Name:", getFieldEditorParent()));
}
}
This code can now save and retrieve values in your default preference store. if you want to override the ok, cancel, default, etc actions, you can add on the MyPreference class.
-
How To Display A Date With Textfield Click With Swift
Displaying Date with TextField Click with Swift First you must have a textfield connected to storyboard. @IBOutlet weak var txtField_helloDatePicker: UITextField! Next you should have a constant of UIDatePicker type. let datePicker...
-
How To Handle Checkbox Event In Swift
A very simple checkbox control. @IBAction func btn_box(sender: UIButton) { if (btn_box.selected == true) { btn_box.setBackgroundImage(UIImage(named: "box"),...
-
Useful Article Links In Studying Swift
1.) For studying the basic of swift : file:///Users/czetsuya/Downloads/404_advanced_swift.pdf-,%20attachment 2.) Useful for studying "Case Classes" http://masteringios.com/blog/2014/06/26/hello-swift/2/ 3.) “Building...
-
How To Access Asp:textbox With Runat=server Attribute In Javascript
For example you have a textbox which has a default value, and you want to clear that value when the user click on the textbox: <asp:TextBox ID="txtBox" runat="server" onclick="clear()" Text="Enter Keyword" /> <script type="text/javascript">...
-
Remove Or Customize The Close/minimize/maximize Button In An Eclipse-rcp's Application's Window
There are times when you just want your eclipse rcp in the middle of the screen. To do that you have to set the style bits for the window's shell to customize the look of your window. The API is accessible here: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/index.html,...
Tech-Today