Commit b5645c55 authored by Chen Wenwen's avatar Chen Wenwen
Browse files

refs 1071
parent 2cbc39f5
......@@ -34,13 +34,17 @@ import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.ContextElement;
import org.fortiss.af3.mira.model.WordElement;
import org.fortiss.af3.mira.model.glossary.Glossary;
import org.fortiss.af3.mira.model.glossary.GlossaryEntry;
import org.fortiss.af3.mira.model.glossary.WordElement;
import org.fortiss.af3.mira.model.requirementSource.Person;
import org.fortiss.af3.mira.model.requirementSource.RequirementSource;
import org.fortiss.af3.mira.model.requirementSource.RequirementSourceElement;
import org.fortiss.af3.mira.model.requirementSource.Stakeholder;
import org.fortiss.af3.mira.ui.utils.ConnetionUtils;
import org.fortiss.tooling.base.model.element.IHierarchicElement;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
/**
* {@link IContentAssistProcessor} that finds proposals for glossary entries
......@@ -48,7 +52,7 @@ import org.fortiss.tooling.base.model.element.IHierarchicElement;
* @author kisslinger
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: D0F62DED246583363FDADB9D5E771D1D
* @ConQAT.Rating YELLOW Hash: 12300913C73E9FFCF4CD4DE3963C8C4A
*/
public class ConnectionContentAssistProcessor implements IContentAssistProcessor {
......@@ -80,46 +84,26 @@ public class ConnectionContentAssistProcessor implements IContentAssistProcessor
for(Glossary glossary : analysis.getGlossariesList()) {
for(IHierarchicElement entryElement : glossary.getContainedElementsList()) {
GlossaryEntry entry = (GlossaryEntry)entryElement;
int pos = -1;
// check entry name
if((pos =
ConnetionUtils.match(currentWord, entry.getName(), viewer,
currentWordRegion, true)) >= 0)
proposalList.add(new CompletionProposal(entry.getName(),
currentWordRegion.getOffset() - pos, currentWordRegion
.getLength() + pos, entry.getName().length()));
// check synonyms
for(WordElement synoym : entry.getSynonyms())
if((pos =
ConnetionUtils.match(currentWord, synoym.getText(), viewer,
currentWordRegion, true)) >= 0)
proposalList.add(new CompletionProposal(synoym.getText(),
currentWordRegion.getOffset() - pos, currentWordRegion
.getLength() + pos, synoym.getText().length()));
// check abbreviations
for(WordElement abbreviation : entry.getAbbreviations())
if((pos =
ConnetionUtils.match(currentWord, abbreviation.getText(),
viewer, currentWordRegion, true)) >= 0)
proposalList
.add(new CompletionProposal(abbreviation.getText(),
currentWordRegion.getOffset() - pos,
currentWordRegion.getLength() + pos, abbreviation
.getText().length()));
checkAllProposal(proposalList, currentWord, currentWordRegion, viewer,
entry);
}
}
for(RequirementSource requirementSource : analysis.getRequirementSourceList()) {
for(RequirementSourceElement element : requirementSource
.getRequirementSourceElement()) {
int pos = -1;
// check elmenet name
if((pos =
ConnetionUtils.match(currentWord, element.getName(), viewer,
currentWordRegion, true)) >= 0)
proposalList.add(new CompletionProposal(element.getName(),
currentWordRegion.getOffset() - pos, currentWordRegion
.getLength() + pos, element.getName().length()));
checkAllProposal(proposalList, currentWord, currentWordRegion, viewer,
element);
if(element instanceof Stakeholder) {
for(Person person : ((Stakeholder)element).getContactList()) {
checkNameProposal(proposalList, currentWord, currentWordRegion,
viewer, person);
}
}
}
}
Comparator<ICompletionProposal> alphabeticallyComparator =
......@@ -149,6 +133,47 @@ public class ConnectionContentAssistProcessor implements IContentAssistProcessor
return null;
}
/** check proposal for current word */
private void checkNameProposal(List<ICompletionProposal> proposalList, String currentWord,
IRegion currentWordRegion, ITextViewer viewer, INamedCommentedElement element) {
int pos = -1;
// check entry name
if((pos =
ConnetionUtils.match(currentWord, element.getName(), viewer, currentWordRegion,
true)) >= 0) {
proposalList.add(new CompletionProposal(element.getName(), currentWordRegion
.getOffset() - pos, currentWordRegion.getLength() + pos, element.getName()
.length()));
}
}
/** check proposal for current word */
private void checkAllProposal(List<ICompletionProposal> proposalList, String currentWord,
IRegion currentWordRegion, ITextViewer viewer, ContextElement element) {
int pos = -1;
// check entry name
checkNameProposal(proposalList, currentWord, currentWordRegion, viewer, element);
// check synonyms
for(WordElement synoym : element.getSynonyms())
if((pos =
ConnetionUtils.match(currentWord, synoym.getText(), viewer, currentWordRegion,
true)) >= 0)
proposalList.add(new CompletionProposal(synoym.getText(), currentWordRegion
.getOffset() - pos, currentWordRegion.getLength() + pos, synoym.getText()
.length()));
// check abbreviations
for(WordElement abbreviation : element.getAbbreviations())
if((pos =
ConnetionUtils.match(currentWord, abbreviation.getText(), viewer,
currentWordRegion, true)) >= 0)
proposalList.add(new CompletionProposal(abbreviation.getText(), currentWordRegion
.getOffset() - pos, currentWordRegion.getLength() + pos, abbreviation
.getText().length()));
}
/** {@inheritDoc} */
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
......
......@@ -27,21 +27,32 @@ import org.eclipse.swt.widgets.Display;
* @author kisslinger
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: E038B7C1D5D95D67E52FEF1B86ED589F
* @ConQAT.Rating YELLOW Hash: FD6302EA6B65B6CF8ABC1BF331D005C9
*/
public class ConnectionHighlightColorConstants {
/** color defined for external system: Blue */
public static final Color EXTERNALSYSTEM_COLOR = new Color(Display.getCurrent(), new RGB(0, 0,
255));
/** color defined for external system synonym: MediumBlue */
public static final Color EXTERNALSYSTEM_SYNONYM_COLOR = new Color(Display.getCurrent(),
new RGB(0, 0, 205));
/** color defined for : Red1 */
public static final Color ENTRY_COLOR = new Color(Display.getCurrent(), new RGB(225, 0, 0));
/** color defined for entries synonyms: Red4 */
public static final Color ENTRY_SYNONYM_COLOR = new Color(Display.getCurrent(), new RGB(139, 0,
0));
/** color defined for stakeholder: gold */
public static final Color STAKEHOLDER_COLOR = EXTERNALSYSTEM_COLOR;
// new Color(Display.getCurrent(), new RGB(255, 215,0));
/** color defined for stakeholder synonym: goldenrod */
public static final Color STAKEHOLDER_SYNONYM_COLOR = EXTERNALSYSTEM_COLOR;
// new Color(Display.getCurrent(), new RGB(218, 165, 32));
/** color defined for requirement document: Green */
public static final Color REQUIREMENTDOCUMENT_COLOR = EXTERNALSYSTEM_COLOR;
// new Color(Display.getCurrent(), new RGB0, 255, 0));
/** color defined for requirement document synonym: SpringGreen */
public static final Color REQUIREMENTDOCUMENT_SYNONYM_COLOR = EXTERNALSYSTEM_COLOR;
// new Color(Display.getCurrent(),new RGB(0, 255, 127));
/** color defined for synonyms */
public static final Color SYNONYM_COLOR = new Color(Display.getCurrent(), new RGB(128, 0, 0));
/** color defined for entries */
public static final Color ENTRY_COLOR = new Color(Display.getCurrent(), new RGB(65, 105, 225));
/** color defined for stakeholder */
public static final Color STAKEHOLDER_COLOR = new Color(Display.getCurrent(), new RGB(147, 112,
219));
/** color defined for requirement document */
public static final Color REQUIREMENTDOCUMENT_COLOR = new Color(Display.getCurrent(), new RGB(
244, 164, 96));
/** color defined for external system */
public static final Color EXTERNALSYSTEM_COLOR = new Color(Display.getCurrent(), new RGB(0,
128, 0));
}
......@@ -31,14 +31,17 @@ import org.eclipse.jface.text.ITextHoverExtension2;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.source.ISourceViewer;
import org.fortiss.af3.mira.model.Analysis;
import org.fortiss.af3.mira.model.ContextElement;
import org.fortiss.af3.mira.model.IImageContainer;
import org.fortiss.af3.mira.model.WordElement;
import org.fortiss.af3.mira.model.glossary.Glossary;
import org.fortiss.af3.mira.model.glossary.GlossaryEntry;
import org.fortiss.af3.mira.model.glossary.WordElement;
import org.fortiss.af3.mira.model.requirementSource.ExternalSystem;
import org.fortiss.af3.mira.model.requirementSource.Person;
import org.fortiss.af3.mira.model.requirementSource.RequirementDocument;
import org.fortiss.af3.mira.model.requirementSource.RequirementSource;
import org.fortiss.af3.mira.model.requirementSource.RequirementSourceElement;
import org.fortiss.af3.mira.model.requirementSource.Stakeholder;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
/**
* Computes the information which should be shown in a hover popup over a
......@@ -48,7 +51,7 @@ import org.fortiss.af3.mira.model.requirementSource.Stakeholder;
* @author kisslinger
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: B0436520FF38048624034FBDCBD854D7
* @ConQAT.Rating YELLOW Hash: 25638CDF3FD309897FD071DD7CFA614A
*/
public class ConnectionTextHover extends DefaultTextHover implements ITextHoverExtension2 {
......@@ -83,63 +86,49 @@ public class ConnectionTextHover extends DefaultTextHover implements ITextHoverE
// add HTML code for each result
for(ConnectionSearchResult resultListElement : resultList) {
if(resultListElement.getEntry() != null) {
hoverText.append("<p><h4> Glossary Entry </h4></p>");
if(resultListElement.getEntry().getImagesLength() > 0)
hoverText
.append("<div style='width:150px; font-size:80%; text-align:center;float:right;margin-left:15px;margin-bottom:10px'>" +
"<div><img src='" +
getImageFile(resultListElement.getEntry().getImages(0))
.getAbsolutePath() +
"' width='150' /></div>" +
(resultListElement.getEntry().getImages(0).getName() != null
? resultListElement.getEntry().getImages(0)
.getName() : "") + "</div>");
hoverText.append("<span style='margin-right:10px;'><b><a href='id:" +
resultListElement.getEntry().getId() + "'>" +
resultListElement.getMatchingPropertyText() + "</a></b></span>");
if(resultListElement.getType().equals(ResultType.ABBREVIATION)) {
hoverText.append("<i>Abbreviation of " +
resultListElement.getEntry().getName() + "</i>");
}
if(resultListElement.getType().equals(ResultType.SYNONYM)) {
hoverText.append("<i>Synonym of " + resultListElement.getEntry().getName() +
"</i>");
}
hoverText.append("<p> Definition: " +
resultListElement.getEntry().getDefinition() + "</p>");
hoverText.append("<hr style='clear:right'>");
if(resultListElement.getElememnt() == null) {
continue;
}
if(resultListElement.getRequirementSourceElement() != null) {
if(resultListElement.getType().equals(ResultType.SNAME)) {
hoverText.append("<h4> Stakeholder </h4>");
hoverText.append("<span style='margin-right:10px;'><b><a href='id:" +
resultListElement.getRequirementSourceElement().getId() + "'>" +
resultListElement.getMatchingPropertyText() + "</a></b></span>");
}
if(resultListElement.getType().equals(ResultType.DNAME)) {
hoverText.append("<h4> Document </h4>");
hoverText.append("<span style='margin-right:10px;'><b><a href='id:" +
resultListElement.getRequirementSourceElement().getId() + "'>" +
resultListElement.getMatchingPropertyText() + "</a></b></span>");
}
if(resultListElement.getType().equals(ResultType.ENAME)) {
hoverText.append("<h4> External System </h4>");
hoverText.append("<span style='margin-right:10px;'><b><a href='id:" +
resultListElement.getRequirementSourceElement().getId() + "'>" +
resultListElement.getMatchingPropertyText() + "</a></b></span>");
}
hoverText.append("<p> Description: " +
resultListElement.getRequirementSourceElement().getDescription() +
"</p>");
hoverText.append("<hr style='clear:right'>");
if(resultListElement.getElememnt() instanceof GlossaryEntry) {
hoverText(hoverText, resultListElement.getElememnt(), "Glossary Entry",
resultListElement.getMatchingPropertyText(),
((GlossaryEntry)resultListElement.getElememnt()).getImagesLength() > 0,
resultListElement.getType().equals(ResultType.GABBREVIATION),
resultListElement.getType().equals(ResultType.GSYNONYM), true);
}
if(resultListElement.getElememnt() instanceof Stakeholder) {
hoverText(hoverText, resultListElement.getElememnt(), "Stakeholder",
resultListElement.getMatchingPropertyText(), false, resultListElement
.getType().equals(ResultType.SABBREVIATION), resultListElement
.getType().equals(ResultType.SSYNONYM), true);
}
if(resultListElement.getElememnt() instanceof Person) {
hoverText(hoverText, resultListElement.getElememnt(), "Contact Person",
resultListElement.getMatchingPropertyText(), false, false, false, false);
Person person = (Person)resultListElement.getElememnt();
hoverText.append("<i>Contact person of " + person.getStakeholder().getName() +
"</i>");
String eMail = person.getEMailAddress() == null ? "" : person.getEMailAddress();
String telephone =
person.getTelephoneNr() == null ? "" : person.getTelephoneNr();
String mobile = person.getMobileNr() == null ? "" : person.getMobileNr();
hoverText.append("<ul><li>Email: " + eMail + "</li><li>Telephone: " +
telephone + "</li><li>Mobile: " + mobile + "</li></ul>");
}
if(resultListElement.getElememnt() instanceof RequirementDocument) {
hoverText(hoverText, resultListElement.getElememnt(), "Document",
resultListElement.getMatchingPropertyText(), false, resultListElement
.getType().equals(ResultType.DABBREVIATION), resultListElement
.getType().equals(ResultType.DSYNONYM), true);
}
if(resultListElement.getElememnt() instanceof ExternalSystem) {
hoverText(hoverText, resultListElement.getElememnt(), "External System",
resultListElement.getMatchingPropertyText(), false, resultListElement
.getType().equals(ResultType.EABBREVIATION), resultListElement
.getType().equals(ResultType.ESYNONYM), true);
}
}
return hoverText.toString();
......@@ -147,6 +136,41 @@ public class ConnectionTextHover extends DefaultTextHover implements ITextHoverE
return "";
}
/** hover text */
private void hoverText(StringBuilder hoverText, INamedCommentedElement element, String title,
String text, boolean hasImage, boolean isAbbreviation, boolean isSynonym,
boolean hasLine) {
hoverText.append("<p><h4> " + title + " </h4></p>");
if(hasImage && element instanceof IImageContainer) {
hoverText
.append("<div style='width:150px; font-size:80%; text-align:center;float:right;margin-left:15px;margin-bottom:10px'>" +
"<div><img src='" +
getImageFile(((IImageContainer)element).getImages(0)).getAbsolutePath() +
"' width='150' /></div>" +
(((IImageContainer)element).getImages(0).getName() != null
? ((IImageContainer)element).getImages(0).getName() : "") +
"</div>");
}
hoverText.append("<span style='margin-right:10px;'><b><a href='id:" + element.getId() +
"'>" + text + "</a></b></span>");
if(isAbbreviation) {
hoverText.append("<i>Abbreviation of " + element.getName() + "</i>");
}
if(isSynonym) {
hoverText.append("<i>Synonym of " + element.getName() + "</i>");
}
if(element instanceof ContextElement) {
hoverText.append("<p> Definition: " + ((ContextElement)element).getDefinition() +
"</p>");
}
if(hasLine) {
hoverText.append("<hr style='clear:right'>");
}
}
/**
*
* Method to search glossary entries matching to a hovered word (plus
......@@ -171,55 +195,37 @@ public class ConnectionTextHover extends DefaultTextHover implements ITextHoverE
for(Glossary glossary : analysis.getGlossariesList()) {
for(GlossaryEntry entry : glossary.getGlossaryEntryList()) {
searchAllMatching(entry, textViewer, hoverRegion, hoveredWord,
ResultType.GNAME, ResultType.GABBREVIATION, ResultType.GSYNONYM,
resultList);
// search entries with matching name
if(match(hoveredWord, entry.getName(), textViewer, hoverRegion, false) >= 0) {
resultList.add(new ConnectionSearchResult(entry, null, ResultType.NAME,
entry.getName()));
}
// search entries with matching abbreviation
for(WordElement abbreviation : entry.getAbbreviations()) {
if(match(hoveredWord, abbreviation.getText(), textViewer, hoverRegion,
false) >= 0) {
resultList.add(new ConnectionSearchResult(entry, null,
ResultType.ABBREVIATION, abbreviation.getText()));
}
}
// search entries with matching synonym
for(WordElement synonym : entry.getSynonyms()) {
if(match(hoveredWord, synonym.getText(), textViewer, hoverRegion, false) >= 0) {
resultList.add(new ConnectionSearchResult(entry, null,
ResultType.SYNONYM, synonym.getText()));
}
}
}
}
for(RequirementSource requirementSource : analysis.getRequirementSourceList()) {
for(Stakeholder stakeholder : requirementSource.getStakeholder()) {
// search stakeholder with matching name
if(match(hoveredWord, stakeholder.getName(), textViewer, hoverRegion, false) >= 0) {
resultList.add(new ConnectionSearchResult(null, stakeholder,
ResultType.SNAME, stakeholder.getName()));
searchAllMatching(stakeholder, textViewer, hoverRegion, hoveredWord,
ResultType.SNAME, ResultType.SABBREVIATION, ResultType.SSYNONYM,
resultList);
// search contact person of stakeholder with matching name
for(Person person : stakeholder.getContactList()) {
searchNameMatching(person, textViewer, hoverRegion, hoveredWord,
ResultType.SCONTACT, resultList);
}
}
for(RequirementDocument requirementDocument : requirementSource
.getRequirementDocument()) {
// search requirement document with matching name
if(match(hoveredWord, requirementDocument.getName(), textViewer, hoverRegion,
false) >= 0) {
resultList.add(new ConnectionSearchResult(null, requirementDocument,
ResultType.DNAME, requirementDocument.getName()));
}
searchAllMatching(requirementDocument, textViewer, hoverRegion, hoveredWord,
ResultType.DNAME, ResultType.DABBREVIATION, ResultType.DSYNONYM,
resultList);
}
for(ExternalSystem externalSystem : requirementSource.getExternalSystem()) {
// search external system with matching name
if(match(hoveredWord, externalSystem.getName(), textViewer, hoverRegion, false) >= 0) {
resultList.add(new ConnectionSearchResult(null, externalSystem,
ResultType.ENAME, externalSystem.getName()));
}
searchAllMatching(externalSystem, textViewer, hoverRegion, hoveredWord,
ResultType.ENAME, ResultType.EABBREVIATION, ResultType.ESYNONYM,
resultList);
}
}
} catch(BadLocationException e) {
......@@ -228,21 +234,69 @@ public class ConnectionTextHover extends DefaultTextHover implements ITextHoverE
return resultList;
}
/** search element with matching name */
private void searchNameMatching(INamedCommentedElement element, ITextViewer textViewer,
IRegion hoverRegion, String hoveredWord, ResultType nameType,
List<ConnectionSearchResult> resultList) {
if(match(hoveredWord, element.getName(), textViewer, hoverRegion, false) >= 0) {
resultList.add(new ConnectionSearchResult(element, nameType, element.getName()));
}
}
/** search element with matching name, abbreviation and synonym */
private void searchAllMatching(ContextElement element, ITextViewer textViewer,
IRegion hoverRegion, String hoveredWord, ResultType nameType,
ResultType abbreviationType, ResultType synonymType,
List<ConnectionSearchResult> resultList) {
// search entries with matching name
searchNameMatching(element, textViewer, hoverRegion, hoveredWord, nameType, resultList);
// search entries with matching abbreviation
for(WordElement abbreviation : element.getAbbreviations()) {
if(match(hoveredWord, abbreviation.getText(), textViewer, hoverRegion, false) >= 0) {
resultList.add(new ConnectionSearchResult(element, abbreviationType, abbreviation
.getText()));
}
}
// search entries with matching synonym
for(WordElement synonym : element.getSynonyms()) {
if(match(hoveredWord, synonym.getText(), textViewer, hoverRegion, false) >= 0) {
resultList.add(new ConnectionSearchResult(element, synonymType, synonym.getText()));
}
}
}
/** enumeration of possible result types */
private static enum ResultType {
/** matching by the stakeholder name */
SNAME(-3),
SNAME(0),
/** matching by a synonym text of the stakeholder */
SSYNONYM(1),
/** matching by an abbreviation text of the stakeholder */
SABBREVIATION(2),
/** matching by a contact person text of the stakeholder */
SCONTACT(3),
/** matching by the requirement document name */
DNAME(-2),
DNAME(4),
/** matching by a synonym text of the document */
DSYNONYM(5),
/** matching by an abbreviation text of the document */
DABBREVIATION(6),
/** matching by the external system name */
ENAME(-1),
ENAME(7),
/** matching by a synonym text of the external system */
ESYNONYM(8),
/** matching by an abbreviation text of the external system */
EABBREVIATION(9),
/** matching by the entry name */
NAME(0),
/** matching by a synonym text */
SYNONYM(1),
/** matching by an abbreviation text */
ABBREVIATION(2);
GNAME(10),
/** matching by a synonym text of the entry */
GSYNONYM(11),
/** matching by an abbreviation text of the entry */
GABBREVIATION(12);
/** level code for comparison */
private int level;
......@@ -268,10 +322,9 @@ public class ConnectionTextHover extends DefaultTextHover implements ITextHoverE
* @ConQAT.Rating YELLOW Hash: BB01F907B5F1563F57D6DF69FEBE4148
*/
private static class ConnectionSearchResult implements Comparable<ConnectionSearchResult> {
/** the found entry */
private GlossaryEntry entry;
/** the found element */
private RequirementSourceElement element;
private INamedCommentedElement element;
/** the type of the result */
private ResultType type;
/**
......@@ -283,28 +336,22 @@ public class ConnectionTextHover extends DefaultTextHover implements ITextHoverE
/**
* constructor
*
* @param entry
* the found entry
* @param element
* the found element
* @param type
* the type of the result
* @param matchingPropertyText
* the property text which matched to the search request
*/
public ConnectionSearchResult(GlossaryEntry entry, RequirementSourceElement element,
ResultType type, String matchingPropertyText) {
this.entry = entry;
public ConnectionSearchResult(INamedCommentedElement element, ResultType type,
String matchingPropertyText) {
this.element = element;
this.type = type;
this.matchingPropertyText = matchingPropertyText;