下面列出了org.eclipse.ui.part.FileEditorInput#getFile ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean isEditable() {
IEditorInput input = getEditorInput();
if (input instanceof FileEditorInput) {
FileEditorInput fei = (FileEditorInput) input;
IFile inputFile = fei.getFile();
if (inputFile.toString().contains(N4JSGlobals.NODE_MODULES)) {
FileURI fileUri = new FileURI(inputFile.getFullPath().toFile());
FileURI project = extWS.findProjectWith(fileUri);
boolean editorShowsExternalFile = project != null;
if (editorShowsExternalFile) {
return false;
}
}
}
return super.isEditable();
}
/**
* Provides input so that the Project Explorer can locate the editor's input in its tree.
*/
@Override
public ShowInContext getShowInContext() {
IEditorInput editorInput = getEditorInput();
if (editorInput instanceof FileEditorInput) {
FileEditorInput fei = (FileEditorInput) getEditorInput();
return new ShowInContext(fei.getFile(), null);
} else if (editorInput instanceof XtextReadonlyEditorInput) {
XtextReadonlyEditorInput readOnlyEditorInput = (XtextReadonlyEditorInput) editorInput;
IStorage storage;
try {
storage = readOnlyEditorInput.getStorage();
return new ShowInContext(storage.getFullPath(), null);
} catch (CoreException e) {
// Do nothing
}
}
return new ShowInContext(null, null);
}
static IResource getAdapter(final IEditorReference ref) {
IEditorInput input;
try {
input = ref.getEditorInput();
} catch (final PartInitException e) {
// ignore if factory can't restore input, see bug 461786
return null;
}
if (input instanceof FileEditorInput) {
final FileEditorInput fi = (FileEditorInput) input;
final IFile file = fi.getFile();
if (file != null) { return file; }
}
// here we can only guess how the input might be related to a resource
final IFile adapter = CloseResourceAction.getAdapter(input, IFile.class);
if (adapter != null) { return adapter; }
return CloseResourceAction.getAdapter(input, IResource.class);
}
static IResource getAdapter(final IEditorReference ref) {
IEditorInput input;
try {
input = ref.getEditorInput();
} catch (final PartInitException e) {
// ignore if factory can't restore input, see bug 461786
return null;
}
if (input instanceof FileEditorInput) {
final FileEditorInput fi = (FileEditorInput) input;
final IFile file = fi.getFile();
if (file != null) { return file; }
}
// here we can only guess how the input might be related to a resource
final IFile adapter = getAdapter(input, IFile.class);
if (adapter != null) { return adapter; }
return getAdapter(input, IResource.class);
}
/**
* 获取数据源
* @param editorInput
* @return ;
*/
@SuppressWarnings("unchecked")
public T getDataSource(IEditorInput editorInput) {
if (editorInput instanceof FileEditorInput) {
if (editorInput instanceof FileEditorInput) {
FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
IFile file = fileEditorInput.getFile();
return this.getDataSource(file);
}
} else if (editorInput instanceof FileStoreEditorInput) {
FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) editorInput;
Object obj = map.get(generateKey(fileStoreEditorInput));
if (dataSourceClass.isInstance(obj)) {
return (T) obj;
}
}
return null;
}
/**
* 获取数据源
* @param editorInput
* @return ;
*/
@SuppressWarnings("unchecked")
public T getDataSource(IEditorInput editorInput) {
if (editorInput instanceof FileEditorInput) {
if (editorInput instanceof FileEditorInput) {
FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
IFile file = fileEditorInput.getFile();
return this.getDataSource(file);
}
} else if (editorInput instanceof FileStoreEditorInput) {
FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) editorInput;
Object obj = map.get(generateKey(fileStoreEditorInput));
if (dataSourceClass.isInstance(obj)) {
return (T) obj;
}
}
return null;
}
public boolean test( Object receiver, String property, Object[] args,
Object expectedValue )
{
if ( property.equals( "isRptdesign" ) )//$NON-NLS-1$
{
IFile file = null;
if ( receiver instanceof FileEditorInput )
{
FileEditorInput input = (FileEditorInput) receiver;
if ( input.getFile( ) != null
&& IReportElementConstants.DESIGN_FILE_EXTENSION.equals( input.getFile( )
.getFileExtension( ) ) )
{
return true;
}
}
}
return false;
}
@Override
public void resourceChanged(IResourceChangeEvent e) {
IResourceDelta delta = e.getDelta();
final FileEditorInput fInput = (FileEditorInput) getEditorInput();
final IFile file = fInput.getFile();
if (delta != null) {
delta = delta.findMember(file.getFullPath());
}
if (delta != null) {
final int flags = delta.getFlags();
if (delta.getKind() == IResourceDelta.REMOVED && (IResourceDelta.MOVED_TO & flags) != 0) {
updateEditorInput(
new FileEditorInput(file.getWorkspace().getRoot().getFile(delta.getMovedToPath())));
} else if (delta.getKind() == IResourceDelta.CHANGED) {
if ((flags & IResourceDelta.CONTENT) != 0 || (flags & IResourceDelta.REPLACED) != 0) {
if (!resourceChangeEventSkip) {
FileEditorInput newEditorInput = new FileEditorInput(delta.getResource().getAdapter(IFile.class));
Display.getDefault().asyncExec(() -> updateEditorInput(newEditorInput));
}
}
}
}
}
/**
* This method gets the file that is currently opened in the editor as an {@link IFile}.
*
* @param part Editor part that contains the file.
* @return Currently open file.
*/
public static IFile getCurrentlyOpenFile(final IEditorPart part) {
if (part != null) {
final IEditorInput editorInput = part.getEditorInput();
if (editorInput instanceof FileEditorInput) {
final FileEditorInput inputFile = (FileEditorInput) part.getEditorInput();
return inputFile.getFile();
}
}
return null;
}
public void init(IEditorSite site, IEditorInput input) throws PartInitException
{
tlaEditorInput = input;
if (input instanceof FileEditorInput)
{
FileEditorInput finput = (FileEditorInput) input;
if (finput != null)
{
final IFile file = finput.getFile();
if (ResourceHelper.isModule(file))
{
// MAK 04/2019: Strip off filename extension to align with Toolbox's Spec
// Explorer which doesn't show the extension either. The Toolbox only has
// two editors (TLA+ specs and TLC models). Showing the extension thus
// provides little value to users. Also, the editor description shows the
// full path to the actual file on disk right below where the part name
// is shown.
this.setPartName(file.getName().replaceFirst(".tla$", ""));
}
if (ResourceHelper.isRoot(file))
{
setTitleImage(rootImage);
}
}
}
super.init(site, input);
}
@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
setSite(site);
final FileEditorInput fi = (FileEditorInput) input;
file = fi.getFile();
final IPath path = fi.getPath();
final File f = path.makeAbsolute().toFile();
try {
pathStr = f.getAbsolutePath();
final ShapefileDataStore store = new ShapefileDataStore(f.toURI().toURL());
store.setCharset(Charset.forName("UTF8"));
content = new MapContent();
featureSource = store.getFeatureSource();
style = Utils.createStyle2(featureSource);
layer = new FeatureLayer(featureSource, style);
mode = determineMode(featureSource.getSchema(), "Polygon");
final List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
if (ftsList.size() > 0) {
fts = ftsList.get(0);
} else {
fts = null;
}
if (fts != null) {
this.setFillColor(PreferencesHelper.SHAPEFILE_VIEWER_FILL.getValue(), mode, fts);
this.setStrokeColor(PreferencesHelper.SHAPEFILE_VIEWER_LINE_COLOR.getValue(), mode, fts);
((StyleLayer) layer).setStyle(style);
}
content.addLayer(layer);
} catch (final IOException e) {
DEBUG.ERR("Unable to view file " + path);
}
this.setPartName(path.lastSegment());
setInput(input);
}
/**
* 设置数据源
* @param editorInput
* @param dataSource
* @return ;
*/
public boolean setDataSource(IEditorInput editorInput, T dataSource) {
if (editorInput instanceof FileEditorInput) {
FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
IFile file = fileEditorInput.getFile();
return setDataSource(file, dataSource);
} else if (editorInput instanceof FileStoreEditorInput) {
FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) editorInput;
map.put(generateKey(fileStoreEditorInput), dataSource);
return true;
}
return false;
}
public XSPPropBean(DesignerProject desPrj, XSPPropBeanLoader dbl, XSPParentEditor dbEditor, FileEditorInput fei, XSPDesignPropsBean designProps) {
this.desProject = desPrj;
this.ourEditor = dbEditor;
dbLoader = dbl;
xspPropFile = fei.getFile();
xspDesignProps = designProps;
}
/**
* 设置数据源
* @param editorInput
* @param dataSource
* @return ;
*/
public boolean setDataSource(IEditorInput editorInput, T dataSource) {
if (editorInput instanceof FileEditorInput) {
FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
IFile file = fileEditorInput.getFile();
return setDataSource(file, dataSource);
} else if (editorInput instanceof FileStoreEditorInput) {
FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) editorInput;
map.put(generateKey(fileStoreEditorInput), dataSource);
return true;
}
return false;
}
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element, ICasDocument document,
boolean overwrite) throws CoreException {
if (element instanceof FileEditorInput) {
FileEditorInput fileInput = (FileEditorInput) element;
IFile file = fileInput.getFile();
if (document instanceof DocumentUimaImpl) {
DocumentUimaImpl documentImpl = (DocumentUimaImpl) document;
ByteArrayOutputStream outStream = new ByteArrayOutputStream(40000);
documentImpl.serialize(outStream);
InputStream stream = new ByteArrayInputStream(outStream.toByteArray());
isFileChangeTrackingEnabled = false;
try {
file.setContents(stream, true, false, null);
}
finally {
isFileChangeTrackingEnabled = true;
}
}
}
// tell everyone that the element changed and is not dirty any longer
fireElementDirtyStateChanged(element, false);
}
public Object execute(ExecutionEvent event) throws ExecutionException {
boolean isMultiFile = false;
IFile multiTempIFile = null;
IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
// 改为布局
if (editorPart != null && editorPart instanceof XLIFFEditorImplWithNatTable) {
String qaItem = event.getParameter("qaItemId");
XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) editorPart;
ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
FileEditorInput input = (FileEditorInput) nattable.getEditorInput();
// 首先判断是否是合并打开的文件
if (nattable.isMultiFile()) {
isMultiFile = true;
}
if (isMultiFile) {
multiTempIFile = input.getFile();
List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
for (String filePath : multiFilesList) {
selectIFiles.add(ResourceUtils.fileToIFile(filePath));
}
} else {
selectIFiles.add(input.getFile());
}
QAModel model = new QAModel();
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
shell = window.getShell();
// 先调用方法,查看品质检查结果视图是否处于显示状态,如果是显示的,就删除数据
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = workbenchPage.findView(QAResultViewPart.ID);
if (view != null) {
// 运行时,将结果视图中列表的数据清除
((QAResultViewPart) view).clearTableData();
}
QAResult qaResult = new QAResult();
// 存储品质检查的检查项
// model.setBatchQAItemIdList(getBatchQAItems());
// 存储品质检查的检查时不包括的文本段
model.setNotInclude(getNotIncludePara());
// 给品质检查结果视图发出通告,本次检查对象为合并打开文件
qaResult.firePropertyChange(isMultiFile, new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles,
multiTempIFile));
if (isMultiFile) {
model.setMuliFiles(true);
model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles,multiTempIFile));
} else {
model.setMuliFiles(false);
}
boolean isNumberQA = false;
if (QAConstant.QA_NUMBER.equals(qaItem)) {
isNumberQA = true;
} else if (QAConstant.QA_TAG.equals(qaItem)) {
isNumberQA = false;
}
List<String> fileList = new ArrayList<String>();
for(IFile iFIle : selectIFiles){
fileList.add(iFIle.getLocation().toOSString());
}
qaResult.setFilePathList(fileList);
HsMultiActiveCellEditor.commit(true);
beginQA(selectIFiles, model, isNumberQA, qaResult);
}
return null;
}
public Object execute(ExecutionEvent event) throws ExecutionException {
boolean isMultiFile = false;
IFile multiTempIFile = null;
IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
// 改为布局
if (editorPart != null && editorPart instanceof XLIFFEditorImplWithNatTable) {
String qaItem = event.getParameter("qaItemId");
XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) editorPart;
ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
FileEditorInput input = (FileEditorInput) nattable.getEditorInput();
// 首先判断是否是合并打开的文件
if (nattable.isMultiFile()) {
isMultiFile = true;
}
if (isMultiFile) {
multiTempIFile = input.getFile();
List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
for (String filePath : multiFilesList) {
selectIFiles.add(ResourceUtils.fileToIFile(filePath));
}
} else {
selectIFiles.add(input.getFile());
}
QAModel model = new QAModel();
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
shell = window.getShell();
// 先调用方法,查看品质检查结果视图是否处于显示状态,如果是显示的,就删除数据
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = workbenchPage.findView(QAResultViewPart.ID);
if (view != null) {
// 运行时,将结果视图中列表的数据清除
((QAResultViewPart) view).clearTableData();
}
QAResult qaResult = new QAResult();
// 存储品质检查的检查项
// model.setBatchQAItemIdList(getBatchQAItems());
// 存储品质检查的检查时不包括的文本段
model.setNotInclude(getNotIncludePara());
// 给品质检查结果视图发出通告,本次检查对象为合并打开文件
qaResult.firePropertyChange(isMultiFile, new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles,
multiTempIFile));
if (isMultiFile) {
model.setMuliFiles(true);
model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles,multiTempIFile));
} else {
model.setMuliFiles(false);
}
boolean isNumberQA = false;
if (QAConstant.QA_NUMBER.equals(qaItem)) {
isNumberQA = true;
} else if (QAConstant.QA_TAG.equals(qaItem)) {
isNumberQA = false;
}
HsMultiActiveCellEditor.commit(true);
beginQA(selectIFiles, model, isNumberQA, qaResult);
}
return null;
}