org.eclipse.ui.IEditorDescriptor Java Examples

The following examples show how to use org.eclipse.ui.IEditorDescriptor. 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: EditorOpener.java    From typescript.java with MIT License 8 votes vote down vote up
public IEditorPart openAndSelect(IWorkbenchPage wbPage, IFile file, int offset, int length, boolean activate) throws PartInitException {
	String editorId= null;
	IEditorDescriptor desc= IDE.getEditorDescriptor(file);
	if (desc == null || !desc.isInternal()) {
		editorId= "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
	} else {
		editorId= desc.getId();
	}

	IEditorPart editor;
	if (NewSearchUI.reuseEditor()) {
		editor= showWithReuse(file, wbPage, editorId, activate);
	} else {
		editor= showWithoutReuse(file, wbPage, editorId, activate);
	}

	if (editor instanceof ITextEditor) {
		ITextEditor textEditor= (ITextEditor) editor;
		textEditor.selectAndReveal(offset, length);
	} else if (editor != null) {
		showWithMarker(editor, file, offset, length);
	}
	return editor;
}
 
Example #2
Source File: TestEditor.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
private void initializeTitle(IEditorInput input) {

		Image oldImage = fTitleImage;
		fTitleImage = null;
		String title = ""; //$NON-NLS-1$

		if (input != null) {
			IEditorRegistry editorRegistry = PlatformUI.getWorkbench()
					.getEditorRegistry();
			IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite()
					.getId());
			ImageDescriptor imageDesc = editorDesc != null ? editorDesc
					.getImageDescriptor() : null;

			fTitleImage = imageDesc != null ? imageDesc.createImage() : null;
			title = input.getName();
		}

		setTitleImage(fTitleImage);
		setPartName(title);

		firePropertyChange(PROP_DIRTY);

		if (oldImage != null && !oldImage.isDisposed())
			oldImage.dispose();
	}
 
Example #3
Source File: Util.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static void resetDefaultEditor(String extension) {
  EditorRegistry editorRegistry = (EditorRegistry) PlatformUI.getWorkbench().getEditorRegistry();
  IFileEditorMapping[] editorMappings = editorRegistry.getFileEditorMappings();

  // Search the file=>editor mappings for the specified extension
  for (IFileEditorMapping editorMapping : editorMappings) {
    if (extension.equals(editorMapping.getExtension())) {
      FileEditorMapping internalMapping = (FileEditorMapping) editorMapping;
      // Only need to do anything if there's an explicit default set
      if (internalMapping.getDeclaredDefaultEditors().length > 0) {
        // Clear any default editor associations for this extension

        List<IEditorDescriptor> list = new ArrayList<IEditorDescriptor>();
        internalMapping.setDefaultEditors(list);

        // Save the updated editor registry to disk
        editorRegistry.saveAssociations();

        // TODO: remove
        GWTPluginLog.logInfo("Reset default editor for extension: "
            + extension);
      }
      break;
    }
  }
}
 
Example #4
Source File: SVNConflictResolver.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private String getEditorId(IFileStore file) {
	IWorkbench workbench = PlatformUI.getWorkbench();
	IEditorRegistry editorRegistry= workbench.getEditorRegistry();
	IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(file.getName(), getContentType(file));

	// check the OS for in-place editor (OLE on Win32)
	if (descriptor == null && editorRegistry.isSystemInPlaceEditorAvailable(file.getName()))
		descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
	
	// check the OS for external editor
	if (descriptor == null && editorRegistry.isSystemExternalEditorAvailable(file.getName()))
		descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
	
	if (descriptor != null)
		return descriptor.getId();
	
	return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
}
 
Example #5
Source File: DiagramPartitioningUtil.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Opens a subdiagram for a given {@link Diagram}
 */
public static IEditorPart openEditor(Diagram diagramToOpen) {
	IFile file = WorkspaceSynchronizer.getFile(diagramToOpen.eResource());
	try {
		IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
		final IWorkbenchPage wbPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		if (diagramToOpen.getElement() instanceof Statechart) {
			return wbPage.openEditor(new FileEditorInput(file), desc.getId());
		} else if (diagramToOpen.getElement() instanceof State) {
			return wbPage.openEditor(new DiagramEditorInput(diagramToOpen), desc.getId());
		}
	} catch (PartInitException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example #6
Source File: EditorUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Open a file in an editor and return the opened editor part.<br>
 * This method will try to open the file in an internal editor, unless there is no editor descriptor assigned to
 * that file type.
 * 
 * @param file
 * @return The {@link IEditorPart} that was created when the file was opened; Return null in case of an error
 */
public static IEditorPart openInEditor(File file)
{
	// NOTE: Moved from PHP's EditorUtils
	if (file == null)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(),
				"Error open a file in the editor", new IllegalArgumentException("file is null")); //$NON-NLS-1$ //$NON-NLS-2$
		return null;
	}
	try
	{
		URI uri = file.toURI();
		IEditorDescriptor desc = getEditorDescriptor(uri);
		String editorId = (desc == null) ? IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID : desc.getId();
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

		return IDE.openEditor(page, uri, editorId, true);
	}
	catch (Exception e)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(), "Error open a file in the editor", e); //$NON-NLS-1$
	}
	return null;
}
 
Example #7
Source File: HtmlBrowserEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	setSite(site);
	setInput(input);
	setPartName(input.getName());
	
	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	FileEditorInput fileInput = (FileEditorInput) input;
	htmlUrl = fileInput.getFile().getLocation().toOSString();
}
 
Example #8
Source File: XLIFFEditor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 启动编辑器。
 * 
 * @param site
 *            the site
 * @param input
 *            the input
 * @throws PartInitException
 *             the part init exception
 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
 *      org.eclipse.ui.IEditorInput)
 */
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("init(IEditorSite site, IEditorInput input)");
	}
	setSite(site);
	setInput(input);
	// 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
	setPartName(input.getName());

	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	getSite().setSelectionProvider(this);
}
 
Example #9
Source File: TestEditor.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
private void initializeTitle(final IEditorInput input) {

        final Image oldImage = fTitleImage;
        fTitleImage = null;
        String title = ""; //$NON-NLS-1$

        if (input != null) {
            final IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
            final IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
            final ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;

            fTitleImage = imageDesc != null ? imageDesc.createImage() : null;
            title = input.getName();
        }

        setTitleImage(fTitleImage);
        setPartName(title);

        firePropertyChange(PROP_DIRTY);

        if (oldImage != null && !oldImage.isDisposed())
            oldImage.dispose();
    }
 
Example #10
Source File: ModulaSearchResultPage.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
protected void showMatch( Match match, int currentOffset
                        , int currentLength, boolean activate 
                        ) throws PartInitException 
{
    if (match instanceof ModulaSymbolMatch) {
        try {
            ModulaSymbolMatch em = (ModulaSymbolMatch)match;
            IFile f = em.getFile();
            IWorkbenchPage page = WorkbenchUtils.getActivePage();
            IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(f.getName());
            IEditorPart ep = page.openEditor(new FileEditorInput(f), desc.getId());
            ITextEditor te = (ITextEditor)ep;
            Control ctr = (Control)te.getAdapter(Control.class);
            ctr.setFocus();
            te.selectAndReveal(em.getOffset(), em.getLength());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example #11
Source File: ClassFileBasedOpenerContributor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean collectSourceFileOpeners(IEditorPart editor, IAcceptor<FileOpener> acceptor) {
	if (!(editor instanceof XtextEditor) && editor.getEditorInput() != null) {
		try {
			IClassFile classFile = Adapters.adapt(editor, IClassFile.class);
			if (classFile == null) {
				return false;
			}
			ITrace trace = traceForTypeRootProvider.getTraceToSource(classFile);
			if (trace == null) {
				return false;
			}
			for (ILocationInResource location : trace.getAllAssociatedLocations()) {
				String name = location.getAbsoluteResourceURI().getURI().lastSegment();
				IEditorDescriptor editorDescriptor = IDE.getEditorDescriptor(name);
				acceptor.accept(createEditorOpener(editor.getEditorInput(), editorDescriptor.getId()));
				return true;
			}
		} catch (PartInitException e) {
			LOG.error(e.getMessage(), e);
		}
	}
	return false;
}
 
Example #12
Source File: HtmlBrowserEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	setSite(site);
	setInput(input);
	setPartName(input.getName());
	
	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	FileEditorInput fileInput = (FileEditorInput) input;
	htmlUrl = fileInput.getFile().getLocation().toOSString();
}
 
Example #13
Source File: XLIFFEditor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 启动编辑器。
 * 
 * @param site
 *            the site
 * @param input
 *            the input
 * @throws PartInitException
 *             the part init exception
 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
 *      org.eclipse.ui.IEditorInput)
 */
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("init(IEditorSite site, IEditorInput input)");
	}
	setSite(site);
	setInput(input);
	// 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
	setPartName(input.getName());

	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	getSite().setSelectionProvider(this);
}
 
Example #14
Source File: PyOpenResourceAction.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void openFiles(PythonpathZipChildTreeNode[] pythonPathFilesSelected) {
    for (PythonpathZipChildTreeNode n : pythonPathFilesSelected) {
        try {
            if (PythonPathHelper.isValidSourceFile(n.zipPath)) {
                new PyOpenAction().run(new ItemPointer(n.zipStructure.file, new Location(), new Location(), null,
                        n.zipPath));
            } else {
                IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
                IEditorDescriptor defaultEditor = editorReg.getDefaultEditor(n.zipPath);
                PydevZipFileStorage storage = new PydevZipFileStorage(n.zipStructure.file, n.zipPath);
                PydevZipFileEditorInput input = new PydevZipFileEditorInput(storage);

                if (defaultEditor != null) {
                    IDE.openEditor(page, input, defaultEditor.getId());
                } else {
                    IDE.openEditor(page, input, EditorsUI.DEFAULT_TEXT_EDITOR_ID);
                }
            }
        } catch (PartInitException e) {
            Log.log(e);
        }
    }
}
 
Example #15
Source File: OriginalEditorSelector.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public IEditorDescriptor findXbaseEditor(IEditorInput editorInput, boolean ignorePreference) {
	IFile file = ResourceUtil.getFile(editorInput);
	if (file == null)
		return null;
	if (!ignorePreference) {
		if (file.exists()) {
			try {
				String favoriteEditor = file.getPersistentProperty(IDE.EDITOR_KEY);
				if (favoriteEditor != null)
					return null;
			} catch (CoreException e) {
				logger.debug(e.getMessage(), e);
			}
		}
	}
	// TODO stay in same editor if local navigation
	Decision decision = decisions.decideAccordingToCaller();
	if (decision == Decision.FORCE_JAVA) {
		return null;
	}
	IEclipseTrace traceToSource = traceInformation.getTraceToSource(file);
	return getXtextEditor(traceToSource);
}
 
Example #16
Source File: N4JSApplicationWorkbenchWindowAdvisor.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void updateDefaultEditorMappingIfAbsent() {
	final EditorRegistry registry = (EditorRegistry) WorkbenchPlugin.getDefault().getEditorRegistry();
	for (final IFileEditorMapping editorMapping : registry.getFileEditorMappings()) {
		final IEditorDescriptor defaultEditor = editorMapping.getDefaultEditor();
		if (null == defaultEditor) {

			final String extension = editorMapping.getExtension();
			LOGGER.info("No default editor is associated with files with extension: '." + extension + "'.");
			final IEditorDescriptor defaultTextEditor = registry.findEditor(DEFAULT_TEXT_EDITOR_ID);
			if (null != defaultTextEditor) {
				((FileEditorMapping) editorMapping).setDefaultEditor(defaultTextEditor);
				String editorName = defaultTextEditor.getLabel();
				if (null == editorName) {
					editorName = defaultTextEditor.getId();
				}
				if (null != editorName) {
					LOGGER.info("Associated files with extension " + extension + " with '" + editorName + "'.");
				}
			}
		}
	}
	registry.saveAssociations();
	PrefUtil.savePrefs();
}
 
Example #17
Source File: OpenJavaSourceAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private String getEditorId( IFileStore file )
{
	IWorkbench workbench = window.getWorkbench( );
	IEditorRegistry editorRegistry = workbench.getEditorRegistry( );
	IEditorDescriptor descriptor = editorRegistry.getDefaultEditor( file.getName( ),
			getContentType( file ) );

	// check the OS for in-place editor (OLE on Win32)
	if ( descriptor == null
			&& editorRegistry.isSystemInPlaceEditorAvailable( file.getName( ) ) )
	{
		descriptor = editorRegistry.findEditor( IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID );
	}

	// check the OS for external editor
	if ( descriptor == null
			&& editorRegistry.isSystemExternalEditorAvailable( file.getName( ) ) )
	{
		descriptor = editorRegistry.findEditor( IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID );
	}

	return ( descriptor == null ) ? "" : descriptor.getId( ); //$NON-NLS-1$
}
 
Example #18
Source File: EditorOpener.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public IEditorPart openAndSelect(IWorkbenchPage wbPage, IFile file, int offset, int length, boolean activate)
        throws PartInitException {
    String editorId = null;
    IEditorDescriptor desc = IDE.getEditorDescriptor(file);
    if (desc == null || !desc.isInternal()) {
        editorId = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
    } else {
        editorId = desc.getId();
    }

    IEditorPart editor;
    if (NewSearchUI.reuseEditor()) {
        editor = showWithReuse(file, wbPage, editorId, activate);
    } else {
        editor = showWithoutReuse(file, wbPage, editorId, activate);
    }

    if (editor instanceof ITextEditor) {
        ITextEditor textEditor = (ITextEditor) editor;
        textEditor.selectAndReveal(offset, length);
    } else if (editor != null) {
        showWithMarker(editor, file, offset, length);
    }
    return editor;
}
 
Example #19
Source File: OpenGeneratedSourceInEditorHandler.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void tryOpenFileInEditor(final IFile file, final IFile generatedFile) {
	final IEditorDescriptor desc = getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
	if (null != desc) {
		final IWorkbenchPage page = getWorkbench().getActiveWorkbenchWindow().getActivePage();
		try {
			page.openEditor(new FileEditorInput(generatedFile), desc.getId());
		} catch (final PartInitException e) {
			throw new RuntimeException("Error while trying to open generated JS file for " + file, e);
		}
	}
}
 
Example #20
Source File: XLFEditor.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("init(IEditorSite site, IEditorInput input)");
	}
	setSite(site);
	setInput(input);

	// 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
	setPartName(input.getName());

	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	getSite().setSelectionProvider(this);

	cursorIbeam = new Cursor(null, SWT.CURSOR_IBEAM);
	cursorArrow = new Cursor(null, SWT.CURSOR_ARROW);

	hookListener();
}
 
Example #21
Source File: OpenFileAction.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new action that will open instances of the specified editor on the then-selected file resources.
 *
 * @param page
 *            the workbench page in which to open the editor
 * @param descriptor
 *            the editor descriptor, or <code>null</code> if unspecified
 */
public OpenFileAction(final IWorkbenchPage page, final IEditorDescriptor descriptor) {
	super(page);
	setText(descriptor == null ? IDEWorkbenchMessages.OpenFileAction_text : descriptor.getLabel());
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IIDEHelpContextIds.OPEN_FILE_ACTION);
	setToolTipText(IDEWorkbenchMessages.OpenFileAction_toolTip);
	setId(ID);
	this.editorDescriptor = descriptor;
}
 
Example #22
Source File: ViewLogCommandHandler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param filePath
 *            TODO: we should really make this into a utility function, and have the Ruble::Editor.open method use
 *            it. But I am giving up for now because Eclipse plugin dependencies drive me crazy!
 */
private void openEditorForFile(String filePath)
{
	File file = new File(filePath);
	// Process an existing file.
	if (file.exists() && file.isFile())
	{
		Path path = new Path(filePath);
		IFile fileForLocation = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDescriptor = null;
		if (fileForLocation == null)
		{
			IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(filePath);
			editorDescriptor = editorRegistry.getDefaultEditor(filePath, contentType);
		}
		else
		{
			editorDescriptor = editorRegistry.getDefaultEditor(filePath);
		}
		String editorId = (editorDescriptor == null) ? "com.aptana.editor.text" : editorDescriptor.getId(); //$NON-NLS-1$
		try
		{
			IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file.toURI(),
					editorId, true);
		}
		catch (PartInitException e)
		{
			IdeLog.logError(UIPlugin.getDefault(), e);
		}
	}
}
 
Example #23
Source File: URIHyperlink.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected IEditorDescriptor getEditorDescriptor()
{
	IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
	if (uri.getPath() == null || uri.getPath().equals("/") || uri.getPath().trim().equals("")) //$NON-NLS-1$ //$NON-NLS-2$
	{
		return null;
	}
	IPath path = new Path(uri.getPath());
	return editorReg.getDefaultEditor(path.lastSegment());
}
 
Example #24
Source File: EditorUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the editor descriptor for the given URI. The editor descriptor is computed by the last segment of the URI
 * (the file name).
 * 
 * @param uri
 *            A file URI
 * @return the descriptor of the default editor, or null if not found
 */
public static IEditorDescriptor getEditorDescriptor(URI uri)
{
	// NOTE: Moved from PHP's EditorUtils
	String uriPath = uri.getPath();
	if (StringUtil.isEmpty(uriPath) || uriPath.equals("/")) //$NON-NLS-1$
	{
		return null;
	}
	IPath path = new Path(uriPath);
	return PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(path.lastSegment());
}
 
Example #25
Source File: EditorOpener.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private String getEditorID(IFile file) throws PartInitException {
    IEditorDescriptor desc = IDE.getEditorDescriptor(file);
    if (desc == null) {
        return PydevPlugin.getDefault().getWorkbench().getEditorRegistry()
                .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID).getId();
    }
    return desc.getId();
}
 
Example #26
Source File: EditorInputTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void dragStart(DragSourceEvent event) {
	fEditorInputDatas= new ArrayList<EditorInputData>();

	ISelection selection= fProvider.getSelection();
	if (selection instanceof IStructuredSelection) {
		IStructuredSelection structuredSelection= (IStructuredSelection) selection;
		for (Iterator<?> iter= structuredSelection.iterator(); iter.hasNext();) {
			Object element= iter.next();
			IEditorInput editorInput= EditorUtility.getEditorInput(element);
			if (editorInput != null && editorInput.getPersistable() != null) {
				try {
					String editorId= EditorUtility.getEditorID(editorInput);
					// see org.eclipse.ui.internal.ide.EditorAreaDropAdapter.openNonExternalEditor(..):
					IEditorRegistry editorReg= PlatformUI.getWorkbench().getEditorRegistry();
					IEditorDescriptor editorDesc= editorReg.findEditor(editorId);
					if (editorDesc != null && !editorDesc.isOpenExternal()) {
						fEditorInputDatas.add(EditorInputTransfer.createEditorInputData(editorId, editorInput));
					}
				} catch (PartInitException e) {
					JavaPlugin.log(e);
				}
			}
		}
	}

	event.doit= fEditorInputDatas.size() > 0;
}
 
Example #27
Source File: XLFEditor.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("init(IEditorSite site, IEditorInput input)");
	}
	setSite(site);
	setInput(input);

	// 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
	setPartName(input.getName());

	Image oldTitleImage = titleImage;
	if (input != null) {
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
		ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
		titleImage = imageDesc != null ? imageDesc.createImage() : null;
	}

	setTitleImage(titleImage);
	if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
		oldTitleImage.dispose();
	}

	getSite().setSelectionProvider(this);

	cursorIbeam = new Cursor(null, SWT.CURSOR_IBEAM);
	cursorArrow = new Cursor(null, SWT.CURSOR_ARROW);

	hookListener();
}
 
Example #28
Source File: OpenFileAction.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private IEditorDescriptor getEditorDescriptor( IEditorInput input,
		boolean determineContentType )
{
	if ( input == null )
	{
		throw new IllegalArgumentException( );
	}
	IContentType contentType = Platform.getContentTypeManager( )
			.findContentTypeFor( input.getName( ) );
	IEditorRegistry editorReg = PlatformUI.getWorkbench( )
			.getEditorRegistry( );
	return editorReg.getDefaultEditor( input.getName( ), contentType );
}
 
Example #29
Source File: OpenFileWithValidAction.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new action that will open instances of the specified editor on the then-selected file resources.
 * @param page
 *            the workbench page in which to open the editor
 * @param descriptor
 *            the editor descriptor, or <code>null</code> if unspecified
 */
public OpenFileWithValidAction(IWorkbenchPage page, IEditorDescriptor descriptor) {
	super(page);
	setText(descriptor == null ? IDEWorkbenchMessages.OpenFileAction_text : descriptor.getLabel());
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IIDEHelpContextIds.OPEN_FILE_ACTION);
	setToolTipText(IDEWorkbenchMessages.OpenFileAction_toolTip);
	setId(ID);
	this.editorDescriptor = descriptor;
}
 
Example #30
Source File: OpenFileWithValidAction.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new action that will open instances of the specified editor on the then-selected file resources.
 * @param page
 *            the workbench page in which to open the editor
 * @param descriptor
 *            the editor descriptor, or <code>null</code> if unspecified
 */
public OpenFileWithValidAction(IWorkbenchPage page, IEditorDescriptor descriptor) {
	super(page);
	setText(descriptor == null ? IDEWorkbenchMessages.OpenFileAction_text : descriptor.getLabel());
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IIDEHelpContextIds.OPEN_FILE_ACTION);
	setToolTipText(IDEWorkbenchMessages.OpenFileAction_toolTip);
	setId(ID);
	this.editorDescriptor = descriptor;
}