Search in sources :

Example 6 with INameable

use of com.archimatetool.model.INameable in project archi by archimatetool.

the class TreeModelViewerFindReplaceProviderTests method testFindNextElement_Backward_NotCaseSensitive_2.

@Test
public void testFindNextElement_Backward_NotCaseSensitive_2() {
    provider.setParameter(IFindReplaceProvider.PARAM_FORWARD, false);
    provider.setParameter(IFindReplaceProvider.PARAM_CASE_SENSITIVE, false);
    provider.setParameter(IFindReplaceProvider.PARAM_ALL_MODELS, true);
    String searchString = "director";
    Object startElement = ArchimateModelUtils.getObjectByID(model2, "16fe3cf9");
    assertNotNull(startElement);
    INameable element = provider.findNextElement(startElement, searchString);
    assertEquals("Director of Sales", element.getName());
    element = provider.findNextElement(element, searchString);
    assertEquals("Director of Operations", element.getName());
    element = provider.findNextElement(element, searchString);
    assertEquals("Director of Finance", element.getName());
    // No more
    assertNull(provider.findNextElement(element, searchString));
}
Also used : INameable(com.archimatetool.model.INameable) Test(org.junit.Test)

Example 7 with INameable

use of com.archimatetool.model.INameable in project archi by archimatetool.

the class TreeModelViewerFindReplaceProviderTests method testFindNextElement_Forward_NotCaseSensitive_1.

@Test
public void testFindNextElement_Forward_NotCaseSensitive_1() {
    provider.setParameter(IFindReplaceProvider.PARAM_FORWARD, true);
    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";
    INameable element = provider.findNextElement(null, searchString);
    assertEquals("FindMe 0", element.getName());
    for (int i = 1; i < 11; 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 8 with INameable

use of com.archimatetool.model.INameable in project archi by archimatetool.

the class TreeModelViewerFindReplaceProvider method replace.

public boolean replace(String toFind, String toReplaceWith) {
    // Replace All
    if (isAll()) {
        List<INameable> elements = getAllMatchingElements(toFind);
        if (!elements.isEmpty()) {
            List<String> newNames = new ArrayList<String>();
            for (INameable nameable : elements) {
                String newName = getNewName(nameable.getName(), toFind, toReplaceWith);
                newNames.add(newName);
            }
            RenameCommandHandler.doRenameCommands(elements, newNames);
            fTreeModelViewer.setSelection(new StructuredSelection(elements), true);
        }
        return !elements.isEmpty();
    } else // Replace Next/Previous
    {
        // Replace on selected elements
        if (replaceSelection) {
            List<Object> selected = getSelectedObjects();
            if (!selected.isEmpty()) {
                List<INameable> elements = new ArrayList<INameable>();
                List<String> newNames = new ArrayList<String>();
                for (Object object : selected) {
                    if (matches(object, toFind)) {
                        INameable nameable = (INameable) object;
                        elements.add(nameable);
                        String newName = getNewName(nameable.getName(), toFind, toReplaceWith);
                        newNames.add(newName);
                    }
                }
                if (!elements.isEmpty()) {
                    RenameCommandHandler.doRenameCommands(elements, newNames);
                    return true;
                }
            }
        } else // Replace on next single selection
        {
            Object object = getFirstSelectedObject();
            if (matches(object, toFind)) {
                RenameCommandHandler.doRenameCommand((INameable) object, getNewName(((INameable) object).getName(), toFind, toReplaceWith));
                return true;
            }
        }
        // Else move forward
        return find(toFind);
    }
}
Also used : INameable(com.archimatetool.model.INameable) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject)

Example 9 with INameable

use of com.archimatetool.model.INameable in project archi by archimatetool.

the class TreeModelViewerFindReplaceProvider method find.

public boolean find(String toFind) {
    // Find All
    if (isAll()) {
        List<INameable> elements = getAllMatchingElements(toFind);
        fTreeModelViewer.setSelection(new StructuredSelection(elements), true);
        return !elements.isEmpty();
    } else // Find Next/Previous
    {
        INameable element = findNextElement(getFirstSelectedObject(), toFind);
        if (element != null) {
            fTreeModelViewer.setSelection(new StructuredSelection(element), true);
        }
        return (element != null);
    }
}
Also used : INameable(com.archimatetool.model.INameable) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 10 with INameable

use of com.archimatetool.model.INameable in project archi-modelrepository-plugin by archi-contribs.

the class GraficoModelLoader method getRestoredObjectsAsString.

/**
 * @return The list of resolved objects as a message string or null
 */
public String getRestoredObjectsAsString() {
    if (fRestoredObjects == null) {
        return null;
    }
    String s = Messages.GraficoModelLoader_0;
    for (IIdentifier id : fRestoredObjects) {
        if (id instanceof INameable) {
            String name = ((INameable) id).getName();
            String className = id.eClass().getName();
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            s += "\n" + (StringUtils.isSet(name) ? name + " (" + className + ")" : className);
        }
    }
    return s;
}
Also used : IIdentifier(com.archimatetool.model.IIdentifier) INameable(com.archimatetool.model.INameable)

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