Search in sources :

Example 1 with IPathEditorInput

use of org.eclipse.ui.IPathEditorInput in project dbeaver by serge-rider.

the class ImageEditorPart method loadImage.

private void loadImage() {
    if (imageViewer == null || imageViewer.isDisposed()) {
        return;
    }
    if (getEditorInput() instanceof IPathEditorInput) {
        try {
            final IPath absolutePath = ((IPathEditorInput) getEditorInput()).getPath();
            File localFile = absolutePath.toFile();
            if (localFile.exists()) {
                try (InputStream inputStream = new FileInputStream(localFile)) {
                    contentValid = imageViewer.loadImage(inputStream);
                    imageViewer.update();
                }
            }
        } catch (Exception e) {
            log.error("Can't load image contents", e);
        }
    }
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IPath(org.eclipse.core.runtime.IPath) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) PartInitException(org.eclipse.ui.PartInitException)

Example 2 with IPathEditorInput

use of org.eclipse.ui.IPathEditorInput in project dbeaver by serge-rider.

the class ImageEditorPart method resourceChanged.

@Override
public void resourceChanged(IResourceChangeEvent event) {
    IResourceDelta delta = event.getDelta();
    if (delta == null) {
        return;
    }
    IEditorInput input = getEditorInput();
    IPath localPath = null;
    if (input instanceof IPathEditorInput) {
        localPath = ((IPathEditorInput) input).getPath();
    }
    if (localPath == null) {
        return;
    }
    localPath = ContentUtils.convertPathToWorkspacePath(localPath);
    delta = delta.findMember(localPath);
    if (delta == null) {
        return;
    }
    if (delta.getKind() == IResourceDelta.CHANGED) {
        // Refresh editor
        DBeaverUI.asyncExec(new Runnable() {

            @Override
            public void run() {
                loadImage();
            }
        });
    }
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IPath(org.eclipse.core.runtime.IPath) IEditorInput(org.eclipse.ui.IEditorInput) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Aggregations

IPath (org.eclipse.core.runtime.IPath)2 IPathEditorInput (org.eclipse.ui.IPathEditorInput)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 IEditorInput (org.eclipse.ui.IEditorInput)1 PartInitException (org.eclipse.ui.PartInitException)1