java - How to fetch path of a file from preference page and print the Output on console via Button on Workbench? -
i have made 1 preference page programming is:
public class saml extends fieldeditorpreferencepage implements iworkbenchpreferencepage { public saml() { super(grid); setpreferencestore(rmpplugin.getdefault().getpreferencestore()); setdescription("browse appropriate files"); } public filefieldeditor f; public filefieldeditor f1; public void createfieldeditors() { f=new filefieldeditor(preferenceconstants.p_path, "&prism.bat file:", getfieldeditorparent()); addfield(f); f1=new filefieldeditor(preferenceconstants.p_path1, "&nusmv application file:", getfieldeditorparent()); addfield(f1); }
i want path of filefieldeditor f
, want path run on button embedded on workbench (but programming of button in different project on same workspace). button programming has hard coded path of "prism.bat" file is:
try { //to clear console on every click of button iviewpart view = platformui.getworkbench().getactiveworkbenchwindow().getactivepage().findview(iconsoleconstants.id_console_view); if (view != null) { (myconsole).clearconsole(); } processbuilder pb=new processbuilder("c:\\program files\\prism-4.0\\bin\\prism.bat"); pb.directory(new file("c:\\program files\\prism-4.0\\bin")); process p=pb.start(); bufferedreader input = new bufferedreader(new inputstreamreader(p.getinputstream())); string in; while((in = input.readline()) != null) { out.println(in); } int exitval=p.waitfor(); if(exitval==0) { out.println("process successful"); out.println("printing on console exitvalue =0"); } else {out.println("process failed"); out.println("exitvalue = 1"); } } catch (exception e) { out.println(e.tostring()); e.printstacktrace(); }
but want fetch file preference page filefieldeditor f
, want path embed in button programming when button pressed, result shown.
you need 2 parts:
- code initialize default preference
- code use current value
to set default, use following code in activator
:
public class activator extends abstractuiplugin { @override public void start(bundlecontext context) throws exception { super.start(context); ipreferencestore ps = getpreferencestore(); ps.setdefault(show_image, true); } public static final string show_image = "showimage"; }
alternatively, can use org.eclipse.core.runtime.preferences
extension point...
note code above assume type of preference boolean
- there other methods numbers, strings, etc... file name string.
to use current value, use
if (activator.getdefault().getpreferencestore().getboolean(activator.show_image)) { … }
the following slides contains little more information...
Comments
Post a Comment