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

jadex.base.gui.modeltree.RemovePathAction Maven / Gradle / Ivy

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

import java.awt.event.ActionEvent;

import javax.swing.Icon;
import javax.swing.JOptionPane;
import javax.swing.UIDefaults;
import javax.swing.tree.TreePath;

import jadex.commons.gui.SGUI;
import jadex.commons.gui.ToolTipAction;

/**
 *  Action for removing a path. 
 */
public class RemovePathAction extends ToolTipAction
{
	//-------- constants --------
	
	/** The image icons. */
	protected static final UIDefaults icons = new UIDefaults(new Object[]
	{
		"removepath",	SGUI.makeIcon(ModelTreePanel.class, "/jadex/base/gui/images/remove_folder424.png"),
	});

	//-------- attributes --------	

	/** The tree. */
	protected ITreeAbstraction treepanel;
	
	//-------- constructors --------
	
	/**
	 *  Create a new action.
	 */
	public RemovePathAction(ITreeAbstraction treepanel)
	{
		this(getName(), getIcon(), getTooltipText(), treepanel);
	}
	
	/**
	 *  Create a new action. 
	 */
	public RemovePathAction(String name, Icon icon, String desc, ITreeAbstraction treepanel)
	{
		super(name, icon, desc);
		this.treepanel = treepanel;
	}
	
	//-------- methods --------
	
	/**
	 *  Test if action is available in current context.
	 *  @return True, if available.
	 */
	public boolean isEnabled()
	{
		Object rm = treepanel.getTree().getLastSelectedPathComponent();
		return rm!=null; //&& rm.getParent().equals(treepanel.getTree().getModel().getRoot());
	}
	
	/**
	 *  Action performed.
	 */
	public void actionPerformed(ActionEvent e)
	{
		// Can be used from toolbar without considering enabled state.
		if(!isEnabled())
		{
			JOptionPane.showMessageDialog(SGUI.getWindowParent(treepanel.getTree()), "Only root folders can be removed.");
			return;
		}
		
		TreePath[]	selected	= treepanel.getTree().getSelectionPaths();
		for(int i=0; selected!=null && i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy