package com.idega.block.building.presentation; import java.rmi.RemoteException; import java.util.Collection; import java.util.Iterator; import java.util.List; import javax.ejb.FinderException; import com.idega.block.building.business.BuildingService; import com.idega.block.building.data.ApartmentType; import com.idega.business.IBOLookup; import com.idega.idegaweb.IWBundle; import com.idega.idegaweb.IWResourceBundle; import com.idega.presentation.Block; import com.idega.presentation.IWContext; import com.idega.presentation.Image; import com.idega.presentation.Table; import com.idega.presentation.text.Text; import com.idega.presentation.ui.CloseButton; import com.idega.presentation.ui.DropdownMenu; import com.idega.presentation.ui.Form; import com.idega.presentation.ui.PrintButton; import com.idega.util.Property; import com.idega.util.text.TextSoap; /** * Title: BuildingViewer Description: Views buildings in a campus Copyright: * Copyright (c) 2001 Company: idega * * @author Laddi * @version 1.0 */ public class ApartmentTypeViewer extends Block { private static final String IW_RESOURCE_BUNDLE = "com.idega.block.building"; public static final String PARAMETER_STRING = "type_id"; private int apartmenttypeid = -1; private String style = "font-family:verdana,arial,sans-serif; font-size: 11pt; font-weight: bold; color: #FFFFFF;"; private String infoStyle = "font-family:verdana,arial,sans-serif; font-size:10px; color:#000000; text-align: justify;"; protected IWResourceBundle iwrb_; protected IWBundle iwb_; private String specialAttributesName = null; private List specialAttributes = null; private String extraSpecialAttributesName = null; private List extraSpecialAttributes = null; private BuildingService service = null; public ApartmentTypeViewer() { } public ApartmentTypeViewer(int apartmenttypeid) { this.apartmenttypeid = apartmenttypeid; } public void setSpecialAttributes(String name, List attributes) { this.specialAttributesName = name; this.specialAttributes = attributes; } public void setExtraSpecialAttributes(String name, List attributes) { this.extraSpecialAttributesName = name; this.extraSpecialAttributes = attributes; } public void main(IWContext iwc) throws Exception { if (this.iwrb_ == null) { this.iwrb_ = getResourceBundle(iwc); } if (this.iwb_ == null) { this.iwb_ = getBundle(iwc); } this.service = (BuildingService) IBOLookup.getServiceInstance(iwc, BuildingService.class); if (iwc.getParameter(PARAMETER_STRING) != null) { try { this.apartmenttypeid = Integer.parseInt(iwc .getParameter(PARAMETER_STRING)); } catch (NumberFormatException e) { this.apartmenttypeid = 0; } } this.getParentPage().setTitle("Apartment Viewer"); this.getParentPage().setAllMargins(0); if (this.iwrb_ != null && this.iwb_ != null) { getApartmentType(iwc); } else { add(getBoldText("No bundle available")); } } public void setDefaultValues() { this.style = "font-family:verdana; font-size: 11pt; font-weight: bold; color: #FFFFFF;"; this.infoStyle = "font-family:arial; font-size:8pt; color:#000000; line-height: 1.8; text-align: justify;"; } private void getApartmentType(IWContext iwc) throws RemoteException, FinderException { ApartmentType room = this.service.getApartmentTypeHome().findByPrimaryKey( new Integer(this.apartmenttypeid)); Table roomTable = new Table(1, 6); roomTable.setWidth("400"); roomTable.setHeight("100%"); roomTable.setBorder(0); roomTable.setCellpadding(0); roomTable.setCellspacing(0); roomTable.setHeight(3, "100%"); roomTable.setVerticalAlignment(1, 3, "top"); Table topTable = new Table(2, 2); topTable.mergeCells(2, 1, 2, 2); topTable.setColor(1, 1, "#27324B"); topTable.setWidth(1, "100%"); topTable.addText("", 1, 2); topTable.setHeight(1, 1, "33"); topTable.setHeight(1, 2, "7"); topTable.setCellpadding(0); topTable.setCellspacing(0); Text roomName = new Text(" :: " + room.getName()); if (this.style != null) { roomName.setFontStyle(this.style); } else { roomName.setBold(); roomName.setFontSize(3); } topTable.add(roomName, 1, 1); topTable.add(this.iwrb_.getImage("/room/topright.gif", "", 153, 40), 2, 1); roomTable.add(topTable, 1, 1); roomTable.add(getApartmentTable(room, iwc), 1, 3); //roomTable.add(getBuildingApartmentTypes(room), 1, 4); roomTable.add(getSubcategoryApartmentTypes(room), 1, 4); if (!"false".equals(this.iwb_.getProperty( "apartment_type_viewer.show_bottom", "false"))) { roomTable .add(this.iwrb_.getImage("/room/bottom.gif", "", 400, 66), 1, 5); } add(roomTable); } private Table getApartmentTable(ApartmentType room, IWContext iwc) { Table roomTable = new Table(2, 2); roomTable.mergeCells(1, 1, 1, 2); roomTable.setWidth("100%"); roomTable.setHeight("100%"); roomTable.setHeight(2, 2, "100%"); roomTable.setWidth(1, "212"); roomTable.setAlignment(1, 1, "center"); roomTable.setColumnVerticalAlignment(1, "top"); roomTable.setColumnVerticalAlignment(2, "top"); roomTable.setBorder(0); try { int pid = room.getFloorPlanId(); Image floorPlan = this.iwb_.getImage("/shared/room/nopic.gif"); if (pid > 0) { floorPlan = new Image(pid); } floorPlan.setMaxImageWidth(200); floorPlan.setHorizontalSpacing(6); roomTable.add(floorPlan, 1, 1); String roomText = room.getInfo(); if (roomText == null) { roomText = ""; } roomText = TextSoap.findAndReplace(roomText, "\n", "<br>"); if (roomText.length() == 0) { roomText = this.iwrb_.getLocalizedString("no_information", "No information available"); } else { roomTable.add(getBoldText(this.iwrb_.getLocalizedString( "information", "Information")), 2, 1); roomTable.add(Text.getBreak(), 2, 1); } roomTable.add(getInfoText(roomText), 2, 1); roomTable.add(Text.getBreak(), 2, 1); roomTable.add(Text.getBreak(), 2, 1); roomTable.add(getBoldText(this.iwrb_.getLocalizedString("size", "Size (sqm)") + ": "), 2, 1); String areaString = TextSoap.singleDecimalFormat((double) room .getArea()); if (areaString.length() > 0) { areaString += " m<sup>2</sup>"; } else { areaString = "?? m<sup>2</sup>"; } roomTable.add(getInfoText(areaString), 2, 1); roomTable.add(Text.getBreak(), 2, 1); roomTable.add(getBoldText(this.iwrb_.getLocalizedString( "number_of_rooms", "Number of rooms") + ": "), 2, 1); roomTable.add(getInfoText("" + room.getRoomCount()), 2, 1); roomTable.add(Text.getBreak(), 2, 1); Table Inventory = new Table(); Inventory.setCellpadding(0); Inventory.setCellspacing(3); Inventory.setWidth("100%"); Inventory.setWidth(1, "50%"); Inventory.setWidth(2, "50%"); Image included = this.iwb_.getImage("/shared/room/x.gif", this.iwrb_ .getLocalizedString("in_apartment", "Available in apartment"), 9, 9); included.setAlignment("middle"); included.setHorizontalSpacing(4); Image notIncluded = this.iwb_.getImage("/shared/room/x1.gif", this.iwrb_ .getLocalizedString("not_in_apartment", "Not available in apartment"), 9, 9); notIncluded.setAlignment("middle"); notIncluded.setHorizontalSpacing(4); int a = 1; Inventory.add(room.getKitchen() ? included : notIncluded, 1, a); Inventory.add(getBoldText(this.iwrb_.getLocalizedString("kitchen", "Kitchen")), 1, a); Inventory.add(room.getStorage() ? included : notIncluded, 2, a); Inventory.add(getBoldText(this.iwrb_.getLocalizedString("storage", "Storage")), 2, a++); Inventory.add(room.getBathRoom() ? included : notIncluded, 1, a); Inventory.add(getBoldText(this.iwrb_.getLocalizedString("bathroom", "Bathroom")), 1, a); Inventory.add(room.getBalcony() ? included : notIncluded, 2, a); Inventory.add(getBoldText(this.iwrb_.getLocalizedString("balcony", "Balcony")), 2, a++); Inventory.add(room.getStudy() ? included : notIncluded, 1, a); Inventory.add(getBoldText(this.iwrb_ .getLocalizedString("study", "Study")), 1, a); Inventory.add(room.getLoft() ? included : notIncluded, 2, a); Inventory.add( getBoldText(this.iwrb_.getLocalizedString("loft", "Loft")), 2, a++); Inventory.add(room.getFurniture() ? included : notIncluded, 1, a); Inventory.add(getBoldText(this.iwrb_.getLocalizedString("furniture", "Furniture")), 1, a++); roomTable.add(Inventory, 2, 1); roomTable.add(Text.getBreak(), 2, 1); if (this.specialAttributes != null) { Table T = new Table(); T.setCellpadding(0); T.setCellspacing(0); int row = 1; if (this.specialAttributesName != null) { T.add(getBoldText(this.specialAttributesName), 1, row++); } Iterator iter = this.specialAttributes.iterator(); while (iter.hasNext()) { Property me = (Property) iter.next(); T.add(getBoldText(me.getKey()), 1, row); T.add(getInfoText(me.getValue()), 3, row); row++; } T.mergeCells(1, 1, 3, 1); T.setColumnAlignment(3, "right"); T.setWidth(2, "5"); roomTable.add(T, 2, 1); if (this.extraSpecialAttributes != null) { roomTable.add(Text.BREAK, 2, 1); Table T1 = new Table(); T1.setCellpadding(0); T1.setCellspacing(0); row = 1; if (this.extraSpecialAttributesName != null) { T1.add(getBoldText(this.extraSpecialAttributesName), 1, row++); } iter = this.extraSpecialAttributes.iterator(); while (iter.hasNext()) { Property me = (Property) iter.next(); T1.add(getBoldText(me.getKey()), 1, row); T1.add(getInfoText(me.getValue()), 3, row); row++; } T1.mergeCells(1, 1, 3, 1); T1.setColumnAlignment(3, "right"); T1.setWidth(2, "5"); roomTable.add(T1, 2, 1); } } Table linksTable = new Table(2, 3); linksTable.setWidth("100%"); linksTable.mergeCells(1, 1, 2, 1); linksTable.mergeCells(1, 3, 2, 3); linksTable.setCellpadding(0); linksTable.setCellspacing(0); linksTable.addText("", 1, 1); linksTable.addText("", 1, 3); linksTable.setHeight(1, "3"); linksTable.setHeight(3, "3"); linksTable.setBackgroundImage(1, 1, this.iwb_ .getImage("/shared/room/line.gif")); linksTable.setBackgroundImage(1, 3, this.iwb_ .getImage("/shared/room/line.gif")); PrintButton print = new PrintButton(this.iwrb_ .getImage("/room/print.gif")); CloseButton close = new CloseButton(this.iwrb_ .getImage("/room/close.gif")); linksTable.add(print, 2, 2); linksTable.add(close, 1, 2); roomTable.add(linksTable, 2, 2); } catch (Exception e) { e.printStackTrace(System.err); } return roomTable; } private Text getInfoText(String text) { Text T = new Text(text); T.setFontStyle(this.infoStyle); return T; } private Text getBoldText(String text) { Text T = new Text(text); T.setFontStyle(this.infoStyle + "font-weight: bold;"); return T; } private Form getSubcategoryApartmentTypes(ApartmentType thetype) throws RemoteException, FinderException { Collection types = this.service.getApartmentTypeHome().findBySubcategory( new Integer(thetype.getApartmentSubcategoryID())); Form roomForm = new Form(); Text appartmentText = getBoldText(this.iwrb_.getLocalizedString( "category_apartments", "Other apartments in category") + ": "); Table table = new Table(1, 1); table.setCellpaddingAndCellspacing(0); table.setWidth(Table.HUNDRED_PERCENT); table.setAlignment(1, 1, Table.HORIZONTAL_ALIGN_CENTER); Table formTable = new Table(1, 1); formTable.setCellpadding(0); formTable.setCellspacing(0); formTable.setWidth("90%"); formTable.setAlignment(1, 1, "right"); table.add(formTable, 1, 1); DropdownMenu roomTypes = new DropdownMenu("type_id"); roomTypes.setToSubmit(); roomTypes.keepStatusOnAction(); for (Iterator iter = types.iterator(); iter.hasNext();) { ApartmentType type = (ApartmentType) iter.next(); roomTypes.addMenuElement(type.getPrimaryKey().toString(), type .getName()); } roomTypes.setSelectedElement(String.valueOf(thetype.getPrimaryKey() .toString())); roomTypes .setMarkupAttribute("style", "font-family: Verdana; font-size: 8pt; border: 1 solid #000000"); formTable.add(appartmentText, 1, 1); formTable.add(roomTypes, 1, 1); roomForm.add(table); return roomForm; } public void setStyle(String style) { this.style = style; } public void setInfoStyle(String infoStyle) { this.infoStyle = infoStyle; } public String getBundleIdentifier() { return (IW_RESOURCE_BUNDLE); } }