diff --git a/org.fortiss.tooling.kernel.ui/trunk/META-INF/MANIFEST.MF b/org.fortiss.tooling.kernel.ui/trunk/META-INF/MANIFEST.MF index ae868f1be4e131bdfb489e51a4fb366960527fed..a6a374e0970b64064d6612f0281ab2e7040b4c67 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.kernel.ui/trunk/META-INF/MANIFEST.MF @@ -20,6 +20,7 @@ Export-Package: org.fortiss.tooling.kernel.ui, org.fortiss.tooling.kernel.ui.extension, org.fortiss.tooling.kernel.ui.extension.base, org.fortiss.tooling.kernel.ui.extension.data, + org.fortiss.tooling.kernel.ui.extension.editingsupport, org.fortiss.tooling.kernel.ui.listener, org.fortiss.tooling.kernel.ui.service, org.fortiss.tooling.kernel.ui.util diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java index de5f45aedd4aabc5eaed1d6fcd30272727a3351e..2f8ff49533229b36a9d910554264a545bf90a5d4 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/EditorBase.java @@ -56,8 +56,7 @@ public abstract class EditorBase<T extends EObject> extends EditorPart protected final EMFDataBindingContext dbc = new EMFDataBindingContext(); /** Returns the edited object. */ - // TODO: shouldn't we return T here? - public EObject getEditedObject() { + public T getEditedObject() { return editedObject; } diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/FormsEditorBase.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/FormsEditorBase.java new file mode 100644 index 0000000000000000000000000000000000000000..fb0a231ca0cd502561a25b44e4750f82a34e35ec --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/FormsEditorBase.java @@ -0,0 +1,105 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| Copyright 2011 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.kernel.ui.extension.base; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.forms.widgets.ColumnLayout; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.eclipse.ui.forms.widgets.Section; + +/** + * Basic GEF editor based on forms. + * + * @author ratiu + * @author $Author: hoelzl $ + * @version $Rev: 18709 $ + * @ConQAT.Rating RED Hash: + */ +public abstract class FormsEditorBase<T extends EObject> extends EditorBase<T> { + + /** Our toolkit. */ + protected FormToolkit toolkit; + + /** The main form. */ + private ScrolledForm form; + + /** Grid data factory used. */ + protected final GridDataFactory gridDataFactory = GridDataFactory + .fillDefaults(); + + /** {@inheritDoc} */ + @Override + public final void createPartControl(Composite parent) { + toolkit = new FormToolkit(parent.getDisplay()); + + form = toolkit.createScrolledForm(parent); + form.setText("Overview"); + // + T + // .getElementTypeName(getEditedObject())); + // form.setImage(getModelElementManager().getImage(getEditedObject())); + toolkit.decorateFormHeading(form.getForm()); + + form.getBody().setLayout(new ColumnLayout()); + + createSections(); + + } + + /** {@inheritDoc} */ + @Override + public void setFocus() { + form.setFocus(); + } + + /** {@inheritDoc} */ + @Override + public void dispose() { + toolkit.dispose(); + dbc.dispose(); + super.dispose(); + } + + /** Creates the sections for this editor. */ + protected abstract void createSections(); + + /** + * Creates a new section and returns the client which is used to add + * controls to. The client is assigned a 3 column grid layout, but this can + * be changed. + */ + protected Composite createNewSection(String title, String description) { + final Section section = toolkit.createSection(form.getForm().getBody(), + ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE + | ExpandableComposite.TITLE_BAR | Section.DESCRIPTION); + section.setText(title); + section.setDescription(description); + final Composite client = toolkit.createComposite(section); + section.setClient(client); + + toolkit.paintBordersFor(client); + client.setLayout(new GridLayout(3, false)); + + return client; + } + +} diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/TableViewerBase.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/TableViewerBase.java new file mode 100644 index 0000000000000000000000000000000000000000..c52212e6385110832f05ef7fae3a2901b4457594 --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/base/TableViewerBase.java @@ -0,0 +1,105 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| Copyright 2011 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.kernel.ui.extension.base; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; + +/** + * Base class configuring default table viewer. + * + * @author ratiu + * @author $Author: hoelzl $ + * @version $Rev: 18709 $ + * @ConQAT.Rating RED Hash: + */ +public abstract class TableViewerBase implements IStructuredContentProvider { + + /** Compares content objects. */ + protected abstract int compare(Viewer viewer, Object o1, Object o2); + + /** Returns the content object. */ + protected abstract Object getContentObject(); + + /** Creates the viewer columns. */ + protected abstract void createColumns(TableViewer viewer); + + /** + * Returns the the table widget. May be overridden by sub-classes to + * customize the widget. + */ + protected Table getTableWidget(Composite parent) { + Table table = new Table(parent, SWT.SINGLE | SWT.H_SCROLL + | SWT.V_SCROLL | SWT.FULL_SELECTION); + GridDataFactory.fillDefaults().hint(485, 250).span(1, 5).applyTo(table); + table.setLinesVisible(true); + table.setHeaderVisible(true); + return table; + } + + /** Creates the table viewer on the given table. */ + public TableViewer createTableViewer(Composite parent) { + TableViewer viewer = new TableViewer(getTableWidget(parent)); + + createColumns(viewer); + + viewer.setSorter(new TableViewerSorter()); + viewer.setContentProvider(this); + viewer.setInput(getContentObject()); + + return viewer; + } + + /** Creates a simple column. */ + public TableViewerColumn makeColumn(TableViewer viewer, int width, + String title, String tooltip, ColumnLabelProvider labelProvider, + EditingSupport editingSupport) { + TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEFT); + column.getColumn().setWidth(width); + column.getColumn().setText(title); + column.getColumn().setToolTipText(tooltip); + column.setLabelProvider(labelProvider); + column.setEditingSupport(editingSupport); + return column; + } + + /** + * ViewerSorter using {@link TableViewerBase#compare} + * + * @author hoelzlf + * @author $Author: hoelzlf $ + * @version $Rev: 955 $ + * @levd.rating RED Rev: + */ + private class TableViewerSorter extends ViewerSorter { + /** {@inheritDoc} */ + @Override + public int compare(Viewer viewer, Object o1, Object o2) { + return TableViewerBase.this.compare(viewer, o1, o2); + } + } +} diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/editingsupport/AbstractDecoratedTextCellDatabindingEditingSupport.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/editingsupport/AbstractDecoratedTextCellDatabindingEditingSupport.java new file mode 100644 index 0000000000000000000000000000000000000000..5cc67979fdc06291c2395ab5d6b146397267881f --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/editingsupport/AbstractDecoratedTextCellDatabindingEditingSupport.java @@ -0,0 +1,102 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| Copyright 2011 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.kernel.ui.extension.editingsupport; + +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.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.fortiss.tooling.kernel.ui.util.DataBindingUtils; + +/** + * Abstract class implementing text cell editing support with decorated cell + * editor. The binding is created using {@link DataBindingUtils} and the + * information provided by sub-classes in the abstract methods. + * <P> + * Decoration is in effect if either {@link #getTextValidator()} or + * {@link #getTextPostConvertValidator()} returns a non-null {@link IValidator}. + * + * @author hoelzlf + * @author $Author: hoelzlf $ + * @version $Rev: 1670 $ + * @levd.rating RED Rev: + */ +public abstract class AbstractDecoratedTextCellDatabindingEditingSupport extends + AbstractTextCellDatabindingEditingSupport { + + /** Constructor. */ + public AbstractDecoratedTextCellDatabindingEditingSupport( + ColumnViewer viewer, DataBindingContext bindingContext) { + super(viewer, bindingContext); + cellEditor.getControl().setData( + DataBindingUtils.DECORATION_KEY, + new ControlDecoration(cellEditor.getControl(), SWT.LEFT + | SWT.TOP)); + } + + /** {@inheritDoc} */ + @Override + protected Binding[] createBinding(CellEditor cellEditor, ViewerCell cell, + CellEditor editor, DataBindingContext context) { + return DataBindingUtils.performComplexTextBinding(dbc, + cellEditor.getControl(), + getModelObservableValue(cell.getElement()), + getModelToTextConverter(), getTextToModelConverter(), + getTextValidator(), getTextPostConvertValidator()); + } + + /** 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 + */ + protected IValidator getTextValidator() { + return null; + } + + /** + * Sub-classes should overwrite to provide a {@link IValidator} for the + * conversion result. + * + * @return <code>null</code>, by default + */ + protected IValidator getTextPostConvertValidator() { + return null; + } +} \ No newline at end of file diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/editingsupport/AbstractTextCellDatabindingEditingSupport.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/editingsupport/AbstractTextCellDatabindingEditingSupport.java new file mode 100644 index 0000000000000000000000000000000000000000..20c2615bcb70903cd826e879f87642808c7c3ed0 --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/extension/editingsupport/AbstractTextCellDatabindingEditingSupport.java @@ -0,0 +1,197 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| Copyright 2011 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.kernel.ui.extension.editingsupport; + +import org.conqat.lib.commons.assertion.CCSMPre; +import org.eclipse.core.databinding.Binding; +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.observable.value.IObservableValue; +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; + +/** + * Abstract base class for inline text cell editors using data binding. + * + * @author hoelzlf + * @author $Author: hoelzlf $ + * @version $Rev: 5848 $ + * @levd.rating RED Rev: + */ +public abstract class AbstractTextCellDatabindingEditingSupport extends + EditingSupport { + + /** Cell editor. */ + protected final CellEditor cellEditor; + + /** Data binding context. */ + protected final DataBindingContext dbc; + + /** + * Complex data bindings. + * + * @see DataBindingUtils#performComplexTextBinding(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, + * 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 AbstractTextCellDatabindingEditingSupport(ColumnViewer viewer, + DataBindingContext bindingContext) { + super(viewer); + this.cellEditor = createCellEditor(viewer); + this.dbc = bindingContext; + } + + /** Override this method to create another cell editor. */ + protected CellEditor createCellEditor(ColumnViewer viewer) { + return new TextCellEditor((Composite) viewer.getControl()); + } + + /** {@inheritDoc} */ + @Override + public final CellEditor getCellEditor(Object model) { + 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); + + CCSMPre.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}. + * + * @author hoelzlf + * @author $Author: hoelzlf $ + * @version $Rev: 5848 $ + * @levd.rating RED Rev: + */ + 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 + } + } +}