blob: 06e383960d42f5a1d0442f0e83b68e4b86c310bf [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011-2014 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:
* Eugen Neufeld - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.ecp.edit.spi.swt.table;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.property.value.IValueProperty;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.databinding.viewers.CellEditorProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
/**
* A String cell editor which displays strings.
*
* @author Eugen Neufeld
* @since 1.5
*
*/
public class StringCellEditor extends StringBasedCellEditor {
private EStructuralFeature eStructuralFeature;
/**
* Default constructor.
*/
public StringCellEditor() {
super();
}
/**
* A constructor which takes only a parent.
*
* @param parent the {@link Composite} to use as a parent.
*/
public StringCellEditor(Composite parent) {
super(parent);
}
/**
* A constructor which takes the parent and the style.
*
* @param parent the {@link Composite} to use as a parent
* @param style the Style to set
*/
public StringCellEditor(Composite parent, int style) {
super(parent, style);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.edit.spi.swt.table.ECPCellEditor#getValueProperty()
*/
@Override
public IValueProperty getValueProperty() {
return CellEditorProperties.control().value(WidgetProperties.text(SWT.FocusOut));
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.edit.spi.swt.table.ECPCellEditor#instantiate(org.eclipse.emf.ecore.EStructuralFeature,
* org.eclipse.emf.ecp.view.spi.context.ViewModelContext)
*/
@Override
public void instantiate(EStructuralFeature feature, ViewModelContext viewModelContext) {
eStructuralFeature = feature;
}
/**
*
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.edit.spi.swt.table.ECPCellEditor#getFormatedString(java.lang.Object)
*/
@Override
public String getFormatedString(Object value) {
if (value == null) {
return ""; //$NON-NLS-1$
}
return String.valueOf(value);
}
/**
*
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.edit.spi.swt.table.ECPCellEditor#getColumnWidthWeight()
*/
@Override
public int getColumnWidthWeight() {
return 100;
}
/**
*
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.edit.spi.swt.table.ECPCellEditor#getTargetToModelStrategy(org.eclipse.core.databinding.DataBindingContext)
* @since 1.6
*/
@Override
public UpdateValueStrategy getTargetToModelStrategy(DataBindingContext databindingContext) {
return withPreSetValidation(eStructuralFeature, new UpdateValueStrategy());
}
/**
*
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.edit.spi.swt.table.ECPCellEditor#getModelToTargetStrategy(org.eclipse.core.databinding.DataBindingContext)
* @since 1.6
*/
@Override
public UpdateValueStrategy getModelToTargetStrategy(DataBindingContext databindingContext) {
return null;
}
/**
*
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.edit.spi.swt.table.ECPCellEditor#setEditable(boolean)
*/
@Override
public void setEditable(boolean editable) {
if (text != null) {
text.setEditable(editable);
}
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.edit.spi.swt.table.ECPCellEditor#getImage(java.lang.Object)
*/
@Override
public Image getImage(Object value) {
return null;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.ecp.edit.spi.swt.table.ECPCellEditor#getMinWidth()
* @since 1.6
*/
@Override
public int getMinWidth() {
return 0;
}
}