/*******************************************************************************
 * Copyright (c) 2010 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.csstudio.trends.databrowser2;

import org.csstudio.openfile.IOpenDisplayAction;
import org.csstudio.trends.databrowser2.editor.DataBrowserEditor;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;

/** Support opening Data Browser configurations from
 *  the command-line.
 *  plugin.xml registers this {@link IOpenDisplayAction}
 *  for Data Browser "plt" files.
 *  @author Kay Kasemir
 */
@SuppressWarnings("nls")
public class OpenDisplayFile implements IOpenDisplayAction
{
	/** {@inheritDoc} */
    @Override
	public void openDisplay(final String path, final String data) throws Exception
	{
        final IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
        if (! (resource instanceof IFile))
        	throw new Exception("Cannot locate '" + path + "' in workspace");
        final IFile file = (IFile) resource;
        if (! file.exists())
        	throw new Exception("File  '" + file + "' does not exist in workspace");

    	// Create new editor
        final DataBrowserEditor editor = DataBrowserEditor.createInstance(new DataBrowserInput(file.getFullPath()));
        if (editor == null)
            throw new Exception("Cannot create Data Browser");
	}
}

@@ -497,16 +497,70 @@
 wser2;%0A%0A
+import java.io.File;%0Aimport java.io.FileInputStream;%0A%0A
 import o
@@ -666,16 +666,210 @@
 Editor;%0A
+import org.csstudio.trends.databrowser2.editor.DataBrowserModelEditorInput;%0Aimport org.csstudio.trends.databrowser2.editor.EmptyEditorInput;%0Aimport org.csstudio.trends.databrowser2.model.Model;%0A
 import o
@@ -996,16 +996,52 @@
 sPlugin;
+%0Aimport org.eclipse.ui.IEditorInput;
 %0A%0A/** Su
@@ -1433,16 +1433,93 @@
 tion%0A%09%7B%0A
+        final IEditorInput input;%0A        %0A        // Try workspace resource%0A
         
@@ -1614,19 +1614,16 @@
       if
- (!
  (resour
@@ -1642,18 +1642,113 @@
 f IFile)
-)
 %0A
+        %7B%0A            final IFile file = (IFile) resource;%0A            if (! file.exists())%0A    
         
@@ -1773,36 +1773,43 @@
 on(%22
-Cannot locat
+Fil
 e 
+ 
 '%22 + 
-path
+file
  + %22'
+ does not exist
  in 
@@ -1821,16 +1821,135 @@
 pace%22);%0A
+            input = new DataBrowserInput(file.getFullPath());%0A        %7D%0A        else%0A        %7B   // Try plain file%0A    
         
@@ -1946,33 +1946,32 @@
           final 
-I
 File file = (IFi
@@ -1970,34 +1970,34 @@
 e = 
-(IFile) resource;%0A
+new File(path);%0A  
         
 if (
@@ -1984,38 +1984,39 @@
 ath);%0A          
+  
 if (!
- 
 file.exists())%0A 
@@ -2014,33 +2014,40 @@
 ists())%0A        
+  
-%09
+      
 throw new Except
@@ -2055,66 +2055,383 @@
 on(%22
-F
+Cannot locate f
 ile 
- 
 '%22 + 
-file
+path
  + %22'
- does not exist in workspace%22);%0A%0A    %09
+%22);%0A            // Read model from file, but don't associate a (Workspace) file%0A            // with it because can't save outside of workspace%0A            final Model model = new Model();%0A            model.read(new FileInputStream(file));%0A            input = new DataBrowserModelEditorInput(new EmptyEditorInput(), model);%0A        %7D%0A%0A        
 // C
@@ -2525,48 +2525,13 @@
 nce(
-new DataBrowserInput(file.getFullPath())
+input
 );%0A 

Support --laucher.openFile for files outside the workspace