Search in sources :

Example 61 with IEditorInput

use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.

the class MassifViewPart method dispose.

@Override
public void dispose() {
    // Close all chart editors to keep Valgrind output consistent throughout workbench
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    if (page != null) {
        for (IEditorInput input : chartInputs) {
            IEditorPart part = page.findEditor(input);
            if (part != null) {
                page.closeEditor(part, false);
            }
        }
    }
    super.dispose();
}
Also used : IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput)

Example 62 with IEditorInput

use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.

the class DoubleClickTest method testDoubleClickFile.

@Test
public void testDoubleClickFile() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testDoubleClickFile");
    doDoubleClick();
    IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    IEditorInput input = editor.getEditorInput();
    assertTrue("Input should be IFileEditorInput", input instanceof IFileEditorInput);
    IFileEditorInput fileInput = (IFileEditorInput) input;
    File expectedFile = new File(proj.getProject().getLocation().toOSString(), frame.getFile());
    File actualFile = fileInput.getFile().getLocation().toFile();
    assertEquals(expectedFile.getCanonicalPath(), actualFile.getCanonicalPath());
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput) Test(org.junit.Test)

Example 63 with IEditorInput

use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.

the class AddStapProbeHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ITextEditor editor;
    try {
        editor = (ITextEditor) HandlerUtil.getActiveEditor(event);
    } catch (ClassCastException e) {
        ExceptionErrorDialog.openError(Messages.AddStapProbe_unableToInsertProbe, Messages.AddStapProbe_editorError, e);
        throw new ExecutionException(Messages.AddStapProbe_editorError, e);
    }
    IVerticalRulerInfo rulerInfo = editor.getAdapter(IVerticalRulerInfo.class);
    Shell shell = editor.getSite().getShell();
    shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
    int lineno = rulerInfo.getLineOfLastMouseButtonActivity();
    IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    String s = document.get();
    // $NON-NLS-1$
    String[] lines = s.split("\n");
    String line = lines[lineno].trim();
    boolean die = false;
    if (line.isEmpty()) {
        // eat blank lines
        die = true;
    }
    if (line.startsWith("#")) {
        // eat preprocessor directives //$NON-NLS-1$
        die = true;
    }
    if (line.startsWith("//")) {
        // eat C99 comments //$NON-NLS-1$
        die = true;
    }
    if (line.startsWith("/*") && !line.contains("*/") && !line.endsWith("*/")) {
        // try to eat single-line C comments //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        die = true;
    }
    // gogo find comment segments
    try {
        ArrayList<Integer> commentChunks = new ArrayList<>();
        char[] chars = s.toCharArray();
        int needle = 1;
        int offset = document.getLineOffset(lineno);
        while (needle < chars.length) {
            if (chars[needle - 1] == '/' && chars[needle] == '*') {
                commentChunks.add(needle);
                while (needle < chars.length) {
                    if (chars[needle - 1] == '*' && chars[needle] == '/') {
                        commentChunks.add(needle);
                        needle++;
                        break;
                    }
                    needle++;
                }
            }
            needle++;
        }
        for (int i = 0, pair, start, end; i < commentChunks.size(); i++) {
            if (!(commentChunks.get(i).intValue() < offset)) {
                pair = i - i % 2;
                start = commentChunks.get(pair).intValue();
                end = commentChunks.get(pair + 1).intValue();
                if (offset >= start && offset <= end) {
                    die = true;
                }
            }
        }
    } catch (BadLocationException excp) {
        ExceptionErrorDialog.openError(Messages.AddStapProbe_unableToInsertProbe, excp);
        return null;
    }
    if (die) {
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.CEditor_probeInsertFailed, Messages.CEditor_canNotProbeLine);
    } else {
        IEditorInput in = editor.getEditorInput();
        if (in instanceof FileStoreEditorInput) {
            FileStoreEditorInput input = (FileStoreEditorInput) in;
            IPreferenceStore p = IDEPlugin.getDefault().getPreferenceStore();
            String kernroot = p.getString(IDEPreferenceConstants.P_KERNEL_SOURCE);
            String filepath = input.getURI().getPath();
            String kernrelative = filepath.substring(kernroot.length() + 1, filepath.length());
            StringBuffer sb = new StringBuffer();
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            sb.append("probe kernel.statement(\"*@" + kernrelative + ":" + (lineno + 1) + "\")");
            // $NON-NLS-1$
            sb.append("\n{\n\t\n}\n");
            STPEditor activeSTPEditor = IDESessionSettings.getOrAskForActiveSTPEditor(false);
            if (activeSTPEditor != null) {
                activeSTPEditor.insertText(sb.toString());
            }
        }
    }
    // Return the cursor to normal
    shell.setCursor(null);
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ArrayList(java.util.ArrayList) STPEditor(org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp.STPEditor) Shell(org.eclipse.swt.widgets.Shell) ExecutionException(org.eclipse.core.commands.ExecutionException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IVerticalRulerInfo(org.eclipse.jface.text.source.IVerticalRulerInfo) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 64 with IEditorInput

use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.

the class IndentHandler method getDocument.

/**
 * Returns the document currently displayed in the editor, or
 * <code>null</code> if none can be obtained.
 *
 * @return the current document or <code>null</code>
 */
private IDocument getDocument(ITextEditor editor) {
    if (editor != null) {
        IDocumentProvider provider = editor.getDocumentProvider();
        IEditorInput input = editor.getEditorInput();
        if (provider != null && input != null)
            return provider.getDocument(input);
    }
    return null;
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IEditorInput(org.eclipse.ui.IEditorInput)

Example 65 with IEditorInput

use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.

the class CreaterepoCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    // $NON-NLS-1$
    final String executionType = event.getParameter("executionType");
    try {
        IWorkbench wb = PlatformUI.getWorkbench();
        IWorkbenchPage wbPage = wb.getActiveWorkbenchWindow().getActivePage();
        IEditorInput editorInput = wbPage.getActiveEditor().getEditorInput();
        IResource resource = ResourceUtil.getResource(editorInput);
        final CreaterepoProject project = new CreaterepoProject(resource.getProject());
        Job executeCreaterepo = new Job(Messages.Createrepo_jobName) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    monitor.beginTask(Messages.CreaterepoProject_executeCreaterepo, IProgressMonitor.UNKNOWN);
                    MessageConsoleStream os = CreaterepoUtils.findConsole(Messages.CreaterepoProject_consoleName).newMessageStream();
                    if (executionType.equals("refresh")) {
                        // $NON-NLS-1$
                        return project.update(os);
                    } else {
                        return project.createrepo(os);
                    }
                } catch (CoreException e) {
                    Activator.logError(Messages.Createrepo_errorExecuting, e);
                } finally {
                    monitor.done();
                }
                return null;
            }
        };
        executeCreaterepo.setUser(true);
        executeCreaterepo.schedule();
    } catch (CoreException e) {
        Activator.logError(Messages.CreaterepoProject_executeCreaterepo, e);
    }
    return null;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) Job(org.eclipse.core.runtime.jobs.Job) CreaterepoProject(org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)135 IFile (org.eclipse.core.resources.IFile)38 IEditorPart (org.eclipse.ui.IEditorPart)37 PartInitException (org.eclipse.ui.PartInitException)31 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)28 CoreException (org.eclipse.core.runtime.CoreException)25 IFileEditorInput (org.eclipse.ui.IFileEditorInput)22 IDocument (org.eclipse.jface.text.IDocument)17 IEditorReference (org.eclipse.ui.IEditorReference)17 FileEditorInput (org.eclipse.ui.part.FileEditorInput)16 File (java.io.File)14 ArrayList (java.util.ArrayList)14 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)14 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)14 IResource (org.eclipse.core.resources.IResource)13 Shell (org.eclipse.swt.widgets.Shell)13 IViewPart (org.eclipse.ui.IViewPart)13 IPath (org.eclipse.core.runtime.IPath)12 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)11