blob: 6fe0eae9df1a8a1f405d58fdd12cf8d423c4ce85 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2012, 2021 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.internal.r.ui.pkgmanager;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.graphics.Image;
public class StatusLabelProvider extends CellLabelProvider {
public StatusLabelProvider() {
}
@Override
public void update(final ViewerCell cell) {
final Object element= cell.getElement();
if (element instanceof IStatus) {
final IStatus status= (IStatus) element;
cell.setImage(getImage(status));
cell.setText(status.getMessage());
}
else {
throw new IllegalArgumentException();
}
}
public Image getImage(final IStatus status) {
switch (status.getSeverity()) {
case IStatus.ERROR:
return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
case IStatus.WARNING:
return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
default:
return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
}
}
@Override
public Image getToolTipImage(final Object element) {
if (element instanceof IStatus) {
return getImage((IStatus) element);
}
return null;
}
@Override
public String getToolTipText(final Object element) {
if (element instanceof IStatus) {
return ((IStatus) element).getMessage();
}
return null;
}
}