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

jadex.base.gui.filetree.RemoteDirNode Maven / Gradle / Ivy

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

import jadex.base.gui.asynctree.AsyncTreeModel;
import jadex.base.gui.asynctree.ITreeNode;
import jadex.bridge.IComponentStep;
import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.bridge.service.types.deployment.FileData;
import jadex.commons.IRemoteFilter;
import jadex.commons.future.CollectionResultListener;
import jadex.commons.future.DefaultResultListener;
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;
import jadex.commons.transformation.annotations.Classname;

import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import javax.swing.JTree;
import javax.swing.SwingUtilities;

/**
 *  The remote dir node.
 */
public class RemoteDirNode extends RemoteFileNode
{
	//-------- attributes --------
	
	// hack: should belong to the model
	/** The factory. */
	protected INodeFactory factory;
	
	//-------- constructors --------
	
	/**
	 *  Create a new service container node.
	 */
	public RemoteDirNode(ITreeNode parent, AsyncTreeModel model, JTree tree, FileData file, 
		IIconCache iconcache, IExternalAccess exta, INodeFactory factory)
	{
		super(parent, model, tree, file, iconcache, exta);
		this.factory = factory;
//		System.out.println("node: "+getClass()+" "+desc.getName());
	}
	
	//-------- AbstractComponentTreeNode methods --------
	
	/**
	 *  Asynchronously search for children.
	 *  Should call setChildren() once children are found.
	 */
	protected void	searchChildren()
	{
		listFiles().addResultListener(new SwingDefaultResultListener()
		{
			public void customResultAvailable(Object result)
			{
				Collection files = (Collection)result;
				CollectionResultListener lis = new CollectionResultListener(files==null? 0: files.size(), true, 
					new DefaultResultListener()
				{
					public void resultAvailable(Object result)
					{
						setChildren((List)result);
					}
				});
				
				if(files!=null)
				{
					for(Iterator it=files.iterator(); it.hasNext();)
					{
						FileData file = (FileData)it.next();
						ITreeNode node = getModel().getNode(file.toString());
						if(node!=null)
						{
							lis.resultAvailable(node);
						}
						else
						{
							lis.resultAvailable(factory.createNode(RemoteDirNode.this, model, tree, 
								file, iconcache, exta, factory));
						}
					}
				}
			}
		});
	}
	
	/**
	 *  Check if the node is a leaf.
	 */
	public boolean	isLeaf()
	{
		assert SwingUtilities.isEventDispatchThread();

		return false;
	}
	
	/**
	 *	Get a file filter according to current file type settings. 
	 */
	protected IFuture listFiles()
	{
		final Future ret = new Future();
		
		if(file instanceof RemoteJarFile)
		{
			RemoteJarFile myfile = (RemoteJarFile)file;
			Collection files = myfile.listFiles();
			
			ret.setResult(files);
			
//			for(int i=0; i()
			{
				@Classname("listFiles")
				public IFuture execute(IInternalAccess ia)
				{
					Future ret = new Future();
					
					File f = new File(myfile.getPath());
					final File[] files = f.listFiles();
					if(files!=null)
					{
						final CollectionResultListener lis = new CollectionResultListener(files.length, 
							true, new DelegationResultListener(ret));
						
						for(int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy