use of com.archimatetool.model.INameable in project archi by archimatetool.
the class TreeModelViewerFindReplaceProviderTests method testFindNextElement_Backward_NotCaseSensitive_1.
@Test
public void testFindNextElement_Backward_NotCaseSensitive_1() {
provider.setParameter(IFindReplaceProvider.PARAM_FORWARD, false);
provider.setParameter(IFindReplaceProvider.PARAM_CASE_SENSITIVE, false);
provider.setParameter(IFindReplaceProvider.PARAM_ALL_MODELS, true);
// Relations as well
provider.setParameter(IFindReplaceProvider.PARAM_INCLUDE_RELATIONS, true);
String searchString = "findme";
Object startElement = ArchimateModelUtils.getObjectByID(model1, "2b0cb580");
assertNotNull(startElement);
INameable element = provider.findNextElement(startElement, searchString);
assertEquals("FindMe 10", element.getName());
for (int i = 9; i >= 0; i--) {
element = provider.findNextElement(element, searchString);
assertEquals("FindMe " + i, element.getName());
}
// No more
assertNull(provider.findNextElement(element, searchString));
}
use of com.archimatetool.model.INameable in project archi by archimatetool.
the class TreeModelViewerFindReplaceProviderTests method testFindNextElement_Backward_CaseSensitive.
@Test
public void testFindNextElement_Backward_CaseSensitive() {
provider.setParameter(IFindReplaceProvider.PARAM_FORWARD, false);
provider.setParameter(IFindReplaceProvider.PARAM_CASE_SENSITIVE, true);
provider.setParameter(IFindReplaceProvider.PARAM_ALL_MODELS, true);
// Relations as well
provider.setParameter(IFindReplaceProvider.PARAM_INCLUDE_RELATIONS, true);
String searchString = "Find";
Object startElement = ArchimateModelUtils.getObjectByID(model1, "2b0cb580");
assertNotNull(startElement);
INameable element = provider.findNextElement(startElement, searchString);
assertEquals("FindMe 10", element.getName());
for (int i = 9; i >= 0; i--) {
element = provider.findNextElement(element, searchString);
assertEquals("FindMe " + i, element.getName());
}
// No more
assertNull(provider.findNextElement(element, searchString));
}
use of com.archimatetool.model.INameable in project archi by archimatetool.
the class TreeModelViewerFindReplaceProvider method findNextElement.
/**
* Find the next/previous element in the tree that matches the find criteria
* @param startElement The element to start the search from for next/previous
* @param toFind The string to find
* @return The next/previous element if found, or null
*/
INameable findNextElement(Object startElement, String toFind) {
// Get *all* elements in the viewer
List<INameable> elements = getAllNameableElements();
if (elements.isEmpty()) {
return null;
}
// Increment for forward/backward
int increment = isForward() ? 1 : -1;
// Starting index (defaults for a null startElement)
int startIndex = isForward() ? 0 : elements.size() - 1;
// Find starting point from startElement, if we have one
if (startElement != null) {
startIndex = elements.indexOf(startElement) + increment;
}
// Iterate through all elements forwards or backwards until we find the next matching element
for (int i = startIndex; isForward() ? (i < elements.size()) : (i >= 0); i += increment) {
Object element = elements.get(i);
if (matches(element, toFind)) {
return (INameable) element;
}
}
return null;
}
use of com.archimatetool.model.INameable in project archi by archimatetool.
the class SearchFilter method matchesFilter.
/**
* Query whether element matches filter criteria when filtering on node/leaf elements
* @param element Any element, children will not be queried.
* @return
*/
public boolean matchesFilter(Object element) {
// EObject Type filter - do this first as the master filter
if (isObjectFiltered(element)) {
return false;
}
boolean textSearchResult = false;
boolean propertyKeyResult = false;
// Properties Key filter
if (isFilteringPropertyKeys() && element instanceof IProperties) {
for (IProperty property : ((IProperties) element).getProperties()) {
if (fPropertiesFilter.contains(property.getKey())) {
propertyKeyResult = true;
if (hasSearchText() && property.getValue().toLowerCase().contains(fSearchText.toLowerCase())) {
textSearchResult = true;
}
}
}
}
// If has search Text and no text found yet
if (hasSearchText()) {
// Name...
if (fFilterName && !textSearchResult && element instanceof INameable) {
String name = StringUtils.safeString(((INameable) element).getName());
if (name.toLowerCase().contains(fSearchText.toLowerCase())) {
textSearchResult = true;
}
}
// Then Documentation
if (fFilterDocumentation && !textSearchResult && element instanceof IDocumentable) {
String text = StringUtils.safeString(((IDocumentable) element).getDocumentation());
if (text.toLowerCase().contains(fSearchText.toLowerCase())) {
textSearchResult = true;
}
}
}
if ((hasSearchText())) {
return textSearchResult;
}
if (isFilteringPropertyKeys()) {
return propertyKeyResult;
}
return !isObjectFiltered(element);
}
Aggregations