@Override public List<PropertyEditorFieldInfo> getFields() { return new ArrayList<PropertyEditorFieldInfo>(super.getFields()) { @Override public boolean remove(Object o) { if (o instanceof PropertyEditorFieldInfo) { final PropertyEditorFieldInfo info = (PropertyEditorFieldInfo) o; configContext.removeComponentProperty(info.getLabel()); } return super.remove(o); } }; } };
@Override public List<PropertyEditorFieldInfo> getFields() { return new ArrayList<PropertyEditorFieldInfo>(super.getFields()) { @Override public boolean remove(Object o) { if (o instanceof PropertyEditorFieldInfo) { final PropertyEditorFieldInfo info = (PropertyEditorFieldInfo) o; configContext.removeComponentProperty(info.getLabel()); } return super.remove(o); } }; } };
private static void sortEditorFieldInfoByPriority(List<PropertyEditorCategory> properties) { for (PropertyEditorCategory category : properties) { sort(category.getFields(), new Comparator<PropertyEditorFieldInfo>() { @Override public int compare(final PropertyEditorFieldInfo o1, final PropertyEditorFieldInfo o2) { if (o1.getPriority() < o2.getPriority()) { return -1; } else if (o1.getPriority() > o2.getPriority()) { return 1; } else { return 0; } } }); } }
private static void sortEditorFieldInfoByPriority(List<PropertyEditorCategory> properties) { for (PropertyEditorCategory category : properties) { sort(category.getFields(), new Comparator<PropertyEditorFieldInfo>() { @Override public int compare(final PropertyEditorFieldInfo o1, final PropertyEditorFieldInfo o2) { if (o1.getPriority() < o2.getPriority()) { return -1; } else if (o1.getPriority() > o2.getPriority()) { return 1; } else { return 0; } } }); } }
@Override public void onClick(ClickEvent event) { category.getFields().remove(field); categoryPanel.remove(parent); } });
public void reset() { if (layoutElement != null) { currentValues.clear(); layoutElement.getPropertyCategories() .forEach(category -> category.getFields() .forEach(field -> { String property = field.getKey(); layoutElement.removeProperty(property); field.setCurrentStringValue(""); })); this.edit(layoutElement); propertyClearAllEvent.fire(new LayoutElementClearAllPropertiesEvent(layoutElement)); } }
public void reset() { if (layoutElement != null) { currentValues.clear(); layoutElement.getPropertyCategories() .forEach(category -> category.getFields() .forEach(field -> { String property = field.getKey(); layoutElement.removeProperty(property); field.setCurrentStringValue(""); })); this.edit(layoutElement); propertyClearAllEvent.fire(new LayoutElementClearAllPropertiesEvent(layoutElement)); } }
public void edit(LayoutEditorElement element) { this.layoutElement = element; view.clear(); layoutElement.getPropertyCategories().forEach(category -> { view.addCategory(category); category.getFields().forEach(field -> { String prop = field.getKey(); String val = field.getCurrentStringValue(); if (val != null && !val.isEmpty()) { currentValues.put(prop, val); } }); }); view.show(); }
public void edit(LayoutEditorElement element) { this.layoutElement = element; view.clear(); layoutElement.getPropertyCategories().forEach(category -> { view.addCategory(category); category.getFields().forEach(field -> { String prop = field.getKey(); String val = field.getCurrentStringValue(); if (val != null && !val.isEmpty()) { currentValues.put(prop, val); } }); }); view.show(); }
@Test public void samplePlanBean_shouldGenerateCategory() throws ClassNotFoundException { BeanPropertyEditorBuilder builder = new BeanPropertyEditorBuilder(); PropertyEditorCategory category = builder.extract("org.uberfire.ext.properties.editor.server.beans.SamplePlanBean"); assertTrue(!category.getFields().isEmpty()); assertProperty(category.getFields().get(0), "text1", PropertyEditorType.TEXT); assertProperty(category.getFields().get(1), "text2", PropertyEditorType.TEXT); }
@Test public void convertMapToCategory() { HashMap<String, List<String>> categoryMap = new HashMap<String, List<String>>(); List<String> categoryFields = new ArrayList<String>(); categoryFields.add("field1"); categoryFields.add("field2"); categoryMap.put("Category1", categoryFields); PropertyEditorCategory category = PropertyUtils.convertMapToCategory(categoryMap); assertNotNull(category); assertEquals(category.getFields().size(), 2); assertEquals(category.getFields().get(0).getLabel(), "field1"); assertEquals(category.getFields().get(1).getLabel(), "field2"); } }
@Test public void convertMapToCategory() { HashMap<String, List<String>> categoryMap = new HashMap<String, List<String>>(); List<String> categoryFields = new ArrayList<String>(); categoryFields.add("field1"); categoryFields.add("field2"); categoryMap.put("Category1", categoryFields); PropertyEditorCategory category = PropertyUtils.convertMapToCategory(categoryMap); assertNotNull(category); assertEquals(category.getFields().size(), 2); assertEquals(category.getFields().get(0).getLabel(), "field1"); assertEquals(category.getFields().get(1).getLabel(), "field2"); } }
@Test public void nullValuesOnInstanceShouldGenerateEmptyStrings() throws ClassNotFoundException { BeanPropertyEditorBuilder builder = new BeanPropertyEditorBuilder(); PropertyEditorCategory category = builder.extract("org.uberfire.ext.properties.editor.server.beans.SamplePlanBean", new SamplePlanBean(null, null)); assertTrue(!category.getFields().isEmpty()); PropertyEditorFieldInfo field1 = category.getFields().get(0); PropertyEditorFieldInfo fiedl2 = category.getFields().get(1); assertProperty(field1, "text1", PropertyEditorType.TEXT, ""); assertProperty(fiedl2, "text2", PropertyEditorType.TEXT, ""); }
@Test public void samplePlanBeanAndInstance_shouldGenerateCategoryAndValues() throws ClassNotFoundException { BeanPropertyEditorBuilder builder = new BeanPropertyEditorBuilder(); PropertyEditorCategory category = builder.extract("org.uberfire.ext.properties.editor.server.beans.SamplePlanBean", new SamplePlanBean("value1", "value2")); assertTrue(!category.getFields().isEmpty()); PropertyEditorFieldInfo field1 = category.getFields().get(0); PropertyEditorFieldInfo fiedl2 = category.getFields().get(1); assertProperty(field1, "text1", PropertyEditorType.TEXT, "value1"); assertProperty(fiedl2, "text2", PropertyEditorType.TEXT, "value2"); }
@Test public void shouldNotGenerateUnhandledTypes() throws ClassNotFoundException { BeanPropertyEditorBuilder builder = new BeanPropertyEditorBuilder(); PropertyEditorCategory category = builder.extract("org.uberfire.ext.properties.editor.server.beans.UnknownTypesBean", new UnknownTypesBean()); assertTrue(category.getFields().isEmpty()); category = builder.extract("org.uberfire.ext.properties.editor.server.beans.UnknownTypesBean"); assertTrue(category.getFields().isEmpty()); }
assertTrue(!category.getFields().isEmpty()); PropertyEditorFieldInfo text = category.getFields().get(0); PropertyEditorFieldInfo bool = category.getFields().get(1); PropertyEditorFieldInfo bool2 = category.getFields().get(2); PropertyEditorFieldInfo integer = category.getFields().get(3); PropertyEditorFieldInfo inti = category.getFields().get(4); PropertyEditorFieldInfo lon = category.getFields().get(5); PropertyEditorFieldInfo plong = category.getFields().get(6); PropertyEditorFieldInfo enumSample = category.getFields().get(7); List<String> enumValues = new ArrayList<String>(); enumValues.add(SampleEnum.VALUE1.toString());
PropertyEditorCategory category = builder.extract("org.uberfire.ext.properties.editor.server.beans.ComplexPlanBean", instance); assertTrue(!category.getFields().isEmpty()); PropertyEditorFieldInfo text = category.getFields().get(0); PropertyEditorFieldInfo bool = category.getFields().get(1); PropertyEditorFieldInfo bool2 = category.getFields().get(2); PropertyEditorFieldInfo integer = category.getFields().get(3); PropertyEditorFieldInfo inti = category.getFields().get(4); PropertyEditorFieldInfo lon = category.getFields().get(5); PropertyEditorFieldInfo plong = category.getFields().get(6); PropertyEditorFieldInfo enumSample = category.getFields().get(7); List<String> enumValues = new ArrayList<String>(); enumValues.add(SampleEnum.VALUE1.toString());
@Test public void sortFieldsByPriority() { PropertyEditorFieldInfo highPriority = new PropertyEditorFieldInfo("highPriority", PropertyEditorType.BOOLEAN).withPriority(1); PropertyEditorFieldInfo lowPriority = new PropertyEditorFieldInfo("lowPriority", PropertyEditorType.BOOLEAN).withPriority(10); PropertyEditorCategory category = new PropertyEditorCategory("cat1", 2) .withField(lowPriority) .withField(highPriority); PropertyEditorEvent event = new PropertyEditorEvent("event", category); assertEquals(highPriority, event.getSortedProperties().get(0).getFields().get(0)); assertEquals(lowPriority, event.getSortedProperties().get(0).getFields().get(1)); } }
@Test public void sortFieldsByPriority() { PropertyEditorFieldInfo highPriority = new PropertyEditorFieldInfo("highPriority", PropertyEditorType.BOOLEAN).withPriority(1); PropertyEditorFieldInfo lowPriority = new PropertyEditorFieldInfo("lowPriority", PropertyEditorType.BOOLEAN).withPriority(10); PropertyEditorCategory category = new PropertyEditorCategory("cat1", 2) .withField(lowPriority) .withField(highPriority); PropertyEditorEvent event = new PropertyEditorEvent("event", category); assertEquals(highPriority, event.getSortedProperties().get(0).getFields().get(0)); assertEquals(lowPriority, event.getSortedProperties().get(0).getFields().get(1)); } }
static void createCategory(final PropertyEditorWidget propertyEditorWidget, final PanelGroup propertyMenu, final PropertyEditorCategory category, final String propertyNameFilter) { Panel panel = GWT.create(Panel.class); PanelCollapse panelCollapse = createPanelCollapse(propertyEditorWidget, category); PanelHeader headerPanel = createPanelHeader(category, propertyMenu, panelCollapse); PanelBody panelBody = createPanelBody(); Form form = createPanelContent(panelBody); boolean categoryHasActiveChilds = false; for (final PropertyEditorFieldInfo field : category.getFields()) { if (isAMatchOfFilter(propertyNameFilter, field)) { categoryHasActiveChilds = true; form.add(createItemsWidget(field, category, form)); } } if (categoryHasActiveChilds) { panelCollapse.add(panelBody); panel.add(headerPanel); panel.add(panelCollapse); propertyMenu.add(panel); } }