Search in sources :

Example 21 with IProperty

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

the class UserPropertiesSection method getDropTargetPosition.

private int getDropTargetPosition(DropTargetEvent event) {
    int index = -1;
    Point pt = fTableViewer.getControl().toControl(event.x, event.y);
    if (pt.y < 5) {
        index = 0;
    } else if (event.item != null) {
        IProperty property = (IProperty) event.item.getData();
        index = fPropertiesElement.getProperties().indexOf(property);
    } else {
        index = fPropertiesElement.getProperties().size();
    }
    // Dropped in after position
    int feedback = getDragFeedbackType(event);
    if (feedback == DND.FEEDBACK_INSERT_AFTER) {
        index += 1;
    }
    return index;
}
Also used : IProperty(com.archimatetool.model.IProperty) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 22 with IProperty

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

the class AbstractModelView method getParentToRefreshFromNotification.

/**
 * @return The parent folder to refresh when one of its children is added/removed/set
 */
protected Object getParentToRefreshFromNotification(Notification msg) {
    int type = msg.getEventType();
    EObject element = null;
    if (type == Notification.REMOVE) {
        if (msg.getNotifier() instanceof EObject) {
            element = (EObject) msg.getNotifier();
            // Property removed and element has format expression
            if (msg.getOldValue() instanceof IProperty && hasFormatExpression(element)) {
                element = element.eContainer();
            }
        }
    } else if (type == Notification.ADD) {
        if (msg.getNewValue() instanceof EObject) {
            element = ((EObject) msg.getNewValue()).eContainer();
            // Property added and element has format expression
            if (msg.getNewValue() instanceof IProperty && hasFormatExpression(element)) {
                element = element.eContainer();
            }
        }
    } else if (type == Notification.SET) {
        // Need to refresh parent node on name or label expression change because of using a ViewerSorter
        if (msg.getNotifier() instanceof EObject) {
            element = ((EObject) msg.getNotifier());
            // Name
            if (msg.getFeature() == IArchimatePackage.Literals.NAMEABLE__NAME) {
                element = element.eContainer();
            } else // Ancestor folder has label expression
            if (hasFormatExpression(element)) {
                element = element.eContainer();
                // Property set
                if (msg.getNotifier() instanceof IProperty) {
                    element = element.eContainer();
                }
            }
        }
    }
    return (element instanceof IFolder) ? element : null;
}
Also used : IProperty(com.archimatetool.model.IProperty) EObject(org.eclipse.emf.ecore.EObject) IFolder(com.archimatetool.model.IFolder)

Example 23 with IProperty

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

the class PropertiesRenderer method getAllProperties.

private String getAllProperties(IProperties object, boolean full) {
    String s = "";
    for (int i = 0; i < object.getProperties().size(); i++) {
        IProperty property = object.getProperties().get(i);
        if (full) {
            s += property.getKey() + ": ";
        }
        s += property.getValue();
        if (i < object.getProperties().size() - 1) {
            s += "\n";
        }
    }
    return s;
}
Also used : IProperty(com.archimatetool.model.IProperty)

Example 24 with IProperty

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

the class PropertiesRenderer method renderPropertyValue.

private String renderPropertyValue(IArchimateModelObject object, String text) {
    Matcher matcher = PROPERTY_VALUE_PATTERN.matcher(text);
    while (matcher.find()) {
        String prefix = matcher.group(1);
        String key = matcher.group(2);
        String propertyValue = "";
        IArchimateModelObject refObject = getObjectFromPrefix(object, prefix);
        if (refObject instanceof IProperties) {
            IProperty property = getProperty((IProperties) refObject, key);
            if (property != null) {
                propertyValue = property.getValue();
            }
        }
        text = text.replace(matcher.group(), propertyValue);
    }
    return text;
}
Also used : IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) Matcher(java.util.regex.Matcher) IProperty(com.archimatetool.model.IProperty) IProperties(com.archimatetool.model.IProperties)

Example 25 with IProperty

use of com.archimatetool.model.IProperty 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());
            // Normalise in case of multi-line text
            name = StringUtils.normaliseNewLineCharacters(name);
            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

IProperty (com.archimatetool.model.IProperty)32 EObject (org.eclipse.emf.ecore.EObject)10 Test (org.junit.Test)9 IArchimateElement (com.archimatetool.model.IArchimateElement)5 IProperties (com.archimatetool.model.IProperties)5 IArchimateModel (com.archimatetool.model.IArchimateModel)4 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)4 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)4 Point (org.eclipse.swt.graphics.Point)4 HashSet (java.util.HashSet)3 Matcher (java.util.regex.Matcher)3 EObjectNonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand)2 IArchimateConcept (com.archimatetool.model.IArchimateConcept)2 Command (org.eclipse.gef.commands.Command)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Element (org.jdom2.Element)2 CSVParseException (com.archimatetool.csv.CSVParseException)1 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)1 IPreferenceConstants (com.archimatetool.editor.preferences.IPreferenceConstants)1