Search in sources :

Example 6 with TextPropertyDescriptor

use of org.eclipse.ui.views.properties.TextPropertyDescriptor in project webtools.sourceediting by eclipse.

the class XMLTableTreePropertyDescriptorFactory method createElementPropertyDescriptor.

public IPropertyDescriptor createElementPropertyDescriptor(Element element) {
    IPropertyDescriptor result = null;
    List list = treeContentHelper.getElementTextContent(element);
    if (list != null) {
        Text text = treeContentHelper.getEffectiveTextNodeForCombinedNodeList(list);
        if (text != null) {
            result = createTextPropertyDescriptor(text);
        }
    }
    if (result == null) {
        result = new TextPropertyDescriptor(HACK, HACK);
    }
    return result;
}
Also used : List(java.util.List) Text(org.w3c.dom.Text) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor)

Example 7 with TextPropertyDescriptor

use of org.eclipse.ui.views.properties.TextPropertyDescriptor in project webtools.sourceediting by eclipse.

the class XMLPropertySource method updatePropertyDescriptors.

protected void updatePropertyDescriptors() {
    if ((fDescriptors == null) || (fDescriptors.length == 0)) {
        // Nothing to update
        return;
    }
    // List of all names encountered in the tag and defined by the element
    List declaredNames = new ArrayList();
    // New descriptor list that will become fDescriptors after all
    // processing is done
    List descriptors = new ArrayList();
    // Names of the descriptors in the above List
    List descriptorNames = new ArrayList();
    // Update any descriptors derived from the metainfo
    CMElementDeclaration ed = getDeclaration();
    CMNamedNodeMap attrMap = null;
    if (ed != null) {
        attrMap = ed.getAttributes();
        CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrMap);
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(fNode.getOwnerDocument());
        if (modelQuery != null) {
            List nodes = modelQuery.getAvailableContent((Element) fNode, ed, ModelQuery.INCLUDE_ATTRIBUTES);
            for (int k = 0; k < nodes.size(); k++) {
                CMNode cmnode = (CMNode) nodes.get(k);
                if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
                    allAttributes.put(cmnode);
                }
            }
        }
        attrMap = allAttributes;
    }
    // Update exiting descriptors; not added to the final list here
    if (attrMap != null) {
        // Update existing descriptor types based on metainfo
        CMAttributeDeclaration attrDecl = null;
        for (int i = 0; i < attrMap.getLength(); i++) {
            attrDecl = (CMAttributeDeclaration) attrMap.item(i);
            String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null);
            if (!declaredNames.contains(attrName)) {
                declaredNames.add(attrName);
            }
            for (int j = 0; j < fDescriptors.length; j++) {
                boolean sameName = (fCaseSensitive && fDescriptors[j].getId().equals(attrDecl.getNodeName())) || (!fCaseSensitive && attrDecl.getNodeName().equals(fDescriptors[j].getId().toString()));
                if (sameName) {
                    String[] validValues = getValidValues(attrDecl);
                    // updated for now)
                    if (fDescriptors[j] instanceof EnumeratedStringPropertyDescriptor) {
                        ((EnumeratedStringPropertyDescriptor) fDescriptors[j]).updateValues(validValues);
                    } else // Replace with better descriptor
                    if ((validValues != null) && (validValues.length > 0)) {
                        fDescriptors[j] = createPropertyDescriptor(attrDecl, null);
                    }
                }
            }
        }
    } else {
        // Update existing descriptors based on not having any metainfo
        for (int j = 0; j < fDescriptors.length; j++) {
            // Replace with basic descriptor
            if (!(fDescriptors[j] instanceof TextPropertyDescriptor)) {
                fDescriptors[j] = createDefaultPropertyDescriptor((String) fDescriptors[j].getId());
            }
        }
    }
    NamedNodeMap attributes = fNode.getAttributes();
    // are present or declared
    for (int i = 0; i < fDescriptors.length; i++) {
        if (fDescriptors[i] != null) {
            String descriptorName = fDescriptors[i].getId().toString();
            if ((declaredNames.contains(descriptorName) || (attributes.getNamedItem(descriptorName) != null)) && !descriptorNames.contains(descriptorName)) {
                descriptorNames.add(descriptorName);
                descriptors.add(fDescriptors[i]);
            }
        }
    }
    // Add descriptors for declared attributes that don't already have one
    if (attrMap != null) {
        // Update existing descriptor types based on metainfo
        CMAttributeDeclaration attrDecl = null;
        for (int i = 0; i < attrMap.getLength(); i++) {
            attrDecl = (CMAttributeDeclaration) attrMap.item(i);
            String attrName = DOMNamespaceHelper.computeName(attrDecl, fNode, null);
            if (fCaseSensitive) {
                if (!descriptorNames.contains(attrName)) {
                    IPropertyDescriptor descriptor = createPropertyDescriptor(attrDecl, null);
                    if (descriptor != null) {
                        descriptorNames.add(attrName);
                        descriptors.add(descriptor);
                    }
                }
            } else {
                boolean exists = false;
                for (int j = 0; j < descriptorNames.size(); j++) {
                    exists = (descriptorNames.get(j).toString().equalsIgnoreCase(attrName)) || exists;
                }
                if (!exists) {
                    descriptorNames.add(attrName);
                    IPropertyDescriptor descriptor = createPropertyDescriptor(attrDecl, null);
                    if (descriptor != null) {
                        descriptorNames.add(attrName);
                        descriptors.add(descriptor);
                    }
                }
            }
        }
    }
    // Add descriptors for existing attributes that don't already have one
    if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {
            Attr attr = (Attr) attributes.item(i);
            String attrName = attr.getName();
            if (fCaseSensitive) {
                if (!descriptorNames.contains(attrName)) {
                    descriptorNames.add(attrName);
                    descriptors.add(createDefaultPropertyDescriptor(attrName));
                }
            } else {
                boolean exists = false;
                for (int j = 0; j < descriptorNames.size(); j++) {
                    exists = (descriptorNames.get(j).toString().equalsIgnoreCase(attrName)) || exists;
                }
                if (!exists) {
                    descriptorNames.add(attrName);
                    descriptors.add(createDefaultPropertyDescriptor(attrName));
                }
            }
        }
    }
    // Update fDescriptors
    IPropertyDescriptor[] newDescriptors = new IPropertyDescriptor[descriptors.size()];
    for (int i = 0; i < newDescriptors.length; i++) {
        newDescriptors[i] = (IPropertyDescriptor) descriptors.get(i);
    }
    fDescriptors = newDescriptors;
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) NamedNodeMap(org.w3c.dom.NamedNodeMap) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) ArrayList(java.util.ArrayList) Attr(org.w3c.dom.Attr) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ArrayList(java.util.ArrayList) List(java.util.List) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 8 with TextPropertyDescriptor

use of org.eclipse.ui.views.properties.TextPropertyDescriptor in project webtools.sourceediting by eclipse.

the class XMLPropertySource method createDefaultPropertyDescriptor.

private IPropertyDescriptor createDefaultPropertyDescriptor(String attributeName, boolean hideOnFilter) {
    // The descriptor class used here is also used in
    // updatePropertyDescriptors()
    TextPropertyDescriptor descriptor = new TextPropertyDescriptor(attributeName, attributeName);
    descriptor.setCategory(getCategory(null, null));
    descriptor.setDescription(attributeName);
    if (hideOnFilter && fSetExpertFilter) {
        descriptor.setFilterFlags(new String[] { IPropertySheetEntry.FILTER_ID_EXPERT });
    }
    return descriptor;
}
Also used : TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor)

Example 9 with TextPropertyDescriptor

use of org.eclipse.ui.views.properties.TextPropertyDescriptor in project jbosstools-hibernate by jbosstools.

the class ExporterFactoryPropertySource method getPropertyDescriptors.

public IPropertyDescriptor[] getPropertyDescriptors() {
    List<IPropertyDescriptor> descriptors = new ArrayList<IPropertyDescriptor>();
    Map<String, String> values = factory.getProperties();
    // get the values we explicitly have
    for (String key : values.keySet()) {
        ExporterProperty element = factory.getExporterProperty(key);
        if (element != null) {
            descriptors.add(new TextPropertyDescriptor(element.getName(), element.getDescription() == null ? element.getName() : element.getDescription()));
        } else {
            descriptors.add(new TextPropertyDescriptor(key, key));
        }
    }
    return descriptors.toArray(new IPropertyDescriptor[0]);
}
Also used : ArrayList(java.util.ArrayList) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) ExporterProperty(org.hibernate.eclipse.console.model.impl.ExporterProperty)

Aggregations

TextPropertyDescriptor (org.eclipse.ui.views.properties.TextPropertyDescriptor)9 IPropertyDescriptor (org.eclipse.ui.views.properties.IPropertyDescriptor)7 ArrayList (java.util.ArrayList)3 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)3 List (java.util.List)2 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)2 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)2 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 TreeNode (javax.swing.tree.TreeNode)1 PropertyDescriptor (org.eclipse.ui.views.properties.PropertyDescriptor)1 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)1 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)1 ExporterProperty (org.hibernate.eclipse.console.model.impl.ExporterProperty)1 Config (org.knime.core.node.config.Config)1 AbstractConfigEntry (org.knime.core.node.config.base.AbstractConfigEntry)1 Attr (org.w3c.dom.Attr)1 Element (org.w3c.dom.Element)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1