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

jadex.base.gui.componentviewer.DefaultComponentServiceViewerPanel Maven / Gradle / Ivy

There is a newer version: 4.0.267
Show newest version
package jadex.base.gui.componentviewer;

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import jadex.base.gui.plugin.AbstractJCCPlugin;
import jadex.base.gui.plugin.IControlCenter;
import jadex.bridge.IExternalAccess;
import jadex.bridge.service.IService;
import jadex.bridge.service.search.SServiceProvider;
import jadex.commons.SReflect;
import jadex.commons.future.CounterResultListener;
import jadex.commons.future.DelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;
import jadex.commons.gui.future.SwingDefaultResultListener;

/**
 *  Default panel for viewing BDI agents that include viewable capabilities. 
 */
public class DefaultComponentServiceViewerPanel extends AbstractComponentViewerPanel
{
	//-------- attributes --------

	/** The constant for the optional component viewerclass. */
	public static final String PROPERTY_COMPONENTVIEWERCLASS = "viewerpanel.componentviewerclass";
	
	//-------- attributes --------
	
	/** The panel. */
	protected JPanel panel;
	
	//-------- methods --------
	
	/**
	 *  Called once to initialize the panel.
	 *  Called on the swing thread.
	 *  @param jcc	The jcc.
	 * 	@param component The component.
	 */
	public IFuture init(final IControlCenter jcc, final IExternalAccess component)
	{
		this.panel = new JPanel(new BorderLayout());
		final Future ret = new Future();
		
		// Init interface is asynchronous but super implementation is not.
		IFuture	fut	= super.init(jcc, component);
		assert fut.isDone();
		
		SServiceProvider.getDeclaredServices(component)
			.addResultListener(new IResultListener>()
		{
			public void resultAvailable(Collection result)
			{
				createPanels(component, result).addResultListener(new DelegationResultListener(ret));
			}
			
			public void exceptionOccurred(Exception exception)
			{
				ret.setException(exception);
			}
		});
		
		return ret;
	}
	
	/**
	 *  Create the panels.
	 */
	protected IFuture createPanels(final IExternalAccess exta, final Collection services)
	{
		final Future ret = new Future();
		
		AbstractJCCPlugin.getClassLoader(exta.getComponentIdentifier(), jcc)
			.addResultListener(new SwingDefaultResultListener()
		{
			public void customResultAvailable(final ClassLoader cl)
			{
				final List panels = new ArrayList();
				
				final CounterResultListener lis = new CounterResultListener(
					services!=null ? services.size()+1 : 1, true, new DelegationResultListener(ret)
				{
					public void customResultAvailable(Void result) 
					{
		//				if(subpanels.size()==1)
		//				{
		//					Object[] tmp = (Object[])subpanels.get(0);
		//					add(((IComponentViewerPanel)tmp[1]).getComponent(), BorderLayout.CENTER);
		//				}
		//				else if(subpanels.size()>1)
						{
							JTabbedPane tp = new JTabbedPane();
							for(int i=0; i[]	classes	= getGuiClasses(exta.getModel().getProperty(PROPERTY_COMPONENTVIEWERCLASS, cl), cl);
				boolean	found	= false;
				for(int i=0; !found && i[]	getGuiClasses(Object prop, ClassLoader cl)
	{
		List>	classes	= new ArrayList>();
		
		if(SReflect.isIterable(prop))
		{
			for(Iterator	it=SReflect.getIterator(prop); it.hasNext(); )
			{
				Object	tmp	= it.next();
				Class	clazz	= tmp instanceof Class? (Class)tmp: tmp instanceof String? SReflect.classForName0((String)tmp, cl): null;
				if(clazz!=null)
				{
					classes.add(clazz);
				}
			}			
		}
		else
		{
			Class	clazz	= prop instanceof Class? (Class)prop: prop instanceof String? SReflect.classForName0((String)prop, cl): null;
			if(clazz!=null)
			{
				classes.add(clazz);
			}			
		}

		return classes.toArray(new Class[0]);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy