use of org.eclipse.core.resources.IFileState in project egit by eclipse.
the class FileRevisionEditorInput method getName.
@Override
public String getName() {
IFileRevision rev = AdapterUtils.adapt(this, IFileRevision.class);
if (rev != null) {
return NLS.bind(UIText.FileRevisionEditorInput_NameAndRevisionTitle, new String[] { rev.getName(), rev.getContentIdentifier() });
}
IFileState state = AdapterUtils.adapt(this, IFileState.class);
if (state != null) {
return state.getName() + ' ' + PreferenceBasedDateFormatter.create().formatDate(new Date(state.getModificationTime()));
}
return storage.getName();
}
use of org.eclipse.core.resources.IFileState in project che by eclipse.
the class FileUndoState method recordStateFromHistory.
public void recordStateFromHistory(IResource resource, IProgressMonitor monitor) throws CoreException {
Assert.isLegal(resource.getType() == IResource.FILE);
if (location != null) {
// file is linked, no need to record any history
return;
}
IFileState[] states = ((IFile) resource).getHistory(monitor);
if (states.length > 0) {
final IFileState state = getMatchingFileState(states);
this.fileContentDescription = new IFileContentDescription() {
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.ide.undo.IFileContentDescription#exists()
*/
public boolean exists() {
return state.exists();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.ide.undo.IFileContentDescription#getContents()
*/
public InputStream getContents() throws CoreException {
return state.getContents();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.ide.undo.IFileContentDescription#getCharset()
*/
public String getCharset() throws CoreException {
return state.getCharset();
}
};
}
}
use of org.eclipse.core.resources.IFileState in project che by eclipse.
the class FileDescription method recordStateFromHistory.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.ide.undo.ResourceDescription#recordStateFromHistory(org.eclipse.core.resources.IResource,
* org.eclipse.core.runtime.IProgressMonitor)
*/
public void recordStateFromHistory(IResource resource, IProgressMonitor monitor) throws CoreException {
Assert.isLegal(resource.getType() == IResource.FILE);
if (location != null) {
// file is linked, no need to record any history
return;
}
IFileState[] states = ((IFile) resource).getHistory(monitor);
if (states.length > 0) {
final IFileState state = getMatchingFileState(states);
this.fileContentDescription = new IFileContentDescription() {
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.ide.undo.IFileContentDescription#exists()
*/
public boolean exists() {
return state.exists();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.ide.undo.IFileContentDescription#getContents()
*/
public InputStream getContents() throws CoreException {
return state.getContents();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.internal.ide.undo.IFileContentDescription#getCharset()
*/
public String getCharset() throws CoreException {
return state.getCharset();
}
};
}
}
use of org.eclipse.core.resources.IFileState in project dbeaver by serge-rider.
the class SQLEditor method deleteFileIfEmpty.
private void deleteFileIfEmpty(IFile sqlFile) {
if (sqlFile == null || !sqlFile.exists()) {
return;
}
SQLPreferenceConstants.EmptyScriptCloseBehavior emptyScriptCloseBehavior = SQLPreferenceConstants.EmptyScriptCloseBehavior.getByName(getActivePreferenceStore().getString(SQLPreferenceConstants.SCRIPT_DELETE_EMPTY));
if (emptyScriptCloseBehavior == SQLPreferenceConstants.EmptyScriptCloseBehavior.NOTHING) {
return;
}
File osFile = sqlFile.getLocation().toFile();
if (!osFile.exists() || osFile.length() != 0) {
// Not empty
return;
}
try {
IProgressMonitor monitor = new NullProgressMonitor();
if (emptyScriptCloseBehavior == SQLPreferenceConstants.EmptyScriptCloseBehavior.DELETE_NEW) {
IFileState[] fileHistory = sqlFile.getHistory(monitor);
if (!ArrayUtils.isEmpty(fileHistory)) {
for (IFileState historyItem : fileHistory) {
try (InputStream contents = historyItem.getContents()) {
int cValue = contents.read();
if (cValue != -1) {
// At least once there was some content saved
return;
}
}
}
}
}
// This file is empty and never (at least during this session) had any contents.
// Drop it.
log.debug("Delete empty SQL script '" + sqlFile.getFullPath().toOSString() + "'");
sqlFile.delete(true, monitor);
} catch (Exception e) {
// $NON-NLS-1$
log.error("Can't delete empty script file", e);
}
}
use of org.eclipse.core.resources.IFileState in project dbeaver by dbeaver.
the class SQLEditor method deleteFileIfEmpty.
private void deleteFileIfEmpty(IFile sqlFile) {
if (sqlFile == null || !sqlFile.exists()) {
return;
}
SQLPreferenceConstants.EmptyScriptCloseBehavior emptyScriptCloseBehavior = SQLPreferenceConstants.EmptyScriptCloseBehavior.getByName(getActivePreferenceStore().getString(SQLPreferenceConstants.SCRIPT_DELETE_EMPTY));
if (emptyScriptCloseBehavior == SQLPreferenceConstants.EmptyScriptCloseBehavior.NOTHING) {
return;
}
File osFile = sqlFile.getLocation().toFile();
if (!osFile.exists() || osFile.length() != 0) {
// Not empty
return;
}
try {
IProgressMonitor monitor = new NullProgressMonitor();
if (emptyScriptCloseBehavior == SQLPreferenceConstants.EmptyScriptCloseBehavior.DELETE_NEW) {
IFileState[] fileHistory = sqlFile.getHistory(monitor);
if (!ArrayUtils.isEmpty(fileHistory)) {
for (IFileState historyItem : fileHistory) {
try (InputStream contents = historyItem.getContents()) {
int cValue = contents.read();
if (cValue != -1) {
// At least once there was some content saved
return;
}
}
}
}
}
// This file is empty and never (at least during this session) had any contents.
// Drop it.
log.debug("Delete empty SQL script '" + sqlFile.getFullPath().toOSString() + "'");
sqlFile.delete(true, monitor);
} catch (Exception e) {
// $NON-NLS-1$
log.error("Can't delete empty script file", e);
}
}
Aggregations