blob: f8f0b11bd4b4364b6784196811e7816f5f5cf6b3 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2015 ALL4TEC & CEA LIST.
* 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:
* ALL4TEC & CEA LIST - initial API and implementation
******************************************************************************/
package org.polarsys.esf.core.common.ui.filter;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.uml2.uml.NamedElement;
/**
* Custom implementation of filter, using the name property
* of the object on which is applied the filter.
*
* The object must implements {@link IAbstractNamedObject}, otherwise
* the parent {@link ToStringFilter} is applied.
*
* @author $Author: jdumont $
* @version $Revision: 83 $
*/
public class NamePropertyFilter
extends ToStringFilter {
/**
* Default constructor.
*/
public NamePropertyFilter() {
super();
}
/**
* {@inheritDoc}
*
* Return the result of the {@link #toString()} method applied
* on the element, to apply the filter on this value.
*
* @return The value of the {@link #toString()} method applied on the given element
*/
@Override
protected String getFilterPropertyValue(final Object pElement) {
String vFilteredValue = StringUtils.EMPTY;
if (pElement instanceof NamedElement) {
// Get the name value to apply the filter
vFilteredValue = ((NamedElement) pElement).getName();
} else {
// Call the parent method to get the toString value to apply the filter
vFilteredValue = super.getFilterPropertyValue(pElement);
}
return vFilteredValue;
}
}