I've a pdf report generated with iText containing a PdfPTable added to MultiColumnText, sometimes becomes so large that it will be split on more than one page.
Currently the MultiColumnText has been divided by two columns and MultiColumnText fills the PdfPTable vertically Like:
Page-1
+--+--+
|T1|T5|
+--+--+
|T2|T6|
+--+--+
|T3|T7|
+--+--+
|T4|T8|
+--+--+
Page-2
+---+---+
|T9 |T13|
+---+---+
|T10|T14|
+---+---+
|T11|T15|
+---+---+
|T12|T16|
+---+---+
....I want to make this:
Page-1
+--+--+
|T1|T2|
+--+--+
|T3|T4|
+--+--+
|T5|T6|
+--+--+
|T7|T8|
+--+--+
Page-2
+---+---+
|T9 |T10|
+---+---+
|T11|T12|
+---+---+
|T13|T14|
+---+---+
|T15|T16|
+---+---+
The code is:
/**
* Initializes the fonts and collections.
* Creates a PDF document.
*
* #param from as a Date
* #param to as a Date
* #param weeklyComplianceMap as a Map for print weekly compliance
* #param monthlyComplianceMap as a Map for print monthly compliance
* #param calLogList as a List for calculate the add event
* #param locale Locale in case you want to create a Calendar in another language
* #throws DocumentException, IOException, ParseException
* #return ByteArrayOutputStream of PDF output
*/
public ByteArrayOutputStream createPdf(Date from, Date to, Map<String, Integer> weeklyComplianceMap,
Map<String, Double> monthlyComplianceMap, List<InjectionLogInfo> calLogList, Locale locale)
throws DocumentException, ParseException, IOException {
calendar = new GregorianCalendar();
calendar.setTime(from);
BaseFont bf_normal = BaseFont.createFont(
"C:/Windows/Fonts/arial.ttf", BaseFont.WINANSI,
BaseFont.EMBEDDED);
small = new Font(bf_normal, 8);
normal = new Font(bf_normal, 11);
BaseFont bf_bold = BaseFont.createFont(
"C:/Windows/Fonts/arialbd.ttf", BaseFont.WINANSI,
BaseFont.EMBEDDED);
smallBold = new Font(bf_bold, 10);
normalBold = new Font(bf_bold, 12);
bigBold = new Font(bf_bold, 14);
document = new Document(PageSize.A4, 20, 20, 40, 30);
baos = new ByteArrayOutputStream();
writer = PdfWriter.getInstance(document, baos);
ResourceBundle rb = ResourceBundle.getBundle("com.resources.messages", locale);
Paragraph hText = new Paragraph(rb.getString("lbl.calendar.view"), bigBold);
hText.setAlignment(Element.ALIGN_CENTER);
Chunk c1 = new Chunk(rb.getString("lbl.document.generated") + " ", normal);
Chunk c2 = new Chunk(fdf.format(new Date()), normal);
Chunk c3 = new Chunk(" " + rb.getString("lbl.at") + " ", normal);
Chunk c4 = new Chunk(tdf.format(new Date()), normal);
Chunk c5 = new Chunk(new VerticalPositionMark(), 500f, false);
Chunk c6 = new Chunk(rb.getString("lbl.page") + " ", normal);
Phrase fText = new Phrase();
fText.add(c1);fText.add(c2);fText.add(c3);
fText.add(c4);fText.add(c5);fText.add(c6);
HeaderFooter header = new HeaderFooter(hText, false);
HeaderFooter footer = new HeaderFooter(fText, true);
document.setHeader(header);
document.setFooter(footer);
document.open();
document.leftMargin();
mct = new MultiColumnText();
mct.addRegularColumns(document.left(), document.right(), 20, 2);
mct.setRunDirection(PdfWriter.RUN_DIRECTION_LTR);
for (int month = 0; month < monthsBetween(from, to, Calendar.MONTH); month++) {
// create a table with 8 columns
float[] colsWidth = {35f, 35f, 35f, 35f, 35f, 35f, 35f, 50f};
table = new PdfPTable(colsWidth);
table.setWidthPercentage(100);
// add the name of the month
table.getDefaultCell().setBackgroundColor(Color.WHITE);
table.addCell(getMonthCell(calendar, locale));
Double monAdh = monthlyComplianceMap.get(mdf.format(calendar.getTime()));
table.addCell(getMonthlyAdherence(monAdherence));
// add the name of the days
String[] days = getDayNames();
for (String day : days) {
table.addCell(getDayNamesCell(day, locale));
}
int day = 1;
int position = 2;
int dayofWeek = calendar.get(Calendar.DAY_OF_WEEK);
int daysinMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
// add empty cells
int rc = 0;
while (position != dayofWeek) {
rc++;
position = (position % 7) + 1;
table.addCell("");
}
// add cells for each day
while (day <= daysinMonth) {
calendar = new GregorianCalendar(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), day++);
table.addCell(getDayCell(calLogList, calendar, locale));
if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
rc++;
String week = (calendar.get(Calendar.WEEK_OF_YEAR)-1) + ", " + calendar.get(Calendar.YEAR);
if (null != weeklyComplianceMap) {
wa = weeklyComplianceMap.get(week);
table.addCell(getDayAdherenceCell(weekAdherence));
} else {
String weekAdherence = "0%";
table.addCell(getDayAdherenceCell(weekAdherence));
}
}
}
if (9 < rc)
table.setSpacingAfter(20);
else
table.setSpacingAfter(40);
// complete the table
table.completeRow();
// add the table to MultiColumnText object
mct.addElement(table);
// increment the day by 1
calendar.add(Calendar.DATE, 1);
}
document.add(mct);
document.newPage();
document.close();
return baos;
}
/**
* Creates a PdfPCell with the name of the month
*
* #param calendar a date
* #param locale a locale
* #return a PdfPCell with rowspan 7, containing the name of the month
*/
public PdfPCell getMonthCell(Calendar calendar, Locale locale) {
PdfPCell cell = new PdfPCell();
cell.setColspan(7);
cell.setMinimumHeight(30);
cell.setBackgroundColor(Color.GRAY);
Paragraph p = new Paragraph(String.format(locale, "%1$tB %1$tY", calendar), normalBold);
p.setAlignment(Element.ALIGN_LEFT);
cell.addElement(p);
return cell;
}
/**
* Creates a PdfPCell for a month
*
* #param string adherence of a month
* #return a PdfPCell
*/
private PdfPCell getMonthlyAdherence(String adherence) {
PdfPCell cell = new PdfPCell();
cell.setMinimumHeight(35);
//cell.setBorderColorLeft(Color.GRAY);
cell.setBackgroundColor(Color.GRAY);
Paragraph p = new Paragraph(adherence, smallBold);
p.setAlignment(Element.ALIGN_RIGHT);
cell.addElement(p);
return cell;
}
/**
* Creates a PdfPCell with the name of the day
*
* #param day name of a day
* #param locale a locale
* #return a PdfPCell, containing the name of the day
*/
public PdfPCell getDayNamesCell(String day, Locale locale) {
PdfPCell cell = new PdfPCell();
cell.setPadding(3);
cell.setBackgroundColor(Color.LIGHT_GRAY);
Paragraph p = new Paragraph(day, smallBold);
p.setAlignment(Element.ALIGN_CENTER);
cell.addElement(p);
return cell;
}
/**
* Creates a PdfPCell for a specific day
*
* #param calendar a date
* #param locale a locale
* #return a PdfPCell
*/
public PdfPCell getDayCell(List<InjectionLogInfo> calLogList, Calendar calendar, Locale locale) {
PdfPCell cell = new PdfPCell();
cell.setPadding(3);
// set the content in the language of the locale
Chunk chunk = new Chunk(String.format(locale, "%1$te", calendar), small);
// a paragraph with the day
Paragraph p = new Paragraph(chunk);
p.setAlignment(Element.ALIGN_CENTER);
cell.addElement(p);
return cell;
}
/**
* Creates a PdfPCell for a week
*
* #param string adherence of a week
* #return a PdfPCell
*/
public PdfPCell getDayAdherenceCell(String adherence) {
PdfPCell cell = new PdfPCell();
cell.setPadding(3);
// set the adherence for each week
Chunk chunk = new Chunk(adherence, small);
// a paragraph with the adherence
Paragraph p = new Paragraph(chunk);
p.setAlignment(Element.ALIGN_CENTER);
cell.addElement(p);
return cell;
}
/**
* Retrieves a Day Names for a single week
*
* #return a String array of day names
*/
public String[] getDayNames() {
DateFormatSymbols symbols = new DateFormatSymbols();
String[] dayNames = symbols.getShortWeekdays();
List<String> stringList = new ArrayList<String>();
for (String string : dayNames) {
if (string != null && string.length() > 0) {
stringList.add(string);
}
}
if (stringList.size() > 0) {
String one = stringList.get(0);
stringList.remove(0);
stringList.add(one);
stringList.add("%");
}
dayNames = stringList.toArray(new String[stringList.size()]);
return dayNames;
}
I stuck with this so any help is very appreciated.
Thanks.
I think you are using new PdfPtable(1) per MultiColumnText. change it to new PdfPtable(2) to get 2 columns table per 1 MultiColumnText.
Related
Please advise how can we generate dynamic wsu:Id in soap request xml.
<wsu:Timestamp wsu:Id="TS-C68ABF4EC1E628F5B5143638245038886955">
<wsu:Created>2015-07-08T19:07:30.388Z</wsu:Created>
<wsu:Expires>2015-07-08T19:12:30.388Z</wsu:Expires>
</wsu:Timestamp>
Java code :
private Element addTimestamp(Element wsSecurityHeaderElement)
throws SOAPException, DatatypeConfigurationException {
/if (false == this.addTimestamp) {
return null;
}/
Document document = wsSecurityHeaderElement.getOwnerDocument();
Element timestampElement = document.createElementNS(WSU_NAMESPACE,
"wsu:Timestamp");
timestampElement.setAttributeNS(WSU_NAMESPACE, "wsu:Id", "TS");
// hard coded ts needs to be removed
Attr idAttr = timestampElement.getAttributeNodeNS(WSU_NAMESPACE, "Id");
timestampElement.setIdAttributeNode(idAttr, true);
Element createdElement = document.createElementNS(WSU_NAMESPACE,
"wsu:Created");
DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
GregorianCalendar gregorianCalendar = new GregorianCalendar();
Date now = new Date();
gregorianCalendar.setTime(now);
gregorianCalendar.setTimeZone(TimeZone.getTimeZone("UTC"));
XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory
.newXMLGregorianCalendar(gregorianCalendar);
createdElement.setTextContent(xmlGregorianCalendar.toXMLFormat());
timestampElement.appendChild(createdElement);
Element expiresElement = document.createElementNS(WSU_NAMESPACE,
"wsu:Expires");
Date expiresDate = new Date(now.getTime() + 1000 * 60 * 5);
gregorianCalendar.setTime(expiresDate);
xmlGregorianCalendar = datatypeFactory
.newXMLGregorianCalendar(gregorianCalendar);
expiresElement.setTextContent(xmlGregorianCalendar.toXMLFormat());
timestampElement.appendChild(expiresElement);
wsSecurityHeaderElement.appendChild(timestampElement);
return timestampElement;
} </code>
Please find the below code.
public class MakingFieldReadOnly implements PdfPCellEvent {
/** The resulting PDF. */
public static final String RESULT1 = "text_fields.pdf";
/** The resulting PDF. */
public static final String RESULT2 = "text_filled.pdf";
/** The text field index of a TextField that needs to be added to a cell. */
protected int tf;
public static final String CONTENT = "Write any thing so that it exceeds the content limit of the textfield and scroll bar comes. asdadasdasdasdasdasdasdasdasddlfjklfjljdflkjasdfjasdfjsldfjlsdjflsjdfljdflkjsdfljsldfjlsdjflskdfjlskdfjlsdjflskdjflksdjflksdjflkjsdflkjsdfljsdfkljsdlfjlsdjkfasdadasdasdasdasdasdasdasdasddlfjklfjljdflkjasdfjasdfjsldfjlsdjflsjdfljdflkjsdfljsldfjlsdjflskdfjlskdfjlsdjflskdjflksdjflksdjflkjsdflkjsdfljsdfkljsdlfjlsdjkfasdadasdasdasdasdasdasdasdasddlfjklfjljdflkjasdfjasdfjsldfjlsdjflsjdfljdflkjsdfljsldfjlsdjflskdfjlskdfjlsdjflskdjflksdjflksdjflkjsdflkjsdfljsdfkljsdlfjljkf";
/**
* Creates a cell event that will add a text field to a cell.
* #param tf a text field index.
*/
public MakingFieldReadOnly(int tf) {
this.tf = tf;
}
/**
* Manipulates a PDF file src with the file dest as result
* #param src the original PDF
* #param dest the resulting PDF
* #throws IOException
* #throws DocumentException */
public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
AcroFields form = stamper.getAcroFields();
form.setField("text1_1", CONTENT);
form.setField("text1_2", CONTENT);
form.setField("text1_3", CONTENT);
form.setField("text1_4", CONTENT);
form.setFieldProperty("text1_1","setfflags",TextField.READ_ONLY , null);
form.setFieldProperty("text1_2","setfflags",TextField.READ_ONLY , null);
form.setFieldProperty("text1_3","setfflags",TextField.READ_ONLY , null);
form.setFieldProperty("text1_4","setfflags",TextField.READ_ONLY , null);
stamper.close();
//reader.close();
}
/**
* Creates a PDF document.
* #param filename the path to the new PDF document
* #throws DocumentException
* #throws IOException
*/
public void createPdf(String filename) throws DocumentException, IOException {
// step 1
Document document = new Document();
// step 2
PdfWriter.getInstance(document, new FileOutputStream(filename));
// step 3
document.open();
// step 4
PdfPCell cell;
PdfPTable table = new PdfPTable(2);
table.setWidths(new int[]{ 1, 2 });
table.addCell("Name:");
cell = new PdfPCell();
cell.setCellEvent(new MakingFieldReadOnly(1));
cell.setFixedHeight(60);
table.addCell(cell);
table.addCell("Loginname:");
cell = new PdfPCell();
cell.setCellEvent(new MakingFieldReadOnly(2));
cell.setFixedHeight(60);
table.addCell(cell);
table.addCell("Password:");
cell = new PdfPCell();
cell.setCellEvent(new MakingFieldReadOnly(3));
cell.setFixedHeight(60);
table.addCell(cell);
table.addCell("Reason:");
cell = new PdfPCell();
cell.setCellEvent(new MakingFieldReadOnly(4));
cell.setFixedHeight(60);
table.addCell(cell);
document.add(table);
// step 5
document.close();
}
/**
* Creates and adds a text field that will be added to a cell.
* #see com.itextpdf.text.pdf.PdfPCellEvent#cellLayout(com.itextpdf.text.pdf.PdfPCell,
* com.itextpdf.text.Rectangle, com.itextpdf.text.pdf.PdfContentByte[])
*/
public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
PdfWriter writer = canvases[0].getPdfWriter();
TextField text = new TextField(writer, rectangle, String.format("text1_%s",tf));
text.setBackgroundColor(new GrayColor(0.75f));
text.setOptions(TextField.MULTILINE | TextField.REQUIRED);
text.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
text.setFontSize(8);
try {
PdfFormField field = text.getTextField();
writer.addAnnotation(field);
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
catch(DocumentException de) {
throw new ExceptionConverter(de);
}
}
/**
* Main method
* #param args no arguments needed
* #throws IOException
* #throws DocumentException
*/
public static void main(String[] args) throws DocumentException, IOException {
MakingFieldReadOnly example = new MakingFieldReadOnly(0);
example.createPdf(RESULT1);
example.manipulatePdf(RESULT1, RESULT2);
}
}
Please run the above code and generate the document. I have used itext-1.3.jar but same behavior shown with itext-5.3.5.jar.
In the second file named as "text_filled.pdf", I have four pdf cells(fields) in the table. My code is making these editable fields read only but I want scroll bar also(when content exceeds the field limit) as like it is coming for 4th one only, so that user can be able to view whole content without having edit permission.
Could I get read only mode with scroll bar(if content is more than limit of the text field) for each cell of the the table.
I have tried the below code also for making the fields read only.
form.setFieldProperty("text1_1","setfflags",PdfFormField.FF_READ_ONLY , null);
form.setFieldProperty("text1_2","setfflags",PdfFormField.FF_READ_ONLY , null);
form.setFieldProperty("text1_3","setfflags",PdfFormField.FF_READ_ONLY, null);
form.setFieldProperty("text1_4","setfflags",PdfFormField.FF_READ_ONLY , null);
If from these codes can't be done then any other possible solution.
I have tried your example, and I have discovered that the behavior you experience is caused by a bug in Adobe Acrobat / Reader. The bug occurs when the borders of the widget annotations of different text fields overlap.
Once I made sure that there was no overlap between the different fields, the scroll bars appeared.
How did I make sure that there was no overlap? Simply by changing the way the TextField instance created in your cellLayout() method:
Rectangle rect = new Rectangle(
rectangle.getLeft(), rectangle.getTop() - 1,
rectangle.getRight(), rectangle.getBottom() + 1);
TextField text = new TextField(writer, rect, String.format("text1_%s",tf));
Now the rectangles that define the text field no longer overlap, and you no longer experience the Adobe Acrobat / Reader bug.
finally I got a custom DataGrid running. It is the same like that from the showcase of gwt. So I got some subitems and some mainitems. But now I want to detect ClickEvents. After a while I found out, that I need a SelectionHandler. But after implementing it, it only select the mainitems.
Is there a way to catch the selection of the subitems?
I also set one as selected via selectionHandler.setSelected(subitem, true); and it worked great, but how do I get the selection on my subitems from the userinput/ClickEvent?
The basic code is just:
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
#Override
public void onSelectionChange(final SelectionChangeEvent event) {
File selected = ((SingleSelectionModel) selectionModel).getSelectedObject();
if(selected != null){
Window.alert(selected.getFileName());
}
}
}
});
/**
* Renders the data rows that display each contact in the table.
*/
private class CustomTableBuilder extends AbstractCellTableBuilder<File> {
private final String childCell = " " + FileTreeViewImpl.this.resources.styles().childCell();
private final String rowStyle;
private final String selectedRowStyle;
private final String cellStyle;
private final String selectedCellStyle;
public CustomTableBuilder() {
super(FileTreeViewImpl.this.fileDataGrid);
DefaultSelectionEventManager.createCustomManager(new DefaultSelectionEventManager
.WhitelistEventTranslator<File>(0));
// Cache styles for faster access.
com.google.gwt.user.cellview.client.AbstractCellTable.Style style = FileTreeViewImpl.this.fileDataGrid.getResources().style();
this.rowStyle = style.evenRow();
this.selectedRowStyle = " " + style.selectedRow();
this.cellStyle = style.cell() + " " + style.evenRowCell();
this.selectedCellStyle = " " + style.selectedRowCell();
}
#Override
protected void buildRowImpl(final File rowValue, final int absRowIndex) {
buildContactRow(rowValue, absRowIndex, false);
// Display list of files.
if (FileTreeViewImpl.this.displayFolderContent.contains(rowValue.getFileName())) {
Set<File> files = FileTreeViewImpl.this.folderMap.get(rowValue.getFileName());
for (File file : files) {
buildContactRow(file, absRowIndex, true);
}
}
}
/**
* Build a row.
*
* #param rowValue
* the file info
* #param absRowIndex
* the absolute row index
* #param isFriend
* true if this is a subrow, false if a top level row
*/
private void buildContactRow(final File rowValue, final int absRowIndex, final boolean isFriend) {
// Calculate the row styles.
SelectionModel<? super File> selectionModel = FileTreeViewImpl.this.fileDataGrid.getSelectionModel();
boolean isSelected = (selectionModel == null || rowValue == null) ? false : selectionModel.isSelected(rowValue);
StringBuilder trClasses = new StringBuilder(this.rowStyle);
if (isSelected) {
trClasses.append(this.selectedRowStyle);
}
// Calculate the cell styles.
String cellStyles = this.cellStyle;
if (isSelected) {
cellStyles += this.selectedCellStyle;
}
if (isFriend) {
cellStyles += this.childCell;
}
TableRowBuilder row = startRow();
row.className(trClasses.toString());
// Column one to expand the submenu.
TableCellBuilder td = row.startTD();
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
if (!isFriend) {
renderCell(td, createContext(0), FileTreeViewImpl.this.viewFolderContent, rowValue);
}
td.endTD();
// Filename goes here.
td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
if (isFriend) {
td.text(rowValue.getFileName());
} else {
renderCell(td, createContext(1), FileTreeViewImpl.this.nameColumn, rowValue);
}
td.endTD();
// Filesize goes here.
td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
if (isFriend) {
td.text(rowValue.getFileSizeAsString());
} else {
renderCell(td, createContext(2), FileTreeViewImpl.this.sizeColumn, rowValue);
}
td.endTD();
// Last Editor goes here.
td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
if (isFriend) {
td.text(rowValue.getLastEditedBy());
} else {
renderCell(td, createContext(3), FileTreeViewImpl.this.editedColumn, rowValue);
}
td.endTD();
row.endTR();
}
}</code>
Greetings
Can anyone give me any recommendations as to how i should approach this properly?
Heres the problem, grab a beer first. My attempt to explain might require a cold one :)
I have a ListView that is being populated via JSON that its being downloaded from a server.
This listview has a pickup_time (String), I am calculating the difference in time between current time and pickup_time
What I am trying to do is load either a green, yellow or red circle image to the assigned pickup_time according to the difference in time I have calculated by using a textView and using textView.setBackgroundColor. in the ListView.
The ListView WAS working properly and displaying information correctly. I've recently only tried to add the green/yellow/red images to the corresponding pickup_time string and this is where its crashing and I need help.
Now for some Codes!
Heres is where I am populating the listView using an AsyncTask. If you notice, I have parse_ready_at(JobsArray, i1); This is where I am caluclating the time difference.
public class Jobs extends ListActivity {
String NEW_JOB = " ";
Vibrator vib;
boolean reloadOnResume;
TextView assigned;
static ProjectDebug LOGCAT = new ProjectDebug();
ProgressDialogManager pDialog = new ProgressDialogManager();
static String JOB, ON_TIME_PERFORMANCE;
// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList;
int PU_time_until_late;
int DEL_time_until_late;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.jobs);
getWindow().setLayout (LayoutParams.FILL_PARENT /* width */ , LayoutParams.WRAP_CONTENT /* height */);
vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
assigned = (TextView) findViewById(R.id.assigned);
RELOAD = true;
Jobs.this.setTitle("My Jobs");
reloadOnResume = false;
VerifyDriverCredentials();
// selecting single ListView item
final ListView lv = getListView();
// Launching new screen on Selecting Single ListItem
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long ide) {
vib.vibrate(40);
// Starting new intent
try { Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra("jobInfo", JOBS.getJSONObject(position).toString());
in.putExtra(pays, JOBS.getJSONObject(position).toString());
in.putExtra(customer_name, JOBS.getJSONObject(position).toString());
in.putExtra(job, JOBS.getJSONObject(position).toString());
in.putExtra(ready_at, JOBS.getJSONObject(position).toString());
in.putExtra(due_by, JOBS.getJSONObject(position).toString());
in.putExtra(customer_reference, JOBS.getJSONObject(position).toString());
in.putExtra(pieces, JOBS.getJSONObject(position).toString());
in.putExtra(weight, JOBS.getJSONObject(position).toString());
in.putExtra(signature_required, JOBS.getJSONObject(position).toString());
in.putExtra(acknowledged, JOBS.getJSONObject(position).toString());
in.putExtra(pickup_actual_datetime, JOBS.getJSONObject(position).toString());
// Pickup Info
in.putExtra(pickup_name, JOBS.getJSONObject(position).toString());
in.putExtra(pickup_addr1, JOBS.getJSONObject(position).toString());
in.putExtra(pickup_city, JOBS.getJSONObject(position).toString());
in.putExtra(pickup_state, JOBS.getJSONObject(position).toString());
in.putExtra(pickup_to_see, JOBS.getJSONObject(position).toString());
in.putExtra(pickup_room, JOBS.getJSONObject(position).toString());
in.putExtra(pickup_phone, JOBS.getJSONObject(position).toString());
in.putExtra(pickup_zip_postal, JOBS.getJSONObject(position).toString());
in.putExtra(pickup_special_instr, JOBS.getJSONObject(position).toString());
// Deliver Info
in.putExtra(deliver_name, JOBS.getJSONObject(position).toString());
in.putExtra(deliver_addr1, JOBS.getJSONObject(position).toString());
in.putExtra(deliver_city, JOBS.getJSONObject(position).toString());
in.putExtra(deliver_state, JOBS.getJSONObject(position).toString());
in.putExtra(deliver_zip_postal, JOBS.getJSONObject(position).toString());
in.putExtra(deliver_to_see, JOBS.getJSONObject(position).toString());
in.putExtra(deliver_room, JOBS.getJSONObject(position).toString());
in.putExtra(deliver_special_instr, JOBS.getJSONObject(position).toString());
in.putExtra(deliver_phone, JOBS.getJSONObject(position).toString());
startActivity(in);
Jobs.this.overridePendingTransition(R.anim.fadein, R.anim.fadeout);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private void VerifyDriverCredentials() {
if (jobs_assigned == 0){
assigned.setVisibility(View.VISIBLE);
assigned.setText("You have no jobs assigned");
GetWindowParameters();
}
if (jobs_assigned > 0 && reloadOnResume == false) {
assigned.setVisibility(View.GONE);
new ParseJobs().execute();
}
}
public class ParseJobs extends AsyncTask<Void, Void, Void> {
String DEL_late = "del_late";
String PU_late = " pu_late";
int i1 = 0;
#Override
protected void onPreExecute() {
pDialog.showProgressDialog(Jobs.this, "Performing calculations", "Loading... Please Wait...");
}
#Override
protected Void doInBackground(Void... params) {
contactList = new ArrayList<HashMap<String, String>>();
// looping through All Contacts
try { for (i1 = 0; i1 < JOBS.length(); i1++) {
JobsArray = JOBS.getJSONObject(i1);
JOB = JobsArray.getString(job);
ON_TIME_PERFORMANCE = JobsArray.getString(on_time_performance);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(job, JobsArray.getString(job));
map.put(pays, JobsArray.getString(pays));
map.put(ready_at, JobsArray.getString(ready_at));
map.put(due_by, JobsArray.getString(due_by));
map.put(new_job, JobsArray.getString(new_job));
//map.put(PU_late, Integer.toString(PU_time_until_late));
//map.put(DEL_late, Integer.toString(DEL_time_until_late));
// adding HashList to ArrayList
contactList.add(map);
}
} catch (JSONException e) {
}
parse_ready_at(JobsArray, i1);
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
if (JOB != null) { assigned.setText(""); }
else { assigned.setText("You have no jobs assigned"); }
GetWindowParameters();
/** Updating parsed JSON data into ListView */
ListAdapter adapter = new SimpleAdapter(Jobs.this, contactList, R.layout.list_item, new String[] { job, pays, ready_at, due_by, new_job, PU_late, DEL_late},
new int[] { R.id.job1, R.id.pays1, R.id.ready_at1, R.id.due_by1, R.id.newjob1, R.id.imageViewReadyAt, R.id.imageViewDueBy });
TextView imageViewReadyAt = (TextView) findViewById(R.id.imageViewReadyAt);
//Change color/answer/etc for textView_5
if ( PU_time_until_late > 60) { // if more than 60 minutes
imageViewReadyAt.setBackgroundResource(R.drawable.notification);
}
if ( PU_time_until_late < 60) { //if less than 60
imageViewReadyAt.setBackgroundResource(R.drawable.green_light);
}
if ( PU_time_until_late < 30) { // if less than 30
imageViewReadyAt.setBackgroundResource(R.drawable.yellow_light);
}
if ( PU_time_until_late < 1) { // if less than 1 minutes
imageViewReadyAt.setBackgroundResource(R.drawable.red_light);
}
setListAdapter(adapter);
pDialog.dismissProgressDialog(Jobs.this);
}
}
public void parse_ready_at(JSONObject JobsArray, int i1) {
String parse_ready_at_ARRAY;
String tracking_Number;
try { for (i1 = 0; i1 < JOBS.length(); i1++) {
JobsArray = JOBS.getJSONObject(i1);
parse_ready_at_ARRAY = JobsArray.getString(ready_at);
tracking_Number = JobsArray.getString(job);
//Example of ready_at String --> "ready_at": "07/25/2012 08:26:00 PM" we split time from date to get time only
SimpleDateFormat parserSDF = new SimpleDateFormat("M/d/yyyy hh:mm:ss a"); // <--- Correct format to read "lastLatitudeUpdate"
try { parserSDF.parse(parse_ready_at_ARRAY);
}
catch (ParseException e) { LOGCAT.DEBUG("JOBS parse_ready_at", "Error parsing tracking number = " + tracking_Number + " ready_at Array = " + parse_ready_at_ARRAY + " Error = " + e.toString()); }
/* ################################################
* #### DISSECTING READY_AT STRING ARRAY ###
* ################################################
*/
String[] dissect_ready_at_DATE_TIME = parse_ready_at_ARRAY.split(" "); // Splitting space between 07/25/2012 and 08:26:00 and PM
String get_ready_at_DATE = String.valueOf(dissect_ready_at_DATE_TIME[0]); // Set at 0 because we want date. 07-25-2012
String get_ready_at_TIME = String.valueOf(dissect_ready_at_DATE_TIME[1]); // Set at 1 because we want time. 08:26:00
String get_ready_at_AMPM = String.valueOf(dissect_ready_at_DATE_TIME[2]); // Set at 2 because we want AM PM.
/* ########################################################
* #### GETTING DATE FROM READY_AT STRING ARRAY ###
* ########################################################
*/
String[] dissect_ready_at_DATE = get_ready_at_DATE.split("/"); // Splitting the / between 07 and 25 and 2012 from 07/25/2012
int get_ready_at_MONTH = Integer.valueOf(dissect_ready_at_DATE[0]); // Set at 0 because we want month. 07
int get_ready_at_DAY = Integer.valueOf(dissect_ready_at_DATE[1]); // Set at 1 because we want day. 25
int get_ready_at_YEAR = Integer.valueOf(dissect_ready_at_DATE[2]); // Set at 2 because we want yeay. 2012
/* ########################################################
* #### GETTING TIME FROM READY_AT STRING ARRAY ###
* ########################################################
*/
String[] dissect_ready_at_TIME = get_ready_at_TIME.split(":"); // Splitting the : between 08 and 26 and 00
int get_ready_at_HOUR = Integer.valueOf(dissect_ready_at_TIME[0]); // Set at 0 because we want hour. 08
int get_ready_at_MINUTE = Integer.valueOf(dissect_ready_at_TIME[1]); // Set at 1 because we want minute. 26
/* ################################################################
* #### CONVERT HOUR FROM READY_AT STRING TO MILITARY TIME ###
* ################################################################
*/
int convert_ready_at_HOUR_to_military = 0; // By default, ready_at String is in 12 hour format. we need to fix it so it is military time.
if (get_ready_at_AMPM.contentEquals("PM")) { // Checking to see if ready_at String has a PM at the end
convert_ready_at_HOUR_to_military = get_ready_at_HOUR + 12; // If it does, add 12 so we can get military time
}
if (get_ready_at_HOUR == 12 & get_ready_at_AMPM.contentEquals("PM") ) {// If hour is set at 12 PM, leave it at 12
convert_ready_at_HOUR_to_military = 12;
}
if (get_ready_at_AMPM.matches("AM")) { // Do Nothing if its AM
convert_ready_at_HOUR_to_military = get_ready_at_HOUR + 0;
}
/* ############################################################
* #### GET THE CURRENT DATE/TIME FROM USERS DEVICE ###
* ############################################################
*/
int current_MONTH = Calendar.getInstance().get(Calendar.MONTH); // Get todays month
int current_DAY = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); // Get todays date
int current_YEAR = Calendar.getInstance().get(Calendar.YEAR); // Get todays year
int current_HOUR = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); // Get todays Hour in military format
int current_MINUTE = Calendar.getInstance().get(Calendar.MINUTE); // Get todays minute
int current_year_FIXUP = current_YEAR - 1900; // example, this year is 2013, subtract 1900 you get 113 which is what Date parameter is requesting
int get_ready_at_year_FIXUP = get_ready_at_YEAR - 1900;
int get_ready_at_MONTH_FIXUP = // * We dont need to fixup current_MONTH because java has already done so
get_ready_at_MONTH - 1; // <-- we subtract 1 because according to parameters, January starts at 0 and December is 11
/*
* How to use Date(int, int, int)
*
*
* *Parameters*
* - year the year, 0 is 1900.
* - month the month, 0 - 11.
* - day the day of the month, 1 - 31
*/
Date ready_at_time = new Date(get_ready_at_year_FIXUP, get_ready_at_MONTH_FIXUP, get_ready_at_DAY); // (2010, June, 20th) = (110, 5, 20) June is 5 instead of 6 because we start
Date current_time = new Date(current_year_FIXUP, current_MONTH, current_DAY); // January at 0 in Java. As for days, it starts at 1 like normal.
int days_between = Days.daysBetween(new DateTime(current_time), new DateTime(ready_at_time)).getDays(); // Get the difference in days of current date and ready_at date
int minutes_difference_in_days_between = days_between * 1440; // 1440 minutes = 1 day. multiply with the date difference of int days_between to get the minutes between those days.
/* ############################################################################
* #### FINAL OUTPUT OF CALCULATING TIMES FROM CURRENT AND READY_AT ###
* ############################################################################
*/
int current_TOTAL_MINUTES = current_HOUR * 60 + current_MINUTE; // Multiply hour by 60 to get the minutes in the hour = RIGHT NOW'S time in minute format
int ready_at_TOTAL_MINUTES = convert_ready_at_HOUR_to_military * 60 + get_ready_at_MINUTE + minutes_difference_in_days_between;
PU_time_until_late = ready_at_TOTAL_MINUTES - current_TOTAL_MINUTES;
LOGCAT.DEBUG("READY_AT " + tracking_Number,"'" + days_between + "'" + " days between today and when the package is scheduled for pickup");
LOGCAT.DEBUG("READY_AT " + tracking_Number, "ready_at String's time = " + parse_ready_at_ARRAY +
" Time now in Minutes = " + current_TOTAL_MINUTES +
" ready_at time in Minutes = " + ready_at_TOTAL_MINUTES +
" Minutes left to complete pickup = " + PU_time_until_late + "\n" + "\n" + "\n" + " ");
}
}
catch (Exception e) {
LOGCAT.DEBUG("Jobs", "Error Splitting/Converting ready_at Time");
}
}
public void GetWindowParameters() {
WindowManager.LayoutParams params = getWindow().getAttributes();
Jobs.this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Jobs.this.getWindow().setBackgroundDrawableResource(R.drawable.listviewbackground);
/* params.x = 0;
params.height = 480;
params.width = 480;
params.y = 160; */
params.y = 160;
params.height = 600;
params.dimAmount = .70f;
Jobs.this.getWindow().setAttributes(params);
}
Heres the code to get the time difference **public void parse_ready_at()***WARNING* Im pretty sure there is a MUCH easier way to do this but, I'm new and dont know any better lol
public void parse_ready_at(JSONObject JobsArray, int i1) {
String parse_ready_at_ARRAY;
String tracking_Number;
try { for (i1 = 0; i1 < JOBS.length(); i1++) {
JobsArray = JOBS.getJSONObject(i1);
parse_ready_at_ARRAY = JobsArray.getString(ready_at);
tracking_Number = JobsArray.getString(job);
//Example of ready_at String --> "ready_at": "07/25/2012 08:26:00 PM" we split time from date to get time only
SimpleDateFormat parserSDF = new SimpleDateFormat("M/d/yyyy hh:mm:ss a"); // <--- Correct format to read "lastLatitudeUpdate"
try { parserSDF.parse(parse_ready_at_ARRAY);
}
catch (ParseException e) { LOGCAT.DEBUG("JOBS parse_ready_at", "Error parsing tracking number = " + tracking_Number + " ready_at Array = " + parse_ready_at_ARRAY + " Error = " + e.toString()); }
/* ################################################
* #### DISSECTING READY_AT STRING ARRAY ###
* ################################################
*/
String[] dissect_ready_at_DATE_TIME = parse_ready_at_ARRAY.split(" "); // Splitting space between 07/25/2012 and 08:26:00 and PM
String get_ready_at_DATE = String.valueOf(dissect_ready_at_DATE_TIME[0]); // Set at 0 because we want date. 07-25-2012
String get_ready_at_TIME = String.valueOf(dissect_ready_at_DATE_TIME[1]); // Set at 1 because we want time. 08:26:00
String get_ready_at_AMPM = String.valueOf(dissect_ready_at_DATE_TIME[2]); // Set at 2 because we want AM PM.
/* ########################################################
* #### GETTING DATE FROM READY_AT STRING ARRAY ###
* ########################################################
*/
String[] dissect_ready_at_DATE = get_ready_at_DATE.split("/"); // Splitting the / between 07 and 25 and 2012 from 07/25/2012
int get_ready_at_MONTH = Integer.valueOf(dissect_ready_at_DATE[0]); // Set at 0 because we want month. 07
int get_ready_at_DAY = Integer.valueOf(dissect_ready_at_DATE[1]); // Set at 1 because we want day. 25
int get_ready_at_YEAR = Integer.valueOf(dissect_ready_at_DATE[2]); // Set at 2 because we want yeay. 2012
/* ########################################################
* #### GETTING TIME FROM READY_AT STRING ARRAY ###
* ########################################################
*/
String[] dissect_ready_at_TIME = get_ready_at_TIME.split(":"); // Splitting the : between 08 and 26 and 00
int get_ready_at_HOUR = Integer.valueOf(dissect_ready_at_TIME[0]); // Set at 0 because we want hour. 08
int get_ready_at_MINUTE = Integer.valueOf(dissect_ready_at_TIME[1]); // Set at 1 because we want minute. 26
/* ################################################################
* #### CONVERT HOUR FROM READY_AT STRING TO MILITARY TIME ###
* ################################################################
*/
int convert_ready_at_HOUR_to_military = 0; // By default, ready_at String is in 12 hour format. we need to fix it so it is military time.
if (get_ready_at_AMPM.contentEquals("PM")) { // Checking to see if ready_at String has a PM at the end
convert_ready_at_HOUR_to_military = get_ready_at_HOUR + 12; // If it does, add 12 so we can get military time
}
if (get_ready_at_HOUR == 12 & get_ready_at_AMPM.contentEquals("PM") ) {// If hour is set at 12 PM, leave it at 12
convert_ready_at_HOUR_to_military = 12;
}
if (get_ready_at_AMPM.matches("AM")) { // Do Nothing if its AM
convert_ready_at_HOUR_to_military = get_ready_at_HOUR + 0;
}
/* ############################################################
* #### GET THE CURRENT DATE/TIME FROM USERS DEVICE ###
* ############################################################
*/
int current_MONTH = Calendar.getInstance().get(Calendar.MONTH); // Get todays month
int current_DAY = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); // Get todays date
int current_YEAR = Calendar.getInstance().get(Calendar.YEAR); // Get todays year
int current_HOUR = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); // Get todays Hour in military format
int current_MINUTE = Calendar.getInstance().get(Calendar.MINUTE); // Get todays minute
int current_year_FIXUP = current_YEAR - 1900; // example, this year is 2013, subtract 1900 you get 113 which is what Date parameter is requesting
int get_ready_at_year_FIXUP = get_ready_at_YEAR - 1900;
int get_ready_at_MONTH_FIXUP = // * We dont need to fixup current_MONTH because java has already done so
get_ready_at_MONTH - 1; // <-- we subtract 1 because according to parameters, January starts at 0 and December is 11
/*
* How to use Date(int, int, int)
*
*
* *Parameters*
* - year the year, 0 is 1900.
* - month the month, 0 - 11.
* - day the day of the month, 1 - 31
*/
Date ready_at_time = new Date(get_ready_at_year_FIXUP, get_ready_at_MONTH_FIXUP, get_ready_at_DAY); // (2010, June, 20th) = (110, 5, 20) June is 5 instead of 6 because we start
Date current_time = new Date(current_year_FIXUP, current_MONTH, current_DAY); // January at 0 in Java. As for days, it starts at 1 like normal.
int days_between = Days.daysBetween(new DateTime(current_time), new DateTime(ready_at_time)).getDays(); // Get the difference in days of current date and ready_at date
int minutes_difference_in_days_between = days_between * 1440; // 1440 minutes = 1 day. multiply with the date difference of int days_between to get the minutes between those days.
/* ############################################################################
* #### FINAL OUTPUT OF CALCULATING TIMES FROM CURRENT AND READY_AT ###
* ############################################################################
*/
int current_TOTAL_MINUTES = current_HOUR * 60 + current_MINUTE; // Multiply hour by 60 to get the minutes in the hour = RIGHT NOW'S time in minute format
int ready_at_TOTAL_MINUTES = convert_ready_at_HOUR_to_military * 60 + get_ready_at_MINUTE + minutes_difference_in_days_between;
PU_time_until_late = ready_at_TOTAL_MINUTES - current_TOTAL_MINUTES;
LOGCAT.DEBUG("READY_AT " + tracking_Number,"'" + days_between + "'" + " days between today and when the package is scheduled for pickup");
LOGCAT.DEBUG("READY_AT " + tracking_Number, "ready_at String's time = " + parse_ready_at_ARRAY +
" Time now in Minutes = " + current_TOTAL_MINUTES +
" ready_at time in Minutes = " + ready_at_TOTAL_MINUTES +
" Minutes left to complete pickup = " + PU_time_until_late + "\n" + "\n" + "\n" + " ");
}
}
catch (Exception e) {
LOGCAT.DEBUG("Jobs", "Error Splitting/Converting ready_at Time");
}
}
Basically I want those lights to resemble on-time, late etc... not looking to be fed with a golden spoon, just some guidance towards the right direction thats all. Thanks!
EDIT here is my stack trace I forgot to include. I am getting a null pointer exception in onPostExecute. I have declared the textView and already defined it in my onCreate. I believe I have already called it properly in my ListAdapter as well.
if ( PU_ time_until_late < 60) { imageViewReadyAt.setBackgroundColor (R.drawable.green_light); }
EDIT Okay, I figured out why I was getting a null exception when calling imageViewReadyAt Textview. That textview belongs to another XML that belongs in the custom list_item. Still could use some help though.
I'm not sure if it's a bug or what, but I've also had issues modifying the UI from onPostExecute(). To work around it I'll either call a method from there to the main activity and have that work with views, or use a handler and post a message to the proper activity that is using the UI thread.
To make sure I'm on the UI thread I usually use a handler message instead like so:
Handler handlerJobs = new jobsHandler();
public class jobsHandler extends Handler {
#Override
public void handleMessage(Message msg) {
switch(msg.arg1) {
case 1:
updateBackgroundColor(msg.arg2);
break;
default:
super.handleMessage(msg);
}
}
}
private void updateBackgroundColor(int dataPassedInMessage) {
if (JOB != null) {
assigned.setText("");
} else {
assigned.setText("You have no jobs assigned");
}
GetWindowParameters();
/** Updating parsed JSON data into ListView */
ListAdapter adapter = new SimpleAdapter(Jobs.this, contactList, R.layout.list_item, new String[] { job, pays, ready_at, due_by, new_job, PU_late, DEL_late},
new int[] { R.id.job1, R.id.pays1, R.id.ready_at1, R.id.due_by1, R.id.newjob1, R.id.imageViewReadyAt, R.id.imageViewDueBy });
TextView imageViewReadyAt = (TextView) findViewById(R.id.imageViewReadyAt);
//Change color/answer/etc for textView_5
if ( PU_time_until_late > 60) {
// if more than 60 minutes
imageViewReadyAt.setBackgroundResource(R.drawable.notification);
}
if ( PU_time_until_late < 60) {
//if less than 60
imageViewReadyAt.setBackgroundResource(R.drawable.green_light);
}
if ( PU_time_until_late < 30) {
// if less than 30
imageViewReadyAt.setBackgroundResource(R.drawable.yellow_light);
}
if ( PU_time_until_late < 1) {
// if less than 1 minutes
imageViewReadyAt.setBackgroundResource(R.drawable.red_light);
}
setListAdapter(adapter);
pDialog.dismissProgressDialog(Jobs.this);
}
}
And then to call it you would use:
#Override
protected void onPostExecute(Void result) {
Message updateBackground = new Message();
updateBackground.arg1 = 1;
updateBackground.arg2 = R.drawable.green_light; //or any int you need to pass
handlerJobs.sendMessage(updateBackground);
}
edit: updated the example so it should work with your code
I think the problem is you are setting background color instead of setting background image. Your image setting code should be as follows e.g. :
imageViewReadyAt.setBackgroundDrawable(R.drawable.green_light);
I am trying to build a CellTable Widget for time tracking. The first Column must represent all days for current month in following form
Fri, 1
Sat, 2
Sun, 3
Mon, 4
Tue, 5
…
etc. till the end of the month (28 -31 rows).
My code looks like that:
Column<Rec,String> dayColumn = new Column<Rec,String>(new TextCell())
{
#Override
public String getValue(Rec rec)
{
dayNr = DateTimeFormat.getFormat( "EE,d" ).format(new Date());
return dayNr;
}
};
table.addColumn(dayColumn, "Date");
So can I see in this Column only Today-date in all cells.
How can I get all days of the month (1...28/30/31) in this Column each in its own cell?
It would be ideal if you prepared the list of Rec items with a Date variable.
Declaring a Rec pojo with date
Class Rec{
Date date;
//getter and setters.
}
Populate list of Rec items
List<Rec> recItems = new ArrayList<Rec>();
Date now = new Date();
int nowMonth = now.getMonth();
int nowYear = now.getYear();
List<Date> listOfDatesInThisMonth = new ArrayList<Date>();
Date beginningOfMonth = new Date(nowYear,nowMonth,1);
Date beginningOfNextMonth = new Date(nowYear,nowMonth+1,1);
Date start = beginningOfMonth;
while(start.before(beginningOfNextMonth)){
listOfDatesInThisMonth.add(start);
start = new Date(nowYear,nowMonth,start.getDate()+1);
}
for(Date date:listOfDatesInThisMonth){
Rec recItem = new Rec();
recItem.setDate(date);
recItems.add(recItem );
}
Rendering
Column<Rec,String> dayColumn = new Column<Rec,String>(new TextCell())
{
#Override
public String getValue(Rec rec)
{
dayNr = DateTimeFormat.getFormat( "EE,d" ).format(rec.getDate());
return dayNr;
}
};
Something like this ??
private static String getMonthsString() {
StringBuffer buffer = new StringBuffer();
Date date = new Date() ;
int i = date.getMonth();
if(i==2)//feb {
for (int j = 0; j < 28; j++) {
buffer.append(DateTimeFormat.getFormat( "EE,d" ).format( new Date(new Date().getTime() + ((1000 * 60 * 60 * 24*j)))));
}
return buffer.toString();
}
In a Cell Table each row is one record. A month will have atleast 28 days. So you must build atleast 28 records and do setList or setData on the cell Table. A short code snippet is given below -
Date currentDate = new Date();
Map<Integer, String> daysMap = new HashMap<Integer, String>();
daysMap .put(0,"Sunday");
.
.
daysMap .put(6, "Saturday");
Map<Integer, Integer> monthMap = new HashMap<Integer, Integer>();
monthMap.put(0, 31);
.
.
monthMap.put(0, 31);
List<Rec> list = new ArrayList<Rec>();
for(int i=1;i <= monthMap.get(currentDate.getMonth());i++)
{
list.add(new Rec( daysMap.get(currentDate.getDay())+" , "+ i ));
}
Column<Rec,String> dayColumn = new Column<Rec,String>(new TextCell())
{
#Override
public String getValue(Rec rec)
{
return rec.getDayDateString(); // which returns Friday, 1 etc.
}
};
table.addColumn(dayColumn, "Date");
ListDataProvider<Rec> listDataProvider = new ListDataProvider<Rec>();
listDataProvider.addDataDisplay(table);
listDataProvider.setList( list );
You could get the dates of each month on the server side using java.util.Calendar
Showing a scrollable list for dates is horrible usability. I would suggest using a DatePickerCell instead. It uses a date picker, so that the user can just click on the date to choose it.