Java Code Examples for org.eclipse.ui.ide.IDE#openEditorOnFileStore()

The following examples show how to use org.eclipse.ui.ide.IDE#openEditorOnFileStore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLAnalysesManagerPreferencePage.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Edit analysis file(s) with built-in editor.
 */
private void editAnalysis() {
    Map<@NonNull String, @NonNull File> listFiles = XmlUtils.listFiles();
    for (TableItem item : fAnalysesTable.getSelection()) {
        String selection = XmlUtils.createXmlFileString(item.getText());
        @Nullable File file = listFiles.get(selection);
        if (file == null) {
            Activator.logError(NLS.bind(Messages.ManageXMLAnalysisDialog_FailedToEdit, selection));
            TraceUtils.displayErrorMsg(NLS.bind(Messages.ManageXMLAnalysisDialog_FailedToEdit, selection), NLS.bind(Messages.ManageXMLAnalysisDialog_FailedToEdit, selection));
            return;
        }
        try {
            IEditorPart editorPart = IDE.openEditorOnFileStore(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), EFS.getStore(file.toURI()));
            // Remove listener first in case the editor was already opened
            editorPart.removePropertyListener(SAVE_EDITOR_LISTENER);
            editorPart.addPropertyListener(SAVE_EDITOR_LISTENER);
        } catch (CoreException e) {
            Activator.logError(NLS.bind(Messages.ManageXMLAnalysisDialog_FailedToEdit, selection));
            TraceUtils.displayErrorMsg(NLS.bind(Messages.ManageXMLAnalysisDialog_FailedToEdit, selection), e.getMessage());
        }
    }
}
 
Example 2
Source File: WorkspaceUtils.java    From JReFrameworker with MIT License 6 votes vote down vote up
public static void openFileInEclipseEditor(File file) {
	if (file.exists() && file.isFile()) {
		IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toURI());
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		try {
			IDE.openEditorOnFileStore(page, fileStore);
		} catch (PartInitException e) {
			Log.error("Could not display file: " + file.getAbsolutePath(), e);
		}
	} else {
		MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.OK);
		mb.setText("Alert");
		mb.setMessage("Could not find file: " + file.getAbsolutePath());
		mb.open();
	}
}
 
Example 3
Source File: EditorSearchHyperlink.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void open()
{
	try
	{
		final IFileStore store = EFS.getStore(document);
		// Now open an editor to this file (and highlight the occurrence if possible)
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IEditorPart part = IDE.openEditorOnFileStore(page, store);
		// Now select the occurrence if we can
		IFindReplaceTarget target = (IFindReplaceTarget) part.getAdapter(IFindReplaceTarget.class);
		if (target != null && target.canPerformFind())
		{
			target.findAndSelect(0, searchString, true, caseSensitive, wholeWord);
		}
	}
	catch (Exception e)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(), e);
	}
}
 
Example 4
Source File: BibtexEditor.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * open the file document which is refered to in the bibtex entry. The path
 * has to start from the root of the project where the bibtex entry is
 * included.
 */
private void openPdf() {
	IFile res = Utils.getIFilefromDocument(document);
	if (res == null || res.getProject() == null) {
		MessageDialog.openInformation(this.getSite().getShell(), "Bibtex" + document.getKey(), "Root or Resource not found");
		return;
	}
	IFile file = res.getProject().getFile(document.getFile());
	if (file.exists()) {
		IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.getLocation());
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

		try {
			IDE.openEditorOnFileStore(page, fileStore);
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	} else {
		MessageDialog.openInformation(this.getSite().getShell(), "Bibtex" + document.getKey(), "Document not found");
	}
}
 
Example 5
Source File: OpenLogCommand.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	IFileStore fileStore = EFS.getLocalFileSystem().getStore(Platform.getLogFileLocation());
	try {
		IDE.openEditorOnFileStore(page, fileStore);
	} catch (PartInitException e) {
		BonitaStudioLog.error(e);
		try {
			IDE.openInternalEditorOnFileStore(page, fileStore);
		} catch (PartInitException e1) {
			BonitaStudioLog.error(e1);
			BonitaStudioLog.log("Can't open .log file in editor. You should associate .log to a program at OS level.");
		}
	}		
	return null;
}
 
Example 6
Source File: TestJSON.java    From wildwebdeveloper with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFormatEnabled() throws IOException, PartInitException, CoreException {
	File file = File.createTempFile("test", ".json");
	IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	IDE.openEditorOnFileStore(activePage, EFS.getStore(file.toURI()));
	ICommandService service = activePage.getWorkbenchWindow().getService(ICommandService.class);
	Command formatCommand = service.getCommand("org.eclipse.lsp4e.format");
	assertNotNull("Format command not found", formatCommand);
	assertTrue("Format command not defined", formatCommand.isDefined());
	assertTrue("Format command not enabled", formatCommand.isEnabled());
	assertTrue("Format command not handled", formatCommand.isHandled());
}
 
Example 7
Source File: CodeRecommendationResultsController.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onTargetDoubleClicked(CodeRecommendationTarget target) {
	IPath location = target.getFile().getLocation();

	try {
		IDE.openEditorOnFileStore(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
				EFS.getLocalFileSystem().getStore(location));
	} catch (PartInitException e) {
		e.printStackTrace();
		MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error",
				"Unexpected error during opening file \n" + location + "\n" + e);
	}
}
 
Example 8
Source File: CoreEditorUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static IEditorPart openInEditor(IFileStore fileStore) {
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	try {
	    return IDE.openEditorOnFileStore(page, fileStore);
	} catch (PartInitException e) {
	}
	return null;
}
 
Example 9
Source File: AbstractExportDialog.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
@Override
protected void perfomeOK() throws Exception {
    try {
        final ProgressMonitorDialog monitor = new ProgressMonitorDialog(getShell());

        final ExportWithProgressManager manager = getExportWithProgressManager(settings.getExportSetting());

        manager.init(diagram, getBaseDir());

        final ExportManagerRunner runner = new ExportManagerRunner(manager);

        monitor.run(true, true, runner);

        if (runner.getException() != null) {
            throw runner.getException();
        }

        if (openAfterSavedButton != null && openAfterSavedButton.getSelection()) {
            final File openAfterSaved = openAfterSaved();

            final URI uri = openAfterSaved.toURI();

            final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

            if (openWithExternalEditor()) {
                IDE.openEditor(page, uri, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);

            } else {
                final IFileStore fileStore = EFS.getStore(uri);
                IDE.openEditorOnFileStore(page, fileStore);
            }
        }

        // there is a case in another project
        diagram.getEditor().refreshProject();

    } catch (final InterruptedException e) {
        throw new InputException();
    }
}
 
Example 10
Source File: EditorUtils.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Open an editor anywhere on the file system using Eclipse's default editor registered for the given file.
 *
 * @param fileToOpen File to open
 * @note we must be in the UI thread for this method to work.
 * @return Editor opened or created
 */
public static IEditorPart openFile(File fileToOpen, boolean activate) {

    final IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench == null) {
        throw new RuntimeException("workbench cannot be null");
    }

    IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null) {
        throw new RuntimeException(
                "activeWorkbenchWindow cannot be null (we have to be in a ui thread for this to work)");
    }

    IWorkbenchPage wp = activeWorkbenchWindow.getActivePage();

    final IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());

    try {
        if (activate) {
            // open the editor on the file
            return IDE.openEditorOnFileStore(wp, fileStore);
        }

        // Workaround when we don't want to activate (as there's no suitable API
        // in the core for that).
        IEditorInput input = getEditorInput(fileStore);
        String editorId = getEditorId(input, null);

        return wp.openEditor(input, editorId, activate);

    } catch (Exception e) {
        Log.log("Editor failed to open", e);
        return null;
    }
}
 
Example 11
Source File: PyOpenResourceAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void openFiles(PythonpathTreeNode[] pythonPathFilesSelected) {
    for (PythonpathTreeNode n : pythonPathFilesSelected) {
        try {
            if (PythonPathHelper.isValidSourceFile(n.file.getName())) {
                new PyOpenAction().run(new ItemPointer(n.file));
            } else {
                final IFileStore fileStore = EFS.getLocalFileSystem().getStore(n.file.toURI());
                IDE.openEditorOnFileStore(page, fileStore);
            }
        } catch (PartInitException e) {
            Log.log(e);
        }
    }
}
 
Example 12
Source File: GoNavigatorActionProvider.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
	if(isEnabled()) {
		try {
			IDE.openEditorOnFileStore(page, fileStore);
		} catch (PartInitException exception) {
			UIOperationsStatusHandler.handleInternalError("Error Opening File", exception);
		}
	}
}
 
Example 13
Source File: OpenUIDLogCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean execute(ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final Optional<File> logFile = UIDesignerServerManager.getInstance().getLogFile();
    if (logFile.isPresent() && logFile.get().exists()) {
        try {
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(logFile.get().toURI());
            final File localFile = fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR);
            final long fileSize = localFile.length();
            if (fileSize < MAX_FILE_SIZE) {
                IDE.openEditorOnFileStore(page, fileStore);
            } else {
                Program textEditor = Program.findProgram("log");
                if (textEditor == null) {
                    textEditor = Program.findProgram("txt");
                }
                if (textEditor == null || !textEditor.execute(localFile.getAbsolutePath())) {
                    showWarningMessage(localFile);
                }
            }
            return true;
        } catch (final Exception e) {
            BonitaStudioLog.error(e);
            return false;
        }
    }
    MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            Messages.unableTofindLogTitle, Messages.unableTofindLogMessage);
    return false;
}
 
Example 14
Source File: OpenEngineLogCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Boolean execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final File logFile = BOSWebServerManager.getInstance().getBonitaLogFile();
    if (logFile != null && logFile.exists()) {
        IFileStore fileStore;
        try {
            fileStore = EFS.getLocalFileSystem().getStore(logFile.toURI());
            final File localFile = fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR);
            final long fileSize = localFile.length();
            if (fileSize < MAX_FILE_SIZE) {
                IDE.openEditorOnFileStore(page, fileStore);
            } else {
                Program textEditor = Program.findProgram("log");
                if (textEditor == null) {
                    textEditor = Program.findProgram("txt");
                }
                if (textEditor != null) {
                    final boolean success = textEditor.execute(localFile.getAbsolutePath());
                    if (!success) {
                        showWarningMessage(localFile);
                    }
                } else {
                    showWarningMessage(localFile);
                }
            }

            return Boolean.TRUE;
        } catch (final Exception e) {
            BonitaStudioLog.error(e);
            return Boolean.FALSE;
        }
    } else {
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.unableTofindLogTitle, Messages.unableTofindLogMessage);
        return Boolean.FALSE;
    }
}