blob: ec36a3cb512a3747e08347e1d46e18a4415d2297 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2017 EclipseSource Muenchen GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Edgar Mueller - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.ecp.edit.spi.swt.table;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecp.view.spi.model.VViewPackage;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Composite;
/**
* Common base class for combo-based enum cell editors.
*
* @since 1.13
*/
public abstract class ECPEnumCellEditor extends CellEditor implements ECPCellEditor {
/**
* Constructor.
*
* @param parent the parent {@link Composite}
*/
public ECPEnumCellEditor(Composite parent) {
super(parent);
}
/**
* Constructor.
*
* @param parent the parent {@link Composite}
* @param style SWT style bits
*/
public ECPEnumCellEditor(Composite parent, int style) {
super(parent, style);
}
/**
* Returns the {@link EEnum} is cell editor responsible for.
*
* @return the enum
*/
public abstract EEnum getEEnum();
/**
* Returns the list of literals of the enum.
*
* @return a list of literals
*
* @see #getEEnum
*/
public List<EEnumLiteral> getELiterals() {
final List<EEnumLiteral> filtered = new ArrayList<EEnumLiteral>();
final EList<EEnumLiteral> eLiterals = getEEnum().getELiterals();
for (final EEnumLiteral literal : eLiterals) {
final String isInputtable = EcoreUtil.getAnnotation(literal,
VViewPackage.NS_URI_170,
"isInputtable"); //$NON-NLS-1$
if (isInputtable == null || Boolean.getBoolean(isInputtable)) {
filtered.add(literal);
}
}
return filtered;
}
}