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

jadex.micro.testcases.semiautomatic.ExternalAccessInvokerAgent Maven / Gradle / Ivy

Go to download

The Jadex micro applications package contains several example applications, benchmarks and testcases using micro agents.

There is a newer version: 4.0.267
Show newest version
package jadex.micro.testcases.semiautomatic;

import javax.swing.SwingUtilities;

import jadex.base.gui.CMSUpdateHandler;
import jadex.base.gui.ComponentSelectorDialog;
import jadex.base.gui.componenttree.ComponentIconCache;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IComponentStep;
import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.search.SServiceProvider;
import jadex.bridge.service.types.cms.IComponentManagementService;
import jadex.commons.future.DefaultResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.transformation.annotations.Classname;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentBody;

/**
 *  Agent that opens a component selector dialog and then executes a 
 *  step on the selected component.
 */
@Agent
public class ExternalAccessInvokerAgent
{
	@Agent
	protected IInternalAccess agent;
	
	/**
	 *  Execute the functional body of the agent.
	 *  Is only called once.
	 */
	@AgentBody
	public IFuture executeBody()
	{
		SwingUtilities.invokeLater(new Runnable()
		{
			public void run()
			{
				final ComponentSelectorDialog agentselector	= new ComponentSelectorDialog(null, agent.getExternalAccess(), agent.getExternalAccess(), 
					new CMSUpdateHandler(agent.getExternalAccess()), null, new ComponentIconCache(agent.getExternalAccess()));
				final IComponentIdentifier cid = agentselector.selectAgent(null);
				if(cid!=null)
				{
					SServiceProvider.getService(agent.getExternalAccess(), IComponentManagementService.class, RequiredServiceInfo.SCOPE_PLATFORM)
						.addResultListener(new DefaultResultListener()
					{
						public void resultAvailable(IComponentManagementService cms)
						{
							cms.getExternalAccess(cid).addResultListener(new DefaultResultListener()
							{
								public void resultAvailable(IExternalAccess ea)
								{
									ea.scheduleStep(new IComponentStep()
									{
										@Classname("exe")
										public IFuture execute(IInternalAccess ia)
										{
											System.out.println("Executing step on component: "+ia);
											return IFuture.DONE;
										}
									});
								}
							});
						}
					});
				}
			}
		});
		
		return new Future(); // never kill?!
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy