Search in sources :

Example 1 with IJobErrorHandler

use of org.csstudio.swt.widgets.util.IJobErrorHandler in project yamcs-studio by yamcs.

the class NativeButtonFigure method setImagePath.

@SuppressWarnings("nls")
public void setImagePath(final IPath path) {
    if (image != null) {
        image.dispose();
        image = null;
        button.setImage(null);
    }
    AbstractInputStreamRunnable uiTask = new AbstractInputStreamRunnable() {

        @Override
        public void runWithInputStream(InputStream stream) {
            image = new Image(null, stream);
            try {
                stream.close();
            } catch (IOException e) {
            }
            if (!button.isDisposed()) {
                button.setImage(image);
            }
        }
    };
    if (path != null && !path.isEmpty()) {
        ResourceUtil.pathToInputStreamInJob(path, uiTask, "Load Button Icon...", new IJobErrorHandler() {

            @Override
            public void handleError(Exception exception) {
                image = null;
                ErrorHandlerUtil.handleError("Failed to load button icon.", exception);
            }
        });
    }
}
Also used : AbstractInputStreamRunnable(org.csstudio.swt.widgets.util.AbstractInputStreamRunnable) InputStream(java.io.InputStream) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) IJobErrorHandler(org.csstudio.swt.widgets.util.IJobErrorHandler) IOException(java.io.IOException)

Example 2 with IJobErrorHandler

use of org.csstudio.swt.widgets.util.IJobErrorHandler in project yamcs-studio by yamcs.

the class ActionButtonFigure method setImagePath.

@SuppressWarnings("nls")
public void setImagePath(final IPath path) {
    dispose();
    AbstractInputStreamRunnable uiTask = new AbstractInputStreamRunnable() {

        @Override
        public void runWithInputStream(InputStream stream) {
            image = new Image(null, stream);
            try {
                stream.close();
            } catch (IOException e) {
            }
            if (label.isEnabled())
                label.setIcon(image);
            else {
                if (grayImage == null && image != null)
                    grayImage = new Image(null, image, SWT.IMAGE_GRAY);
                label.setIcon(grayImage);
            }
            calculateTextPosition();
        }
    };
    if (path != null && !path.isEmpty()) {
        this.imagePath = path;
        ResourceUtil.pathToInputStreamInJob(path, uiTask, "Load Action Button Icon...", new IJobErrorHandler() {

            @Override
            public void handleError(Exception exception) {
                image = null;
                Activator.getLogger().log(Level.WARNING, "Failed to load image from path" + path, exception);
            }
        });
    }
    if (label.isEnabled())
        label.setIcon(image);
    else {
        if (grayImage == null && image != null)
            grayImage = new Image(null, image, SWT.IMAGE_GRAY);
        label.setIcon(grayImage);
    }
    calculateTextPosition();
}
Also used : AbstractInputStreamRunnable(org.csstudio.swt.widgets.util.AbstractInputStreamRunnable) InputStream(java.io.InputStream) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) IJobErrorHandler(org.csstudio.swt.widgets.util.IJobErrorHandler) IOException(java.io.IOException) IntrospectionException(java.beans.IntrospectionException)

Example 3 with IJobErrorHandler

use of org.csstudio.swt.widgets.util.IJobErrorHandler in project yamcs-studio by yamcs.

the class TabEditPart method setTabFigureProperty.

private void setTabFigureProperty(int index, TabProperty tabProperty, final Object newValue) {
    Label label = getTabFigure().getTabLabel(index);
    switch(tabProperty) {
        case TITLE:
            label.setText((String) newValue);
            updateTabAreaSize();
            break;
        case FONT:
            label.setFont(((OPIFont) newValue).getSWTFont());
            updateTabAreaSize();
            break;
        case BACKCOLOR:
            getTabFigure().setTabColor(index, ((OPIColor) newValue).getSWTColor());
            break;
        case FORECOLOR:
            label.setForegroundColor(CustomMediaFactory.getInstance().getColor(((OPIColor) newValue).getRGBValue()));
            break;
        case ENABLED:
            getTabFigure().setTabEnabled(index, (Boolean) newValue);
            break;
        case ICON_PATH:
            getTabFigure().setIconPath(index, getWidgetModel().toAbsolutePath((IPath) newValue), new IJobErrorHandler() {

                @Override
                public void handleError(Exception e) {
                    String message = "Failed to load image from " + newValue + "\n" + e;
                    Activator.getLogger().log(Level.WARNING, message, e);
                    ConsoleService.getInstance().writeError(message);
                }
            });
            break;
        default:
            break;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Label(org.eclipse.draw2d.Label) IJobErrorHandler(org.csstudio.swt.widgets.util.IJobErrorHandler) OPIColor(org.csstudio.opibuilder.util.OPIColor)

Example 4 with IJobErrorHandler

use of org.csstudio.swt.widgets.util.IJobErrorHandler in project yamcs-studio by yamcs.

the class GIFSymbolImage method asyncLoadImage.

@Override
public void asyncLoadImage() {
    if (imagePath == null)
        return;
    loadingImage = true;
    if (animated) {
        stopAnimation();
        showIndex = 0;
        animationIndex = 0;
    }
    // loading by stream
    loadAnimatedImage(new IJobErrorHandler() {

        private int maxAttempts = 5;

        @Override
        public void handleError(Exception e) {
            if (maxAttempts-- > 0) {
                try {
                    Thread.sleep(100);
                    loadAnimatedImage(this);
                    return;
                } catch (InterruptedException exception) {
                }
            }
            loadingImage = false;
            // fireSymbolImageLoaded();
            Activator.getLogger().log(Level.WARNING, "ERROR in loading GIF image " + imagePath, e);
        }
    });
}
Also used : IJobErrorHandler(org.csstudio.swt.widgets.util.IJobErrorHandler) IOException(java.io.IOException)

Example 5 with IJobErrorHandler

use of org.csstudio.swt.widgets.util.IJobErrorHandler in project yamcs-studio by yamcs.

the class PNGSymbolImage method asyncLoadImage.

public void asyncLoadImage() {
    if (imagePath == null)
        return;
    loadingImage = true;
    loadImage(new IJobErrorHandler() {

        private int maxAttempts = 5;

        public void handleError(Exception exception) {
            if (maxAttempts-- > 0) {
                try {
                    Thread.sleep(100);
                    loadImage(this);
                    return;
                } catch (InterruptedException e) {
                }
            }
            loadingImage = false;
            // fireSymbolImageLoaded();
            Activator.getLogger().log(Level.WARNING, "ERROR in loading PNG image " + imagePath, exception);
        }
    });
}
Also used : IJobErrorHandler(org.csstudio.swt.widgets.util.IJobErrorHandler) IOException(java.io.IOException)

Aggregations

IJobErrorHandler (org.csstudio.swt.widgets.util.IJobErrorHandler)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)2 AbstractInputStreamRunnable (org.csstudio.swt.widgets.util.AbstractInputStreamRunnable)2 Image (org.eclipse.swt.graphics.Image)2 IntrospectionException (java.beans.IntrospectionException)1 OPIColor (org.csstudio.opibuilder.util.OPIColor)1 IPath (org.eclipse.core.runtime.IPath)1 Label (org.eclipse.draw2d.Label)1