Search in sources :

Example 1 with OpenFileAction

use of org.eclipse.ui.actions.OpenFileAction in project sling by apache.

the class PackageExplorerOpenActionProvider method init.

@Override
public void init(ICommonActionExtensionSite site) {
    super.init(site);
    action = new OpenFileAction(getActivePage());
    ICommonViewerWorkbenchSite workbenchSite = null;
    if (site.getViewSite() instanceof ICommonViewerWorkbenchSite)
        workbenchSite = (ICommonViewerWorkbenchSite) site.getViewSite();
    if (workbenchSite != null) {
        if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
            IViewPart viewPart = (IViewPart) workbenchSite.getPart();
            if (site.getStructuredViewer() instanceof TreeViewer) {
                treeViewer = (TreeViewer) site.getStructuredViewer();
                treeViewer.addSelectionChangedListener(action);
            }
            fInViewPart = true;
        }
    }
}
Also used : OpenFileAction(org.eclipse.ui.actions.OpenFileAction) IViewPart(org.eclipse.ui.IViewPart) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICommonViewerWorkbenchSite(org.eclipse.ui.navigator.ICommonViewerWorkbenchSite)

Example 2 with OpenFileAction

use of org.eclipse.ui.actions.OpenFileAction in project sling by apache.

the class PackageExplorerOpenActionProvider method fillActionBars.

@Override
public void fillActionBars(IActionBars actionBars) {
    if (fInViewPart) {
        ISelection selection = treeViewer.getSelection();
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection iss = (IStructuredSelection) selection;
            if (iss.getFirstElement() instanceof JcrNode) {
                final JcrNode node = (JcrNode) iss.getFirstElement();
                final IFile file = node.getFileForEditor();
                if (file != null) {
                    actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, new OpenFileAction(getActivePage()) {

                        @Override
                        public void run() {
                            try {
                                IDE.openEditor(getActivePage(), file, true);
                            } catch (PartInitException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    });
                }
                return;
            }
        }
    //			fOpenGroup.fillActionBars(actionBars);
    //
    //			if (fOpenAndExpand == null && fOpenGroup.getOpenAction().isEnabled()) // TODO: is not updated!
    //				actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, fOpenGroup.getOpenAction());
    //			else if (fOpenAndExpand != null && fOpenAndExpand.isEnabled())
    }
    actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, action);
}
Also used : OpenFileAction(org.eclipse.ui.actions.OpenFileAction) JcrNode(org.apache.sling.ide.eclipse.ui.nav.model.JcrNode) IFile(org.eclipse.core.resources.IFile) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

OpenFileAction (org.eclipse.ui.actions.OpenFileAction)2 JcrNode (org.apache.sling.ide.eclipse.ui.nav.model.JcrNode)1 IFile (org.eclipse.core.resources.IFile)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 IViewPart (org.eclipse.ui.IViewPart)1 PartInitException (org.eclipse.ui.PartInitException)1 ICommonViewerWorkbenchSite (org.eclipse.ui.navigator.ICommonViewerWorkbenchSite)1