/**
* 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.Application;
import hidb2.gui.DBDataView;
import hidb2.gui.DBStructView;
import hidb2.gui.SearchView;
import hidb2.gui.editor.DataPathEditor;
import hidb2.gui.editor.EnumItemListEditor;
import hidb2.gui.editor.FolderDescrEditor;
import hidb2.gui.editor.FolderEditor;
import hidb2.gui.editor.FolderListEditor;
import hidb2.gui.editor.ListDescrEditor;
import hidb2.gui.node.DataPathNode;
import hidb2.gui.node.DataPathTitleNode;
import hidb2.gui.node.EnumItemListNode;
import hidb2.gui.node.FolderDescrNode;
import hidb2.gui.node.FolderListNode;
import hidb2.gui.node.FolderNode;
import hidb2.gui.node.ListDescrNode;
import java.util.logging.Logger;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
/**
* Open the Editors.
*/
public class GeneralOpen implements IActionDelegate, IViewActionDelegate
{
final static Logger log = Logger.getLogger("hidb2.gui.action");
private ISelection _selection;
public void init(IViewPart view)
{
}
public GeneralOpen()
{
}
public void run(IAction action)
{
try
{
if ((_selection != null) && (!_selection.isEmpty()))
{
Object obj = ((IStructuredSelection) _selection).getFirstElement();
IWorkbenchWindow wbwin = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
// For Tests of editor
IWorkbenchPage page = wbwin.getActivePage();
IWorkbenchPart iwp = page.getActivePart();
// Control Destination Class
if (obj instanceof FolderDescrNode)
{
if (iwp instanceof DBStructView)
{
// Get the FolderDescrNode and open the editor
FolderDescrNode fnd = (FolderDescrNode) obj;
if (Application.getLock(fnd.getDescr()))
{
page.openEditor(fnd, FolderDescrEditor.ID);
}
}
}
else
{
if (obj instanceof FolderListNode)
{
if ((iwp instanceof DBDataView) || (iwp instanceof SearchView))
{
// Get the FolderDescrNode and open the editor
FolderListNode fld = ((FolderListNode) obj);
if (Application.getLock(fld.getDescr()))
{
page.openEditor(fld, FolderListEditor.ID);
}
}
}
else
{
if (obj instanceof DataPathNode)
{
// Open datapath editor
DataPathNode dnp = (DataPathNode) obj;
DataPathTitleNode dptn = (DataPathTitleNode) dnp.getParent();
dptn.addChild(dnp);
page.openEditor(dptn, DataPathEditor.ID);
// Update the tree view, but does not refresh the visible parts.
if (iwp instanceof DBStructView)
{
((DBStructView) iwp).getTree().refresh(dptn, true);
}
}
else
{
if (obj instanceof ListDescrNode)
{
if (iwp instanceof DBStructView)
{
// Get the ListDescrNode and open the editor
ListDescrNode fnd = ((ListDescrNode) obj);
if (Application.getLock(fnd.getDescr()))
{
page.openEditor(fnd, ListDescrEditor.ID);
}
}
}
else
{
if (obj instanceof EnumItemListNode)
{
// Open the EnumItem list editor
if (iwp instanceof DBDataView)
{
// Get the FolderDescrNode and open the editor
EnumItemListNode fld = ((EnumItemListNode) obj);
if (Application.getLock(fld.getDescr()))
{
page.openEditor(fld, EnumItemListEditor.ID);
}
}
}
else
{
if (obj instanceof FolderNode)
{
FolderNode fn = (FolderNode) obj;
if (Application.getLock(fn.getFolder()))
{
page.openEditor(fn, FolderEditor.ID);
}
}
}
}
}
}
}
}
}
catch (PartInitException piex)
{
piex.printStackTrace();
}
}
public void selectionChanged(IAction action, ISelection selection)
{
_selection = selection;
}
}