Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Open file in Eclipse view programmatically
Open file in Eclipse view programmatically [message #1830501] Mon, 27 July 2020 22:09 Go to next message
Katya Doersam is currently offline Katya DoersamFriend
Messages: 25
Registered: June 2020
Junior Member
I have created an Eclipse PDE view, called SampleView. Currently, to programmatically display the output from my file on the view, I am consuming each line from the file, and printing to the view using a scanner. Is this the best way to display the file data? Or is there a better, existing function that I can use in my code to open the file in the view?

Sample View Code:

public class SampleView extends ViewPart {

    /**
     * The ID of the view as specified by the extension.
     */
    public static final String ID = "asher.views.id.SampleView";

    @Inject IWorkbench workbench;


     

    @Override
    public void createPartControl(Composite parent) {
        
        Text text = new Text(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
        
         File file = new File("/Users/user/Desktop/untitled.json");
         Scanner sc;
        
        try {
            sc = new Scanner(file);
            while (sc.hasNextLine()) 
                  text.setText(text.getText()+"\n"+sc.nextLine()); 
            sc.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    public void setFocus() {
    }
}

Re: Open file in Eclipse view programmatically [message #1830540 is a reply to message #1830501] Tue, 28 July 2020 21:30 Go to previous messageGo to next message
Katya Doersam is currently offline Katya DoersamFriend
Messages: 25
Registered: June 2020
Junior Member
No Message Body
Re: Open file in Eclipse view programmatically [message #1830541 is a reply to message #1830540] Tue, 28 July 2020 21:31 Go to previous message
Katya Doersam is currently offline Katya DoersamFriend
Messages: 25
Registered: June 2020
Junior Member
The link to the answer I received from StackOverflow is below: https://stackoverflow.com/questions/63124287/open-a-file-in-an-eclipse-pde-view
Previous Topic:Eclipse IDE 2020‑06 (eclipse-inst-win64.exe) won't install on Win 7 Pro SP1 64-bit OS
Next Topic:Having problem with Classpath, lead to more problem
Goto Forum:
  


Current Time: Tue Aug 04 01:26:06 GMT 2020

Powered by FUDForum. Page generated in 0.02749 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top