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;
}
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;
}
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;
}
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]);
}
Aggregations