Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Open external file into rcp
Open external file into rcp [message #973454] Tue, 06 November 2012 10:47 Go to next message
Yumin Zhou is currently offline Yumin Zhou
Messages: 21
Registered: July 2012
Junior Member
Hello Experts,

I want to open a local file in my rcp view. I created a welcome view where has a button to open a file dialog. I want to get the file path chosen in the file dialog and do something with this path in another view.

I have saved the file name with following code.
fileName = dialog.getFileNames();
      filterPath = dialog.getFilterPath();
      selectedFiles = new File[fileName.length];
      for (int i = 0; i < fileName.length; i++) {
    	  if(filterPath != null && filterPath.trim().length() > 0) {
    		  selectedFiles[i] = new File(filterPath, fileName[i]);
    	  } else {
    		  selectedFiles[i] = new File(fileName[i]);
    	  }
      }

And also I can call the another view after choosing the file, but I cannot get the file path in the another view. This is my another view calling code.
if (openFile.getXMLFileName() != null ) {
					IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

					String viewIdToClose = WelcomeView.ID;
					IViewReference viewToClose = activePage.findViewReference(viewIdToClose);
					activePage.hideView(viewToClose);

					try {
						String viewIdToOpen_1 = IPXACTView.ID;
						String viewIdToOpen_2 = DetailView.ID;
						activePage.showView(viewIdToOpen_1, viewIdToOpen_2, 2);
					} catch (PartInitException ex) {
						ex.printStackTrace();
					}
				}

I have searched some online. I doubt whether I should use "activity" stuff or change this another view to editor?

Thank you in advance!
Re: Open external file into rcp [message #974182 is a reply to message #973454] Tue, 06 November 2012 23:00 Go to previous messageGo to next message
Simon Scholz is currently offline Simon Scholz
Messages: 73
Registered: April 2012
Location: Germany
Member
Hello Yumin,

There are several ways to pass information to different views.
So you want to open files in a certain view and then pass the filenames to a different view, right?
The quick&dirty method would be offering a setter for filepaths in the view, which should get those filepaths and then make the view with the filedialog use this setter.
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

List<String> filePaths = ....
IViewReference viewWithFilePathSetterReference = activePage.findViewReference(ViewWithFilePathSetter.ID);
if(viewWithFilePathSetterReference  != null){
   IViewPart viewWithFilePathSetter = viewWithFilePathSetter.getView(true);
   if(viewWithFilePathSetter instanceof ViewWithFilePathSetter){
       ((ViewWithFilePathSetter)viewWithFilePathSetter).setFilePaths(filePaths);
   }
}


Best regards,

Simon
Re: Open external file into rcp [message #977877 is a reply to message #974182] Fri, 09 November 2012 16:56 Go to previous messageGo to next message
Yumin Zhou is currently offline Yumin Zhou
Messages: 21
Registered: July 2012
Junior Member
Hello Simon,

I tried the method you mentioned here. But I got nothing after open file action. I debugged the code and it could not pass the if condition. Do you have any idea about it? And some guy told me maybe I could use singleton. Is it possible with my case?

BR
YM
Re: Open external file into rcp [message #978105 is a reply to message #974182] Fri, 09 November 2012 21:13 Go to previous message
Yumin Zhou is currently offline Yumin Zhou
Messages: 21
Registered: July 2012
Junior Member
Hi Simon,

I figured it out. I just need to create a file name class and set this class as static.
Thank you for your advice!!!

BR
YM
Previous Topic:e4 Branding in General
Next Topic:Adding PDFRenderder.jar to my Plug-In Project - Runtime Error
Goto Forum:
  


Current Time: Sun Sep 21 04:06:11 GMT 2014

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

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