类org.eclipse.ui.IURIEditorInput源码实例Demo

下面列出了怎么用org.eclipse.ui.IURIEditorInput的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: xtext-eclipse   文件: XtextDocumentProvider.java
@Override
public String getEncoding(Object element) {
	String encoding = super.getEncoding(element);
	if (encoding == null && element instanceof IStorageEditorInput) {
		try {
			IStorage storage = ((IStorageEditorInput) element).getStorage();
			URI uri = storage2UriMapper.getUri(storage);
			if (uri != null) {
				encoding = encodingProvider.getEncoding(uri);
			} else if (storage instanceof IEncodedStorage) {
				encoding = ((IEncodedStorage)storage).getCharset();
			}
		} catch (CoreException e) {
			throw new WrappedException(e);
		}
	}
	if (encoding == null) {
		if (isWorkspaceExternalEditorInput(element))
			encoding = getWorkspaceExternalEncoding((IURIEditorInput)element);
		else
			encoding = getWorkspaceOrDefaultEncoding();
	}
	return encoding;
}
 
源代码2 项目: xtext-eclipse   文件: XtextDocumentProvider.java
@Override
public boolean isModifiable(Object element) {
	if (isWorkspaceExternalEditorInput(element)) {
		URIInfo info= (URIInfo) getElementInfo(element);
		if (info != null) {
			if (info.updateCache) {
				try {
					updateCache((IURIEditorInput) element);
				} catch (CoreException x) {
					handleCoreException(x, "XtextDocumentProvider.isModifiable");
				}
			}
			return info.isModifiable;
		}
	}
	return super.isModifiable(element);
}
 
源代码3 项目: xtext-eclipse   文件: XtextDocumentProvider.java
@Override
public boolean isReadOnly(Object element) {
	if (isWorkspaceExternalEditorInput(element)) {
		URIInfo info= (URIInfo) getElementInfo(element);
		if (info != null) {
			if (info.updateCache) {
				try {
					updateCache((IURIEditorInput) element);
				} catch (CoreException x) {
					handleCoreException(x, "XtextDocumentProvider.isReadOnly");
				}
			}
			return info.isReadOnly;
		}
	}
	return super.isReadOnly(element);
}
 
源代码4 项目: xtext-eclipse   文件: XtextDocumentProvider.java
/**
 * @since 2.3
 */
protected void updateCache(IURIEditorInput input) throws CoreException {
	URIInfo info= (URIInfo) getElementInfo(input);
	if (info != null) {
		URI emfURI = toEmfUri(input.getURI());
		if (emfURI != null) {
			boolean readOnly = true;
			if (emfURI.isFile() && !emfURI.isArchive()) {
				// TODO: Should we use the ResourceSet somehow to obtain the URIConverter for the file protocol?
				// see also todo below, but don't run into a stackoverflow ;-)
				Map<String, ?> attributes = URIConverter.INSTANCE.getAttributes(emfURI, null);
				readOnly = Boolean.TRUE.equals(attributes.get(URIConverter.ATTRIBUTE_READ_ONLY));
			}
			info.isReadOnly=  readOnly;
			info.isModifiable= !readOnly;
		}
		info.updateCache= false;
	}
}
 
源代码5 项目: xds-ide   文件: CoreEditorUtils.java
/**
    * 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;
}
 
源代码6 项目: xds-ide   文件: XdsModel.java
/**
 * TODO : common with CoreEditorUtils
 * @param input
 * @return
 */
private static URI toURI(IEditorInput input) {
	URI uri = null;
	if (input instanceof IStorageEditorInput) {
		IStorageEditorInput storageEditorInput = (IStorageEditorInput)input;
		IFileRevision state = AdapterUtilities.getAdapter(storageEditorInput, IFileRevision.class);
		if (state != null) {
			uri = HistoryFs.toURI(state);
		}
	}
	else if (input instanceof IURIEditorInput) {

		IURIEditorInput uriEditorInput = (IURIEditorInput) input;
		uri = uriEditorInput.getURI();
	}

	return uri;
}
 
源代码7 项目: APICloud-Studio   文件: UIUtils.java
/**
 * Returns the URI for the specific editor input.
 * 
 * @param input
 *            the editor input
 * @return the URI, or null if none could be determined
 */
public static URI getURI(IEditorInput input)
{
	if (input instanceof IFileEditorInput)
	{
		return ((IFileEditorInput) input).getFile().getLocationURI();
	}
	if (input instanceof IURIEditorInput)
	{
		return ((IURIEditorInput) input).getURI();
	}
	if (input instanceof IPathEditorInput)
	{
		return URIUtil.toURI(((IPathEditorInput) input).getPath());
	}
	return null;
}
 
源代码8 项目: APICloud-Studio   文件: FilenameDifferentiator.java
private IPath getPath(IEditorPart otherEditor)
{
	IEditorInput input = otherEditor.getEditorInput();
	try
	{
		if (input instanceof IPathEditorInput)
		{
			return ((IPathEditorInput) input).getPath();
		}

		URI uri = (URI) input.getAdapter(URI.class);
		if (uri != null)
		{
			return new Path(uri.getHost() + Path.SEPARATOR + uri.getPath());
		}
		if (input instanceof IURIEditorInput)
		{
			return URIUtil.toPath(((IURIEditorInput) input).getURI());
		}
	}
	catch (Exception e)
	{
	}
	return null;
}
 
源代码9 项目: CppStyle   文件: ClangFormatFormatter.java
private static IPath getSourceFilePathFromEditorInput(IEditorInput editorInput) {
	if (editorInput instanceof IURIEditorInput) {
		URI uri = ((IURIEditorInput) editorInput).getURI();
		if (uri != null) {
			IPath path = URIUtil.toPath(uri);
			if (path != null) {
				  return path;
			}
		}
	}

	if (editorInput instanceof IFileEditorInput) {
		IFile file = ((IFileEditorInput) editorInput).getFile();
		if (file != null) {
			return file.getLocation();
		}
	}

	if (editorInput instanceof ILocationProvider) {
		return ((ILocationProvider) editorInput).getPath(editorInput);
	}

	return null;
}
 
源代码10 项目: eclipse-wakatime   文件: CustomEditorListener.java
@Override
public void partActivated(IWorkbenchPartReference partRef) {
    IEditorPart part = partRef.getPage().getActiveEditor();
    if (!(part instanceof AbstractTextEditor))
        return;

    // log new active file
    IEditorInput input = part.getEditorInput();
    if (input instanceof IURIEditorInput) {
        URI uri = ((IURIEditorInput)input).getURI();
        if (uri != null && uri.getPath() != null) {
            String currentFile = uri.getPath();
            long currentTime = System.currentTimeMillis() / 1000;
            if (!currentFile.equals(WakaTime.getDefault().lastFile) || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) {
                WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), false);
                WakaTime.getDefault().lastFile = currentFile;
                WakaTime.getDefault().lastTime = currentTime;
            }
        }
    }
}
 
源代码11 项目: birt   文件: IDEFileReportProvider.java
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;
}
 
源代码12 项目: Pydev   文件: PydevPackageExplorer.java
/**
 * 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;
}
 
源代码13 项目: Pydev   文件: AbstractBreakpointRulerAction.java
/**
 * @return the IEditorInput if we're dealing with an external file (or null otherwise)
 */
public static IEditorInput getExternalFileEditorInput(ITextEditor editor) {
    IEditorInput input = editor.getEditorInput();

    //only return not null if it's an external file (IFileEditorInput marks a workspace file, not external file)
    if (input instanceof IFileEditorInput) {
        return null;
    }

    if (input instanceof IPathEditorInput) { //PydevFileEditorInput would enter here
        return input;
    }

    try {
        if (input instanceof IURIEditorInput) {
            return input;
        }
    } catch (Throwable e) {
        //IURIEditorInput not added until eclipse 3.3
    }

    //Note that IStorageEditorInput is not handled for external files (files from zip)

    return input;
}
 
源代码14 项目: xtext-eclipse   文件: XtextDocumentProvider.java
@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);
}
 
源代码15 项目: xds-ide   文件: CoreEditorUtils.java
public static IFileStore editorInputToFileStore(IEditorInput input) {
	if (input == null) 
	    return null;
	
	IFileStore result = null;
	
       if (input instanceof IFileEditorInput) {
       	IFile file = editorInputToIFile(input);
           if (file != null) {
           	result =  ResourceUtils.toFileStore(file);
           }
       }
       else if (input instanceof IURIEditorInput) {
           IURIEditorInput uriEditorInput = (IURIEditorInput) input;
           result =  ResourceUtils.toFileStore(uriEditorInput.getURI());
       }
       else if (input instanceof CommonSourceNotFoundEditorInput || input instanceof CompareEditorInput) {
       	// do nothing
       	 return null;
	}
       else if (input instanceof IStorageEditorInput) {
       	IStorageEditorInput storageEditorInput = (IStorageEditorInput)input;
       	IFileRevision state = AdapterUtilities.getAdapter(storageEditorInput, IFileRevision.class);
       	if (state != null) {
       		result = ResourceUtils.toFileStore(HistoryFs.toURI(state));
       	}
       }
       
       if (result == null){
       	LogHelper.logError("Unknown editor input");
       }
       
       return result;
}
 
源代码16 项目: eclipse-extras   文件: DeleteEditorFileHandler.java
private static File getFile( IEditorInput editorInput ) {
  File result = null;
  if( editorInput instanceof IPathEditorInput ) {
    IPathEditorInput pathEditorInput = ( IPathEditorInput )editorInput;
    result = pathEditorInput.getPath().toFile();
  } else if( editorInput instanceof IURIEditorInput ) {
    IURIEditorInput uriEditorInput = ( IURIEditorInput )editorInput;
    result = URIUtil.toFile( uriEditorInput.getURI() );
  }
  return result;
}
 
@Test
public void testExecuteWithUriEditorInput() throws IOException {
  File file = tempFolder.newFile( "foo.txt" );
  IURIEditorInput editorInput = mockUriEditorInput( file );

  executeHandler( editorInput );

  assertThat( file ).doesNotExist();
}
 
源代码18 项目: eclipse-extras   文件: ImageViewerEditor.java
private static void checkEditorInput( IEditorInput input ) {
  if(    !( input instanceof IStorageEditorInput )
      && !( input instanceof IPathEditorInput )
      && !( input instanceof IURIEditorInput ) )
  {
    throw new IllegalArgumentException( "Invalid input: " + input );
  }
}
 
protected URI getURI()
{
	// Now try and resolve the value as a URI...
	IEditorInput input = getEditorInput();
	if (input instanceof IURIEditorInput)
	{
		return ((IURIEditorInput) input).getURI();
	}
	if (input instanceof IFileEditorInput)
	{
		IFile file = ((IFileEditorInput) input).getFile();
		return file.getLocationURI();
	}
	return null;
}
 
源代码20 项目: APICloud-Studio   文件: EditorUtil.java
/**
 * 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;
}
 
/**
 * Creates a fake compilation unit.
 *
 * @param editorInput the URI editor input
 * @return the fake compilation unit
 * @since 3.3
 */
private ICompilationUnit createFakeCompiltationUnit(IURIEditorInput editorInput) {
	try {
		final URI uri= editorInput.getURI();
		final IFileStore fileStore= EFS.getStore(uri);
		final IPath path= URIUtil.toPath(uri);
		String fileStoreName= fileStore.getName();
		if (fileStoreName == null || path == null)
			return null;

		WorkingCopyOwner woc= new WorkingCopyOwner() {
			/*
			 * @see org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org.eclipse.jdt.core.ICompilationUnit)
			 * @since 3.2
			 */
			@Override
			public IBuffer createBuffer(ICompilationUnit workingCopy) {
				return new DocumentAdapter(workingCopy, fileStore, path);
			}
		};

		IClasspathEntry[] cpEntries= null;
		IJavaProject jp= findJavaProject(path);
		if (jp != null)
			cpEntries= jp.getResolvedClasspath(true);

		if (cpEntries == null || cpEntries.length == 0)
			cpEntries= new IClasspathEntry[] { JavaRuntime.getDefaultJREContainerEntry() };

		final ICompilationUnit cu= woc.newWorkingCopy(fileStoreName, cpEntries, getProgressMonitor());

		if (!isModifiable(editorInput))
			JavaModelUtil.reconcile(cu);

		return cu;
	} catch (CoreException ex) {
		return null;
	}
}
 
源代码22 项目: dawnsci   文件: H5Editor.java
/**
 * Get the file path from a FileStoreEditorInput. Removes any "file:"
 * from the URI to the file path if it exists.
 * 
 * @param fileInput
 * @return String
 */
public String getFilePath(IEditorInput fileInput) {
	
	final IFile file = (IFile)fileInput.getAdapter(IFile.class);
	if (file!=null) return file.getLocation().toOSString();

	if (fileInput instanceof IURIEditorInput) {
		String path = ((IURIEditorInput)fileInput).getURI().toString();
		if (path.startsWith("file:")) path = path.substring(5);
		path = path.replace("%20", " ");
		return path;
	} 
	return null;
}
 
源代码23 项目: eclipse-wakatime   文件: CustomCaretListener.java
@Override
public void caretMoved(CaretEvent event) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    if (window == null) return;
    if (window.getPartService() == null) return;
    if (window.getPartService().getActivePart() == null) return;
    if (window.getPartService().getActivePart().getSite() == null) return;
    if (window.getPartService().getActivePart().getSite().getPage() == null) return;
    if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return;
    if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return;

    // log file if one is opened by default
    IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput();
    if (input instanceof IURIEditorInput) {
        URI uri = ((IURIEditorInput)input).getURI();
        if (uri != null && uri.getPath() != null) {
            String currentFile = uri.getPath();
            long currentTime = System.currentTimeMillis() / 1000;
            if (!currentFile.equals(WakaTime.getDefault().lastFile) || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) {
                WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), false);
                WakaTime.getDefault().lastFile = currentFile;
                WakaTime.getDefault().lastTime = currentTime;
            }
        }
    }
}
 
源代码24 项目: eclipse-wakatime   文件: CustomExecutionListener.java
@Override
public void postExecuteSuccess(String commandId, Object returnValue) {
    if (commandId.equals("org.eclipse.ui.file.save")) {
        IWorkbench workbench = PlatformUI.getWorkbench();
        if (workbench == null) return;
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        if (window == null) return;

        if (window.getPartService() == null) return;
        if (window.getPartService().getActivePart() == null) return;
        if (window.getPartService().getActivePart().getSite() == null) return;
        if (window.getPartService().getActivePart().getSite().getPage() == null) return;
        if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return;
        if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return;

        // log file save event
        IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput();
        if (input instanceof IURIEditorInput) {
            URI uri = ((IURIEditorInput)input).getURI();
            if (uri != null && uri.getPath() != null) {
                String currentFile = uri.getPath();
                long currentTime = System.currentTimeMillis() / 1000;

                // always log writes
                WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), true);
                WakaTime.getDefault().lastFile = currentFile;
                WakaTime.getDefault().lastTime = currentTime;
            }
        }
    }
}
 
源代码25 项目: birt   文件: ReportEditorProxy.java
public void init( IEditorSite site, IEditorInput input )
		throws PartInitException
{
	cachedSite = site;

	if ( instance != null )
	{
		getSite( ).getWorkbenchWindow( )
				.getPartService( )
				.removePartListener( instance );
		instance.dispose( );
	}

	if ( input instanceof IFileEditorInput
			|| input instanceof IURIEditorInput )
	{
		instance = new IDEMultiPageReportEditor( );
	}
	else
	{
		instance = new MultiPageReportEditor( );
	}

	// must add property listener before init.
	instance.addPropertyListener( this );

	instance.init( site, input );
	getSite( ).getWorkbenchWindow( )
			.getPartService( )
			.addPartListener( this );

}
 
源代码26 项目: Pydev   文件: PydevFileEditorInput.java
@Override
public URI getURI(Object element) {
    if (element instanceof IURIEditorInput) {
        IURIEditorInput editorInput = (IURIEditorInput) element;
        return editorInput.getURI();
    }
    return null;
}
 
源代码27 项目: xtext-eclipse   文件: XtextDocumentProvider.java
/**
 * @since 2.5
 */
protected String getWorkspaceExternalEncoding(IURIEditorInput element) {
	URI emfURI = toEmfUri(element.getURI());
	return encodingProvider.getEncoding(emfURI);
}
 
源代码28 项目: xtext-eclipse   文件: XtextDocumentProvider.java
/**
 * @since 2.3
 */
protected boolean isWorkspaceExternalEditorInput(Object element) {
	return element instanceof IURIEditorInput && !(element instanceof IFileEditorInput);
}
 
private static IURIEditorInput mockUriEditorInput( File file ) {
  IURIEditorInput editorInput = mock( IURIEditorInput.class );
  when( editorInput.getURI() ).thenReturn( file.toURI() );
  return editorInput;
}
 
源代码30 项目: APICloud-Studio   文件: EditorUtil.java
/**
 * Gets the URI associated with the editor.
 * 
 * @param editor
 * @return
 */
public static URI getURI(IEditorPart editor)
{
	// NOTE: Moved from CommonContentAssistProcessor
	if (editor != null)
	{
		IEditorInput editorInput = editor.getEditorInput();

		if (editorInput instanceof IURIEditorInput)
		{
			IURIEditorInput uriEditorInput = (IURIEditorInput) editorInput;
			return uriEditorInput.getURI();
		}
		if (editorInput instanceof IPathEditorInput)
		{
			IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput;
			return URIUtil.toURI(pathEditorInput.getPath());
		}
		if (editorInput instanceof IFileEditorInput)
		{
			IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
			return fileEditorInput.getFile().getLocationURI();
		}
		try
		{
			if (editorInput instanceof IStorageEditorInput)
			{
				IStorageEditorInput storageEditorInput = (IStorageEditorInput) editorInput;
				IStorage storage = storageEditorInput.getStorage();
				if (storage != null)
				{
					IPath path = storage.getFullPath();
					if (path != null)
					{
						return URIUtil.toURI(path);
					}
				}
			}
		}
		catch (CoreException e)
		{
			IdeLog.logError(CommonEditorPlugin.getDefault(), e);
		}
		if (editorInput instanceof ILocationProviderExtension)
		{
			ILocationProviderExtension lpe = (ILocationProviderExtension) editorInput;
			return lpe.getURI(null);
		}
		if (editorInput instanceof ILocationProvider)
		{
			ILocationProvider lp = (ILocationProvider) editorInput;
			return URIUtil.toURI(lp.getPath(null));
		}
	}

	return null;
}
 
 类所在包
 类方法
 同包方法