@Test public void layoutParentTest() { final LayoutPanel layout = ContextUtil.getDefaultPanel(TabbedLayoutPanel.class); Assert.assertNotNull(layout); for (int i = 1; i <= 5; i++) { final Panel content = ContextUtil.getDefaultPanel(PlaceholderPanel.class); Assert.assertNotNull(content); layout.getSubpanels().add(content); Assert.assertEquals(layout, content.getParent()); } Assert.assertEquals(5, layout.getSubpanels().size()); for (final Panel content : layout.getSubpanels().toArray(new Panel[] {})) { content.setParent(null); } Assert.assertEquals(0, layout.getSubpanels().size()); for (int i = 1; i <= 5; i++) { final Panel content = ContextUtil.getDefaultPanel(PlaceholderPanel.class); Assert.assertNotNull(content); layout.getSubpanels().add(content); Assert.assertEquals(layout, content.getParent()); } Assert.assertEquals(5, layout.getSubpanels().size()); final Panel[] array = layout.getSubpanels().toArray(new Panel[] {}); layout.getSubpanels().clear(); for (final Panel panel : array) { Assert.assertNull(panel.getParent()); } }
@Test public void myTest() { final PlaceholderPanel panel1 = ContextUtil.getDefaultPanel(PlaceholderPanel.class); Assert.assertNotNull(panel1); final PlaceholderPanel panel2 = ContextUtil.getDefaultPanel(PlaceholderPanel.class); Assert.assertNotNull(panel2); final PlaceholderPanel panel3 = ContextUtil.getDefaultPanel(PlaceholderPanel.class); Assert.assertNotNull(panel3); final TabbedLayoutPanel tabbed1 = ContextUtil.getDefaultPanel(TabbedLayoutPanel.class); Assert.assertNotNull(tabbed1); final TabbedLayoutPanel tabbed2 = ContextUtil.getDefaultPanel(TabbedLayoutPanel.class); Assert.assertNotNull(tabbed2); tabbed1.getSubpanels().add(panel1); tabbed1.getSubpanels().add(panel2); tabbed1.getSubpanels().add(panel3); Assert.assertEquals(3, tabbed1.getSubpanels().size()); panel1.setParent(null); panel2.setParent(null); Assert.assertEquals(1, tabbed1.getSubpanels().size()); tabbed1.getSubpanels().replace(panel3, panel1); Assert.assertEquals(1, tabbed1.getSubpanels().size()); panel1.setParent(tabbed2); Assert.assertEquals(1, tabbed2.getSubpanels().size()); Assert.assertEquals(0, tabbed1.getSubpanels().size()); }
@Test public void comparatorTest() { final LayoutPanel layout = ContextUtil.getDefaultPanel(TabbedLayoutPanel.class); Assert.assertNotNull(layout); for (int i = 1; i <= 5; i++) { final Panel content = ContextUtil.getDefaultPanel(MutableEntityViewPanel.class); content.setParent(layout); content.setIndex(i); Assert.assertEquals(layout, content.getParent()); } Assert.assertEquals(5, layout.getSubpanels().size()); final Panel[] array = layout.getSubpanels().toArray(new Panel[] {}); for (int i = 0; i <= 4; i++) { array[i].setIndex(4 - i); } layout.getSubpanels().sort(); int i = 4; for (final Panel panel : layout.getSubpanels()) { Assert.assertEquals(panel, array[i]); i--; } }
private void processDefaultHolder( Entity entity, AnnotationMetadata<DefaultHolder> defaultHolder) { Query query = ContextUtil.getEntityFactory().buildQuery(entity.getEntityType()); for (String filter : defaultHolder.getAnnotation().filters()) { query.addCriterion( new Path(filter), Condition.EQ, ContextUtil.getMRS() .getPropertyMetadata(entity.getEntityType(), filter) .getValue(entity)); } List<Entity> existingEntities = ContextUtil.getDRS().findByQuery(query); PropertyMetadata propertyMetadata = ContextUtil.getMRS() .getPropertyMetadata(entity.getEntityType(), defaultHolder.getField().getName()); boolean currentValue = (Boolean) propertyMetadata.getValue(entity); if (existingEntities.size() > 1 && currentValue) { for (Entity existingEntity : existingEntities) { if (!existingEntity.equals(entity) && (Boolean) propertyMetadata.getValue(existingEntity)) { propertyMetadata.setValue(existingEntity, false); sessionFactory.getCurrentSession().saveOrUpdate(existingEntity); } } } else if (existingEntities.size() == 1 && !currentValue) { propertyMetadata.setValue(entity, true); sessionFactory.getCurrentSession().saveOrUpdate(entity); } }
@Test public void creationTest() { final Panel content = ContextUtil.getDefaultPanel(PlaceholderPanel.class); Assert.assertNotNull(content); final Panel layout = ContextUtil.getDefaultPanel(TabbedLayoutPanel.class); Assert.assertNotNull(layout); }
public <E extends Entity> void save(E entity) { sessionFactory.getCurrentSession().saveOrUpdate(entity); for (AnnotationMetadata<DefaultHolder> defaultHolder : ContextUtil.getMRS().getAnnotationMetadata(entity.getEntityType(), DefaultHolder.class)) { processDefaultHolder(entity, defaultHolder); } }
@Test public void replaceTest() { final Panel content1 = ContextUtil.getDefaultPanel(PlaceholderPanel.class); final Panel content2 = ContextUtil.getDefaultPanel(PlaceholderPanel.class); final LayoutPanel layout1 = ContextUtil.getDefaultPanel(TabbedLayoutPanel.class); Assert.assertFalse(layout1.getSubpanels().replace(content1, content2)); content1.setParent(layout1); content2.setParent(layout1); Assert.assertFalse(layout1.getSubpanels().replace(content1, content2)); content2.setParent(null); Assert.assertTrue(layout1.getSubpanels().replace(content1, content2)); Assert.assertNull(content1.getParent()); Assert.assertNotNull(content2.getParent()); Assert.assertEquals(content2, layout1.getSubpanels().first()); }
@Test public void setParentTest() { final LayoutPanel layout1 = ContextUtil.getDefaultPanel(TabbedLayoutPanel.class); Assert.assertNotNull(layout1); final LayoutPanel layout2 = ContextUtil.getDefaultPanel(TabbedLayoutPanel.class); Assert.assertNotNull(layout2); final Panel content = ContextUtil.getDefaultPanel(PlaceholderPanel.class); content.setParent(layout1); Assert.assertNotNull(content.getParent()); Assert.assertEquals(layout1.getSubpanels().first(), content); content.setParent(layout2); Assert.assertNotNull(content.getParent()); Assert.assertEquals(layout2.getSubpanels().first(), content); Assert.assertEquals(0, layout1.getSubpanels().size()); content.setParent(null); Assert.assertNull(content.getParent()); Assert.assertEquals(0, layout1.getSubpanels().size()); Assert.assertEquals(0, layout2.getSubpanels().size()); }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { return ContextUtil.getSessionContext().getSecurityContext().getUserIdentity(); }