Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package jadex.tools.starter;
  
 
 import java.io.File;
 
The starter gui allows for starting components platform independently.
 
 public class StarterPluginPanel extends JPanel
 {
 	//-------- static part --------
 
The image icons.
 
 	protected static final UIDefaults icons = new UIDefaults(new Object[]
 	{
 		"add_remote_component", SGUI.makeIcon(StarterPluginPanel.class"/jadex/tools/common/images/add_remote_component.png"),
 		"kill_platform", SGUI.makeIcon(StarterPluginPanel.class"/jadex/tools/common/images/new_killplatform.png"),
 		"starter", SGUI.makeIcon(StarterPluginPanel.class"/jadex/tools/common/images/new_starter.png"),
 		"starter_sel", SGUI.makeIcon(StarterPluginPanel.class"/jadex/tools/common/images/new_starter_sel.png"),
 		"start_component",	SGUI.makeIcon(StarterPluginPanel.class"/jadex/tools/common/images/start.png"),
 		"checking_menu",	SGUI.makeIcon(StarterPluginPanel.class"/jadex/tools/common/images/new_agent_broken.png")
 	});
 
 	//-------- attributes --------
 
The starter panel.
 
 	protected StarterPanel spanel;

The panel showing the classpath models.
 
 	protected ModelTreePanel mpanel;

The component instances in a tree.
 
A split panel.
 
 	protected JSplitPanel lsplit;

A split panel.
 
     protected JSplitPanel csplit;

    
The jcc.
 
     protected IControlCenter jcc;
     
 	//-------- constructors --------
 
Open the GUI.

Parameters:
starter The starter.
 
 	public StarterPluginPanel(final IControlCenter jcc)
	{
		super(new BorderLayout());
		this. = jcc;
		{
			public void removeTopLevelNode(ITreeNode node)
			{
				super.removeTopLevelNode(node);
				if(node instanceof IFileNode && !=null && .!=null)
				{
					final String	path	= ((IFileNode)node).getFilePath();
					final String	model.;
					{
						@XMLClassname("matchModel")
						{
							boolean	matchfalse;
							File	pathfile	= LibraryService.urlToFile(path);
							File	modelfile	= LibraryService.urlToFile(model);
							try
							{
								matchpathfile!=null && modelfile!=null && modelfile.getCanonicalPath().startsWith(pathfile.getCanonicalPath());
							}
							catch(IOException e)
							{
							}
							return Boolean.valueOf(match);
						}
					{
						public void customResultAvailable(Object result)
						{
							if(((Boolean)result).booleanValue() && model.equals(.))
							{
							}
						}
						public void customExceptionOccurred(Exception exception)
						{
							// ignore.
						}
					});
				}
			}
		};
		{
			{
				String filename = null;
				if(node instanceof FileNode)
				{
					filename = ((FileNode)node).getFile().getAbsolutePath();
				}
				else if(node instanceof RemoteFileNode)
				{
					filename = ((RemoteFileNode)node).getRemoteFile().getPath();
				}
				if(filename!=null)
				{
					// Models have to be loaded with absolute path.
					// An example to facilitate understanding:
					// root
					//  +-classes1
					//  |  +- MyComponent.component.xml
					//  +-classes2
					//  |  +- MyComponent.component.xml
					final String ffilename = filename;
					{
						public void customResultAvailable(Object result)
						{
							if(((Boolean)result).booleanValue())
								.loadModel(ffilename);
						}
					});
//					else if(getJCC().getComponent().getPlatform().getApplicationFactory().isLoadable(model))
//					{
//						loadModel(model);
//					}
				}
			}
		});
		{
			public void mousePressed(MouseEvent e)
			{
				int row = .getTree().getRowForLocation(e.getX(), e.getY());
				if(row != -1)
				{
					if(e.getClickCount() == 2)
					{
						String filename = null;
						if(node instanceof FileNode)
						{
							filename = ((FileNode)node).getFile().getAbsolutePath();
						}
						else if(node instanceof RemoteFileNode)
						{
							filename = ((RemoteFileNode)node).getRemoteFile().getPath();
						}
//						if(getJCC().getComponent().getPlatform().getComponentFactory().isStartable(type))
						// todo: resultcollect = false?
						if(filename!=null)
						{
							final String ftype = filename;
							{
								public void customResultAvailable(Object result)
								{
									if(((Boolean)result).booleanValue())
										StarterPanel.createComponent(jcc.getPlatformAccess(), jccftypenullnullnullfalsenullnullnullnullnullStarterPluginPanel.this);
								}
							});
						}
					}
				}
      		}
  		};
		{
			public void nodeRemoved(final ITreeNode node)
			{
				if(node instanceof IActiveComponentTreeNode)
				{
				}
			}
			public void nodeAdded(ITreeNode node)
			{
			}
		});
//		lsplit.add(tp);
//				lsplit.setDividerLocation(300);
//		SGUI.setDividerLocation(lsplit, 300);
		 = new StarterPanel(jcc.getPlatformAccess(), jcc);
//				csplit.setDividerLocation(180);
//		SGUI.setDividerLocation(csplit, 180);
            			
		loadPlatformProperties();	// Todo: wait for loaded properties.
	}

Dynamically create a new menu item structure for starting components.
	{
Get or create a new menu item (struture).

Returns:
The menu item (structure).
		{
			JMenuItem ret = null;
			{
				if(node instanceof FileNode)
				{
					final String type = ((FileNode)node).getFile().getAbsolutePath();
					if(((Boolean)SComponentFactory.isStartable(.getPlatformAccess(), type).get(new ThreadSuspendable())).booleanValue())//&& ((FileNode)node).isValid())
					{
						try
						{
//							IComponentFactory componentfactory = getJCC().getComponent().getPlatform().getComponentFactory();
							IModelInfo model = (IModelInfo)SComponentFactory.loadModel(.getPlatformAccess(), type).get(new ThreadSuspendable());
							String[] inistates = model.getConfigurationNames();
//							IMBDIComponent model = SXML.loadComponentModel(type, null);
//							final IMConfiguration[] inistates = model.getConfigurationbase().getConfigurations();
							if(inistates.length>1)
							{
								JMenu re = new JMenu("Start Component");
								re.setIcon(.getIcon("start_component"));
								for(int i=0; i<inistates.lengthi++)
								{
									final String config = inistates[i];
									JMenuItem me = new JMenuItem(config);
									re.add(me);
									{
										public void actionPerformed(ActionEvent e)
										{
											// todo: collectresults = false?
											StarterPanel.createComponent(.getPlatformAccess(), typenullconfignullfalsenullnullnullnullnull);
										}
									});
									me.setToolTipText("Start in configuration: "+config);
								}
								ret = re;
								ret.setToolTipText("Start component in selectable configuration");
							}
							else
							{
								if(inistates.length==1)
								{
									ret = new JMenuItem("Start Component ("+inistates[0]+")");
									ret.setToolTipText("Start component in configuration:"+inistates[0]);
								}
								else
								{
									ret = new JMenuItem("Start Component");
									ret.setToolTipText("Start component without explicit initial state");
								}
								ret.setIcon(.getIcon("start_component"));
								{
									public void actionPerformed(ActionEvent e)
									{
										// todo: collectresults = false?
										StarterPanel.createComponent(.getPlatformAccess(), typenullnullnullfalsenullnullnullnullnull);
									}
								});
							}
						}
						catch(Exception e)
						{
							// NOP
						}
					}
				}
			}
			return ret;
		}

Test if action is available in current context.

Returns:
True, if available.
		public boolean isEnabled()
		{
			boolean ret = false;
			if(node instanceof FileNode)
			{
				String type = ((FileNode)node).getFile().getAbsolutePath();
				if(((Boolean)SComponentFactory.isStartable(.getPlatformAccess(), type).get(new ThreadSuspendable())))
					ret = true;
			}
			return ret;
		}
	}

Get the mpanel.

Returns:
the mpanel.
	{
		return ;
	}

Get the comptree.

Returns:
the comptree.
	{
		return ;
	}

Load and apply the platform properties.
	{
		final Future	retnew Future();
		{
			public void customResultAvailable(Object result)
			{
				settings.getProperties("StarterServicePanel")
				{
					public void customResultAvailable(Object result)
					{
						if(result!=null)
						{
							final Properties	props	= (Properties)result;
							{
								public void customResultAvailable(Object result)
								{
									ret.setResult(null);
								}
							});
						}
						else
						{
							ret.setResult(null);
						}
					}
				});
			}
			public void customExceptionOccurred(Exception exception)
			{
				// No settings service: ignore.
				ret.setResult(null);
			}
		});
		return ret;
	}

Save the platform properties.
	{
		final Future	retnew Future();
//		System.out.println("fetching settings service");
		{
			public void customResultAvailable(Object result)
			{
//				System.out.println("fetching mpanel properties");
				final ISettingsService	settings	= (ISettingsService)result;
				{
					public void customResultAvailable(Object result)
					{
//						System.out.println("fetched mpanel properties");
						final Properties	propsnew Properties();
						props.addSubproperties("mpanel", (Properties)result);
						{
							public void customResultAvailable(Object result)
							{
//								System.out.println("fetched spanel properties");
								props.addSubproperties("spanel", (Properties)result);
								settings.setProperties("StarterServicePanel"props)
							}
						});
					}
				});
			}
			public void customExceptionOccurred(Exception exception)
			{
				// No settings service: ignore.
				ret.setResult(null);
			}
		});
		return ret;
	}

Load the properties.
	{
		double dl = props.getDoubleProperty("leftsplit_location");
		if(dl!=0)
		{
		}
		dl = props.getDoubleProperty("mainsplit_location");
		if(dl!=0)
		{
		}
//		SGUI.setDividerLocation(lsplit, props.getIntProperty("leftsplit_location"));
//		SGUI.setDividerLocation(csplit, props.getIntProperty("mainsplit_location"));
		return .;
	}

Save the properties.

Parameters:
props
	{
		Properties	propsnew Properties();
		props.addProperty(new Property("leftsplit_location"""+.getProportionalDividerLocation()));
		props.addProperty(new Property("mainsplit_location"""+.getProportionalDividerLocation()));
//		props.addProperty(new Property("leftsplit_location", ""+lsplit.getDividerLocation()));
//		props.addProperty(new Property("mainsplit_location", ""+csplit.getDividerLocation()));
		return new Future(props);
	}

Dispose the panel.
	public void dispose()
	{
	}
New to GrepCode? Check out our FAQ X