use of org.jdom.Element in project intellij-community by JetBrains.
the class Palette method processItemElement.
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)
// can be null
final String toolTipText = LwXmlReader.getString(itemElement, ATTRIBUTE_TOOLTIP_TEXT);
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<>();
{
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);
}
use of org.jdom.Element in project intellij-community by JetBrains.
the class Palette method upgradeGroup.
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);
}
}
}
}
use of org.jdom.Element in project intellij-community by JetBrains.
the class Palette method processDefaultConstraintsElement.
/**
* 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;
}
use of org.jdom.Element in project intellij-community by JetBrains.
the class IpnbEditorProvider method readState.
@NotNull
@Override
public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
final IpnbEditorState state = new IpnbEditorState(-1, 0);
final Element child = sourceElement.getChild(SELECTED_CELL);
state.setSelectedIndex(child == null ? 0 : Integer.parseInt(child.getAttributeValue(ID)));
return state;
}
use of org.jdom.Element in project intellij-community by JetBrains.
the class StudyMigrationTest method testFromThirdToForth.
@Test
public void testFromThirdToForth() throws JDOMException, IOException, StudySerializationUtils.StudyUnrecognizedFormatException {
Element element = JdomKt.loadElement(getTestDataPath().resolve("3.xml"));
assertThat(StudySerializationUtils.Xml.convertToForthVersion(element)).isEqualTo(getTestDataPath().resolve("4.xml"));
}
Aggregations