Search in sources :

Example 16 with INameable

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));
}
Also used : INameable(com.archimatetool.model.INameable) Test(org.junit.Test)

Example 17 with INameable

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));
}
Also used : INameable(com.archimatetool.model.INameable) Test(org.junit.Test)

Example 18 with INameable

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;
}
Also used : INameable(com.archimatetool.model.INameable) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject)

Example 19 with INameable

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);
}
Also used : IDocumentable(com.archimatetool.model.IDocumentable) IProperty(com.archimatetool.model.IProperty) INameable(com.archimatetool.model.INameable) IProperties(com.archimatetool.model.IProperties)

Aggregations

INameable (com.archimatetool.model.INameable)19 Test (org.junit.Test)7 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)3 CommandStack (org.eclipse.gef.commands.CommandStack)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 ExportAsImageWizard (com.archimatetool.editor.diagram.wizard.ExportAsImageWizard)2 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)2 ExtendedWizardDialog (com.archimatetool.editor.ui.components.ExtendedWizardDialog)2 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)2 IDocumentable (com.archimatetool.model.IDocumentable)2 IIdentifier (com.archimatetool.model.IIdentifier)2 ArrayList (java.util.ArrayList)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 IArchimateConcept (com.archimatetool.model.IArchimateConcept)1 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)1 IArchimateModel (com.archimatetool.model.IArchimateModel)1