/**
* This file is part of HIDB2.
*
* HIDB2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HIDB2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser Public License
* along with HIDB2. If not, see <http://www.gnu.org/licenses/>.
*/
package hidb2.gui.action;
import hidb2.gui.node.FileNode;
import hidb2.gui.ressources.RscMan;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
/**
* Generic open file command.
*
*/
public class OpenFile extends Action
{
private TreeViewer viewer;
public OpenFile(TreeViewer viewer)
{
this.viewer = viewer;
setText("Open File");
setToolTipText("Open");
// The id is used to refer to the action in a menu or toolbar
setId("hidb2.gui.action.OpenFile");
// Associate the action with a pre-defined command, to allow key bindings.
// setActionDefinitionId("hidb2.gui.action.OpenFile");
setImageDescriptor(RscMan.getImageDescriptor(RscMan.IN_OPEN_STD));
}
public void run()
{
if (viewer != null)
{
try
{
ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof FileNode)
{
// Expand directory nodes
FileNode n = (FileNode) obj;
if (n.getCategory() == FileNode.C_DIRECTORY)
{
viewer.expandToLevel(obj, 1);
}
}
else
{
// petit message d'erreur
MessageDialog.openError(viewer.getControl().getShell(), getText(), "Can not be open");
}
}
catch (/*PartInit*/Exception e)
{
MessageDialog.openError(viewer.getControl().getShell(), "Error", "Error opening Editor: " + e.getMessage()
+ "\n loc \n" + e.getLocalizedMessage() + "\n Stack Trace " + e.getStackTrace() + " \nCaused by "
+ e.getCause());
e.printStackTrace();
}
}
}
}