Commit 44d71fbd authored by Kisslinger's avatar Kisslinger
Browse files

Added glossary functionality

refs 85
parent 73b759d5
......@@ -23,3 +23,8 @@ Export-Package: org.fortiss.af3.mira.ui,
org.fortiss.af3.mira.ui.example,
org.fortiss.af3.mira.ui.handler,
org.fortiss.af3.mira.ui.views
Import-Package: org.eclipse.core.databinding.beans,
org.eclipse.jface.text,
org.eclipse.jface.text.presentation,
org.eclipse.jface.text.rules,
org.eclipse.jface.text.source
......@@ -67,6 +67,7 @@ import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.fortiss.af3.mira.command.CreateRelationCommand;
import org.fortiss.af3.mira.command.DeleteRelationCommand;
import org.fortiss.af3.mira.command.SortRequirementCommand;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.Requirement;
import org.fortiss.af3.mira.model.RequirementPriority;
import org.fortiss.af3.mira.model.RequirementRelation;
......@@ -76,6 +77,7 @@ import org.fortiss.af3.mira.ui.action.ExportReportAction;
import org.fortiss.af3.mira.ui.action.ExportReportSummarizationAction;
import org.fortiss.af3.mira.ui.action.ShowHierarchyAction;
import org.fortiss.af3.mira.ui.action.VerifyAction;
import org.fortiss.af3.mira.ui.editor.glossary.GlossaryHighlightText;
import org.fortiss.tooling.base.ui.editor.FormsEditorBase;
import com.ibm.icu.text.NumberFormat;
......@@ -86,7 +88,7 @@ import com.ibm.icu.text.NumberFormat;
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 68E0059B5E6AFA83018CD93EA6D685D2
* @ConQAT.Rating YELLOW Hash: 36E30A5E67603FE2DC9900E7968223CC
*/
public class RequirementEditor<T extends Requirement> extends
FormsEditorBase<T> {
......@@ -116,6 +118,9 @@ public class RequirementEditor<T extends Requirement> extends
/** id observable */
protected IObservableValue idObservable;
/** Analysis associated with the edited object */
private Analysis analysis;
/** {@inheritDoc} */
@Override
public void init(IEditorSite site, IEditorInput input)
......@@ -130,6 +135,8 @@ public class RequirementEditor<T extends Requirement> extends
.getAnalysis()));
}
});
analysis = editedObject.getAnalysis();
}
/** {@inheritDoc} */
......@@ -203,29 +210,33 @@ public class RequirementEditor<T extends Requirement> extends
SWT.READ_ONLY);
singleLineLabelFactory.applyTo(titleLabel);
Text titleInput = toolkit.createText(generalComposite, "", SWT.BORDER);
singleLineInputFactory.applyTo(titleInput);
bind(dbc, titleInput, editedObject, INAMED_ELEMENT__NAME);
GlossaryHighlightText titleInput = new GlossaryHighlightText(
generalComposite, SWT.BORDER, analysis);
singleLineInputFactory.applyTo(titleInput.getControl());
bind(dbc, titleInput.getTextWidget(), editedObject,
INAMED_ELEMENT__NAME);
Label descriptionLabel = toolkit.createLabel(generalComposite,
"Description ", SWT.READ_ONLY);
multiLineLabelFactory.applyTo(descriptionLabel);
Text descriptionInput = toolkit.createText(generalComposite,
editedObject.getDescription(), SWT.BORDER | SWT.WRAP
| SWT.MULTI | SWT.V_SCROLL);
multiLineInputFactory.applyTo(descriptionInput);
bind(dbc, descriptionInput, editedObject, REQUIREMENT__DESCRIPTION);
GlossaryHighlightText descriptionInput = new GlossaryHighlightText(
generalComposite, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP
| SWT.MULTI, analysis);
multiLineInputFactory.applyTo(descriptionInput.getControl());
bind(dbc, descriptionInput.getTextWidget(), editedObject,
REQUIREMENT__DESCRIPTION);
Label rationaleLabel = toolkit.createLabel(generalComposite,
"Rationale ", SWT.READ_ONLY);
multiLineLabelFactory.applyTo(rationaleLabel);
Text rationaleInput = toolkit.createText(generalComposite,
editedObject.getRationale(), SWT.BORDER | SWT.WRAP | SWT.MULTI
| SWT.V_SCROLL);
multiLineInputFactory.applyTo(rationaleInput);
bind(dbc, rationaleInput, editedObject, REQUIREMENT__RATIONALE);
GlossaryHighlightText rationaleInput = new GlossaryHighlightText(
generalComposite, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP
| SWT.MULTI, analysis);
multiLineInputFactory.applyTo(rationaleInput.getControl());
bind(dbc, rationaleInput.getTextWidget(), editedObject,
REQUIREMENT__RATIONALE);
Label authorLabel = toolkit.createLabel(generalComposite, "Author ",
SWT.READ_ONLY);
......@@ -277,11 +288,11 @@ public class RequirementEditor<T extends Requirement> extends
SWT.READ_ONLY);
multiLineLabelFactory.applyTo(todoLabel);
Text todoInput = toolkit.createText(generalComposite,
editedObject.getTodo(), SWT.BORDER | SWT.WRAP | SWT.MULTI
| SWT.V_SCROLL);
multiLineInputFactory.applyTo(todoInput);
bind(dbc, todoInput, editedObject, REQUIREMENT__TODO);
GlossaryHighlightText todoInput = new GlossaryHighlightText(
generalComposite, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP
| SWT.MULTI, analysis);
multiLineInputFactory.applyTo(todoInput.getControl());
bind(dbc, todoInput.getTextWidget(), editedObject, REQUIREMENT__TODO);
}
/** Create other composites */
......@@ -389,9 +400,11 @@ public class RequirementEditor<T extends Requirement> extends
Composite commentComposite = createNewSection("Comment",
"Comment information");
Text commentInput = toolkit.createText(commentComposite,
editedObject.getComment(), SWT.BORDER | SWT.MULTI | SWT.WRAP);
fillControlFactory.applyTo(commentInput);
bind(dbc, commentInput, editedObject, INAMED_COMMENTED_ELEMENT__COMMENT);
GlossaryHighlightText commentInput = new GlossaryHighlightText(
commentComposite, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP
| SWT.MULTI, analysis);
fillControlFactory.applyTo(commentInput.getControl());
bind(dbc, commentInput.getTextWidget(), editedObject,
INAMED_COMMENTED_ELEMENT__COMMENT);
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.glossary;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.jface.text.rules.WordRule;
import org.fortiss.af3.mira.model.Analysis;
/**
* A update strategy that updates the word rule after a glossary entry was
* changed (its name, abbreviations or synonmys)
*
* As the wordRule cannot be changed it must be rebuilt from scratch
*
* @author kisslinger
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: D2801FA347B1AFA2D2535B249A8404A0
*/
public class EntryPropertyToWordRuleUpdateStrategy extends UpdateValueStrategy {
/** root element analysis of which entries should be used for highlighting */
Analysis analysis;
/** constructor */
public EntryPropertyToWordRuleUpdateStrategy(Analysis analysis) {
this.analysis = analysis;
}
/** {@inheritDoc} */
@Override
public Object convert(Object value) {
WordRule rule = ScannerManager.createNewWordRule(analysis);
return rule;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.glossary;
import org.fortiss.af3.mira.model.glossary.GlossaryEntry;
/**
* Representation of one search result in a search for matching glossary entries
*
* @author kisslinger
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: BB01F907B5F1563F57D6DF69FEBE4148
*/
public class EntrySearchResult implements Comparable<EntrySearchResult> {
/** the found entry */
GlossaryEntry entry;
/** the type of the result */
ResultType type;
/**
* the property text which matched to the search request, e.g. the text of
* one synonym
*/
String matchingPropertyText;
/** enum of possible result types */
enum ResultType {
/** matching by the entry name */
NAME,
/** matching by a synonym text */
SYNONYM,
/** matching by an abbreviation text */
ABBREVIATION
}
/**
* constructor
*
* @param entry
* the found entry
* @param type
* the type of the result
* @param matchingPropertyText
* the property text which matched to the search request
*/
public EntrySearchResult(GlossaryEntry entry, ResultType type,
String matchingPropertyText) {
super();
this.entry = entry;
this.type = type;
this.matchingPropertyText = matchingPropertyText;
}
/**
* {@inheritDoc}
*
* entries should appear in this order of type: NAME, ABBREVIATION, SYNONYM.
* If the type is the same the longer matchingPropertyText should appear
* first
* */
@Override
public int compareTo(EntrySearchResult otherResult) {
if (otherResult.type == ResultType.NAME && this.type != ResultType.NAME)
return 1;
if (otherResult.type != ResultType.NAME && this.type == ResultType.NAME)
return -1;
if (otherResult.type == ResultType.ABBREVIATION
&& this.type == ResultType.SYNONYM)
return 1;
if (otherResult.type == ResultType.ABBREVIATION
&& this.type == ResultType.ABBREVIATION)
return -1;
if (otherResult.matchingPropertyText.length() > this.matchingPropertyText
.length())
return 1;
return -1;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| 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.glossary;
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.emf.databinding.EMFObservables.observeValue;
import static org.eclipse.jface.databinding.viewers.ViewersObservables.observeSinglePostSelection;
import static org.fortiss.af3.mira.model.glossary.GlossaryPackage.Literals.GLOSSARY_ENTRY__ABBREVIATIONS;
import static org.fortiss.af3.mira.model.glossary.GlossaryPackage.Literals.GLOSSARY_ENTRY__DEFINITION;
import static org.fortiss.af3.mira.model.glossary.GlossaryPackage.Literals.GLOSSARY_ENTRY__STATUS;
import static org.fortiss.af3.mira.model.glossary.GlossaryPackage.Literals.GLOSSARY_ENTRY__SYNONYMS;
import static org.fortiss.tooling.kernel.model.FortissToolingKernelPackage.Literals.INAMED_COMMENTED_ELEMENT__COMMENT;
import static org.fortiss.tooling.kernel.model.FortissToolingKernelPackage.Literals.INAMED_ELEMENT__NAME;
import static org.fortiss.tooling.kernel.ui.util.DataBindingUtils.bind;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ArrayContentProvider;
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.fortiss.af3.mira.command.glossary.CreateAbbreviationCommand;
import org.fortiss.af3.mira.command.glossary.CreateSynonymCommand;
import org.fortiss.af3.mira.command.glossary.DeleteWordElementCommand;
import org.fortiss.af3.mira.model.glossary.GlossaryEntry;
import org.fortiss.af3.mira.model.glossary.GlossaryEntryStatus;
import org.fortiss.af3.mira.model.glossary.WordElement;
import org.fortiss.tooling.base.ui.editor.FormsEditorBase;
/**
* Editor to edit a {@link GlossaryEntry}
*
* @author kisslinger
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 4E6CE7FDB8192892510844240E57ABC9
*/
public class GlossaryEntryEditor extends FormsEditorBase<GlossaryEntry> {
/** single line label grid data factory */
protected static GridDataFactory singleLineLabelFactory = GridDataFactory
.swtDefaults().align(SWT.RIGHT, SWT.CENTER).grab(false, false);
/** single line input grid data factory */
protected static GridDataFactory singleLineInputFactory = GridDataFactory
.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false);
/** fill control grid data factory */
protected static GridDataFactory fillControlFactory = GridDataFactory
.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true)
.hint(SWT.DEFAULT, 200);
/** multi line label grid data factory */
protected static GridDataFactory multiLineLabelFactory = GridDataFactory
.swtDefaults().align(SWT.RIGHT, SWT.TOP).grab(false, false);
/** multi line input grid data factory */
protected static GridDataFactory multiLineInputFactory = GridDataFactory
.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true)
.hint(500, 120);
/** {@inheritDoc} */
@Override
protected void createSections() {
createGeneralSection();
createAbbreviationsSection();
createSynonymSection();
createCommentSection();
}
/** create the general section */
private void createGeneralSection() {
Composite generalComposite = createNewSection("General",
"General information");
generalComposite.setLayout(new GridLayout(2, false));
// Name
Label nameLabel = toolkit.createLabel(generalComposite, "Name ",
SWT.READ_ONLY);
singleLineLabelFactory.applyTo(nameLabel);
Text nameInput = toolkit.createText(generalComposite, "", SWT.BORDER);
singleLineInputFactory.applyTo(nameInput);
// create binding to the model
bind(dbc, nameInput, editedObject, INAMED_ELEMENT__NAME);
// create binding to the highlight scanner
IObservableValue target = ScannerManager.getScanner(
editedObject.getGlossary().getAnalysis())
.getObservableWordRule();
IObservableValue model = observeValue(editedObject,
INAMED_ELEMENT__NAME);
dbc.bindValue(target, model, new UpdateValueStrategy(POLICY_NEVER),
new EntryPropertyToWordRuleUpdateStrategy(editedObject
.getGlossary().getAnalysis()));
// Definition
Label definitionLabel = toolkit.createLabel(generalComposite,
"Definition ", SWT.READ_ONLY);
multiLineLabelFactory.applyTo(definitionLabel);
Text defintionInput = toolkit.createText(generalComposite, "",
SWT.BORDER | SWT.V_SCROLL | SWT.WRAP);
multiLineInputFactory.applyTo(defintionInput);
// binding to model
bind(dbc, defintionInput, editedObject, GLOSSARY_ENTRY__DEFINITION);
// 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(GlossaryEntryStatus.values());
// binding to model
dbc.bindValue(observeSinglePostSelection(statusInput),
observeValue(editedObject, GLOSSARY_ENTRY__STATUS));
}
/** create section for abbreviations */
private void createAbbreviationsSection() {
Composite abbreviationsComposite = createNewSection("Abbreviations",
"Abbreviations for the glossary entry");
abbreviationsComposite.setLayout(new GridLayout(1, false));
// 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(abbreviationsComposite,
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(100));
tableColumn.setLabelProvider(new WordItemCellProvider());
// the editing support is also responsible to create the binding 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(
abbreviationsTableViewer, editedObject.getGlossary()
.getAnalysis(), dbc));
// binding to model
abbreviationsTableViewer.setInput(observeList(editedObject,
GLOSSARY_ENTRY__ABBREVIATIONS));
multiLineInputFactory.applyTo(tableComposite);
// buttons
Composite buttonList = toolkit.createComposite(abbreviationsComposite);
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 synonymComposite = createNewSection("Synonyms",
"Synonyms for the glossary entry");
synonymComposite.setLayout(new GridLayout(1, false));
// 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(synonymComposite, 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(100));
tableColumn.setLabelProvider(new WordItemCellProvider());
// the editing support is also responsible to create the binding to the
// highlight scanner
// like this the number of binding can kept as low as possible, as only