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

The following examples show how to use org.eclipse.ui.part.FileEditorInput#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: N4JSEditor.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: AbstractEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@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));
                }
            }
        }
    }
}
 
Example 3
Source File: ScriptDebuggerPropertyTester.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: DataSourceHelper.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获取数据源
 * @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;
}
 
Example 5
Source File: DataSourceHelper.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获取数据源
 * @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;
}
 
Example 6
Source File: CloseResourceAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example 7
Source File: DeleteResourceAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example 8
Source File: N4JSEditor.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@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();
}
 
Example 9
Source File: ShapeFileViewer.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example 10
Source File: DataSourceHelper.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置数据源
 * @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;
}
 
Example 11
Source File: XSPPropBean.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: TLAEditorAndPDFViewer.java    From tlaplus with MIT License 5 votes vote down vote up
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);
}
 
Example 13
Source File: DataSourceHelper.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置数据源
 * @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;
}
 
Example 14
Source File: UIUtils.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source File: DefaultCasDocumentProvider.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 16
Source File: NumberOrTagConsisQAHandler.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 17
Source File: NumberOrTagConsisQAHandler.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
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;
}