Search in sources :

Example 26 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project webtools.sourceediting by eclipse.

the class WorkspaceFileHyperlink method getEditorLabel.

private String getEditorLabel() throws CoreException {
    final IContentDescription description = fFile.getContentDescription();
    final IEditorDescriptor defaultEditor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(fFile.getName(), description != null ? description.getContentType() : null);
    return defaultEditor != null ? defaultEditor.getLabel() : null;
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Example 27 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project webtools.sourceediting by eclipse.

the class NewXSLFileWizard method openEditor.

private void openEditor(final IFile file, final int cursorOffset) {
    // Open editor on new file.
    String editorId = null;
    try {
        IEditorDescriptor editor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getFullPath().toString(), file.getContentDescription().getContentType());
        if (editor != null) {
            editorId = editor.getId();
        }
    } catch (CoreException e1) {
        // editor id could not be retrieved, so we can not open editor
        return;
    }
    final String finalEditorId = editorId;
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            try {
                if (dw != null) {
                    IWorkbenchPage page = dw.getActivePage();
                    if (page != null) {
                        IEditorPart editor = page.openEditor(new FileEditorInput(file), finalEditorId, true);
                        ITextEditor textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
                        if (textEditor != null)
                            textEditor.selectAndReveal(cursorOffset, 0);
                        editor.setFocus();
                    }
                }
            } catch (PartInitException e) {
                // editor can not open for some reason
                XSLUIPlugin.log(e);
            }
        }
    });
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) CoreException(org.eclipse.core.runtime.CoreException) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 28 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project webtools.sourceediting by eclipse.

the class NewXMLWizard method openEditor.

public void openEditor(IFile file) {
    long length = 0;
    IPath location = file.getLocation();
    if (location != null) {
        File localFile = location.toFile();
        length = localFile.length();
    }
    if (length < XML_EDITOR_FILE_SIZE_LIMIT) {
        // Open editor on new file.
        String editorId = null;
        try {
            IEditorDescriptor editor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getLocation().toOSString(), file.getContentDescription().getContentType());
            if (editor != null) {
                editorId = editor.getId();
            }
        } catch (CoreException e1) {
            // editor id could not be retrieved, so we can not open editor
            return;
        }
        IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        try {
            if (dw != null) {
                IWorkbenchPage page = dw.getActivePage();
                if (page != null) {
                    page.openEditor(new FileEditorInput(file), editorId, true);
                }
            }
        } catch (PartInitException e) {
            // editor can not open for some reason
            return;
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 29 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project azure-tools-for-java by Microsoft.

the class UIHelperImpl method openWebAppPropertyView.

@Override
public void openWebAppPropertyView(WebAppNode node) {
    if (Utils.isEmptyString(node.getId())) {
        return;
    }
    AzureTaskManager.getInstance().runLater(() -> {
        IWorkbench workbench = PlatformUI.getWorkbench();
        WebAppPropertyEditorInput input = new WebAppPropertyEditorInput(node.getSubscriptionId(), node.getId(), node.getName());
        IEditorDescriptor descriptor = workbench.getEditorRegistry().findEditor(WebAppPropertyEditor.ID);
        openEditor(EditorType.WEBAPP_EXPLORER, input, descriptor);
    });
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) WebAppPropertyEditorInput(com.microsoft.azuretools.azureexplorer.editors.webapp.WebAppPropertyEditorInput) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor)

Example 30 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project azure-tools-for-java by Microsoft.

the class UIHelperImpl method openRedisExplorer.

@Override
public void openRedisExplorer(@NotNull RedisCacheNode node) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    RedisExplorerEditorInput input = new RedisExplorerEditorInput(node.getSubscriptionId(), node.getResourceId(), node.getName());
    IEditorDescriptor descriptor = workbench.getEditorRegistry().findEditor(RedisExplorerEditor.ID);
    openEditor(EditorType.REDIS_EXPLORER, input, descriptor);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) RedisExplorerEditorInput(com.microsoft.azuretools.azureexplorer.editors.rediscache.RedisExplorerEditorInput)

Aggregations

IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)74 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)34 PartInitException (org.eclipse.ui.PartInitException)34 FileEditorInput (org.eclipse.ui.part.FileEditorInput)27 IWorkbench (org.eclipse.ui.IWorkbench)25 IEditorPart (org.eclipse.ui.IEditorPart)21 IFile (org.eclipse.core.resources.IFile)19 IEditorRegistry (org.eclipse.ui.IEditorRegistry)18 CoreException (org.eclipse.core.runtime.CoreException)10 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)10 IEditorInput (org.eclipse.ui.IEditorInput)8 IContentType (org.eclipse.core.runtime.content.IContentType)7 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)7 AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)7 Image (org.eclipse.swt.graphics.Image)5 InputStream (java.io.InputStream)4 BadLocationException (org.eclipse.jface.text.BadLocationException)4 Path (org.eclipse.core.runtime.Path)3 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)3 JavaModelException (org.eclipse.jdt.core.JavaModelException)3