Commit dfb951ea authored by Andreas Bayha's avatar Andreas Bayha
Browse files

MIRA: Removed ContextElementOtherEditor

Removed ContextElementOtherEditor and corresponding binding.

Issue-Ref: 3886
Issue-Url: https://af3-developer.fortiss.org/issues/3886

Signed-off-by: Andreas Bayha's avatarAndreas Bayha <bayha@fortiss.org>
parent 8ad7bd7a
/*-------------------------------------------------------------------------+
| Copyright 2012 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.af3.mira.ui.editor.contextElement;
import static org.conqat.ide.commons.ui.selection.SelectionUtils.selectAll;
import static org.eclipse.core.databinding.UpdateValueStrategy.POLICY_NEVER;
import static org.eclipse.emf.databinding.EMFObservables.observeList;
import static org.eclipse.jface.databinding.viewers.ViewersObservables.observeSinglePostSelection;
import static org.fortiss.af3.mira.model.MiraPackage.Literals.CONTEXT_ELEMENT__ABBREVIATIONS;
import static org.fortiss.af3.mira.model.MiraPackage.Literals.CONTEXT_ELEMENT__STATUS;
import static org.fortiss.af3.mira.model.MiraPackage.Literals.CONTEXT_ELEMENT__SYNONYMS;
import static org.fortiss.af3.mira.ui.editor.highlight.ScannerManager.getScanner;
import static org.fortiss.af3.mira.ui.utils.HighlightUtils.createSourceViewer;
import static org.fortiss.af3.mira.ui.utils.MiraLayoutUtils.fillControlFactory;
import static org.fortiss.af3.mira.ui.utils.MiraLayoutUtils.multiLineInputFactory;
import static org.fortiss.af3.mira.ui.utils.MiraLayoutUtils.singleLineLabelFactory;
import static org.fortiss.af3.mira.utils.MiraUtils.getAnalysisFor;
import static org.fortiss.tooling.base.model.element.ElementPackage.Literals.IHIERARCHIC_ELEMENT_CONTAINER__CONTAINED_ELEMENTS;
import static org.fortiss.tooling.kernel.model.FortissToolingKernelPackage.Literals.INAMED_COMMENTED_ELEMENT__COMMENT;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.bind;
import static org.fortiss.tooling.kernel.ui.util.ObservableUtils.observeValue;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.databinding.UpdateListStrategy;
import org.eclipse.core.databinding.observable.ChangeEvent;
import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.TextStyledTextActionHandler;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.fortiss.af3.mira.command.contextElement.CreateAbbreviationCommand;
import org.fortiss.af3.mira.command.contextElement.CreateSynonymCommand;
import org.fortiss.af3.mira.command.contextElement.DeleteWordElementCommand;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.ContextElement;
import org.fortiss.af3.mira.model.ContextElementStatus;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.WordElement;
import org.fortiss.af3.mira.model.glossary.Glossary;
import org.fortiss.af3.mira.ui.editor.highlight.ListToWordRuleUpdateStrategy;
import org.fortiss.af3.mira.ui.editor.highlight.ScannerManager;
import org.fortiss.tooling.base.ui.editor.FormsEditorBase;
import org.fortiss.tooling.kernel.ui.service.IActionService;
/**
* Base class for {@link ContextElement}s, i.e., elements having a name, a comment, a definition,
* abbreviations and synonyms.
*
* @author wenwenchen
*/
public class ContextElementOtherEditor<T extends ContextElement> extends FormsEditorBase<T> {
/** Single line input grid data factory. */
protected static GridDataFactory singleLineInputFactory =
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
/** The {@link Analysis} which contains this {@link Requirement}. */
protected Analysis analysis;
/**
* List of all sourceViewers on the form (which needed to inform the (on updates of glossary and
* requirement source).
*/
protected List<SourceViewer> registeredSourceViewers;
/** List of all Text fields on the form (needed to add {@link TextStyledTextActionHandler}). */
protected List<Text> registeredTextFields;
/**
* Listener connected to the observable word rule of the scanner associated to the corresponding
* analysis.
*/
private IChangeListener wordRuleUpdateListener;
/** {@inheritDoc} */
@Override
public void dispose() {
getScanner(analysis).getObservableWordRule().removeChangeListener(wordRuleUpdateListener);
wordRuleUpdateListener = null;
super.dispose();
}
/** {@inheritDoc} */
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
analysis = getAnalysisFor(editedObject);
registeredSourceViewers = new ArrayList<SourceViewer>();
registeredTextFields = new ArrayList<Text>();
createUpdateListener();
}
/** {@inheritDoc} */
@Override
public void registerGlobalActions(IActionBars bars) {
IActionService.getInstance().registerGlobalUndoRedoActions(bars);
super.registerGlobalActions(bars);
}
/** {@inheritDoc} */
@Override
protected void addTextStyledText(TextStyledTextActionHandler textStyledTextActionHandler) {
for(Text text : registeredTextFields) {
textStyledTextActionHandler.addText(text);
}
for(SourceViewer sourceViewer : registeredSourceViewers)
textStyledTextActionHandler.addText(sourceViewer.getTextWidget());
}
/** Create a listener to get informed when the glossary and requirement source changed. */
private void createUpdateListener() {
wordRuleUpdateListener = new IChangeListener() {
@Override
public void handleChange(ChangeEvent event) {
for(SourceViewer viewer : registeredSourceViewers)
// Refresh after changes to guarantee update of the text highlighting.
viewer.refresh();
}
};
getScanner(analysis).getObservableWordRule().addChangeListener(wordRuleUpdateListener);
}
/** {@inheritDoc} */
@Override
protected void setupScrolledForm(ScrolledForm form) {
super.setupScrolledForm(form);
this.form = form;
}
/** {@inheritDoc} */
@Override
protected void createSections() {
createBindings();
Composite section = createGeneralSection();
createAbbreviationsSection(section);
createSynonymSection(section);
createCommentSection(section);
}
/** Create the bindings to glossary. */
@SuppressWarnings("unchecked")
private void createBindings() {
dbc.bindList(ScannerManager.getScanner(analysis).getObservableList(),
EMFObservables.observeList(analysis,
IHIERARCHIC_ELEMENT_CONTAINER__CONTAINED_ELEMENTS),
new UpdateListStrategy(POLICY_NEVER), new ListToWordRuleUpdateStrategy(analysis));
for(Glossary glossary : analysis.getGlossariesList()) {
dbc.bindList(ScannerManager.getScanner(analysis).getObservableList(),
EMFObservables.observeList(glossary,
IHIERARCHIC_ELEMENT_CONTAINER__CONTAINED_ELEMENTS),
new UpdateListStrategy(POLICY_NEVER),
new ListToWordRuleUpdateStrategy(analysis));
}
}
/** Create the general section. */
private Composite createGeneralSection() {
Composite generalComposite = createNewSection("Additional information", "");
generalComposite.setLayout(new GridLayout(2, false));
// Status
Label statusLabel = toolkit.createLabel(generalComposite, "Status ", SWT.READ_ONLY);
singleLineLabelFactory.applyTo(statusLabel);
ComboViewer statusInput = new ComboViewer(generalComposite, SWT.READ_ONLY);
singleLineInputFactory.applyTo(statusInput.getCombo());
toolkit.adapt(statusInput.getCombo());
statusInput.setContentProvider(new ArrayContentProvider());
statusInput.setLabelProvider(new LabelProvider());
statusInput.setInput(ContextElementStatus.values());
// binding to model
dbc.bindValue(observeSinglePostSelection(statusInput),
observeValue(editedObject, CONTEXT_ELEMENT__STATUS));
return generalComposite;
}
/** Create section for abbreviations. */
private void createAbbreviationsSection(Composite section) {
Label abbreviationsLabel = toolkit.createLabel(section, "Abbreviations ", SWT.READ_ONLY);
singleLineLabelFactory.applyTo(abbreviationsLabel);
// We use a separate composite with a table layout to set the width of the single column to
// the full width of the table.
Composite tableComposite = new Composite(section, SWT.NONE);
TableColumnLayout tableLayout = new TableColumnLayout();
tableComposite.setLayout(tableLayout);
// create table viewer
final TableViewer abbreviationsTableViewer = new TableViewer(
toolkit.createTable(tableComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL));
abbreviationsTableViewer.getTable().setLinesVisible(true);
abbreviationsTableViewer.setContentProvider(new ObservableListContentProvider());
// create column viewer and set column properties
TableViewerColumn tableColumn = new TableViewerColumn(abbreviationsTableViewer, SWT.NONE);
tableLayout.setColumnData(tableColumn.getColumn(), new ColumnWeightData(400));
tableColumn.setLabelProvider(new ColumnLabelProvider());
// the editing support is also responsible to create the binding of the edited content to
// the highlight scanner like this the number of binding can kept as low as possible, as
// only a binding for a list entry is created if it might be changed.
tableColumn.setEditingSupport(
new WordElementEditingSupport(this, abbreviationsTableViewer, analysis, dbc));
IObservableList<?> observableAbbreviationsList =
observeList(editedObject, CONTEXT_ELEMENT__ABBREVIATIONS);
abbreviationsTableViewer.setInput(observableAbbreviationsList);
// binding of synonyms list to highlight scanner
dbc.bindList(ScannerManager.getScanner(analysis).getObservableList(),
observableAbbreviationsList, new UpdateListStrategy(POLICY_NEVER),
new ListToWordRuleUpdateStrategy(analysis));
multiLineInputFactory.applyTo(tableComposite);
// Fake label
toolkit.createLabel(section, " ", SWT.READ_ONLY);
// buttons
Composite buttonList = toolkit.createComposite(section);
buttonList.setLayout(new RowLayout());
GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.TOP).applyTo(buttonList);
Button addAbbreviationButton = toolkit.createButton(buttonList, "Add", SWT.FLAT);
addAbbreviationButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
executeCommand(new CreateAbbreviationCommand(editedObject));
}
});
Button removeAbbreviationButton = toolkit.createButton(buttonList, "Remove", SWT.FLAT);
removeAbbreviationButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
ISelection select = abbreviationsTableViewer.getSelection();
if(select != null) {
executeCommand(
new DeleteWordElementCommand(selectAll(select, WordElement.class)));
}
}
});
}
/** Create section for synonyms. */
private void createSynonymSection(Composite section) {
Label synonymLabel = toolkit.createLabel(section, "Synonyms ", SWT.READ_ONLY);
singleLineLabelFactory.applyTo(synonymLabel);
// We use a separate composite with a table layout to set the width of the single column to
// the full width of the table.
Composite tableComposite = new Composite(section, SWT.NONE);
TableColumnLayout tableLayout = new TableColumnLayout();
tableComposite.setLayout(tableLayout);
// create table viewer
final TableViewer synonymTableViewer = new TableViewer(
toolkit.createTable(tableComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL));
synonymTableViewer.getTable().setLinesVisible(true);
synonymTableViewer.setContentProvider(new ObservableListContentProvider());
// create column viewer and set column properties
TableViewerColumn tableColumn = new TableViewerColumn(synonymTableViewer, SWT.NONE);
tableLayout.setColumnData(tableColumn.getColumn(), new ColumnWeightData(400));
tableColumn.setLabelProvider(new ColumnLabelProvider());
// The editing support is also responsible to create the binding of the edited content to
// the highlight scanner like this the number of binding can kept as low as possible, as
// only a binding for a list entry is created if it might be changed.
tableColumn.setEditingSupport(
new WordElementEditingSupport(this, synonymTableViewer, analysis, dbc));
IObservableList<?> observableSynonymsList =
observeList(editedObject, CONTEXT_ELEMENT__SYNONYMS);
synonymTableViewer.setInput(observableSynonymsList);
// binding of synonyms list to highlight scanner
dbc.bindList(ScannerManager.getScanner(analysis).getObservableList(),
observableSynonymsList, new UpdateListStrategy(POLICY_NEVER),
new ListToWordRuleUpdateStrategy(analysis));
multiLineInputFactory.applyTo(tableComposite);
// Fake label
toolkit.createLabel(section, " ", SWT.READ_ONLY);
// buttons
Composite buttonList = toolkit.createComposite(section);
buttonList.setLayout(new RowLayout());
GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.TOP).applyTo(buttonList);
Button addSynonymButton = toolkit.createButton(buttonList, "Add", SWT.FLAT);
addSynonymButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
executeCommand(new CreateSynonymCommand(editedObject));
synonymTableViewer.refresh();
}
});
Button removeSynonymButton = toolkit.createButton(buttonList, "Remove", SWT.FLAT);
removeSynonymButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
ISelection select = synonymTableViewer.getSelection();
if(select != null) {
executeCommand(
new DeleteWordElementCommand(selectAll(select, WordElement.class)));
synonymTableViewer.refresh();
}
}
});
}
/** Create the comment section */
private void createCommentSection(Composite section) {
Label synonymLabel = toolkit.createLabel(section, "Comment ", SWT.READ_ONLY);
singleLineLabelFactory.applyTo(synonymLabel);
SourceViewer commentInput = createSourceViewer(form, section,
SWT.BORDER | SWT.V_SCROLL | SWT.WRAP | SWT.MULTI, analysis);
registeredSourceViewers.add(commentInput);
fillControlFactory.applyTo(commentInput.getControl());
bind(dbc, commentInput.getTextWidget(), editedObject, INAMED_COMMENTED_ELEMENT__COMMENT);
}
}
AnalysisEditorBinding.java ca735cd4b22e526d164b8fb2c3c80ac37435c6ef GREEN
AspectBindings.java 2fbaa0ffeec81e4d4ec79bebe92160fcad44f0ff GREEN
ExternalSystemEditorbindings.java 45b40ded33df4609036f32acb9c20da311a74dd7 GREEN
GlossaryEditorBinding.java 4dd69c6ef1605a123db5a4d2ca93e5f600c0b360 GREEN
GlossaryEntryEditorBindings.java d85a70bb7efaa20a225ea7c2697feba364357b8e GREEN
GlossaryEntryEditorBindings.java a1a892987d1a285b199ab3a63e31932399f5568e GREEN
GlossaryOccurrencesEditorBinding.java b872b600ddf3f21f25a88ae1bd0a8a00e93f025e GREEN
OtherEditorBinding.java 6174179045e781e2122f74352f63a422890875f7 GREEN
RequirementDocumentEditorBindings.java 2d29d68fbde23ce50c39af17716141baa6bbc04c GREEN
RequirementEditorBinding.java d6a58d1ece5fa633501a1f069572bb656e777327 GREEN
RequirementSourcesEditorBinding.java 8a3d929f035a7d8c1daba0613ac2ceba7435c3dd GREEN
RequirementsContainerEditorBinding.java e3680aedca66a77f76c0758293a8c10ffb923f63 GREEN
RequirementsPackageEditorBinding.java c9018d99b57522da711bf447447f1b0e354c91a2 GREEN
SignalRequirementEditorBinding.java a2f5a4f1d6364f6cbf376b88cd1c3be42854c384 GREEN
StakeholderEditorBindings.java 2533d23342ac105f9401aae34e1713c048fddde4 GREEN
TracesEditorBinding.java 16340b97593fac97327b2b5eda8988a04142d945 GREEN
......@@ -16,11 +16,9 @@
package org.fortiss.af3.mira.ui.editorbinding;
import static org.fortiss.af3.mira.utils.MiraUtils.FIRSTEDITORPRIORITY;
import static org.fortiss.af3.mira.utils.MiraUtils.SECONDEDITORPRIORITY;
import org.eclipse.ui.IEditorPart;
import org.fortiss.af3.mira.model.glossary.GlossaryEntry;
import org.fortiss.af3.mira.ui.editor.contextElement.ContextElementOtherEditor;
import org.fortiss.af3.mira.ui.editor.glossary.GlossaryEntryEditor;
import org.fortiss.tooling.kernel.ui.extension.base.ModelEditorBindingBase;
......@@ -52,27 +50,4 @@ public class GlossaryEntryEditorBindings {
return FIRSTEDITORPRIORITY;
}
}
/** Secondary editor for {@link GlossaryEntry}s. */
public static class GlossaryEntrySecondaryEditorBinding
extends ModelEditorBindingBase<GlossaryEntry> {
/** {@inheritDoc} */
@Override
public Class<? extends IEditorPart> getEditorClass() {
return ContextElementOtherEditor.class;
}
/** {@inheritDoc} */
@Override
public String getLabel() {
return "Other";
}
/** {@inheritDoc} */
@Override
public int getPriority() {
return SECONDEDITORPRIORITY;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment