Java Code Examples for org.eclipse.ui.IEditorInput

The following examples show how to use org.eclipse.ui.IEditorInput. These examples are extracted from open source projects. 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 Project: birt   Source File: IDEFileReportProvider.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public IPath getInputPath( IEditorInput input )
{
	if ( input instanceof IURIEditorInput )
	{
		//return new Path( ( (IURIEditorInput) input ).getURI( ).getPath( ) );
		URI uri = ( (IURIEditorInput) input ).getURI( );
		if(uri == null && input instanceof IFileEditorInput)
			return ((IFileEditorInput)input).getFile( ).getFullPath( );
		IPath localPath = URIUtil.toPath( uri );
		String host = uri.getHost( );
		if ( host != null && localPath == null )
		{
			return new Path( host + uri.getPath( ) ).makeUNC( true );
		}
		return localPath;
	}
	if ( input instanceof IFileEditorInput )
	{
		return ( (IFileEditorInput) input ).getFile( ).getLocation( );
	}
	return null;
}
 
Example 2
@Override
public IStructuredSelection findSelection(IEditorInput anInput) {
    IDiagramDocument document = ProcessDiagramEditorPlugin.getInstance().getDocumentProvider()
            .getDiagramDocument(anInput);
    if (document == null) {
        return super.findSelection(anInput);
    }
    Diagram diagram = document.getDiagram();
    if (diagram == null || diagram.eResource() == null) {
        return StructuredSelection.EMPTY;
    }
    IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
    if (file != null) {
        return new StructuredSelection(file);
    }
    return StructuredSelection.EMPTY;
}
 
Example 3
Source Project: tmxeditor8   Source File: XLIFFEditor.java    License: 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 4
Source Project: wildwebdeveloper   Source File: SelectionUtils.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private static IFile getSelectedIFile() {
	try {
		ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
		if (selection instanceof IStructuredSelection) {
			return Adapters.adapt(((IStructuredSelection)selection).getFirstElement(), IFile.class);
		}
	} catch (Exception e) {
		Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
	}
	IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
	if (editor != null) {
		IEditorInput input = editor.getEditorInput();
		if (input instanceof IFileEditorInput) {
			return ((IFileEditorInput)input).getFile();
		}
	}
	return null;
}
 
Example 5
Source Project: xds-ide   Source File: CoreEditorUtils.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
    * Returns File underlying this editor input. 
    * 
    * This method should be modified, whenever new editor input is supported 
    * for some editor requiring access to File.
    * 
    * @param input the editor input to operate on.
    * 
    * @return file underlying given editor input.
    */    
   public static File editorInputToFile(IEditorInput input) {
	if (input == null) 
	    return null;
	
       if (input instanceof IFileEditorInput) {
       	IFile file = editorInputToIFile(input);
           if (file != null) {
               return ResourceUtils.getAbsoluteFile(file);
           }
       }
       else if (input instanceof IURIEditorInput) {
           IURIEditorInput uriEditorInput = (IURIEditorInput) input;
           return new File(uriEditorInput.getURI());
       }
       else if (input instanceof CommonSourceNotFoundEditorInput || input instanceof CompareEditorInput || input instanceof IStorageEditorInput) {
       	// do nothing
	}
       else{
       	LogHelper.logError("Unknown editor input");
       }
       
       return null;
}
 
Example 6
Source Project: Pydev   Source File: PydevPackageExplorer.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the element contained in the EditorInput
 */
Object getElementOfInput(IEditorInput input) {
    if (input instanceof IFileEditorInput) {
        return ((IFileEditorInput) input).getFile();
    }
    if (input instanceof IURIEditorInput) {
        IURIEditorInput iuriEditorInput = (IURIEditorInput) input;
        URI uri = iuriEditorInput.getURI();
        return new File(uri);

    }
    if (input instanceof PydevZipFileEditorInput) {
        PydevZipFileEditorInput pydevZipFileEditorInput = (PydevZipFileEditorInput) input;
        try {
            IStorage storage = pydevZipFileEditorInput.getStorage();
            if (storage instanceof PydevZipFileStorage) {
                PydevZipFileStorage pydevZipFileStorage = (PydevZipFileStorage) storage;
                return pydevZipFileStorage;
            }
        } catch (CoreException e) {
            Log.log(e);
        }

    }
    return null;
}
 
Example 7
@Override
public Object execute( ExecutionEvent event ) {
  IEditorInput editorInput = HandlerUtil.getActiveEditorInput( event );
  IFile resource = ResourceUtil.getFile( editorInput );
  if( resource != null ) {
    if( resource.isAccessible() ) {
      deleteResource( HandlerUtil.getActiveWorkbenchWindow( event ), resource );
    }
  } else {
    File file = getFile( editorInput );
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow( event );
    if( file != null && prompter.confirmDelete( workbenchWindow, file )) {
      deleteFile( workbenchWindow, file );
    }
  }
  return null;
}
 
Example 8
@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 9
private void closeRelatedEditorIfOpened(final ICompilationUnit compilationUnit) throws PartInitException {
    Optional<IWorkbenchPage> activePage = Optional.ofNullable(PlatformUI.getWorkbench().getActiveWorkbenchWindow())
            .map(IWorkbenchWindow::getActivePage);
    if (activePage.isPresent()) {
        if (editorPart != null) {
            if (PlatformUI.isWorkbenchRunning()) {
                activePage.get().closeEditor(editorPart, false);
            }
        } else {
            if (PlatformUI.isWorkbenchRunning()) {
                for (final IEditorReference editorReference : activePage.get().getEditorReferences()) {
                    final IEditorInput editorInput = editorReference.getEditorInput();
                    if (compilationUnit.getResource()
                            .equals(EditorUtil.retrieveResourceFromEditorInput(editorInput))) {
                        activePage.get().closeEditors(new IEditorReference[] { editorReference }, false);
                        break;
                    }
                }
            }
        }
    }
}
 
Example 10
Source Project: Pydev   Source File: PyEditTitle.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private boolean isDjangoHandledModule(String djangoModulesHandling, IEditorInput input, String lastSegment) {
    boolean handled = false;
    if (djangoModulesHandling == PyTitlePreferencesPage.TITLE_EDITOR_DJANGO_MODULES_SHOW_PARENT_AND_DECORATE
            || djangoModulesHandling == PyTitlePreferencesPage.TITLE_EDITOR_DJANGO_MODULES_DECORATE) {

        if (input instanceof IFileEditorInput) {
            IFileEditorInput iFileEditorInput = (IFileEditorInput) input;
            IFile file = iFileEditorInput.getFile();
            IProject project = file.getProject();
            try {
                if (project.hasNature(PythonNature.DJANGO_NATURE_ID)) {
                    if (PyTitlePreferencesPage.isDjangoModuleToDecorate(lastSegment)) {
                        //remove the module name.
                        handled = true;
                    }
                }
            } catch (CoreException e) {
                Log.log(e);
            }
        }
    }
    return handled;
}
 
Example 11
private static IEditorInput getEditorInput(IJavaElement element) {
	while (element != null) {
		if (element instanceof ICompilationUnit) {
			ICompilationUnit unit= ((ICompilationUnit) element).getPrimary();
				IResource resource= unit.getResource();
				if (resource instanceof IFile)
					return new FileEditorInput((IFile) resource);
		}

		if (element instanceof IClassFile)
			return new InternalClassFileEditorInput((IClassFile) element);

		element= element.getParent();
	}

	return null;
}
 
Example 12
Source Project: xtext-eclipse   Source File: DefaultMergeViewer.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected void configureSourceViewer(SourceViewer sourceViewer) {
	IEditorInput editorInput = getEditorInput(sourceViewer);
	SourceViewerConfiguration sourceViewerConfiguration = createSourceViewerConfiguration(sourceViewer, editorInput);
	sourceViewer.unconfigure();
	sourceViewer.configure(sourceViewerConfiguration);
	IXtextDocument xtextDocument = xtextDocumentUtil.getXtextDocument(sourceViewer);
	if (xtextDocument != null) {
		if (!xtextDocument.readOnly(TEST_EXISTING_XTEXT_RESOURCE)) {
			String[] configuredContentTypes = sourceViewerConfiguration.getConfiguredContentTypes(sourceViewer);
			for (String contentType : configuredContentTypes) {
				sourceViewer.removeTextHovers(contentType);
			}
			sourceViewer.setHyperlinkDetectors(null, sourceViewerConfiguration.getHyperlinkStateMask(sourceViewer));
		}
	}
}
 
Example 13
@Override
public IEditorPart open(final URI uri, final EReference crossReference, final int indexInList, final boolean select) {
	Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator();
	if (storages != null && storages.hasNext()) {
		try {
			IStorage storage = storages.next().getFirst();
			IEditorInput editorInput = EditorUtils.createEditorInput(storage);
			IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
			final IEditorPart editor = IDE.openEditor(activePage, editorInput, getEditorId());
			selectAndReveal(editor, uri, crossReference, indexInList, select);
			return EditorUtils.getXtextEditor(editor);
		} catch (WrappedException e) {
			logger.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause());
		} catch (PartInitException partInitException) {
			logger.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException);
		}
	}
	return null;
}
 
Example 14
Source Project: tlaplus   Source File: TLAHyperlinkDetector.java    License: MIT License 6 votes vote down vote up
private int[] getDocumentAndRegion(SyntaxTreeNode csNode, IDocumentProvider documentProvider, IEditorInput editorInput)
		throws CoreException {
	IDocument document;
	// connect to the resource
	try {
		documentProvider.connect(editorInput);
		document = documentProvider.getDocument(editorInput);
	} finally {
		/*
		 * Once the document has been retrieved, the document provider is not needed.
		 * Always disconnect it to avoid a memory leak.
		 * 
		 * Keeping it connected only seems to provide synchronization of the document
		 * with file changes. That is not necessary in this context.
		 */
		documentProvider.disconnect(editorInput);
	}

	return getRegion(csNode, document);
}
 
Example 15
Source Project: scava   Source File: PartEventListener.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private void subscribeDocumentEventListener(IWorkbenchPartReference partRef) {
	IWorkbenchPart part = partRef.getPart(false);
	if (part instanceof IEditorPart) {
		IEditorPart editor = (IEditorPart) part;
		IEditorInput input = editor.getEditorInput();

		if (editor instanceof ITextEditor && input instanceof FileEditorInput) {
			ITextEditor textEditor = (ITextEditor) editor;

			// EventManager.setEditor(textEditor);

			saveListener(textEditor);

			IDocument document = textEditor.getDocumentProvider().getDocument(input);

			DocumentEventListener documentListener = new DocumentEventListener(textEditor.getTitle());
			document.addDocumentListener(documentListener);
		}
	}
}
 
Example 16
Source Project: doclipser   Source File: DockerRunLaunchShortcut.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void launch(IEditorPart editor, String mode) {
    IEditorInput input = editor.getEditorInput();
    IFile dockerfile = (IFile) input.getAdapter(IFile.class);
    IPath dockerfilePath = null;
    if (dockerfile != null) {
        dockerfilePath = dockerfile.getLocation().removeLastSegments(1);
    }
    if (dockerfilePath == null) {
        ILocationProvider locationProvider = (ILocationProvider) input
                .getAdapter(ILocationProvider.class);
        if (locationProvider != null) {
            dockerfilePath = locationProvider.getPath(input);
        }
    }
    if (dockerfilePath != null) {
        launch(dockerfile, dockerfilePath);
    }
}
 
Example 17
Source Project: Pydev   Source File: PyDebugModelPresentation.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns editor to be displayed
 */
@Override
public IEditorInput getEditorInput(Object element) {
    if (element instanceof PyBreakpoint) {
        String file = ((PyBreakpoint) element).getFile();
        if (file != null) {
            return EditorInputFactory.create(new File(file), false);

            //We should not open the editor here, just create the input... the debug framework opens it later on.
            //IPath path = new Path(file);
            //IEditorPart part = PyOpenEditor.doOpenEditor(path);
            //return part.getEditorInput();
        }
    }
    return null;
}
 
Example 18
/**
 * Returns the editors to save before performing global Java-related
 * operations.
 *
 * @param saveUnknownEditors <code>true</code> iff editors with unknown buffer management should also be saved
 * @return the editors to save
 * @since 3.3
 */
public static IEditorPart[] getDirtyEditorsToSave(boolean saveUnknownEditors) {
	Set<IEditorInput> inputs= new HashSet<IEditorInput>();
	List<IEditorPart> result= new ArrayList<IEditorPart>(0);
	IWorkbench workbench= PlatformUI.getWorkbench();
	IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
	for (int i= 0; i < windows.length; i++) {
		IWorkbenchPage[] pages= windows[i].getPages();
		for (int x= 0; x < pages.length; x++) {
			IEditorPart[] editors= pages[x].getDirtyEditors();
			for (int z= 0; z < editors.length; z++) {
				IEditorPart ep= editors[z];
				IEditorInput input= ep.getEditorInput();
				if (!mustSaveDirtyEditor(ep, input, saveUnknownEditors))
					continue;

				if (inputs.add(input))
					result.add(ep);
			}
		}
	}
	return result.toArray(new IEditorPart[result.size()]);
}
 
Example 19
Source Project: texlipse   Source File: SpellUncheckAction.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
    * Clear the spelling error markers.
    * @param action the action
 */
public void run(IAction action) {
       
       if (targetEditor == null) {
           return;
       }
       if (!(targetEditor instanceof ITextEditor)) {
           return;
       }
       
       ITextEditor textEditor = (ITextEditor) targetEditor;
       IEditorInput input = textEditor.getEditorInput();
       
       if (input instanceof FileEditorInput) {
           SpellChecker.clearMarkers(((FileEditorInput)input).getFile());
       }
}
 
Example 20
private IJavaProject getProject() {
	ITextEditor editor= getEditor();
	if (editor == null)
		return null;

	IJavaElement element= null;
	IEditorInput input= editor.getEditorInput();
	IDocumentProvider provider= editor.getDocumentProvider();
	if (provider instanceof ICompilationUnitDocumentProvider) {
		ICompilationUnitDocumentProvider cudp= (ICompilationUnitDocumentProvider) provider;
		element= cudp.getWorkingCopy(input);
	} else if (input instanceof IClassFileEditorInput) {
		IClassFileEditorInput cfei= (IClassFileEditorInput) input;
		element= cfei.getClassFile();
	}

	if (element == null)
		return null;

	return element.getJavaProject();
}
 
Example 21
protected IFile getFile()
{
	AbstractThemeableEditor editor = fEditor;
	if (editor != null)
	{
		IEditorInput editorInput = editor.getEditorInput();

		if (editorInput instanceof IFileEditorInput)
		{
			IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
			return fileEditorInput.getFile();
		}
	}

	return null;
}
 
Example 22
Source Project: birt   Source File: IDEMultiPageReportEditor.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected void setInput( IEditorInput input )
{

	// The workspace never changes for an editor. So, removing and re-adding
	// the
	// resourceListener is not necessary. But it is being done here for the
	// sake
	// of proper implementation. Plus, the resourceListener needs to be
	// added
	// to the workspace the first time around.
	if ( isWorkspaceResource )
	{
		getFile( getEditorInput( ) ).getWorkspace( )
				.removeResourceChangeListener( resourceListener );
	}

	isWorkspaceResource = input instanceof IFileEditorInput;

	super.setInput( input );

	if ( isWorkspaceResource )
	{
		getFile( getEditorInput( ) ).getWorkspace( )
				.addResourceChangeListener( resourceListener );
	}
}
 
Example 23
Source Project: birt   Source File: SaveReportAsWizard.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public SaveReportAsWizard( ModuleHandle model,
		IEditorInput orginalFile )
{
	setWindowTitle( SaveAsWizardWindowTitle );
	this.model = model;
	this.orginalFile = orginalFile;
}
 
Example 24
Source Project: Pydev   Source File: EditorUtils.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private static IEditorInput getEditorInput(IFileStore fileStore) {
    IFile workspaceFile = getWorkspaceFile(fileStore);
    if (workspaceFile != null) {
        return new FileEditorInput(workspaceFile);
    }
    return new FileStoreEditorInput(fileStore);
}
 
Example 25
Source Project: Pydev   Source File: BaseEditor.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the project for the file that's being edited (or null if not available)
 */
public IProject getProject() {
    IEditorInput editorInput = this.getEditorInput();
    if (editorInput instanceof IAdaptable) {
        IAdaptable adaptable = editorInput;
        IFile file = adaptable.getAdapter(IFile.class);
        if (file != null) {
            return file.getProject();
        }
        IResource resource = adaptable.getAdapter(IResource.class);
        if (resource != null) {
            return resource.getProject();
        }
        if (editorInput instanceof IStorageEditorInput) {
            IStorageEditorInput iStorageEditorInput = (IStorageEditorInput) editorInput;
            try {
                IStorage storage = iStorageEditorInput.getStorage();
                IPath fullPath = storage.getFullPath();
                if (fullPath != null) {
                    IWorkspace ws = ResourcesPlugin.getWorkspace();
                    for (String s : fullPath.segments()) {
                        IProject p = ws.getRoot().getProject(s);
                        if (p.exists()) {
                            return p;
                        }
                    }
                }
            } catch (Exception e) {
                Log.log(e);
            }

        }
    }
    return null;
}
 
Example 26
@Override
public void open(IWorkbenchPage page) {
	try {
		IEditorInput input = EditorUtils.createEditorInput(storage);
		IEditorDescriptor editorDescriptor = IDE.getEditorDescriptor(storage.getName());
		IEditorPart opened = IDE.openEditor(page, input, editorDescriptor.getId());
		if (region != null && opened instanceof ITextEditor) {
			ITextEditor openedTextEditor = (ITextEditor) opened;
			openedTextEditor.selectAndReveal(region.getOffset(), region.getLength());
		}
	} catch (PartInitException e) {
		LOG.error(e.getMessage(), e);
	}
}
 
Example 27
Source Project: dsl-devkit   Source File: AbstractXtextUiTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens an {@link IEditorPart} for a provided {@link org.eclipse.emf.common.util.URI}.
 *
 * @param uri
 *          {@link org.eclipse.emf.common.util.URI} to open editor for
 * @param activate
 *          true if focus is to be set to the opened editor
 * @return {@link IEditorPart} created
 */
private IEditorPart openEditor(final org.eclipse.emf.common.util.URI uri, final boolean activate) {
  UiAssert.isNotUiThread();
  final IEditorPart editorPart = UIThreadRunnable.syncExec(getBot().getDisplay(), new Result<IEditorPart>() {
    @Override
    public IEditorPart run() {
      IEditorPart editor = getXtextTestUtil().get(GlobalURIEditorOpener.class).open(uri, activate);
      editor.setFocus();
      return editor;
    }
  });

  waitForEditorJobs(editorPart);

  getBot().waitUntil(new DefaultCondition() {
    @Override
    public boolean test() {
      if (editorPart.getEditorSite() != null && editorPart.getEditorInput() != null) {
        IEditorInput input = editorPart.getEditorInput();
        if (input instanceof IFileEditorInput) {
          return !((IFileEditorInput) input).getFile().isReadOnly();
        }
      }
      return false;
    }

    @Override
    public String getFailureMessage() {
      return "Editor must be initialized.";
    }
  }, EDITOR_ENABLED_TIMEOUT);

  return editorPart;
}
 
Example 28
Source Project: ice   Source File: AbstractWorkbenchTester.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tries to open an Eclipse editor given the specified input and the ID of
 * the editor.
 * 
 * @param input
 *            The editor's input.
 * @param id
 *            The Eclipse editor's ID as defined in the plug-in extensions.
 * @return The opened editor, or {@code null} if it could not be opened.
 */
protected IEditorReference openEditor(final IEditorInput input,
		final String id) {
	final AtomicReference<IEditorReference> editorRef = new AtomicReference<IEditorReference>();

	// This must be done on the UI thread. Use syncExec so that this method
	// will block until the editor can be opened.
	getDisplay().syncExec(new Runnable() {
		@Override
		public void run() {
			// Get the workbench window so we can open an editor.
			IWorkbenchWindow window = PlatformUI.getWorkbench()
					.getActiveWorkbenchWindow();
			IWorkbenchPage page = window.getActivePage();

			// Try to open the editor in the workbench.
			try {
				// IEditorPart editor = page.openEditor(input, id);
				IEditorReference[] refs = page.openEditors(
						new IEditorInput[] { input }, new String[] { id },
						IWorkbenchPage.MATCH_NONE);
				if (refs.length > 0) {
					editorRef.set(refs[0]);
				}
			} catch (MultiPartInitException e) {
				// Nothing to do.
			}

			return;
		}
	});

	return editorRef.get();
}
 
Example 29
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
	if (!(receiver instanceof ITextEditor)) {
		return false;
	}
	ITextEditor editor = (ITextEditor) receiver;

	IEditorInput input = editor.getEditorInput();
	IDocumentProvider docProvider = editor.getDocumentProvider();
	if (docProvider == null || input == null) {
		return false;
	}

	IDocument document = docProvider.getDocument(input);
	if (document == null) {
		return false;
	}

	IContentType[] contentTypes;
	try {
		ContentTypeInfo info = ContentTypeHelper.findContentTypes(document);
		if(info == null) {
			return false;
		}
		contentTypes = info.getContentTypes();
	} catch (CoreException e) {
		return false;
	}

	LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
	return registry.getLanguageConfigurationFor(contentTypes) != null;
}
 
Example 30
/**
 * Returns the element contained in the EditorInput
 * @param input the editor input
 * @return the input element
 */
Object getElementOfInput(IEditorInput input) {
	if (input instanceof IFileEditorInput)
		return ((IFileEditorInput)input).getFile();
	if (input != null)
		return JavaUI.getEditorInputJavaElement(input);
	return null;
}