Search in sources :

Example 1 with IFileState

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();
}
Also used : IFileRevision(org.eclipse.team.core.history.IFileRevision) IFileState(org.eclipse.core.resources.IFileState) Date(java.util.Date)

Example 2 with IFileState

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();
            }
        };
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IFileState(org.eclipse.core.resources.IFileState)

Example 3 with IFileState

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();
            }
        };
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IFileState(org.eclipse.core.resources.IFileState)

Example 4 with IFileState

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);
    }
}
Also used : IFileState(org.eclipse.core.resources.IFileState) IFile(org.eclipse.core.resources.IFile) Point(org.eclipse.swt.graphics.Point) DBException(org.jkiss.dbeaver.DBException)

Example 5 with IFileState

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);
    }
}
Also used : IFileState(org.eclipse.core.resources.IFileState) IFile(org.eclipse.core.resources.IFile) Point(org.eclipse.swt.graphics.Point) DBException(org.jkiss.dbeaver.DBException)

Aggregations

IFileState (org.eclipse.core.resources.IFileState)5 IFile (org.eclipse.core.resources.IFile)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 CoreException (org.eclipse.core.runtime.CoreException)2 Point (org.eclipse.swt.graphics.Point)2 DBException (org.jkiss.dbeaver.DBException)2 Date (java.util.Date)1 IFileRevision (org.eclipse.team.core.history.IFileRevision)1