Difference between revisions of "UseTabInApplication"

From Protege Wiki
Jump to: navigation, search
Line 1: Line 1:
= Using a Tab Plugin in your own application =
+
= Using a Protege tab plug-in in your own application =
  
This page shows how you can use an existing Tab Plugin as part of your application.
 
  
The following code snippet shows an example on how to add the <code>OWLClassesTab</code> in a <code>JFrame</code>.
+
This page shows how you can use an existing Protege [http://protege.stanford.edu/doc/pdk/plugins/tab_widget.html tab widget plug-in] as part of your application.
  
<code>
+
The following code snippet is an example of adding the <code>OWLClassesTab</code> to a <code>JFrame</code>.
<pre>
+
 
 +
<code><pre>
 
package examples;
 
package examples;
  
Line 22: Line 22:
 
public class StandaloneTabWidget {
 
public class StandaloneTabWidget {
  
public static void main(String[] args) {
+
    public static void main(String[] args) {
ArrayList errors = new ArrayList();
+
        ArrayList errors = new ArrayList();
  
Project prj = Project.loadProjectFromFile("/work/protege/projects/pizza/pizza.owl.pprj", errors);
+
        Project prj = Project.loadProjectFromFile("/work/protege/projects/pizza/pizza.owl.pprj", errors);
 
 
if (errors.size() > 0) {
+
        if (errors.size() > 0) {
System.out.println("There were erros at loading prj: " + prj);
+
            System.out.println("There were erros at loading prj: " + prj);
return;
+
    return;
}
+
        }
 
 
                // Replace in the next line OWLClassesTab with the plugin class that you want to show in the JFrame
+
        // In the next line, replace "OWLClassesTab" with the plug-in class that you want to show in the JFrame
WidgetDescriptor widgetDescriptor = prj.getTabWidgetDescriptor(OWLClassesTab.class.getName());
+
        WidgetDescriptor widgetDescriptor = prj.getTabWidgetDescriptor(OWLClassesTab.class.getName());
 
 
if (widgetDescriptor == null) {
+
        if (widgetDescriptor == null) {
System.out.println("Cannot instantiate tab widget.");
+
            System.out.println("Cannot instantiate tab widget.");
return;
+
    return;
}
+
        }
 
 
TabWidget widget = WidgetUtilities.createTabWidget(widgetDescriptor, prj);
+
        TabWidget widget = WidgetUtilities.createTabWidget(widgetDescriptor, prj);
 
 
JFrame frame = new JFrame("My Application Frame");
+
        JFrame frame = new JFrame("My Application Frame");
frame.getContentPane().add((Component)widget);
+
        frame.getContentPane().add((Component)widget);
 
 
frame.pack();
+
        frame.pack();
frame.setVisible(true);
+
        frame.setVisible(true);
 
+
    }
}
 
 
}
 
}
</pre>
+
</pre></code>
</code>
 
 
 
  
You need to add to your classpath:
+
The following JAR files need to be on the classpath:
* From Protege installation directory:
+
* From the Protege installation directory:
 
** protege.jar
 
** protege.jar
 
** looks-2.1.3.jar
 
** looks-2.1.3.jar
* ''(Optional)'' If you use OWL, add to your classpath:
+
* ''(Optional)'' If you use OWL, add:
** all jars from the ''plugins/edu.stanford.smi.protegex.owl'' folder
+
** all JAR files from the ''plugins/edu.stanford.smi.protegex.owl'' folder
* ''(Optional)'' If you use a tab plugin that is not part of the protege.jar or protege-owl.jar, you will need to include:
+
* ''(Optional)'' If you use a tab plug-in that is not part of protege.jar or protege-owl.jar, you need to include:
** all the jars from the plugin directory (e.g. for TGVizTab, add all jars from ''plugins/uk.ac.iam.soton.akt.tgviztab'')
+
** all JAR files from the plug-in's directory (e.g., for TGVizTab, add all the JAR files from ''plugins/uk.ac.iam.soton.akt.tgviztab'')
** all the jars that the plugin depends on (e.g. if the plugin depends on protege-owl, then add all jars for protege-owl). You can find out the plugins that a plugin depends on by looking in the plugin.properties file. See [[PluginDependencies]] for more information.
+
** all JAR files that the plug-in depends on (e.g., if the plug-in depends on Protege-OWL, then add all the Protege-OWL JAR files). You can find information about the plug-ins that a plug-in depends on by looking in the <code>plugin.properties</code> file. See the [[PluginDependencies|documentation on declaring plug-in dependencies]] for more information.
 +
 
 +
 
 +
 
 +
'''See Also:'''
  
 +
[http://protege.stanford.edu/doc/pdk/using_forms_in_other_applications.html Using Protege Forms in other applications]<br />
 +
[http://protege.stanford.edu/doc/pdk/plugins/tab_widget.html How to write a tab widget plug-in]<br /><br /><br />
  
For more information on using Protege forms in other applications, see [http://protege.stanford.edu/doc/pdk/using_forms_in_other_applications.html this page].
+
[[Category:Protege developer documentation]]

Revision as of 15:13, June 3, 2008

Using a Protege tab plug-in in your own application

This page shows how you can use an existing Protege tab widget plug-in as part of your application.

The following code snippet is an example of adding the OWLClassesTab to a JFrame.

package examples;

import java.awt.Component;
import java.util.ArrayList;

import javax.swing.JFrame;

import edu.stanford.smi.protege.model.Project;
import edu.stanford.smi.protege.model.WidgetDescriptor;
import edu.stanford.smi.protege.widget.TabWidget;
import edu.stanford.smi.protege.widget.WidgetUtilities;
import edu.stanford.smi.protegex.owl.ui.cls.OWLClassesTab;

public class StandaloneTabWidget {

    public static void main(String[] args) {
        ArrayList errors = new ArrayList();

        Project prj = Project.loadProjectFromFile("/work/protege/projects/pizza/pizza.owl.pprj", errors);
		
        if (errors.size() > 0) {
            System.out.println("There were erros at loading prj: " + prj);			
	    return;
        }
		
        // In the next line, replace "OWLClassesTab" with the plug-in class that you want to show in the JFrame
        WidgetDescriptor widgetDescriptor = prj.getTabWidgetDescriptor(OWLClassesTab.class.getName());
		
        if (widgetDescriptor == null) {
            System.out.println("Cannot instantiate tab widget.");
	    return;
        }
		
        TabWidget widget = WidgetUtilities.createTabWidget(widgetDescriptor, prj);
		
        JFrame frame = new JFrame("My Application Frame");
        frame.getContentPane().add((Component)widget);		
		
        frame.pack();
        frame.setVisible(true);
    }		
}

The following JAR files need to be on the classpath:

  • From the Protege installation directory:
    • protege.jar
    • looks-2.1.3.jar
  • (Optional) If you use OWL, add:
    • all JAR files from the plugins/edu.stanford.smi.protegex.owl folder
  • (Optional) If you use a tab plug-in that is not part of protege.jar or protege-owl.jar, you need to include:
    • all JAR files from the plug-in's directory (e.g., for TGVizTab, add all the JAR files from plugins/uk.ac.iam.soton.akt.tgviztab)
    • all JAR files that the plug-in depends on (e.g., if the plug-in depends on Protege-OWL, then add all the Protege-OWL JAR files). You can find information about the plug-ins that a plug-in depends on by looking in the plugin.properties file. See the documentation on declaring plug-in dependencies for more information.


See Also:

Using Protege Forms in other applications
How to write a tab widget plug-in