Java Code Examples for org.eclipse.ui.IFileEditorInput#getFile()

The following examples show how to use org.eclipse.ui.IFileEditorInput#getFile() . 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: PropertiesFileDocumentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks whether the passed file editor input defines a Java properties file.
 * 
 * @param element the file editor input
 * @return <code>true</code> if element defines a Java properties file, <code>false</code>
 *         otherwise
 * @throws CoreException
 * 
 * @since 3.7
 */
public static boolean isJavaPropertiesFile(Object element) throws CoreException {
	if (JAVA_PROPERTIES_FILE_CONTENT_TYPE == null || !(element instanceof IFileEditorInput))
		return false;

	IFileEditorInput input= (IFileEditorInput)element;

	IFile file= input.getFile();
	if (file == null || !file.isAccessible())
		return false;

	IContentDescription description= file.getContentDescription();
	if (description == null || description.getContentType() == null || !description.getContentType().isKindOf(JAVA_PROPERTIES_FILE_CONTENT_TYPE))
		return false;

	return true;
}
 
Example 2
Source File: EditorUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the resource file that the editor belongs to.
 * 
 * @param editor
 * @return
 */
public static IFile getEditorFile(AbstractThemeableEditor editor)
{
	IEditorInput editorInput = editor.getEditorInput();
	if (editorInput instanceof IFileEditorInput)
	{
		IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
		return fileEditorInput.getFile();
	}
	else if (editorInput instanceof FileStoreEditorInput)
	{
		FileStoreEditorInput input = (FileStoreEditorInput) editorInput;
		IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(input.getURI());
		if (files != null && files.length > 0)
		{
			return files[0];
		}
	}
	return null;
}
 
Example 3
Source File: XdsModel.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
    * {@inheritDoc}
    */
   @Override
public IXdsElement getXdsElement(IEditorInput input) {
   	IXdsElement xdsElement = null;
       if (input instanceof IFileEditorInput) {
       	IFileEditorInput fileEditorInput = (IFileEditorInput)input;
       	IFile file = fileEditorInput.getFile();
           if (file != null) {
               xdsElement = XdsModelManager.getModel().getXdsElement(file);
           }
       }
       else {
       	URI uri = toURI(input);
       	IFileStore fileStore = ResourceUtils.toFileStore(uri);
       	xdsElement = XdsModelManager.getModel().getNonWorkspaceXdsElement(fileStore);
       }
       
	return xdsElement;
}
 
Example 4
Source File: IDEFileReportProvider.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void saveReport( ModuleHandle moduleHandle, Object element,
		IPath origReportPath, IProgressMonitor monitor )
{
	if ( element instanceof IFileEditorInput )
	{
		IFileEditorInput input = (IFileEditorInput) element;
		IFile file = input.getFile( );
		if ( ResourcesPlugin.getWorkspace( ).validateEdit( new IFile[]{
			file
		}, IWorkspace.VALIDATE_PROMPT ).getSeverity( ) == IStatus.OK )
		{
			saveFile( moduleHandle, file, origReportPath, monitor );
		}
	}
	else if ( element instanceof IEditorInput )
	{
		IPath path = getInputPath( (IEditorInput) element );
		if ( path != null )
		{
			saveFile( moduleHandle, path.toFile( ), origReportPath, monitor );
		}
	}

}
 
Example 5
Source File: EditorInputPropertyTester.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {

    if (IS_EXPERIMENT_EDITOR_INPUT.equals(property)) {
        if (receiver instanceof IFileEditorInput) {
            IFileEditorInput editorInput = (IFileEditorInput) receiver;
            IFile file = editorInput.getFile();
            if (file != null) {
                try {
                    final String traceTypeId = file.getPersistentProperty(TmfCommonConstants.TRACETYPE);
                    if (traceTypeId != null && ITmfEventsEditorConstants.EXPERIMENT_INPUT_TYPE_CONSTANTS.contains(traceTypeId)) {
                        return true;
                    }
                } catch (CoreException e) {
                    // Ignore
                }
            }
        }
    }
    return false;
}
 
Example 6
Source File: IDEFileReportProvider.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public IPath getSaveAsPath( Object element )
{
	IFile file = null;
	if ( element instanceof IFileEditorInput )
	{
		IFileEditorInput input = (IFileEditorInput) element;
		file = input.getFile( );
	}
	SaveReportAsWizardDialog dialog = new SaveReportAsWizardDialog( UIUtil.getDefaultShell( ),
			new SaveReportAsWizard( model, file ) );
	if ( dialog.open( ) == Window.OK )
	{
		return dialog.getResult( );
	}
	return null;
}
 
Example 7
Source File: AbstractDesignElementPicker.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * This method will get the DesignerProject for the current XPage and return it. 
 * @param compEditor
 * @return
 */
private DesignerProject getDesignerProjectForEditor(CompositeEditor compEditor){
    IWorkbenchPart part = super.getWorkBenchPart();
    if(part instanceof EditorPart){
        EditorPart editor = (EditorPart)part;
        IEditorInput input = editor.getEditorInput();
        if(input instanceof IFileEditorInput){
            IFileEditorInput fileInput = (IFileEditorInput)input;
            IFile xpageFile = fileInput.getFile();
            if(null != xpageFile){
                IProject project = xpageFile.getProject();
                if(null != project){
                    DesignerProject designerProj = DesignerResource.getDesignerProject(project);
                    if(null != designerProj){
                        return designerProj;
                    }
                }
            }
        }
    }
    return null;
}
 
Example 8
Source File: EdgeMatcherEditor.java    From depan with Apache License 2.0 6 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input)
    throws PartInitException {
  setSite(site);
  setInput(input);
  // only accept a file as input.
  if (input instanceof IFileEditorInput) {
    // get the URI
    IFileEditorInput fileInput = (IFileEditorInput) input;
    file = fileInput.getFile();

    EdgeMatcherDocXmlPersist persist = EdgeMatcherDocXmlPersist.build(true);
    matcherInfo = persist.load(file.getRawLocationURI());

    setPartName(buildPartName());
    setDirtyState(false);
    return;
  }

  // Something unexpected
  throw new PartInitException(
      "Input for editor is not suitable for the RelationSetDescriptorEditor");
}
 
Example 9
Source File: CommonReconcilingStrategy.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
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 10
Source File: JavaReconciler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IResource getResource() {
	IEditorInput input= fTextEditor.getEditorInput();
	if (input instanceof IFileEditorInput) {
		IFileEditorInput fileInput= (IFileEditorInput) input;
		return fileInput.getFile();
	}
	return null;
}
 
Example 11
Source File: EditorUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the indexing associated with the editor.
 * 
 * @param editor
 * @return
 */
public static Index getIndex(AbstractThemeableEditor editor)
{
	// NOTE: Moved from CommonContentAssistProcessor
	if (editor != null)
	{
		IEditorInput editorInput = editor.getEditorInput();

		if (editorInput instanceof IFileEditorInput)
		{
			IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
			IFile file = fileEditorInput.getFile();

			return getIndexManager().getIndex(file.getProject().getLocationURI());
		}
		if (editorInput instanceof IURIEditorInput)
		{
			IURIEditorInput uriEditorInput = (IURIEditorInput) editorInput;

			// FIXME This file may be a child, we need to check to see if there's an index with a parent URI.
			return getIndexManager().getIndex(uriEditorInput.getURI());
		}
		if (editorInput instanceof IPathEditorInput)
		{
			IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput;

			// FIXME This file may be a child, we need to check to see if there's an index with a parent URI.
			return getIndexManager().getIndex(URIUtil.toURI(pathEditorInput.getPath()));
		}
	}

	return null;
}
 
Example 12
Source File: AbstractFoldingEditor.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private IFile getFile()
{
	IEditorInput editorInput = getEditorInput();
	if (editorInput instanceof IFileEditorInput)
	{
		IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
		return fileEditorInput.getFile();
	}
	return null;
}
 
Example 13
Source File: ResourceUtils.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the file being edited by a given editor. Note that this method can
 * return null if the specified editor isn't an IFileEditor.
 */
public static IFile getEditorInput(IEditorPart editor) {
  IFileEditorInput fileEditorInput = AdapterUtilities.getAdapter(
      editor.getEditorInput(), IFileEditorInput.class);
  if (fileEditorInput != null) {
    return fileEditorInput.getFile();
  }
  return null;
}
 
Example 14
Source File: RelationSetDescriptorEditor.java    From depan with Apache License 2.0 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input)
    throws PartInitException {
  setSite(site);
  setInput(input);
  // only accept a file as input.
  if (input instanceof IFileEditorInput) {
    // get the URI
    IFileEditorInput fileInput = (IFileEditorInput) input;
    file = fileInput.getFile();

    RelationSetDescriptorXmlPersist persist =
        RelationSetDescriptorXmlPersist.build(true);
    relSetInfo = persist.load(file.getRawLocationURI());

    relRepo = new RelationSetDescrRepo(relSetInfo.getModel().getRelations());
    relRepo.setRelationSet(relSetInfo.getInfo());

    setPartName(buildPartName());
    setDirtyState(false);
    return;
  }

  // Something unexpected
  throw new PartInitException(
      "Input for editor is not suitable for the RelationSetDescriptorEditor");
}
 
Example 15
Source File: SourceEditor.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the corresponding file, if any.
 * 
 * @return
 */
protected IFile getFile() {
    if (!(getEditorInput() instanceof IFileEditorInput))
        return null;
    IFileEditorInput input = (IFileEditorInput) getEditorInput();
    return input.getFile();
}
 
Example 16
Source File: JavaElementDelegate.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void initializeWith(IFileEditorInput editorInput) {
	this.resource = editorInput.getFile();
	IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
	if (activeWorkbenchWindow != null) {
		IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
		this.editor = activePage != null ? activePage.findEditor(editorInput) : null;
	}
}
 
Example 17
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected IAnnotationModel createAnnotationModel(Object element) throws CoreException {
	if (element instanceof IFileEditorInput) {
		IFileEditorInput input = (IFileEditorInput) element;
		return new XtextResourceMarkerAnnotationModel(input.getFile(), issueResolutionProvider, issueUtil);
	} else if (element instanceof IURIEditorInput) {
		return new AnnotationModel();
	}
	return super.createAnnotationModel(element);
}
 
Example 18
Source File: SelectionUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static IFile getSelectedFile(IEditorPart editor) {
	IEditorInput editorInput = editor.getEditorInput();
	if (editorInput instanceof IFileEditorInput) {
		IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
		return fileEditorInput.getFile();
	}
	return null;
}
 
Example 19
Source File: ValidationOperation.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void run(IProgressMonitor monitor) throws CoreException {
    // if the file is not part of a workspace it does not seems that it is a
    // IFileEditorInput
    // but instead a FileStoreEditorInput. Unclear if markers are valid for
    // such files.
    if (!(editorInput instanceof IFileEditorInput)) {
        YEditLog.logError("Marking errors not supported for files outside of a project.");
        YEditLog.logger.info("editorInput is not a part of a project.");
        return;
    }

    final IDocument document = documentProvider.getDocument(editorInput);
    if (document instanceof JsonDocument) {
        SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
        final IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
        final IFile file = fileEditorInput.getFile();

        if (parseFileContents) {
            // force parsing of yaml to init parsing errors
            // subMonitor.split() should NOT be executed before this code
            // as it checks for job cancellation and we want to be sure that
            // the document is parsed on opening
            ((JsonDocument) document).onChange();
        }
        if (subMonitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        subMonitor.newChild(20);

        JsonEditor.clearMarkers(file);
        if (subMonitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        subMonitor.newChild(30);

        validateYaml(file, (JsonDocument) document);
        if (subMonitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        subMonitor.newChild(20);

        validateSwagger(file, (JsonDocument) document, fileEditorInput);
        if (subMonitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        subMonitor.newChild(30);
    }
}
 
Example 20
Source File: TestDiscoveryUIUtils.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private static URI getFileURI(final IFileEditorInput fileEditorInput) {
	final IFile originalFileToRun = fileEditorInput.getFile();
	final String pathName = originalFileToRun.getFullPath().toString();
	return URI.createPlatformResourceURI(pathName, true);
}