private void upgradeGroup(final GroupItem group, final Element groupElement) { for (Object o : groupElement.getChildren(ELEMENT_ITEM)) { Element itemElement = (Element)o; if (itemElement.getAttributeValue(ATTRIBUTE_SINCE_VERSION, "").equals("2")) { processItemElement(itemElement, group, true); } final String className = LwXmlReader.getRequiredString(itemElement, ATTRIBUTE_CLASS); final ComponentItem item = getItem(className); if (item != null) { if (LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_AUTO_CREATE_BINDING, false)) { item.setAutoCreateBinding(true); } if (LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_CAN_ATTACH_LABEL, false)) { item.setCanAttachLabel(true); } } } }
@SuppressWarnings({"HardCodedStringLiteral"}) private void loadEnumProperties(final String className, final Element enumPropertyElement) { Map<String, IntEnumEditor.Pair[]> map = new HashMap<String, IntEnumEditor.Pair[]>(); for(final Object o: enumPropertyElement.getChildren("property")) { final Element e = (Element) o; final String name = LwXmlReader.getRequiredString(e, "name"); final List list = e.getChildren("constant"); IntEnumEditor.Pair[] pairs = new IntEnumEditor.Pair[list.size()]; for(int i=0; i<list.size(); i++) { Element constant = (Element) list.get(i); int value = LwXmlReader.getRequiredInt(constant, "value"); String message = constant.getAttributeValue("message"); String text = (message != null) ? UIDesignerBundle.message(message) : LwXmlReader.getRequiredString(constant, "name"); pairs [i] = new IntEnumEditor.Pair(value, text); } map.put(name, pairs); } if (map.size() > 0) { myClass2EnumProperties.put(className, map); } }
private void upgradeGroup(final GroupItem group, final Element groupElement) { for(Object o: groupElement.getChildren(ELEMENT_ITEM)) { Element itemElement = (Element) o; if (itemElement.getAttributeValue(ATTRIBUTE_SINCE_VERSION, "").equals("2")) { processItemElement(itemElement, group, true); } final String className = LwXmlReader.getRequiredString(itemElement, ATTRIBUTE_CLASS); final ComponentItem item = getItem(className); if (item != null) { if (LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_AUTO_CREATE_BINDING, false)) { item.setAutoCreateBinding(true); } if (LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_CAN_ATTACH_LABEL, false)) { item.setCanAttachLabel(true); } } } }
/** * Reads PaletteElements from */ private void processGroups(final List groupElements){ for(final Object groupElement1 : groupElements) { final Element groupElement = (Element)groupElement1; final String groupName = LwXmlReader.getRequiredString(groupElement, ATTRIBUTE_NAME); final GroupItem group = new GroupItem(groupName); myGroups.add(group); for (final Object o : groupElement.getChildren(ELEMENT_ITEM)) { final Element itemElement = (Element)o; try { processItemElement(itemElement, group, false); } catch (Exception ex) { LOG.error(ex); } } } }
private void upgradeGroup(final GroupItem group, final Element groupElement) { for(Element itemElement : groupElement.getChildren(ELEMENT_ITEM)) { if (itemElement.getAttributeValue(ATTRIBUTE_SINCE_VERSION, "").equals("2")) { processItemElement(itemElement, group, true); } final String className = LwXmlReader.getRequiredString(itemElement, ATTRIBUTE_CLASS); final ComponentItem item = getItem(className); if (item != null) { if (LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_AUTO_CREATE_BINDING, false)) { item.setAutoCreateBinding(true); } if (LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_CAN_ATTACH_LABEL, false)) { item.setCanAttachLabel(true); } } } }
@SuppressWarnings({"HardCodedStringLiteral"}) private void loadEnumProperties(final String className, final Element enumPropertyElement) { Map<String, IntEnumEditor.Pair[]> map = new HashMap<>(); for(final Object o : enumPropertyElement.getChildren("property")) { final Element e = (Element) o; final String name = LwXmlReader.getRequiredString(e, "name"); final List list = e.getChildren("constant"); IntEnumEditor.Pair[] pairs = new IntEnumEditor.Pair[list.size()]; for(int i = 0; i < list.size(); i++) { Element constant = (Element) list.get(i); int value = LwXmlReader.getRequiredInt(constant, "value"); String message = constant.getAttributeValue("message"); String text = (message != null) ? UIDesignerBundle.message(message) : LwXmlReader.getRequiredString(constant, "name"); pairs[i] = new IntEnumEditor.Pair(value, text); } map.put(name, pairs); } if(map.size() > 0) { myClass2EnumProperties.put(className, map); } }
/** * Helper method. */ private static GridConstraints processDefaultConstraintsElement(@NotNull final Element element) { final GridConstraints constraints = new GridConstraints(); // grid related attributes constraints.setVSizePolicy(LwXmlReader.getRequiredInt(element, ATTRIBUTE_VSIZE_POLICY)); constraints.setHSizePolicy(LwXmlReader.getRequiredInt(element, ATTRIBUTE_HSIZE_POLICY)); constraints.setAnchor(LwXmlReader.getRequiredInt(element, ATTRIBUTE_ANCHOR)); constraints.setFill(LwXmlReader.getRequiredInt(element, ATTRIBUTE_FILL)); // minimum size final Element minSizeElement = element.getChild(ELEMENT_MINIMUM_SIZE); if (minSizeElement != null) { constraints.myMinimumSize.width = LwXmlReader.getRequiredInt(minSizeElement, ATTRIBUTE_WIDTH); constraints.myMinimumSize.height = LwXmlReader.getRequiredInt(minSizeElement, ATTRIBUTE_HEIGHT); } // preferred size final Element prefSizeElement = element.getChild(ELEMENT_PREFERRED_SIZE); if (prefSizeElement != null) { constraints.myPreferredSize.width = LwXmlReader.getRequiredInt(prefSizeElement, ATTRIBUTE_WIDTH); constraints.myPreferredSize.height = LwXmlReader.getRequiredInt(prefSizeElement, ATTRIBUTE_HEIGHT); } // maximum size final Element maxSizeElement = element.getChild(ELEMENT_MAXIMUM_SIZE); if (maxSizeElement != null) { constraints.myMaximumSize.width = LwXmlReader.getRequiredInt(maxSizeElement, ATTRIBUTE_WIDTH); constraints.myMaximumSize.height = LwXmlReader.getRequiredInt(maxSizeElement, ATTRIBUTE_HEIGHT); } return constraints; }
/** * Reads PaletteElements from */ private void processGroups(@NotNull List<Element> groupElements) { for (Element groupElement : groupElements) { GroupItem group = new GroupItem(LwXmlReader.getRequiredString(groupElement, ATTRIBUTE_NAME)); myGroups.add(group); for (Element itemElement : groupElement.getChildren(ELEMENT_ITEM)) { try { processItemElement(itemElement, group, false); } catch (Exception ex) { LOG.error(ex); } } } }
@Override public void loadState(Element state) { for (Element classElement : state.getChildren("class")) { final String className = LwXmlReader.getRequiredString(classElement, "name"); // Read "expert" properties final Element expertPropertiesElement = classElement.getChild("expert-properties"); if (expertPropertiesElement != null) { HashSet<String> expertProperties = new HashSet<String>(); for (Element e : expertPropertiesElement.getChildren("property")) { expertProperties.add(LwXmlReader.getRequiredString(e, "name")); } myClass2ExpertProperties.put(className, expertProperties); } // Read "inplace" property. This property is optional final Element inplacePropertyElement = classElement.getChild("inplace-property"); if (inplacePropertyElement != null) { myClass2InplaceProperty.put(className, LwXmlReader.getRequiredString(inplacePropertyElement, "name")); } final Element enumPropertyElement = classElement.getChild("enum-properties"); if (enumPropertyElement != null) { loadEnumProperties(className, enumPropertyElement); } } }
/** * Helper method. */ private static GridConstraints processDefaultConstraintsElement(@NotNull final Element element){ final GridConstraints constraints = new GridConstraints(); // grid related attributes constraints.setVSizePolicy(LwXmlReader.getRequiredInt(element, ATTRIBUTE_VSIZE_POLICY)); constraints.setHSizePolicy(LwXmlReader.getRequiredInt(element, ATTRIBUTE_HSIZE_POLICY)); constraints.setAnchor(LwXmlReader.getRequiredInt(element, ATTRIBUTE_ANCHOR)); constraints.setFill(LwXmlReader.getRequiredInt(element, ATTRIBUTE_FILL)); // minimum size final Element minSizeElement = element.getChild(ELEMENT_MINIMUM_SIZE); if (minSizeElement != null) { constraints.myMinimumSize.width = LwXmlReader.getRequiredInt(minSizeElement, ATTRIBUTE_WIDTH); constraints.myMinimumSize.height = LwXmlReader.getRequiredInt(minSizeElement, ATTRIBUTE_HEIGHT); } // preferred size final Element prefSizeElement = element.getChild(ELEMENT_PREFERRED_SIZE); if (prefSizeElement != null){ constraints.myPreferredSize.width = LwXmlReader.getRequiredInt(prefSizeElement, ATTRIBUTE_WIDTH); constraints.myPreferredSize.height = LwXmlReader.getRequiredInt(prefSizeElement, ATTRIBUTE_HEIGHT); } // maximum size final Element maxSizeElement = element.getChild(ELEMENT_MAXIMUM_SIZE); if (maxSizeElement != null) { constraints.myMaximumSize.width = LwXmlReader.getRequiredInt(maxSizeElement, ATTRIBUTE_WIDTH); constraints.myMaximumSize.height = LwXmlReader.getRequiredInt(maxSizeElement, ATTRIBUTE_HEIGHT); } return constraints; }
@SuppressWarnings({"HardCodedStringLiteral"}) public void readExternal(final Element element) { for (final Object classObject : element.getChildren("class")) { final Element classElement = (Element)classObject; final String className = LwXmlReader.getRequiredString(classElement, "name"); // Read "expert" properties final Element expertPropertiesElement = classElement.getChild("expert-properties"); if (expertPropertiesElement != null) { final HashSet<String> expertProperties = new HashSet<String>(); for (final Object o : expertPropertiesElement.getChildren("property")) { final Element e = (Element)o; final String name = LwXmlReader.getRequiredString(e, "name"); expertProperties.add(name); } myClass2ExpertProperties.put(className, expertProperties); } // Read "inplace" property. This property is optional final Element inplacePropertyElement = classElement.getChild("inplace-property"); if (inplacePropertyElement != null) { myClass2InplaceProperty.put(className, LwXmlReader.getRequiredString(inplacePropertyElement, "name")); } final Element enumPropertyElement = classElement.getChild("enum-properties"); if (enumPropertyElement != null) { loadEnumProperties(className, enumPropertyElement); } } }
@Override public void loadState(@NotNull Element element) { for(final Element classElement : element.getChildren("class")) { final String className = LwXmlReader.getRequiredString(classElement, "name"); // Read "expert" properties final Element expertPropertiesElement = classElement.getChild("expert-properties"); if(expertPropertiesElement != null) { final HashSet<String> expertProperties = new HashSet<>(); for(final Object o : expertPropertiesElement.getChildren("property")) { final Element e = (Element) o; final String name = LwXmlReader.getRequiredString(e, "name"); expertProperties.add(name); } myClass2ExpertProperties.put(className, expertProperties); } // Read "inplace" property. This property is optional final Element inplacePropertyElement = classElement.getChild("inplace-property"); if(inplacePropertyElement != null) { myClass2InplaceProperty.put(className, LwXmlReader.getRequiredString(inplacePropertyElement, "name")); } final Element enumPropertyElement = classElement.getChild("enum-properties"); if(enumPropertyElement != null) { loadEnumProperties(className, enumPropertyElement); } } }
private void processItemElement(@NotNull final Element itemElement, @NotNull final GroupItem group, final boolean skipExisting){ // Class name. It's OK if class does not exist. final String className = LwXmlReader.getRequiredString(itemElement, ATTRIBUTE_CLASS); if (skipExisting && getItem(className) != null) { return; } // Icon (optional) final String iconPath = LwXmlReader.getString(itemElement, ATTRIBUTE_ICON); // Tooltip text (optional) final String toolTipText = LwXmlReader.getString(itemElement, ATTRIBUTE_TOOLTIP_TEXT); // can be null boolean autoCreateBinding = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_AUTO_CREATE_BINDING, false); boolean canAttachLabel = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_CAN_ATTACH_LABEL, false); boolean isContainer = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_IS_CONTAINER, false); // Default constraint final GridConstraints constraints; final Element defaultConstraints = itemElement.getChild(ELEMENT_DEFAULT_CONSTRAINTS); if (defaultConstraints != null) { constraints = processDefaultConstraintsElement(defaultConstraints); } else { constraints = new GridConstraints(); } final HashMap<String, StringDescriptor> propertyName2initialValue = new HashMap<String, StringDescriptor>(); { final Element initialValues = itemElement.getChild(ELEMENT_INITIAL_VALUES); if (initialValues != null){ for(final Object o : initialValues.getChildren(ELEMENT_PROPERTY)) { final Element e = (Element)o; final String name = LwXmlReader.getRequiredString(e, ATTRIBUTE_NAME); // TODO[all] currently all initial values are strings final StringDescriptor value = StringDescriptor.create(LwXmlReader.getRequiredString(e, ATTRIBUTE_VALUE)); propertyName2initialValue.put(name, value); } } } final boolean removable = LwXmlReader.getOptionalBoolean(itemElement, ATTRIBUTE_REMOVABLE, true); final ComponentItem item = new ComponentItem( myProject, className, iconPath, toolTipText, constraints, propertyName2initialValue, removable, autoCreateBinding, canAttachLabel ); item.setIsContainer(isContainer); addItem(group, item); }