Search in sources :

Example 1 with PathEditorInput

use of org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.PathEditorInput in project linuxtools by eclipse.

the class SystemTapScriptLaunchConfigurationTab method getSelectedScriptPath.

private String getSelectedScriptPath() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    // $NON-NLS-1$
    String pathString = "";
    if (window != null) {
        ISelection selection = window.getSelectionService().getSelection();
        // Figure out the selected systemtap script
        if (selection instanceof TreeSelection) {
            Object selectedElement = ((TreeSelection) selection).getFirstElement();
            if (selectedElement instanceof IFile) {
                IPath path = ((IFile) selectedElement).getLocation();
                pathString = path.toOSString();
            }
        }
        // If it is a text selection use the path from the active editor.
        if (selection instanceof TextSelection) {
            IEditorPart ed = window.getActivePage().getActiveEditor();
            if (ed.getEditorInput() instanceof PathEditorInput) {
                pathString = ((PathEditorInput) ed.getEditorInput()).getPath().toString();
            } else {
                pathString = ResourceUtil.getFile(ed.getEditorInput()).getLocation().toString();
            }
        }
    }
    if (pathString.endsWith(".stp")) {
        // $NON-NLS-1$
        return pathString;
    }
    // $NON-NLS-1$
    return "";
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection) IEditorPart(org.eclipse.ui.IEditorPart) PathEditorInput(org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.PathEditorInput)

Example 2 with PathEditorInput

use of org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.PathEditorInput in project linuxtools by eclipse.

the class SystemTapScriptLaunchShortcut method launch.

@Override
public void launch(IEditorPart editor, String mode) {
    String path;
    String project = null;
    if (editor.getEditorInput() instanceof PathEditorInput) {
        path = ((PathEditorInput) editor.getEditorInput()).getPath().toString();
    } else {
        IFile file = ResourceUtil.getFile(editor.getEditorInput());
        path = file.getLocation().toString();
        project = file.getProject().getName();
    }
    this.searchAndLaunch(path, project);
}
Also used : IFile(org.eclipse.core.resources.IFile) PathEditorInput(org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.PathEditorInput)

Aggregations

IFile (org.eclipse.core.resources.IFile)2 PathEditorInput (org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.PathEditorInput)2 IPath (org.eclipse.core.runtime.IPath)1 TextSelection (org.eclipse.jface.text.TextSelection)1 ISelection (org.eclipse.jface.viewers.ISelection)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1