@Override public Component generateBlock(final SimpleOpportunity opportunity, int blockIndex) { CssLayout beanBlock = new CssLayout(); beanBlock.addStyleName("bean-block"); beanBlock.setWidth("350px"); VerticalLayout blockContent = new VerticalLayout(); MHorizontalLayout blockTop = new MHorizontalLayout().withWidth("100%"); CssLayout iconWrap = new CssLayout(); iconWrap.setStyleName("icon-wrap"); FontIconLabel opportunityIcon = new FontIconLabel(CrmAssetsManager.getAsset(CrmTypeConstants.OPPORTUNITY)); iconWrap.addComponent(opportunityIcon); blockTop.addComponent(iconWrap); VerticalLayout opportunityInfo = new VerticalLayout(); opportunityInfo.setSpacing(true); MButton btnDelete = new MButton(FontAwesome.TRASH_O); btnDelete.addClickListener( new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { ConfirmDialogExt.show( UI.getCurrent(), AppContext.getMessage( GenericI18Enum.DIALOG_DELETE_TITLE, AppContext.getSiteName()), AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE), AppContext.getMessage(GenericI18Enum.BUTTON_YES), AppContext.getMessage(GenericI18Enum.BUTTON_NO), new ConfirmDialog.Listener() { private static final long serialVersionUID = 1L; @Override public void onClose(ConfirmDialog dialog) { if (dialog.isConfirmed()) { ContactService contactService = ApplicationContextUtil.getSpringBean(ContactService.class); ContactOpportunity associateOpportunity = new ContactOpportunity(); associateOpportunity.setContactid(contact.getId()); associateOpportunity.setOpportunityid(opportunity.getId()); contactService.removeContactOpportunityRelationship( associateOpportunity, AppContext.getAccountId()); ContactOpportunityListComp.this.refresh(); } } }); } }); btnDelete.addStyleName(UIConstants.BUTTON_ICON_ONLY); blockContent.addComponent(btnDelete); blockContent.setComponentAlignment(btnDelete, Alignment.TOP_RIGHT); Label opportunityName = new Label( String.format( "Name: <a href='%s%s'>%s</a>", SiteConfiguration.getSiteUrl(AppContext.getUser().getSubdomain()), CrmLinkGenerator.generateCrmItemLink( CrmTypeConstants.OPPORTUNITY, opportunity.getId()), opportunity.getOpportunityname()), ContentMode.HTML); opportunityInfo.addComponent(opportunityName); Label opportunityAmount = new Label("Amount: " + (opportunity.getAmount() != null ? opportunity.getAmount() : "")); if (opportunity.getCurrency() != null && opportunity.getAmount() != null) { opportunityAmount.setValue( opportunityAmount.getValue() + opportunity.getCurrency().getSymbol()); } opportunityInfo.addComponent(opportunityAmount); Label opportunitySaleStage = new Label( "Sale Stage: " + (opportunity.getSalesstage() != null ? opportunity.getSalesstage() : "")); opportunityInfo.addComponent(opportunitySaleStage); ELabel opportunityExpectedCloseDate = new ELabel( "Expected Closed Date: " + AppContext.formatPrettyTime(opportunity.getExpectedcloseddate())) .withDescription(AppContext.formatDate(opportunity.getExpectedcloseddate())); opportunityInfo.addComponent(opportunityExpectedCloseDate); blockTop.with(opportunityInfo).expand(opportunityInfo); blockContent.addComponent(blockTop); blockContent.setWidth("100%"); beanBlock.addComponent(blockContent); return beanBlock; }
/** tests house. This one has things like nillable and required properties. */ public void testHouse() throws Exception { House house = new House(); Rectangle base = new Rectangle(); base.setColor(Color.BLUE); base.setHeight(80); base.setWidth(80); base.setLineStyle(LineStyle.solid); base.setId("baseid"); house.setBase(base); Rectangle door = new Rectangle(); door.setColor(Color.YELLOW); door.setHeight(35); door.setWidth(20); door.setLineStyle(LineStyle.solid); door.setId("doorId"); house.setDoor(door); Circle knob = new Circle(); knob.setColor(Color.RED); knob.setId("knobId"); knob.setLineStyle(LineStyle.dashed); knob.setRadius(2); house.setDoorKnob(knob); Label label1 = new Label(); label1.setValue("bachelor-pad"); Label label2 = new Label(); label2.setValue("single-family-dwelling"); house.setLabels(Arrays.asList(label1, label2)); Triangle roof = new Triangle(); roof.setBase(84); roof.setHeight(20); roof.setColor(Color.YELLOW); roof.setLineStyle(LineStyle.solid); house.setRoof(roof); Rectangle window = new Rectangle(); window.setColor(Color.YELLOW); window.setHeight(10); window.setWidth(10); window.setLineStyle(LineStyle.solid); house.setWindows(Arrays.asList(window)); house.setConstructedDate(new DateTime(3L)); house.setType(XmlQNameEnumUtil.toQName(HouseType.brick)); house.setStyle(XmlQNameEnumUtil.toQName(HouseStyle.latin)); house.setColor(XmlQNameEnumUtil.toURI(HouseColor.blue)); JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); ObjectMapper houseMapper = provider.locateMapper(House.class, MediaType.APPLICATION_JSON_TYPE); ObjectMapper clientMapper = new ObjectMapper(); ByteArrayOutputStream out = new ByteArrayOutputStream(); houseMapper.writeValue(out, house); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); shapes.json.structures.House clientHouse = clientMapper.readValue(in, shapes.json.structures.House.class); shapes.json.Rectangle clientBase = clientHouse.getBase(); assertSame(shapes.json.Color.BLUE, clientBase.getColor()); assertSame(shapes.json.LineStyle.solid, clientBase.getLineStyle()); assertEquals(80, clientBase.getHeight()); assertEquals(80, clientBase.getWidth()); assertEquals("baseid", clientBase.getId()); shapes.json.Rectangle clientDoor = clientHouse.getDoor(); assertSame(shapes.json.Color.YELLOW, clientDoor.getColor()); assertSame(shapes.json.LineStyle.solid, clientDoor.getLineStyle()); assertEquals(35, clientDoor.getHeight()); assertEquals(20, clientDoor.getWidth()); assertEquals("doorId", clientDoor.getId()); shapes.json.Circle clientKnob = clientHouse.getDoorKnob(); assertSame(shapes.json.Color.RED, clientKnob.getColor()); assertSame(shapes.json.LineStyle.dashed, clientKnob.getLineStyle()); assertEquals(2, clientKnob.getRadius()); assertEquals("knobId", clientKnob.getId()); List<String> labels = Arrays.asList("bachelor-pad", "single-family-dwelling"); clientHouse.getLabels().size(); for (Object l : clientHouse.getLabels()) { shapes.json.Label label = (shapes.json.Label) l; assertTrue(labels.contains(label.getValue())); } shapes.json.Triangle clientRoof = clientHouse.getRoof(); assertSame(shapes.json.Color.YELLOW, clientRoof.getColor()); assertSame(shapes.json.LineStyle.solid, clientRoof.getLineStyle()); assertNull(clientRoof.getId()); assertEquals(84, clientRoof.getBase()); assertEquals(20, clientRoof.getHeight()); assertEquals(1, clientHouse.getWindows().size()); shapes.json.Rectangle clientWindow = (shapes.json.Rectangle) clientHouse.getWindows().get(0); assertSame(shapes.json.Color.YELLOW, clientWindow.getColor()); assertSame(shapes.json.LineStyle.solid, clientWindow.getLineStyle()); assertEquals(10, clientWindow.getHeight()); assertEquals(10, clientWindow.getWidth()); assertNull(clientWindow.getId()); assertEquals(new Date(3L), clientHouse.getConstructedDate()); out = new ByteArrayOutputStream(); clientMapper.writeValue(out, clientHouse); house = houseMapper.readValue(new ByteArrayInputStream(out.toByteArray()), House.class); base = house.getBase(); assertSame(Color.BLUE, base.getColor()); assertSame(LineStyle.solid, base.getLineStyle()); assertEquals(80, base.getHeight()); assertEquals(80, base.getWidth()); assertEquals("baseid", base.getId()); door = house.getDoor(); assertSame(Color.YELLOW, door.getColor()); assertSame(LineStyle.solid, door.getLineStyle()); assertEquals(35, door.getHeight()); assertEquals(20, door.getWidth()); assertEquals("doorId", door.getId()); knob = house.getDoorKnob(); assertSame(Color.RED, knob.getColor()); assertSame(LineStyle.dashed, knob.getLineStyle()); assertEquals(2, knob.getRadius()); assertEquals("knobId", knob.getId()); labels = Arrays.asList("bachelor-pad", "single-family-dwelling"); house.getLabels().size(); for (Object l : house.getLabels()) { Label label = (Label) l; assertTrue(labels.contains(label.getValue())); } roof = house.getRoof(); assertSame(Color.YELLOW, roof.getColor()); assertSame(LineStyle.solid, roof.getLineStyle()); assertNull(roof.getId()); assertEquals(84, roof.getBase()); assertEquals(20, roof.getHeight()); assertEquals(1, house.getWindows().size()); window = house.getWindows().get(0); assertSame(Color.YELLOW, window.getColor()); assertSame(LineStyle.solid, window.getLineStyle()); assertEquals(10, window.getHeight()); assertEquals(10, window.getWidth()); assertNull(window.getId()); assertEquals(new DateTime(3L), house.getConstructedDate()); assertEquals(XmlQNameEnumUtil.toQName(HouseType.brick), house.getType()); assertEquals(XmlQNameEnumUtil.toQName(HouseStyle.latin), house.getStyle()); assertEquals(XmlQNameEnumUtil.toURI(HouseColor.blue), house.getColor()); // now let's check the nillable and required stuff: // roof is required, but nillable. clientHouse.setRoof(null); out = new ByteArrayOutputStream(); clientMapper.writeValue(out, clientHouse); house = houseMapper.readValue(new ByteArrayInputStream(out.toByteArray()), House.class); base = house.getBase(); assertSame(Color.BLUE, base.getColor()); assertSame(LineStyle.solid, base.getLineStyle()); assertEquals(80, base.getHeight()); assertEquals(80, base.getWidth()); assertEquals("baseid", base.getId()); door = house.getDoor(); assertSame(Color.YELLOW, door.getColor()); assertSame(LineStyle.solid, door.getLineStyle()); assertEquals(35, door.getHeight()); assertEquals(20, door.getWidth()); assertEquals("doorId", door.getId()); knob = house.getDoorKnob(); assertSame(Color.RED, knob.getColor()); assertSame(LineStyle.dashed, knob.getLineStyle()); assertEquals(2, knob.getRadius()); assertEquals("knobId", knob.getId()); labels = Arrays.asList("bachelor-pad", "single-family-dwelling"); house.getLabels().size(); for (Object l : house.getLabels()) { Label label = (Label) l; assertTrue(labels.contains(label.getValue())); } roof = house.getRoof(); assertNull(roof); assertEquals(1, house.getWindows().size()); window = house.getWindows().get(0); assertSame(Color.YELLOW, window.getColor()); assertSame(LineStyle.solid, window.getLineStyle()); assertEquals(10, window.getHeight()); assertEquals(10, window.getWidth()); assertNull(window.getId()); // windows are nillable... clientHouse.setWindows(null); out = new ByteArrayOutputStream(); clientMapper.writeValue(out, clientHouse); house = houseMapper.readValue(new ByteArrayInputStream(out.toByteArray()), House.class); base = house.getBase(); assertSame(Color.BLUE, base.getColor()); assertSame(LineStyle.solid, base.getLineStyle()); assertEquals(80, base.getHeight()); assertEquals(80, base.getWidth()); assertEquals("baseid", base.getId()); door = house.getDoor(); assertSame(Color.YELLOW, door.getColor()); assertSame(LineStyle.solid, door.getLineStyle()); assertEquals(35, door.getHeight()); assertEquals(20, door.getWidth()); assertEquals("doorId", door.getId()); knob = house.getDoorKnob(); assertSame(Color.RED, knob.getColor()); assertSame(LineStyle.dashed, knob.getLineStyle()); assertEquals(2, knob.getRadius()); assertEquals("knobId", knob.getId()); labels = Arrays.asList("bachelor-pad", "single-family-dwelling"); house.getLabels().size(); for (Object l : house.getLabels()) { Label label = (Label) l; assertTrue(labels.contains(label.getValue())); } roof = house.getRoof(); assertNull(roof); assertNull(house.getWindows()); }