下面列出了怎么用org.eclipse.ui.part.FileEditorInput的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public IAdaptable createElement(IMemento memento) {
String fileStr = memento.getString(TAG_FILE);
if (fileStr == null || fileStr.length() == 0) {
return null;
}
String zipPath = memento.getString(TAG_ZIP_PATH);
final File file = new File(fileStr);
if (zipPath == null || zipPath.length() == 0) {
//return EditorInputFactory.create(new File(file), false);
final URI uri = file.toURI();
IFile[] ret = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri,
IContainer.INCLUDE_HIDDEN | IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
if (ret != null && ret.length > 0) {
return new FileEditorInput(ret[0]);
}
try {
return new FileStoreEditorInput(EFS.getStore(uri));
} catch (CoreException e) {
return new PydevFileEditorInput(file);
}
}
return new PydevZipFileEditorInput(new PydevZipFileStorage(file, zipPath));
}
/**
* This also changes the editor's input.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void doSaveAs ()
{
SaveAsDialog saveAsDialog = new SaveAsDialog ( getSite ().getShell () );
saveAsDialog.open ();
IPath path = saveAsDialog.getResult ();
if ( path != null )
{
IFile file = ResourcesPlugin.getWorkspace ().getRoot ().getFile ( path );
if ( file != null )
{
doSaveAs ( URI.createPlatformResourceURI ( file.getFullPath ().toString (), true ), new FileEditorInput ( file ) );
}
}
}
/**
* This also changes the editor's input.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void doSaveAs ()
{
SaveAsDialog saveAsDialog = new SaveAsDialog ( getSite ().getShell () );
saveAsDialog.open ();
IPath path = saveAsDialog.getResult ();
if ( path != null )
{
IFile file = ResourcesPlugin.getWorkspace ().getRoot ().getFile ( path );
if ( file != null )
{
doSaveAs ( URI.createPlatformResourceURI ( file.getFullPath ().toString (), true ), new FileEditorInput ( file ) );
}
}
}
/**
* This also changes the editor's input.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void doSaveAs ()
{
SaveAsDialog saveAsDialog = new SaveAsDialog ( getSite ().getShell () );
saveAsDialog.open ();
IPath path = saveAsDialog.getResult ();
if ( path != null )
{
IFile file = ResourcesPlugin.getWorkspace ().getRoot ().getFile ( path );
if ( file != null )
{
doSaveAs ( URI.createPlatformResourceURI ( file.getFullPath ().toString (), true ), new FileEditorInput ( file ) );
}
}
}
/**
* This also changes the editor's input.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void doSaveAs ()
{
SaveAsDialog saveAsDialog = new SaveAsDialog ( getSite ().getShell () );
saveAsDialog.open ();
IPath path = saveAsDialog.getResult ();
if ( path != null )
{
IFile file = ResourcesPlugin.getWorkspace ().getRoot ().getFile ( path );
if ( file != null )
{
doSaveAs ( URI.createPlatformResourceURI ( file.getFullPath ().toString (), true ), new FileEditorInput ( file ) );
}
}
}
/**
* This also changes the editor's input.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void doSaveAs ()
{
SaveAsDialog saveAsDialog = new SaveAsDialog ( getSite ().getShell () );
saveAsDialog.open ();
IPath path = saveAsDialog.getResult ();
if ( path != null )
{
IFile file = ResourcesPlugin.getWorkspace ().getRoot ().getFile ( path );
if ( file != null )
{
doSaveAs ( URI.createPlatformResourceURI ( file.getFullPath ().toString (), true ), new FileEditorInput ( file ) );
}
}
}
/**
* This also changes the editor's input.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void doSaveAs ()
{
SaveAsDialog saveAsDialog = new SaveAsDialog ( getSite ().getShell () );
saveAsDialog.open ();
IPath path = saveAsDialog.getResult ();
if ( path != null )
{
IFile file = ResourcesPlugin.getWorkspace ().getRoot ().getFile ( path );
if ( file != null )
{
doSaveAs ( URI.createPlatformResourceURI ( file.getFullPath ().toString (), true ), new FileEditorInput ( file ) );
}
}
}
/**
* This also changes the editor's input.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void doSaveAs ()
{
SaveAsDialog saveAsDialog = new SaveAsDialog ( getSite ().getShell () );
saveAsDialog.open ();
IPath path = saveAsDialog.getResult ();
if ( path != null )
{
IFile file = ResourcesPlugin.getWorkspace ().getRoot ().getFile ( path );
if ( file != null )
{
doSaveAs ( URI.createPlatformResourceURI ( file.getFullPath ().toString (), true ), new FileEditorInput ( file ) );
}
}
}
protected void initEditorNameAndDescription(final IEditorInput input) {
// setup the content description and image of spec root
if (input instanceof FileEditorInput)
{
final FileEditorInput finput = (FileEditorInput) input;
if (finput != null)
{
final IPath path = finput.getPath();
setContentDescription(path.toString());
if (ResourceHelper.isRoot(finput.getFile()))
{
setTitleImage(rootImage);
}
}
}
}
/**
* @generated
*/
private static IEditorInput getEditorInput(Diagram diagram) {
Resource diagramResource = diagram.eResource();
for (EObject nextEObject : diagramResource.getContents()) {
if (nextEObject == diagram) {
return new FileEditorInput(WorkspaceSynchronizer.getFile(diagramResource));
}
if (nextEObject instanceof Diagram) {
break;
}
}
URI uri = EcoreUtil.getURI(diagram);
String editorName = uri.lastSegment() + '#' + diagram.eResource().getContents().indexOf(diagram);
IEditorInput editorInput = new URIEditorInput(uri, editorName);
return editorInput;
}
/**
* This also changes the editor's input.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void doSaveAs ()
{
SaveAsDialog saveAsDialog = new SaveAsDialog ( getSite ().getShell () );
saveAsDialog.open ();
IPath path = saveAsDialog.getResult ();
if ( path != null )
{
IFile file = ResourcesPlugin.getWorkspace ().getRoot ().getFile ( path );
if ( file != null )
{
doSaveAs ( URI.createPlatformResourceURI ( file.getFullPath ().toString (), true ), new FileEditorInput ( file ) );
}
}
}
private static String getResourceType( List<IResource> resources,
List<IEditorPart> openedFiles )
{
IResource currentResource = resources.get( 0 );
IEditorInput editorInput = openedFiles.get( 0 ).getEditorInput( );
if ( editorInput instanceof FileEditorInput )
{
currentResource = ( (FileEditorInput) editorInput ).getFile( );
}
switch ( currentResource.getType( ) )
{
case IResource.FILE :
return openedFiles.size( ) != 1 ? Messages.getString( "renameChecker.closeResourceMessage.forManyFile" ) //$NON-NLS-1$
: currentResource.getName( ) + " " //$NON-NLS-1$
+ Messages.getString( "renameChecker.closeResourceMessage.forOneFile" ); //$NON-NLS-1$
case IResource.PROJECT :
return Messages.getString( "renameChecker.closeResourceMessage.forProject" ); //$NON-NLS-1$
default :
return Messages.getString( "renameChecker.closeResourceMessage.forFolder" ); //$NON-NLS-1$
}
}
/**
* @generated BonitaSoft
*/
protected IDocument createDocument(Object element) throws CoreException {
if (false == element instanceof FileEditorInput && false == element instanceof URIEditorInput) {
throw new CoreException(new Status(IStatus.ERROR,
org.bonitasoft.studio.model.process.diagram.part.ProcessDiagramEditorPlugin.ID, 0,
NLS.bind(Messages.ProcessDocumentProvider_IncorrectInputError,
new Object[] { element, "org.eclipse.ui.part.FileEditorInput", //$NON-NLS-1$
"org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$
null));
}
String id = null;
if (element instanceof FileEditorInput) {
FileEditorInput fInput = (FileEditorInput) element;
id = fInput.getName();
} else if (element instanceof URIEditorInput) {
id = URI.decode(((URIEditorInput) element).getURI().lastSegment());
}
IDocument document = createEmptyDocument(id);
setDocumentContent(document, (IEditorInput) element);
setupDocument(element, document);
return document;
}
/**
* @generated
*/
protected ElementInfo createElementInfo(Object element) throws CoreException {
if (false == element instanceof FileEditorInput && false == element instanceof URIEditorInput) {
throw new CoreException(new Status(IStatus.ERROR, CrossflowDiagramEditorPlugin.ID, 0,
NLS.bind(Messages.CrossflowDocumentProvider_IncorrectInputError,
new Object[] { element, "org.eclipse.ui.part.FileEditorInput", //$NON-NLS-1$
"org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$
null));
}
IEditorInput editorInput = (IEditorInput) element;
IDiagramDocument document = (IDiagramDocument) createDocument(editorInput);
ResourceSetInfo info = new ResourceSetInfo(document, editorInput);
info.setModificationStamp(computeModificationStamp(info));
info.fStatus = null;
return info;
}
public static String getActiveProject() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
if (window == null) return null;
if (window.getPartService() == null) return null;
if (window.getPartService().getActivePart() == null) return null;
if (window.getPartService().getActivePart().getSite() == null) return null;
if (window.getPartService().getActivePart().getSite().getPage() == null) return null;
if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return null;
if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return null;
IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput();
IProject project = null;
if (input instanceof FileEditorInput) {
project = ((FileEditorInput)input).getFile().getProject();
}
if (project == null)
return null;
return project.getName();
}
/**
* @generated
*/
public boolean isModifiable(Object element) {
if (!isStateValidated(element)) {
if (element instanceof FileEditorInput || element instanceof URIEditorInput) {
return true;
}
}
ResourceSetInfo info = getResourceSetInfo(element);
if (info != null) {
if (info.isUpdateCache()) {
try {
updateCache(element);
} catch (CoreException ex) {
CrossflowDiagramEditorPlugin.getInstance().logError(Messages.CrossflowDocumentProvider_isModifiable,
ex);
// Error message to log was initially taken from org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.StorageDocumentProvider_isModifiable
}
}
return info.isModifiable();
}
return super.isModifiable(element);
}
public void printTransProgFAReslut() {
String htmlPath = createFAResultHtml();
try {
model.getAnalysisIFileList().get(0).getProject().getFolder("Intermediate").getFolder("Report").refreshLocal(IResource.DEPTH_ONE, null);
} catch (CoreException e1) {
e1.printStackTrace();
logger.error(Messages.getString("qa.fileAnalysis.EditProgressFA.log1"), e1);
}
final FileEditorInput input = new FileEditorInput(ResourceUtils.fileToIFile(htmlPath));
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, QAConstant.FA_HtmlBrowserEditor, true);
} catch (PartInitException e) {
e.printStackTrace();
logger.error(Messages.getString("qa.fileAnalysis.EditProgressFA.log2"), e);
}
}
});
}
private static IEditorInput getEditorInput(Diagram diagram) {
Resource diagramResource = diagram.eResource();
for (Iterator<EObject> it = diagramResource.getContents().iterator(); it
.hasNext();) {
EObject nextEObject = (EObject) it.next();
if (nextEObject == diagram) {
return new FileEditorInput(
WorkspaceSynchronizer.getFile(diagramResource));
}
if (nextEObject instanceof Diagram) {
break;
}
}
URI uri = EcoreUtil.getURI(diagram);
String editorName = uri.lastSegment() + "#"
+ diagram.eResource().getContents().indexOf(diagram);
IEditorInput editorInput = new URIEditorInput(uri, editorName);
return editorInput;
}
/**
* Open text editor.
*
* @param fileToOpen the file to open
*/
public void openTextEditor(IFile fileToOpen) {
final IFile ffile = fileToOpen;
Shell shell = new Shell();
shell.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
page.openEditor(new FileEditorInput(ffile), "org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
} catch (PartInitException e) {
throw new InternalErrorCDE("unexpected exception");
}
}
});
}
/**
* @generated
*/
private static IEditorInput getEditorInput(Diagram diagram) {
Resource diagramResource = diagram.eResource();
for (EObject nextEObject : diagramResource.getContents()) {
if (nextEObject == diagram) {
return new FileEditorInput(WorkspaceSynchronizer.getFile(diagramResource));
}
if (nextEObject instanceof Diagram) {
break;
}
}
URI uri = EcoreUtil.getURI(diagram);
String editorName = uri.lastSegment() + '#' + diagram.eResource().getContents().indexOf(diagram);
IEditorInput editorInput = new URIEditorInput(uri, editorName);
return editorInput;
}
protected ITextEditor findOpenEditor(IFile file) {
if (workbench == null) {
return null;
}
return new DisplayRunnableWithResult<ITextEditor>() {
@Override
protected ITextEditor run() throws Exception {
FileEditorInput editorInput = new FileEditorInput(file);
IEditorPart editorPart = workbench.getActiveWorkbenchWindow().getActivePage().findEditor(editorInput);
if (editorPart instanceof ITextEditor) {
return (ITextEditor) editorPart;
}
return null;
}
}.syncExec();
}
public void reLoadMatches(IXliffEditor editor, int rowIndex) {
// 修复 Bug #3064 编辑匹配--更换记忆库后再编辑原记忆库匹配,出现异常.刷新问题
TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);// handler.getTransUnit(rowId);
if (transUnit == null) {
return;
}
XLFHandler handler = editor.getXLFHandler();
if (handler == null) {
return;
}
IProject prj = null;
if (editor instanceof IEditorPart) {
IEditorPart p = (IEditorPart) editor;
FileEditorInput input = (FileEditorInput) p.getEditorInput();
prj = input.getFile().getProject();
}
if (prj == null) {
return;
}
String rowId = handler.getRowId(rowIndex);
TransUnitInfo2TranslationBean tuInfoBean = getTuInfoBean(transUnit, handler, rowId);
executeMatch(editor, rowId, transUnit, tuInfoBean, prj);
}
/**
* Updates the BibTeX -data in the BibTeX-container.
*/
private void updateBibContainer() {
IProject project = editor.getProject();
if (project == null) return;
IResource resource = ((FileEditorInput)editor.getEditorInput()).getFile();
if (bibContainer == null) {
ReferenceContainer refCon = (ReferenceContainer) TexlipseProperties.getSessionProperty(project,
TexlipseProperties.BIBCONTAINER_PROPERTY);
if (refCon != null) {
bibContainer = refCon;
} else {
return;
}
}
boolean changed = bibContainer.updateRefSource(
resource.getFullPath().removeFirstSegments(1).toString(),
entryList);
if (changed) {
TexlipseProperties.setSessionProperty(project,
TexlipseProperties.BIBFILES_CHANGED,
new Boolean(true));
}
}
/**
* 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());
}
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = WorkbenchUtils.getActivePartShell();
HashSet<String> exts = new HashSet<String>();
exts.addAll(XdsFileUtils.COMPILATION_UNIT_FILE_EXTENSIONS);
SelectModulaSourceFileDialog dlg = new SelectModulaSourceFileDialog(Messages.GotoCompilationUnitHandler_OpenModule, shell, ResourceUtils.getWorkspaceRoot(), exts);
if (SelectModulaSourceFileDialog.OK == dlg.open()){
IFile file = (IFile)dlg.getResultAsResource();
if (file != null) {
IEditorInput editorInput = new FileEditorInput(file);
try {
CoreEditorUtils.openInEditor(editorInput, true);
} catch (CoreException e) {
LogHelper.logError(e);
}
}
}
return null;
}
private void openInEditor(final IProject project, File f) {
if (f.isFile()) {
// Open created main module in editor:
final String resoureRelativePath = ResourceUtils.getRelativePath(project, f.getAbsolutePath());
if (resoureRelativePath != null) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
IFile file = project.getFile(resoureRelativePath);
IEditorInput editorInput = new FileEditorInput(file);
try {
CoreEditorUtils.openInEditor(editorInput, true);
} catch (CoreException e) {
}
}
});
}
}
}
private void openInEditor(final IProject project, File f) {
if (f.isFile()) {
// Open created main module in editor:
final String resoureRelativePath = ResourceUtils.getRelativePath(project, f.getAbsolutePath());
if (resoureRelativePath != null) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
IFile file = project.getFile(resoureRelativePath);
IEditorInput editorInput = new FileEditorInput(file);
try {
CoreEditorUtils.openInEditor(editorInput, true);
} catch (CoreException e) {
}
}
});
}
}
}
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();
}
}
}
/**
* if the active editor is the DOT Editor, update the graph, otherwise
* do nothing
*/
private void checkActiveEditorAndUpdateGraph(IWorkbenchPart part) {
if (DotEditorUtils.isDotEditor(part)) {
IEditorInput editorInput = ((EditorPart) part).getEditorInput();
if (editorInput instanceof FileEditorInput) {
IFile file = ((FileEditorInput) editorInput).getFile();
try {
File resolvedFile = DotFileUtils
.resolve(file.getLocationURI().toURL());
if (!resolvedFile.equals(currentFile)) {
updateGraph(resolvedFile);
}
} catch (MalformedURLException e) {
DotActivatorEx.logError(e);
}
}
}
}
final JavaEditor getEditor(IFile file) {
FileEditorInput fei= new FileEditorInput(file);
IWorkbench workbench= JavaPlugin.getDefault().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];
if (ep instanceof JavaEditor) {
JavaEditor je= (JavaEditor) ep;
if (fei.equals(je.getEditorInput()))
return (JavaEditor) ep;
}
}
}
}
return null;
}