All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.base.gui.componenttree.ProvidedServiceInfoProperties Maven / Gradle / Ivy

There is a newer version: 2.4
Show newest version
package jadex.base.gui.componenttree;

import jadex.bridge.IExternalAccess;
import jadex.bridge.service.IServiceIdentifier;
import jadex.bridge.service.ProvidedServiceInfo;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.search.SServiceProvider;
import jadex.bridge.service.types.library.ILibraryService;
import jadex.commons.SReflect;
import jadex.commons.gui.PropertiesPanel;
import jadex.commons.gui.SGUI;
import jadex.commons.gui.future.SwingDefaultResultListener;
import jadex.commons.gui.jtable.ResizeableTableHeader;

import java.awt.BorderLayout;
import java.lang.reflect.Method;
import java.lang.reflect.Type;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *  Panel for showing service properties.
 */
public class ProvidedServiceInfoProperties	extends	PropertiesPanel
{
	//-------- constructors --------
	
	/**
	 *  Create new service properties panel.
	 */
	public ProvidedServiceInfoProperties()
	{
		super(" Service Properties ");

		createTextField("Name");
		createTextField("Type");
		
		// todo:
//		createTextField("Implementation");  
		
		addFullLineComponent("Methods_label", new JLabel("Methods"));
		JTable	table	= SGUI.createReadOnlyTable();
		table.setTableHeader(new ResizeableTableHeader(table.getColumnModel()));
		JPanel	scroll	= new JPanel(new BorderLayout());
		scroll.add(table, BorderLayout.CENTER);
		scroll.add(table.getTableHeader(), BorderLayout.NORTH);
		addFullLineComponent("Methods", scroll);
	}
	
	//-------- methods --------
	
	/**
	 *  Set the service.
	 */
	public void	setService(final ProvidedServiceInfo service, final IServiceIdentifier sid, IExternalAccess ea)
	{
		getTextField("Name").setText(service.getName());
		getTextField("Type").setText(service.getType().getTypeName());
//		getTextField("Implementation").setText();

		if(service.getType().getType()==null)
		{
			SServiceProvider.getService(ea.getServiceProvider(), ILibraryService.class, RequiredServiceInfo.SCOPE_PLATFORM)
				.addResultListener(new SwingDefaultResultListener()
			{
				public void customResultAvailable(ILibraryService ls)
				{
					ls.getClassLoader(sid.getResourceIdentifier())
						.addResultListener(new SwingDefaultResultListener()
					{
						public void customResultAvailable(ClassLoader cl)
						{
							Class type = service.getType().getType(cl);
//							System.out.println("Found: "+service.getType().getTypeName()+" "+cl+" "+type);
							internalSetService(type);
						}
					});
				}
			});
		}
		else
		{
			internalSetService(service.getType().getType());
		}
	}
	
	/**
	 * 
	 */
	protected void internalSetService(Class type)
	{
		if(type==null)
		{
			// Class not available
			JTable	list	= (JTable)getComponent("Methods").getComponent(0);
			DefaultTableModel	dtm	= new DefaultTableModel();
			dtm.addColumn("Not Available", new String[]{"Class file for service type not available locally.", "Methods cannot be displayed."});
			list.setModel(dtm);
		}
		else
		{
			JTable	list	= (JTable)getComponent("Methods").getComponent(0);
			// remote case not supported yet
			Method[] methods	= type.getMethods();
			String[] returntypes	= new String[methods.length]; 
			String[] names	= new String[methods.length]; 
			String[] parameters	= new String[methods.length];
			for(int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy