Search Mailing List Archives


Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[protege-discussion] Protege API loadProjectFromFile() question...

Roosh clroush at usgs.gov
Thu Jun 5 06:23:26 PDT 2008


Yes, sorry for not being very specific.

Here is the code:

/**********MAIN WINDOW*************/
//This function opens a new dialog box which returns a file and 
//assigns it to the File object, fileSource.

private JMenuItem getOpen() {
		if (Open == null) {
			Open = new JMenuItem("Open");
			Open.addActionListener(new ActionListener(){
			      public void actionPerformed(ActionEvent e){
			    	  fileSource = new dSourceDialog(thisClass).getReturnFile();
			    	  if(fileSource != null){
			    		  System.out.println(fileSource.toURI().toString());

                                          //This is where the widget that
uses the ontology is used.
			    		  new StandaloneTabWidget(fileSource.toURI().toString(), true);
			    		  jTabbedPane.setVisible(true);
			    	  }
			    	//new dSourceFrame();
			      }
			    });
		}
		return Open;
	}
//END

/****************Widget Code********************/
//This code is basically a modified copy of what is on the Protege
//Wiki here: http://protegewiki.stanford.edu/index.php/UseTabInApplication

public class StandaloneTabWidget{

	private static String uri = null;
	
	private Project prj = null;
	
	public void setSource(String tempURI){
		uri = tempURI;
	}
	
	public String getSource(){
		return uri;
	}
	
	public StandaloneTabWidget(String tempURI, boolean fromFile) {
		//uri =
"http://www.co-ode.org/ontologies/bio-tutorial/sources/ORGANISM.owl";
		uri = tempURI;
		ArrayList errors = new ArrayList();
	    
		if(fromFile == true){
			prj = Project.loadProjectFromFile(uri, errors);
		}
		else {
			try{
				OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri);
				prj = Project.createBuildProject(owlModel, errors);
		    }
			catch(Exception e){
				System.out.println("File could not be found!");
				return;
			}
		}
		
		if (errors.size() > 0) {
			System.out.println("There were erros at loading prj: " + prj);			
			return;
		}
		
        // Replace in the next line OWLClassesTab with the plugin class that
you want to show in the JFrame
		WidgetDescriptor widgetDescriptor =
prj.getTabWidgetDescriptor(TGVizTab.class.getName());
		
		if (widgetDescriptor == null) {
			System.out.println("Cannot instantiate tab widget.");
			return;
		}
		
		TabWidget widget = WidgetUtilities.createTabWidget(widgetDescriptor, prj);
	
		JFrame frame = new JFrame("TGViz Ontology Viewer");
		
		frame.getContentPane().add((Component)widget);		
		frame.setBounds(100, 100, 1024, 768);
		frame.setVisible(true);
	}		
}

//END OF FILE

I hope this ends up being readable :confused:

Thanks!

Chris Roush


Thomas Russ wrote:
> 
> 
> On Jun 4, 2008, at 2:55 PM, Roosh wrote:
> 
>>
>> Hi everyone!
>>
>> I am working on a Java program and I need to open a protege project.
>>
>> For example, my code is like this:
>>
>> String uri =
>> "file:/D:/Program%20Files/Protege_3.3.1/examples/pizza/ 
>> pizza.owl.pprj";
>> ArrayList errors = new ArrayList();
>> Project prj = Project.loadProjectFromFile(uri, errors);
>>
>> PROBLEM: This is only an example, my actual program uses a file  
>> chooser to
>> select the file
>> and the URI is passed to the loadProjectFromFile() function.
> 
> We'll need to see your actual program code.
> Apparently something is going wrong between when you get the file  
> chooser response and when you call the load function.  How to you  
> convert the file choose results into a URL?
> 
> 
>> However, when I
>> do this the file will not load because it seems that  
>> loadProjectFromFile()
>> concatenates the current build path to the front of the URI
>> passed in. This is what the console says after trying to load the  
>> file:
>>
>> SEVERE: Unable to load project from:
>> file:/D:/Program%20Files/Protege_3.3.1/file:/D:/Program%2520Files/ 
>> Protege_3.3.1/examples/pizza/pizza.owl.pprj
>> -- Project.getProjectInstancesReader()
>>
>> Is there any way to fix this?
>>
>> Any input would be appreciated.
> 
> _______________________________________________
> protege-discussion mailing list
> protege-discussion at lists.stanford.edu
> https://mailman.stanford.edu/mailman/listinfo/protege-discussion
> 
> Instructions for unsubscribing:
> http://protege.stanford.edu/doc/faq.html#01a.03 
> 
> 

-- 
View this message in context: http://www.nabble.com/Protege-API-loadProjectFromFile%28%29-question...-tp17656559p17669695.html
Sent from the Protege - General mailing list archive at Nabble.com.




More information about the protege-discussion mailing list