blob: 1de6ffabf9def7a21879f6247030a23039700db5 [file] [log] [blame]
/**
* Copyright (c) 2009-2010 Thales Corporate Services S.A.S.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales Corporate Services S.A.S - initial API and implementation
*/
package org.eclipse.egf.producer.ui.decorators;
import org.eclipse.egf.core.ui.EGFCoreUIPlugin;
import org.eclipse.egf.core.ui.IEGFCoreUIImages;
import org.eclipse.egf.model.fcore.Contract;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
/**
* Decorate ActivityContract with an overlay to enlight mandatory contract.
*
* @author Xavier Maysonnave
*/
public class MandatoryLabelDecorator implements ILightweightLabelDecorator {
private ImageDescriptor _mandatoryImage;
/**
* @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object,
* org.eclipse.jface.viewers.IDecoration)
*/
public void decorate(Object element, IDecoration decoration) {
if (element instanceof Contract) {
Contract contract = (Contract) element;
if (contract.isMandatory()) {
decoration.addOverlay(getMandatoryImage());
}
}
}
/**
* Return the image for the decoration that should be used to cue the user that a field is
* required.
*
* @return a not null image.
*/
private ImageDescriptor getMandatoryImage() {
if (_mandatoryImage == null) {
_mandatoryImage = EGFCoreUIPlugin.getDefault().getImageDescriptor(IEGFCoreUIImages.IMG_MANDATORY);
}
return _mandatoryImage;
}
/**
* @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
*/
public void addListener(ILabelProviderListener listener_p) {
// Do nothing.
}
/**
* @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
*/
public void dispose() {
_mandatoryImage = null;
}
/**
* @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object,
* java.lang.String)
*/
public boolean isLabelProperty(Object element_p, String property_p) {
return false;
}
/**
* @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
*/
public void removeListener(ILabelProviderListener listener_p) {
// Do nothing.
}
}