sernet.verinice.rcp.ImportDecorator.java Source code

Java tutorial

Introduction

Here is the source code for sernet.verinice.rcp.ImportDecorator.java

Source

/*******************************************************************************
 * Copyright (c) 2010 Daniel Murygin.
 *
 * This program is free software: you can redistribute it and/or 
 * modify it under the terms of the GNU Lesser General Public License 
 * as published by the Free Software Foundation, either version 3 
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,    
 * but WITHOUT ANY WARRANTY; without even the implied warranty 
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. 
 * If not, see <http://www.gnu.org/licenses/>.
 * 
 * Contributors:
 *     Daniel Murygin <dm[at]sernet[dot]de> - initial API and implementation
 ******************************************************************************/
package sernet.verinice.rcp;

import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
import org.eclipse.jface.viewers.LabelProvider;

import sernet.gs.ui.rcp.main.Activator;
import sernet.gs.ui.rcp.main.ImageCache;
import sernet.gs.ui.rcp.main.preferences.PreferenceConstants;
import sernet.verinice.model.common.CnATreeElement;

/**
 * @author Daniel Murygin <dm[at]sernet[dot]de>
 *
 */
public class ImportDecorator extends LabelProvider implements ILightweightLabelDecorator {

    public static final String IMAGE_PATH = "overlays/alien.png";

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object, org.eclipse.jface.viewers.IDecoration)
     */
    @Override
    public void decorate(Object o, IDecoration decoration) {
        if (o instanceof CnATreeElement) {
            CnATreeElement element = (CnATreeElement) o;
            if (element.getSourceId() != null && Activator.getDefault().getPluginPreferences()
                    .getBoolean(PreferenceConstants.SHOW_ALIEN_DECORATOR)) {
                decoration.addOverlay(ImageCache.getInstance().getImageDescriptor(IMAGE_PATH));
                decoration.addSuffix(new StringBuilder().append(" [").append(((CnATreeElement) o).getSourceId())
                        .append("]").toString());
            }
        }
    }
}