| /******************************************************************************* |
| * Copyright (c) 2010 Zoltan Ujhelyi and Istvan Rath and Daniel Varro. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.viatra2.visualisation.common.labelproviders; |
| |
| import org.eclipse.draw2d.IFigure; |
| import org.eclipse.swt.graphics.Color; |
| import org.eclipse.viatra2.core.IModelElement; |
| import org.eclipse.zest.core.viewers.IFigureProvider; |
| |
| /** |
| * Simple label provider that delegates the creation of custom figures to a factory. |
| * If no figure is created, it behaves like the smart label provider. |
| * @author istvan rath |
| * |
| */ |
| public class ImageLabelProvider extends HighlightableSmartLabelProvider implements IFigureProvider |
| { |
| |
| IFigureFactory factory; |
| |
| public void setFactory(IFigureFactory factory) { |
| this.factory = factory; |
| } |
| |
| |
| public IFigure getFigure(Object element) { |
| if (factory!=null) { |
| return factory.createFigure(element); |
| } |
| return null; |
| } |
| |
| @Override |
| public Color getBackgroundColour(Object entity) { |
| if (getFigure(entity)!=null) { |
| // we have a custom figure |
| // no background unless we are highlighted |
| if (isHighlighted((IModelElement)entity)) { |
| return super.getBackgroundColour(entity); |
| } |
| else { |
| return null; |
| } |
| } |
| return super.getBackgroundColour(entity); |
| } |
| |
| } |