Note that there are some explanatory texts on larger screens.

plurals
  1. POCall selected path from preference page in a button programming to use that path and start to run a file
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/6778770/how-to-fetch-path-of-a-file-from-preference-page-and-print-the-output-on-console">How to fetch path of a file from preference page and print the Output on console via Button on Workbench?</a> </p> </blockquote> <p>Hi i have made a preference page and have also embedded a button on eclipse workbench IDE i want to access the path of preference page(user select through FileFieldEditor())</p> <p>The code of Preference page is :-</p> <pre><code> package com.myplugin.rmp.preferences; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.FileFieldEditor; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import com.myplugin.rmp.RmpPlugin; public class SAML extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { public SAML() { super(GRID); setPreferenceStore(RmpPlugin.getDefault().getPreferenceStore()); setDescription("Browse Appropriate files"); } public FileFieldEditor Prism_browse; public FileFieldEditor NuSMV_browse; public void createFieldEditors() { Prism_browse=new FileFieldEditor(PreferenceConstants.PRISM_PATH, "&amp;Prism.bat File:", getFieldEditorParent()); Prism_browse.setEmptyStringAllowed(true); Prism_browse.setFileExtensions(new String[] { "*.bat","*.*" }); Prism_browse.setErrorMessage("The used location for the Prism File is not valid."); addField(Prism_browse); NuSMV_browse=new FileFieldEditor(PreferenceConstants.NUSMV_PATH1, "&amp;NuSMV Application File:", getFieldEditorParent()); NuSMV_browse.setEmptyStringAllowed(true); NuSMV_browse.setFileExtensions(new String[] { "*.exe","*.*" }); NuSMV_browse.setErrorMessage("The used location for the NuSMV file is not valid."); addField(NuSMV_browse); } public void init(IWorkbench workbench) { } </code></pre> <p>}</p> <p>Button programming is: I want to access preference page selected path in my Button programming to execute a program NuSMV.exe and show output on console</p> <pre><code> package com.myplugin.rmp; import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.jface.action.IAction; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.console.IConsole; import org.eclipse.ui.console.IConsoleConstants; import org.eclipse.ui.console.IConsoleManager; import org.eclipse.ui.console.IConsoleView; import org.eclipse.ui.console.MessageConsole; import org.eclipse.ui.console.MessageConsoleStream; import com.myplugin.rmp.preferences.PreferenceConstants; public class NUSMV_BUTTON implements IWorkbenchWindowActionDelegate { IWorkbenchWindow activeWindow = null; public void run(IAction proxyAction) { MessageConsole myConsole = null; String name = "outputConsole"; ConsolePlugin plugin = ConsolePlugin.getDefault(); IConsoleManager conMan = plugin.getConsoleManager(); IConsole[] existing = conMan.getConsoles(); for (int i = 0; i &lt; existing.length; i++) if (name.equals(existing[i].getName())) myConsole = (MessageConsole) existing[i]; //no console found, so create a new one if (myConsole == null) myConsole = new MessageConsole(name, null); conMan.addConsoles(new IConsole[]{myConsole}); IWorkbench wb = PlatformUI.getWorkbench(); IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); IWorkbenchPage page = win.getActivePage(); String id = IConsoleConstants.ID_CONSOLE_VIEW; try { IConsoleView view = (IConsoleView) page.showView(id); view.display(myConsole); } catch (Exception e) { } MessageConsoleStream out = myConsole.newMessageStream(); //To clear the console on every click of button IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(IConsoleConstants.ID_CONSOLE_VIEW); if (view != null) { (myConsole).clearConsole(); } try { out.println("NuSMV Button works !"); IPreferenceStore store1 = plugin.getPreferenceStore(); ProcessBuilder pb=new ProcessBuilder(store1.getString(PreferenceConstants.NUSMV_PATH1)); pb.directory(new File(store1.getString(PreferenceConstants.NUSMV_PATH1))); Process p=pb.start(); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); String in1; while((in1 = input.readLine()) != null) { out.println(in1); } int exitVal1=p.waitFor(); if(exitVal1==0) { out.println("Printing on console"); } else out.println("Process failed"); } catch (Exception e) { out.println(e.toString()); e.printStackTrace(); } } // IActionDelegate method public void selectionChanged(IAction proxyAction, ISelection selection) { // do nothing, action is not dependent on the selection } // IWorkbenchWindowActionDelegate method public void init(IWorkbenchWindow window) { activeWindow = window; } // IWorkbenchWindowActionDelegate method public void dispose() { // nothing to do } </code></pre> <p>}</p> <p>Activator class is :</p> <pre><code> package com.myplugin.rmp; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; import com.myplugin.rmp.preferences.PreferenceConstants; public class RmpPlugin extends AbstractUIPlugin { // The plug-in ID public static final String PLUGIN_ID = "com.myplugin.rmp"; //$NON-NLS-1$ public static final String PRISM_PATH="pathPreference"; public static final String NUSMV_PATH1="pathPreference1"; // The shared instance private static RmpPlugin plugin; /** * The constructor */ public RmpPlugin() { } public void start(BundleContext context) throws Exception { super.start(context); plugin = this; IPreferenceStore ps = getPreferenceStore(); ps.setDefault(PreferenceConstants.PRISM_PATH,""); ps.setDefault(PreferenceConstants.NUSMV_PATH1,""); } public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } public static RmpPlugin getDefault() { return plugin; } public static ImageDescriptor getImageDescriptor(String path) { return imageDescriptorFromPlugin(PLUGIN_ID, path); } </code></pre> <p>}</p> <p>Whenever i click the button NuSMV button on my workbench it does not start the NuSMV process and it shows an error that it is not able to detect file (NuSMV.exe) i.e it is not able to fetch path from preference page.</p> <p>Let me know, how to fix this error</p> <p>Any effort will be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload