org.eclipse.ui.ide.IDE#openEditorOnFileStore ( )源码实例Demo

下面列出了org.eclipse.ui.ide.IDE#openEditorOnFileStore ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * 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());
        }
    }
}
 
源代码2 项目: JReFrameworker   文件: WorkspaceUtils.java
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();
	}
}
 
源代码3 项目: APICloud-Studio   文件: EditorSearchHyperlink.java
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);
	}
}
 
源代码4 项目: slr-toolkit   文件: BibtexEditor.java
/**
 * 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");
	}
}
 
源代码5 项目: bonita-studio   文件: OpenLogCommand.java
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;
}
 
源代码6 项目: wildwebdeveloper   文件: TestJSON.java
@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());
}
 
@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);
	}
}
 
源代码8 项目: xds-ide   文件: CoreEditorUtils.java
public static IEditorPart openInEditor(IFileStore fileStore) {
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	try {
	    return IDE.openEditorOnFileStore(page, fileStore);
	} catch (PartInitException e) {
	}
	return null;
}
 
源代码9 项目: ermasterr   文件: AbstractExportDialog.java
@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();
    }
}
 
源代码10 项目: Pydev   文件: EditorUtils.java
/**
 * 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;
    }
}
 
源代码11 项目: Pydev   文件: PyOpenResourceAction.java
@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);
        }
    }
}
 
源代码12 项目: goclipse   文件: GoNavigatorActionProvider.java
@Override
public void run() {
	if(isEnabled()) {
		try {
			IDE.openEditorOnFileStore(page, fileStore);
		} catch (PartInitException exception) {
			UIOperationsStatusHandler.handleInternalError("Error Opening File", exception);
		}
	}
}
 
源代码13 项目: bonita-studio   文件: OpenUIDLogCommand.java
@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;
}
 
源代码14 项目: bonita-studio   文件: OpenEngineLogCommand.java
@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;
    }
}