Skip to content
Snippets Groups Projects
Commit e9731644 authored by Johannes Eder's avatar Johannes Eder
Browse files

refactored

- removed all redundant classes AbstractDecoratedComplexCellWithTextStyledTextActionHandlerDatabindingEditingSupport, AbstractComplexCellWithTextStyledTextActionHandlerDatabindingEditingSupport, AbstractComplexCellDatabindingEditingSupport
- changed DataStateValueEditing Support so that complex cells are still supported
refs 2267
parent d31d5110
No related branches found
No related tags found
No related merge requests found
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2013 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.databinding;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationListener;
import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.widgets.Composite;
import org.fortiss.tooling.kernel.ui.util.DataBindingUtils;
/**
* TODO (see #2267): Comment?
* TODO (see #2267): This class should be factorized with AbstractTextCellDatabindingEditingSupport
*
* @author czhang
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating YELLOW Hash: FCB06A379AF54BCF157ACFDDCF1158A5
*/
public abstract class AbstractComplexCellDatabindingEditingSupport extends EditingSupport {
/** Cell editor. */
protected CellEditor cellEditor;
/** Data binding context. */
protected final DataBindingContext dbc;
/**
* Complex data bindings.
*
* @see DataBindingUtils#performCellTextBinding(DataBindingContext,
* org.eclipse.swt.widgets.Control, IObservableValue,
* org.eclipse.core.databinding.conversion.IConverter,
* org.eclipse.core.databinding.conversion.IConverter,
* org.eclipse.core.databinding.validation.IValidator)
*/
private Binding[] bindings;
/**
* Listener that destroys {@link Binding}s when the inline editor
* disappears.
*/
private final ColumnViewerEditorActivationListenerHelper activationListener =
new ColumnViewerEditorActivationListenerHelper();
/** Constructor. */
public AbstractComplexCellDatabindingEditingSupport(ColumnViewer viewer,
DataBindingContext bindingContext) {
super(viewer);
this.dbc = bindingContext;
}
/** Override this method to create another {@link CellEditor}. */
protected CellEditor createTextCellEditor(ColumnViewer viewer) {
CellEditor cellEditor = new TextCellEditor((Composite)viewer.getControl());
setupCellEditor(cellEditor);
return cellEditor;
}
/** Set up the new created {@link CellEditor}. */
protected abstract void setupCellEditor(CellEditor cellEditor);
/** Override this method to create another {@link CellEditor}. */
abstract protected CellEditor createComplexCellEditor(ColumnViewer viewer, Object model);
/** Set up dialog {@link CellEditor}. */
protected abstract boolean isComplexCellEditor(Object model);
/** {@inheritDoc} */
@Override
public final CellEditor getCellEditor(Object model) {
if(isComplexCellEditor(model)) {
cellEditor = createComplexCellEditor(getViewer(), model);
setupCellEditor(cellEditor);
} else {
cellEditor = createTextCellEditor(getViewer());
}
return cellEditor;
}
/** {@inheritDoc} */
@Override
protected boolean canEdit(Object element) {
return true;
}
/** {@inheritDoc} */
@Override
protected final Object getValue(Object element) {
// not needed
return null;
}
/** {@inheritDoc} */
@Override
protected final void setValue(Object element, Object value) {
// not needed
}
/** {@inheritDoc} */
@Override
protected void initializeCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
// reset cell editor, because null is not interpreted as empty string
// the value will be set afterwards if it is not null
this.cellEditor.setValue("");
bindings = createBinding(cellEditor, cell, this.cellEditor, dbc);
Assert.isTrue(bindings != null && bindings.length > 0 && bindings[0] != null,
"Illegal implementation: no binding returned.");
getViewer().getColumnViewerEditor().addEditorActivationListener(activationListener);
}
/**
* Creates the current bindings. Sub-classes need to return at least one
* binding. Furthermore, the first binding needs to be the binding that
* effectively stores the value to the model. This binding's
* {@link Binding#updateTargetToModel()} is called when the inline editor is
* closed. After that all the bindings returned here are disposed.
*/
protected abstract Binding[] createBinding(CellEditor cellEditor, ViewerCell cell,
CellEditor editor, DataBindingContext context);
/** {@inheritDoc} */
@Override
protected void saveCellEditorValue(CellEditor cellEditor, ViewerCell cell) {
if(bindings != null && bindings.length > 0 && bindings[0] != null) {
bindings[0].updateTargetToModel();
}
}
/**
* This listener disposes the bindings as soon as the inline editor is
* deactivated. This assures that no binding created by
* {@link #createBinding(CellEditor, ViewerCell, CellEditor, DataBindingContext)} is left behind
* in the {@link DataBindingContext}.
*/
private class ColumnViewerEditorActivationListenerHelper extends
ColumnViewerEditorActivationListener {
/** {@inheritDoc} */
@Override
public void afterEditorActivated(ColumnViewerEditorActivationEvent event) {
// do nothing
}
/** {@inheritDoc} */
@Override
public void afterEditorDeactivated(ColumnViewerEditorDeactivationEvent event) {
if(bindings != null) {
for(final Binding binding : bindings) {
if(binding != null) {
binding.dispose();
}
}
bindings = null;
}
getViewer().getColumnViewerEditor().removeEditorActivationListener(this);
}
/** {@inheritDoc} */
@Override
public void beforeEditorActivated(ColumnViewerEditorActivationEvent event) {
// do nothing
}
/** {@inheritDoc} */
@Override
public void beforeEditorDeactivated(ColumnViewerEditorDeactivationEvent event) {
// do nothing
}
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2013 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.databinding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.swt.widgets.Composite;
import org.fortiss.tooling.base.ui.editor.TextCellEditorWithTextStyledTextActionHandler;
import org.fortiss.tooling.kernel.ui.extension.base.EditorBase;
/**
* TODO (see #2267): Comment?
* TODO (see #2267): Many similarities with AbstractTextCellWithTextStyledblah, should be
* factorized.
*
* @author czhang
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating YELLOW Hash: D9568D4E2904BF4DAA911C573219E4F1
*/
public abstract class AbstractComplexCellWithTextStyledTextActionHandlerDatabindingEditingSupport
extends AbstractComplexCellDatabindingEditingSupport {
/** Editor, which contains this EditingSupport}. */
protected EditorBase<? extends EObject> editor;
/** Constructor. */
public AbstractComplexCellWithTextStyledTextActionHandlerDatabindingEditingSupport(
EditorBase<? extends EObject> editor, ColumnViewer viewer,
DataBindingContext bindingContext) {
super(viewer, bindingContext);
this.editor = editor;
}
/** {@inheritDoc} */
@Override
protected CellEditor createTextCellEditor(ColumnViewer viewer) {
CellEditor cellEditor =
new TextCellEditorWithTextStyledTextActionHandler(
editor.getTextStyledTextActionHandler(), (Composite)getViewer()
.getControl());
setupCellEditor(cellEditor);
return cellEditor;
}
}
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2013 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.databinding;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.DECORATION_KEY;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.performCellTextBinding;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.fortiss.tooling.kernel.ui.extension.base.EditorBase;
/**
* TODO (see #2267): Comment?
* TODO (see #2267): Many similarities with AbstractDecoratedTextCellWithTextStyledblah, should be
* factorized.
*
* @author czhang
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating YELLOW Hash: C85F8D735D8D7E98B0A85A8D3E228DED
*/
public abstract class AbstractDecoratedComplexCellWithTextStyledTextActionHandlerDatabindingEditingSupport
extends AbstractComplexCellWithTextStyledTextActionHandlerDatabindingEditingSupport {
/** Constructor. */
public AbstractDecoratedComplexCellWithTextStyledTextActionHandlerDatabindingEditingSupport(
EditorBase<? extends EObject> editor, ColumnViewer viewer,
DataBindingContext bindingContext) {
super(editor, viewer, bindingContext);
}
/** {@inheritDoc} */
@Override
protected void setupCellEditor(CellEditor cellEditor) {
getText(cellEditor).setData(DECORATION_KEY,
new ControlDecoration(cellEditor.getControl(), SWT.LEFT | SWT.TOP));
}
/** Get text control from {@link CellEditor}. */
protected abstract Text getText(CellEditor cellEditor);
/** {@inheritDoc} */
@Override
protected Binding[] createBinding(CellEditor cellEditor, ViewerCell cell, CellEditor editor,
DataBindingContext context) {
return performCellTextBinding(dbc, getText(cellEditor),
getModelObservableValue(cell.getElement()), getModelToTextConverter(),
getTextToModelConverter(), getTextValidator(cell.getElement()));
}
/** Sub-classes need to provide an {@link IObservableValue} for the model. */
protected abstract IObservableValue getModelObservableValue(Object model);
/**
* Sub-classes need to provide an {@link IConverter} that converts the model
* into its textual representation.
*/
protected abstract IConverter getModelToTextConverter();
/**
* Sub-classes need to provide an {@link IConverter} that converts a text
* into the model representation.
*/
protected abstract IConverter getTextToModelConverter();
/**
* Sub-classes should overwrite to provide a text {@link IValidator}.
*
* @return <code>null</code>, by default
*/
@SuppressWarnings("unused")
protected IValidator getTextValidator(Object object) {
return null;
}
}
......@@ -38,7 +38,7 @@ import org.fortiss.tooling.kernel.ui.util.DataBindingUtils;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: D2BFE907FCC15A418E3B460942D66D89
* @ConQAT.Rating YELLOW Hash: 0B0CD0077452C9E4018D3955C7A1FC05
*/
public abstract class AbstractTextCellDatabindingEditingSupport extends EditingSupport {
......@@ -85,7 +85,7 @@ public abstract class AbstractTextCellDatabindingEditingSupport extends EditingS
/** {@inheritDoc} */
@Override
public final CellEditor getCellEditor(Object model) {
public CellEditor getCellEditor(Object model) {
cellEditor = createCellEditor(getViewer());
return cellEditor;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment