JBoss Rich Faces SVN: r20115 - modules/tests/metamer/trunk/application/src/main/webapp/components/richInplaceInput.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-11-19 06:20:55 -0500 (Fri, 19 Nov 2010)
New Revision: 20115
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richInplaceInput/simple.xhtml
Log:
https://jira.jboss.org/browse/RFPL-757
* disableStateClass renamed
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richInplaceInput/simple.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richInplaceInput/simple.xhtml 2010-11-19 09:54:45 UTC (rev 20114)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richInplaceInput/simple.xhtml 2010-11-19 11:20:55 UTC (rev 20115)
@@ -45,7 +45,7 @@
converter="#{richInplaceInputBean.attributes['converter'].value}"
converterMessage="#{richInplaceInputBean.attributes['converterMessage'].value}"
defaultLabel="#{richInplaceInputBean.attributes['defaultLabel'].value}"
- disableStateClass="#{richInplaceInputBean.attributes['disableStateClass'].value}"
+ disabledStateClass="#{richInplaceInputBean.attributes['disableStateClass'].value}"
editClass="#{richInplaceInputBean.attributes['editClass'].value}"
editEvent="#{richInplaceInputBean.attributes['editEvent'].value}"
editStateClass="#{richInplaceInputBean.attributes['editStateClass'].value}"
14 years, 1 month
JBoss Rich Faces SVN: r20114 - in modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest: richCalendar and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-11-19 04:54:45 -0500 (Fri, 19 Nov 2010)
New Revision: 20114
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/AbstractCalendarTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarBasic.java
Log:
https://jira.jboss.org/browse/RF-9178
* added 60 tests for rich:calendar
Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/AbstractCalendarTest.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/AbstractCalendarTest.java (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/AbstractCalendarTest.java 2010-11-19 09:54:45 UTC (rev 20114)
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richCalendar;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+
+/**
+ * Abstract test case for calendar.
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public abstract class AbstractCalendarTest extends AbstractMetamerTest {
+
+ public enum Month {
+
+ January, February, March, April, May, June, July, August, September, October, November, December;
+
+ public Month previous() {
+ if (ordinal() == 0) {
+ return December;
+ }
+ return Month.values()[ordinal() - 1];
+ }
+
+ public Month next() {
+ if (ordinal() == 11) {
+ return January;
+ }
+ return Month.values()[ordinal() + 1];
+ }
+ }
+ // basic parts
+ protected JQueryLocator calendar = pjq("span[id$=calendar]");
+ protected JQueryLocator inputs = pjq("span[id$=calendarPopup]");
+ protected JQueryLocator input = pjq("input.rf-ca-inp");
+ protected JQueryLocator image = pjq("img.rf-ca-btn");
+ protected JQueryLocator button = pjq("button.rf-ca-btn");
+ // popup
+ protected JQueryLocator popup = pjq("table[id$=calendarContent]");
+ protected JQueryLocator prevYearButton = pjq("td.rf-ca-tl:eq(0) > div");
+ protected JQueryLocator nextYearButton = pjq("td.rf-ca-tl:eq(3) > div");
+ protected JQueryLocator prevMonthButton = pjq("td.rf-ca-tl:eq(1) > div");
+ protected JQueryLocator nextMonthButton = pjq("td.rf-ca-tl:eq(2) > div");
+ protected JQueryLocator closeButton = pjq("td.rf-ca-tl:eq(4) > div");
+ protected JQueryLocator monthLabel = pjq("td.rf-ca-month > div");
+ // 0 = blank, 1 = Sun, 2 = Mon, 3 = Tue ...
+ protected JQueryLocator weekDayLabel = pjq("td.rf-ca-days:eq({0})");
+ // week = 1..6, day = 0..6
+ protected JQueryLocator cellWeekDay = pjq("tr[id$=calendarWeekNum{0}] > td:eq({1})");
+ // day = 0..41
+ protected JQueryLocator cellDay = pjq("td.rf-ca-c:eq({0})");
+ // 0..6
+ protected JQueryLocator week = pjq("td.rf-ca-week:eq({0})");
+ protected JQueryLocator cleanButton = pjq("td.rf-ca-tl-ftr:eq(1) > div");
+ protected JQueryLocator timeButton = pjq("td.rf-ca-tl-ftr:eq(2) > div");
+ protected JQueryLocator todayButton = pjq("td.rf-ca-tl-ftr:eq(4) > div");
+ protected JQueryLocator applyButton = pjq("td.rf-ca-tl-ftr:eq(5) > div");
+ // time panel
+ protected JQueryLocator timePanel = pjq("table[id$=calendarEditor]");
+ protected JQueryLocator hoursInput = pjq("input[id$=calendarTimeHours]");
+ protected JQueryLocator hoursInputUp = pjq("div[id$=calendarTimeHoursBtnUp]");
+ protected JQueryLocator hoursInputDown = pjq("div[id$=calendarTimeHoursBtnDown]");
+ protected JQueryLocator minutesInput = pjq("input[id$=calendarTimeMinutes]");
+ protected JQueryLocator minutesInputUp = pjq("div[id$=calendarTimeMinutesBtnUp]");
+ protected JQueryLocator minutesInputDown = pjq("div[id$=calendarTimeMinutesBtnDown]");
+ protected JQueryLocator okButton = pjq("td.rf-ca-time-layout-ok > div");
+ protected JQueryLocator cancelButton = pjq("td.rf-ca-time-layout-cancel > div");
+}
Property changes on: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/AbstractCalendarTest.java
___________________________________________________________________
Name: svn:keywords
+ Revision
Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarAttributes.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarAttributes.java (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarAttributes.java 2010-11-19 09:54:45 UTC (rev 20114)
@@ -0,0 +1,707 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richCalendar;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardNoRequest;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.net.URL;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.AttributeLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.waiting.EventFiredCondition;
+import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for attributes of a calendar on page faces/components/richCalendar/simple.xhtml.
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TestRichCalendarAttributes extends AbstractCalendarTest {
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath, "faces/components/richCalendar/simple.xhtml");
+ }
+
+ @Test
+ public void testBoundaryDatesModeNull() {
+ selenium.click(input);
+
+ String month = selenium.getText(monthLabel);
+ guardNoRequest(selenium).click(cellWeekDay.format(6, 6));
+ String newMonth = selenium.getText(monthLabel);
+ assertEquals(newMonth, month, "Month should not change.");
+
+ // the most top-left column might be 1st day of month
+ while (selenium.getText(cellWeekDay.format(1, 0)).equals("1")) {
+ selenium.click(prevMonthButton);
+ }
+
+ guardNoRequest(selenium).click(cellWeekDay.format(1, 1));
+ newMonth = selenium.getText(monthLabel);
+ assertEquals(newMonth, month, "Month should not change.");
+ }
+
+ @Test
+ public void testBoundaryDatesModeInactive() {
+ JQueryLocator selectOption = pjq("input[name$=boundaryDatesModeInput][value=inactive]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ testBoundaryDatesModeNull();
+ }
+
+ @Test
+ public void testBoundaryDatesModeScroll() {
+ JQueryLocator selectOption = pjq("input[name$=boundaryDatesModeInput][value=scroll]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+ selenium.click(input);
+
+ String thisMonth = selenium.getText(monthLabel);
+ // November, 2010 -> November
+ thisMonth = thisMonth.substring(0, thisMonth.indexOf(","));
+ guardNoRequest(selenium).click(cellWeekDay.format(6, 6));
+ String newMonth = selenium.getText(monthLabel);
+ newMonth = newMonth.substring(0, newMonth.indexOf(","));
+ assertEquals(Month.valueOf(newMonth), Month.valueOf(thisMonth).next(), "Month did not change correctly.");
+
+ assertNoDateSelected();
+
+ // the most top-left column might be 1st day of month
+ while (selenium.getText(cellWeekDay.format(1, 0)).equals("1")) {
+ selenium.click(prevMonthButton);
+ }
+
+ thisMonth = selenium.getText(monthLabel);
+ // November, 2010 -> November
+ thisMonth = thisMonth.substring(0, thisMonth.indexOf(","));
+ guardNoRequest(selenium).click(cellWeekDay.format(1, 1));
+ newMonth = selenium.getText(monthLabel);
+ newMonth = newMonth.substring(0, newMonth.indexOf(","));
+
+ assertEquals(Month.valueOf(newMonth), Month.valueOf(thisMonth).previous(), "Month did not change correctly.");
+
+ assertNoDateSelected();
+ }
+
+ @Test
+ public void testBoundaryDatesModeSelect() {
+ JQueryLocator selectOption = pjq("input[name$=boundaryDatesModeInput][value=select]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+ selenium.click(input);
+
+ String thisMonth = selenium.getText(monthLabel);
+ String selectedDate = selenium.getText(cellWeekDay.format(6, 6));
+ // November, 2010 -> November
+ thisMonth = thisMonth.substring(0, thisMonth.indexOf(","));
+ guardNoRequest(selenium).click(cellWeekDay.format(6, 6));
+ String newMonth = selenium.getText(monthLabel);
+ newMonth = newMonth.substring(0, newMonth.indexOf(","));
+ assertEquals(Month.valueOf(newMonth), Month.valueOf(thisMonth).next(), "Month did not change correctly.");
+
+ assertSelected(selectedDate);
+
+ // the most top-left column might be 1st day of month
+ while (selenium.getText(cellWeekDay.format(1, 0)).equals("1")) {
+ selenium.click(prevMonthButton);
+ }
+
+ thisMonth = selenium.getText(monthLabel);
+ selectedDate = selenium.getText(cellWeekDay.format(1, 1));
+ // November, 2010 -> November
+ thisMonth = thisMonth.substring(0, thisMonth.indexOf(","));
+ guardNoRequest(selenium).click(cellWeekDay.format(1, 1));
+ newMonth = selenium.getText(monthLabel);
+ newMonth = newMonth.substring(0, newMonth.indexOf(","));
+
+ assertEquals(Month.valueOf(newMonth), Month.valueOf(thisMonth).previous(), "Month did not change correctly.");
+
+ assertSelected(selectedDate);
+ }
+
+ @Test
+ public void testButtonClass() {
+ testStyleClass(image, "buttonClass");
+ }
+
+ @Test
+ public void testButtonClassLabel() {
+ selenium.type(pjq("input[type=text][id$=buttonLabelInput]"), "label");
+ selenium.waitForPageToLoad();
+
+ testStyleClass(button, "buttonClass");
+ }
+
+ @Test
+ public void testButtonClassIcon() {
+ JQueryLocator selectOption = pjq("td:has(label:contains(heart)) > input[name$=buttonIconInput]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ testStyleClass(image, "buttonClass");
+ }
+
+ @Test
+ public void testButtonIcon() {
+ JQueryLocator selectOption = pjq("td:has(label:contains(star)) > input[name$=buttonIconInput]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ AttributeLocator attr = image.getAttribute(Attribute.SRC);
+ String src = selenium.getAttribute(attr);
+ assertTrue(src.contains("star.png"), "Calendar's icon was not updated.");
+
+ selectOption = pjq("td:has(label:contains(null)) > input[name$=buttonIconInput]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ src = selenium.getAttribute(attr);
+ assertTrue(src.contains("calendarIcon.png"), "Calendar's icon was not updated.");
+ }
+
+ @Test
+ public void testButtonIconDisabled() {
+ JQueryLocator selectOption = pjq("input[name$=disabledInput][value=true]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ selectOption = pjq("td:has(label:contains(heart)) > input[name$=buttonIconDisabledInput]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ AttributeLocator attr = image.getAttribute(Attribute.SRC);
+ String src = selenium.getAttribute(attr);
+ assertTrue(src.contains("heart.png"), "Calendar's icon was not updated.");
+
+ selectOption = pjq("td:has(label:contains(null)) > input[name$=buttonIconDisabledInput]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ src = selenium.getAttribute(attr);
+ assertTrue(src.contains("calendarIcon.png"), "Calendar's icon was not updated.");
+ }
+
+ @Test
+ public void testButtonLabel() {
+ selenium.type(pjq("input[type=text][id$=buttonLabelInput]"), "label");
+ selenium.waitForPageToLoad();
+
+ assertTrue(selenium.isDisplayed(button), "Button should be displayed.");
+ assertEquals(selenium.getText(button), "label", "Label of the button.");
+ if (selenium.isElementPresent(image)) {
+ assertFalse(selenium.isDisplayed(image), "Image should not be displayed.");
+ }
+
+ JQueryLocator selectOption = pjq("td:has(label:contains(star)) > input[name$=buttonIconInput]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ if (selenium.isElementPresent(image)) {
+ assertFalse(selenium.isDisplayed(image), "Image should not be displayed.");
+ }
+ }
+
+ @Test
+ public void testDatePattern() {
+ selenium.type(pjq("input[type=text][id$=datePatternInput]"), "hh:mm:ss a MMMM d, yyyy");
+ selenium.waitForPageToLoad();
+
+ selenium.click(input);
+
+ selenium.click(cellDay.format(6));
+ String day = selenium.getText(cellDay.format(6));
+ String month = selenium.getText(monthLabel);
+
+ String selectedDate = null;
+ try {
+ Date date = new SimpleDateFormat("d MMMM, yyyy hh:mm a").parse(day + " " + month + " 12:00 PM");
+ selectedDate = new SimpleDateFormat("hh:mm:ss a MMMM d, yyyy").format(date);
+ } catch (ParseException ex) {
+ fail(ex.getMessage());
+ }
+
+ selenium.click(applyButton);
+ assertFalse(selenium.isDisplayed(popup), "Popup should not be displayed.");
+
+ String inputDate = selenium.getValue(input);
+ assertEquals(inputDate, selectedDate, "Input doesn't contain selected date.");
+ }
+
+ @Test
+ public void testDayStyleClass() {
+ JQueryLocator selectOption = pjq("input[name$=dayStyleClassInput][value=yellowTuesdays]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ selenium.click(input);
+
+ for (int i = 2; i < 42; i += 7) {
+ if (!selenium.belongsClass(cellDay.format(i), "rf-ca-boundary-dates")) {
+ assertTrue(selenium.belongsClass(cellDay.format(i), "yellowDay"), "Cell nr. " + i + " should be yellow.");
+ }
+ }
+
+ selectOption = pjq("input[name$=dayStyleClassInput][value=]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ selenium.click(input);
+
+ for (int i = 0; i < 42; i++) {
+ assertFalse(selenium.belongsClass(cellDay.format(i), "yellowDay"), "Cell nr. " + i + " should not be yellow.");
+ }
+ }
+
+ @Test
+ @IssueTracking("https://jira.jboss.org/browse/RF-9837")
+ public void testDefaultTime() {
+ selenium.type(pjq("input[type=text][id$=defaultTimeInput]"), "21:24");
+ selenium.waitForPageToLoad();
+
+ selenium.click(input);
+ selenium.click(cellWeekDay.format(3, 3));
+
+ boolean displayed = selenium.isDisplayed(timeButton);
+ assertTrue(displayed, "Time button should be visible.");
+ String buttonText = selenium.getText(timeButton);
+ assertEquals(buttonText, "21:24", "Default time");
+ }
+
+ @Test
+ public void testDisabled() {
+ JQueryLocator selectOption = pjq("input[name$=disabledInput][value=true]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ AttributeLocator disabledAttr = input.getAttribute(new Attribute("disabled"));
+ assertTrue(selenium.isAttributePresent(disabledAttr), "Disabled attribute of input should be defined.");
+ assertEquals(selenium.getAttribute(disabledAttr), "disabled", "Input should be disabled.");
+
+ selenium.click(input);
+ assertFalse(selenium.isDisplayed(popup), "Popup should not be displayed.");
+
+ selenium.click(image);
+ assertFalse(selenium.isDisplayed(popup), "Popup should not be displayed.");
+ }
+
+ @Test
+ public void testEnableManualInput() {
+ AttributeLocator readonlyAttr = input.getAttribute(new Attribute("readonly"));
+ assertTrue(selenium.isAttributePresent(readonlyAttr), "Readonly attribute of input should be defined.");
+ assertEquals(selenium.getAttribute(readonlyAttr), "readonly", "Input should be read-only.");
+
+ JQueryLocator selectOption = pjq("input[name$=enableManualInputInput][value=true]");
+ selenium.click(selectOption);
+ selenium.waitForPageToLoad();
+
+ assertFalse(selenium.isAttributePresent(readonlyAttr), "Readonly attribute of input should not be defined.");
+ }
+
+ @Test
+ @IssueTracking("https://jira.jboss.org/browse/RF-9646")
+ public void testFirstWeekDay() {
+ selenium.type(pjq("input[type=text][id$=firstWeekDayInput]"), "6");
+ selenium.waitForPageToLoad();
+
+ selenium.click(input);
+
+ String[] labels = {"", "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri"};
+
+ for (int i = 0; i < 8; i++) {
+ String label = selenium.getText(weekDayLabel.format(i));
+ assertEquals(label, labels[i], "Week day label " + i);
+ }
+
+ // wrong input
+ selenium.type(pjq("input[type=text][id$=firstWeekDayInput]"), "9");
+ selenium.waitForPageToLoad();
+
+ selenium.click(input);
+
+ labels = new String[]{"", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
+
+ for (int i = 0; i < 8; i++) {
+ String label = selenium.getText(weekDayLabel.format(i));
+ assertEquals(label, labels[i], "Week day label " + i);
+ }
+ }
+
+ @Test
+ public void testInputClass() {
+ testStyleClass(input, "inputClass");
+ }
+
+ @Test
+ public void testInputSize() {
+ selenium.type(pjq("input[type=text][id$=inputSizeInput]"), "30");
+ selenium.waitForPageToLoad();
+
+ AttributeLocator sizeAttr = input.getAttribute(Attribute.SIZE);
+ assertTrue(selenium.isAttributePresent(sizeAttr), "Size attribute of input should be defined.");
+ assertEquals(selenium.getAttribute(sizeAttr), "30", "Input should be disabled.");
+ }
+
+ @Test
+ public void testInputStyle() {
+ testStyle(input, "inputStyle");
+ }
+
+ @Test
+ public void testLocale() {
+ selenium.type(pjq("input[type=text][id$=localeInput]"), "ru");
+ selenium.waitForPageToLoad();
+
+ selenium.click(input);
+
+ String[] labels = {"", "Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"};
+
+ for (int i = 0; i < 8; i++) {
+ String label = selenium.getText(weekDayLabel.format(i));
+ assertEquals(label, labels[i], "Week day label " + i);
+ }
+
+ selenium.click(cellDay.format(6));
+ String day = selenium.getText(cellDay.format(6));
+ String month = selenium.getText(monthLabel);
+
+ String selectedDate = null;
+ try {
+ Date date = new SimpleDateFormat("d MMMM, yyyy hh:mm", new Locale("ru")).parse(day + " " + month + " 12:00");
+ selectedDate = new SimpleDateFormat("MMM d, yyyy hh:mm", new Locale("ru")).format(date);
+ } catch (ParseException ex) {
+ fail(ex.getMessage());
+ }
+
+ selenium.click(applyButton);
+ String inputDate = selenium.getValue(input);
+ assertEquals(inputDate, selectedDate, "Input doesn't contain selected date.");
+ }
+
+ @Test
+ public void testOninputblur() {
+ testFireEvent(Event.BLUR, input, "inputblur");
+ }
+
+ @Test
+ @IssueTracking("https://jira.jboss.org/browse/RF-9602")
+ public void testOninputchange() {
+ selenium.type(pjq("input[id$=oninputchangeInput]"), "metamerEvents += \"inputchange \"");
+ selenium.waitForPageToLoad(TIMEOUT);
+
+ selenium.click(input);
+ selenium.click(cellDay.format(6));
+ selenium.click(applyButton);
+
+ waitGui.failWith("Attribute oninputchange does not work correctly").until(
+ new EventFiredCondition(new Event("inputchange")));
+ }
+
+ @Test
+ public void testOninputclick() {
+ testFireEvent(Event.CLICK, input, "inputclick");
+ }
+
+ @Test
+ public void testOninputdblclick() {
+ testFireEvent(Event.DBLCLICK, input, "inputdblclick");
+ }
+
+ @Test
+ public void testOninputfocus() {
+ testFireEvent(Event.FOCUS, input, "inputfocus");
+ }
+
+ @Test
+ public void testOninputkeydown() {
+ testFireEvent(Event.KEYDOWN, input, "inputkeydown");
+ }
+
+ @Test
+ public void testOninputkeypress() {
+ testFireEvent(Event.KEYPRESS, input, "inputkeypress");
+ }
+
+ @Test
+ public void testOninputkeyup() {
+ testFireEvent(Event.KEYUP, input, "inputkeyup");
+ }
+
+ @Test
+ public void testOninputmousedown() {
+ testFireEvent(Event.MOUSEDOWN, input, "inputmousedown");
+ }
+
+ @Test
+ public void testOninputmousemove() {
+ testFireEvent(Event.MOUSEMOVE, input, "inputmousemove");
+ }
+
+ @Test
+ public void testOninputmouseout() {
+ testFireEvent(Event.MOUSEOUT, input, "inputmouseout");
+ }
+
+ @Test
+ public void testOninputmouseover() {
+ testFireEvent(Event.MOUSEOVER, input, "inputmouseover");
+ }
+
+ @Test
+ public void testOninputmouseup() {
+ testFireEvent(Event.MOUSEUP, input, "inputmouseup");
+ }
+
+ @Test
+ public void testOninputselect() {
+ testFireEvent(Event.SELECT, input, "inputselect");
+ }
+
+ @Test
+ public void testPopup() {
+ selenium.click(pjq("input[name$=popupInput][value=false]"));
+ selenium.waitForPageToLoad();
+
+ boolean displayed = selenium.isDisplayed(calendar);
+ assertTrue(displayed, "Calendar is not present on the page.");
+
+ if (selenium.isElementPresent(input)) {
+ displayed = selenium.isDisplayed(input);
+ assertFalse(displayed, "Calendar's input should not be visible.");
+ }
+
+ if (selenium.isElementPresent(image)) {
+ displayed = selenium.isDisplayed(image);
+ assertFalse(displayed, "Calendar's image should not be visible.");
+ }
+
+ displayed = selenium.isDisplayed(popup);
+ assertTrue(displayed, "Popup should be visible.");
+
+ displayed = selenium.isElementPresent(button);
+ assertFalse(displayed, "Calendar's button should not be visible.");
+ }
+
+ @Test
+ public void testRendered() {
+ selenium.click(pjq("input[type=radio][name$=renderedInput][value=false]"));
+ selenium.waitForPageToLoad();
+
+ assertFalse(selenium.isElementPresent(calendar), "Panel should not be rendered when rendered=false.");
+ }
+
+ @Test
+ public void testShowApplyButton() {
+ selenium.click(pjq("input[type=radio][name$=showApplyButtonInput][value=false]"));
+ selenium.waitForPageToLoad();
+
+ selenium.click(input);
+ if (selenium.isElementPresent(applyButton)) {
+ assertFalse(selenium.isDisplayed(applyButton), "Apply button should not be displayed.");
+ }
+
+ guardNoRequest(selenium).click(cellDay.format(6));
+ String day = selenium.getText(cellDay.format(6));
+ String month = selenium.getText(monthLabel);
+
+ String selectedDate = null;
+ try {
+ Date date = new SimpleDateFormat("d MMMM, yyyy hh:mm").parse(day + " " + month + " 12:00");
+ selectedDate = new SimpleDateFormat("MMM d, yyyy hh:mm").format(date);
+ } catch (ParseException ex) {
+ fail(ex.getMessage());
+ }
+
+ assertFalse(selenium.isDisplayed(popup), "Popup should not be displayed.");
+
+ String inputDate = selenium.getValue(input);
+ assertEquals(inputDate, selectedDate, "Input doesn't contain selected date.");
+ }
+
+ @Test
+ public void testShowFooter() {
+ selenium.click(pjq("input[type=radio][name$=showFooterInput][value=false]"));
+ selenium.waitForPageToLoad();
+
+ selenium.click(input);
+ boolean displayed = true;
+
+ if (selenium.isElementPresent(todayButton)) {
+ displayed = selenium.isDisplayed(todayButton);
+ assertFalse(displayed, "Today button should not be visible.");
+ }
+
+ if (selenium.isElementPresent(applyButton)) {
+ displayed = selenium.isDisplayed(applyButton);
+ assertFalse(displayed, "Apply button should not be visible.");
+ }
+
+ displayed = selenium.isElementPresent(cleanButton);
+ assertFalse(displayed, "Clean button should not be visible.");
+
+ displayed = selenium.isElementPresent(timeButton);
+ assertFalse(displayed, "Time button should not be visible.");
+
+ selenium.click(cellWeekDay.format(3, 3));
+
+ if (selenium.isElementPresent(cleanButton)) {
+ displayed = selenium.isDisplayed(cleanButton);
+ assertFalse(displayed, "Clean button should not be visible.");
+ }
+
+ if (selenium.isElementPresent(timeButton)) {
+ displayed = selenium.isDisplayed(timeButton);
+ assertFalse(displayed, "Time button should not be visible.");
+ }
+ }
+
+ @Test
+ public void testShowHeader() {
+ selenium.click(pjq("input[type=radio][name$=showHeaderInput][value=false]"));
+ selenium.waitForPageToLoad();
+
+ selenium.click(input);
+ boolean displayed = true;
+
+ if (selenium.isElementPresent(prevYearButton)) {
+ displayed = selenium.isDisplayed(prevYearButton);
+ assertFalse(displayed, "Previous year button should not be visible.");
+ }
+
+ if (selenium.isElementPresent(prevMonthButton)) {
+ displayed = selenium.isDisplayed(prevMonthButton);
+ assertFalse(displayed, "Previous month button should not be visible.");
+ }
+
+ if (selenium.isElementPresent(nextMonthButton)) {
+ displayed = selenium.isDisplayed(nextMonthButton);
+ assertFalse(displayed, "Next month button should not be visible.");
+ }
+
+ if (selenium.isElementPresent(nextYearButton)) {
+ displayed = selenium.isDisplayed(nextYearButton);
+ assertFalse(displayed, "Next year button should not be visible.");
+ }
+
+ if (selenium.isElementPresent(closeButton)) {
+ displayed = selenium.isDisplayed(closeButton);
+ assertFalse(displayed, "Close button should not be visible.");
+ }
+
+ if (selenium.isElementPresent(monthLabel)) {
+ displayed = selenium.isDisplayed(monthLabel);
+ assertFalse(displayed, "Month label should not be visible.");
+ }
+ }
+
+ @Test
+ public void testShowInput() {
+ selenium.click(pjq("input[type=radio][name$=showInputInput][value=false]"));
+ selenium.waitForPageToLoad();
+
+ if (selenium.isElementPresent(input)) {
+ boolean displayed = selenium.isDisplayed(input);
+ assertFalse(displayed, "Input should not be visible.");
+ }
+ }
+
+ @Test
+ public void testShowWeekDaysBar() {
+ selenium.click(pjq("input[type=radio][name$=showWeekDaysBarInput][value=false]"));
+ selenium.waitForPageToLoad();
+
+ for (int i = 0; i < 8; i++) {
+ if (selenium.isElementPresent(weekDayLabel.format(i))) {
+ boolean displayed = selenium.isDisplayed(weekDayLabel.format(i));
+ assertFalse(displayed, "Bar with week days should not be visible.");
+ }
+ }
+ }
+
+ @Test
+ public void testShowWeeksBar() {
+ selenium.click(pjq("input[type=radio][name$=showWeeksBarInput][value=false]"));
+ selenium.waitForPageToLoad();
+
+ for (int i = 0; i < 6; i++) {
+ if (selenium.isElementPresent(week.format(i))) {
+ boolean displayed = selenium.isDisplayed(week.format(i));
+ assertFalse(displayed, "Bar with week numbers should not be visible.");
+ }
+ }
+ }
+
+ /**
+ * Checks that no date in the open month is selected.
+ */
+ private void assertNoDateSelected() {
+ for (int i = 0; i < 42; i++) {
+ assertFalse(selenium.belongsClass(cellDay.format(i), "rf-ca-sel"), "Cell nr. " + i + " should not be selected.");
+ }
+ }
+
+ /**
+ * Checks that no date in the open month is selected except of one passed as argument.
+ * @param exceptOfDate date that should be selected (e.g. "13")
+ */
+ private void assertSelected(String exceptOfDate) {
+ int lowerBoundary = 0;
+ int upperBoundary = 42;
+
+ if (Integer.parseInt(exceptOfDate) < 15) {
+ upperBoundary = 21;
+ } else {
+ lowerBoundary = 21;
+ }
+
+ // check 3 lines of cells that contain selected date
+ for (int i = lowerBoundary; i < upperBoundary; i++) {
+ if (exceptOfDate.equals(selenium.getText(cellDay.format(i)))) {
+ assertTrue(selenium.belongsClass(cellDay.format(i), "rf-ca-sel"), "Cell nr. " + i + " should not be selected.");
+ } else {
+ assertFalse(selenium.belongsClass(cellDay.format(i), "rf-ca-sel"), "Cell nr. " + i + " should not be selected.");
+ }
+ }
+
+ lowerBoundary = lowerBoundary == 0 ? 21 : 0;
+ upperBoundary = upperBoundary == 21 ? 42 : 21;
+
+ // check other 3 lines of cells
+ for (int i = lowerBoundary; i < upperBoundary; i++) {
+ assertFalse(selenium.belongsClass(cellDay.format(i), "rf-ca-sel"), "Cell nr. " + i + " should not be selected.");
+ }
+ }
+}
Property changes on: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarAttributes.java
___________________________________________________________________
Name: svn:keywords
+ Revision
Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarBasic.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarBasic.java (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarBasic.java 2010-11-19 09:54:45 UTC (rev 20114)
@@ -0,0 +1,336 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richCalendar;
+
+import java.text.ParseException;
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardNoRequest;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.testng.annotations.Test;
+
+/**
+ * Test case for basic functionality of calendar on page faces/components/richCalendar/simple.xhtml.
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TestRichCalendarBasic extends AbstractCalendarTest {
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath, "faces/components/richCalendar/simple.xhtml");
+ }
+
+ @Test
+ public void testInit() {
+ boolean displayed = selenium.isDisplayed(calendar);
+ assertTrue(displayed, "Calendar is not present on the page.");
+
+ displayed = selenium.isDisplayed(input);
+ assertTrue(displayed, "Calendar's input should be visible.");
+
+ displayed = selenium.isDisplayed(image);
+ assertTrue(displayed, "Calendar's image should be visible.");
+
+ displayed = selenium.isDisplayed(popup);
+ assertFalse(displayed, "Popup should not be visible.");
+
+ displayed = selenium.isElementPresent(button);
+ assertFalse(displayed, "Calendar's button should not be visible.");
+ }
+
+ @Test
+ public void testOpenPopupClickOnInput() {
+ guardNoRequest(selenium).click(input);
+ boolean displayed = selenium.isDisplayed(popup);
+ assertTrue(displayed, "Popup should be visible.");
+ }
+
+ @Test
+ public void testOpenPopupClickOnImage() {
+ guardNoRequest(selenium).click(image);
+ boolean displayed = selenium.isDisplayed(popup);
+ assertTrue(displayed, "Popup should be visible.");
+ }
+
+ @Test
+ public void testHeaderButtons() {
+ selenium.click(input);
+
+ boolean displayed = selenium.isDisplayed(prevYearButton);
+ assertTrue(displayed, "Previous year button should be visible.");
+ String buttonText = selenium.getText(prevYearButton);
+ assertEquals(buttonText, "<<", "Previous year button");
+
+ displayed = selenium.isDisplayed(prevMonthButton);
+ assertTrue(displayed, "Previous month button should be visible.");
+ buttonText = selenium.getText(prevMonthButton);
+ assertEquals(buttonText, "<", "Previous month button");
+
+ displayed = selenium.isDisplayed(nextMonthButton);
+ assertTrue(displayed, "Next month button should be visible.");
+ buttonText = selenium.getText(nextMonthButton);
+ assertEquals(buttonText, ">", "Next month button");
+
+ displayed = selenium.isDisplayed(nextYearButton);
+ assertTrue(displayed, "Next year button should be visible.");
+ buttonText = selenium.getText(nextYearButton);
+ assertEquals(buttonText, ">>", "Next year button");
+
+ displayed = selenium.isDisplayed(closeButton);
+ assertTrue(displayed, "Close button should be visible.");
+ buttonText = selenium.getText(closeButton);
+ assertEquals(buttonText, "x", "Close button");
+ }
+
+ @Test
+ public void testHeaderMonth() {
+ SimpleDateFormat formatter = new SimpleDateFormat("MMMM, yyyy");
+ String month = formatter.format(new Date());
+
+ selenium.click(input);
+ String month2 = selenium.getText(monthLabel);
+ assertEquals(month2, month, "Calendar shows wrong month or year in its header.");
+ }
+
+ @Test
+ public void testFooterButtons() {
+ selenium.click(input);
+
+ boolean displayed = selenium.isDisplayed(todayButton);
+ assertTrue(displayed, "Today button should be visible.");
+ String buttonText = selenium.getText(todayButton);
+ assertEquals(buttonText, "Today", "Button's text");
+
+ displayed = selenium.isDisplayed(applyButton);
+ assertTrue(displayed, "Apply button should be visible.");
+ buttonText = selenium.getText(applyButton);
+ assertEquals(buttonText, "Apply", "Button's text");
+
+ displayed = selenium.isElementPresent(cleanButton);
+ assertFalse(displayed, "Clean button should not be visible.");
+
+ displayed = selenium.isElementPresent(timeButton);
+ assertFalse(displayed, "Time button should not be visible.");
+
+ selenium.click(cellWeekDay.format(3, 3));
+
+ displayed = selenium.isDisplayed(cleanButton);
+ assertTrue(displayed, "Clean button should be visible.");
+ buttonText = selenium.getText(cleanButton);
+ assertEquals(buttonText, "Clean", "Button's text");
+
+ displayed = selenium.isDisplayed(timeButton);
+ assertTrue(displayed, "Time button should be visible.");
+ buttonText = selenium.getText(timeButton);
+ assertEquals(buttonText, "12:00", "Button's text");
+ }
+
+ @Test
+ public void testWeekDaysLabels() {
+ selenium.click(input);
+
+ String[] labels = {"", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
+
+ for (int i = 0; i < 8; i++) {
+ String label = selenium.getText(weekDayLabel.format(i));
+ assertEquals(label, labels[i], "Week day label " + i);
+ }
+ }
+
+ @Test
+ public void testTodayIsSelected() {
+ SimpleDateFormat formatter = new SimpleDateFormat("d");
+ String today = formatter.format(new Date());
+
+ int lowerBoundary = 0;
+ int upperBoundary = 42;
+
+ // go through first half of popup or second half of popup depending on today's date
+ // it is necessary because of dates from other months are also displayed
+ if (Integer.parseInt(today) < 15) {
+ upperBoundary = 28;
+ } else {
+ lowerBoundary = 14;
+ }
+
+ selenium.click(input);
+
+ for (int i = lowerBoundary; i < upperBoundary; i++) {
+ String day = selenium.getText(cellDay.format(i));
+ if (day.equals(today)) {
+ assertTrue(selenium.belongsClass(cellDay.format(i), "rf-ca-today"), "Today's date is not styled correctly.");
+ return;
+ }
+ }
+
+ fail("Today's date is not styled correctly.");
+ }
+
+ @Test
+ public void testWeekNumbers() {
+ selenium.click(input);
+ String month = selenium.getText(monthLabel);
+ String day = selenium.getText(cellDay.format(6));
+
+ Date date = null;
+ try {
+ date = new SimpleDateFormat("d MMMM, yyyy").parse(day + " " + month);
+ } catch (ParseException ex) {
+ fail(ex.getMessage());
+ }
+ String weekNumber = new SimpleDateFormat("w").format(date);
+
+ assertEquals(selenium.getText(week.format(0)), weekNumber, "Week number on the first line.");
+ }
+
+ @Test
+ public void testSelectDate() {
+ selenium.click(input);
+
+ guardNoRequest(selenium).click(cellDay.format(6));
+ assertTrue(selenium.belongsClass(cellDay.format(6), "rf-ca-sel"), "Last date in the first week is not selected.");
+
+ selenium.click(cellDay.format(8));
+ assertFalse(selenium.belongsClass(cellDay.format(6), "rf-ca-sel"), "Last date in the first week should not be selected.");
+ }
+
+ @Test
+ public void testCleanButton() {
+ selenium.click(input);
+ selenium.click(cellDay.format(6));
+
+ guardNoRequest(selenium).click(cleanButton);
+ assertFalse(selenium.belongsClass(cellDay.format(6), "rf-ca-sel"), "Last date in the first week should not be selected.");
+ }
+
+ @Test
+ public void testCloseButton() {
+ selenium.click(input);
+ boolean displayed = selenium.isDisplayed(popup);
+ assertTrue(displayed, "Popup should be visible.");
+
+ guardNoRequest(selenium).click(closeButton);
+ displayed = selenium.isDisplayed(popup);
+ assertFalse(displayed, "Popup should not be visible.");
+ }
+
+ @Test
+ public void testPrevYearButton() {
+ selenium.click(input);
+ String thisYear = selenium.getText(monthLabel);
+ // November, 2010 -> 2010
+ thisYear = thisYear.substring(thisYear.indexOf(" ") + 1, thisYear.length());
+
+ guardNoRequest(selenium).click(prevYearButton);
+ String prevYear = selenium.getText(monthLabel);
+ prevYear = prevYear.substring(prevYear.indexOf(" ") + 1, prevYear.length());
+
+ assertEquals(Integer.parseInt(prevYear), Integer.parseInt(thisYear) - 1, "Year did not change correctly.");
+ }
+
+ @Test
+ public void testNextYearButton() {
+ selenium.click(input);
+ String thisYear = selenium.getText(monthLabel);
+ // November, 2010 -> 2010
+ thisYear = thisYear.substring(thisYear.indexOf(" ") + 1, thisYear.length());
+
+ guardNoRequest(selenium).click(nextYearButton);
+ String nextYear = selenium.getText(monthLabel);
+ nextYear = nextYear.substring(nextYear.indexOf(" ") + 1, nextYear.length());
+
+ assertEquals(Integer.parseInt(nextYear), Integer.parseInt(thisYear) + 1, "Year did not change correctly.");
+ }
+
+ @Test
+ public void testPrevMonthButton() {
+ selenium.click(input);
+ String thisMonth = selenium.getText(monthLabel);
+ // November, 2010 -> November
+ thisMonth = thisMonth.substring(0, thisMonth.indexOf(","));
+
+ guardNoRequest(selenium).click(prevMonthButton);
+ String prevMonth = selenium.getText(monthLabel);
+ prevMonth = prevMonth.substring(0, prevMonth.indexOf(","));
+
+ assertEquals(Month.valueOf(prevMonth), Month.valueOf(thisMonth).previous(), "Month did not change correctly.");
+ }
+
+ @Test
+ public void testNextMonthButton() {
+ selenium.click(input);
+ String thisMonth = selenium.getText(monthLabel);
+ // November, 2010 -> November
+ thisMonth = thisMonth.substring(0, thisMonth.indexOf(","));
+
+ guardNoRequest(selenium).click(nextMonthButton);
+ String nextMonth = selenium.getText(monthLabel);
+ nextMonth = nextMonth.substring(0, nextMonth.indexOf(","));
+
+ assertEquals(Month.valueOf(nextMonth), Month.valueOf(thisMonth).next(), "Month did not change correctly.");
+ }
+
+ @Test
+ public void testTodayButton() {
+ selenium.click(input);
+ String thisMonth = selenium.getText(monthLabel);
+
+ selenium.click(nextMonthButton);
+ selenium.click(prevYearButton);
+ guardNoRequest(selenium).click(todayButton);
+ String thisMonth2 = selenium.getText(monthLabel);
+
+ assertEquals(thisMonth2, thisMonth, "Today button does not work.");
+ }
+
+ @Test
+ public void testApplyButton() {
+ selenium.click(input);
+
+ selenium.click(cellDay.format(6));
+ String day = selenium.getText(cellDay.format(6));
+ String month = selenium.getText(monthLabel);
+
+ String selectedDate = null;
+ try {
+ Date date = new SimpleDateFormat("d MMMM, yyyy hh:mm").parse(day + " " + month + " 12:00");
+ selectedDate = new SimpleDateFormat("MMM d, yyyy hh:mm").format(date);
+ } catch (ParseException ex) {
+ fail(ex.getMessage());
+ }
+
+ guardNoRequest(selenium).click(applyButton);
+ assertFalse(selenium.isDisplayed(popup), "Popup should not be displayed.");
+
+ String inputDate = selenium.getValue(input);
+ assertEquals(inputDate, selectedDate, "Input doesn't contain selected date.");
+ }
+}
Property changes on: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCalendar/TestRichCalendarBasic.java
___________________________________________________________________
Name: svn:keywords
+ Revision
14 years, 1 month
JBoss Rich Faces SVN: r20113 - in modules/tests/metamer/trunk/application/src/main: resources/org/richfaces/tests/metamer/bean and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-11-19 04:45:06 -0500 (Fri, 19 Nov 2010)
New Revision: 20113
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java
modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichCalendarBean.properties
modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml
Log:
https://jira.jboss.org/browse/RF-9178
* calendar sample fixed
* attributes direction and jointPoint added
* attributes monthLabels, monthLabelsShort, weekDayLabels and weekDayLabelsShort removed
Modified: modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java
===================================================================
--- modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java 2010-11-19 02:44:12 UTC (rev 20112)
+++ modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichCalendarBean.java 2010-11-19 09:45:06 UTC (rev 20113)
@@ -59,6 +59,8 @@
attributes = Attributes.getUIComponentAttributes(UICalendar.class, getClass(), false);
attributes.setAttribute("datePattern", "MMM d, yyyy HH:mm");
+ attributes.setAttribute("direction", "bottom-right");
+ attributes.setAttribute("jointPoint", "bottom-left");
attributes.setAttribute("popup", true);
attributes.setAttribute("rendered", true);
attributes.setAttribute("showApplyButton", true);
Modified: modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichCalendarBean.properties
===================================================================
--- modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichCalendarBean.properties 2010-11-19 02:44:12 UTC (rev 20112)
+++ modules/tests/metamer/trunk/application/src/main/resources/org/richfaces/tests/metamer/bean/RichCalendarBean.properties 2010-11-19 09:45:06 UTC (rev 20113)
@@ -29,6 +29,10 @@
attr.jointPoint.auto=auto
attr.jointPoint.null=
+attr.mode.client=client
+attr.mode.ajax=ajax
+attr.mode.null=
+
attr.todayControlMode.scroll=scroll
attr.todayControlMode.select=select
attr.todayControlMode.hidden=hidden
Modified: modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml
===================================================================
--- modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml 2010-11-19 02:44:12 UTC (rev 20112)
+++ modules/tests/metamer/trunk/application/src/main/webapp/components/richCalendar/simple.xhtml 2010-11-19 09:45:06 UTC (rev 20113)
@@ -36,11 +36,11 @@
</f:metadata>
<style type="text/css">
.yellowDay {
- background: yellow;
+ background: yellow !important;
}
.aquaDay {
- background: aqua;
+ background: aqua !important;
}
</style>
@@ -82,7 +82,7 @@
dayEnabled="#{richCalendarBean.attributes['dayEnabled'].value}"
dayStyleClass="#{richCalendarBean.attributes['dayStyleClass'].value}"
defaultTime="#{richCalendarBean.attributes['defaultTime'].value}"
-
+ direction="#{richCalendarBean.attributes['direction'].value}"
disabled="#{richCalendarBean.attributes['disabled'].value}"
enableManualInput="#{richCalendarBean.attributes['enableManualInput'].value}"
firstWeekDay="#{richCalendarBean.attributes['firstWeekDay'].value}"
@@ -92,11 +92,9 @@
inputClass="#{richCalendarBean.attributes['inputClass'].value}"
inputSize="#{richCalendarBean.attributes['inputSize'].value}"
inputStyle="#{richCalendarBean.attributes['inputStyle'].value}"
-
+ jointPoint="#{richCalendarBean.attributes['jointPoint'].value}"
locale="#{richCalendarBean.attributes['locale'].value}"
minDaysInFirstWeek="#{richCalendarBean.attributes['minDaysInFirstWeek'].value}"
- monthLabels="#{richCalendarBean.attributes['monthLabels'].value}"
- monthLabelsShort="#{richCalendarBean.attributes['monthLabelsShort'].value}"
oninputblur="#{richCalendarBean.attributes['oninputblur'].value}"
oninputchange="#{richCalendarBean.attributes['oninputchange'].value}"
oninputclick="#{richCalendarBean.attributes['oninputclick'].value}"
@@ -129,8 +127,6 @@
validatorMessage="#{richCalendarBean.attributes['validatorMessage'].value}"
value="#{richCalendarBean.attributes['value'].value}"
verticalOffset="#{richCalendarBean.attributes['verticalOffset'].value}"
- weekDayLabels="#{richCalendarBean.attributes['weekDayLabels'].value}"
- weekDayLabelsShort="#{richCalendarBean.attributes['weekDayLabelsShort'].value}"
zindex="#{richCalendarBean.attributes['zindex'].value}"
>
<a4j:ajax event="inputchange" render="output"/>
14 years, 1 month
JBoss Rich Faces SVN: r20112 - in sandbox/trunk/ui/fileupload/ui/src/main: templates and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2010-11-18 21:44:12 -0500 (Thu, 18 Nov 2010)
New Revision: 20112
Modified:
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.ecss
sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js
sandbox/trunk/ui/fileupload/ui/src/main/templates/fileupload.template.xml
Log:
RF-9496
Modified: sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.ecss
===================================================================
--- sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.ecss 2010-11-19 02:36:39 UTC (rev 20111)
+++ sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.ecss 2010-11-19 02:44:12 UTC (rev 20112)
@@ -23,6 +23,10 @@
overflow-y: auto;
}
+.rf-fu-frm {
+ display: none;
+}
+
.rf-fu-btns-lft, .rf-fu-btns-rgh, .rf-fu-itm-lft, .rf-fu-itm-rgh {
display: inline-block;
overflow: hidden;
@@ -55,12 +59,12 @@
display: none;
}
-.rf-fu-btn-cnt-add, .rf-fu-btn-cnt-upl, .rf-fu-btn-cnt-clr, .rf-fu-itm-lbl, .rf-fu-itm-lnk {
+.rf-fu-btn-cnt-add, .rf-fu-btn-cnt-upl, .rf-fu-btn-cnt-clr, .rf-fu-itm-lbl, .rf-fu-itm-st, .rf-fu-itm-lnk {
font-family: '#{richSkin.generalFamilyFont}';
font-size: '#{richSkin.generalSizeFont}';
}
-.rf-fu-btn-cnt-add, .rf-fu-btn-cnt-upl, .rf-fu-btn-cnt-clr, .rf-fu-itm-lbl {
+.rf-fu-btn-cnt-add, .rf-fu-btn-cnt-upl, .rf-fu-btn-cnt-clr, .rf-fu-itm-lbl, .rf-fu-itm-st {
color: '#{richSkin.generalTextColor}';
}
@@ -77,9 +81,12 @@
position: relative;
}
+.rf-fu-btn-cnt-upl, .rf-fu-itm-st {
+ font-weight: bold;
+}
+
.rf-fu-btn-cnt-upl {
background-image: url("#{resource['org.richfaces:fu-upl.gif']}");
- font-weight: bold;
}
.rf-fu-btn-cnt-clr {
@@ -126,4 +133,9 @@
.rf-fu-itm-lnk {
color: '#{richSkin.generalLinkColor}';
+}
+
+.rf-fu-itm-st {
+ display: none;
+ margin-top: 5px;
}
\ No newline at end of file
Modified: sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js
===================================================================
--- sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js 2010-11-19 02:36:39 UTC (rev 20111)
+++ sandbox/trunk/ui/fileupload/ui/src/main/resources/META-INF/resources/org.richfaces/fileupload.js 2010-11-19 02:44:12 UTC (rev 20112)
@@ -20,13 +20,11 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
(function(richfaces, jQuery) {
- var ITEM_STATE = {
- NEW: {},
- IN_PROGRESS: {},
- DONE: {}
- };
-
- var ITEM_HTML = '<div class="rf-fu-itm"><span class="rf-fu-itm-lft"><span class="rf-fu-itm-lbl"/></span>'
+
+ var UID = "rf_fu_uid";
+
+ var ITEM_HTML = '<div class="rf-fu-itm">'
+ + '<span class="rf-fu-itm-lft"><span class="rf-fu-itm-lbl"/><span class="rf-fu-itm-st"/></span>'
+ '<span class="rf-fu-itm-rgh"><a href="javascript:void(0)" class="rf-fu-itm-lnk"/></span></div>';
richfaces.ui = richfaces.ui || {};
@@ -40,6 +38,8 @@
init: function(id) {
this.id = id;
this.element = jQuery(this.attachToDom());
+ this.form = this.element.parents("form:first");
+ this.iframe = this.element.children("iframe:first");
var header = this.element.children(".rf-fu-hdr:first");
var leftButtons = header.children(".rf-fu-btns-lft:first");
this.addButton = leftButtons.children(".rf-fu-btn-add:first");
@@ -51,6 +51,7 @@
this.cleanInput = this.input.clone();
this.addProxy = jQuery.proxy(this.__addItem, this);
this.input.change(this.addProxy);
+ this.uploadButton.click(jQuery.proxy(this.__startUpload, this));
this.clearButton.click(jQuery.proxy(this.__removeAllItems, this));
},
@@ -67,8 +68,6 @@
},
__removeItem: function(item) {
- item.input.remove();
- item.element.remove();
this.items.splice(this.items.indexOf(item), 1);
this.__updateButtons();
},
@@ -81,16 +80,11 @@
},
__updateButtons: function() {
- if (this.items.length) {
- var hide = true;
- for ( var i = 0; i < this.items.length && hide; i++) {
- if (this.items[i].state == ITEM_STATE.NEW) {
- this.uploadButton.css("display", "inline-block");
- hide = false;
- }
- }
- if (hide) {
- this.uploadButton.hide();
+ if (!this.loadableItem && this.list.children(".rf-fu-itm").size()) {
+ if (this.items.length) {
+ this.uploadButton.css("display", "inline-block");
+ } else {
+ this.uploadButton.hide();
}
this.clearButton.css("display", "inline-block");
} else {
@@ -99,14 +93,38 @@
}
},
- __getLinkText: function(state) {
- var text = "";
- if (state == ITEM_STATE.NEW) {
- text = "Delete";
- } else if (state == ITEM_STATE.DONE) {
- text = "Clear";
+ __startUpload: function() {
+ this.loadableItem = this.items.shift();
+ this.loadableItem.startUploading();
+ this.__updateButtons();
+ this.__submit();
+ },
+
+ __submit: function() {
+ var originalAction = this.form.attr("action");
+ var originalEnctype = this.form.attr("enctype");
+ try {
+ this.loadableItem.input.attr("name", this.id);
+ this.form.attr("action", originalAction + "?" + UID + "=1");
+ this.form.attr("enctype", "multipart/form-data");
+ this.iframe.load(jQuery.proxy(this.__load, this));
+ richfaces.submitForm(this.form, null, this.id);
+ } finally {
+ this.form.attr("action", originalAction);
+ this.form.attr("enctype", originalEnctype);
+ this.loadableItem.input.removeAttr("name");
+ }
+ },
+
+ __load: function(event) {
+ var result = event.target.contentDocument.documentElement.id.split(":");
+ if (this.loadableItem && UID + 1 == result[0]) {
+ if ("done" == result[1]) {
+ this.loadableItem.finishUploading();
+ this.loadableItem = null;
+ this.__updateButtons();
+ }
}
- return text;
}
});
@@ -116,20 +134,34 @@
jQuery.extend(Item.prototype, {
getJQuery: function() {
- this.state = ITEM_STATE.NEW;
this.input = this.fileUpload.input;
this.element = jQuery(ITEM_HTML);
- this.label = this.element.children(".rf-fu-itm-lft:first").children(".rf-fu-itm-lbl:first");
+ var leftArea = this.element.children(".rf-fu-itm-lft:first");
+ this.label = leftArea.children(".rf-fu-itm-lbl:first");
+ this.state = leftArea.children(".rf-fu-itm-st:first");
this.link = this.element.children(".rf-fu-itm-rgh:first").children("a");
this.label.html(this.input.val());
- this.link.html(this.fileUpload.__getLinkText(this.state));
+ this.link.html("Delete");
- this.link.click(jQuery.proxy(this.remove, this));
+ this.link.click(jQuery.proxy(this.removeOrStop, this));
return this.element;
},
- remove: function() {
+ removeOrStop: function() {
+ this.input.remove();
+ this.element.remove();
this.fileUpload.__removeItem(this);
+ },
+
+ startUploading: function() {
+ this.state.css("display", "block");;
+ this.link.html("");
+ },
+
+ finishUploading: function() {
+ this.input.remove();
+ this.state.html("Done");
+ this.link.html("Clear");
}
});
}(window.RichFaces, jQuery));
Modified: sandbox/trunk/ui/fileupload/ui/src/main/templates/fileupload.template.xml
===================================================================
--- sandbox/trunk/ui/fileupload/ui/src/main/templates/fileupload.template.xml 2010-11-19 02:36:39 UTC (rev 20111)
+++ sandbox/trunk/ui/fileupload/ui/src/main/templates/fileupload.template.xml 2010-11-19 02:44:12 UTC (rev 20112)
@@ -42,7 +42,7 @@
<span class="rf-fu-btn-add">
<span class="rf-fu-btn-cnt-add">
<span class="rf-fu-inp-cntr"> <!-- This span is needed for IE7 only. -->
- <input type="file" class="rf-fu-inp" />
+ <input type="file" class="rf-fu-inp"/>
</span>
Add...
</span>
@@ -57,7 +57,8 @@
</span>
</span>
</div>
- <div class="rf-fu-lst" />
+ <div class="rf-fu-lst"/>
+ <iframe name="#{clientId}" class="rf-fu-frm"/>
<script type="text/javascript">new RichFaces.ui.FileUpload('#{clientId}');</script>
</div>
</cc:implementation>
14 years, 1 month
JBoss Rich Faces SVN: r20111 - in sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces: component and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2010-11-18 21:36:39 -0500 (Thu, 18 Nov 2010)
New Revision: 20111
Modified:
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/application/FileUploadPhaselistener.java
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/request/MultipartRequest.java
Log:
RF-9497
Modified: sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/application/FileUploadPhaselistener.java
===================================================================
--- sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/application/FileUploadPhaselistener.java 2010-11-19 02:34:15 UTC (rev 20110)
+++ sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/application/FileUploadPhaselistener.java 2010-11-19 02:36:39 UTC (rev 20111)
@@ -51,13 +51,12 @@
private static final long serialVersionUID = 138000954953175986L;
- /** Multipart request start */
- private static final String MULTIPART = "multipart/";
-
private static final Pattern AMPERSAND = Pattern.compile("&+");
private static final Logger LOGGER = RichfacesLogger.APPLICATION.getLogger();
+ private static final String UID = "rf_fu_uid";
+
/** Flag indicating whether a temporary file should be used to cache the uploaded file */
private boolean createTempFiles = false;
@@ -88,8 +87,16 @@
*
* @see javax.faces.event.PhaseListener#afterPhase(javax.faces.event.PhaseEvent)
*/
- public void afterPhase(PhaseEvent event) {
- }
+ public void afterPhase(PhaseEvent event) {
+ if (PhaseId.APPLY_REQUEST_VALUES.equals(event.getPhaseId())) {
+ FacesContext facesContext = event.getFacesContext();
+ Object request = facesContext.getExternalContext().getRequest();
+ if (request instanceof MultipartRequest) {
+ printResponse(facesContext, HttpServletResponse.SC_OK,
+ "<html id=\"" + UID + ((MultipartRequest)request).getUploadId() + ":done\"/>");
+ }
+ }
+ }
/*
* (non-Javadoc)
@@ -97,43 +104,56 @@
* @see javax.faces.event.PhaseListener#beforePhase(javax.faces.event.PhaseEvent)
*/
public void beforePhase(PhaseEvent event) {
- FacesContext facesContext = event.getFacesContext();
- ExternalContext externalContext = facesContext.getExternalContext();
- HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
- Map<String, String> queryParamMap = parseQueryString(request.getQueryString());
- String uid = queryParamMap.get(MultipartRequest.UPLOAD_FILES_ID);
- if (uid != null && isMultipartRequest(request)) {
- if (maxRequestSize != 0 && externalContext.getRequestContentLength() > maxRequestSize) {
- boolean sendError = Boolean.parseBoolean(queryParamMap.get(MultipartRequest.SEND_HTTP_ERROR));
- if (sendError) {
- printResponse(facesContext, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, null);
- } else {
- printResponse(facesContext, HttpServletResponse.SC_OK,
- "<html id=\"_richfaces_file_upload_size_restricted\"></html>");
- }
- } else if (!checkFileCount(externalContext, queryParamMap.get("id"))) {
- printResponse(facesContext, HttpServletResponse.SC_OK,
- "<html id=\"_richfaces_file_upload_forbidden\"></html>");
- } else {
- MultipartRequest multipartRequest = new MultipartRequest(request, createTempFiles,
- tempFilesDirectory, maxRequestSize, uid);
- try {
- multipartRequest.parseRequest();
- if (!multipartRequest.isDone()) {
- printResponse(facesContext, HttpServletResponse.SC_OK,
- "<html id=\"_richfaces_file_upload_stopped\"></html>");
- } else {
- externalContext.getRequestMap().put(MultipartRequest.UPLOAD_FILES_ID, multipartRequest);
- externalContext.setRequest(multipartRequest);
- }
- } catch (FileUploadException e) {
- printResponse(facesContext, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null);
- throw e; //TODO remove it
- } finally {
- multipartRequest.clearRequestData();
- }
- }
- }
+ if (PhaseId.RESTORE_VIEW.equals(event.getPhaseId())) {
+ FacesContext facesContext = event.getFacesContext();
+ ExternalContext externalContext = facesContext.getExternalContext();
+ HttpServletRequest request = (HttpServletRequest) externalContext
+ .getRequest();
+ Map<String, String> queryParamMap = parseQueryString(request
+ .getQueryString());
+ String uid = queryParamMap.get(UID);
+ if (uid != null) {
+ if (maxRequestSize != 0
+ && externalContext.getRequestContentLength() > maxRequestSize) {
+ boolean sendError = Boolean.parseBoolean(queryParamMap
+ .get(MultipartRequest.SEND_HTTP_ERROR));
+ if (sendError) {
+ printResponse(
+ facesContext,
+ HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE,
+ null);
+ } else {
+ printResponse(facesContext, HttpServletResponse.SC_OK,
+ "<html id=\"" + UID + uid + ":size_restricted\"/>");
+ }
+ } else if (!checkFileCount(externalContext,
+ queryParamMap.get("id"))) {
+ printResponse(facesContext, HttpServletResponse.SC_OK,
+ "<html id=\"" + UID + uid + ":forbidden\"/>");
+ } else {
+ MultipartRequest multipartRequest = new MultipartRequest(
+ request, createTempFiles, tempFilesDirectory,
+ maxRequestSize, uid);
+ try {
+ multipartRequest.parseRequest();
+ if (!multipartRequest.isDone()) {
+ printResponse(facesContext,
+ HttpServletResponse.SC_OK,
+ "<html id=\"" + UID + uid + ":stopped\"/>");
+ } else {
+ externalContext.setRequest(multipartRequest);
+ }
+ } catch (FileUploadException e) {
+ printResponse(facesContext,
+ HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ null);
+ throw e; //TODO remove it
+ } finally {
+ multipartRequest.clearRequestData();
+ }
+ }
+ }
+ }
}
private boolean checkFileCount(ExternalContext externalContext, String idParameter) {
@@ -187,23 +207,6 @@
}
}
- private boolean isMultipartRequest(HttpServletRequest request) {
- if (!"post".equals(request.getMethod().toLowerCase())) {
- return false;
- }
-
- String contentType = request.getContentType();
- if (contentType == null) {
- return false;
- }
-
- if (contentType.toLowerCase().startsWith(MULTIPART)) {
- return true;
- }
-
- return false;
- }
-
private void printResponse(FacesContext facesContext, int statusCode, String message) {
facesContext.responseComplete();
ExternalContext externalContext = facesContext.getExternalContext();
@@ -226,7 +229,7 @@
* @see javax.faces.event.PhaseListener#getPhaseId()
*/
public PhaseId getPhaseId() {
- return PhaseId.RESTORE_VIEW;
+ return PhaseId.ANY_PHASE;
}
}
Modified: sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java
===================================================================
--- sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java 2010-11-19 02:34:15 UTC (rev 20110)
+++ sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java 2010-11-19 02:36:39 UTC (rev 20111)
@@ -51,10 +51,9 @@
@Override
public void decode(FacesContext context) {
super.decode(context);
- MultipartRequest request = (MultipartRequest) context.getExternalContext().getRequestMap()
- .get(MultipartRequest.UPLOAD_FILES_ID);
- if (request != null) {
- queueEvent(new UploadEvent(this, request.getUploadItems()));
+ Object request = context.getExternalContext().getRequest();
+ if (request instanceof MultipartRequest) {
+ queueEvent(new UploadEvent(this, ((MultipartRequest)request).getUploadItems()));
}
}
Modified: sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/request/MultipartRequest.java
===================================================================
--- sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/request/MultipartRequest.java 2010-11-19 02:34:15 UTC (rev 20110)
+++ sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/request/MultipartRequest.java 2010-11-19 02:36:39 UTC (rev 20111)
@@ -56,9 +56,6 @@
*/
public static final String SEND_HTTP_ERROR = "_richfaces_send_http_error";
- /** Request parameter that indicates if multipart request forced by rich file upload component */
- public static final String UPLOAD_FILES_ID = "_richfaces_upload_uid";
-
public static final String TEXT_HTML = "text/html";
private static final BytesHandler NOOP_HANDLER = new BytesHandler() {
@@ -720,7 +717,7 @@
return "application/x-www-form-urlencoded";
}
- protected String getUploadId() {
+ public String getUploadId() {
return uid;
}
14 years, 1 month
JBoss Rich Faces SVN: r20110 - in sandbox/trunk/examples/fileupload-demo/src/main: webapp and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2010-11-18 21:34:15 -0500 (Thu, 18 Nov 2010)
New Revision: 20110
Added:
sandbox/trunk/examples/fileupload-demo/src/main/java/org/richfaces/demo/SkinBean.java
Modified:
sandbox/trunk/examples/fileupload-demo/src/main/webapp/fileupload.xhtml
Log:
RF-9501
Added: sandbox/trunk/examples/fileupload-demo/src/main/java/org/richfaces/demo/SkinBean.java
===================================================================
--- sandbox/trunk/examples/fileupload-demo/src/main/java/org/richfaces/demo/SkinBean.java (rev 0)
+++ sandbox/trunk/examples/fileupload-demo/src/main/java/org/richfaces/demo/SkinBean.java 2010-11-19 02:34:15 UTC (rev 20110)
@@ -0,0 +1,29 @@
+package org.richfaces.demo;
+
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+
+@ManagedBean(name = "skinBean")
+@SessionScoped
+public class SkinBean {
+
+ private static final String[] SKINS = {"blueSky", "deepMarine", "emeraldTown", "NULL", "ruby", "classic",
+ "DEFAULT", "japanCherry", "plain", "wine" };
+
+ private String skin = "blueSky";
+
+ public SkinBean() {
+ skin = "blueSky";
+ }
+ public String getSkin() {
+ return skin;
+ }
+
+ public void setSkin(String skin) {
+ this.skin = skin;
+ }
+
+ public String[] getSkins() {
+ return SKINS;
+ }
+}
Modified: sandbox/trunk/examples/fileupload-demo/src/main/webapp/fileupload.xhtml
===================================================================
--- sandbox/trunk/examples/fileupload-demo/src/main/webapp/fileupload.xhtml 2010-11-19 00:24:09 UTC (rev 20109)
+++ sandbox/trunk/examples/fileupload-demo/src/main/webapp/fileupload.xhtml 2010-11-19 02:34:15 UTC (rev 20110)
@@ -33,18 +33,12 @@
<title>Richfaces FileUpload Demo</title>
</h:head>
<h:body>
- <h:form id="form" enctype="multipart/form-data">
- <script type="text/javascript">
- <!--
- var myForm = document.getElementById("form");
- myForm.action = myForm.action + "?_richfaces_upload_uid=1";
- //-->
- </script>
- <!--h:outputText value="Skin: "/>
+ <h:form id="form">
+ <h:outputText value="Skin: "/>
<h:selectOneMenu value="#{skinBean.skin}" onchange="submit();">
<f:selectItems value="#{skinBean.skins}"/>
</h:selectOneMenu>
- <br /-->
+ <br />
<fu:fileUpload fileUploadListener="#{fileUploadBean.listener}"/>
<h:outputText value="File name:" />
<h:outputText value="#{fileUploadBean.item.fileName}" />
14 years, 1 month
JBoss Rich Faces SVN: r20109 - in branches/RF-8742-1: core/impl/src/main/java/org/richfaces/resource and 7 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-11-18 19:24:09 -0500 (Thu, 18 Nov 2010)
New Revision: 20109
Removed:
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryResource.java
Modified:
branches/RF-8742-1/core/api/src/main/java/org/richfaces/resource/ResourceKey.java
branches/RF-8742-1/core/api/src/main/java/org/richfaces/resource/ResourceLibrary.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/resource/StaticResourceLibrary.java
branches/RF-8742-1/core/impl/src/test/java/org/richfaces/resource/DynamicResourceLibrary.java
branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/resource/AjaxResourceLibrary.java
branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/LibraryFunctionImplementation.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/NullConverterScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptRenderer.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
Log:
CODING IN PROGRESS - issue RF-9799: CSV code review
https://jira.jboss.org/browse/RF-9799
Modified: branches/RF-8742-1/core/api/src/main/java/org/richfaces/resource/ResourceKey.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/richfaces/resource/ResourceKey.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/core/api/src/main/java/org/richfaces/resource/ResourceKey.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -28,21 +28,18 @@
* @author Nick Belaevski
*
*/
-public class ResourceKey {
+public final class ResourceKey {
public static final Function<String, ResourceKey> FACTORY = new Function<String, ResourceKey>() {
public ResourceKey apply(String from) {
- return new ResourceKey(from);
+ return create(from);
};
};
- private String resourceName;
+ private final String resourceName;
- private String libraryName;
+ private final String libraryName;
- public ResourceKey(String resourceQualifier) {
- this(extractResourceName(resourceQualifier), extractLibraryName(resourceQualifier));
- }
public ResourceKey(String resourceName, String libraryName) {
super();
@@ -50,6 +47,14 @@
this.libraryName = libraryName;
}
+ public static ResourceKey create(String resourceQualifier){
+ return new ResourceKey(extractResourceName(resourceQualifier), extractLibraryName(resourceQualifier));
+ }
+
+ public static ResourceKey create(String resourceName, String libraryName){
+ return new ResourceKey(resourceName,libraryName);
+ }
+
private static String extractResourceName(String resourceQualifier) {
int idx = resourceQualifier.lastIndexOf(':');
if (idx < 0) {
@@ -76,14 +81,7 @@
return libraryName;
}
- public void setResourceName(String resourceName) {
- this.resourceName = resourceName;
- }
- public void setLibraryName(String libraryName) {
- this.libraryName = libraryName;
- }
-
@Override
public int hashCode() {
final int prime = 31;
Modified: branches/RF-8742-1/core/api/src/main/java/org/richfaces/resource/ResourceLibrary.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/richfaces/resource/ResourceLibrary.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/core/api/src/main/java/org/richfaces/resource/ResourceLibrary.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -29,6 +29,6 @@
*/
public interface ResourceLibrary {
- public ResourceKey[] getResources(FacesContext context);
+ public Iterable<ResourceKey> getResources(FacesContext context);
}
Modified: branches/RF-8742-1/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java
===================================================================
--- branches/RF-8742-1/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/core/impl/src/main/java/org/richfaces/resource/ResourceFactoryImpl.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -114,7 +114,7 @@
}
return new ExternalStaticResourceFactory(
- new ResourceKey(resourceQualifier), resourceLocation, skinDependent);
+ ResourceKey.create(resourceQualifier), resourceLocation, skinDependent);
}
};
@@ -125,7 +125,7 @@
Map<String, String> params = Util.parseResourceParameters(resourceLocation);
String resourceQualifier = extractParametersFromResourceName(resourceLocation);
- return new MappedResourceData(new ResourceKey(resourceQualifier), params);
+ return new MappedResourceData(ResourceKey.create(resourceQualifier), params);
}
};
@@ -179,7 +179,7 @@
Map<ResourceKey, V> result = Maps.newHashMap();
for (Entry<String, String> entry : PropertiesUtil.loadProperties(mappingFileName).entrySet()) {
- result.put(new ResourceKey(entry.getKey()), producer.apply(entry));
+ result.put(ResourceKey.create(entry.getKey()), producer.apply(entry));
}
result = Collections.unmodifiableMap(result);
Modified: branches/RF-8742-1/core/impl/src/main/java/org/richfaces/resource/StaticResourceLibrary.java
===================================================================
--- branches/RF-8742-1/core/impl/src/main/java/org/richfaces/resource/StaticResourceLibrary.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/core/impl/src/main/java/org/richfaces/resource/StaticResourceLibrary.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -23,20 +23,22 @@
import javax.faces.context.FacesContext;
+import com.google.common.collect.ImmutableList;
+
/**
* @author Nick Belaevski
*
*/
class StaticResourceLibrary implements ResourceLibrary {
- private ResourceKey[] keys;
+ private final ImmutableList<ResourceKey> keys;
public StaticResourceLibrary(ResourceKey[] keys) {
super();
- this.keys = keys;
+ this.keys = ImmutableList.copyOf(keys);
}
- public ResourceKey[] getResources(FacesContext context) {
+ public Iterable<ResourceKey> getResources(FacesContext context) {
return keys;
}
Modified: branches/RF-8742-1/core/impl/src/test/java/org/richfaces/resource/DynamicResourceLibrary.java
===================================================================
--- branches/RF-8742-1/core/impl/src/test/java/org/richfaces/resource/DynamicResourceLibrary.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/core/impl/src/test/java/org/richfaces/resource/DynamicResourceLibrary.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -23,17 +23,17 @@
import javax.faces.context.FacesContext;
+import com.google.common.collect.ImmutableList;
+
/**
* @author Nick Belaevski
*
*/
public class DynamicResourceLibrary implements ResourceLibrary {
- private ResourceKey[] keys = new ResourceKey[] {
- new ResourceKey("skinning_classes.ecss"), new ResourceKey("jquery.js", null)
- };
+ private ImmutableList<ResourceKey> keys = ImmutableList.of(ResourceKey.create("skinning_classes.ecss"), ResourceKey.create("jquery.js", null));
- public ResourceKey[] getResources(FacesContext context) {
+ public Iterable<ResourceKey> getResources(FacesContext context) {
return keys;
}
Modified: branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/resource/AjaxResourceLibrary.java
===================================================================
--- branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/resource/AjaxResourceLibrary.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/resource/AjaxResourceLibrary.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -27,6 +27,7 @@
import org.richfaces.application.CommonComponentsConfiguration;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ObjectArrays;
/**
@@ -35,18 +36,18 @@
*/
public class AjaxResourceLibrary implements ResourceLibrary {
- private ResourceKey[] ajaxResourceKeys = new ResourceKey[] {
- new ResourceKey("jsf.js", "javax.faces"), new ResourceKey("jquery.js", null), new ResourceKey("richfaces.js", null)
- };
+ private static final ImmutableList<ResourceKey> AJAX_ONLY_KEYS = ImmutableList.of(
+ ResourceKey.create("jsf.js", "javax.faces"), ResourceKey.create("jquery.js", null), ResourceKey.create("richfaces.js", null)
+ );
- private ResourceKey[] ajaxQueueResourceKeys = ObjectArrays.concat(ajaxResourceKeys, new ResourceKey("richfaces-queue.js", null));
+ private static final ImmutableList<ResourceKey> AJAX_WITH_QUEUE_KEYS = ImmutableList.<ResourceKey>builder().addAll(AJAX_ONLY_KEYS).add(ResourceKey.create("richfaces-queue.js", null)).build();
- public ResourceKey[] getResources(FacesContext context) {
+ public Iterable<ResourceKey> getResources(FacesContext context) {
if (getBooleanConfigurationValue(context, CommonComponentsConfiguration.Items.queueEnabled)) {
- return ajaxQueueResourceKeys;
+ return AJAX_WITH_QUEUE_KEYS;
}
- return ajaxResourceKeys;
+ return AJAX_ONLY_KEYS;
}
}
Deleted: branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryResource.java
===================================================================
--- branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryResource.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryResource.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -1,103 +0,0 @@
-package org.richfaces.javascript;
-
-import java.util.LinkedHashSet;
-
-
-import com.google.common.collect.Sets;
-
-/**
- * This class represent information about external JavaScript library as JSF resource
- *
- * @author asmirnov
- *
- */
-public class LibraryResource {
-
- private final String library;
-
- private final String resourceName;
-
- /**
- * @param library
- * @param resourceName
- */
- public LibraryResource(String library, String resourceName) {
- this.library = library;
- this.resourceName = resourceName;
- }
-
- /**
- * @return the library
- */
- public String getLibrary() {
- return library;
- }
-
- /**
- * @return the resourceName
- */
- public String getResourceName() {
- return resourceName;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((library == null) ? 0 : library.hashCode());
- result = prime * result + ((resourceName == null) ? 0 : resourceName.hashCode());
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- LibraryResource other = (LibraryResource) obj;
- if (library == null) {
- if (other.library != null) {
- return false;
- }
- } else if (!library.equals(other.library)) {
- return false;
- }
- if (resourceName == null) {
- if (other.resourceName != null) {
- return false;
- }
- } else if (!resourceName.equals(other.resourceName)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return getLibrary()+':'+getResourceName();
- }
-
- public static Iterable<LibraryResource> of(Iterable<LibraryScriptString> scripts){
- LinkedHashSet<LibraryResource> resources = Sets.newLinkedHashSet();
- for (LibraryScriptString scriptString : scripts) {
- resources.add(scriptString.getResource());
- }
- return resources;
- }
-}
\ No newline at end of file
Modified: branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryScript.java
===================================================================
--- branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryScript.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/validator/api/src/main/java/org/richfaces/javascript/LibraryScript.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -23,6 +23,8 @@
package org.richfaces.javascript;
+import org.richfaces.resource.ResourceKey;
+
/**
* <p class="changed_added_4_0">
* This class contains information about JavaScript associated with JSF object ( converter or validator )
@@ -33,6 +35,6 @@
*/
public interface LibraryScript {
- LibraryResource getResource();
+ ResourceKey getResource();
}
Modified: branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/LibraryFunctionImplementation.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/LibraryFunctionImplementation.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/javascript/LibraryFunctionImplementation.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -1,21 +1,23 @@
package org.richfaces.javascript;
+import org.richfaces.resource.ResourceKey;
+
final class LibraryFunctionImplementation implements LibraryFunction {
- private final LibraryResource library;
+ private final ResourceKey library;
private final String functionName;
- LibraryFunctionImplementation(LibraryResource library, String functionName) {
+ LibraryFunctionImplementation(ResourceKey library, String functionName) {
this.library = library;
this.functionName = functionName;
}
LibraryFunctionImplementation(String library, String resource, String functionName) {
- this.library = new LibraryResource(library, resource);
+ this.library = new ResourceKey(library, resource);
this.functionName = functionName;
}
- public LibraryResource getResource() {
+ public ResourceKey getResource() {
return library;
}
Modified: branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/AjaxOnlyScript.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -1,9 +1,8 @@
package org.richfaces.renderkit.html;
-import java.util.Collection;
import java.util.Collections;
-import org.richfaces.javascript.LibraryResource;
+import org.richfaces.resource.ResourceKey;
public class AjaxOnlyScript extends ValidatorScriptBase {
@@ -16,7 +15,7 @@
}
- public Collection<LibraryResource> getResources() {
+ public Iterable<ResourceKey> getResources() {
return Collections.emptySet();
}
Modified: branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -3,8 +3,8 @@
import java.util.Collection;
import java.util.LinkedHashSet;
-import org.richfaces.javascript.LibraryResource;
import org.richfaces.javascript.LibraryScriptString;
+import org.richfaces.resource.ResourceKey;
import com.google.common.collect.Sets;
@@ -25,8 +25,9 @@
}
- public Collection<LibraryResource> getResources() {
- LinkedHashSet<LibraryResource> resources = Sets.newLinkedHashSet();
+ public Iterable<ResourceKey> getResources() {
+ // TODO - make immutable.
+ LinkedHashSet<ResourceKey> resources = Sets.newLinkedHashSet();
resources.add(converter.getResource());
for (LibraryScriptString scriptString : validators) {
resources.add(scriptString.getResource());
Modified: branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -1,15 +1,13 @@
package org.richfaces.renderkit.html;
-import java.util.Collection;
-
import org.ajax4jsf.javascript.ScriptString;
-import org.richfaces.javascript.LibraryResource;
+import org.richfaces.resource.ResourceKey;
public interface ComponentValidatorScript extends ScriptString {
String getName();
- Collection<LibraryResource> getResources();
+ Iterable<ResourceKey> getResources();
/**
* <p class="changed_added_4_0">Creates JavasCript that calls validator function.</p>
Modified: branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/LibraryScriptFunction.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -25,8 +25,8 @@
import org.ajax4jsf.javascript.JSFunction;
import org.richfaces.javascript.LibraryFunction;
-import org.richfaces.javascript.LibraryResource;
import org.richfaces.javascript.LibraryScriptString;
+import org.richfaces.resource.ResourceKey;
/**
* <p class="changed_added_4_0">
@@ -38,13 +38,13 @@
*/
public class LibraryScriptFunction extends JSFunction implements LibraryScriptString {
- private final LibraryResource resource;
- private String name;
+ private final ResourceKey resource;
+ private final String name;
public LibraryScriptFunction(LibraryFunction libraryScript, Object... parameters) {
super(libraryScript.getName(), parameters);
this.resource = libraryScript.getResource();
- name = libraryScript.getName();
+ this.name = libraryScript.getName();
}
public String getName() {
@@ -56,7 +56,7 @@
*
* @see org.richfaces.renderkit.html.LibraryScriptString#getResource()
*/
- public LibraryResource getResource() {
+ public ResourceKey getResource() {
return resource;
}
Modified: branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/NullConverterScript.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/NullConverterScript.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/NullConverterScript.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -4,8 +4,8 @@
package org.richfaces.renderkit.html;
import org.ajax4jsf.javascript.JSLiteral;
-import org.richfaces.javascript.LibraryResource;
import org.richfaces.javascript.LibraryScriptString;
+import org.richfaces.resource.ResourceKey;
/**
* This class represents "dummy" converter call ( just refference to "value" variable )
@@ -30,7 +30,7 @@
*
* @see org.richfaces.renderkit.html.LibraryScriptString#getResource()
*/
- public LibraryResource getResource() {
+ public ResourceKey getResource() {
return null;
}
Modified: branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptRenderer.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptRenderer.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptRenderer.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -16,8 +16,9 @@
import javax.faces.render.Renderer;
import org.richfaces.component.UIValidatorScript;
-import org.richfaces.javascript.LibraryResource;
+import org.richfaces.resource.ResourceKey;
+import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
@@ -38,12 +39,12 @@
Collection<ComponentValidatorScript> scripts = validatorScript.getScripts();
// flatten all dependent resources.
- LinkedHashSet<LibraryResource> resources = Sets.newLinkedHashSet();
+ LinkedHashSet<ResourceKey> resources = Sets.newLinkedHashSet();
for (ComponentValidatorScript script : scripts) {
- resources.addAll(script.getResources());
+ Iterables.addAll(resources, script.getResources());
}
// render dependencies
- for (LibraryResource resource : resources) {
+ for (ResourceKey resource : resources) {
encodeResource(context, resource);
}
ResponseWriter responseWriter = context.getResponseWriter();
@@ -56,9 +57,9 @@
responseWriter.endElement(SCRIPT);
}
- private void encodeResource(FacesContext context, LibraryResource resource) throws IOException {
+ private void encodeResource(FacesContext context, ResourceKey resource) throws IOException {
ResourceHandler resourceHandler = context.getApplication().getResourceHandler();
- Resource jsfResource = resourceHandler.createResource(resource.getResourceName(), resource.getLibrary());
+ Resource jsfResource = resourceHandler.createResource(resource.getResourceName(), resource.getLibraryName());
if (null != jsfResource) {
ResponseWriter responseWriter = context.getResponseWriter();
responseWriter.startElement(SCRIPT, null);
Modified: branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -2,10 +2,9 @@
import java.io.IOException;
-import org.richfaces.validator.LibraryResource;
-import org.richfaces.validator.LibraryScriptString;
+import org.richfaces.resource.ResourceKey;
-final class Script implements LibraryScriptString {
+final class Script implements org.richfaces.javascript.LibraryScriptString {
private final String name;
Script(String name) {
@@ -28,7 +27,7 @@
}
}
- public LibraryResource getResource() {
+ public ResourceKey getResource() {
return UIValidatorScriptCollectionTest.FOO_RESOURCE;
}
Modified: branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2010-11-18 23:14:43 UTC (rev 20108)
+++ branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2010-11-19 00:24:09 UTC (rev 20109)
@@ -31,6 +31,7 @@
import org.richfaces.javascript.LibraryResource;
import org.richfaces.javascript.LibraryScriptString;
import org.richfaces.javascript.ScriptNotFoundException;
+import org.richfaces.resource.ResourceKey;
import org.richfaces.validator.ConverterDescriptor;
import org.richfaces.validator.FacesObjectDescriptor;
import org.richfaces.validator.ValidatorDescriptor;
@@ -219,7 +220,7 @@
return name;
}
- public LibraryResource getResource() {
+ public ResourceKey getResource() {
return CLIENT_VALIDATOR_LIBRARY;
}
};
14 years, 1 month
JBoss Rich Faces SVN: r20108 - in branches/RF-8742-1: cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model and 42 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2010-11-18 18:14:43 -0500 (Thu, 18 Nov 2010)
New Revision: 20108
Added:
branches/RF-8742-1/.gitignore
branches/RF-8742-1/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java
branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarDataModelImpl.java
branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarDataModelItemImpl.java
branches/RF-8742-1/examples/iteration-demo/src/main/java/org/richfaces/demo/LazyTreeNode.java
branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/
branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/leaf.png
branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/minus.png
branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/plus.png
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java
branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java
branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java
branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java
branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java
branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java
branches/RF-8742-1/ui/iteration/ui/src/main/config/
branches/RF-8742-1/ui/iteration/ui/src/main/config/faces-config.xml
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeSelectionChangeListener.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeToggleListener.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeState.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java
branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/component/UIPanel.java
Removed:
branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/StringBuilderWriter.java
branches/RF-8742-1/core/api/src/test/java/org/ajax4jsf/javascript/StringBuilderWriterTest.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/util/ViewUtil.java
branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/leaf.png
branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/minus.png
branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/plus.png
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java
branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionEvent.java
branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionListener.java
branches/RF-8742-1/ui/iteration/ui/src/main/config/faces-config.xml
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java
branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/component/UIPanel.java
Modified:
branches/RF-8742-1/
branches/RF-8742-1/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/EventBean.java
branches/RF-8742-1/cdk/generator/src/main/resources/META-INF/templates/listenerTagHandler.ftl
branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSBind.java
branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSFunction.java
branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java
branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java
branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSObject.java
branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSReference.java
branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptString.java
branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptStringBase.java
branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java
branches/RF-8742-1/core/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/application/push/impl/AbstractRequest.java
branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/ScriptOptions.java
branches/RF-8742-1/core/impl/src/main/resources/META-INF/resources/jquery.position.js
branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarBean.java
branches/RF-8742-1/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml
branches/RF-8742-1/examples/input-demo/src/main/webapp/examples/calendar.xhtml
branches/RF-8742-1/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java
branches/RF-8742-1/examples/iteration-demo/src/main/webapp/WEB-INF/web.xml
branches/RF-8742-1/examples/iteration-demo/src/main/webapp/tree.xhtml
branches/RF-8742-1/examples/output-demo/src/main/webapp/examples/tooltip.xhtml
branches/RF-8742-1/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/TreeBean.java
branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxEventOptions.java
branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
branches/RF-8742-1/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java
branches/RF-8742-1/ui/core/ui/src/main/java/org/richfaces/renderkit/AjaxFunctionRendererBase.java
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java
branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.ecss
branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.js
branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js
branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleListener.java
branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/ExtendedTreeDataModelImpl.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java
branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
branches/RF-8742-1/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.ecss
branches/RF-8742-1/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
branches/RF-8742-1/ui/iteration/ui/src/main/templates/tree.template.xml
branches/RF-8742-1/ui/iteration/ui/src/main/templates/treeNode.template.xml
branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Bean.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java
Log:
Merged revisions 20079-20080,20083-20084,20088-20107 via svnmerge from
https://svn.jboss.org/repos/richfaces/trunk
.......
r20079 | amarkhel | 2010-11-17 08:53:40 -0800 (Wed, 17 Nov 2010) | 1 line
RF-9683 Calendar component: data model support, RF-9684 Calendar component: AJAX scrolling
.......
r20080 | amarkhel | 2010-11-17 08:58:18 -0800 (Wed, 17 Nov 2010) | 1 line
RF-9683 Calendar component: data model support, RF-9684 Calendar component: AJAX scrolling. Demo is updated.
.......
r20083 | pyaschenko | 2010-11-18 00:29:52 -0800 (Thu, 18 Nov 2010) | 2 lines
https://jira.jboss.org/browse/RF-9650
https://jira.jboss.org/browse/RF-9644
.......
r20084 | pyaschenko | 2010-11-18 00:34:56 -0800 (Thu, 18 Nov 2010) | 2 lines
http://jira.jboss.com/jira/browse/RF-9672
.......
r20088 | nbelaevski | 2010-11-18 08:02:06 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9715
.......
r20089 | nbelaevski | 2010-11-18 08:03:02 -0800 (Thu, 18 Nov 2010) | 1 line
added
.......
r20090 | nbelaevski | 2010-11-18 08:05:30 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9715
.......
r20091 | nbelaevski | 2010-11-18 08:10:17 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9715
.......
r20092 | nbelaevski | 2010-11-18 08:15:48 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9716
.......
r20093 | nbelaevski | 2010-11-18 08:17:55 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9715
.......
r20094 | nbelaevski | 2010-11-18 08:20:00 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9715
.......
r20095 | nbelaevski | 2010-11-18 08:21:47 -0800 (Thu, 18 Nov 2010) | 1 line
Checkstyle error fixed
.......
r20096 | nbelaevski | 2010-11-18 08:24:23 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9715
.......
r20097 | nbelaevski | 2010-11-18 08:26:56 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9715
.......
r20098 | nbelaevski | 2010-11-18 08:28:44 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9716
.......
r20099 | nbelaevski | 2010-11-18 08:31:41 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9715
.......
r20100 | nbelaevski | 2010-11-18 08:33:28 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9715
.......
r20101 | nbelaevski | 2010-11-18 08:35:18 -0800 (Thu, 18 Nov 2010) | 1 line
Checkstyle error fixed
.......
r20102 | nbelaevski | 2010-11-18 08:37:36 -0800 (Thu, 18 Nov 2010) | 1 line
RF-9714
.......
r20103 | nbelaevski | 2010-11-18 08:54:07 -0800 (Thu, 18 Nov 2010) | 1 line
RF-9714
.......
r20104 | nbelaevski | 2010-11-18 08:56:05 -0800 (Thu, 18 Nov 2010) | 1 line
svn rebase...
.......
r20105 | nbelaevski | 2010-11-18 09:01:46 -0800 (Thu, 18 Nov 2010) | 1 line
https://jira.jboss.org/browse/RF-9714
.......
r20106 | nbelaevski | 2010-11-18 09:10:13 -0800 (Thu, 18 Nov 2010) | 2 lines
https://jira.jboss.org/browse/RF-9714
https://jira.jboss.org/browse/RF-9717
.......
r20107 | nbelaevski | 2010-11-18 10:50:06 -0800 (Thu, 18 Nov 2010) | 1 line
Rest of tree work merged manually from GIT
.......
Property changes on: branches/RF-8742-1
___________________________________________________________________
Name: svnmerge-integrated
- /trunk:1-20077
+ /trunk:1-20107
Copied: branches/RF-8742-1/.gitignore (from rev 20107, trunk/.gitignore)
===================================================================
--- branches/RF-8742-1/.gitignore (rev 0)
+++ branches/RF-8742-1/.gitignore 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,8 @@
+target
+.settings
+.project
+.classpath
+.clover
+.externalToolBuilders
+
+
Modified: branches/RF-8742-1/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/EventBean.java
===================================================================
--- branches/RF-8742-1/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/EventBean.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/EventBean.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -48,6 +48,7 @@
private ClassName sourceInterface;
private ClassName type;
private List<TagModel> tags = Lists.newArrayList();
+ private String listenerMethod;
/**
* <p class="changed_added_4_0"></p>
@@ -165,4 +166,19 @@
public void setTags(List<TagModel> tags) {
this.tags = tags;
}
+
+ /**
+ * @return the listenerMethod
+ */
+ @XmlElement(name = "listener-method", namespace = ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
+ public String getListenerMethod() {
+ return listenerMethod;
+ }
+
+ /**
+ * @param listenerMethod the listenerMethod to set
+ */
+ public void setListenerMethod(String listenerMethod) {
+ this.listenerMethod = listenerMethod;
+ }
}
Modified: branches/RF-8742-1/cdk/generator/src/main/resources/META-INF/templates/listenerTagHandler.ftl
===================================================================
--- branches/RF-8742-1/cdk/generator/src/main/resources/META-INF/templates/listenerTagHandler.ftl 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/cdk/generator/src/main/resources/META-INF/templates/listenerTagHandler.ftl 2010-11-18 23:14:43 UTC (rev 20108)
@@ -98,7 +98,7 @@
private TagAttribute listenerMethod;
- public TestListenerHandler(TagConfig config) {
+ public ${tag.targetClass.simpleName}(TagConfig config) {
super(config);
this.binding = this.getAttribute("binding");
Modified: branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSBind.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSBind.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSBind.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -23,6 +23,8 @@
package org.ajax4jsf.javascript;
+import java.io.IOException;
+
/**
* Created 04.08.2008
* @author Nick Belaevski
@@ -38,9 +40,9 @@
this.vars = vars;
}
- public void appendScript(StringBuffer functionString) {
- functionString.append("function () {");
- functionString.append("var vars = {");
+ public void appendScript(Appendable target) throws IOException {
+ target.append("function () {");
+ target.append("var vars = {");
boolean isFirst = true;
@@ -48,17 +50,18 @@
if (isFirst) {
isFirst = false;
} else {
- functionString.append(',');
+ target.append(',');
}
- functionString.append(var);
- functionString.append(':');
- functionString.append(var);
+ target.append(var);
+ target.append(':');
+ target.append(var);
}
- functionString.append("};");
- functionString.append("return function() { with (vars) {");
- functionString.append(function.toScript());
- functionString.append("}}}()");
+ target.append("};");
+ target.append("return function() { with (vars) {");
+ target.append(function.toScript());
+ target.append("}}}()");
}
+
}
Modified: branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSFunction.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSFunction.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSFunction.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -23,6 +23,7 @@
package org.ajax4jsf.javascript;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -52,8 +53,8 @@
return this;
}
- public void appendScript(StringBuffer functionString) {
- functionString.append(name).append('(');
+ public void appendScript(Appendable target) throws IOException {
+ target.append(name).append('(');
boolean first = true;
List<?> parameters = getParameters();
@@ -63,26 +64,27 @@
Object element = param.next();
if (!first) {
- functionString.append(',');
+ target.append(',');
}
if (null != element) {
- functionString.append(ScriptUtils.toScript(element));
+ ScriptUtils.appendScript(target, element);
} else {
- functionString.append("null");
+ target.append("null");
}
first = false;
}
}
- functionString.append(")");
+ target.append(")");
}
-
+
/**
* @return the parameters
*/
public List<Object> getParameters() {
return this.parameters;
}
+
}
Modified: branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSFunctionDefinition.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -23,6 +23,7 @@
package org.ajax4jsf.javascript;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -56,18 +57,14 @@
return this;
}
- /*
- * (non-Javadoc)
- * @see org.ajax4jsf.components.renderkit.scriptutils.ScriptString#appendScript(java.lang.StringBuffer)
- */
- public void appendScript(StringBuffer functionString) {
- functionString.append("function");
+ public void appendScript(Appendable target) throws IOException {
+ target.append("function");
if (null != name) {
- functionString.append(" ").append(name);
+ target.append(" ").append(name);
}
- functionString.append("(");
+ target.append("(");
boolean first = true;
@@ -75,16 +72,16 @@
Object element = param.next();
if (!first) {
- functionString.append(',');
+ target.append(',');
}
- functionString.append(element.toString());
+ target.append(element.toString());
first = false;
}
- functionString.append("){").append(body).append("}");
+ target.append("){").append(body).append("}");
}
-
+
/**
* @return the name
*/
@@ -98,4 +95,5 @@
public void setName(String name) {
this.name = name;
}
+
}
Modified: branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSLiteral.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -23,6 +23,7 @@
package org.ajax4jsf.javascript;
+import java.io.IOException;
import java.io.Serializable;
/**
@@ -53,14 +54,10 @@
this.literal = literal;
}
- /*
- * (non-Javadoc)
- * @see org.ajax4jsf.javascript.ScriptString#appendScript(java.lang.StringBuffer)
- */
- public void appendScript(StringBuffer jsString) {
- jsString.append(literal);
+ public void appendScript(Appendable target) throws IOException {
+ target.append(literal);
}
-
+
/**
* @return the literal
*/
Modified: branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSObject.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSObject.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSObject.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -23,6 +23,8 @@
package org.ajax4jsf.javascript;
+import java.io.IOException;
+
/**
* @author shura (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:30 $
@@ -40,8 +42,8 @@
// TODO Auto-generated constructor stub
}
- public void appendScript(StringBuffer functionString) {
- functionString.append("new ");
- super.appendScript(functionString);
+ public void appendScript(Appendable target) throws IOException {
+ target.append("new ");
+ super.appendScript(target);
}
}
Modified: branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSReference.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSReference.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/JSReference.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -23,6 +23,8 @@
package org.ajax4jsf.javascript;
+import java.io.IOException;
+
/**
* Create reference to JavaScript variable with optional index.
* @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
@@ -58,15 +60,14 @@
this.index = index;
}
- /*
- * (non-Javadoc)
- * @see org.ajax4jsf.javascript.ScriptString#appendScript(java.lang.StringBuffer)
- */
- public void appendScript(StringBuffer functionString) {
- functionString.append(name);
+ public void appendScript(Appendable target) throws IOException {
+ target.append(name);
if (null != index) {
- functionString.append("[").append(ScriptUtils.toScript(index)).append("]");
+ target.append("[");
+ ScriptUtils.appendScript(target, index);
+ target.append("]");
}
}
+
}
Modified: branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptString.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptString.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptString.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -23,6 +23,9 @@
package org.ajax4jsf.javascript;
+import java.io.IOException;
+
+
/**
* @author shura (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:58:32 $
@@ -37,8 +40,15 @@
public abstract String toScript();
/**
- * Append JavaScript code to @link StringBuffer
- * @param functionString
+ * Append JavaScript code to @link {@link Appendable}
+ * @param target
+ * @throws IOException
*/
- public void appendScript(StringBuffer functionString);
+ public void appendScript(Appendable target) throws IOException;
+
+ /**
+ * Append JavaScript code to @link {@link StringBuilder}
+ * @param stringBuilder
+ */
+ public void appendScriptToStringBuilder(StringBuilder stringBuilder);
}
Modified: branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptStringBase.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptStringBase.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptStringBase.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -23,6 +23,11 @@
package org.ajax4jsf.javascript;
+import java.io.IOException;
+
+import javax.faces.FacesException;
+
+
/**
* @author shura (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1.2.2 $ $Date: 2007/01/26 10:38:52 $
@@ -30,13 +35,24 @@
*/
public abstract class ScriptStringBase implements ScriptString {
public String toScript() {
- StringBuffer functionString = new StringBuffer();
+ StringBuilder builder = new StringBuilder();
- appendScript(functionString);
+ try {
+ appendScript(builder);
+ return builder.toString();
+ } catch (IOException e) {
+ throw new FacesException(e.getMessage(), e);
+ }
+ }
- return functionString.toString();
+ public void appendScriptToStringBuilder(StringBuilder stringBuilder) {
+ try {
+ appendScript(stringBuilder);
+ } catch (IOException e) {
+ //ignore
+ }
}
-
+
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
@@ -44,4 +60,5 @@
public String toString() {
return toScript();
}
+
}
Modified: branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -26,8 +26,8 @@
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import java.io.Writer;
import java.lang.reflect.Array;
+import java.nio.CharBuffer;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collection;
@@ -66,7 +66,7 @@
return cs;
}
- private static void writeScriptToStream(Writer writer, Object obj, Map<Object, Boolean> cycleBusterMap) throws IOException {
+ private static void appendScript(Appendable appendable, Object obj, Map<Object, Boolean> cycleBusterMap) throws IOException {
Boolean cycleBusterValue = cycleBusterMap.put(obj, Boolean.TRUE);
if (cycleBusterValue != null) {
@@ -81,14 +81,14 @@
LOG.debug(formattedMessage);
}
- writer.write("null");
+ appendable.append("null");
} else if (null == obj) {
//TODO nick - skip non-rendered values like Integer.MIN_VALUE
- writer.write("null");
+ appendable.append("null");
} else if (obj instanceof ScriptString) {
- writer.write(((ScriptString) obj).toScript());
+ ((ScriptString) obj).appendScript(appendable);
} else if (obj.getClass().isArray()) {
- writer.write("[");
+ appendable.append("[");
boolean first = true;
@@ -96,20 +96,20 @@
Object element = Array.get(obj, i);
if (!first) {
- writer.write(',');
+ appendable.append(',');
}
- writeScriptToStream(writer, element, cycleBusterMap);
+ appendScript(appendable, element, cycleBusterMap);
first = false;
}
- writer.write("] ");
+ appendable.append("] ");
} else if (obj instanceof Collection<?>) {
// Collections put as JavaScript array.
@SuppressWarnings("unchecked") Collection<Object> collection = (Collection<Object>) obj;
- writer.write("[");
+ appendable.append("[");
boolean first = true;
@@ -117,51 +117,51 @@
Object element = iter.next();
if (!first) {
- writer.write(',');
+ appendable.append(',');
}
- writeScriptToStream(writer, element, cycleBusterMap);
+ appendScript(appendable, element, cycleBusterMap);
first = false;
}
- writer.write("] ");
+ appendable.append("] ");
} else if (obj instanceof Map<?, ?>) {
// Maps put as JavaScript hash.
@SuppressWarnings("unchecked") Map<Object, Object> map = (Map<Object, Object>) obj;
- writer.write("{");
+ appendable.append("{");
boolean first = true;
for (Map.Entry<Object, Object> entry : map.entrySet()) {
if (!first) {
- writer.write(',');
+ appendable.append(',');
}
- writeEncodedString(writer, entry.getKey());
- writer.write(":");
- writeScriptToStream(writer, entry.getValue(), cycleBusterMap);
+ appendEncodedString(appendable, entry.getKey());
+ appendable.append(":");
+ appendScript(appendable, entry.getValue(), cycleBusterMap);
first = false;
}
- writer.write("} ");
+ appendable.append("} ");
} else if (obj instanceof Number || obj instanceof Boolean) {
// numbers and boolean put as-is, without conversion
- writer.write(obj.toString());
+ appendable.append(obj.toString());
} else if (obj instanceof String) {
// all other put as encoded strings.
- writeEncodedString(writer, obj);
+ appendEncodedString(appendable, obj);
} else if (obj instanceof Enum<?>) {
// all other put as encoded strings.
- writeEncodedString(writer, obj);
+ appendEncodedString(appendable, obj);
} else {
// All other objects threaded as Java Beans.
- writer.write("{");
+ appendable.append("{");
PropertyDescriptor[] propertyDescriptors;
@@ -194,16 +194,16 @@
}
if (!first) {
- writer.write(',');
+ appendable.append(',');
}
- writeEncodedString(writer, key);
- writer.write(":");
- writeScriptToStream(writer, propertyValue, cycleBusterMap);
+ appendEncodedString(appendable, key);
+ appendable.append(":");
+ appendScript(appendable, propertyValue, cycleBusterMap);
first = false;
}
- writer.write("} ");
+ appendable.append("} ");
}
if (cycleBusterValue == null) {
@@ -220,7 +220,7 @@
* @throws IOException
*/
public static void writeToStream(final ResponseWriter responseWriter, Object obj) throws IOException {
- writeScriptToStream(new ResponseWriterWrapper(responseWriter), obj, new IdentityHashMap<Object, Boolean>());
+ appendScript(new ResponseWriterWrapper(responseWriter), obj, new IdentityHashMap<Object, Boolean>());
}
/**
@@ -233,7 +233,7 @@
StringBuilder sb = new StringBuilder();
try {
- writeScriptToStream(new StringBuilderWriter(sb), obj, new IdentityHashMap<Object, Boolean>());
+ appendScript(sb, obj, new IdentityHashMap<Object, Boolean>());
} catch (IOException e) {
// ignore
@@ -242,22 +242,17 @@
return sb.toString();
}
- public static void writeEncodedString(Writer w, Object obj) throws IOException {
- w.write("\"");
- writeEncoded(w, obj);
- w.write("\"");
+ public static void appendScript(Appendable appendable, Object obj) throws IOException {
+ appendScript(appendable, obj, new IdentityHashMap<Object, Boolean>());
}
-
- public static void addEncodedString(StringBuilder buff, Object obj) {
- try {
- writeEncodedString(new StringBuilderWriter(buff), obj);
- } catch (IOException e) {
-
- // ignore
- }
+
+ public static void appendEncodedString(Appendable appendable, Object obj) throws IOException {
+ appendable.append("\"");
+ appendEncoded(appendable, obj);
+ appendable.append("\"");
}
- public static void writeEncoded(Writer w, Object obj) throws IOException {
+ public static void appendEncoded(Appendable appendable, Object obj) throws IOException {
JSEncoder encoder = new JSEncoder();
char[] chars = obj.toString().toCharArray();
@@ -265,22 +260,13 @@
char c = chars[i];
if (!encoder.compile(c)) {
- w.write(encoder.encode(c));
+ appendable.append(CharBuffer.wrap(encoder.encode(c)));
} else {
- w.write(c);
+ appendable.append(c);
}
}
}
- public static void addEncoded(StringBuilder buff, Object obj) {
- try {
- writeEncoded(new StringBuilderWriter(buff), obj);
- } catch (IOException e) {
-
- // ignore
- }
- }
-
public static String getValidJavascriptName(String s) {
StringBuffer buf = null;
final int len = s.length();
Deleted: branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/StringBuilderWriter.java
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/StringBuilderWriter.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/main/java/org/ajax4jsf/javascript/StringBuilderWriter.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,88 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-
-package org.ajax4jsf.javascript;
-
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- * @author Nick Belaevski
- * @since 3.3.2
- */
-final class StringBuilderWriter extends Writer {
- private StringBuilder builder;
-
- public StringBuilderWriter(StringBuilder builder) {
- super();
- this.builder = builder;
- }
-
- /**
- * Closing this writer doesn't have any effect
- */
- @Override
- public void close() throws IOException {
-
- // do nothing
- }
-
- /*
- * (non-Javadoc)
- * @see java.io.Writer#flush()
- */
- @Override
- public void flush() throws IOException {
-
- // do nothing
- }
-
- /*
- * (non-Javadoc)
- * @see java.io.Writer#write(char[], int, int)
- */
- @Override
- public void write(char[] cbuf, int off, int len) throws IOException {
- builder.append(cbuf, off, len);
- }
-
- @Override
- public void write(char[] cbuf) throws IOException {
- builder.append(cbuf);
- }
-
- @Override
- public void write(String str) throws IOException {
- builder.append(str);
- }
-
- @Override
- public void write(String str, int off, int len) throws IOException {
- builder.append(str, off, off + len);
- }
-
- @Override
- public void write(int c) throws IOException {
- builder.append((char) c);
- }
-}
Copied: branches/RF-8742-1/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java (from rev 20107, trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
--- branches/RF-8742-1/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java (rev 0)
+++ branches/RF-8742-1/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import javax.faces.component.UIComponent;
+
+import com.google.common.base.Predicate;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class ComponentPredicates {
+
+ private static final Predicate<UIComponent> IS_RENDERED = new Predicate<UIComponent>() {
+ public boolean apply(UIComponent input) {
+ return input.isRendered();
+ };
+ };
+
+ private ComponentPredicates() {}
+
+ public static Predicate<UIComponent> isRendered() {
+ return IS_RENDERED;
+ }
+}
Modified: branches/RF-8742-1/core/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java
===================================================================
--- branches/RF-8742-1/core/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/test/java/org/ajax4jsf/javascript/ScriptUtilsTest.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -246,21 +246,23 @@
/**
* Test method for {@link org.ajax4jsf.javascript.ScriptUtils#addEncodedString(java.lang.StringBuffer, java.lang.Object)}.
+ * @throws Exception
*/
- public void testAddEncodedString() {
+ public void testAddEncodedString() throws Exception {
StringBuilder buff = new StringBuilder();
- ScriptUtils.addEncodedString(buff, "foo");
+ ScriptUtils.appendEncodedString(buff, "foo");
assertEquals("\"foo\"", buff.toString());
}
/**
* Test method for {@link org.ajax4jsf.javascript.ScriptUtils#addEncoded(java.lang.StringBuffer, java.lang.Object)}.
+ * @throws Exception
*/
- public void testAddEncoded() {
+ public void testAddEncoded() throws Exception {
StringBuilder buff = new StringBuilder();
- ScriptUtils.addEncoded(buff, "foo");
+ ScriptUtils.appendEncoded(buff, "foo");
assertEquals("foo", buff.toString());
}
Deleted: branches/RF-8742-1/core/api/src/test/java/org/ajax4jsf/javascript/StringBuilderWriterTest.java
===================================================================
--- branches/RF-8742-1/core/api/src/test/java/org/ajax4jsf/javascript/StringBuilderWriterTest.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/api/src/test/java/org/ajax4jsf/javascript/StringBuilderWriterTest.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,96 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-
-package org.ajax4jsf.javascript;
-
-import java.io.Writer;
-
-import junit.framework.TestCase;
-
-/**
- * @author Nick Belaevski
- * @since 3.3.2
- */
-public class StringBuilderWriterTest extends TestCase {
- private StringBuilder builder;
- private Writer writer;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- this.builder = new StringBuilder();
- this.writer = new StringBuilderWriter(this.builder);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- this.builder = null;
- this.writer = null;
- }
-
- public void testWrite() throws Exception {
- writer.write(new char[] {'a', 'b'});
- assertEquals("ab", builder.toString());
- }
-
- public void testWrite2() throws Exception {
- writer.write(0x12345678);
-
- String s = builder.toString();
-
- assertEquals(1, s.length());
- assertEquals(0x5678, s.charAt(0));
- }
-
- public void testWrite3() throws Exception {
- writer.write("test");
- assertEquals("test", builder.toString());
- }
-
- public void testWrite4() throws Exception {
- writer.write("abcd".toCharArray(), 1, 2);
- assertEquals("bc", builder.toString());
- writer.write("efgh".toCharArray(), 0, 3);
- assertEquals("bcefg", builder.toString());
- writer.write("ijkl".toCharArray(), 2, 2);
- assertEquals("bcefgkl", builder.toString());
- }
-
- public void testWrite5() throws Exception {
- writer.write("abcd", 1, 2);
- assertEquals("bc", builder.toString());
- writer.write("efgh", 0, 3);
- assertEquals("bcefg", builder.toString());
- writer.write("ijklm", 2, 3);
- assertEquals("bcefgklm", builder.toString());
- }
-
- public void testFlush() throws Exception {
- writer.flush();
- }
-
- public void testClose() throws Exception {
- writer.close();
- }
-}
Modified: branches/RF-8742-1/core/impl/src/main/java/org/richfaces/application/push/impl/AbstractRequest.java
===================================================================
--- branches/RF-8742-1/core/impl/src/main/java/org/richfaces/application/push/impl/AbstractRequest.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/impl/src/main/java/org/richfaces/application/push/impl/AbstractRequest.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -70,17 +70,31 @@
}
public String toScript() {
+ Map<String, Object> map = createScriptMap();
+
+ return ScriptUtils.toScript(map);
+ }
+
+ private Map<String, Object> createScriptMap() {
Map<String,Object> map = new HashMap<String, Object>(2);
map.put(TOPIC_KEY, topicKey.getTopicAddress());
map.put(DATA_KEY, new JSLiteral(serializedData));
-
- return ScriptUtils.toScript(map);
+ return map;
}
- public void appendScript(StringBuffer functionString) {
- functionString.append(toScript());
+ public void appendScript(Appendable target) throws IOException {
+ target.append(toScript());
}
+
+ public void appendScriptToStringBuilder(StringBuilder stringBuilder) {
+ try {
+ appendScript(stringBuilder);
+ } catch (IOException e) {
+ //ignore
+ }
+ }
+
}
private static final class FlushMessagesTask implements Runnable {
Deleted: branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/util/ViewUtil.java
===================================================================
--- branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/util/ViewUtil.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/impl/src/main/java/org/richfaces/component/util/ViewUtil.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,53 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.component.util;
-
-import javax.faces.context.FacesContext;
-
-/**
- * @author Nick Belaevski - nbelaevski(a)exadel.com
- * created 19.02.2007
- */
-public final class ViewUtil {
- private ViewUtil() {
- }
-
- public static String getResourceURL(String url) {
- if (null == url) {
- return null;
- }
-
- return ViewUtil.getResourceURL(url, FacesContext.getCurrentInstance());
- }
-
- public static String getResourceURL(String url, FacesContext context) {
- if (null == url) {
- return null;
- }
-
- String value = url;
-
- value = context.getApplication().getViewHandler().getResourceURL(context, value);
-
- return context.getExternalContext().encodeResourceURL(value);
- }
-}
Modified: branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/ScriptOptions.java
===================================================================
--- branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/ScriptOptions.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/impl/src/main/java/org/richfaces/renderkit/ScriptOptions.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -21,16 +21,18 @@
package org.richfaces.renderkit;
-import org.ajax4jsf.javascript.JSFunctionDefinition;
-import org.ajax4jsf.javascript.ScriptStringBase;
-import org.ajax4jsf.javascript.ScriptUtils;
-
-import javax.faces.component.UIComponent;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
+import javax.faces.component.UIComponent;
+
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.ScriptStringBase;
+import org.ajax4jsf.javascript.ScriptUtils;
+
/**
* @author Maksim Kaszynski
*/
@@ -42,8 +44,8 @@
this.component = component;
}
- public void appendScript(StringBuffer functionString) {
- functionString.append(ScriptUtils.toScript(opts));
+ public void appendScript(Appendable target) throws IOException {
+ ScriptUtils.appendScript(target, opts);
}
public void addOption(String name) {
Modified: branches/RF-8742-1/core/impl/src/main/resources/META-INF/resources/jquery.position.js
===================================================================
--- branches/RF-8742-1/core/impl/src/main/resources/META-INF/resources/jquery.position.js 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/core/impl/src/main/resources/META-INF/resources/jquery.position.js 2010-11-18 23:14:43 UTC (rev 20108)
@@ -5,7 +5,7 @@
*/
// draft examples of usage
-// jQuery('#tooltip').setPosition('#aaa',{from:'LB', to:'AA'});
+// jQuery('#tooltip').setPosition('#aaa',{from:'bottom-left', to:'auto-auto'});
// jQuery('#bbb').bind("click",function(e){jQuery('#tooltip').setPosition(e);});
// TODO: clear code
// TODO: optimization
@@ -81,6 +81,14 @@
var def = params.type || params.from || params.to ? $.PositionTypes[params.type || defaultType] : {noPositionType:true};
var options = $.extend({}, defaults, def, params);
+ if (!options.noPositionType) {
+ if (options.from.length>2) {
+ options.from = positionDefinition[options.from.toLowerCase()];
+ }
+ if (options.to.length>2) {
+ options.to = positionDefinition[options.to.toLowerCase()];
+ }
+ }
return this.each(function() {
element = $(this);
//alert(rect.left+" "+rect.top+" "+rect.width+" "+rect.height);
@@ -98,6 +106,17 @@
var re = /^(left|right)-(top|buttom|auto)$/i;
// TODO: make it private
+ var positionDefinition = {
+ 'top-left':'LT',
+ 'top-right':'RT',
+ 'bottom-left':'LB',
+ 'bottom-right':'RB',
+ 'top-auto':'AT',
+ 'bottom-auto':'AB',
+ 'auto-left':'LA',
+ 'auto-right':'RA',
+ 'auto-auto':'AA'
+ };
$.PositionTypes = {
// horisontal constants: L-left, R-right, C-center, A-auto
// vertical constants: T-top, B-bottom, M-middle, A-auto
@@ -147,15 +166,15 @@
offset = e.offset();
var d = rect.left - offset.left;
if (d<0) {
- rect.width = (width > rect.width) ? width : rect.width - d;
+ if (width-d > rect.width) rect.width = width - d;
} else {
- if (d + width > rect.width) rect.width = d + width;
+ rect.width += d;
}
var d = rect.top - offset.top;
if (d<0) {
- rect.height = (height > rect.height) ? height : rect.height - d;
+ if (height-d > rect.height) rect.height = height -d;
} else {
- if (d + height > rect.height) rect.height = d + height;
+ rect.height += d;
}
if (offset.left < rect.left) rect.left = offset.left;
if (offset.top < rect.top) rect.top = offset.top;
Modified: branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarBean.java
===================================================================
--- branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarBean.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarBean.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -4,11 +4,11 @@
import java.util.Locale;
import javax.faces.bean.ManagedBean;
-import javax.faces.bean.RequestScoped;
+import javax.faces.bean.SessionScoped;
import javax.faces.event.ValueChangeEvent;
@ManagedBean
-@RequestScoped
+@SessionScoped
public class CalendarBean {
private Locale locale;
@@ -17,6 +17,9 @@
private Date selectedDate;
private boolean showApply = true;
private boolean useCustomDayLabels;
+ private String mode = "client";
+ private String jointPoint = "auto-auto";
+ private String direction = "auto-auto";
public CalendarBean() {
@@ -25,6 +28,14 @@
pattern = "d/M/yy HH:mm";
}
+ public String getMode() {
+ return mode;
+ }
+
+ public void setMode(String mode) {
+ this.mode = mode;
+ }
+
public Locale getLocale() {
return locale;
}
@@ -83,4 +94,20 @@
this.showApply = showApply;
}
+ public void setJointPoint(String jointPoint) {
+ this.jointPoint = jointPoint;
+ }
+
+ public String getJointPoint() {
+ return jointPoint;
+ }
+
+ public void setDirection(String direction) {
+ this.direction = direction;
+ }
+
+ public String getDirection() {
+ return direction;
+ }
+
}
\ No newline at end of file
Copied: branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarDataModelImpl.java (from rev 20107, trunk/examples/input-demo/src/main/java/org/richfaces/demo/CalendarDataModelImpl.java)
===================================================================
--- branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarDataModelImpl.java (rev 0)
+++ branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarDataModelImpl.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,70 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.demo;
+
+import java.util.Date;
+import java.util.Random;
+
+import javax.faces.bean.ApplicationScoped;
+import javax.faces.bean.ManagedBean;
+
+import org.richfaces.model.CalendarDataModel;
+import org.richfaces.model.CalendarDataModelItem;
+
+/**
+ * @author Nick Belaevski - mailto:nbelaevski@exadel.com
+ * created 30.06.2007
+ *
+ */
+@ManagedBean(name="calendarDataModel")
+@ApplicationScoped
+public class CalendarDataModelImpl implements CalendarDataModel {
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.CalendarDataModel#getData(java.util.Date[])
+ */
+ public CalendarDataModelItem[] getData(Date[] dateArray) {
+ if (dateArray == null) {
+ return null;
+ }
+
+ CalendarDataModelItem[] items = new CalendarDataModelItem[dateArray.length];
+ for (int i = 0; i < dateArray.length; i++) {
+ items[i] = createDataModelItem(dateArray[i]);
+ }
+
+ return items;
+ }
+
+ protected CalendarDataModelItem createDataModelItem(Date date) {
+ CalendarDataModelItemImpl item = new CalendarDataModelItemImpl();
+
+ if (new Random().nextInt(10) > 5) {
+ item.setEnabled(true);
+
+ } else {
+ item.setEnabled(false);
+ }
+
+ return item;
+ }
+}
Copied: branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarDataModelItemImpl.java (from rev 20107, trunk/examples/input-demo/src/main/java/org/richfaces/demo/CalendarDataModelItemImpl.java)
===================================================================
--- branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarDataModelItemImpl.java (rev 0)
+++ branches/RF-8742-1/examples/input-demo/src/main/java/org/richfaces/demo/CalendarDataModelItemImpl.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,58 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.demo;
+
+import org.richfaces.model.CalendarDataModelItem;
+
+/**
+ * @author Nick Belaevski - mailto:nbelaevski@exadel.com
+ * created 04.07.2007
+ *
+ */
+public class CalendarDataModelItemImpl implements CalendarDataModelItem {
+
+ private boolean enabled = true;
+ private String styleClass = "";
+
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.CalendarDataModelItem#isEnabled()
+ */
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ /**
+ * @param enabled the enabled to set
+ */
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public String getStyleClass() {
+ return styleClass;
+ }
+
+ public void setStyleClass(String styleClass) {
+ this.styleClass = styleClass;
+ }
+}
Modified: branches/RF-8742-1/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml
===================================================================
--- branches/RF-8742-1/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/examples/input-demo/src/main/webapp/examples/autocomplete.xhtml 2010-11-18 23:14:43 UTC (rev 20108)
@@ -38,7 +38,7 @@
</script>
<input:autocomplete autofill="false" id="myAutocomplete" clientFilterFunction="customFilterFunction" mode="#{autoCompleteBean.mode}" minChars="2" autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country" fetchValue="#{country.name}" showButton="true"
- value = "#{autoCompleteBean.value}"
+ value = "#{autoCompleteBean.value}" layout="list"
onchange="return onEvent.call(this, event);" onselectitem="return onEvent.call(this, event);" onblur="return onEvent.call(this, event);" onfocus="return onEvent.call(this, event);">
#{country.name} #{country.iso} #{country.domain}
<a4j:ajax event="change" render="output"/>
@@ -88,6 +88,29 @@
<a4j:log mode="inline"></a4j:log>
</div>
</h:form>
+ <h:form>
+ RF-9567:<br/><br/>
+ <a4j:outputPanel ajaxRendered="true"><h:messages /></a4j:outputPanel>
+
+
+ <input:autocomplete mode="ajax" id="autocomplete" autocompleteMethod="#{autoCompleteBean.autocomplete}" value="#{autoCompleteBean.value}">
+ <f:validateRegex pattern="Alabama" />
+ </input:autocomplete>
+
+ <a4j:commandButton render="@form" execute="autocomplete" />
+ </h:form>
+ <h:form>
+ <input:autocomplete mode="cachedAjax" tokens="," minChars="0"
+autofill="true" selectFirst="false" layout="table"
+autocompleteMethod="#{autoCompleteBean.autocomplete}" var="country" fetchValue="#{country.name}">
+<h:column>
+#{country.name}
+</h:column>
+<h:column>
+#{country.iso}
+</h:column>
+</input:autocomplete>
+</h:form>
</ui:define>
</ui:composition>
Modified: branches/RF-8742-1/examples/input-demo/src/main/webapp/examples/calendar.xhtml
===================================================================
--- branches/RF-8742-1/examples/input-demo/src/main/webapp/examples/calendar.xhtml 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/examples/input-demo/src/main/webapp/examples/calendar.xhtml 2010-11-18 23:14:43 UTC (rev 20108)
@@ -37,12 +37,14 @@
<h:panelGrid id="panel" columns="2">
<h:panelGroup layout="block">
<calendar:calendar value="#{calendarBean.selectedDate}" id="calendar"
+ jointPoint="#{calendarBean.jointPoint}" direction="#{calendarBean.direction}"
locale="#{calendarBean.locale}" popup="#{calendarBean.popup}"
datePattern="#{calendarBean.pattern}"
+ dataModel="#{calendarDataModel}"
+ mode="#{calendarBean.mode}"
showApplyButton="#{calendarBean.showApply}" cellWidth="24px"
- cellHeight="22px" style="width:200px">
- <f:convertDateTime pattern="#{calendarBean.pattern}"
- onchange="alert('1')" />
+ cellHeight="22px" style="width:200px" minDaysInFirstWeek="3">
+ <f:convertDateTime pattern="#{calendarBean.pattern}" />
</calendar:calendar>
</h:panelGroup>
<h:panelGrid columns="2">
@@ -73,6 +75,31 @@
<f:selectItem itemLabel="d/MMM/y" itemValue="d/MMM/y" />
<f:selectItem itemLabel="MMM d, yyyy" itemValue="MMM d, yyyy" />
</h:selectOneMenu>
+
+ <h:outputText value="Mode" />
+ <h:selectOneMenu value="#{calendarBean.mode}" onchange="submit()">
+ <f:selectItem itemValue="client"/>
+ <f:selectItem itemValue="ajax"/>
+ </h:selectOneMenu><br/>
+
+ <h:outputText value="Select joint point:" />
+ <h:selectOneMenu value="#{calendarBean.jointPoint}">
+ <f:ajax execute="@form" event="change" render="calendar @this" />
+ <f:selectItem itemLabel="auto-auto" itemValue="auto-auto" />
+ <f:selectItem itemLabel="top-left" itemValue="top-left" />
+ <f:selectItem itemLabel="top-right" itemValue="top-right" />
+ <f:selectItem itemLabel="bottom-left" itemValue="bottom-left" />
+ <f:selectItem itemLabel="bottom-right" itemValue="bottom-right" />
+ </h:selectOneMenu>
+ <h:outputText value="Select direction:" />
+ <h:selectOneMenu value="#{calendarBean.direction}">
+ <f:ajax execute="@form" event="change" render="calendar @this" />
+ <f:selectItem itemLabel="auto-auto" itemValue="auto-auto" />
+ <f:selectItem itemLabel="top-left" itemValue="top-left" />
+ <f:selectItem itemLabel="top-right" itemValue="top-right" />
+ <f:selectItem itemLabel="bottom-left" itemValue="bottom-left" />
+ <f:selectItem itemLabel="bottom-right" itemValue="bottom-right" />
+ </h:selectOneMenu>
</h:panelGrid>
</h:panelGrid>
</h:form>
Copied: branches/RF-8742-1/examples/iteration-demo/src/main/java/org/richfaces/demo/LazyTreeNode.java (from rev 20107, trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/LazyTreeNode.java)
===================================================================
--- branches/RF-8742-1/examples/iteration-demo/src/main/java/org/richfaces/demo/LazyTreeNode.java (rev 0)
+++ branches/RF-8742-1/examples/iteration-demo/src/main/java/org/richfaces/demo/LazyTreeNode.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.demo;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.swing.tree.TreeNode;
+
+import com.google.common.collect.Iterators;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class LazyTreeNode implements TreeNode, Serializable {
+
+ private static final long serialVersionUID = 7222747310505408841L;
+
+ private TreeNode srcNode;
+
+ private LazyTreeNode parentNode;
+
+ private List<LazyTreeNode> children = null;
+
+ public LazyTreeNode(LazyTreeNode parentNode, TreeNode srcNode) {
+ super();
+ this.parentNode = parentNode;
+ this.srcNode = srcNode;
+ }
+
+ public LazyTreeNode(TreeNode srcNode) {
+ this(null, srcNode);
+ }
+
+ private void initializeChildren() {
+ if (children != null) {
+ return;
+ }
+
+ children = new ArrayList<LazyTreeNode>();
+
+ Enumeration srcChildren = srcNode.children();
+ while (srcChildren.hasMoreElements()) {
+ TreeNode srcChild = (TreeNode) srcChildren.nextElement();
+ children.add(new LazyTreeNode(this, srcChild));
+ }
+ }
+
+ public TreeNode getChildAt(int childIndex) {
+ initializeChildren();
+
+ return children.get(childIndex);
+ }
+
+ public int getChildCount() {
+ initializeChildren();
+
+ return children.size();
+ }
+
+ public TreeNode getParent() {
+ return parentNode;
+ }
+
+ public int getIndex(TreeNode node) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean getAllowsChildren() {
+ return true;
+ }
+
+ public boolean isLeaf() {
+ if (children == null) {
+ return false;
+ }
+
+ return children.isEmpty();
+ }
+
+ public Enumeration children() {
+ initializeChildren();
+
+ return Iterators.asEnumeration(children.iterator());
+ }
+
+ public TreeNode getWrappedNode() {
+ return srcNode;
+ }
+}
Modified: branches/RF-8742-1/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java
===================================================================
--- branches/RF-8742-1/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -22,6 +22,7 @@
package org.richfaces.demo;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -30,9 +31,18 @@
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.AjaxBehaviorEvent;
+import javax.faces.event.FacesEvent;
import javax.swing.tree.TreeNode;
+import org.richfaces.component.AbstractTree;
+import org.richfaces.component.AbstractTreeNode;
import org.richfaces.component.SwitchType;
+import org.richfaces.event.TreeSelectionChangeEvent;
+import org.richfaces.event.TreeSelectionChangeListener;
+import org.richfaces.event.TreeToggleEvent;
+import org.richfaces.event.TreeToggleListener;
import org.richfaces.log.LogFactory;
import org.richfaces.log.Logger;
@@ -44,26 +54,98 @@
@SessionScoped
public class TreeBean implements Serializable {
+ public static final class SelectionChangeHandler implements TreeSelectionChangeListener {
+
+ private boolean fromExpression = false;
+
+ public SelectionChangeHandler() {
+ }
+
+ public SelectionChangeHandler(boolean fromExpression) {
+ super();
+ this.fromExpression = fromExpression;
+ }
+
+ public void processSelectionChange(TreeSelectionChangeEvent event) throws AbortProcessingException {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ facesContext.addMessage(getTree(event).getBaseClientId(facesContext), createEventMessage(event, fromExpression));
+ }
+
+ }
+
+ public static final class ToggleHandler implements TreeToggleListener {
+
+ private boolean fromExpression = false;
+
+ public ToggleHandler() {
+ }
+
+ public ToggleHandler(boolean fromExpression) {
+ super();
+ this.fromExpression = fromExpression;
+ }
+
+ public void processToggle(TreeToggleEvent event) throws AbortProcessingException {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ facesContext.addMessage(getTree(event).getBaseClientId(facesContext), createEventMessage(event, fromExpression));
+ }
+
+ }
+
private static final long serialVersionUID = 3368885134614548497L;
private static final Logger LOGGER = LogFactory.getLogger(TreeBean.class);
private List<TreeNode> rootNodes;
+ private List<TreeNode> lazyRootNodes;
+
private SwitchType toggleType = SwitchType.DEFAULT;
private SwitchType selectionType = SwitchType.client;
- private Object nodeData;
+ private boolean showCustomClasses = true;
private Collection<Object> selection = new TracingSet<Object>();
+
+ private String toggleNodeEvent = "";
+ private static Object staticGetNodeData() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ return facesContext.getApplication().evaluateExpressionGet(facesContext, "#{node}", Object.class);
+ }
+
+ private static FacesMessage createEventMessage(FacesEvent event, boolean fromExpression) {
+ String summary = event + (fromExpression ? " called from attribute" : " called from tag") + ", data: " + staticGetNodeData();
+ return new FacesMessage(summary);
+ }
+
+ private static AbstractTree getTree(FacesEvent event) {
+ if (event.getComponent() instanceof AbstractTree) {
+ return (AbstractTree) event.getComponent();
+ }
+
+ return ((AbstractTreeNode) event.getComponent()).findTreeComponent();
+ }
+
+ private List<TreeNode> createLazyNodes(List<TreeNode> nodes) {
+ List<TreeNode> result = new ArrayList<TreeNode>(nodes.size());
+
+ for (TreeNode srcNode : nodes) {
+ result.add(new LazyTreeNode(srcNode));
+ }
+
+ return result;
+ }
+
@PostConstruct
public void init() {
try {
TreeNodeParser parser = new TreeNodeParser();
parser.parse(TreeBean.class.getResource("plants.xml"));
rootNodes = parser.getRootNodes();
+ lazyRootNodes = createLazyNodes(rootNodes);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
@@ -73,6 +155,10 @@
return rootNodes;
}
+ public List<TreeNode> getLazyRootNodes() {
+ return lazyRootNodes;
+ }
+
public SwitchType[] getTypes() {
return SwitchType.values();
}
@@ -94,13 +180,9 @@
}
public Object getNodeData() {
- return nodeData;
+ return staticGetNodeData();
}
- public void setNodeData(Object nodeData) {
- this.nodeData = nodeData;
- }
-
public Collection<Object> getSelection() {
return selection;
}
@@ -113,4 +195,40 @@
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.addMessage(null, new FacesMessage("Clicked node: " + getNodeData()));
}
+
+ public boolean isShowCustomClasses() {
+ return showCustomClasses;
+ }
+
+ public void setShowCustomClasses(boolean showCustomClasses) {
+ this.showCustomClasses = showCustomClasses;
+ }
+
+ public void behaviorToggleListener(AjaxBehaviorEvent event) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ facesContext.addMessage(null, new FacesMessage("Toggle node: " + getNodeData() + ", source is: " + event.getSource()));
+ }
+
+ public void behaviorSelectionChangeListener(AjaxBehaviorEvent event) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ facesContext.addMessage(event.getComponent().getClientId(facesContext), new FacesMessage("Selection changed, source is: " + event.getSource()));
+ }
+
+ public void processSelectionChange(TreeSelectionChangeEvent event) {
+ new SelectionChangeHandler(true).processSelectionChange(event);
+ }
+
+ public void processToggle(TreeToggleEvent event) {
+ new ToggleHandler(true).processToggle(event);
+ }
+
+ public String getToggleNodeEvent() {
+ return toggleNodeEvent;
+ }
+
+ public void setToggleNodeEvent(String toggleNodeEvent) {
+ this.toggleNodeEvent = toggleNodeEvent;
+ }
+
+
}
Modified: branches/RF-8742-1/examples/iteration-demo/src/main/webapp/WEB-INF/web.xml
===================================================================
--- branches/RF-8742-1/examples/iteration-demo/src/main/webapp/WEB-INF/web.xml 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/examples/iteration-demo/src/main/webapp/WEB-INF/web.xml 2010-11-18 23:14:43 UTC (rev 20108)
@@ -72,6 +72,11 @@
<param-value>true</param-value>
</context-param>
+ <context-param>
+ <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
+ <param-value>true</param-value>
+ </context-param>
+
<context-param>
<description>
Set this flag to true if you want the JavaServer Faces
Copied: branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images (from rev 20107, trunk/examples/iteration-demo/src/main/webapp/images)
Deleted: branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/leaf.png
===================================================================
--- trunk/examples/iteration-demo/src/main/webapp/images/leaf.png 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/leaf.png 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,4 +0,0 @@
-�PNG
-
-
\ No newline at end of file
Copied: branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/leaf.png (from rev 20107, trunk/examples/iteration-demo/src/main/webapp/images/leaf.png)
===================================================================
--- branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/leaf.png (rev 0)
+++ branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/leaf.png 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,4 @@
+�PNG
+
+
\ No newline at end of file
Deleted: branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/minus.png
===================================================================
--- trunk/examples/iteration-demo/src/main/webapp/images/minus.png 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/minus.png 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,4 +0,0 @@
-�PNG
-
-
\ No newline at end of file
Copied: branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/minus.png (from rev 20107, trunk/examples/iteration-demo/src/main/webapp/images/minus.png)
===================================================================
--- branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/minus.png (rev 0)
+++ branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/minus.png 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,4 @@
+�PNG
+
+
\ No newline at end of file
Deleted: branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/plus.png
===================================================================
--- trunk/examples/iteration-demo/src/main/webapp/images/plus.png 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/plus.png 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,5 +0,0 @@
-�PNG
-
-
-�<n3�%ϥh�
\ No newline at end of file
Copied: branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/plus.png (from rev 20107, trunk/examples/iteration-demo/src/main/webapp/images/plus.png)
===================================================================
--- branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/plus.png (rev 0)
+++ branches/RF-8742-1/examples/iteration-demo/src/main/webapp/images/plus.png 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,5 @@
+�PNG
+
+
+�<n3�%ϥh�
\ No newline at end of file
Modified: branches/RF-8742-1/examples/iteration-demo/src/main/webapp/tree.xhtml
===================================================================
--- branches/RF-8742-1/examples/iteration-demo/src/main/webapp/tree.xhtml 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/examples/iteration-demo/src/main/webapp/tree.xhtml 2010-11-18 23:14:43 UTC (rev 20108)
@@ -3,14 +3,80 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:it="http://richfaces.org/iteration">
+ xmlns:it="http://richfaces.org/iteration"
+ xmlns:a4j="http://richfaces.org/a4j">
<f:view contentType="text/html" />
<h:head>
<title>Richfaces Tree</title>
+
+ <h:outputStylesheet>/*<![CDATA[*/
+ .customClass .customNodeClass {
+ border: 1px solid navy;
+ }
+
+ .customClass .customHandleClass {
+ border: 1px solid red;
+ }
+
+ .customClass .customIconClass {
+ border: 1px solid yellow;
+ }
+
+ .customClass .customLabelClass {
+ border: 1px solid green;
+ }
+
+ /*]]>*/</h:outputStylesheet>
</h:head>
<h:body>
+ <h:outputScript>
+ function nodesArrayToString(nodes) {
+ var result = new Array();
+ jQuery.each(nodes, function(k, v) {
+ result.push(v.getId());
+ });
+
+ return result.join('');
+ }
+
+ function getNodeStateString(treeNode) {
+ return treeNode.isLeaf() ?
+ 'leaf'
+ : (treeNode.isExpanded() ? 'expanded' : 'collapsed');
+ }
+
+ function handleNodeToggle(nodeData, event, isTreeNodeLevel) {
+ var treeNode = RichFaces.$(event.target);
+ RichFaces.log.info('Toggle event ' + (isTreeNodeLevel ? '(treeNode level)' : '')
+ + '[' + nodeData + ']:\n ' + treeNode.getId() + ' became ' + getNodeStateString(treeNode));
+ }
+
+ function handleBeforeNodeToggle(event, isTreeNodeLevel) {
+ var treeNode = RichFaces.$(event.target);
+ return confirm('Tree' + (isTreeNodeLevel ? ' node ' : ' ') + 'asks: really toggle node ' + treeNode.getId() + '?');
+ }
+
+ function handleBeforeNodeSelect(event) {
+ var treeNode = RichFaces.$(event.target);
+
+ var oldSelectionString = nodesArrayToString(event.rf.data.oldSelection);
+ var newSelectionString = nodesArrayToString(event.rf.data.newSelection);
+
+ return confirm('Selection will be changed from: [' + oldSelectionString + '] to: [' + newSelectionString + ']');
+ }
+
+ function handleNodeSelect(event) {
+ var treeNode = RichFaces.$(event.target);
+
+ var oldSelectionString = nodesArrayToString(event.rf.data.oldSelection);
+ var newSelectionString = nodesArrayToString(event.rf.data.newSelection);
+
+ RichFaces.log.info('Selection changed from: [' + oldSelectionString + '] to: [' + newSelectionString + ']');
+ }
+ </h:outputScript>
+
<h:messages id="messages" />
<h:form>
@@ -21,17 +87,27 @@
Selection mode: <h:selectOneRadio value="#{treeBean.selectionType}" onclick="submit()">
<f:selectItems value="#{treeBean.types}" itemDisabled="#{item == 'server'}" var="item" itemValue="#{item}" />
</h:selectOneRadio>
+
+ Show custom classes: <h:selectBooleanCheckbox value="#{treeBean.showCustomClasses}" onclick="submit()" />
+
+ <br />
+ Toggle node event:
+ <h:selectOneMenu value="#{treeBean.toggleNodeEvent}" onchange="submit()">
+ <f:selectItem itemLabel="none" itemValue="" />
+ <f:selectItem itemLabel="click" itemValue="click" />
+ <f:selectItem itemLabel="mouseenter" itemValue="mouseenter" />
+ <f:selectItem itemLabel="dblclick" itemValue="dblclick" />
+ </h:selectOneMenu>
</h:form>
<h:form id="form">
+ Base tree:
<it:tree id="tree" nodeType="#{node.parent == null ? 'rootNode': 'childNode'}" var="node" value="#{treeBean.rootNodes}"
selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}" selection="#{treeBean.selection}">
<it:treeNode type="rootNode">
<h:panelGroup id="rootNodeGroup">
Root node: #{node.data} -
<h:commandLink value="link" action="#{treeBean.clickNode}">
- <f:setPropertyActionListener value="#{node.data}" target="#{treeBean.nodeData}" />
-
<f:ajax render=":messages" />
</h:commandLink>
</h:panelGroup>
@@ -40,8 +116,6 @@
<h:panelGroup id="childNodeGroup">
#{node.data} -
<h:commandLink value="link" action="#{treeBean.clickNode}">
- <f:setPropertyActionListener value="#{node.data}" target="#{treeBean.nodeData}" />
-
<f:ajax render=":messages" />
</h:commandLink>
</h:panelGroup>
@@ -51,6 +125,94 @@
<h:commandLink value="Re-render">
<f:ajax render=":form:tree" execute="@all" />
</h:commandLink>
+
+ Tree with customized look:
+ <it:tree id="customizedTree" var="node" value="#{treeBean.rootNodes}"
+ selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}"
+ styleClass="#{treeBean.showCustomClasses ? 'customClass' : ''}"
+ nodeClass="customNodeClassFromTree"
+ handleClass="customHandleClassFromTree" iconClass="customIconClassFromTree" labelClass="customLabelClassFromTree">
+
+ <it:treeNode iconLeaf="/images/leaf.png" iconExpanded="/images/minus.png" iconCollapsed="/images/plus.png"
+ styleClass="customNodeClass" handleClass="customHandleClass" iconClass="customIconClass" labelClass="customLabelClass">
+ #{node.data}
+ </it:treeNode>
+ </it:tree>
+
+ Tree with default node:
+ <it:tree id="defaultNodeTree" var="node" value="#{treeBean.rootNodes}"
+ selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}">
+ </it:tree>
+
+ Tree with client-side event handlers:
+ <it:tree id="clientSideEventsTree" var="node" value="#{treeBean.rootNodes}"
+ selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}"
+ onnodetoggle="handleNodeToggle("#{node.data}", event, false)"
+ onselectionchange="handleNodeSelect(event)"
+ onbeforeselectionchange="return handleBeforeNodeSelect(event)"
+ onbeforenodetoggle="return handleBeforeNodeToggle(event, false)">
+
+ <it:treeNode ontoggle="handleNodeToggle("#{node.data}", event, true)"
+ onbeforetoggle="return handleBeforeNodeToggle(event, true)">
+ #{node.data}
+ </it:treeNode>
+ </it:tree>
+
+ Tree with attached behaviors:
+ <h:messages id="treeBehaviorsMessages" for="behaviorsAttachedTree" />
+ <h:messages id="treeNodeBehaviorsMessages" globalOnly="true" />
+
+ <it:tree id="behaviorsAttachedTree" var="node" value="#{treeBean.rootNodes}"
+ selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}">
+
+ <f:ajax event="nodetoggle" listener="#{treeBean.behaviorToggleListener}" render=":form:treeBehaviorsMessages" />
+ <f:ajax event="selectionchange" listener="#{treeBean.behaviorSelectionChangeListener}" render=":form:treeBehaviorsMessages :form:treeNodeBehaviorsMessages" />
+
+ <it:treeNode>
+ #{node.data}
+
+ <f:ajax event="toggle" listener="#{treeBean.behaviorToggleListener}" render=":form:treeNodeBehaviorsMessages" />
+ </it:treeNode>
+ </it:tree>
+
+ Lazy loaded tree:
+ <it:tree id="lazyLoadedTree" var="node" value="#{treeBean.lazyRootNodes}"
+ selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}">
+
+ <it:treeNode>
+ #{node.wrappedNode.data}
+ </it:treeNode>
+ </it:tree>
+
+ <a4j:outputPanel ajaxRendered="true">
+ <h:messages for="serverListenersTree" />
+ </a4j:outputPanel>
+
+ Server listeners test:
+ <it:tree id="serverListenersTree" var="node" value="#{treeBean.rootNodes}"
+ selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}"
+ selectionChangeListener="#{treeBean.processSelectionChange}"
+ toggleListener="#{treeBean.processToggle}">
+
+ <it:treeSelectionChangeListener type="org.richfaces.demo.TreeBean$SelectionChangeHandler" />
+ <it:treeToggleListener type="org.richfaces.demo.TreeBean$ToggleHandler" />
+
+ <it:treeNode toggleListener="#{treeBean.processToggle}">
+ <it:treeToggleListener type="org.richfaces.demo.TreeBean$ToggleHandler" />
+
+ #{node.data}
+ </it:treeNode>
+ </it:tree>
+
+ Toggle node event:
+ <it:tree toggleNodeEvent="#{treeBean.toggleNodeEvent}" var="node" value="#{treeBean.rootNodes}"
+ selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}">
+ <it:treeNode>
+ #{node.data}
+ </it:treeNode>
+ </it:tree>
+
+ <a4j:log />
</h:form>
</h:body>
</html>
Modified: branches/RF-8742-1/examples/output-demo/src/main/webapp/examples/tooltip.xhtml
===================================================================
--- branches/RF-8742-1/examples/output-demo/src/main/webapp/examples/tooltip.xhtml 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/examples/output-demo/src/main/webapp/examples/tooltip.xhtml 2010-11-18 23:14:43 UTC (rev 20108)
@@ -26,7 +26,7 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
- xmlns:pn="http://richfaces.org/output">
+ xmlns:rich="http://richfaces.org/output">
<body>
<ui:composition template="/templates/template.xhtml">
@@ -39,11 +39,67 @@
<ui:define name="body_head">TOOLTIP JS Development</ui:define>
<ui:define name="body">
- <h:form id="f" style="border:blue solid thin;">
- <pn:tooltip id="tooltip">
- <!-- TODO -->
- </pn:tooltip>
- </h:form>
+ <h:panelGrid columns="2">
+ <rich:panel id="sample1" styleClass="tooltip-text"
+ bodyClass="rich-laguna-panel-no-header">
+ <p>Here you can see <b>default client-side</b> tool-tip</p>
+ <rich:tooltip id="tt1" styleClass="tooltip">
+ <span style="white-space: nowrap"> This tool-tip content was
+ <strong>pre-rendered</strong> to the page.<br />
+ Also the tooltip following mouse by default </span>
+ </rich:tooltip>
+ </rich:panel>
+ <rich:panel id="sample2" styleClass="tooltip"
+ bodyClass="rich-laguna-panel-no-header">
+ <p>This tool-tip will not <b>follow mouse</b>. Also this tool-tip
+ has a <b>delay 1.5 sec</b>, so be patient!</p>
+ <rich:tooltip followMouse="false" showDelay="1500"
+ styleClass="tooltip-custom-body">
+ <span style="white-space: nowrap"> This tool-tip content also
+ <strong>pre-rendered</strong> to the page.<br />
+ </span>
+ </rich:tooltip>
+ </rich:panel>
+ <h:form>
+ <rich:panel id="sample3" styleClass="tooltip-text"
+ bodyClass="rich-laguna-panel-no-header">
+ <p>This tool-tip rendered on server <b>in separate request</b>.
+ </p>
+ <rich:tooltip mode="ajax" styleClass="tooltip" layout="block">
+ <f:facet name="defaultContent">
+ <strong>Wait...</strong>
+ </f:facet>
+ <span style="white-space: nowrap">This tool-tip content was
+ <strong>rendered on server</strong> </span>
+ <h:panelGrid columns="2">
+ <h:outputText style="white-space:nowrap"
+ value="tooltips requested" />
+ </h:panelGrid>
+ </rich:tooltip>
+ </rich:panel>
+ </h:form>
+ <h:form>
+ <rich:panel id="sample4" styleClass="tooltip-text"
+ bodyClass="rich-laguna-panel-no-header">
+ <p>This tool-tip will be <b>activated on mouse click</b>.</p>
+ <rich:tooltip showEvent="click" mode="ajax" styleClass="tooltip"
+ layout="block">
+ <f:facet name="defaultContent">
+ <strong>Wait...</strong>
+ </f:facet>
+ <span style="white-space: nowrap">This tool-tip content was
+ <strong>rendered on server</strong><br />
+ </span>
+ <h:panelGrid columns="2">
+ <h:outputText style="white-space:nowrap"
+ value="tooltips requested:" />
+ <h:outputText value="#{tooltipData.tooltipCounter}"
+ styleClass="tooltipData" />
+ </h:panelGrid>
+ </rich:tooltip>
+ </rich:panel>
+ </h:form>
+ </h:panelGrid>
</ui:define>
</ui:composition>
</body>
Modified: branches/RF-8742-1/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/TreeBean.java
===================================================================
--- branches/RF-8742-1/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/TreeBean.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/TreeBean.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -36,7 +36,7 @@
import org.richfaces.demo.tree.model.CD;
import org.richfaces.demo.tree.model.Company;
import org.richfaces.demo.tree.model.Country;
-import org.richfaces.event.TreeSelectionEvent;
+import org.richfaces.event.TreeSelectionChangeEvent;
/**
* @author Ilya Shaikovsky
@@ -88,7 +88,7 @@
return company;
}
- private void selectionListener(TreeSelectionEvent event) {
+ private void selectionListener(TreeSelectionChangeEvent event) {
//TODO: implement when ready
}
Modified: branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java
===================================================================
--- branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/component/UIDataAdaptor.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -853,6 +853,10 @@
return clientId;
}
+ public String getBaseClientId(FacesContext context) {
+ return super.getClientId(context);
+ }
+
/**
* Save current state of data variable.
*
@@ -1489,7 +1493,7 @@
int separatorIndex = substring.indexOf(separatorChar);
if (separatorIndex < 0) {
- return substring;
+ return null;
} else {
return substring.substring(0, separatorIndex);
}
Modified: branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxEventOptions.java
===================================================================
--- branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxEventOptions.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/renderkit/AjaxEventOptions.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -21,6 +21,7 @@
package org.richfaces.renderkit;
+import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -40,8 +41,8 @@
private Map<String, Object> options = new HashMap<String, Object>();
- public void appendScript(StringBuffer functionString) {
- functionString.append(ScriptUtils.toScript(options));
+ public void appendScript(Appendable target) throws IOException {
+ ScriptUtils.appendScript(target, options);
}
public boolean isEmpty() {
Modified: branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
===================================================================
--- branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -299,7 +299,7 @@
}
if (isChained) {
- result.insert(0, "jsf.util.chain(this, event, ");
+ result.insert(0, "return jsf.util.chain(this, event, ");
result.append(")");
}
@@ -326,6 +326,8 @@
return false;
} else if (attributeValue instanceof Long && (Long) attributeValue == Long.MIN_VALUE) {
return false;
+ } else if (attributeValue instanceof Collection<?> || attributeValue instanceof Map<?, ?>) {
+ return true;
}
return attributeValue.toString().length() > 0;
@@ -382,6 +384,8 @@
}
}
+ //TODO - create special method for event handlers that will return String?
+ //TODO - add check for 'disabled'?
public static Object getAttributeAndBehaviorsValue(FacesContext facesContext, UIComponent component,
ComponentAttribute componentAttribute) {
if (facesContext == null) {
@@ -699,6 +703,51 @@
return path;
}
+ public static String getResourceURL(String url, FacesContext context) {
+ if (null == url) {
+ return null;
+ }
+
+ String value = url;
+
+ value = context.getApplication().getViewHandler().getResourceURL(context, value);
+
+ return context.getExternalContext().encodeResourceURL(value);
+ }
+
+ public static Object getFirstNonEmptyAttribute(String attributeName, UIComponent component) {
+ Object attributeValue = component.getAttributes().get(attributeName);
+
+ return !isEmpty(attributeValue) ? attributeValue : null;
+ }
+
+ public static Object getFirstNonEmptyAttribute(String attributeName, UIComponent componentA, UIComponent componentB) {
+ Object attributeValue = componentA.getAttributes().get(attributeName);
+
+ if (!isEmpty(attributeValue)) {
+ return attributeValue;
+ }
+
+ attributeValue = componentB.getAttributes().get(attributeName);
+
+ if (!isEmpty(attributeValue)) {
+ return attributeValue;
+ }
+
+ return null;
+ }
+
+ public static Object getFirstNonEmptyAttribute(String attributeName, UIComponent... components) {
+ for (UIComponent component : components) {
+ Object attributeValue = component.getAttributes().get(attributeName);
+ if (!isEmpty(attributeValue)) {
+ return attributeValue;
+ }
+ }
+
+ return null;
+ }
+
@SuppressWarnings("serial")
public static final class Attributes extends TreeSet<ComponentAttribute> {
Modified: branches/RF-8742-1/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java
===================================================================
--- branches/RF-8742-1/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -199,10 +199,10 @@
ClientBehaviorHolder behaviorHolder = createMockClientBehaviorHolder();
UIComponent component = (UIComponent) behaviorHolder;
- responseWriter.writeAttribute(eq("onkeypress"), eq("jsf.util.chain(this, event, 'alert(keypress)','prompt(keypress)')"),
+ responseWriter.writeAttribute(eq("onkeypress"), eq("return jsf.util.chain(this, event, 'alert(keypress)','prompt(keypress)')"),
EasyMock.<String>isNull());
responseWriter.writeAttribute(eq("onclick"),
- eq("jsf.util.chain(this, event, 'alert(click)','prompt(action1)','prompt(action2)')"), EasyMock.<String>isNull());
+ eq("return jsf.util.chain(this, event, 'alert(click)','prompt(action1)','prompt(action2)')"), EasyMock.<String>isNull());
responseWriter.writeAttribute(eq("onmousemove"), eq("alert(mousemove)"), EasyMock.<String>isNull());
responseWriter.writeAttribute(eq("oncontextmenu"), eq("prompt(contextmenu)"), EasyMock.<String>isNull());
@@ -249,7 +249,7 @@
componentAttributes.put("disabled", Boolean.FALSE);
UIComponent component = setupBehaviorsTestForDisabledComponent();
- responseWriter.writeAttribute(eq("onclick"), eq("jsf.util.chain(this, event, 'alert(click)','prompt(action1)')"),
+ responseWriter.writeAttribute(eq("onclick"), eq("return jsf.util.chain(this, event, 'alert(click)','prompt(action1)')"),
EasyMock.<String>isNull());
responseWriter.writeAttribute(eq("onmousemove"),
eq("alert(mousemove)"), EasyMock.<String>isNull());
Modified: branches/RF-8742-1/ui/core/ui/src/main/java/org/richfaces/renderkit/AjaxFunctionRendererBase.java
===================================================================
--- branches/RF-8742-1/ui/core/ui/src/main/java/org/richfaces/renderkit/AjaxFunctionRendererBase.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/core/ui/src/main/java/org/richfaces/renderkit/AjaxFunctionRendererBase.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -23,19 +23,20 @@
package org.richfaces.renderkit;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIParameter;
+import javax.faces.context.FacesContext;
+
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.renderkit.util.AjaxRendererUtils;
-import javax.faces.FacesException;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIParameter;
-import javax.faces.context.FacesContext;
-import java.util.Iterator;
-import java.util.Map;
-
/**
* @author shura
*
@@ -48,7 +49,7 @@
throw new FacesException("Value of 'name' attribute of a4j:jsFunction component is null!");
}
- StringBuffer script = new StringBuffer(functionName).append("=");
+ StringBuilder script = new StringBuilder(functionName).append("=");
JSFunctionDefinition func = new JSFunctionDefinition();
// func.setName(component.getName());
@@ -94,7 +95,7 @@
// TODO - added in 4.0 - ?
func.addParameter(JSReference.EVENT);
func.addToBody(ajaxFunction.toScript());
- func.appendScript(script);
+ func.appendScriptToStringBuilder(script);
return script.toString();
}
Modified: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/component/AbstractCalendar.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -22,16 +22,24 @@
package org.richfaces.component;
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import javax.el.ELContext;
import javax.el.ValueExpression;
import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UIViewRoot;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;
import javax.faces.event.AbortProcessingException;
@@ -43,22 +51,28 @@
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.context.ExtendedVisitContext;
+import org.richfaces.context.ExtendedVisitContextMode;
+import org.richfaces.event.CurrentDateChangeEvent;
+import org.richfaces.event.CurrentDateChangeListener;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
+import org.richfaces.model.CalendarDataModel;
+import org.richfaces.model.CalendarDataModelItem;
+import org.richfaces.renderkit.MetaComponentRenderer;
import org.richfaces.utils.CalendarHelper;
-import org.richfaces.event.CurrentDateChangeEvent;
-import org.richfaces.event.CurrentDateChangeListener;
-
/**
* @author amarkhel
*
*/
@JsfComponent(type = AbstractCalendar.COMPONENT_TYPE, family = AbstractCalendar.COMPONENT_FAMILY, generate = "org.richfaces.component.UICalendar", renderer = @JsfRenderer(type = "org.richfaces.CalendarRenderer"), tag = @Tag(name = "calendar"))
-public abstract class AbstractCalendar extends UIInput {
+public abstract class AbstractCalendar extends UIInput implements MetaComponentResolver, MetaComponentEncoder {
+ public static final String DAYSDATA_META_COMPONENT_ID = "daysData";
+
public static final String COMPONENT_TYPE = "org.richfaces.Calendar";
public static final String COMPONENT_FAMILY = "org.richfaces.Calendar";
@@ -75,7 +89,12 @@
locale
};
+ public enum Modes {
+ CLIENT,
+ AJAX
+ }
+
@Attribute(defaultValue = "MMM d, yyyy")
public abstract String getDatePattern();
@@ -144,6 +163,9 @@
@Attribute(defaultValue = "3")
public abstract int getZindex();
+
+ @Attribute(defaultValue = "client")
+ public abstract String getMode();
@Attribute
public abstract String getStyle();
@@ -184,6 +206,7 @@
@Attribute
public abstract Object getCurrentDate();
+ @Attribute
public abstract void setCurrentDate(Object date);
@Attribute
@@ -194,6 +217,19 @@
@Attribute
public abstract Object getDefaultTime();
+
+ @Attribute(defaultValue = "getDefaultPreloadBegin(getCurrentDateOrDefault())")
+ public abstract Object getPreloadDateRangeBegin();
+
+ public abstract void setPreloadDateRangeBegin(Object date);
+
+ @Attribute(defaultValue = "getDefaultPreloadEnd(getCurrentDateOrDefault())")
+ public abstract Object getPreloadDateRangeEnd();
+
+ public abstract void setPreloadDateRangeEnd(Object date);
+
+ @Attribute
+ public abstract CalendarDataModel getDataModel();
@Attribute(events = @EventName("inputclick"))
public abstract String getOninputclick();
@@ -306,7 +342,46 @@
public CurrentDateChangeListener[] getCurrentDateChangeListeners() {
return (CurrentDateChangeListener[]) getFacesListeners(CurrentDateChangeListener.class);
}
+
+ protected Date getDefaultPreloadBegin(Date date) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Calendar calendar = Calendar.getInstance(getTimeZone(),
+ CalendarHelper.getAsLocale(facesContext, this, getLocale()));
+ calendar.setTime(date);
+ calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
+ return calendar.getTime();
+ }
+ protected Date getDefaultPreloadEnd(Date date) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Calendar calendar = Calendar.getInstance(getTimeZone(),
+ CalendarHelper.getAsLocale(facesContext, this, getLocale()));
+ calendar.setTime(date);
+ calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
+ /*
+ * //force recalculation calendar.getTimeInMillis();
+ * calendar.set(Calendar.DAY_OF_WEEK, getLastDayOfWeek(calendar));
+ */
+ return calendar.getTime();
+ }
+
+ public Date getCurrentDateOrDefault() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ Date date = CalendarHelper.getAsDate(facesContext, this, getCurrentDate());
+
+ if (date != null) {
+ return date;
+ } else {
+ Date value = CalendarHelper.getAsDate(facesContext, this, this.getValue());
+ if (value != null) {
+ return value;
+ } else {
+ return java.util.Calendar.getInstance(getTimeZone()).getTime();
+ }
+ }
+ }
+
public void broadcast(FacesEvent event) throws AbortProcessingException {
if (event instanceof CurrentDateChangeEvent) {
FacesContext facesContext = getFacesContext();
@@ -348,4 +423,110 @@
event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
}
}
+
+ public String resolveClientId(FacesContext facesContext, UIComponent contextComponent, String metaComponentId) {
+ if (DAYSDATA_META_COMPONENT_ID.equals(metaComponentId)) {
+ return getClientId(facesContext) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
+ }
+ return null;
+ }
+
+ public String substituteUnresolvedClientId(FacesContext facesContext, UIComponent contextComponent,
+ String metaComponentId) {
+ return null;
+ }
+
+ @Override
+ public boolean visitTree(VisitContext context, VisitCallback callback) {
+ if (context instanceof ExtendedVisitContext) {
+ ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext) context;
+ if (extendedVisitContext.getVisitMode() == ExtendedVisitContextMode.RENDER) {
+
+ VisitResult result = extendedVisitContext.invokeMetaComponentVisitCallback(this, callback,
+ DAYSDATA_META_COMPONENT_ID);
+ if (result == VisitResult.COMPLETE) {
+ return true;
+ } else if (result == VisitResult.REJECT) {
+ return false;
+ }
+ }
+ }
+
+ return super.visitTree(context, callback);
+ }
+
+ public void encodeMetaComponent(FacesContext context, String metaComponentId) throws IOException {
+ ((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this, metaComponentId);
+ }
+
+ public Object getPreload() {
+ Date[] preloadDateRange = getPreloadDateRange();
+ if (preloadDateRange != null && preloadDateRange.length != 0) {
+ CalendarDataModel calendarDataModel = (CalendarDataModel) getDataModel();
+ if (calendarDataModel != null) {
+ CalendarDataModelItem[] calendarDataModelItems = calendarDataModel
+ .getData(preloadDateRange);
+
+ HashMap<String, Object> args = new HashMap<String, Object>();
+
+ args.put("startDate", formatStartDate(preloadDateRange[0]));
+ args.put("days", calendarDataModelItems);
+ return args;
+ }
+ }
+ return null;
+ }
+
+ public static Object formatStartDate(Date date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(date);
+ HashMap <String, Object> hashDate = new HashMap<String,Object>();
+ hashDate.put("month", calendar.get(Calendar.MONTH));
+ hashDate.put("year", calendar.get(Calendar.YEAR));
+ return hashDate;
+ }
+
+ public Date[] getPreloadDateRange() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ Date dateRangeBegin = null;
+ Date dateRangeEnd = null;
+
+ if (Modes.AJAX.toString().equalsIgnoreCase(getMode())) {
+ dateRangeBegin = CalendarHelper.getAsDate(facesContext, this,
+ getDefaultPreloadBegin((Date) getCurrentDate()));
+ dateRangeEnd = CalendarHelper.getAsDate(facesContext, this,
+ getDefaultPreloadEnd((Date) getCurrentDate()));
+ } else {
+ dateRangeBegin = CalendarHelper.getAsDate(facesContext, this, getPreloadDateRangeBegin());
+ dateRangeEnd = CalendarHelper.getAsDate(facesContext, this, getPreloadDateRangeEnd());
+ }
+
+ if (dateRangeBegin == null && dateRangeEnd == null) {
+ return null;
+ } else {
+ if (dateRangeBegin.after(dateRangeEnd)) {
+ // XXX add message
+ FacesMessage message = new FacesMessage(
+ "preloadDateRangeBegin is greater than preloadDateRangeEnd");
+ message.setSeverity(FacesMessage.SEVERITY_ERROR);
+ facesContext.addMessage(getClientId(facesContext), message);
+ throw new IllegalArgumentException();
+ }
+
+ List<Date> dates = new ArrayList<Date>();
+
+ Calendar calendar = Calendar.getInstance(this.getTimeZone(), CalendarHelper.getAsLocale(facesContext, this, this.getLocale()));
+ Calendar calendar2 = (Calendar) calendar.clone();
+ calendar.setTime(dateRangeBegin);
+ calendar2.setTime(dateRangeEnd);
+
+ do {
+ dates.add(calendar.getTime());
+ calendar.add(Calendar.DATE, 1);
+ } while (!calendar.after(calendar2));
+
+ return (Date[]) dates.toArray(new Date[dates.size()]);
+ }
+ }
}
Copied: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model (from rev 20107, trunk/ui/input/ui/src/main/java/org/richfaces/model)
Deleted: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,40 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.model;
-
-import java.util.Date;
-/**
- * @author Alexej Kushunin
- * created 19.06.2007
- *
- */
-public interface CalendarDataModel {
- /**
- * @return array of CalendarDataModelItems for selected dates.
- * This method will be called every time when components will need next
- * block of CalendarDataItems.
- * That may happens when calendar rendered, or when user navigate to
- * next(previous) month or in any other case when calendar renders.
- * This method will be called in Ajax mode when Calendar renders new page.
- * */
- CalendarDataModelItem[] getData(Date[] dateArray);
-
-}
Copied: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java (from rev 20107, trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java)
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java (rev 0)
+++ branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModel.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,40 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.model;
+
+import java.util.Date;
+/**
+ * @author Alexej Kushunin
+ * created 19.06.2007
+ *
+ */
+public interface CalendarDataModel {
+ /**
+ * @return array of CalendarDataModelItems for selected dates.
+ * This method will be called every time when components will need next
+ * block of CalendarDataItems.
+ * That may happens when calendar rendered, or when user navigate to
+ * next(previous) month or in any other case when calendar renders.
+ * This method will be called in Ajax mode when Calendar renders new page.
+ * */
+ CalendarDataModelItem[] getData(Date[] dateArray);
+
+}
Deleted: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,47 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.richfaces.model;
-
-
-
-/**
- * @author Alexej Kushunin
- * created 19.06.2007
- *
- */
-
-public interface CalendarDataModelItem {
- /**
- *@return true if date is �selectable� on calendar, default
- *implementation return true
- **/
- boolean isEnabled();
-
- /**
- * @return String that will be appended to style class for that date span.
- * For example it may be �relevant holyday� � that mean class will be like �rich-cal-day relevant holyday�.
- * Default implementation return empty string.
- * */
- public String getStyleClass();
-}
-
-
-
Copied: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java (from rev 20107, trunk/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java)
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java (rev 0)
+++ branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/model/CalendarDataModelItem.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,47 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.richfaces.model;
+
+
+
+/**
+ * @author Alexej Kushunin
+ * created 19.06.2007
+ *
+ */
+
+public interface CalendarDataModelItem {
+ /**
+ *@return true if date is �selectable� on calendar, default
+ *implementation return true
+ **/
+ boolean isEnabled();
+
+ /**
+ * @return String that will be appended to style class for that date span.
+ * For example it may be �relevant holyday� � that mean class will be like �rich-cal-day relevant holyday�.
+ * Default implementation return empty string.
+ * */
+ public String getStyleClass();
+}
+
+
+
Modified: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -64,7 +64,7 @@
public void encodeItem(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
encodeItemBegin(facesContext, component);
- writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-opt rf-au-fnt rf-au-inp", null);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-itm rf-au-opt rf-au-fnt rf-au-inp", null);
for (UIComponent child : component.getChildren()) {
child.encodeAll(facesContext);
}
Modified: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -22,7 +22,7 @@
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.startElement(HtmlConstants.UL_ELEMENT, component);
responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE, getContainerElementId(facesContext, component), null);
- responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-list-ul", null);
+ responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-lst-ul", null);
}
public void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws IOException {
@@ -43,7 +43,7 @@
public void encodeItem(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
encodeItemBegin(facesContext, component);
- writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-opt rf-au-fnt rf-au-inp", null);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-itm rf-au-opt rf-au-fnt rf-au-inp", null);
for (UIComponent child : component.getChildren()) {
child.encodeAll(facesContext);
}
Modified: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -212,7 +212,7 @@
} else {
if (item != null) {
strategy.encodeItemBegin(facesContext, comboBox);
- writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-opt rf-au-fnt rf-au-inp", null);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-itm rf-au-opt rf-au-fnt rf-au-inp", null);
// TODO nick - use converter
String value = null;
if (comboBox.getItemConverter() != null) {
Modified: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -25,6 +25,7 @@
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.startElement(HtmlConstants.TABLE_ELEMENT, component);
responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE, getContainerElementId(facesContext, component), null);
+ responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-tbl", null);
responseWriter.startElement(HtmlConstants.TBODY_ELEMENT, component);
}
@@ -37,6 +38,7 @@
public void encodeItemBegin(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
writer.startElement(HtmlConstants.TR_ELEMENT, component);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-itm", null);
writer.startElement(HtmlConstants.TD_ELEM, component);
}
@@ -59,10 +61,11 @@
public void encodeItem(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
writer.startElement(HtmlConstants.TR_ELEMENT, component);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-itm", null);
for (UIComponent child : component.getChildren()) {
if (child instanceof UIColumn) {
encodeItemChildBegin(facesContext, component);
- writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-opt rf-au-fnt rf-au-inp", null);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, "rf-au-fnt rf-au-inp", null);
child.encodeAll(facesContext);
encodeItemChildEnd(facesContext, component);
}
Modified: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/CalendarRendererBase.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -40,18 +40,20 @@
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import javax.faces.context.PartialViewContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.DateTimeConverter;
+import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSReference;
import org.richfaces.component.AbstractCalendar;
+import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.util.HtmlUtil;
import org.richfaces.component.util.MessageUtil;
import org.richfaces.component.util.SelectUtils;
-import org.richfaces.component.util.ViewUtil;
import org.richfaces.event.CurrentDateChangeEvent;
import org.richfaces.utils.CalendarHelper;
@@ -73,7 +75,7 @@
@ResourceDependency(library = "org.richfaces", name = "calendar-utils.js"),
@ResourceDependency(library = "org.richfaces", name = "calendar.js"),
@ResourceDependency(library = "org.richfaces", name = "calendar.ecss") })
-public class CalendarRendererBase extends InputRendererBase {
+public class CalendarRendererBase extends InputRendererBase implements MetaComponentRenderer {
public static final String CALENDAR_BUNDLE = "org.richfaces.renderkit.calendar";
@@ -146,9 +148,8 @@
public static final String CALENDAR_DISABLE_ICON_RESOURCE_NAME = "disabledCalendarIcon.png";
public static final String CURRENT_DATE_INPUT = "InputCurrentDate";
-
-
+ public static final String OPTION_MODE = "mode";
protected static final Map<String, ComponentAttribute> CALENDAR_INPUT_HANDLER_ATTRIBUTES = Collections.unmodifiableMap(ComponentAttribute.createMap(
@@ -200,7 +201,7 @@
private static final String MINUTES_VALUE = "minutes";
protected void doDecode(FacesContext context, UIComponent component) {
- if(!(component instanceof AbstractCalendar)) {
+ if (!(component instanceof AbstractCalendar)) {
return;
}
@@ -221,6 +222,15 @@
if (selectedDateString != null) {
calendar.setSubmittedValue(selectedDateString);
}
+
+ if (requestParameterMap.get(component.getClientId(context) + ".ajax") != null) {
+ PartialViewContext pvc = context.getPartialViewContext();
+ pvc.getRenderIds().add(
+ component.getClientId(context) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR
+ + AbstractCalendar.DAYSDATA_META_COMPONENT_ID);
+
+ context.renderResponse();
+ }
}
public void renderInputHandlers(FacesContext facesContext, UIComponent component) throws IOException {
@@ -256,7 +266,7 @@
@Override
public String getInputValue(FacesContext facesContext, UIComponent component) {
- if(!(component instanceof AbstractCalendar)) {
+ if (!(component instanceof AbstractCalendar)) {
return null;
}
@@ -290,12 +300,12 @@
public String getButtonIcon(FacesContext facesContext, UIComponent component) {
boolean disable = (Boolean)component.getAttributes().get("disabled");
String buttonIcon = (String)component.getAttributes().get("buttonIcon");
- if(disable) {
+ if (disable) {
buttonIcon = (String)component.getAttributes().get("buttonIconDisabled");
}
if(buttonIcon != null && buttonIcon.trim().length() != 0) {
- buttonIcon = ViewUtil.getResourceURL(buttonIcon, facesContext);
+ buttonIcon = RenderKitUtils.getResourceURL(buttonIcon, facesContext);
} else {
buttonIcon = disable ? CALENDAR_ICON_RESOURCE_NAME: CALENDAR_ICON_RESOURCE_NAME;
buttonIcon = RenderKitUtils.getResourcePath(facesContext, "org.richfaces.images",buttonIcon);
@@ -307,11 +317,11 @@
public Object getSelectedDate(FacesContext facesContext, UIComponent component) throws IOException {
Object returnValue = null;
AbstractCalendar calendar = (AbstractCalendar)component;
- if(calendar.isValid()) {
+ if (calendar.isValid()) {
Date date;
Object value = calendar.getValue();
date = CalendarHelper.getAsDate(facesContext, calendar, value);
- if(date != null) {
+ if (date != null) {
returnValue = formatSelectedDate(calendar.getTimeZone(), date);
}
}
@@ -382,7 +392,6 @@
return ((dayStyleClass != null && dayStyleClass.trim().length() != 0)) ? new JSReference(dayStyleClass) : null;
}
-
public Map<String, Object> getLabels(FacesContext facesContext, AbstractCalendar calendar) {
ResourceBundle bundle1 = null;
ResourceBundle bundle2 = null;
@@ -409,11 +418,11 @@
protected Map<String, Object> getCollectedLabels(ResourceBundle [] bundles , String[] names) {
Map<String, Object> labels = new HashMap<String, Object>();
- if(bundles != null && names != null) {
+ if (bundles != null && names != null) {
for (String name: names) {
String label = null;
String bundleKey = "RICH_CALENDAR_" + name.toUpperCase() + "_LABEL";
- for(ResourceBundle bundle: bundles) {
+ for (ResourceBundle bundle: bundles) {
if (bundle != null) {
try {
label = bundle.getString(bundleKey);
@@ -421,7 +430,7 @@
// Current key was not found, ignore this exception;
}
}
- if(label != null) {
+ if (label != null) {
break;
}
}
@@ -478,36 +487,35 @@
int monthMin = calendar.getActualMinimum(Calendar.MONTH);
String [] weekDayLabels = RenderKitUtils.asArray(calendarComponent.getWeekDayLabels());
- if(weekDayLabels == null) {
+ if (weekDayLabels == null) {
weekDayLabels = dateFormat.getWeekdays();
weekDayLabels = shiftDates(minimum, maximum, weekDayLabels);
}
RenderKitUtils.addToScriptHash(map, WEEK_DAY_LABELS, weekDayLabels);
String [] weekDayLabelsShort = RenderKitUtils.asArray(calendarComponent.getWeekDayLabelsShort());
- if(weekDayLabelsShort == null) {
+ if (weekDayLabelsShort == null) {
weekDayLabelsShort = dateFormat.getShortWeekdays();
weekDayLabelsShort = shiftDates(minimum, maximum, weekDayLabelsShort);
}
RenderKitUtils.addToScriptHash(map, WEEK_DAY_LABELS_SHORT, weekDayLabelsShort);
String [] monthLabels = RenderKitUtils.asArray(calendarComponent.getMonthLabels());
- if(monthLabels == null) {
+ if (monthLabels == null) {
monthLabels = dateFormat.getMonths();
monthLabels = shiftDates(monthMin, monthMax, monthLabels);
}
RenderKitUtils.addToScriptHash(map, MONTH_LABELS, monthLabels);
-
String [] monthLabelsShort = RenderKitUtils.asArray(calendarComponent.getMonthLabelsShort());
- if(monthLabelsShort == null) {
+ if (monthLabelsShort == null) {
monthLabelsShort = dateFormat.getShortMonths();
monthLabelsShort = shiftDates(monthMin, monthMax, monthLabelsShort);
}
RenderKitUtils.addToScriptHash(map, MONTH_LABELS_SHORT, monthLabelsShort);
int minDaysInFirstWeek = calendarComponent.getMinDaysInFirstWeek();
- if(minDaysInFirstWeek == Integer.MIN_VALUE) {
+ if (minDaysInFirstWeek == Integer.MIN_VALUE) {
minDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek();
}
@@ -516,7 +524,7 @@
}
int day = calendarComponent.getFirstWeekDay();
- if(day == Integer.MIN_VALUE) {
+ if (day == Integer.MIN_VALUE) {
day = calendar.getFirstDayOfWeek();
day = calendar.getFirstDayOfWeek() - calendar.getActualMinimum(Calendar.DAY_OF_WEEK);
}
@@ -526,7 +534,6 @@
} else if (day != Integer.MIN_VALUE) {
facesContext.getExternalContext().log(day + " value of firstWeekDay attribute is not a legal one for component: " + MessageUtil.getLabel(facesContext, calendarComponent) + ". Default value was applied.");
}
-
return map;
}
@@ -538,7 +545,7 @@
scriptOptions.addOption(OPTION_READONLY);
scriptOptions.addOption(OPTION_RESET_TIME_ON_DATE_SELECT);
scriptOptions.addOption(OPTION_SHOW_APPLY_BUTTON);
- scriptOptions.addOption(OPTION_POPUP);
+ scriptOptions.addOption(OPTION_POPUP);
scriptOptions.addOption(OPTION_SHOW_INPUT);
scriptOptions.addOption(OPTION_SHOW_HEADER);
scriptOptions.addOption(OPTION_SHOW_FOOTER);
@@ -565,12 +572,13 @@
scriptOptions.addOption("styleClass");
scriptOptions.addOption("style", HtmlUtil.concatStyles("z-index: " + calendar.getZindex(), calendar.getStyle()));
+ scriptOptions.addOption(OPTION_MODE, calendar.getMode());
return scriptOptions;
}
public void buildAddLocaleScript(ResponseWriter writer, FacesContext facesContext, UIComponent component) throws IOException {
- if(component instanceof AbstractCalendar) {
+ if (component instanceof AbstractCalendar) {
AbstractCalendar calendar = (AbstractCalendar)component;
JSFunction function = new JSFunction("RichFaces.ui.Calendar.addLocale", CalendarHelper.getAsLocale(facesContext, calendar).toString(), getLocaleOptions(facesContext, calendar));
writer.write(function.toScript());
@@ -579,12 +587,18 @@
}
public void buildCalendarScript(ResponseWriter writer, FacesContext facesContext, UIComponent component) throws IOException {
- if(component instanceof AbstractCalendar) {
+ if (component instanceof AbstractCalendar) {
AbstractCalendar calendar = (AbstractCalendar)component;
ScriptOptions scriptOptions = createCalendarScriptOption(facesContext, calendar);
JSFunction function = new JSFunction("new RichFaces.ui.Calendar", calendar.getClientId(facesContext), CalendarHelper.getAsLocale(facesContext, calendar).toString(), scriptOptions, "");
StringBuffer scriptBuffer = new StringBuffer();
- scriptBuffer.append(function.toScript()).append(".load();");
+ scriptBuffer.append(function.toScript()).append(".load(");
+ Object preload = calendar.getPreload();
+ if (null != preload){
+ scriptBuffer.append(RenderKitUtils.toScriptArgs(preload));
+ }
+
+ scriptBuffer.append(");");
writer.write(scriptBuffer.toString());
}
}
@@ -599,11 +613,11 @@
}
protected Converter setupConverter(FacesContext facesContext, Converter converter, AbstractCalendar calendar) {
- if(converter == null || calendar == null) {
+ if (converter == null || calendar == null) {
return null;
}
- if(converter instanceof DateTimeConverter) {
+ if (converter instanceof DateTimeConverter) {
DateTimeConverter defaultConverter = (DateTimeConverter) converter;
defaultConverter.setPattern(calendar.getDatePattern());
defaultConverter.setLocale( CalendarHelper.getAsLocale(facesContext, calendar));
@@ -611,5 +625,21 @@
}
return converter;
}
+
+ public void encodeMetaComponent(FacesContext context, UIComponent component, String metaComponentId)
+ throws IOException {
+ if (AbstractCalendar.DAYSDATA_META_COMPONENT_ID.equals(metaComponentId)) {
+ Object preload = ((AbstractCalendar) component).getPreload();
+ if (preload != null) {
+ Map<String, Object> dataMap = AjaxContext.getCurrentInstance(context).getResponseComponentDataMap();
+ dataMap.put(component.getClientId(context), preload);
+ }
+ } else {
+ throw new IllegalArgumentException(metaComponentId);
+ }
+ }
+ public void decodeMetaComponent(FacesContext context, UIComponent component, String metaComponentId) {
+ throw new UnsupportedOperationException();
+ }
}
\ No newline at end of file
Modified: branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/java/org/richfaces/renderkit/ClientSelectItem.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -22,6 +22,8 @@
package org.richfaces.renderkit;
+import java.io.IOException;
+
import org.ajax4jsf.javascript.ScriptString;
import org.ajax4jsf.javascript.ScriptUtils;
@@ -59,14 +61,23 @@
return convertedValue;
}
- public void appendScript(StringBuffer functionString) {
- functionString.append(this.toScript());
+ public void appendScript(Appendable target) throws IOException {
+ target.append(this.toScript());
}
+ public void appendScriptToStringBuilder(StringBuilder stringBuilder) {
+ try {
+ appendScript(stringBuilder);
+ } catch (IOException e) {
+ //ignore
+ }
+ }
+
public String toScript() {
return "{ 'id' : " + ScriptUtils.toScript(clientId)
+ " , 'label' : " + ScriptUtils.toScript(label)
+ ", 'value' : " + ScriptUtils.toScript(convertedValue)
+ "}";
}
+
}
Modified: branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.ecss
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.ecss 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.ecss 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,5 +1,4 @@
-
-.rf-au-inp.rf-au-fnt, .rf-au-opt.rf-au-fnt{
+.rf-au-fnt{
color: '#{richSkin.generalTextColor}';
font-size: '#{richSkin.generalSizeFont}';
font-family: '#{richSkin.generalFamilyFont}';
@@ -72,22 +71,28 @@
min-height: 20px;
}
-.rf-au-opt{
+.rf-au-itm{
+ cursor: default;
padding: 2px;
- white-space: nowrap;
- cursor: default;
- list-style-type: none;
}
-.rf-au-sel{
- padding: 1px;
- width: 100%;
+.rf-au-itm-sel{
background-color: '#{richSkin.headerBackgroundColor}';
border-width: 1px;
border-style: dotted;
border-color: '#{richSkin.generalTextColor}';
+ padding: 1px;
}
+.rf-au-opt{
+ white-space: nowrap;
+ list-style-type: none;
+}
+
+.rf-au-opt-sel{
+ width: 100%;
+}
+
.rf-au-shdw{
border: 0px solid red;
display: inline-block;
@@ -141,4 +146,9 @@
.rf-au-lst-ul{
margin: 0px;
padding: 0px;
+}
+
+.rf-au-tbl{
+ border-spacing: 0px;
+
}
\ No newline at end of file
Modified: branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.js
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.js 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/Autocomplete.js 2010-11-18 23:14:43 UTC (rev 20108)
@@ -115,8 +115,10 @@
var $super = rf.ui.Autocomplete.$super;
var defaultOptions = {
- selectedItemClass:'rf-au-sel',
- itemClass:'rf-au-opt',
+ itemClass:'rf-au-itm',
+ selectedItemClass:'rf-au-itm-sel',
+ subItemClass:'rf-au-opt',
+ selectedSubItemClass:'rf-au-opt-sel',
autofill:true,
minChars:1,
selectFirst:true,
@@ -244,7 +246,10 @@
if (this.items.length==0 || (!isOffset && this.index == index)) return;
if (this.index!=-1) {
- this.items.eq(this.index).removeClass(this.options.selectedItemClass);
+ var element = this.items.eq(this.index)
+ if (element.removeClass(this.options.selectedItemClass).hasClass(this.options.subItemClass)){
+ element.removeClass(this.options.selectedSubItemClass);
+ }
}
if (index==undefined) {
@@ -268,7 +273,9 @@
this.index = index;
}
var item = this.items.eq(this.index);
- item.addClass(this.options.selectedItemClass);
+ if (item.addClass(this.options.selectedItemClass).hasClass(this.options.subItemClass)) {
+ item.addClass(this.options.selectedSubItemClass);
+ }
scrollToSelectedItem.call(this);
if (event &&
event.which != rf.KEYS.BACKSPACE &&
Modified: branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js
===================================================================
--- branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/calendar.js 2010-11-18 23:14:43 UTC (rev 20108)
@@ -261,6 +261,7 @@
selectedDate: null,
currentDate: null,
defaultTime: {hours:12,minutes:0, seconds:0},
+ mode: "client",
hidePopupOnScroll: true
};
@@ -494,6 +495,9 @@
this.scrollElements = null;
//alert(new Date().getTime()-_d.getTime());
+
+ //define isAjaxMode variable
+ "ajax" == this.params.mode ? this.isAjaxMode = true : this.isAjaxMode = false;
};
@@ -1118,10 +1122,12 @@
}
},
- indexData:function(daysData, isAjaxMode) {
- var dateYear = daysData.startDate.getFullYear();
- var dateMonth = daysData.startDate.getMonth();
+ indexData: function(daysData, isAjaxMode) {
+ var dateYear = daysData.startDate.year;
+ var dateMonth = daysData.startDate.month;
+ daysData.startDate = new Date(dateYear,dateMonth)
+
daysData.index = [];
daysData.index[dateYear+'-'+dateMonth] = 0;
if (isAjaxMode)
@@ -1402,12 +1408,31 @@
var formattedDate = rf.calendarUtils.formatDate(this.getCurrentDate(),"MM/yyyy");
rf.getDomElement(this.id+'InputCurrentDate').value=formattedDate;
- if (this.submitFunction)
- this.submitFunction.call(this, formattedDate);
+ if (this.isAjaxMode && this.callAjax)
+ this.callAjax.call(this, formattedDate);
else
this.render();
},
+ callAjax: function(calendar, date) {
+ var _this = this;
+ var ajaxSuccess = function (event) {
+ if (event.componentData && event.componentData[_this.id])
+ {
+ var dataDays=event.componentData[_this.id]
+ _this.load(dataDays, true);
+ }
+ }
+ var ajaxError = function (event) {
+ // do nothing
+ }
+ var params = {};
+ params[this.id + ".ajax"] = "1";
+
+ rf.ajax(this.id, null, {parameters: params, error: ajaxError, complete:ajaxSuccess});
+
+ },
+
nextMonth: function() {
this.changeCurrentDateOffset(0,1);
},
Copied: branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java (from rev 20107, trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+import java.util.Collection;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TreeSelectionChangeEvent extends FacesEvent {
+
+ private static final long serialVersionUID = 6292604445872458007L;
+
+ private Collection<Object> oldSelection;
+
+ private Collection<Object> newSelection;
+
+ public TreeSelectionChangeEvent(UIComponent component, Collection<Object> oldSelection, Collection<Object> newSelection) {
+ super(component);
+
+ this.oldSelection = oldSelection;
+ this.newSelection = newSelection;
+ }
+
+ @Override
+ public boolean isAppropriateListener(FacesListener listener) {
+ return listener instanceof TreeSelectionChangeListener;
+ }
+
+ @Override
+ public void processListener(FacesListener listener) {
+ ((TreeSelectionChangeListener) listener).processSelectionChange(this);
+ }
+
+ public Collection<Object> getOldSelection() {
+ return oldSelection;
+ }
+
+ public Collection<Object> getNewSelection() {
+ return newSelection;
+ }
+
+}
Copied: branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java (from rev 20107, trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeSelectionChangeListener extends FacesListener {
+
+ public void processSelectionChange(TreeSelectionChangeEvent event) throws AbortProcessingException;
+
+}
Copied: branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java (from rev 20107, trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeSelectionChangeSource {
+
+ public void addTreeSelectionChangeListener(TreeSelectionChangeListener listener);
+
+ public void removeTreeSelectionChangeListener(TreeSelectionChangeListener listener);
+
+}
Deleted: branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionEvent.java
===================================================================
--- branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionEvent.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionEvent.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,67 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.event;
-
-import java.util.Collection;
-
-import javax.faces.component.UIComponent;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.FacesListener;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class TreeSelectionEvent extends FacesEvent {
-
- private static final long serialVersionUID = 6292604445872458007L;
-
- private Collection<Object> oldSelection;
-
- private Collection<Object> newSelection;
-
- public TreeSelectionEvent(UIComponent component, Collection<Object> oldSelection, Collection<Object> newSelection) {
- super(component);
-
- this.oldSelection = oldSelection;
- this.newSelection = newSelection;
- }
-
- @Override
- public boolean isAppropriateListener(FacesListener listener) {
- return listener instanceof TreeSelectionListener;
- }
-
- @Override
- public void processListener(FacesListener listener) {
- ((TreeSelectionListener) listener).processSelection(this);
- }
-
- public Collection<Object> getOldSelection() {
- return oldSelection;
- }
-
- public Collection<Object> getNewSelection() {
- return newSelection;
- }
-
-}
Deleted: branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionListener.java
===================================================================
--- branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionListener.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionListener.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,34 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.event;
-
-import javax.faces.event.FacesListener;
-
-/**
- * @author Nick Belaevski
- *
- */
-public interface TreeSelectionListener extends FacesListener {
-
- public void processSelection(TreeSelectionEvent event);
-
-}
Modified: branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleListener.java
===================================================================
--- branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleListener.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleListener.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -21,6 +21,7 @@
*/
package org.richfaces.event;
+import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesListener;
/**
@@ -29,6 +30,6 @@
*/
public interface TreeToggleListener extends FacesListener {
- public void processToggle(TreeToggleEvent event);
+ public void processToggle(TreeToggleEvent event) throws AbortProcessingException;
}
Copied: branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java (from rev 20107, trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeToggleSource {
+
+ public void addTreeToggleListener(TreeToggleListener listener);
+
+ public void removeTreeToggleListener(TreeToggleListener listener);
+
+}
Modified: branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java
===================================================================
--- branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/SwingTreeNodeImpl.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -28,6 +28,8 @@
import javax.swing.tree.TreeNode;
+import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.Iterators;
/**
@@ -99,4 +101,12 @@
public List<TreeNode> getChildrenList() {
return children;
}
+
+ @Override
+ public String toString() {
+ ToStringHelper toStringHelper = Objects.toStringHelper(this);
+ toStringHelper.add("data", data);
+
+ return toStringHelper.toString();
+ }
}
Modified: branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java
===================================================================
--- branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -21,8 +21,11 @@
*/
package org.richfaces.model;
-import java.util.Iterator;
+import javax.faces.context.FacesContext;
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.Range;
+
/**
* @author Nick Belaevski
*
@@ -36,10 +39,16 @@
public boolean isDataAvailable();
+ public boolean isLeaf();
+
public E getData();
- public Iterator<Object> getChildrenRowKeysIterator(Object rowKey);
+ public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument);
+
+ public void enterNode(DataVisitor visitor);
+ public void exitNode(DataVisitor visitor);
+
public Object getParentRowKey(Object rowKey);
public Object getWrappedData();
Copied: branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java (from rev 20107, trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.model;
+
+import org.ajax4jsf.model.DataVisitor;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeDataVisitor extends DataVisitor {
+
+ public void enterNode();
+
+ public void exitNode();
+
+}
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/config (from rev 20107, trunk/ui/iteration/ui/src/main/config)
Deleted: branches/RF-8742-1/ui/iteration/ui/src/main/config/faces-config.xml
===================================================================
--- trunk/ui/iteration/ui/src/main/config/faces-config.xml 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/config/faces-config.xml 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
- xmlns:cdk="http://jboss.org/schema/richfaces/cdk/extensions"
- version="2.0">
-
- <faces-config-extension>
- <cdk:faces-event>
- <cdk:event-class>org.richfaces.event.TreeToggleEvent</cdk:event-class>
- <cdk:listener-class>org.richfaces.event.TreeToggleListener</cdk:listener-class>
- <cdk:source-class>org.richfaces.event.TreeToggleSource</cdk:source-class>
- <cdk:listener-method>processToggle</cdk:listener-method>
- <cdk:tag>
- <cdk:tag-name>treeToggleListener</cdk:tag-name>
- <cdk:tag-type>Facelets</cdk:tag-type>
- <cdk:handler-class>org.richfaces.view.facelets.TreeToggleListenerHandler</cdk:handler-class>
- <cdk:generate>true</cdk:generate>
- </cdk:tag>
- </cdk:faces-event>
-
- <cdk:faces-event>
- <cdk:event-class>org.richfaces.event.TreeSelectionChangeEvent</cdk:event-class>
- <cdk:listener-class>org.richfaces.event.TreeSelectionChangeListener</cdk:listener-class>
- <cdk:source-class>org.richfaces.event.TreeSelectionChangeSource</cdk:source-class>
- <cdk:listener-method>processSelectionChange</cdk:listener-method>
- <cdk:tag>
- <cdk:tag-name>treeSelectionChangeListener</cdk:tag-name>
- <cdk:tag-type>Facelets</cdk:tag-type>
- <cdk:handler-class>org.richfaces.view.facelets.TreeSelectionChangeListenerHandler</cdk:handler-class>
- <cdk:generate>true</cdk:generate>
- </cdk:tag>
- </cdk:faces-event>
- </faces-config-extension>
-
-</faces-config>
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/config/faces-config.xml (from rev 20107, trunk/ui/iteration/ui/src/main/config/faces-config.xml)
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/config/faces-config.xml (rev 0)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/config/faces-config.xml 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+ xmlns:cdk="http://jboss.org/schema/richfaces/cdk/extensions"
+ version="2.0">
+
+ <faces-config-extension>
+ <cdk:faces-event>
+ <cdk:event-class>org.richfaces.event.TreeToggleEvent</cdk:event-class>
+ <cdk:listener-class>org.richfaces.event.TreeToggleListener</cdk:listener-class>
+ <cdk:source-class>org.richfaces.event.TreeToggleSource</cdk:source-class>
+ <cdk:listener-method>processToggle</cdk:listener-method>
+ <cdk:tag>
+ <cdk:tag-name>treeToggleListener</cdk:tag-name>
+ <cdk:tag-type>Facelets</cdk:tag-type>
+ <cdk:handler-class>org.richfaces.view.facelets.TreeToggleListenerHandler</cdk:handler-class>
+ <cdk:generate>true</cdk:generate>
+ </cdk:tag>
+ </cdk:faces-event>
+
+ <cdk:faces-event>
+ <cdk:event-class>org.richfaces.event.TreeSelectionChangeEvent</cdk:event-class>
+ <cdk:listener-class>org.richfaces.event.TreeSelectionChangeListener</cdk:listener-class>
+ <cdk:source-class>org.richfaces.event.TreeSelectionChangeSource</cdk:source-class>
+ <cdk:listener-method>processSelectionChange</cdk:listener-method>
+ <cdk:tag>
+ <cdk:tag-name>treeSelectionChangeListener</cdk:tag-name>
+ <cdk:tag-type>Facelets</cdk:tag-type>
+ <cdk:handler-class>org.richfaces.view.facelets.TreeSelectionChangeListenerHandler</cdk:handler-class>
+ <cdk:generate>true</cdk:generate>
+ </cdk:tag>
+ </cdk:faces-event>
+ </faces-config-extension>
+
+</faces-config>
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -26,35 +26,56 @@
import java.util.HashSet;
import java.util.Iterator;
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.MethodExpression;
import javax.el.ValueExpression;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
+import javax.faces.component.UpdateModelException;
+import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ExceptionQueuedEvent;
+import javax.faces.event.ExceptionQueuedEventContext;
import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
import javax.swing.tree.TreeNode;
import org.ajax4jsf.model.DataComponentState;
import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
+import org.richfaces.application.MessageFactory;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.appplication.FacesMessages;
import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Signature;
import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.component.util.MessageUtil;
import org.richfaces.context.ExtendedVisitContext;
import org.richfaces.context.ExtendedVisitContextMode;
import org.richfaces.convert.SequenceRowKeyConverter;
-import org.richfaces.event.TreeSelectionEvent;
-import org.richfaces.event.TreeSelectionListener;
+import org.richfaces.event.TreeSelectionChangeEvent;
+import org.richfaces.event.TreeSelectionChangeListener;
+import org.richfaces.event.TreeSelectionChangeSource;
+import org.richfaces.event.TreeToggleEvent;
+import org.richfaces.event.TreeToggleListener;
+import org.richfaces.event.TreeToggleSource;
import org.richfaces.model.ExtendedTreeDataModelImpl;
import org.richfaces.model.SwingTreeNodeDataModelImpl;
import org.richfaces.model.TreeDataModel;
import org.richfaces.renderkit.MetaComponentRenderer;
import com.google.common.base.Predicate;
+import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
@@ -65,19 +86,22 @@
@JsfComponent(
type = AbstractTree.COMPONENT_TYPE,
family = AbstractTree.COMPONENT_FAMILY,
- tag = @Tag(name = "tree"),
- renderer = @JsfRenderer(type = "org.richfaces.TreeRenderer")
+ tag = @Tag(name = "tree", handler = "org.richfaces.view.facelets.TreeHandler"),
+ renderer = @JsfRenderer(type = "org.richfaces.TreeRenderer"),
+ attributes = {"events-props.xml", "core-props.xml", "i18n-props.xml"}
)
-public abstract class AbstractTree extends UIDataAdaptor implements MetaComponentResolver, MetaComponentEncoder {
+public abstract class AbstractTree extends UIDataAdaptor implements MetaComponentResolver, MetaComponentEncoder, TreeSelectionChangeSource, TreeToggleSource {
public static final String COMPONENT_TYPE = "org.richfaces.Tree";
public static final String COMPONENT_FAMILY = "org.richfaces.Tree";
public static final String SELECTION_META_COMPONENT_ID = "selection";
-
+
+ private static final String DEFAULT_TREE_NODE_CREATED = AbstractTree.class.getName() + ":DEFAULT_TREE_NODE_CREATED";
+
private static final class MatchingTreeNodePredicate implements Predicate<UIComponent> {
-
+
private String type;
public MatchingTreeNodePredicate(String type) {
@@ -89,20 +113,16 @@
if (!(input instanceof AbstractTreeNode)) {
return false;
}
-
- if (!input.isRendered()) {
- return false;
- }
-
+
String nodeType = ((AbstractTreeNode) input).getType();
if (type == null && nodeType == null) {
return true;
}
-
+
return type != null && type.equals(nodeType);
}
};
-
+
private static final Converter ROW_KEY_CONVERTER = new SequenceRowKeyConverter();
/**
@@ -119,6 +139,12 @@
selection
}
+ @Attribute(generate = false, signature = @Signature(returnType = Void.class, parameters = TreeSelectionChangeEvent.class))
+ private MethodExpression selectionChangeListener;
+
+ @Attribute(generate = false, signature = @Signature(returnType = Void.class, parameters = TreeToggleListener.class))
+ private MethodExpression toggleListener;
+
public AbstractTree() {
setKeepSaved(true);
setRendererType("org.richfaces.TreeRenderer");
@@ -128,28 +154,53 @@
public abstract boolean isImmediate();
- @Override
- public String getFamily() {
- return COMPONENT_FAMILY;
- }
+ public abstract String getIconLeaf();
+ public abstract String getIconExpanded();
+
+ public abstract String getIconCollapsed();
+
+ public abstract String getNodeClass();
+
+ public abstract String getHandleClass();
+
+ public abstract String getIconClass();
+
+ public abstract String getLabelClass();
+
+ @Attribute(events = @EventName("nodetoggle"))
+ public abstract String getOnnodetoggle();
+
+ @Attribute(events = @EventName("beforenodetoggle"))
+ public abstract String getOnbeforenodetoggle();
+
+ @Attribute(events = @EventName("selectionchange"))
+ public abstract String getOnselectionchange();
+
+ @Attribute(events = @EventName("beforeselectionchange"))
+ public abstract String getOnbeforeselectionchange();
+
@Attribute(defaultValue = "SwitchType.DEFAULT")
public abstract SwitchType getToggleType();
@Attribute(defaultValue = "SwitchType.client")
public abstract SwitchType getSelectionType();
-
+
public abstract String getNodeType();
+
+ public abstract String getToggleNodeEvent();
- //TODO - move to template
- public abstract String getStyleClass();
-
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
public Collection<Object> getSelection() {
@SuppressWarnings("unchecked")
Collection<Object> selection = (Collection<Object>) getStateHelper().eval(PropertyKeys.selection);
if (selection == null) {
selection = new HashSet<Object>();
-
+
ValueExpression ve = getValueExpression(PropertyKeys.selection.toString());
if (ve != null) {
ve.setValue(getFacesContext().getELContext(), selection);
@@ -157,14 +208,14 @@
getStateHelper().put(PropertyKeys.selection, selection);
}
}
-
+
return selection;
}
-
+
public void setSelection(Collection<Object> selection) {
getStateHelper().put(PropertyKeys.selection, selection);
}
-
+
@Override
protected ExtendedDataModel<?> createExtendedDataModel() {
ExtendedTreeDataModelImpl<?> model = new ExtendedTreeDataModelImpl<TreeNode>(new SwingTreeNodeDataModelImpl());
@@ -187,21 +238,40 @@
return converter;
}
- public Iterator<Object> getChildrenRowKeysIterator(FacesContext faces, Object rowKey) {
- TreeDataModel<?> dataModel = (TreeDataModel<?>) getExtendedDataModel();
- return dataModel.getChildrenRowKeysIterator(rowKey);
- }
+ public AbstractTreeNode findTreeNodeComponent() {
+ FacesContext facesContext = getFacesContext();
- public AbstractTreeNode findTreeNodeComponent() {
- if (getChildCount() == 0) {
- return null;
+ String nodeType = getNodeType();
+ Iterator<UIComponent> matchingNodes = Iterators.filter(getChildren().iterator(),
+ new MatchingTreeNodePredicate(nodeType));
+
+ boolean hasNodes = matchingNodes.hasNext();
+ if (hasNodes) {
+ Iterator<UIComponent> renderedTreeNodes = Iterators.filter(matchingNodes, ComponentPredicates.isRendered());
+ if (renderedTreeNodes.hasNext()) {
+ return (AbstractTreeNode) renderedTreeNodes.next();
+ } else {
+ return null;
+ }
}
- Iterator<UIComponent> iterator = Iterators.filter(getChildren().iterator(),
- new MatchingTreeNodePredicate(getNodeType()));
-
- if (iterator.hasNext()) {
- return (AbstractTreeNode) iterator.next();
+ if (Strings.isNullOrEmpty(nodeType)) {
+ if (getAttributes().put(DEFAULT_TREE_NODE_CREATED, Boolean.TRUE) != null) {
+ return null;
+ }
+
+ Application application = facesContext.getApplication();
+ AbstractTreeNode treeNode = (AbstractTreeNode) application.createComponent(AbstractTreeNode.COMPONENT_TYPE);
+ treeNode.setId("__defaultTreeNode");
+
+ getChildren().add(treeNode);
+
+ UIComponent text = application.createComponent(HtmlOutputText.COMPONENT_TYPE);
+ text.setValueExpression("value", application.getExpressionFactory().createValueExpression(facesContext.getELContext(),
+ "#{" + getVar() + "}", String.class));
+ treeNode.getChildren().add(text);
+
+ return treeNode;
}
return null;
@@ -211,30 +281,85 @@
public void broadcast(FacesEvent event) throws AbortProcessingException {
super.broadcast(event);
- if (event instanceof TreeSelectionEvent) {
- TreeSelectionEvent selectionEvent = (TreeSelectionEvent) event;
-
+ if (event instanceof TreeSelectionChangeEvent) {
+ TreeSelectionChangeEvent selectionEvent = (TreeSelectionChangeEvent) event;
+
final Collection<Object> newSelection = selectionEvent.getNewSelection();
Collection<Object> selectionCollection = getSelection();
-
+
Iterables.removeIf(selectionCollection, new Predicate<Object>() {
public boolean apply(Object input) {
return !newSelection.contains(input);
};
});
-
+
if (!newSelection.isEmpty()) {
Iterables.addAll(selectionCollection, newSelection);
}
+ } else if (event instanceof TreeToggleEvent) {
+ TreeToggleEvent toggleEvent = (TreeToggleEvent) event;
+ AbstractTreeNode treeNodeComponent = findTreeNodeComponent();
+
+ boolean newExpandedValue = toggleEvent.isExpanded();
+
+ FacesContext context = getFacesContext();
+ ValueExpression expression = getValueExpression(AbstractTreeNode.PropertyKeys.expanded.toString());
+ if (expression != null) {
+ ELContext elContext = context.getELContext();
+ Exception caught = null;
+ FacesMessage message = null;
+ try {
+ expression.setValue(elContext, newExpandedValue);
+ } catch (ELException e) {
+ caught = e;
+ String messageStr = e.getMessage();
+ Throwable result = e.getCause();
+ while (null != result &&
+ result.getClass().isAssignableFrom(ELException.class)) {
+ messageStr = result.getMessage();
+ result = result.getCause();
+ }
+ if (null == messageStr) {
+ MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
+ message =
+ messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
+ MessageUtil.getLabel(context, this));
+ } else {
+ message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ messageStr,
+ messageStr);
+ }
+ } catch (Exception e) {
+ caught = e;
+ MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
+ message =
+ messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
+ MessageUtil.getLabel(context, this));
+ }
+ if (caught != null) {
+ assert(message != null);
+ UpdateModelException toQueue = new UpdateModelException(message, caught);
+ ExceptionQueuedEventContext eventContext =
+ new ExceptionQueuedEventContext(context,
+ toQueue,
+ this,
+ PhaseId.UPDATE_MODEL_VALUES);
+ context.getApplication().publishEvent(context,
+ ExceptionQueuedEvent.class,
+ eventContext);
+ }
+ } else {
+ treeNodeComponent.setExpanded(newExpandedValue);
+ }
}
}
-
+
@Override
protected boolean visitFixedChildren(VisitContext visitContext, VisitCallback callback) {
if (visitContext instanceof ExtendedVisitContext) {
ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext) visitContext;
-
+
if (ExtendedVisitContextMode.RENDER == extendedVisitContext.getVisitMode()) {
VisitResult result = extendedVisitContext.invokeMetaComponentVisitCallback(this, callback, SELECTION_META_COMPONENT_ID);
if (result != VisitResult.ACCEPT) {
@@ -245,7 +370,7 @@
return super.visitFixedChildren(visitContext, callback);
}
-
+
void decodeMetaComponent(FacesContext context, String metaComponentId) {
((MetaComponentRenderer) getRenderer(context)).decodeMetaComponent(context, this, metaComponentId);
}
@@ -253,15 +378,15 @@
public void encodeMetaComponent(FacesContext context, String metaComponentId) throws IOException {
((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this, metaComponentId);
}
-
+
public String resolveClientId(FacesContext facesContext, UIComponent contextComponent, String metaComponentId) {
if (SELECTION_META_COMPONENT_ID.equals(metaComponentId)) {
return getClientId(facesContext) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
}
-
+
return null;
}
-
+
public String substituteUnresolvedClientId(FacesContext facesContext, UIComponent contextComponent,
String metaComponentId) {
@@ -277,35 +402,58 @@
return Iterators.<UIComponent>emptyIterator();
}
}
-
+
@Override
public DataComponentState getComponentState() {
return new TreeComponentState();
}
- public void addSelectionListener(TreeSelectionListener listener) {
+ public void addTreeSelectionChangeListener(TreeSelectionChangeListener listener) {
addFacesListener(listener);
}
- public TreeSelectionListener[] getSelectionListeners() {
- return (TreeSelectionListener[]) getFacesListeners(TreeSelectionListener.class);
+ @Attribute(hidden = true)
+ public TreeSelectionChangeListener[] getTreeSelectionChangeListeners() {
+ return (TreeSelectionChangeListener[]) getFacesListeners(TreeSelectionChangeListener.class);
}
-
- public void removeSelectionListener(TreeSelectionListener listener) {
+
+ public void removeTreeSelectionChangeListener(TreeSelectionChangeListener listener) {
removeFacesListener(listener);
}
+ public void addTreeToggleListener(TreeToggleListener listener) {
+ addFacesListener(listener);
+ }
+
@Attribute(hidden = true)
+ public TreeToggleListener[] getTreeToggleListeners() {
+ return (TreeToggleListener[]) getFacesListeners(TreeToggleListener.class);
+ }
+
+ public void removeTreeToggleListener(TreeToggleListener listener) {
+ removeFacesListener(listener);
+ }
+
+ @Attribute(hidden = true)
public boolean isExpanded() {
if (getRowKey() == null) {
return true;
}
-
+
AbstractTreeNode treeNode = findTreeNodeComponent();
if (treeNode == null) {
return false;
}
-
+
return treeNode.isExpanded();
}
+
+ @Attribute(hidden = true)
+ public boolean isLeaf() {
+ if (getRowKey() == null) {
+ return false;
+ }
+
+ return ((TreeDataModel<?>) getExtendedDataModel()).isLeaf();
+ }
}
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -23,36 +23,30 @@
import java.io.IOException;
-import javax.el.ELContext;
-import javax.el.ELException;
+import javax.el.MethodExpression;
import javax.el.ValueExpression;
-import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
-import javax.faces.component.UpdateModelException;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
-import javax.faces.event.ExceptionQueuedEvent;
-import javax.faces.event.ExceptionQueuedEventContext;
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
import org.ajax4jsf.component.IterationStateHolder;
-import org.richfaces.application.MessageFactory;
-import org.richfaces.application.ServiceTracker;
-import org.richfaces.appplication.FacesMessages;
import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Signature;
import org.richfaces.cdk.annotations.Tag;
-import org.richfaces.component.util.MessageUtil;
import org.richfaces.context.ExtendedVisitContext;
import org.richfaces.context.ExtendedVisitContextMode;
import org.richfaces.event.TreeToggleEvent;
import org.richfaces.event.TreeToggleListener;
+import org.richfaces.event.TreeToggleSource;
import org.richfaces.renderkit.MetaComponentRenderer;
/**
@@ -62,10 +56,11 @@
@JsfComponent(
type = AbstractTreeNode.COMPONENT_TYPE,
family = AbstractTreeNode.COMPONENT_FAMILY,
- tag = @Tag(name = "treeNode"),
- renderer = @JsfRenderer(type = "org.richfaces.TreeNodeRenderer")
+ tag = @Tag(name = "treeNode", handler = "org.richfaces.view.facelets.TreeNodeHandler"),
+ renderer = @JsfRenderer(type = "org.richfaces.TreeNodeRenderer"),
+ attributes = {"events-props.xml", "core-props.xml", "i18n-props.xml"}
)
-public abstract class AbstractTreeNode extends UIComponentBase implements MetaComponentResolver, MetaComponentEncoder, IterationStateHolder {
+public abstract class AbstractTreeNode extends UIComponentBase implements MetaComponentResolver, MetaComponentEncoder, IterationStateHolder, TreeToggleSource {
public static final String COMPONENT_TYPE = "org.richfaces.TreeNode";
@@ -73,10 +68,13 @@
public static final String SUBTREE_META_COMPONENT_ID = "subtree";
- private enum PropertyKeys {
+ enum PropertyKeys {
expanded
}
+ @Attribute(generate = false, signature = @Signature(returnType = Void.class, parameters = TreeToggleEvent.class))
+ private MethodExpression toggleListener;
+
public AbstractTreeNode() {
setRendererType("org.richfaces.TreeNodeRenderer");
}
@@ -91,9 +89,24 @@
public abstract String getType();
- //TODO - move to template
- public abstract String getStyleClass();
+ public abstract String getIconLeaf();
+ public abstract String getIconExpanded();
+
+ public abstract String getIconCollapsed();
+
+ public abstract String getHandleClass();
+
+ public abstract String getIconClass();
+
+ public abstract String getLabelClass();
+
+ @Attribute(events = @EventName("toggle"))
+ public abstract String getOntoggle();
+
+ @Attribute(events = @EventName("beforetoggle"))
+ public abstract String getOnbeforetoggle();
+
protected Boolean getLocalExpandedValue(FacesContext facesContext) {
return (Boolean) getStateHelper().get(PropertyKeys.expanded);
}
@@ -152,69 +165,20 @@
if (event instanceof TreeToggleEvent) {
TreeToggleEvent toggleEvent = (TreeToggleEvent) event;
- boolean newExpandedValue = toggleEvent.isExpanded();
-
- FacesContext context = getFacesContext();
- ValueExpression expression = getValueExpression(PropertyKeys.expanded.toString());
- if (expression != null) {
- ELContext elContext = context.getELContext();
- Exception caught = null;
- FacesMessage message = null;
- try {
- expression.setValue(elContext, newExpandedValue);
- } catch (ELException e) {
- caught = e;
- String messageStr = e.getMessage();
- Throwable result = e.getCause();
- while (null != result &&
- result.getClass().isAssignableFrom(ELException.class)) {
- messageStr = result.getMessage();
- result = result.getCause();
- }
- if (null == messageStr) {
- MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
- message =
- messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
- MessageUtil.getLabel(context, this));
- } else {
- message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
- messageStr,
- messageStr);
- }
- } catch (Exception e) {
- caught = e;
- MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
- message =
- messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
- MessageUtil.getLabel(context, this));
- }
- if (caught != null) {
- assert(message != null);
- UpdateModelException toQueue = new UpdateModelException(message, caught);
- ExceptionQueuedEventContext eventContext =
- new ExceptionQueuedEventContext(context,
- toQueue,
- this,
- PhaseId.UPDATE_MODEL_VALUES);
- context.getApplication().publishEvent(context,
- ExceptionQueuedEvent.class,
- eventContext);
- }
- } else {
- setExpanded(newExpandedValue);
- }
+ new TreeToggleEvent(findTreeComponent(), toggleEvent.isExpanded()).queue();
}
}
- public void addToggleListener(TreeToggleListener listener) {
+ public void addTreeToggleListener(TreeToggleListener listener) {
addFacesListener(listener);
}
+ @Attribute(hidden = true)
public TreeToggleListener[] getTreeToggleListeners() {
return (TreeToggleListener[]) getFacesListeners(TreeToggleListener.class);
}
- public void removeToggleListener(TreeToggleListener listener) {
+ public void removeTreeToggleListener(TreeToggleListener listener) {
removeFacesListener(listener);
}
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -50,8 +50,7 @@
return true;
}
- tree.setRowKey(facesContext, rowKey);
- return tree.isExpanded();
+ return !tree.isLeaf() && tree.isExpanded();
}
}
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeSelectionChangeListener.java (from rev 20107, trunk/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeSelectionChangeListener.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeSelectionChangeListener.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeSelectionChangeListener.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+import javax.el.MethodExpression;
+import javax.faces.event.AbortProcessingException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MethodExpressionTreeSelectionChangeListener extends MethodExpressionEventListener implements TreeSelectionChangeListener {
+
+ public MethodExpressionTreeSelectionChangeListener() {
+ super();
+ }
+
+ public MethodExpressionTreeSelectionChangeListener(MethodExpression methodExprOneArg,
+ MethodExpression methodExprZeroArg) {
+ super(methodExprOneArg, methodExprZeroArg);
+ }
+
+ public MethodExpressionTreeSelectionChangeListener(MethodExpression methodExpressionOneArg) {
+ super(methodExpressionOneArg);
+ }
+
+ public void processSelectionChange(TreeSelectionChangeEvent event) throws AbortProcessingException {
+ processEvent(event);
+ }
+
+}
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeToggleListener.java (from rev 20107, trunk/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeToggleListener.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeToggleListener.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeToggleListener.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+import javax.el.MethodExpression;
+import javax.faces.event.AbortProcessingException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MethodExpressionTreeToggleListener extends MethodExpressionEventListener implements TreeToggleListener {
+
+ public MethodExpressionTreeToggleListener() {
+ super();
+ }
+
+ public MethodExpressionTreeToggleListener(MethodExpression methodExprOneArg, MethodExpression methodExprZeroArg) {
+ super(methodExprOneArg, methodExprZeroArg);
+ }
+
+ public MethodExpressionTreeToggleListener(MethodExpression methodExpressionOneArg) {
+ super(methodExpressionOneArg);
+ }
+
+ public void processToggle(TreeToggleEvent event) throws AbortProcessingException {
+ processEvent(event);
+ }
+
+}
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/ExtendedTreeDataModelImpl.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/ExtendedTreeDataModelImpl.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/ExtendedTreeDataModelImpl.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -21,15 +21,11 @@
*/
package org.richfaces.model;
-import java.util.Iterator;
-
import javax.faces.context.FacesContext;
-import org.ajax4jsf.model.DataVisitResult;
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
-import org.richfaces.component.TreeRange;
/**
* @author Nick Belaevski
@@ -52,10 +48,6 @@
return wrappedModel.getData();
}
- public Iterator<Object> getChildrenRowKeysIterator(Object rowKey) {
- return wrappedModel.getChildrenRowKeysIterator(rowKey);
- }
-
public Object getParentRowKey(Object rowKey) {
throw new UnsupportedOperationException();
}
@@ -70,27 +62,11 @@
return wrappedModel.getRowKey();
}
- protected void walk(FacesContext context, DataVisitor visitor, Range range, Object argument, Iterator<Object> keysIterator) {
- while (keysIterator.hasNext()) {
- Object object = (Object) keysIterator.next();
-
- DataVisitResult visitResult = visitor.process(context, object, argument);
- if (visitResult == DataVisitResult.CONTINUE) {
- if (((TreeRange) range).shouldIterateChildren(object)) {
- Iterator<Object> childrenIterator = getChildrenRowKeysIterator(object);
- walk(context, visitor, range, argument, childrenIterator);
- }
- }
- }
- }
-
@Override
public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument) {
- TreeRange treeRange = (TreeRange) range;
- if (treeRange.shouldIterateChildren(null)) {
- Iterator<Object> iterator = getChildrenRowKeysIterator(null);
- walk(context, visitor, range, argument, iterator);
- }
+ wrappedModel.enterNode(visitor);
+ wrappedModel.walk(context, visitor, range, argument);
+ wrappedModel.exitNode(visitor);
}
@Override
@@ -127,5 +103,31 @@
wrappedModel.setWrappedData(data);
}
+ /* (non-Javadoc)
+ * @see org.richfaces.model.TreeDataModel#isLeaf()
+ */
+ public boolean isLeaf() {
+ // TODO Auto-generated method stub
+ return wrappedModel.isLeaf();
+ }
+ /* (non-Javadoc)
+ * @see org.richfaces.model.TreeDataModel#enterNode(org.ajax4jsf.model.DataVisitor)
+ */
+ public void enterNode(DataVisitor visitor) {
+ // TODO Auto-generated method stub
+
+ wrappedModel.enterNode(visitor);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.TreeDataModel#exitNode(org.ajax4jsf.model.DataVisitor)
+ */
+ public void exitNode(DataVisitor visitor) {
+ // TODO Auto-generated method stub
+
+ wrappedModel.exitNode(visitor);
+ }
+
+
}
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -49,6 +49,24 @@
return new SequenceRowKey<T>(ObjectArrays.concat(simpleKeys, segment));
}
+ public T getLastKeySegment() {
+ if (simpleKeys.length == 0) {
+ return null;
+ }
+
+ return simpleKeys[simpleKeys.length - 1];
+ }
+
+ public SequenceRowKey<T> getParent() {
+ if (simpleKeys.length == 0) {
+ return null;
+ }
+
+ T[] parentSimpleKeys = ObjectArrays.newArray(simpleKeys, simpleKeys.length - 1);
+ System.arraycopy(simpleKeys, 0, parentSimpleKeys, 0, parentSimpleKeys.length);
+ return new SequenceRowKey<T>(parentSimpleKeys);
+ }
+
@Override
public int hashCode() {
final int prime = 31;
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -23,25 +23,29 @@
import java.util.Iterator;
+import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
+
/**
* @author Nick Belaevski
*
*/
-public class SequenceRowKeyIterator<T> implements Iterator<Object> {
+public abstract class SequenceRowKeyIterator<K, T> implements Iterator<Object> {
- private int counter = 0;
+ private SequenceRowKey<K> baseKey;
- private SequenceRowKey<Integer> baseKey;
-
private Iterator<T> itr;
private T element;
- private SequenceRowKey<Integer> elementKey;
+ private SequenceRowKey<K> elementKey;
+
+ private T baseElement;
- public SequenceRowKeyIterator(SequenceRowKey<Integer> baseKey, Iterator<T> itr) {
+ public SequenceRowKeyIterator(SequenceRowKey<K> baseKey, T baseElement, Iterator<T> itr) {
super();
this.baseKey = baseKey;
+ this.baseElement = baseElement;
this.itr = itr;
}
@@ -49,10 +53,17 @@
return itr.hasNext();
}
+ protected abstract K nextKey();
+
public Object next() {
element = itr.next();
- elementKey = baseKey.append(counter++);
+ if (baseKey != null) {
+ elementKey = baseKey.append(nextKey());
+ } else {
+ elementKey = new SequenceRowKey<K>(nextKey());
+ }
+
return elementKey;
}
@@ -60,7 +71,15 @@
return element;
}
- public SequenceRowKey<Integer> getElementKey() {
+ public SequenceRowKey<K> getBaseKey() {
+ return baseKey;
+ }
+
+ public T getBaseElement() {
+ return baseElement;
+ }
+
+ public SequenceRowKey<K> getElementKey() {
return elementKey;
}
@@ -68,4 +87,12 @@
throw new UnsupportedOperationException();
}
+ @Override
+ public String toString() {
+ ToStringHelper helper = Objects.toStringHelper(this);
+
+ helper.add("element", element).add("elementKey", elementKey);
+
+ return helper.toString();
+ }
}
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -36,13 +36,46 @@
* @author Nick Belaevski
*
*/
-public class SwingTreeNodeDataModelImpl implements TreeDataModel<TreeNode> {
+public class SwingTreeNodeDataModelImpl extends TreeSequenceKeyModel<Integer, TreeNode> {
/**
* @author Nick Belaevski
*
*/
+ private static final class SwingTreeNodeRowKeyIterator extends SequenceRowKeyIterator<Integer, TreeNode> {
+
+ private int counter = 0;
+
+ /**
+ * @param baseKey
+ * @param baseElement
+ * @param itr
+ */
+ private SwingTreeNodeRowKeyIterator(SequenceRowKey<Integer> baseKey, TreeNode baseElement,
+ Iterator<TreeNode> itr) {
+ super(baseKey, baseElement, itr);
+ }
+
+ @Override
+ protected Integer nextKey() {
+ return counter++;
+ }
+ }
+
+
+ /**
+ * @author Nick Belaevski
+ *
+ */
private final class FakeRootNode implements TreeNode {
+
+ private Collection<TreeNode> wrappedData;
+
+ public FakeRootNode(Collection<TreeNode> wrappedData) {
+ super();
+ this.wrappedData = wrappedData;
+ }
+
public boolean isLeaf() {
return !wrappedData.isEmpty();
}
@@ -86,21 +119,13 @@
return Iterators.asEnumeration(wrappedData.iterator());
}
+
+ public Collection<TreeNode> getWrappedData() {
+ return wrappedData;
+ }
}
- private static final SequenceRowKey<Integer> EMPTY_SEQUENCE_ROW_KEY = new SequenceRowKey<Integer>();
-
- private Collection<TreeNode> wrappedData = null;
-
- private TreeNode fakeRootNode = new FakeRootNode();
-
- private TreeNode selectedNode;
-
- private SequenceRowKey<Integer> selectedRowKey;
-
- private Iterator<TreeNode> findChildren(SequenceRowKey<Integer> compositeKey) {
- TreeNode treeNode = findNode(compositeKey);
-
+ private Iterator<TreeNode> safeGetChildren(SequenceRowKey<Integer> key, TreeNode treeNode) {
if (treeNode == null) {
return Iterators.emptyIterator();
}
@@ -108,72 +133,48 @@
return Iterators.forEnumeration((Enumeration<TreeNode>) treeNode.children());
}
- private TreeNode findNode(SequenceRowKey<Integer> compositeKey) {
- if (compositeKey == null) {
- return null;
+
+ public Object getParentRowKey(Object rowKey) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isLeaf() {
+ if (!isDataAvailable()) {
+ throw new IllegalStateException();
}
- TreeNode result = fakeRootNode;
+ TreeNode treeNode = getData();
- for (Integer simpleKey : compositeKey.getSimpleKeys()) {
- int idx = simpleKey.intValue();
-
- if (idx < result.getChildCount()) {
- result = result.getChildAt(idx);
- } else {
- result = null;
- break;
- }
- }
-
- return result;
+ return !treeNode.getAllowsChildren() || treeNode.isLeaf();
}
-
- public void setRowKey(Object key) {
- this.selectedRowKey = (SequenceRowKey<Integer>) key;
- this.selectedNode = findNode(selectedRowKey);
- }
- public Object getRowKey() {
- return selectedRowKey;
+ public void setWrappedData(Object data) {
+ setRootNode(new FakeRootNode((Collection<TreeNode>) data));
}
-
- private SequenceRowKey<Integer> castKeyAndWrapNull(Object rowKey) {
- if (rowKey == null) {
- return EMPTY_SEQUENCE_ROW_KEY;
+
+ public Collection<TreeNode> getWrappedData() {
+ FakeRootNode rootNode = (FakeRootNode) getRootNode();
+ if (rootNode == null) {
+ return null;
}
-
- return (SequenceRowKey<Integer>) rowKey;
+ return rootNode.getWrappedData();
}
-
- public Iterator<Object> getChildrenRowKeysIterator(Object rowKey) {
- SequenceRowKey<Integer> sequenceKey = castKeyAndWrapNull(rowKey);
- Iterator<TreeNode> itr = findChildren(sequenceKey);
-
- return new SequenceRowKeyIterator<TreeNode>(sequenceKey, itr);
- }
- public TreeNode getData() {
- if (!isDataAvailable()) {
- throw new IllegalArgumentException();
+ @Override
+ protected TreeNode findChild(TreeNode parent, Integer simpleKey) {
+ int idx = simpleKey.intValue();
+ if (idx >= 0 && idx < parent.getChildCount()) {
+ return parent.getChildAt(idx);
}
- return selectedNode;
+ return null;
}
- public Object getParentRowKey(Object rowKey) {
- throw new UnsupportedOperationException();
- }
- public boolean isDataAvailable() {
- return selectedNode != null;
+ @Override
+ protected SequenceRowKeyIterator<Integer, TreeNode> createChildrenIterator(SequenceRowKey<Integer> baseKey,
+ TreeNode value) {
+
+ return new SwingTreeNodeRowKeyIterator(baseKey, value, safeGetChildren(baseKey, value));
}
-
- public Object getWrappedData() {
- return wrappedData;
- }
-
- public void setWrappedData(Object wrappedData) {
- this.wrappedData = (Collection<TreeNode>) wrappedData;
- }
}
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java (from rev 20107, trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,168 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.model;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.ListIterator;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.Range;
+import org.richfaces.component.TreeRange;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class TreeSequenceKeyModel<K, V> implements TreeDataModel<V> {
+
+ private V rootNode;
+
+ private V currentData;
+
+ private SequenceRowKey<K> currentRowKey;
+
+ private LinkedList<SequenceRowKeyIterator<K, V>> keysStack = new LinkedList<SequenceRowKeyIterator<K, V>>();
+
+ public SequenceRowKey<K> getRowKey() {
+ return currentRowKey;
+ }
+
+ public void setRowKey(Object rowKey) {
+ this.currentRowKey = (SequenceRowKey<K>) rowKey;
+ this.currentData = findData(currentRowKey);
+ }
+
+ public boolean isDataAvailable() {
+ return currentRowKey == null || currentData != null;
+ }
+
+ public abstract boolean isLeaf();
+
+ public V getData() {
+ if (!isDataAvailable()) {
+ throw new IllegalArgumentException();
+ }
+
+ return currentData;
+ }
+
+ protected boolean isRootNodeKey(SequenceRowKey<K> key) {
+ return key == null || key.getLastKeySegment() == null;
+ }
+
+ protected V findData(SequenceRowKey<K> key) {
+ if (key == null) {
+ return rootNode;
+ }
+
+ if (!keysStack.isEmpty()) {
+ ListIterator<SequenceRowKeyIterator<K, V>> listIterator = keysStack.listIterator(keysStack.size());
+
+ while (listIterator.hasPrevious()) {
+ SequenceRowKeyIterator<K, V> previous = listIterator.previous();
+
+ V baseNode = null;
+
+ SequenceRowKey<K> baseKey = previous.getBaseKey();
+ if (isRootNodeKey(baseKey) && isRootNodeKey(key.getParent())) {
+ baseNode = rootNode;
+ } else if (baseKey.equals(key.getParent())) {
+ baseNode = previous.getBaseElement();
+ }
+
+ if (baseNode == null) {
+ continue;
+ }
+
+ return findChild(baseNode, key.getLastKeySegment());
+ }
+ }
+
+ V result = rootNode;
+
+ for (K simpleKey : key.getSimpleKeys()) {
+ result = findChild(result, simpleKey);
+
+ if (result == null) {
+ break;
+ }
+ }
+
+ return result;
+ }
+
+ protected abstract V findChild(V parent, K simpleKey);
+
+ protected abstract SequenceRowKeyIterator<K, V> createChildrenIterator(SequenceRowKey<K> baseKey, V value);
+
+ public void enterNode(DataVisitor visitor) {
+ SequenceRowKey<K> sequenceKey = getRowKey();
+ V data = findData(sequenceKey);
+
+ keysStack.addLast(createChildrenIterator(sequenceKey, data));
+
+ if (visitor instanceof TreeDataVisitor) {
+ ((TreeDataVisitor) visitor).enterNode();
+ }
+ }
+
+ public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument) {
+ if (getRowKey() != null) {
+ visitor.process(context, getRowKey(), argument);
+ }
+
+ TreeRange treeRange = (TreeRange) range;
+
+ if (treeRange.shouldIterateChildren(getRowKey())) {
+ enterNode(visitor);
+ Iterator<Object> keysIterator = keysStack.getLast();
+ while (keysIterator.hasNext()) {
+ Object key = (Object) keysIterator.next();
+ setRowKey(key);
+ walk(context, visitor, range, argument);
+ }
+ exitNode(visitor);
+ }
+ }
+
+ public void exitNode(DataVisitor visitor) {
+ if (visitor instanceof TreeDataVisitor) {
+ ((TreeDataVisitor) visitor).exitNode();
+ }
+
+ keysStack.removeLast();
+ }
+
+ public abstract Object getParentRowKey(Object rowKey);
+
+ protected V getRootNode() {
+ return rootNode;
+ }
+
+ protected void setRootNode(V rootNode) {
+ this.rootNode = rootNode;
+ }
+
+}
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/DataScrollerBaseRenderer.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -321,9 +321,9 @@
function.addParameter(options);
- StringBuffer buffer = new StringBuffer();
- function.appendScript(buffer);
- definition.addToBody(buffer);
+ StringBuilder sb = new StringBuilder();
+ function.appendScriptToStringBuilder(sb);
+ definition.addToBody(sb);
return definition;
}
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -22,113 +22,139 @@
package org.richfaces.renderkit;
import java.io.IOException;
-import java.util.Iterator;
import java.util.LinkedList;
+import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.model.DataVisitResult;
import org.richfaces.component.AbstractTree;
import org.richfaces.component.AbstractTreeNode;
-import org.richfaces.component.TreeRange;
import org.richfaces.component.util.HtmlUtil;
-import org.richfaces.renderkit.TreeRendererBase.NodeState;
+import org.richfaces.model.TreeDataVisitor;
import org.richfaces.renderkit.TreeRendererBase.QueuedData;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.UnmodifiableIterator;
+abstract class TreeEncoderBase implements TreeDataVisitor {
-abstract class TreeEncoderBase {
+ static final String TREE_NODE_STATE_ATTRIBUTE = "__treeNodeState";
- private static final String TREE_NODE_HANDLE_CLASS_ATTRIBUTE = "__treeNodeHandleClass";
-
- private static final String TREE_NODE_ICON_CLASS_ATTRIBUTE = "__treeNodeIconClass";
-
protected final FacesContext context;
-
+
protected final ResponseWriter responseWriter;
-
+
protected final AbstractTree tree;
- private TreeRange treeRange;
-
- private LinkedList<QueuedData> queuedData = new LinkedList<QueuedData>();
-
+ private LinkedList<QueuedData> queuedDataList = new LinkedList<QueuedData>();
+
+ private QueuedData queuedData;
+
public TreeEncoderBase(FacesContext context, AbstractTree tree) {
super();
this.context = context;
this.responseWriter = context.getResponseWriter();
this.tree = tree;
-
- this.treeRange = (TreeRange) tree.getComponentState().getRange();
}
- protected void encodeTree(Iterator<Object> childrenIterator) throws IOException {
- Predicate<Object> renderedTreeNodeKeyPredicate = new Predicate<Object>() {
- public boolean apply(Object input) {
- tree.setRowKey(input);
-
- if (!tree.isRowAvailable()) {
- return false;
+ protected void encodeTree() throws IOException {
+ tree.walk(context, this, null);
+ }
+
+ protected void flushNode() throws IOException {
+ if (!queuedData.isEncoded()) {
+ tree.setRowKey(context, queuedData.getRowKey());
+
+ TreeNodeState state;
+ if (tree.isLeaf()) {
+ state = TreeNodeState.leaf;
+ } else {
+ if (queuedData.isVisited()) {
+ state = TreeNodeState.leaf;
+ } else {
+ state = TreeNodeState.collapsed;
}
-
- return tree.findTreeNodeComponent() != null;
}
- };
+
+ writeTreeNodeStartElement(state);
+ }
+
+ writeTreeNodeEndElement();
+ }
+
+ protected void flushParentNode() throws IOException {
+ if (queuedDataList.isEmpty()) {
+ return;
+ }
- UnmodifiableIterator<Object> filteredIterator = Iterators.filter(childrenIterator, renderedTreeNodeKeyPredicate);
- while (filteredIterator.hasNext()) {
- Object rowKey = filteredIterator.next();
+ QueuedData data = queuedDataList.getLast();
+ if (!data.isEncoded()) {
+ data.setEncoded(true);
+ tree.setRowKey(context, data.getRowKey());
- encodeTreeNode(rowKey, !filteredIterator.hasNext());
+ writeTreeNodeStartElement(tree.isExpanded() ? TreeNodeState.expanded : TreeNodeState.collapsed);
}
}
- protected void encodeTreeNode(Object rowKey, boolean isLastNode) throws IOException {
- if (!queuedData.isEmpty()) {
- QueuedData data = queuedData.getLast();
- if (!data.isEncoded()) {
- tree.setRowKey(context, data.getRowKey());
-
- writeTreeNodeStartElement(data.isExpanded() ? NodeState.expanded : NodeState.collapsed, data.isLastNode());
-
- data.setEncoded(true);
+ public void enterNode() {
+ if (queuedData != null) {
+ queuedData.makeVisited();
+ queuedDataList.add(queuedData);
+ queuedData = null;
+ }
+ }
+
+ public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
+ try {
+ if (queuedData != null) {
+ flushNode();
+ queuedData = null;
+ } else {
+ flushParentNode();
}
+ } catch (IOException e) {
+ throw new FacesException(e.getMessage(), e);
}
-
- tree.setRowKey(context, rowKey);
- boolean expanded = tree.isExpanded();
- queuedData.add(new QueuedData(rowKey, isLastNode, expanded));
-
- boolean iterateChildren = treeRange.shouldIterateChildren(rowKey);
-
- if (iterateChildren) {
- encodeTree(tree.getChildrenRowKeysIterator(context, rowKey));
+ if (rowKey != null) {
+ tree.setRowKey(context, rowKey);
+
+ if (tree.isRowAvailable() && tree.findTreeNodeComponent() != null) {
+ queuedData = new QueuedData(rowKey);
+ }
}
- QueuedData data = queuedData.removeLast();
- if (!data.isEncoded()) {
- NodeState nodeState = iterateChildren ? NodeState.leaf : NodeState.collapsed;
- writeTreeNodeStartElement(nodeState, data.isLastNode());
+ return DataVisitResult.CONTINUE;
+ }
+
+ public void exitNode() {
+ try {
+ if (queuedData != null) {
+ flushNode();
+ queuedData = null;
+ }
+
+ if (!queuedDataList.isEmpty()) {
+ queuedData = queuedDataList.removeLast();
+ }
+ } catch (IOException e) {
+ throw new FacesException(e.getMessage(), e);
}
-
- writeTreeNodeEndElement();
}
-
- protected void writeTreeNodeStartElement(NodeState nodeState, boolean isLast) throws IOException {
+
+ protected void writeTreeNodeStartElement(TreeNodeState nodeState) throws IOException {
AbstractTreeNode treeNodeComponent = tree.findTreeNodeComponent();
- context.getAttributes().put(TREE_NODE_HANDLE_CLASS_ATTRIBUTE, nodeState.getHandleClass());
- context.getAttributes().put(TREE_NODE_ICON_CLASS_ATTRIBUTE, nodeState.getIconClass());
-
+ context.getAttributes().put(TREE_NODE_STATE_ATTRIBUTE, nodeState);
+
responseWriter.startElement(HtmlConstants.DIV_ELEM, tree);
responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
- HtmlUtil.concatClasses("rf-tr-nd", isLast ? "rf-tr-nd-last" : null, nodeState.getNodeClass()),
+ HtmlUtil.concatClasses("rf-tr-nd", nodeState.getNodeClass()),
null);
responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE, treeNodeComponent.getClientId(context), null);
-
+
+ emitClientToggleEvent(treeNodeComponent, nodeState);
treeNodeComponent.encodeAll(context);
}
@@ -137,5 +163,16 @@
}
public abstract void encode() throws IOException;
-
+
+ private void emitClientToggleEvent(AbstractTreeNode treeNode, TreeNodeState nodeState) {
+ if (treeNode.getClientId(context).equals(context.getAttributes().get(TreeNodeRendererBase.AJAX_TOGGLED_NODE_ATTRIBUTE))) {
+ TreeNodeState submittedState = ((Boolean) (context.getAttributes().get(TreeNodeRendererBase.AJAX_TOGGLED_NODE_STATE_ATTRIBUTE)))
+ ? TreeNodeState.expanded : TreeNodeState.collapsed;
+
+ if (submittedState == nodeState || nodeState == TreeNodeState.leaf) {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ ajaxContext.appendOncomplete(new JSFunction("RichFaces.ui.TreeNode.emitToggleEvent", treeNode.getClientId(context)));
+ }
+ }
+ }
}
\ No newline at end of file
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -38,7 +38,8 @@
public void encode() throws java.io.IOException {
Object initialRowKey = tree.getRowKey();
try {
- encodeTree(tree.getChildrenRowKeysIterator(context, null));
+ tree.setRowKey(context, null);
+ encodeTree();
} finally {
try {
tree.setRowKey(context, initialRowKey);
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -22,6 +22,7 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.util.Collections;
import javax.faces.context.FacesContext;
import javax.faces.context.PartialResponseWriter;
@@ -58,23 +59,30 @@
PartialResponseWriter prw = context.getPartialViewContext().getPartialResponseWriter();
prw.startUpdate(elementId);
+ Object clientEventHandlers = null;
Object initialRowKey = tree.getRowKey();
try {
+ TreeRenderingContext.create(context, tree);
+ tree.setRowKey(context, rowKey);
+
+ encodeTree();
- encodeTreeNode(rowKey, true);
-
prw.endUpdate();
+ clientEventHandlers = TreeRenderingContext.get(context).getHandlers();
} finally {
try {
tree.setRowKey(context, initialRowKey);
} catch (Exception e) {
TreeRendererBase.LOGGER.error(e.getMessage(), e);
}
+
+ TreeRenderingContext.delete(context);
}
prw.startEval();
- JSFunction function = new JSFunction("RichFaces.ui.TreeNode.initNodeByAjax", elementId);
+ JSFunction function = new JSFunction("RichFaces.ui.TreeNode.initNodeByAjax", elementId,
+ Collections.singletonMap("clientEventHandlers", clientEventHandlers));
prw.write(function.toScript());
prw.endEval();
}
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeRendererBase.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -21,23 +21,34 @@
*/
package org.richfaces.renderkit;
+import static org.richfaces.renderkit.RenderKitUtils.getFirstNonEmptyAttribute;
+
import java.io.IOException;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.PartialViewContext;
+import javax.faces.context.ResponseWriter;
+import org.richfaces.component.AbstractTree;
import org.richfaces.component.AbstractTreeNode;
import org.richfaces.component.MetaComponentResolver;
+import org.richfaces.component.SwitchType;
import org.richfaces.event.TreeToggleEvent;
+import com.google.common.base.Strings;
+
/**
* @author Nick Belaevski
*
*/
public class TreeNodeRendererBase extends RendererBase implements MetaComponentRenderer {
+ static final String AJAX_TOGGLED_NODE_ATTRIBUTE = TreeNodeRendererBase.class.getName() + ":AJAX_TOGGLED_NODE_ATTRIBUTE";
+
+ static final String AJAX_TOGGLED_NODE_STATE_ATTRIBUTE = TreeNodeRendererBase.class.getName() + ":AJAX_TOGGLED_NODE_STATE_ATTRIBUTE";
+
private static final String NEW_NODE_TOGGLE_STATE = "__NEW_NODE_TOGGLE_STATE";
private static final String TRIGGER_NODE_AJAX_UPDATE = "__TRIGGER_NODE_AJAX_UPDATE";
@@ -60,6 +71,9 @@
PartialViewContext pvc = context.getPartialViewContext();
if (pvc.isAjaxRequest() && map.get(component.getClientId(context) + TRIGGER_NODE_AJAX_UPDATE) != null) {
pvc.getRenderIds().add(treeNode.getClientId(context) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + AbstractTreeNode.SUBTREE_META_COMPONENT_ID);
+
+ context.getAttributes().put(AJAX_TOGGLED_NODE_ATTRIBUTE, component.getClientId(context));
+ context.getAttributes().put(AJAX_TOGGLED_NODE_STATE_ATTRIBUTE, expanded);
}
}
}
@@ -77,6 +91,79 @@
} else {
throw new IllegalArgumentException(metaComponentId);
}
+ }
+
+ protected TreeNodeState getNodeState(FacesContext context) {
+ return (TreeNodeState) context.getAttributes().get(TreeEncoderBase.TREE_NODE_STATE_ATTRIBUTE);
+ }
+
+ protected UIComponent getTreeComponent(UIComponent treeNodeComponent) {
+ return ((AbstractTreeNode) treeNodeComponent).findTreeComponent();
+ }
+ protected void encodeDefaultIcon(FacesContext context, UIComponent component, String styleClass) throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+
+ writer.startElement(HtmlConstants.SPAN_ELEM, component);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, styleClass, null);
+ writer.endElement(HtmlConstants.SPAN_ELEM);
}
+
+ protected void encodeCustomIcon(FacesContext context, UIComponent component, String styleClass, String iconSource) throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+
+ writer.startElement(HtmlConstants.IMG_ELEMENT, component);
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, styleClass, null);
+ writer.writeAttribute(HtmlConstants.ALT_ATTRIBUTE, "", null);
+ writer.writeURIAttribute(HtmlConstants.SRC_ATTRIBUTE, RenderKitUtils.getResourceURL(iconSource, context), null);
+ writer.endElement(HtmlConstants.IMG_ELEMENT);
+ }
+
+ protected void encodeIcon(FacesContext context, UIComponent component) throws IOException {
+ TreeNodeState nodeState = getNodeState(context);
+
+ AbstractTreeNode treeNode = (AbstractTreeNode) component;
+
+ AbstractTree tree = treeNode.findTreeComponent();
+
+ if (nodeState.isLeaf()) {
+ String iconLeaf = (String) getFirstNonEmptyAttribute("iconLeaf", treeNode, tree);
+ encodeIconForNodeState(context, tree, treeNode, nodeState, iconLeaf);
+ } else {
+ String iconExpanded = (String) getFirstNonEmptyAttribute("iconExpanded", treeNode, tree);
+ String iconCollapsed = (String) getFirstNonEmptyAttribute("iconCollapsed", treeNode, tree);
+
+ if (Strings.isNullOrEmpty(iconCollapsed) && Strings.isNullOrEmpty(iconExpanded)) {
+ encodeIconForNodeState(context, tree, treeNode, nodeState, null);
+ } else {
+ SwitchType toggleType = treeNode.findTreeComponent().getToggleType();
+
+ if (toggleType == SwitchType.client || nodeState == TreeNodeState.collapsed) {
+ encodeIconForNodeState(context, tree, treeNode, TreeNodeState.collapsed, iconCollapsed);
+ }
+
+ if (toggleType == SwitchType.client || nodeState == TreeNodeState.expanded) {
+ encodeIconForNodeState(context, tree, treeNode, TreeNodeState.expanded, iconExpanded);
+ }
+ }
+ }
+ }
+
+ protected void encodeIconForNodeState(FacesContext context, AbstractTree tree, AbstractTreeNode treeNode, TreeNodeState nodeState, String customIcon) throws IOException {
+ if (Strings.isNullOrEmpty(customIcon)) {
+ encodeDefaultIcon(context, treeNode, concatClasses(nodeState.getIconClass(), treeNode.getAttributes().get("iconClass"),
+ tree.getAttributes().get("iconClass")));
+ } else {
+ encodeCustomIcon(context, treeNode, concatClasses(nodeState.getCustomIconClass(), treeNode.getAttributes().get("iconClass"),
+ tree.getAttributes().get("iconClass")), customIcon);
+ }
+ }
+
+ protected void addClientEventHandlers(FacesContext facesContext, UIComponent component) {
+ AbstractTreeNode treeNode = (AbstractTreeNode) component;
+
+ //TODO check toggle/selection types
+ TreeRenderingContext renderingContext = TreeRenderingContext.get(facesContext);
+ renderingContext.addHandlers(treeNode);
+ }
}
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeState.java (from rev 20107, trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeState.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeState.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeNodeState.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.renderkit;
+
+import org.richfaces.component.util.HtmlUtil;
+
+public enum TreeNodeState {
+ expanded("rf-tr-nd-exp", "rf-trn-hnd-exp", "rf-trn-ico-exp") {
+ @Override
+ public boolean isLeaf() {
+ return false;
+ }
+ },
+ collapsed("rf-tr-nd-colps", "rf-trn-hnd-colps", "rf-trn-ico-colps") {
+ @Override
+ public boolean isLeaf() {
+ return false;
+ }
+ },
+ leaf("rf-tr-nd-lf", "rf-trn-hnd-lf", "rf-trn-ico-lf") {
+ @Override
+ public boolean isLeaf() {
+ return true;
+ }
+ };
+
+ private String nodeClass;
+
+ private String handleClass;
+
+ private String iconClass;
+
+ private String customIconClass;
+
+ private TreeNodeState(String nodeClass, String defaultHandleClass, String iconClass) {
+ this.nodeClass = nodeClass;
+ this.handleClass = HtmlUtil.concatClasses(defaultHandleClass, "rf-trn-hnd");
+ this.iconClass = HtmlUtil.concatClasses(iconClass, "rf-trn-ico");
+ this.customIconClass = HtmlUtil.concatClasses(this.iconClass, "rf-trn-ico-cst");
+ }
+
+ public abstract boolean isLeaf();
+
+ public String getNodeClass() {
+ return nodeClass;
+ }
+
+ public String getHandleClass() {
+ return handleClass;
+ }
+
+ public String getIconClass() {
+ return iconClass;
+ }
+
+ public String getCustomIconClass() {
+ return customIconClass;
+ }
+}
\ No newline at end of file
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -45,7 +45,7 @@
import org.richfaces.component.AbstractTreeNode;
import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.SwitchType;
-import org.richfaces.event.TreeSelectionEvent;
+import org.richfaces.event.TreeSelectionChangeEvent;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
@@ -84,51 +84,16 @@
}
}
- enum NodeState {
- expanded("rf-tr-nd-exp", "rf-trn-hnd-exp", "rf-trn-ico-nd"),
- collapsed("rf-tr-nd-colps", "rf-trn-hnd-colps", "rf-trn-ico-nd"),
- leaf("rf-tr-nd-lf", "rf-trn-hnd-lf", "rf-trn-ico-lf");
-
- private String nodeClass;
-
- private String handleClass;
-
- private String iconClass;
-
- private NodeState(String nodeClass, String handleClass, String iconClass) {
- this.nodeClass = nodeClass;
- this.handleClass = handleClass;
- this.iconClass = iconClass;
- }
-
- public String getNodeClass() {
- return nodeClass;
- }
-
- public String getHandleClass() {
- return handleClass;
- }
-
- public String getIconClass() {
- return iconClass;
- }
-
- }
-
static final class QueuedData {
private Object rowKey;
- private boolean lastNode;
-
- private boolean expanded;
-
private boolean encoded;
- public QueuedData(Object rowKey, boolean lastNode, boolean expanded) {
+ private boolean visited;
+
+ public QueuedData(Object rowKey) {
this.rowKey = rowKey;
- this.lastNode = lastNode;
- this.expanded = expanded;
}
public void setEncoded(boolean encoded) {
@@ -143,12 +108,12 @@
return rowKey;
}
- public boolean isLastNode() {
- return lastNode;
+ public boolean isVisited() {
+ return visited;
}
-
- public boolean isExpanded() {
- return expanded;
+
+ public void makeVisited() {
+ visited = true;
}
}
@@ -247,7 +212,7 @@
writer.startEval();
JSFunction function = new JSFunction("RichFaces.$", component.getClientId(context));
- writer.write(function.toScript() + ".__updateSelection();");
+ writer.write(function.toScript() + ".__updateSelectionFromInput();");
writer.endEval();
} else {
@@ -293,7 +258,7 @@
}
if (newSelection != null) {
- new TreeSelectionEvent(component, Sets.newHashSet(selection), newSelection).queue();
+ new TreeSelectionChangeEvent(component, Sets.newHashSet(selection), newSelection).queue();
}
PartialViewContext pvc = context.getPartialViewContext();
@@ -302,4 +267,17 @@
+ AbstractTree.SELECTION_META_COMPONENT_ID);
}
}
+
+ protected void createTreeRenderingContext(FacesContext context, UIComponent component) {
+ TreeRenderingContext.create(context, (AbstractTree) component);
+ }
+
+ protected Object getClientEventHandlers(FacesContext facesContext) {
+ TreeRenderingContext treeRenderingContext = TreeRenderingContext.get(facesContext);
+ return treeRenderingContext.getHandlers();
+ }
+
+ protected void deleteTreeRenderingContext(FacesContext context) {
+ TreeRenderingContext.delete(context);
+ }
}
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java (from rev 20107, trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,208 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.renderkit;
+
+import static com.google.common.base.Strings.isNullOrEmpty;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSReference;
+import org.ajax4jsf.javascript.ScriptStringBase;
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.richfaces.component.AbstractTree;
+import org.richfaces.component.AbstractTreeNode;
+import org.richfaces.component.SwitchType;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class TreeRenderingContext {
+
+ private static final String ATTRIBUTE_NAME = TreeRenderingContext.class.getName() + ":ATTRIBUTE_NAME";
+
+ private static final ComponentAttribute ONTOGGLE_ATTRIBUTE = new ComponentAttribute("ontoggle").setEventNames("toggle");
+
+ private static final ComponentAttribute ONNODETOGGLE_ATTRIBUTE = new ComponentAttribute("onnodetoggle").setEventNames("nodetoggle");
+
+ private static final ComponentAttribute ONBEFORETOGGLE_ATTRIBUTE = new ComponentAttribute("onbeforetoggle").setEventNames("beforetoggle");
+
+ private static final ComponentAttribute ONBEFORENODETOGGLE_ATTRIBUTE = new ComponentAttribute("onbeforenodetoggle").setEventNames("beforenodetoggle");
+
+ public static final class Handlers extends ScriptStringBase {
+
+ private String toggleHandler;
+
+ private String nodeToggleHandler;
+
+ private String beforeToggleHandler;
+
+ private String beforeNodeToggleHandler;
+
+ protected Object chain(String firstHandler, String secondHandler) {
+ if (isNullOrEmpty(firstHandler) && isNullOrEmpty(secondHandler)) {
+ return null;
+ }
+
+ if (isNullOrEmpty(firstHandler)) {
+ return secondHandler;
+ }
+
+ if (isNullOrEmpty(secondHandler)) {
+ return firstHandler;
+ }
+
+ return new JSFunction("return jsf.util.chain", JSReference.THIS, JSReference.EVENT, firstHandler, secondHandler).toScript();
+ }
+
+ public void setToggleHandler(String toggleHandler) {
+ this.toggleHandler = toggleHandler;
+ }
+
+ public String getToggleHandler() {
+ return toggleHandler;
+ }
+
+ public void setNodeToggleHandler(String nodeToggleHandler) {
+ this.nodeToggleHandler = nodeToggleHandler;
+ }
+
+ public String getNodeToggleHandler() {
+ return nodeToggleHandler;
+ }
+
+ public void setBeforeToggleHandler(String beforeToggleHandler) {
+ this.beforeToggleHandler = beforeToggleHandler;
+ }
+
+ public String getBeforeToggleHandler() {
+ return beforeToggleHandler;
+ }
+
+ public void setBeforeNodeToggleHandler(String beforeNodeToggleHandler) {
+ this.beforeNodeToggleHandler = beforeNodeToggleHandler;
+ }
+
+ public String getBeforeNodeToggleHandler() {
+ return beforeNodeToggleHandler;
+ }
+
+ public void appendScript(Appendable target) throws IOException {
+ Object chainedToggleHandler = chain(toggleHandler, nodeToggleHandler);
+ Object chainedBeforeToggleHandler = chain(beforeToggleHandler, beforeNodeToggleHandler);
+
+ if (chainedToggleHandler != null || chainedBeforeToggleHandler != null) {
+ Map<String,Object> map = new HashMap<String, Object>(2);
+
+ if (chainedToggleHandler != null) {
+ map.put("th", chainedToggleHandler);
+ }
+
+ if (chainedBeforeToggleHandler != null) {
+ map.put("bth", chainedBeforeToggleHandler);
+ }
+
+ ScriptUtils.appendScript(target, map);
+ } else {
+ ScriptUtils.appendScript(target, null);
+ }
+ }
+ }
+
+ private FacesContext context;
+
+ private AbstractTree tree;
+
+ private String baseClientId;
+
+ private Map<String, Handlers> handlersMap = new HashMap<String, Handlers>();
+
+ private Handlers handlers;
+
+ private TreeRenderingContext(FacesContext context, AbstractTree tree) {
+ super();
+ this.context = context;
+ this.tree = tree;
+ this.baseClientId = tree.getBaseClientId(context);
+ }
+
+ public static TreeRenderingContext create(FacesContext context, AbstractTree tree) {
+ TreeRenderingContext renderingContext = new TreeRenderingContext(context, tree);
+ context.getAttributes().put(ATTRIBUTE_NAME, renderingContext);
+ return renderingContext;
+ }
+
+ public static TreeRenderingContext get(FacesContext context) {
+ return (TreeRenderingContext) context.getAttributes().get(ATTRIBUTE_NAME);
+ }
+
+ public static void delete(FacesContext context) {
+ context.getAttributes().remove(ATTRIBUTE_NAME);
+ }
+
+ private Handlers getOrCreateHandlers(String relativeClientId) {
+ if (handlers == null) {
+ handlers = new Handlers();
+ handlersMap.put(relativeClientId, handlers);
+ }
+ return handlers;
+ }
+
+ public void addHandlers(AbstractTreeNode treeNode) {
+ handlers = null;
+
+ String clientId = treeNode.getClientId(context);
+
+ String relativeClientId = clientId.substring(baseClientId.length());
+
+ if (tree.getToggleType() != SwitchType.server) {
+ String toggleHandler = (String) RenderKitUtils.getAttributeAndBehaviorsValue(context, treeNode, ONTOGGLE_ATTRIBUTE);
+ if (!isNullOrEmpty(toggleHandler)) {
+ getOrCreateHandlers(relativeClientId).setToggleHandler(toggleHandler);
+ }
+
+ String beforeToggleHandler = (String) RenderKitUtils.getAttributeAndBehaviorsValue(context, treeNode, ONBEFORETOGGLE_ATTRIBUTE);
+ if (!isNullOrEmpty(beforeToggleHandler)) {
+ getOrCreateHandlers(relativeClientId).setBeforeToggleHandler(beforeToggleHandler);
+ }
+
+ String nodeToggleHandler = (String) RenderKitUtils.getAttributeAndBehaviorsValue(context, tree, ONNODETOGGLE_ATTRIBUTE);
+ if (!isNullOrEmpty(nodeToggleHandler)) {
+ getOrCreateHandlers(relativeClientId).setNodeToggleHandler(nodeToggleHandler);
+ }
+
+ String beforeNodeToggleHandler = (String) RenderKitUtils.getAttributeAndBehaviorsValue(context, tree, ONBEFORENODETOGGLE_ATTRIBUTE);
+ if (!isNullOrEmpty(beforeNodeToggleHandler)) {
+ getOrCreateHandlers(relativeClientId).setBeforeNodeToggleHandler(beforeNodeToggleHandler);
+ }
+ }
+ }
+
+ public Object getHandlers() {
+ return handlersMap;
+ }
+}
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view (from rev 20107, trunk/ui/iteration/ui/src/main/java/org/richfaces/view)
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets (from rev 20107, trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets)
Deleted: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,66 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.view.facelets;
-
-import javax.faces.view.facelets.ComponentConfig;
-import javax.faces.view.facelets.ComponentHandler;
-import javax.faces.view.facelets.MetaRule;
-import javax.faces.view.facelets.MetaRuleset;
-import javax.faces.view.facelets.Metadata;
-import javax.faces.view.facelets.MetadataTarget;
-import javax.faces.view.facelets.TagAttribute;
-
-import org.richfaces.component.AbstractTree;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class TreeHandler extends ComponentHandler {
-
- private static final MetaRule RULE = new MetaRule() {
-
- @Override
- public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) {
- if (meta.isTargetInstanceOf(AbstractTree.class)) {
- if ("selectionChangeListener".equals(name)) {
- return new TreeSelectionChangeListenerExpressionMetadata(attribute);
- } else if ("toggleListener".equals(name)) {
- return new TreeToggleListenerExpressionMetadata(attribute);
- }
-
- }
- return null;
- }
- };
-
- public TreeHandler(ComponentConfig config) {
- super(config);
- }
-
- @Override
- protected MetaRuleset createMetaRuleset(Class type) {
- MetaRuleset metaRuleset = super.createMetaRuleset(type);
- metaRuleset.addRule(RULE);
- return metaRuleset;
- }
-}
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java (from rev 20107, trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.view.facelets;
+
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.richfaces.component.AbstractTree;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TreeHandler extends ComponentHandler {
+
+ private static final MetaRule RULE = new MetaRule() {
+
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) {
+ if (meta.isTargetInstanceOf(AbstractTree.class)) {
+ if ("selectionChangeListener".equals(name)) {
+ return new TreeSelectionChangeListenerExpressionMetadata(attribute);
+ } else if ("toggleListener".equals(name)) {
+ return new TreeToggleListenerExpressionMetadata(attribute);
+ }
+
+ }
+ return null;
+ }
+ };
+
+ public TreeHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset metaRuleset = super.createMetaRuleset(type);
+ metaRuleset.addRule(RULE);
+ return metaRuleset;
+ }
+}
Deleted: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,63 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.view.facelets;
-
-import javax.faces.view.facelets.ComponentConfig;
-import javax.faces.view.facelets.ComponentHandler;
-import javax.faces.view.facelets.MetaRule;
-import javax.faces.view.facelets.MetaRuleset;
-import javax.faces.view.facelets.Metadata;
-import javax.faces.view.facelets.MetadataTarget;
-import javax.faces.view.facelets.TagAttribute;
-
-import org.richfaces.component.AbstractTreeNode;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class TreeNodeHandler extends ComponentHandler {
-
- private static final MetaRule RULE = new MetaRule() {
-
- @Override
- public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) {
- if (meta.isTargetInstanceOf(AbstractTreeNode.class)) {
- if ("toggleListener".equals(name)) {
- return new TreeToggleListenerExpressionMetadata(attribute);
- }
- }
- return null;
- }
- };
-
- public TreeNodeHandler(ComponentConfig config) {
- super(config);
- }
-
- @Override
- protected MetaRuleset createMetaRuleset(Class type) {
- MetaRuleset metaRuleset = super.createMetaRuleset(type);
- metaRuleset.addRule(RULE);
- return metaRuleset;
- }
-}
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java (from rev 20107, trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.view.facelets;
+
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.richfaces.component.AbstractTreeNode;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TreeNodeHandler extends ComponentHandler {
+
+ private static final MetaRule RULE = new MetaRule() {
+
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) {
+ if (meta.isTargetInstanceOf(AbstractTreeNode.class)) {
+ if ("toggleListener".equals(name)) {
+ return new TreeToggleListenerExpressionMetadata(attribute);
+ }
+ }
+ return null;
+ }
+ };
+
+ public TreeNodeHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset metaRuleset = super.createMetaRuleset(type);
+ metaRuleset.addRule(RULE);
+ return metaRuleset;
+ }
+}
Deleted: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,31 +0,0 @@
-package org.richfaces.view.facelets;
-
-import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.Metadata;
-import javax.faces.view.facelets.TagAttribute;
-
-import org.richfaces.event.MethodExpressionTreeSelectionChangeListener;
-import org.richfaces.event.TreeSelectionChangeEvent;
-import org.richfaces.event.TreeSelectionChangeSource;
-
-/**
- * @author Nick Belaevski
- *
- */
-final class TreeSelectionChangeListenerExpressionMetadata extends Metadata {
-
- private static final Class<?>[] SIGNATURE = new Class[] { TreeSelectionChangeEvent.class };
-
- private final TagAttribute attr;
-
- TreeSelectionChangeListenerExpressionMetadata(TagAttribute attr) {
- this.attr = attr;
- }
-
- @Override
- public void applyMetadata(FaceletContext ctx, Object instance) {
- ((TreeSelectionChangeSource) instance).addTreeSelectionChangeListener(new MethodExpressionTreeSelectionChangeListener(
- this.attr.getMethodExpression(ctx, null, SIGNATURE)));
- }
-
-}
\ No newline at end of file
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java (from rev 20107, trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,31 @@
+package org.richfaces.view.facelets;
+
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.richfaces.event.MethodExpressionTreeSelectionChangeListener;
+import org.richfaces.event.TreeSelectionChangeEvent;
+import org.richfaces.event.TreeSelectionChangeSource;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+final class TreeSelectionChangeListenerExpressionMetadata extends Metadata {
+
+ private static final Class<?>[] SIGNATURE = new Class[] { TreeSelectionChangeEvent.class };
+
+ private final TagAttribute attr;
+
+ TreeSelectionChangeListenerExpressionMetadata(TagAttribute attr) {
+ this.attr = attr;
+ }
+
+ @Override
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((TreeSelectionChangeSource) instance).addTreeSelectionChangeListener(new MethodExpressionTreeSelectionChangeListener(
+ this.attr.getMethodExpression(ctx, null, SIGNATURE)));
+ }
+
+}
\ No newline at end of file
Deleted: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,31 +0,0 @@
-package org.richfaces.view.facelets;
-
-import javax.faces.view.facelets.FaceletContext;
-import javax.faces.view.facelets.Metadata;
-import javax.faces.view.facelets.TagAttribute;
-
-import org.richfaces.event.MethodExpressionTreeToggleListener;
-import org.richfaces.event.TreeToggleEvent;
-import org.richfaces.event.TreeToggleSource;
-
-/**
- * @author Nick Belaevski
- *
- */
-final class TreeToggleListenerExpressionMetadata extends Metadata {
-
- private static final Class<?>[] SIGNATURE = new Class[] { TreeToggleEvent.class };
-
- private final TagAttribute attr;
-
- TreeToggleListenerExpressionMetadata(TagAttribute attr) {
- this.attr = attr;
- }
-
- @Override
- public void applyMetadata(FaceletContext ctx, Object instance) {
- ((TreeToggleSource) instance).addTreeToggleListener(new MethodExpressionTreeToggleListener(this.attr
- .getMethodExpression(ctx, null, SIGNATURE)));
- }
-
-}
\ No newline at end of file
Copied: branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java (from rev 20107, trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java)
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java (rev 0)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,31 @@
+package org.richfaces.view.facelets;
+
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.richfaces.event.MethodExpressionTreeToggleListener;
+import org.richfaces.event.TreeToggleEvent;
+import org.richfaces.event.TreeToggleSource;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+final class TreeToggleListenerExpressionMetadata extends Metadata {
+
+ private static final Class<?>[] SIGNATURE = new Class[] { TreeToggleEvent.class };
+
+ private final TagAttribute attr;
+
+ TreeToggleListenerExpressionMetadata(TagAttribute attr) {
+ this.attr = attr;
+ }
+
+ @Override
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((TreeToggleSource) instance).addTreeToggleListener(new MethodExpressionTreeToggleListener(this.attr
+ .getMethodExpression(ctx, null, SIGNATURE)));
+ }
+
+}
\ No newline at end of file
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.ecss
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.ecss 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.ecss 2010-11-18 23:14:43 UTC (rev 20108)
@@ -58,7 +58,7 @@
background: "url(#{resource['org.richfaces.images:minus.png']}) no-repeat center";
}
-.rf-trn-ico-nd {
+.rf-trn-ico-exp, .rf-trn-ico-colps {
background: "url(#{resource['org.richfaces.images:node_icon.gif']}) no-repeat center";
}
@@ -66,6 +66,15 @@
background: "url(#{resource['org.richfaces.images:leaf_icon.gif']}) no-repeat center";
}
+.rf-trn-ico-cst {
+ background-image: none;
+ background-position: 0% 0%;
+}
+
+.rf-tr-nd-exp > .rf-trn > .rf-trn-cnt > .rf-trn-ico-colps, .rf-tr-nd-colps > .rf-trn > .rf-trn-cnt > .rf-trn-ico-exp {
+ display: none;
+}
+
.rf-tr-nd.rf-tr-nd-colps .rf-tr-nd {
display: none;
}
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-11-18 23:14:43 UTC (rev 20108)
@@ -31,21 +31,37 @@
var TREE_HANDLE_CLASSES = ["rf-trn-hnd-colps", "rf-trn-hnd-exp"];
+ var TREE_ICON_CLASSES = ["rf-trn-ico-colps", "rf-trn-ico-exp"];
+
richfaces.ui = richfaces.ui || {};
richfaces.ui.TreeNode = richfaces.BaseComponent.extendClass({
name: "TreeNode",
- init: function (id) {
+ init: function (id, commonOptions) {
this.__rootElt = $(this.attachToDom(id));
this.__children = new Array();
- this.__initializeChildren();
+ this.__initializeChildren(commonOptions);
+
+ var handlers = (commonOptions.clientEventHandlers || {})[this.getId().substring(commonOptions.treeId.length)] || {};
+
+ if (handlers.bth) {
+ richfaces.Event.bind(this.__rootElt, "beforetoggle", new Function("event", handlers.bth));
+ }
+
+ if (handlers.th) {
+ richfaces.Event.bind(this.__rootElt, "toggle", new Function("event", handlers.th));
+ }
+
+ this.__addLastNodeClass();
},
destroy: function() {
+ richfaces.BaseComponent.prototype.destroy.call(this);
+
if (this.parent) {
this.parent.removeChild(this);
this.parent = null;
@@ -58,13 +74,19 @@
this.__rootElt = null;
},
- __initializeChildren: function() {
+ __initializeChildren: function(commonOptions) {
var _this = this;
this.__rootElt.children(".rf-tr-nd").each(function() {
- _this.addChild(new richfaces.ui.TreeNode(this));
+ _this.addChild(new richfaces.ui.TreeNode(this, commonOptions));
});
},
+ __addLastNodeClass: function() {
+ if (this.__rootElt.next("div").length == 0) {
+ this.__rootElt.addClass("rf-tr-nd-last");
+ }
+ },
+
__getHandle: function() {
return this.__rootElt.find(" > .rf-trn:first > .rf-trn-hnd:first");
},
@@ -73,6 +95,10 @@
return this.__rootElt.find(" > .rf-trn:first > .rf-trn-cnt:first");
},
+ __getIcons: function() {
+ return this.__getContent().find(" > .rf-trn-ico");
+ },
+
getParent: function() {
return this.__parent;
},
@@ -116,15 +142,15 @@
},
isExpanded: function() {
- return !this.isLeaf() && this.__getHandle().hasClass("rf-trn-hnd-exp");
+ return !this.isLeaf() && this.__rootElt.hasClass("rf-tr-nd-exp");
},
isCollapsed: function() {
- return !this.isLeaf() && this.__getHandle().hasClass("rf-trn-hnd-colps");
+ return !this.isLeaf() && this.__rootElt.hasClass("rf-tr-nd-colps");
},
isLeaf: function() {
- return this.__getHandle().hasClass("rf-trn-hnd-lf");
+ return this.__rootElt.hasClass("rf-tr-nd-lf");
},
toggle: function() {
@@ -149,16 +175,36 @@
},
+ __fireBeforeToggleEvent: function() {
+ return richfaces.Event.callHandler(this.__rootElt, "beforetoggle");
+ },
+
+ __fireToggleEvent: function() {
+ richfaces.Event.callHandler(this.__rootElt, "toggle");
+ },
+
__changeToggleState: function(newState) {
if (!this.isLeaf()) {
if (newState ^ this.isExpanded()) {
+
+ if (this.__fireBeforeToggleEvent() === false) {
+ return;
+ }
+
var tree = this.getTree();
switch (tree.getToggleType()) {
case 'client':
this.__rootElt.addClass(TREE_CLASSES[newState ? 1 : 0]).removeClass(TREE_CLASSES[!newState ? 1 : 0]);
this.__getHandle().addClass(TREE_HANDLE_CLASSES[newState ? 1 : 0]).removeClass(TREE_HANDLE_CLASSES[!newState ? 1 : 0]);
+
+ var icons = this.__getIcons();
+ if (icons.length == 1) {
+ icons.addClass(TREE_ICON_CLASSES[newState ? 1 : 0]).removeClass(TREE_ICON_CLASSES[!newState ? 1 : 0]);
+ }
+
this.__updateClientToggleStateInput(newState);
+ this.__fireToggleEvent();
break;
case 'ajax':
@@ -204,23 +250,32 @@
});
- richfaces.ui.TreeNode.initNodeByAjax = function(nodeId) {
+ richfaces.ui.TreeNode.initNodeByAjax = function(nodeId, commonOptions) {
var node = $(document.getElementById(nodeId));
- if (node.nextAll(".rf-tr-nd:first").length != 0) {
- node.removeClass("rf-tr-nd-last");
- }
+ var opts = commonOptions || {};
var parent = node.parent(".rf-tr-nd, .rf-tr");
var idx = node.prevAll(".rf-tr-nd").length;
var parentNode = richfaces.$(parent[0]);
- var newChild = new richfaces.ui.TreeNode(node[0]);
+ opts.treeId = parentNode.getTree().getId();
+
+ var newChild = new richfaces.ui.TreeNode(node[0], opts);
parentNode.addChild(newChild, idx);
- parentNode.getTree().__updateSelection();
+ parentNode.getTree().__updateSelectionFromInput();
};
+ richfaces.ui.TreeNode.emitToggleEvent = function(nodeId) {
+ var node = document.getElementById(nodeId);
+ if (!node) {
+ return;
+ }
+
+ richfaces.$(node).__fireToggleEvent();
+ };
+
var findTree = function(elt) {
return richfaces.$($(elt).closest(".rf-tr"));
};
@@ -240,8 +295,12 @@
init: function (id, options) {
this.__treeRootElt = $(richfaces.getDomElement(id));
- this.$super.init.call(this, this.__treeRootElt);
+ var commonOptions = {};
+ commonOptions.clientEventHandlers = options.clientEventHandlers || {};
+ commonOptions.treeId = id;
+ this.$super.init.call(this, this.__treeRootElt, commonOptions);
+
this.__toggleType = options.toggleType || 'ajax';
this.__selectionType = options.selectionType || 'client';
@@ -249,27 +308,52 @@
this.__ajaxSubmitFunction = new Function("event", "source", "params", options.ajaxSubmitFunction);
}
+ if (options.onbeforeselectionchange) {
+ richfaces.Event.bind(this.__treeRootElt, "beforeselectionchange", new Function("event", options.onbeforeselectionchange));
+ }
+
+ if (options.onselectionchange) {
+ richfaces.Event.bind(this.__treeRootElt, "selectionchange", new Function("event", options.onselectionchange));
+ }
+
+ this.__toggleNodeEvent = options.toggleNodeEvent;
+ if (this.__toggleNodeEvent) {
+ this.__treeRootElt.delegate(".rf-trn", this.__toggleNodeEvent, this, this.__nodeToggleActivated);
+ }
+ if (!this.__toggleNodeEvent || this.__toggleNodeEvent != 'click') {
+ this.__treeRootElt.delegate(".rf-trn-hnd", "click", this, this.__nodeToggleActivated);
+ }
+
+ this.__treeRootElt.delegate(".rf-trn-cnt", "mousedown", this, this.__nodeSelectionActivated);
+
this.__selectionInput = $(" > .rf-tr-sel-inp", this.__treeRootElt);
+ this.__selection = new richfaces.ui.TreeNodeSet(this.__selectionInput.val());
- this.__treeRootElt.delegate(".rf-trn-hnd", "click", this, this.__itemHandleClicked);
- this.__treeRootElt.delegate(".rf-trn-cnt", "mousedown", this, this.__itemContentClicked);
-
- this.__updateSelection();
+ $(document).ready($.proxy(this.__updateSelectionFromInput, this));
},
+ __addLastNodeClass: function() {
+ //stub function overriding parent class method
+ },
+
destroy: function() {
- this.$super.destroy.call(this);
+ richfaces.ui.TreeNode.prototype.destroy.call(this);
- this.__treeRootElt.undelegate(".rf-trn-hnd", "click", this.__itemHandleClicked);
- this.__treeRootElt.undelegate(".rf-trn-cnt", "mousedown", this.__itemContentClicked);
+ if (this.__toggleNodeEvent) {
+ this.__treeRootElt.undelegate(".rf-trn", this.__toggleNodeEvent, this, this.__nodeToggleActivated);
+ }
+ if (!this.__toggleNodeEvent || this.__toggleNodeEvent != 'click') {
+ this.__treeRootElt.undelegate(".rf-trn-hnd", "click", this, this.__nodeToggleActivated);
+ }
+
+ this.__treeRootElt.undelegate(".rf-trn-cnt", "mousedown", this.__nodeSelectionActivated);
this.__treeRootElt = null;
- this.__itemContentClickedHandler = null;
this.__selectionInput = null;
this.__ajaxSubmitFunction = null;
},
- __itemHandleClicked: function(event) {
+ __nodeToggleActivated: function(event) {
var theTree = event.data;
if (isEventForAnotherTree(theTree, this)) {
return;
@@ -279,7 +363,7 @@
treeNode.toggle();
},
- __itemContentClicked: function(event) {
+ __nodeSelectionActivated: function(event) {
var theTree = event.data;
if (isEventForAnotherTree(theTree, this)) {
return;
@@ -319,60 +403,119 @@
return this;
},
- __bindFocusHandler: function(elt) {
- elt.mousedown(this.__itemContentClickedHandler);
- },
-
__isSelected: function(node) {
- return this.__selectedNodeId == node.getId();
+ return this.__selection.contains(node);
},
- __handleSelectionChange: function() {
+ __handleSelectionChange: function(newSelection) {
+ var eventData = {
+ oldSelection: this.__selection.getNodes(),
+ newSelection: newSelection.getNodes()
+ };
+
+ if (richfaces.Event.callHandler(this.__treeRootElt, "beforeselectionchange", eventData) === false) {
+ return;
+ }
+
+ this.__selectionInput.val(newSelection.toString());
+
if (this.getSelectionType() == 'client') {
- this.__updateSelection();
+ this.__updateSelection(newSelection);
} else {
this.__ajaxSubmitFunction(null, this.getId());
}
},
__toggleSelection: function(node) {
- if (this.__isSelected(node)) {
- this.__selectionInput.val("");
- } else {
- this.__selectionInput.val(node.getId());
- }
-
- this.__handleSelectionChange();
+ var newSelection = this.__selection.cloneAndToggle(node);
+ this.__handleSelectionChange(newSelection);
},
__addToSelection: function(node) {
- this.__selectionInput.val(node.getId());
+ var newSelection = this.__selection.cloneAndAdd(node);
+ this.__handleSelectionChange(newSelection);
+ },
+
+ __updateSelectionFromInput: function() {
+ this.__updateSelection(new richfaces.ui.TreeNodeSet(this.__selectionInput.val()));
+ },
+
+ __updateSelection: function(newSelection) {
+
+ var oldSelection = this.__selection;
- this.__handleSelectionChange();
+ oldSelection.each(function() {this.__setSelected(false)});
+ newSelection.each(function() {this.__setSelected(true)});
+
+ if (oldSelection.getNodeString() != newSelection.getNodeString()) {
+ richfaces.Event.callHandler(this.__treeRootElt, "selectionchange", {
+ oldSelection: oldSelection.getNodes(),
+ newSelection: newSelection.getNodes()
+ });
+ }
+
+ this.__selection = newSelection;
+ }
+ });
+
+ richfaces.ui.TreeNodeSet = function() {
+ this.init.apply(this, arguments);
+ };
+
+ //TODO - that's a single-node set, implement multi-node support!
+ $.extend(richfaces.ui.TreeNodeSet.prototype, {
+
+ init: function(nodeId) {
+ this.__nodeId = nodeId;
},
- __resetSelection: function() {
- this.__selectedNodeId = null;
- this.__selectionInput.val("");
+ contains: function(node) {
+ if (node.getId) {
+ return this.__nodeId == node.getId();
+ } else {
+ return this.__nodeId == node;
+ }
},
- __updateSelection: function() {
- var oldSelection = this.__selectedNodeId;
- if (oldSelection) {
- var oldSelectionNode = richfaces.$(oldSelection);
- if (oldSelectionNode) {
- oldSelectionNode.__setSelected(false);
+ getNodeString: function() {
+ return this.__nodeId;
+ },
+
+ toString: function() {
+ return this.getNodeString();
+ },
+
+ getNodes: function() {
+ if (this.__nodeId) {
+ var node = richfaces.$(this.__nodeId);
+ if (node) {
+ return [node];
+ } else {
+ return null;
}
}
- var nodeId = this.__selectionInput.val();
+ return [];
+ },
+
+ cloneAndAdd: function(node) {
+ return new richfaces.ui.TreeNodeSet(node.getId());
+ },
+
+ cloneAndToggle: function(node) {
+ var nodeId;
+ if (this.contains(node)) {
+ nodeId = "";
+ } else {
+ nodeId = node.getId();
+ }
- var newSelectionNode = richfaces.$(nodeId);
- if (newSelectionNode) {
- newSelectionNode.__setSelected(true);
- }
- this.__selectedNodeId = nodeId;
+ return new richfaces.ui.TreeNodeSet(nodeId);
+ },
+
+ each: function(callback) {
+ $.each(this.getNodes() || [], callback);
}
});
-
+
}(jQuery, RichFaces));
\ No newline at end of file
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/templates/tree.template.xml
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/templates/tree.template.xml 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/templates/tree.template.xml 2010-11-18 23:14:43 UTC (rev 20108)
@@ -13,19 +13,30 @@
<cdk:resource-dependency name="ajax.reslib" library="org.richfaces" />
<cdk:resource-dependency name="base-component.reslib" library="org.richfaces" />
+ <cdk:resource-dependency name="richfaces-event.js" />
<cdk:resource-dependency name="tree.js" library="org.richfaces" />
<cdk:resource-dependency name="tree.ecss" library="org.richfaces" />
+ <cdk:import-attributes src="urn:attributes:events-props.xml"/>
+ <cdk:import-attributes src="urn:attributes:core-props.xml"/>
+ <cdk:import-attributes src="urn:attributes:i18n-props.xml"/>
+
<cdk:import package="org.richfaces.component" names="SwitchType" />
</cc:interface>
<cc:implementation>
<div id="#{clientId}" class="#{concatClasses('rf-tr', component.attributes['styleClass'])}"
cdk:passThroughWithExclusions="">
+
+ <cdk:call expression="createTreeRenderingContext(facesContext, component)" />
+
<cdk:body>
<cdk:call expression="encodeTree(facesContext, component)" />
</cdk:body>
+ <cdk:object name="clientEventHandlers" value="#{getClientEventHandlers(facesContext)}" />
+ <cdk:call expression="deleteTreeRenderingContext(facesContext)" />
+
<cdk:call expression="encodeSelectionStateInput(facesContext, component)" />
<script type="text/javascript">
@@ -33,6 +44,8 @@
<cdk:scriptOption attributes="toggleType" defaultValue="SwitchType.DEFAULT" />
<cdk:scriptOption name="selectionType" value="#{getSelectionMode(facesContext, component)}" defaultValue="SwitchType.client" />
<cdk:scriptOption name="ajaxSubmitFunction" value="#{getAjaxSubmitFunction(facesContext, component)}" />
+ <cdk:scriptOption attributes="onselectionchange onbeforeselectionchange toggleNodeEvent" />
+ <cdk:scriptOption variables="clientEventHandlers" />
</cdk:scriptObject>
new RichFaces.ui.Tree(#{toScriptArgs(clientId, options)});
Modified: branches/RF-8742-1/ui/iteration/ui/src/main/templates/treeNode.template.xml
===================================================================
--- branches/RF-8742-1/ui/iteration/ui/src/main/templates/treeNode.template.xml 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/iteration/ui/src/main/templates/treeNode.template.xml 2010-11-18 23:14:43 UTC (rev 20108)
@@ -13,14 +13,24 @@
</cdk:component-family>
<cdk:renderer-type>org.richfaces.TreeNodeRenderer
</cdk:renderer-type>
+
+ <cdk:import-attributes src="urn:attributes:events-props.xml"/>
+ <cdk:import-attributes src="urn:attributes:core-props.xml"/>
+ <cdk:import-attributes src="urn:attributes:i18n-props.xml"/>
</cc:interface>
<cc:implementation>
- <div class="#{concatClasses('rf-trn', component.attributes['styleClass'])}">
- <span class="rf-trn-hnd #{facesContext.attributes['__treeNodeHandleClass']}" />
+ <cdk:object name="nodeState" value="#{getNodeState(facesContext)}" type="org.richfaces.renderkit.TreeNodeState" />
+ <cdk:object name="tree" value="#{getTreeComponent(component)}" type="UIComponent" />
+
+ <cdk:call expression="addClientEventHandlers(facesContext, component)" />
+
+ <div class="#{concatClasses('rf-trn', component.attributes['styleClass'], tree.attributes['nodeClass'])}">
+ <span class="#{concatClasses(nodeState.handleClass, component.attributes['handleClass'], tree.attributes['handleClass'])}"></span>
+
<span class="rf-trn-cnt">
- <span class="rf-trn-ico #{facesContext.attributes['__treeNodeIconClass']}" />
- <span class="rf-trn-lbl">
+ <cdk:call expression="encodeIcon(facesContext, component)" />
+ <span class="#{concatClasses('rf-trn-lbl', component.attributes['labelClass'], tree.attributes['labelClass'])}">
<cdk:body />
</span>
</span>
Deleted: branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/component/UIPanel.java
===================================================================
--- branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/component/UIPanel.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/component/UIPanel.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,49 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.component;
-
-import javax.faces.component.UIComponentBase;
-
-import org.richfaces.cdk.annotations.JsfComponent;
-import org.richfaces.cdk.annotations.JsfRenderer;
-import org.richfaces.cdk.annotations.Tag;
-import org.richfaces.cdk.annotations.TagType;
-
-/**
- * JSF component class
- *
- */
-@JsfComponent(tag = @Tag(type = TagType.Facelets),
- renderer = @JsfRenderer(type = "org.richfaces.PanelRenderer")
- )
-public class UIPanel extends UIComponentBase {
- private static final String COMPONENT_FAMILY = "org.richfaces.Panel";
-
- public boolean getRendersChildren() {
- return true;
- }
-
- @Override
- public String getFamily() {
- return COMPONENT_FAMILY;
- }
-}
Copied: branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/component/UIPanel.java (from rev 20107, trunk/ui/output/ui/src/main/java/org/richfaces/component/UIPanel.java)
===================================================================
--- branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/component/UIPanel.java (rev 0)
+++ branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/component/UIPanel.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -0,0 +1,49 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component;
+
+import javax.faces.component.UIComponentBase;
+
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
+
+/**
+ * JSF component class
+ *
+ */
+@JsfComponent(tag = @Tag(type = TagType.Facelets),
+ renderer = @JsfRenderer(type = "org.richfaces.PanelRenderer")
+ )
+public class UIPanel extends UIComponentBase {
+ private static final String COMPONENT_FAMILY = "org.richfaces.Panel";
+
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+}
Modified: branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java
===================================================================
--- branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -206,7 +206,7 @@
addToScriptHash(options, "onbeforeshow", buildEventFunction(attributes.get("onbeforeshow")));
addToScriptHash(options, "onbeforehide", buildEventFunction(attributes.get("onbeforehide")));
- result.append(ScriptUtils.toScript(options));
+ ScriptUtils.appendScript(result, options);
result.append(");");
return result.toString();
}
Modified: branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -18,7 +18,7 @@
}
- protected void finishValidation(StringBuffer body) {
+ protected void finishValidation(StringBuilder body) {
// AJAX callback
body.append("if(!").append(DISABLE_AJAX).append("){\n");
body.append(ajaxScript).append(EOL).append("}\n");
Modified: branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientOnlyScript.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -36,35 +36,35 @@
@Override
protected Object buildBody() {
- StringBuffer body = new StringBuffer();
+ StringBuilder body = new StringBuilder();
// Get component value by clientId.
body.append("var ").append(ClientValidatorRenderer.VALUE_VAR).append("=");
- GET_VALUE_FUNCTION.appendScript(body);
+ GET_VALUE_FUNCTION.appendScriptToStringBuilder(body);
body.append(EOL);
// Try client-side validation
body.append("try {\n");
// convert value
body.append("var ").append(ClientValidatorRenderer.CONVERTED_VALUE_VAR).append("=");
- converter.appendScript(body);
+ converter.appendScriptToStringBuilder(body);
body.append(EOL);
// call validators
for (LibraryScriptString validatorScript : validators) {
- validatorScript.appendScript(body);
+ validatorScript.appendScriptToStringBuilder(body);
body.append(EOL);
}
finishValidation(body);
body.append("return true;\n");
// Catch errors
body.append("} catch(e) {\n");
- SEND_ERROR_FUNCTION.appendScript(body);body.append(EOL);
+ SEND_ERROR_FUNCTION.appendScriptToStringBuilder(body);body.append(EOL);
body.append("return false;\n}");
return body;
}
- protected void finishValidation(StringBuffer body) {
+ protected void finishValidation(StringBuilder body) {
// clear messages after successful validation
body.append("if(!").append(DISABLE_AJAX).append("){\n");
- CLEAR_ERROR_FUNCTION.appendScript(body);
+ CLEAR_ERROR_FUNCTION.appendScriptToStringBuilder(body);
body.append(EOL).append("}\n");
}
Modified: branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,5 +1,7 @@
package org.richfaces.renderkit.html;
+import java.io.IOException;
+
import org.ajax4jsf.javascript.JSFunction;
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSLiteral;
@@ -29,13 +31,13 @@
super(CLIENT_ID,ELEMENT,EVENT,DISABLE_AJAX);
}
- public void appendScript(StringBuffer functionString) {
+ public void appendScript(Appendable target) throws IOException {
if(!bodyProcessed){
// pending RF-9565
addToBody(buildBody());
bodyProcessed = true;
}
- super.appendScript(functionString);
+ super.appendScript(target);
}
protected abstract Object buildBody();
Modified: branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Bean.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Bean.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Bean.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -3,6 +3,7 @@
*/
package org.richfaces.component;
+import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
@@ -36,10 +37,18 @@
return TEST_SCRIPT;
}
- public void appendScript(StringBuffer functionString) {
- functionString.append(TEST_SCRIPT);
+ public void appendScript(Appendable target) throws IOException {
+ target.append(TEST_SCRIPT);
}
+ public void appendScriptToStringBuilder(StringBuilder stringBuilder) {
+ try {
+ appendScript(stringBuilder);
+ } catch (IOException e) {
+ //ignore
+ }
+ }
+
public Collection<LibraryResource> getResources() {
return Collections.singleton(TEST_RESOURCE);
}
@@ -51,6 +60,7 @@
public String createCallScript(String clientId,String sourceId) {
return FOO+"("+clientId+")";
}
+
};
private String value=FOO_VALUE;
Modified: branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java
===================================================================
--- branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java 2010-11-18 18:50:06 UTC (rev 20107)
+++ branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/component/Script.java 2010-11-18 23:14:43 UTC (rev 20108)
@@ -1,8 +1,10 @@
package org.richfaces.component;
-import org.richfaces.javascript.LibraryResource;
-import org.richfaces.javascript.LibraryScriptString;
+import java.io.IOException;
+import org.richfaces.validator.LibraryResource;
+import org.richfaces.validator.LibraryScriptString;
+
final class Script implements LibraryScriptString {
private final String name;
@@ -14,11 +16,18 @@
return name;
}
- public void appendScript(StringBuffer functionString) {
- functionString.append(name);
-
+ public void appendScript(Appendable target) throws IOException {
+ target.append(name);
}
+ public void appendScriptToStringBuilder(StringBuilder stringBuilder) {
+ try {
+ appendScript(stringBuilder);
+ } catch (IOException e) {
+ //ignore
+ }
+ }
+
public LibraryResource getResource() {
return UIValidatorScriptCollectionTest.FOO_RESOURCE;
}
14 years, 1 month
JBoss Rich Faces SVN: r20107 - in trunk: cdk/generator/src/main/resources/META-INF/templates and 19 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-11-18 13:50:06 -0500 (Thu, 18 Nov 2010)
New Revision: 20107
Added:
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/LazyTreeNode.java
trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java
trunk/ui/iteration/ui/src/main/config/
trunk/ui/iteration/ui/src/main/config/faces-config.xml
trunk/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeSelectionChangeListener.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeToggleListener.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/view/
trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/
trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/EventBean.java
trunk/cdk/generator/src/main/resources/META-INF/templates/listenerTagHandler.ftl
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java
trunk/examples/iteration-demo/src/main/webapp/tree.xhtml
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java
trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java
trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java
trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java
trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleListener.java
trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java
trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ExtendedTreeDataModelImpl.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java
trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
trunk/ui/iteration/ui/src/main/templates/tree.template.xml
trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml
trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
Log:
Rest of tree work merged manually from GIT
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/EventBean.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/EventBean.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/EventBean.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -48,6 +48,7 @@
private ClassName sourceInterface;
private ClassName type;
private List<TagModel> tags = Lists.newArrayList();
+ private String listenerMethod;
/**
* <p class="changed_added_4_0"></p>
@@ -165,4 +166,19 @@
public void setTags(List<TagModel> tags) {
this.tags = tags;
}
+
+ /**
+ * @return the listenerMethod
+ */
+ @XmlElement(name = "listener-method", namespace = ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
+ public String getListenerMethod() {
+ return listenerMethod;
+ }
+
+ /**
+ * @param listenerMethod the listenerMethod to set
+ */
+ public void setListenerMethod(String listenerMethod) {
+ this.listenerMethod = listenerMethod;
+ }
}
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates/listenerTagHandler.ftl
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates/listenerTagHandler.ftl 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates/listenerTagHandler.ftl 2010-11-18 18:50:06 UTC (rev 20107)
@@ -98,7 +98,7 @@
private TagAttribute listenerMethod;
- public TestListenerHandler(TagConfig config) {
+ public ${tag.targetClass.simpleName}(TagConfig config) {
super(config);
this.binding = this.getAttribute("binding");
Added: trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java (rev 0)
+++ trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import javax.faces.component.UIComponent;
+
+import com.google.common.base.Predicate;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public final class ComponentPredicates {
+
+ private static final Predicate<UIComponent> IS_RENDERED = new Predicate<UIComponent>() {
+ public boolean apply(UIComponent input) {
+ return input.isRendered();
+ };
+ };
+
+ private ComponentPredicates() {}
+
+ public static Predicate<UIComponent> isRendered() {
+ return IS_RENDERED;
+ }
+}
Added: trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/LazyTreeNode.java
===================================================================
--- trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/LazyTreeNode.java (rev 0)
+++ trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/LazyTreeNode.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.demo;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import javax.swing.tree.TreeNode;
+
+import com.google.common.collect.Iterators;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class LazyTreeNode implements TreeNode, Serializable {
+
+ private static final long serialVersionUID = 7222747310505408841L;
+
+ private TreeNode srcNode;
+
+ private LazyTreeNode parentNode;
+
+ private List<LazyTreeNode> children = null;
+
+ public LazyTreeNode(LazyTreeNode parentNode, TreeNode srcNode) {
+ super();
+ this.parentNode = parentNode;
+ this.srcNode = srcNode;
+ }
+
+ public LazyTreeNode(TreeNode srcNode) {
+ this(null, srcNode);
+ }
+
+ private void initializeChildren() {
+ if (children != null) {
+ return;
+ }
+
+ children = new ArrayList<LazyTreeNode>();
+
+ Enumeration srcChildren = srcNode.children();
+ while (srcChildren.hasMoreElements()) {
+ TreeNode srcChild = (TreeNode) srcChildren.nextElement();
+ children.add(new LazyTreeNode(this, srcChild));
+ }
+ }
+
+ public TreeNode getChildAt(int childIndex) {
+ initializeChildren();
+
+ return children.get(childIndex);
+ }
+
+ public int getChildCount() {
+ initializeChildren();
+
+ return children.size();
+ }
+
+ public TreeNode getParent() {
+ return parentNode;
+ }
+
+ public int getIndex(TreeNode node) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean getAllowsChildren() {
+ return true;
+ }
+
+ public boolean isLeaf() {
+ if (children == null) {
+ return false;
+ }
+
+ return children.isEmpty();
+ }
+
+ public Enumeration children() {
+ initializeChildren();
+
+ return Iterators.asEnumeration(children.iterator());
+ }
+
+ public TreeNode getWrappedNode() {
+ return srcNode;
+ }
+}
Modified: trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java
===================================================================
--- trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -22,6 +22,7 @@
package org.richfaces.demo;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -30,10 +31,18 @@
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
import javax.faces.event.AjaxBehaviorEvent;
+import javax.faces.event.FacesEvent;
import javax.swing.tree.TreeNode;
+import org.richfaces.component.AbstractTree;
+import org.richfaces.component.AbstractTreeNode;
import org.richfaces.component.SwitchType;
+import org.richfaces.event.TreeSelectionChangeEvent;
+import org.richfaces.event.TreeSelectionChangeListener;
+import org.richfaces.event.TreeToggleEvent;
+import org.richfaces.event.TreeToggleListener;
import org.richfaces.log.LogFactory;
import org.richfaces.log.Logger;
@@ -45,28 +54,98 @@
@SessionScoped
public class TreeBean implements Serializable {
+ public static final class SelectionChangeHandler implements TreeSelectionChangeListener {
+
+ private boolean fromExpression = false;
+
+ public SelectionChangeHandler() {
+ }
+
+ public SelectionChangeHandler(boolean fromExpression) {
+ super();
+ this.fromExpression = fromExpression;
+ }
+
+ public void processSelectionChange(TreeSelectionChangeEvent event) throws AbortProcessingException {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ facesContext.addMessage(getTree(event).getBaseClientId(facesContext), createEventMessage(event, fromExpression));
+ }
+
+ }
+
+ public static final class ToggleHandler implements TreeToggleListener {
+
+ private boolean fromExpression = false;
+
+ public ToggleHandler() {
+ }
+
+ public ToggleHandler(boolean fromExpression) {
+ super();
+ this.fromExpression = fromExpression;
+ }
+
+ public void processToggle(TreeToggleEvent event) throws AbortProcessingException {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ facesContext.addMessage(getTree(event).getBaseClientId(facesContext), createEventMessage(event, fromExpression));
+ }
+
+ }
+
private static final long serialVersionUID = 3368885134614548497L;
private static final Logger LOGGER = LogFactory.getLogger(TreeBean.class);
private List<TreeNode> rootNodes;
+ private List<TreeNode> lazyRootNodes;
+
private SwitchType toggleType = SwitchType.DEFAULT;
private SwitchType selectionType = SwitchType.client;
- private Object nodeData;
-
private boolean showCustomClasses = true;
private Collection<Object> selection = new TracingSet<Object>();
+
+ private String toggleNodeEvent = "";
+ private static Object staticGetNodeData() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ return facesContext.getApplication().evaluateExpressionGet(facesContext, "#{node}", Object.class);
+ }
+
+ private static FacesMessage createEventMessage(FacesEvent event, boolean fromExpression) {
+ String summary = event + (fromExpression ? " called from attribute" : " called from tag") + ", data: " + staticGetNodeData();
+ return new FacesMessage(summary);
+ }
+
+ private static AbstractTree getTree(FacesEvent event) {
+ if (event.getComponent() instanceof AbstractTree) {
+ return (AbstractTree) event.getComponent();
+ }
+
+ return ((AbstractTreeNode) event.getComponent()).findTreeComponent();
+ }
+
+ private List<TreeNode> createLazyNodes(List<TreeNode> nodes) {
+ List<TreeNode> result = new ArrayList<TreeNode>(nodes.size());
+
+ for (TreeNode srcNode : nodes) {
+ result.add(new LazyTreeNode(srcNode));
+ }
+
+ return result;
+ }
+
@PostConstruct
public void init() {
try {
TreeNodeParser parser = new TreeNodeParser();
parser.parse(TreeBean.class.getResource("plants.xml"));
rootNodes = parser.getRootNodes();
+ lazyRootNodes = createLazyNodes(rootNodes);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
@@ -76,6 +155,10 @@
return rootNodes;
}
+ public List<TreeNode> getLazyRootNodes() {
+ return lazyRootNodes;
+ }
+
public SwitchType[] getTypes() {
return SwitchType.values();
}
@@ -97,8 +180,7 @@
}
public Object getNodeData() {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- return facesContext.getApplication().evaluateExpressionGet(facesContext, "#{node}", Object.class);
+ return staticGetNodeData();
}
public Collection<Object> getSelection() {
@@ -131,4 +213,22 @@
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.addMessage(event.getComponent().getClientId(facesContext), new FacesMessage("Selection changed, source is: " + event.getSource()));
}
+
+ public void processSelectionChange(TreeSelectionChangeEvent event) {
+ new SelectionChangeHandler(true).processSelectionChange(event);
+ }
+
+ public void processToggle(TreeToggleEvent event) {
+ new ToggleHandler(true).processToggle(event);
+ }
+
+ public String getToggleNodeEvent() {
+ return toggleNodeEvent;
+ }
+
+ public void setToggleNodeEvent(String toggleNodeEvent) {
+ this.toggleNodeEvent = toggleNodeEvent;
+ }
+
+
}
Modified: trunk/examples/iteration-demo/src/main/webapp/tree.xhtml
===================================================================
--- trunk/examples/iteration-demo/src/main/webapp/tree.xhtml 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/examples/iteration-demo/src/main/webapp/tree.xhtml 2010-11-18 18:50:06 UTC (rev 20107)
@@ -53,6 +53,20 @@
+ '[' + nodeData + ']:\n ' + treeNode.getId() + ' became ' + getNodeStateString(treeNode));
}
+ function handleBeforeNodeToggle(event, isTreeNodeLevel) {
+ var treeNode = RichFaces.$(event.target);
+ return confirm('Tree' + (isTreeNodeLevel ? ' node ' : ' ') + 'asks: really toggle node ' + treeNode.getId() + '?');
+ }
+
+ function handleBeforeNodeSelect(event) {
+ var treeNode = RichFaces.$(event.target);
+
+ var oldSelectionString = nodesArrayToString(event.rf.data.oldSelection);
+ var newSelectionString = nodesArrayToString(event.rf.data.newSelection);
+
+ return confirm('Selection will be changed from: [' + oldSelectionString + '] to: [' + newSelectionString + ']');
+ }
+
function handleNodeSelect(event) {
var treeNode = RichFaces.$(event.target);
@@ -75,6 +89,15 @@
</h:selectOneRadio>
Show custom classes: <h:selectBooleanCheckbox value="#{treeBean.showCustomClasses}" onclick="submit()" />
+
+ <br />
+ Toggle node event:
+ <h:selectOneMenu value="#{treeBean.toggleNodeEvent}" onchange="submit()">
+ <f:selectItem itemLabel="none" itemValue="" />
+ <f:selectItem itemLabel="click" itemValue="click" />
+ <f:selectItem itemLabel="mouseenter" itemValue="mouseenter" />
+ <f:selectItem itemLabel="dblclick" itemValue="dblclick" />
+ </h:selectOneMenu>
</h:form>
<h:form id="form">
@@ -125,9 +148,12 @@
<it:tree id="clientSideEventsTree" var="node" value="#{treeBean.rootNodes}"
selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}"
onnodetoggle="handleNodeToggle("#{node.data}", event, false)"
- onselectionchange="handleNodeSelect(event)">
+ onselectionchange="handleNodeSelect(event)"
+ onbeforeselectionchange="return handleBeforeNodeSelect(event)"
+ onbeforenodetoggle="return handleBeforeNodeToggle(event, false)">
- <it:treeNode ontoggle="handleNodeToggle("#{node.data}", event, true)">
+ <it:treeNode ontoggle="handleNodeToggle("#{node.data}", event, true)"
+ onbeforetoggle="return handleBeforeNodeToggle(event, true)">
#{node.data}
</it:treeNode>
</it:tree>
@@ -149,6 +175,43 @@
</it:treeNode>
</it:tree>
+ Lazy loaded tree:
+ <it:tree id="lazyLoadedTree" var="node" value="#{treeBean.lazyRootNodes}"
+ selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}">
+
+ <it:treeNode>
+ #{node.wrappedNode.data}
+ </it:treeNode>
+ </it:tree>
+
+ <a4j:outputPanel ajaxRendered="true">
+ <h:messages for="serverListenersTree" />
+ </a4j:outputPanel>
+
+ Server listeners test:
+ <it:tree id="serverListenersTree" var="node" value="#{treeBean.rootNodes}"
+ selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}"
+ selectionChangeListener="#{treeBean.processSelectionChange}"
+ toggleListener="#{treeBean.processToggle}">
+
+ <it:treeSelectionChangeListener type="org.richfaces.demo.TreeBean$SelectionChangeHandler" />
+ <it:treeToggleListener type="org.richfaces.demo.TreeBean$ToggleHandler" />
+
+ <it:treeNode toggleListener="#{treeBean.processToggle}">
+ <it:treeToggleListener type="org.richfaces.demo.TreeBean$ToggleHandler" />
+
+ #{node.data}
+ </it:treeNode>
+ </it:tree>
+
+ Toggle node event:
+ <it:tree toggleNodeEvent="#{treeBean.toggleNodeEvent}" var="node" value="#{treeBean.rootNodes}"
+ selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}">
+ <it:treeNode>
+ #{node.data}
+ </it:treeNode>
+ </it:tree>
+
<a4j:log />
</h:form>
</h:body>
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -299,7 +299,7 @@
}
if (isChained) {
- result.insert(0, "jsf.util.chain(this, event, ");
+ result.insert(0, "return jsf.util.chain(this, event, ");
result.append(")");
}
@@ -715,6 +715,39 @@
return context.getExternalContext().encodeResourceURL(value);
}
+ public static Object getFirstNonEmptyAttribute(String attributeName, UIComponent component) {
+ Object attributeValue = component.getAttributes().get(attributeName);
+
+ return !isEmpty(attributeValue) ? attributeValue : null;
+ }
+
+ public static Object getFirstNonEmptyAttribute(String attributeName, UIComponent componentA, UIComponent componentB) {
+ Object attributeValue = componentA.getAttributes().get(attributeName);
+
+ if (!isEmpty(attributeValue)) {
+ return attributeValue;
+ }
+
+ attributeValue = componentB.getAttributes().get(attributeName);
+
+ if (!isEmpty(attributeValue)) {
+ return attributeValue;
+ }
+
+ return null;
+ }
+
+ public static Object getFirstNonEmptyAttribute(String attributeName, UIComponent... components) {
+ for (UIComponent component : components) {
+ Object attributeValue = component.getAttributes().get(attributeName);
+ if (!isEmpty(attributeValue)) {
+ return attributeValue;
+ }
+ }
+
+ return null;
+ }
+
@SuppressWarnings("serial")
public static final class Attributes extends TreeSet<ComponentAttribute> {
Modified: trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java
===================================================================
--- trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsMocksTest.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -199,10 +199,10 @@
ClientBehaviorHolder behaviorHolder = createMockClientBehaviorHolder();
UIComponent component = (UIComponent) behaviorHolder;
- responseWriter.writeAttribute(eq("onkeypress"), eq("jsf.util.chain(this, event, 'alert(keypress)','prompt(keypress)')"),
+ responseWriter.writeAttribute(eq("onkeypress"), eq("return jsf.util.chain(this, event, 'alert(keypress)','prompt(keypress)')"),
EasyMock.<String>isNull());
responseWriter.writeAttribute(eq("onclick"),
- eq("jsf.util.chain(this, event, 'alert(click)','prompt(action1)','prompt(action2)')"), EasyMock.<String>isNull());
+ eq("return jsf.util.chain(this, event, 'alert(click)','prompt(action1)','prompt(action2)')"), EasyMock.<String>isNull());
responseWriter.writeAttribute(eq("onmousemove"), eq("alert(mousemove)"), EasyMock.<String>isNull());
responseWriter.writeAttribute(eq("oncontextmenu"), eq("prompt(contextmenu)"), EasyMock.<String>isNull());
@@ -249,7 +249,7 @@
componentAttributes.put("disabled", Boolean.FALSE);
UIComponent component = setupBehaviorsTestForDisabledComponent();
- responseWriter.writeAttribute(eq("onclick"), eq("jsf.util.chain(this, event, 'alert(click)','prompt(action1)')"),
+ responseWriter.writeAttribute(eq("onclick"), eq("return jsf.util.chain(this, event, 'alert(click)','prompt(action1)')"),
EasyMock.<String>isNull());
responseWriter.writeAttribute(eq("onmousemove"),
eq("alert(mousemove)"), EasyMock.<String>isNull());
Modified: trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -53,7 +53,7 @@
@Override
public void processListener(FacesListener listener) {
- ((TreeSelectionChangeListener) listener).processSelection(this);
+ ((TreeSelectionChangeListener) listener).processSelectionChange(this);
}
public Collection<Object> getOldSelection() {
Modified: trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -21,6 +21,7 @@
*/
package org.richfaces.event;
+import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesListener;
/**
@@ -29,6 +30,6 @@
*/
public interface TreeSelectionChangeListener extends FacesListener {
- public void processSelection(TreeSelectionChangeEvent event);
+ public void processSelectionChange(TreeSelectionChangeEvent event) throws AbortProcessingException;
}
Modified: trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -27,8 +27,8 @@
*/
public interface TreeSelectionChangeSource {
- public void addSelectionChangeListener(TreeSelectionChangeListener listener);
+ public void addTreeSelectionChangeListener(TreeSelectionChangeListener listener);
- public void removeSelectionchangeListener(TreeSelectionChangeListener listener);
+ public void removeTreeSelectionChangeListener(TreeSelectionChangeListener listener);
}
Modified: trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleListener.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleListener.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleListener.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -21,6 +21,7 @@
*/
package org.richfaces.event;
+import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesListener;
/**
@@ -29,6 +30,6 @@
*/
public interface TreeToggleListener extends FacesListener {
- public void processToggle(TreeToggleEvent event);
+ public void processToggle(TreeToggleEvent event) throws AbortProcessingException;
}
Modified: trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -27,8 +27,8 @@
*/
public interface TreeToggleSource {
- public void addToggleListener(TreeToggleListener listener);
+ public void addTreeToggleListener(TreeToggleListener listener);
- public void removeToggleListener(TreeToggleListener listener);
+ public void removeTreeToggleListener(TreeToggleListener listener);
}
Modified: trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataModel.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -21,8 +21,11 @@
*/
package org.richfaces.model;
-import java.util.Iterator;
+import javax.faces.context.FacesContext;
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.Range;
+
/**
* @author Nick Belaevski
*
@@ -36,10 +39,16 @@
public boolean isDataAvailable();
+ public boolean isLeaf();
+
public E getData();
- public Iterator<Object> getChildrenRowKeysIterator(Object rowKey);
+ public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument);
+
+ public void enterNode(DataVisitor visitor);
+ public void exitNode(DataVisitor visitor);
+
public Object getParentRowKey(Object rowKey);
public Object getWrappedData();
Added: trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java (rev 0)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/model/TreeDataVisitor.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.model;
+
+import org.ajax4jsf.model.DataVisitor;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeDataVisitor extends DataVisitor {
+
+ public void enterNode();
+
+ public void exitNode();
+
+}
Added: trunk/ui/iteration/ui/src/main/config/faces-config.xml
===================================================================
--- trunk/ui/iteration/ui/src/main/config/faces-config.xml (rev 0)
+++ trunk/ui/iteration/ui/src/main/config/faces-config.xml 2010-11-18 18:50:06 UTC (rev 20107)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+ xmlns:cdk="http://jboss.org/schema/richfaces/cdk/extensions"
+ version="2.0">
+
+ <faces-config-extension>
+ <cdk:faces-event>
+ <cdk:event-class>org.richfaces.event.TreeToggleEvent</cdk:event-class>
+ <cdk:listener-class>org.richfaces.event.TreeToggleListener</cdk:listener-class>
+ <cdk:source-class>org.richfaces.event.TreeToggleSource</cdk:source-class>
+ <cdk:listener-method>processToggle</cdk:listener-method>
+ <cdk:tag>
+ <cdk:tag-name>treeToggleListener</cdk:tag-name>
+ <cdk:tag-type>Facelets</cdk:tag-type>
+ <cdk:handler-class>org.richfaces.view.facelets.TreeToggleListenerHandler</cdk:handler-class>
+ <cdk:generate>true</cdk:generate>
+ </cdk:tag>
+ </cdk:faces-event>
+
+ <cdk:faces-event>
+ <cdk:event-class>org.richfaces.event.TreeSelectionChangeEvent</cdk:event-class>
+ <cdk:listener-class>org.richfaces.event.TreeSelectionChangeListener</cdk:listener-class>
+ <cdk:source-class>org.richfaces.event.TreeSelectionChangeSource</cdk:source-class>
+ <cdk:listener-method>processSelectionChange</cdk:listener-method>
+ <cdk:tag>
+ <cdk:tag-name>treeSelectionChangeListener</cdk:tag-name>
+ <cdk:tag-type>Facelets</cdk:tag-type>
+ <cdk:handler-class>org.richfaces.view.facelets.TreeSelectionChangeListenerHandler</cdk:handler-class>
+ <cdk:generate>true</cdk:generate>
+ </cdk:tag>
+ </cdk:faces-event>
+ </faces-config-extension>
+
+</faces-config>
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -26,9 +26,14 @@
import java.util.HashSet;
import java.util.Iterator;
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
+import javax.faces.component.UpdateModelException;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
@@ -36,22 +41,34 @@
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ExceptionQueuedEvent;
+import javax.faces.event.ExceptionQueuedEventContext;
import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseId;
import javax.swing.tree.TreeNode;
import org.ajax4jsf.model.DataComponentState;
import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
+import org.richfaces.application.MessageFactory;
+import org.richfaces.application.ServiceTracker;
+import org.richfaces.appplication.FacesMessages;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Signature;
import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.component.util.MessageUtil;
import org.richfaces.context.ExtendedVisitContext;
import org.richfaces.context.ExtendedVisitContextMode;
import org.richfaces.convert.SequenceRowKeyConverter;
import org.richfaces.event.TreeSelectionChangeEvent;
import org.richfaces.event.TreeSelectionChangeListener;
+import org.richfaces.event.TreeSelectionChangeSource;
+import org.richfaces.event.TreeToggleEvent;
+import org.richfaces.event.TreeToggleListener;
+import org.richfaces.event.TreeToggleSource;
import org.richfaces.model.ExtendedTreeDataModelImpl;
import org.richfaces.model.SwingTreeNodeDataModelImpl;
import org.richfaces.model.TreeDataModel;
@@ -69,22 +86,22 @@
@JsfComponent(
type = AbstractTree.COMPONENT_TYPE,
family = AbstractTree.COMPONENT_FAMILY,
- tag = @Tag(name = "tree"),
+ tag = @Tag(name = "tree", handler = "org.richfaces.view.facelets.TreeHandler"),
renderer = @JsfRenderer(type = "org.richfaces.TreeRenderer"),
attributes = {"events-props.xml", "core-props.xml", "i18n-props.xml"}
)
-public abstract class AbstractTree extends UIDataAdaptor implements MetaComponentResolver, MetaComponentEncoder {
+public abstract class AbstractTree extends UIDataAdaptor implements MetaComponentResolver, MetaComponentEncoder, TreeSelectionChangeSource, TreeToggleSource {
public static final String COMPONENT_TYPE = "org.richfaces.Tree";
public static final String COMPONENT_FAMILY = "org.richfaces.Tree";
public static final String SELECTION_META_COMPONENT_ID = "selection";
-
+
private static final String DEFAULT_TREE_NODE_CREATED = AbstractTree.class.getName() + ":DEFAULT_TREE_NODE_CREATED";
-
+
private static final class MatchingTreeNodePredicate implements Predicate<UIComponent> {
-
+
private String type;
public MatchingTreeNodePredicate(String type) {
@@ -96,20 +113,16 @@
if (!(input instanceof AbstractTreeNode)) {
return false;
}
-
- if (!input.isRendered()) {
- return false;
- }
-
+
String nodeType = ((AbstractTreeNode) input).getType();
if (type == null && nodeType == null) {
return true;
}
-
+
return type != null && type.equals(nodeType);
}
};
-
+
private static final Converter ROW_KEY_CONVERTER = new SequenceRowKeyConverter();
/**
@@ -126,6 +139,12 @@
selection
}
+ @Attribute(generate = false, signature = @Signature(returnType = Void.class, parameters = TreeSelectionChangeEvent.class))
+ private MethodExpression selectionChangeListener;
+
+ @Attribute(generate = false, signature = @Signature(returnType = Void.class, parameters = TreeToggleListener.class))
+ private MethodExpression toggleListener;
+
public AbstractTree() {
setKeepSaved(true);
setRendererType("org.richfaces.TreeRenderer");
@@ -136,44 +155,52 @@
public abstract boolean isImmediate();
public abstract String getIconLeaf();
-
+
public abstract String getIconExpanded();
-
+
public abstract String getIconCollapsed();
public abstract String getNodeClass();
-
+
public abstract String getHandleClass();
-
+
public abstract String getIconClass();
-
+
public abstract String getLabelClass();
-
+
@Attribute(events = @EventName("nodetoggle"))
public abstract String getOnnodetoggle();
-
+
+ @Attribute(events = @EventName("beforenodetoggle"))
+ public abstract String getOnbeforenodetoggle();
+
@Attribute(events = @EventName("selectionchange"))
public abstract String getOnselectionchange();
-
+
+ @Attribute(events = @EventName("beforeselectionchange"))
+ public abstract String getOnbeforeselectionchange();
+
@Attribute(defaultValue = "SwitchType.DEFAULT")
public abstract SwitchType getToggleType();
@Attribute(defaultValue = "SwitchType.client")
public abstract SwitchType getSelectionType();
-
+
public abstract String getNodeType();
+
+ public abstract String getToggleNodeEvent();
@Override
public String getFamily() {
return COMPONENT_FAMILY;
}
-
+
public Collection<Object> getSelection() {
@SuppressWarnings("unchecked")
Collection<Object> selection = (Collection<Object>) getStateHelper().eval(PropertyKeys.selection);
if (selection == null) {
selection = new HashSet<Object>();
-
+
ValueExpression ve = getValueExpression(PropertyKeys.selection.toString());
if (ve != null) {
ve.setValue(getFacesContext().getELContext(), selection);
@@ -181,14 +208,14 @@
getStateHelper().put(PropertyKeys.selection, selection);
}
}
-
+
return selection;
}
-
+
public void setSelection(Collection<Object> selection) {
getStateHelper().put(PropertyKeys.selection, selection);
}
-
+
@Override
protected ExtendedDataModel<?> createExtendedDataModel() {
ExtendedTreeDataModelImpl<?> model = new ExtendedTreeDataModelImpl<TreeNode>(new SwingTreeNodeDataModelImpl());
@@ -211,41 +238,42 @@
return converter;
}
- public Iterator<Object> getChildrenRowKeysIterator(FacesContext faces, Object rowKey) {
- TreeDataModel<?> dataModel = (TreeDataModel<?>) getExtendedDataModel();
- return dataModel.getChildrenRowKeysIterator(rowKey);
- }
-
public AbstractTreeNode findTreeNodeComponent() {
FacesContext facesContext = getFacesContext();
-
+
String nodeType = getNodeType();
- Iterator<UIComponent> iterator = Iterators.filter(getChildren().iterator(),
+ Iterator<UIComponent> matchingNodes = Iterators.filter(getChildren().iterator(),
new MatchingTreeNodePredicate(nodeType));
-
- if (iterator.hasNext()) {
- return (AbstractTreeNode) iterator.next();
+
+ boolean hasNodes = matchingNodes.hasNext();
+ if (hasNodes) {
+ Iterator<UIComponent> renderedTreeNodes = Iterators.filter(matchingNodes, ComponentPredicates.isRendered());
+ if (renderedTreeNodes.hasNext()) {
+ return (AbstractTreeNode) renderedTreeNodes.next();
+ } else {
+ return null;
+ }
}
if (Strings.isNullOrEmpty(nodeType)) {
if (getAttributes().put(DEFAULT_TREE_NODE_CREATED, Boolean.TRUE) != null) {
return null;
}
-
+
Application application = facesContext.getApplication();
AbstractTreeNode treeNode = (AbstractTreeNode) application.createComponent(AbstractTreeNode.COMPONENT_TYPE);
treeNode.setId("__defaultTreeNode");
-
+
getChildren().add(treeNode);
-
+
UIComponent text = application.createComponent(HtmlOutputText.COMPONENT_TYPE);
text.setValueExpression("value", application.getExpressionFactory().createValueExpression(facesContext.getELContext(),
"#{" + getVar() + "}", String.class));
treeNode.getChildren().add(text);
-
+
return treeNode;
}
-
+
return null;
}
@@ -255,28 +283,83 @@
if (event instanceof TreeSelectionChangeEvent) {
TreeSelectionChangeEvent selectionEvent = (TreeSelectionChangeEvent) event;
-
+
final Collection<Object> newSelection = selectionEvent.getNewSelection();
Collection<Object> selectionCollection = getSelection();
-
+
Iterables.removeIf(selectionCollection, new Predicate<Object>() {
public boolean apply(Object input) {
return !newSelection.contains(input);
};
});
-
+
if (!newSelection.isEmpty()) {
Iterables.addAll(selectionCollection, newSelection);
}
+ } else if (event instanceof TreeToggleEvent) {
+ TreeToggleEvent toggleEvent = (TreeToggleEvent) event;
+ AbstractTreeNode treeNodeComponent = findTreeNodeComponent();
+
+ boolean newExpandedValue = toggleEvent.isExpanded();
+
+ FacesContext context = getFacesContext();
+ ValueExpression expression = getValueExpression(AbstractTreeNode.PropertyKeys.expanded.toString());
+ if (expression != null) {
+ ELContext elContext = context.getELContext();
+ Exception caught = null;
+ FacesMessage message = null;
+ try {
+ expression.setValue(elContext, newExpandedValue);
+ } catch (ELException e) {
+ caught = e;
+ String messageStr = e.getMessage();
+ Throwable result = e.getCause();
+ while (null != result &&
+ result.getClass().isAssignableFrom(ELException.class)) {
+ messageStr = result.getMessage();
+ result = result.getCause();
+ }
+ if (null == messageStr) {
+ MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
+ message =
+ messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
+ MessageUtil.getLabel(context, this));
+ } else {
+ message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ messageStr,
+ messageStr);
+ }
+ } catch (Exception e) {
+ caught = e;
+ MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
+ message =
+ messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
+ MessageUtil.getLabel(context, this));
+ }
+ if (caught != null) {
+ assert(message != null);
+ UpdateModelException toQueue = new UpdateModelException(message, caught);
+ ExceptionQueuedEventContext eventContext =
+ new ExceptionQueuedEventContext(context,
+ toQueue,
+ this,
+ PhaseId.UPDATE_MODEL_VALUES);
+ context.getApplication().publishEvent(context,
+ ExceptionQueuedEvent.class,
+ eventContext);
+ }
+ } else {
+ treeNodeComponent.setExpanded(newExpandedValue);
+ }
}
}
-
+
@Override
protected boolean visitFixedChildren(VisitContext visitContext, VisitCallback callback) {
if (visitContext instanceof ExtendedVisitContext) {
ExtendedVisitContext extendedVisitContext = (ExtendedVisitContext) visitContext;
-
+
if (ExtendedVisitContextMode.RENDER == extendedVisitContext.getVisitMode()) {
VisitResult result = extendedVisitContext.invokeMetaComponentVisitCallback(this, callback, SELECTION_META_COMPONENT_ID);
if (result != VisitResult.ACCEPT) {
@@ -287,7 +370,7 @@
return super.visitFixedChildren(visitContext, callback);
}
-
+
void decodeMetaComponent(FacesContext context, String metaComponentId) {
((MetaComponentRenderer) getRenderer(context)).decodeMetaComponent(context, this, metaComponentId);
}
@@ -295,15 +378,15 @@
public void encodeMetaComponent(FacesContext context, String metaComponentId) throws IOException {
((MetaComponentRenderer) getRenderer(context)).encodeMetaComponent(context, this, metaComponentId);
}
-
+
public String resolveClientId(FacesContext facesContext, UIComponent contextComponent, String metaComponentId) {
if (SELECTION_META_COMPONENT_ID.equals(metaComponentId)) {
return getClientId(facesContext) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR + metaComponentId;
}
-
+
return null;
}
-
+
public String substituteUnresolvedClientId(FacesContext facesContext, UIComponent contextComponent,
String metaComponentId) {
@@ -319,35 +402,58 @@
return Iterators.<UIComponent>emptyIterator();
}
}
-
+
@Override
public DataComponentState getComponentState() {
return new TreeComponentState();
}
- public void addSelectionChangeListener(TreeSelectionChangeListener listener) {
+ public void addTreeSelectionChangeListener(TreeSelectionChangeListener listener) {
addFacesListener(listener);
}
- public TreeSelectionChangeListener[] getSelectionChangeListeners() {
+ @Attribute(hidden = true)
+ public TreeSelectionChangeListener[] getTreeSelectionChangeListeners() {
return (TreeSelectionChangeListener[]) getFacesListeners(TreeSelectionChangeListener.class);
}
-
- public void removeSelectionChangeListener(TreeSelectionChangeListener listener) {
+
+ public void removeTreeSelectionChangeListener(TreeSelectionChangeListener listener) {
removeFacesListener(listener);
}
+ public void addTreeToggleListener(TreeToggleListener listener) {
+ addFacesListener(listener);
+ }
+
@Attribute(hidden = true)
+ public TreeToggleListener[] getTreeToggleListeners() {
+ return (TreeToggleListener[]) getFacesListeners(TreeToggleListener.class);
+ }
+
+ public void removeTreeToggleListener(TreeToggleListener listener) {
+ removeFacesListener(listener);
+ }
+
+ @Attribute(hidden = true)
public boolean isExpanded() {
if (getRowKey() == null) {
return true;
}
-
+
AbstractTreeNode treeNode = findTreeNodeComponent();
if (treeNode == null) {
return false;
}
-
+
return treeNode.isExpanded();
}
+
+ @Attribute(hidden = true)
+ public boolean isLeaf() {
+ if (getRowKey() == null) {
+ return false;
+ }
+
+ return ((TreeDataModel<?>) getExtendedDataModel()).isLeaf();
+ }
}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -23,37 +23,30 @@
import java.io.IOException;
-import javax.el.ELContext;
-import javax.el.ELException;
+import javax.el.MethodExpression;
import javax.el.ValueExpression;
-import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
-import javax.faces.component.UpdateModelException;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
-import javax.faces.event.ExceptionQueuedEvent;
-import javax.faces.event.ExceptionQueuedEventContext;
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
import org.ajax4jsf.component.IterationStateHolder;
-import org.richfaces.application.MessageFactory;
-import org.richfaces.application.ServiceTracker;
-import org.richfaces.appplication.FacesMessages;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.EventName;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Signature;
import org.richfaces.cdk.annotations.Tag;
-import org.richfaces.component.util.MessageUtil;
import org.richfaces.context.ExtendedVisitContext;
import org.richfaces.context.ExtendedVisitContextMode;
import org.richfaces.event.TreeToggleEvent;
import org.richfaces.event.TreeToggleListener;
+import org.richfaces.event.TreeToggleSource;
import org.richfaces.renderkit.MetaComponentRenderer;
/**
@@ -63,11 +56,11 @@
@JsfComponent(
type = AbstractTreeNode.COMPONENT_TYPE,
family = AbstractTreeNode.COMPONENT_FAMILY,
- tag = @Tag(name = "treeNode"),
+ tag = @Tag(name = "treeNode", handler = "org.richfaces.view.facelets.TreeNodeHandler"),
renderer = @JsfRenderer(type = "org.richfaces.TreeNodeRenderer"),
attributes = {"events-props.xml", "core-props.xml", "i18n-props.xml"}
)
-public abstract class AbstractTreeNode extends UIComponentBase implements MetaComponentResolver, MetaComponentEncoder, IterationStateHolder {
+public abstract class AbstractTreeNode extends UIComponentBase implements MetaComponentResolver, MetaComponentEncoder, IterationStateHolder, TreeToggleSource {
public static final String COMPONENT_TYPE = "org.richfaces.TreeNode";
@@ -75,10 +68,13 @@
public static final String SUBTREE_META_COMPONENT_ID = "subtree";
- private enum PropertyKeys {
+ enum PropertyKeys {
expanded
}
+ @Attribute(generate = false, signature = @Signature(returnType = Void.class, parameters = TreeToggleEvent.class))
+ private MethodExpression toggleListener;
+
public AbstractTreeNode() {
setRendererType("org.richfaces.TreeNodeRenderer");
}
@@ -108,6 +104,9 @@
@Attribute(events = @EventName("toggle"))
public abstract String getOntoggle();
+ @Attribute(events = @EventName("beforetoggle"))
+ public abstract String getOnbeforetoggle();
+
protected Boolean getLocalExpandedValue(FacesContext facesContext) {
return (Boolean) getStateHelper().get(PropertyKeys.expanded);
}
@@ -166,69 +165,20 @@
if (event instanceof TreeToggleEvent) {
TreeToggleEvent toggleEvent = (TreeToggleEvent) event;
- boolean newExpandedValue = toggleEvent.isExpanded();
-
- FacesContext context = getFacesContext();
- ValueExpression expression = getValueExpression(PropertyKeys.expanded.toString());
- if (expression != null) {
- ELContext elContext = context.getELContext();
- Exception caught = null;
- FacesMessage message = null;
- try {
- expression.setValue(elContext, newExpandedValue);
- } catch (ELException e) {
- caught = e;
- String messageStr = e.getMessage();
- Throwable result = e.getCause();
- while (null != result &&
- result.getClass().isAssignableFrom(ELException.class)) {
- messageStr = result.getMessage();
- result = result.getCause();
- }
- if (null == messageStr) {
- MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
- message =
- messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
- MessageUtil.getLabel(context, this));
- } else {
- message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
- messageStr,
- messageStr);
- }
- } catch (Exception e) {
- caught = e;
- MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
- message =
- messageFactory.createMessage(context, FacesMessages.UIINPUT_UPDATE,
- MessageUtil.getLabel(context, this));
- }
- if (caught != null) {
- assert(message != null);
- UpdateModelException toQueue = new UpdateModelException(message, caught);
- ExceptionQueuedEventContext eventContext =
- new ExceptionQueuedEventContext(context,
- toQueue,
- this,
- PhaseId.UPDATE_MODEL_VALUES);
- context.getApplication().publishEvent(context,
- ExceptionQueuedEvent.class,
- eventContext);
- }
- } else {
- setExpanded(newExpandedValue);
- }
+ new TreeToggleEvent(findTreeComponent(), toggleEvent.isExpanded()).queue();
}
}
- public void addToggleListener(TreeToggleListener listener) {
+ public void addTreeToggleListener(TreeToggleListener listener) {
addFacesListener(listener);
}
+ @Attribute(hidden = true)
public TreeToggleListener[] getTreeToggleListeners() {
return (TreeToggleListener[]) getFacesListeners(TreeToggleListener.class);
}
- public void removeToggleListener(TreeToggleListener listener) {
+ public void removeTreeToggleListener(TreeToggleListener listener) {
removeFacesListener(listener);
}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeRange.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -50,8 +50,7 @@
return true;
}
- tree.setRowKey(facesContext, rowKey);
- return tree.isExpanded();
+ return !tree.isLeaf() && tree.isExpanded();
}
}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeSelectionChangeListener.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeSelectionChangeListener.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeSelectionChangeListener.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+import javax.el.MethodExpression;
+import javax.faces.event.AbortProcessingException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MethodExpressionTreeSelectionChangeListener extends MethodExpressionEventListener implements TreeSelectionChangeListener {
+
+ public MethodExpressionTreeSelectionChangeListener() {
+ super();
+ }
+
+ public MethodExpressionTreeSelectionChangeListener(MethodExpression methodExprOneArg,
+ MethodExpression methodExprZeroArg) {
+ super(methodExprOneArg, methodExprZeroArg);
+ }
+
+ public MethodExpressionTreeSelectionChangeListener(MethodExpression methodExpressionOneArg) {
+ super(methodExpressionOneArg);
+ }
+
+ public void processSelectionChange(TreeSelectionChangeEvent event) throws AbortProcessingException {
+ processEvent(event);
+ }
+
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeToggleListener.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeToggleListener.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/event/MethodExpressionTreeToggleListener.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+import javax.el.MethodExpression;
+import javax.faces.event.AbortProcessingException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MethodExpressionTreeToggleListener extends MethodExpressionEventListener implements TreeToggleListener {
+
+ public MethodExpressionTreeToggleListener() {
+ super();
+ }
+
+ public MethodExpressionTreeToggleListener(MethodExpression methodExprOneArg, MethodExpression methodExprZeroArg) {
+ super(methodExprOneArg, methodExprZeroArg);
+ }
+
+ public MethodExpressionTreeToggleListener(MethodExpression methodExpressionOneArg) {
+ super(methodExpressionOneArg);
+ }
+
+ public void processToggle(TreeToggleEvent event) throws AbortProcessingException {
+ processEvent(event);
+ }
+
+}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ExtendedTreeDataModelImpl.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ExtendedTreeDataModelImpl.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/ExtendedTreeDataModelImpl.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -21,15 +21,11 @@
*/
package org.richfaces.model;
-import java.util.Iterator;
-
import javax.faces.context.FacesContext;
-import org.ajax4jsf.model.DataVisitResult;
import org.ajax4jsf.model.DataVisitor;
import org.ajax4jsf.model.ExtendedDataModel;
import org.ajax4jsf.model.Range;
-import org.richfaces.component.TreeRange;
/**
* @author Nick Belaevski
@@ -52,10 +48,6 @@
return wrappedModel.getData();
}
- public Iterator<Object> getChildrenRowKeysIterator(Object rowKey) {
- return wrappedModel.getChildrenRowKeysIterator(rowKey);
- }
-
public Object getParentRowKey(Object rowKey) {
throw new UnsupportedOperationException();
}
@@ -70,31 +62,11 @@
return wrappedModel.getRowKey();
}
- protected void walk(FacesContext context, DataVisitor visitor, Range range, Object argument, Iterator<Object> keysIterator) {
- while (keysIterator.hasNext()) {
- Object object = (Object) keysIterator.next();
-
- DataVisitResult visitResult = visitor.process(context, object, argument);
- if (visitResult == DataVisitResult.CONTINUE) {
- if (((TreeRange) range).shouldIterateChildren(object)) {
- Iterator<Object> childrenIterator = getChildrenRowKeysIterator(object);
- walk(context, visitor, range, argument, childrenIterator);
- }
- }
- }
- }
-
@Override
public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument) {
- TreeRange treeRange = (TreeRange) range;
- if (treeRange.shouldIterateChildren(null)) {
- setRowKey(null);
- DataVisitResult visitResult = visitor.process(context, null, argument);
- if (visitResult == DataVisitResult.CONTINUE) {
- Iterator<Object> iterator = getChildrenRowKeysIterator(null);
- walk(context, visitor, range, argument, iterator);
- }
- }
+ wrappedModel.enterNode(visitor);
+ wrappedModel.walk(context, visitor, range, argument);
+ wrappedModel.exitNode(visitor);
}
@Override
@@ -131,5 +103,31 @@
wrappedModel.setWrappedData(data);
}
+ /* (non-Javadoc)
+ * @see org.richfaces.model.TreeDataModel#isLeaf()
+ */
+ public boolean isLeaf() {
+ // TODO Auto-generated method stub
+ return wrappedModel.isLeaf();
+ }
+ /* (non-Javadoc)
+ * @see org.richfaces.model.TreeDataModel#enterNode(org.ajax4jsf.model.DataVisitor)
+ */
+ public void enterNode(DataVisitor visitor) {
+ // TODO Auto-generated method stub
+
+ wrappedModel.enterNode(visitor);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.TreeDataModel#exitNode(org.ajax4jsf.model.DataVisitor)
+ */
+ public void exitNode(DataVisitor visitor) {
+ // TODO Auto-generated method stub
+
+ wrappedModel.exitNode(visitor);
+ }
+
+
}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKey.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -49,6 +49,24 @@
return new SequenceRowKey<T>(ObjectArrays.concat(simpleKeys, segment));
}
+ public T getLastKeySegment() {
+ if (simpleKeys.length == 0) {
+ return null;
+ }
+
+ return simpleKeys[simpleKeys.length - 1];
+ }
+
+ public SequenceRowKey<T> getParent() {
+ if (simpleKeys.length == 0) {
+ return null;
+ }
+
+ T[] parentSimpleKeys = ObjectArrays.newArray(simpleKeys, simpleKeys.length - 1);
+ System.arraycopy(simpleKeys, 0, parentSimpleKeys, 0, parentSimpleKeys.length);
+ return new SequenceRowKey<T>(parentSimpleKeys);
+ }
+
@Override
public int hashCode() {
final int prime = 31;
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -23,25 +23,29 @@
import java.util.Iterator;
+import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
+
/**
* @author Nick Belaevski
*
*/
-public class SequenceRowKeyIterator<T> implements Iterator<Object> {
+public abstract class SequenceRowKeyIterator<K, T> implements Iterator<Object> {
- private int counter = 0;
+ private SequenceRowKey<K> baseKey;
- private SequenceRowKey<Integer> baseKey;
-
private Iterator<T> itr;
private T element;
- private SequenceRowKey<Integer> elementKey;
+ private SequenceRowKey<K> elementKey;
+
+ private T baseElement;
- public SequenceRowKeyIterator(SequenceRowKey<Integer> baseKey, Iterator<T> itr) {
+ public SequenceRowKeyIterator(SequenceRowKey<K> baseKey, T baseElement, Iterator<T> itr) {
super();
this.baseKey = baseKey;
+ this.baseElement = baseElement;
this.itr = itr;
}
@@ -49,10 +53,17 @@
return itr.hasNext();
}
+ protected abstract K nextKey();
+
public Object next() {
element = itr.next();
- elementKey = baseKey.append(counter++);
+ if (baseKey != null) {
+ elementKey = baseKey.append(nextKey());
+ } else {
+ elementKey = new SequenceRowKey<K>(nextKey());
+ }
+
return elementKey;
}
@@ -60,7 +71,15 @@
return element;
}
- public SequenceRowKey<Integer> getElementKey() {
+ public SequenceRowKey<K> getBaseKey() {
+ return baseKey;
+ }
+
+ public T getBaseElement() {
+ return baseElement;
+ }
+
+ public SequenceRowKey<K> getElementKey() {
return elementKey;
}
@@ -68,4 +87,12 @@
throw new UnsupportedOperationException();
}
+ @Override
+ public String toString() {
+ ToStringHelper helper = Objects.toStringHelper(this);
+
+ helper.add("element", element).add("elementKey", elementKey);
+
+ return helper.toString();
+ }
}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -36,13 +36,46 @@
* @author Nick Belaevski
*
*/
-public class SwingTreeNodeDataModelImpl implements TreeDataModel<TreeNode> {
+public class SwingTreeNodeDataModelImpl extends TreeSequenceKeyModel<Integer, TreeNode> {
/**
* @author Nick Belaevski
*
*/
+ private static final class SwingTreeNodeRowKeyIterator extends SequenceRowKeyIterator<Integer, TreeNode> {
+
+ private int counter = 0;
+
+ /**
+ * @param baseKey
+ * @param baseElement
+ * @param itr
+ */
+ private SwingTreeNodeRowKeyIterator(SequenceRowKey<Integer> baseKey, TreeNode baseElement,
+ Iterator<TreeNode> itr) {
+ super(baseKey, baseElement, itr);
+ }
+
+ @Override
+ protected Integer nextKey() {
+ return counter++;
+ }
+ }
+
+
+ /**
+ * @author Nick Belaevski
+ *
+ */
private final class FakeRootNode implements TreeNode {
+
+ private Collection<TreeNode> wrappedData;
+
+ public FakeRootNode(Collection<TreeNode> wrappedData) {
+ super();
+ this.wrappedData = wrappedData;
+ }
+
public boolean isLeaf() {
return !wrappedData.isEmpty();
}
@@ -86,21 +119,13 @@
return Iterators.asEnumeration(wrappedData.iterator());
}
+
+ public Collection<TreeNode> getWrappedData() {
+ return wrappedData;
+ }
}
- private static final SequenceRowKey<Integer> EMPTY_SEQUENCE_ROW_KEY = new SequenceRowKey<Integer>();
-
- private Collection<TreeNode> wrappedData = null;
-
- private TreeNode fakeRootNode = new FakeRootNode();
-
- private TreeNode selectedNode;
-
- private SequenceRowKey<Integer> selectedRowKey;
-
- private Iterator<TreeNode> findChildren(SequenceRowKey<Integer> compositeKey) {
- TreeNode treeNode = findNode(compositeKey);
-
+ private Iterator<TreeNode> safeGetChildren(SequenceRowKey<Integer> key, TreeNode treeNode) {
if (treeNode == null) {
return Iterators.emptyIterator();
}
@@ -108,72 +133,48 @@
return Iterators.forEnumeration((Enumeration<TreeNode>) treeNode.children());
}
- private TreeNode findNode(SequenceRowKey<Integer> compositeKey) {
- if (compositeKey == null) {
- return null;
+
+ public Object getParentRowKey(Object rowKey) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isLeaf() {
+ if (!isDataAvailable()) {
+ throw new IllegalStateException();
}
- TreeNode result = fakeRootNode;
+ TreeNode treeNode = getData();
- for (Integer simpleKey : compositeKey.getSimpleKeys()) {
- int idx = simpleKey.intValue();
-
- if (idx < result.getChildCount()) {
- result = result.getChildAt(idx);
- } else {
- result = null;
- break;
- }
- }
-
- return result;
+ return !treeNode.getAllowsChildren() || treeNode.isLeaf();
}
-
- public void setRowKey(Object key) {
- this.selectedRowKey = (SequenceRowKey<Integer>) key;
- this.selectedNode = findNode(selectedRowKey);
- }
- public Object getRowKey() {
- return selectedRowKey;
+ public void setWrappedData(Object data) {
+ setRootNode(new FakeRootNode((Collection<TreeNode>) data));
}
-
- private SequenceRowKey<Integer> castKeyAndWrapNull(Object rowKey) {
- if (rowKey == null) {
- return EMPTY_SEQUENCE_ROW_KEY;
+
+ public Collection<TreeNode> getWrappedData() {
+ FakeRootNode rootNode = (FakeRootNode) getRootNode();
+ if (rootNode == null) {
+ return null;
}
-
- return (SequenceRowKey<Integer>) rowKey;
+ return rootNode.getWrappedData();
}
-
- public Iterator<Object> getChildrenRowKeysIterator(Object rowKey) {
- SequenceRowKey<Integer> sequenceKey = castKeyAndWrapNull(rowKey);
- Iterator<TreeNode> itr = findChildren(sequenceKey);
-
- return new SequenceRowKeyIterator<TreeNode>(sequenceKey, itr);
- }
- public TreeNode getData() {
- if (!isDataAvailable()) {
- throw new IllegalArgumentException();
+ @Override
+ protected TreeNode findChild(TreeNode parent, Integer simpleKey) {
+ int idx = simpleKey.intValue();
+ if (idx >= 0 && idx < parent.getChildCount()) {
+ return parent.getChildAt(idx);
}
- return selectedNode;
+ return null;
}
- public Object getParentRowKey(Object rowKey) {
- throw new UnsupportedOperationException();
- }
- public boolean isDataAvailable() {
- return selectedRowKey == null || selectedNode != null;
+ @Override
+ protected SequenceRowKeyIterator<Integer, TreeNode> createChildrenIterator(SequenceRowKey<Integer> baseKey,
+ TreeNode value) {
+
+ return new SwingTreeNodeRowKeyIterator(baseKey, value, safeGetChildren(baseKey, value));
}
-
- public Object getWrappedData() {
- return wrappedData;
- }
-
- public void setWrappedData(Object wrappedData) {
- this.wrappedData = (Collection<TreeNode>) wrappedData;
- }
}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -0,0 +1,168 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.model;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.ListIterator;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.Range;
+import org.richfaces.component.TreeRange;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class TreeSequenceKeyModel<K, V> implements TreeDataModel<V> {
+
+ private V rootNode;
+
+ private V currentData;
+
+ private SequenceRowKey<K> currentRowKey;
+
+ private LinkedList<SequenceRowKeyIterator<K, V>> keysStack = new LinkedList<SequenceRowKeyIterator<K, V>>();
+
+ public SequenceRowKey<K> getRowKey() {
+ return currentRowKey;
+ }
+
+ public void setRowKey(Object rowKey) {
+ this.currentRowKey = (SequenceRowKey<K>) rowKey;
+ this.currentData = findData(currentRowKey);
+ }
+
+ public boolean isDataAvailable() {
+ return currentRowKey == null || currentData != null;
+ }
+
+ public abstract boolean isLeaf();
+
+ public V getData() {
+ if (!isDataAvailable()) {
+ throw new IllegalArgumentException();
+ }
+
+ return currentData;
+ }
+
+ protected boolean isRootNodeKey(SequenceRowKey<K> key) {
+ return key == null || key.getLastKeySegment() == null;
+ }
+
+ protected V findData(SequenceRowKey<K> key) {
+ if (key == null) {
+ return rootNode;
+ }
+
+ if (!keysStack.isEmpty()) {
+ ListIterator<SequenceRowKeyIterator<K, V>> listIterator = keysStack.listIterator(keysStack.size());
+
+ while (listIterator.hasPrevious()) {
+ SequenceRowKeyIterator<K, V> previous = listIterator.previous();
+
+ V baseNode = null;
+
+ SequenceRowKey<K> baseKey = previous.getBaseKey();
+ if (isRootNodeKey(baseKey) && isRootNodeKey(key.getParent())) {
+ baseNode = rootNode;
+ } else if (baseKey.equals(key.getParent())) {
+ baseNode = previous.getBaseElement();
+ }
+
+ if (baseNode == null) {
+ continue;
+ }
+
+ return findChild(baseNode, key.getLastKeySegment());
+ }
+ }
+
+ V result = rootNode;
+
+ for (K simpleKey : key.getSimpleKeys()) {
+ result = findChild(result, simpleKey);
+
+ if (result == null) {
+ break;
+ }
+ }
+
+ return result;
+ }
+
+ protected abstract V findChild(V parent, K simpleKey);
+
+ protected abstract SequenceRowKeyIterator<K, V> createChildrenIterator(SequenceRowKey<K> baseKey, V value);
+
+ public void enterNode(DataVisitor visitor) {
+ SequenceRowKey<K> sequenceKey = getRowKey();
+ V data = findData(sequenceKey);
+
+ keysStack.addLast(createChildrenIterator(sequenceKey, data));
+
+ if (visitor instanceof TreeDataVisitor) {
+ ((TreeDataVisitor) visitor).enterNode();
+ }
+ }
+
+ public void walk(FacesContext context, DataVisitor visitor, Range range, Object argument) {
+ if (getRowKey() != null) {
+ visitor.process(context, getRowKey(), argument);
+ }
+
+ TreeRange treeRange = (TreeRange) range;
+
+ if (treeRange.shouldIterateChildren(getRowKey())) {
+ enterNode(visitor);
+ Iterator<Object> keysIterator = keysStack.getLast();
+ while (keysIterator.hasNext()) {
+ Object key = (Object) keysIterator.next();
+ setRowKey(key);
+ walk(context, visitor, range, argument);
+ }
+ exitNode(visitor);
+ }
+ }
+
+ public void exitNode(DataVisitor visitor) {
+ if (visitor instanceof TreeDataVisitor) {
+ ((TreeDataVisitor) visitor).exitNode();
+ }
+
+ keysStack.removeLast();
+ }
+
+ public abstract Object getParentRowKey(Object rowKey);
+
+ protected V getRootNode() {
+ return rootNode;
+ }
+
+ protected void setRootNode(V rootNode) {
+ this.rootNode = rootNode;
+ }
+
+}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderBase.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -22,111 +22,138 @@
package org.richfaces.renderkit;
import java.io.IOException;
-import java.util.Iterator;
import java.util.LinkedList;
+import javax.faces.FacesException;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.model.DataVisitResult;
import org.richfaces.component.AbstractTree;
import org.richfaces.component.AbstractTreeNode;
-import org.richfaces.component.TreeRange;
import org.richfaces.component.util.HtmlUtil;
+import org.richfaces.model.TreeDataVisitor;
import org.richfaces.renderkit.TreeRendererBase.QueuedData;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.UnmodifiableIterator;
+abstract class TreeEncoderBase implements TreeDataVisitor {
-abstract class TreeEncoderBase {
+ static final String TREE_NODE_STATE_ATTRIBUTE = "__treeNodeState";
- static final String TREE_NODE_STATE_ATTRIBUTE = "__treeNodeState";
-
protected final FacesContext context;
-
+
protected final ResponseWriter responseWriter;
-
+
protected final AbstractTree tree;
- private TreeRange treeRange;
-
- private LinkedList<QueuedData> queuedData = new LinkedList<QueuedData>();
-
+ private LinkedList<QueuedData> queuedDataList = new LinkedList<QueuedData>();
+
+ private QueuedData queuedData;
+
public TreeEncoderBase(FacesContext context, AbstractTree tree) {
super();
this.context = context;
this.responseWriter = context.getResponseWriter();
this.tree = tree;
-
- this.treeRange = (TreeRange) tree.getComponentState().getRange();
}
- protected void encodeTree(Iterator<Object> childrenIterator) throws IOException {
- Predicate<Object> renderedTreeNodeKeyPredicate = new Predicate<Object>() {
- public boolean apply(Object input) {
- tree.setRowKey(input);
-
- if (!tree.isRowAvailable()) {
- return false;
+ protected void encodeTree() throws IOException {
+ tree.walk(context, this, null);
+ }
+
+ protected void flushNode() throws IOException {
+ if (!queuedData.isEncoded()) {
+ tree.setRowKey(context, queuedData.getRowKey());
+
+ TreeNodeState state;
+ if (tree.isLeaf()) {
+ state = TreeNodeState.leaf;
+ } else {
+ if (queuedData.isVisited()) {
+ state = TreeNodeState.leaf;
+ } else {
+ state = TreeNodeState.collapsed;
}
-
- return tree.findTreeNodeComponent() != null;
}
- };
+
+ writeTreeNodeStartElement(state);
+ }
+
+ writeTreeNodeEndElement();
+ }
+
+ protected void flushParentNode() throws IOException {
+ if (queuedDataList.isEmpty()) {
+ return;
+ }
- UnmodifiableIterator<Object> filteredIterator = Iterators.filter(childrenIterator, renderedTreeNodeKeyPredicate);
- while (filteredIterator.hasNext()) {
- Object rowKey = filteredIterator.next();
+ QueuedData data = queuedDataList.getLast();
+ if (!data.isEncoded()) {
+ data.setEncoded(true);
+ tree.setRowKey(context, data.getRowKey());
- encodeTreeNode(rowKey, !filteredIterator.hasNext());
+ writeTreeNodeStartElement(tree.isExpanded() ? TreeNodeState.expanded : TreeNodeState.collapsed);
}
}
- protected void encodeTreeNode(Object rowKey, boolean isLastNode) throws IOException {
- if (!queuedData.isEmpty()) {
- QueuedData data = queuedData.getLast();
- if (!data.isEncoded()) {
- tree.setRowKey(context, data.getRowKey());
-
- writeTreeNodeStartElement(data.isExpanded() ? TreeNodeState.expanded : TreeNodeState.collapsed, data.isLastNode());
-
- data.setEncoded(true);
+ public void enterNode() {
+ if (queuedData != null) {
+ queuedData.makeVisited();
+ queuedDataList.add(queuedData);
+ queuedData = null;
+ }
+ }
+
+ public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
+ try {
+ if (queuedData != null) {
+ flushNode();
+ queuedData = null;
+ } else {
+ flushParentNode();
}
+ } catch (IOException e) {
+ throw new FacesException(e.getMessage(), e);
}
-
- tree.setRowKey(context, rowKey);
- boolean expanded = tree.isExpanded();
- queuedData.add(new QueuedData(rowKey, isLastNode, expanded));
-
- boolean iterateChildren = treeRange.shouldIterateChildren(rowKey);
-
- if (iterateChildren) {
- encodeTree(tree.getChildrenRowKeysIterator(context, rowKey));
+ if (rowKey != null) {
+ tree.setRowKey(context, rowKey);
+
+ if (tree.isRowAvailable() && tree.findTreeNodeComponent() != null) {
+ queuedData = new QueuedData(rowKey);
+ }
}
- QueuedData data = queuedData.removeLast();
- if (!data.isEncoded()) {
- TreeNodeState nodeState = iterateChildren ? TreeNodeState.leaf : TreeNodeState.collapsed;
- writeTreeNodeStartElement(nodeState, data.isLastNode());
+ return DataVisitResult.CONTINUE;
+ }
+
+ public void exitNode() {
+ try {
+ if (queuedData != null) {
+ flushNode();
+ queuedData = null;
+ }
+
+ if (!queuedDataList.isEmpty()) {
+ queuedData = queuedDataList.removeLast();
+ }
+ } catch (IOException e) {
+ throw new FacesException(e.getMessage(), e);
}
-
- writeTreeNodeEndElement();
}
-
- protected void writeTreeNodeStartElement(TreeNodeState nodeState, boolean isLast) throws IOException {
+
+ protected void writeTreeNodeStartElement(TreeNodeState nodeState) throws IOException {
AbstractTreeNode treeNodeComponent = tree.findTreeNodeComponent();
context.getAttributes().put(TREE_NODE_STATE_ATTRIBUTE, nodeState);
-
+
responseWriter.startElement(HtmlConstants.DIV_ELEM, tree);
responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
- HtmlUtil.concatClasses("rf-tr-nd", isLast ? "rf-tr-nd-last" : null, nodeState.getNodeClass()),
+ HtmlUtil.concatClasses("rf-tr-nd", nodeState.getNodeClass()),
null);
responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE, treeNodeComponent.getClientId(context), null);
-
+
emitClientToggleEvent(treeNodeComponent, nodeState);
treeNodeComponent.encodeAll(context);
}
@@ -136,12 +163,12 @@
}
public abstract void encode() throws IOException;
-
+
private void emitClientToggleEvent(AbstractTreeNode treeNode, TreeNodeState nodeState) {
if (treeNode.getClientId(context).equals(context.getAttributes().get(TreeNodeRendererBase.AJAX_TOGGLED_NODE_ATTRIBUTE))) {
TreeNodeState submittedState = ((Boolean) (context.getAttributes().get(TreeNodeRendererBase.AJAX_TOGGLED_NODE_STATE_ATTRIBUTE)))
? TreeNodeState.expanded : TreeNodeState.collapsed;
-
+
if (submittedState == nodeState || nodeState == TreeNodeState.leaf) {
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
ajaxContext.appendOncomplete(new JSFunction("RichFaces.ui.TreeNode.emitToggleEvent", treeNode.getClientId(context)));
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderFull.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -38,7 +38,8 @@
public void encode() throws java.io.IOException {
Object initialRowKey = tree.getRowKey();
try {
- encodeTree(tree.getChildrenRowKeysIterator(context, null));
+ tree.setRowKey(context, null);
+ encodeTree();
} finally {
try {
tree.setRowKey(context, initialRowKey);
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeEncoderPartial.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -63,8 +63,9 @@
Object initialRowKey = tree.getRowKey();
try {
TreeRenderingContext.create(context, tree);
-
- encodeTreeNode(rowKey, true);
+ tree.setRowKey(context, rowKey);
+
+ encodeTree();
prw.endUpdate();
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -88,16 +88,12 @@
private Object rowKey;
- private boolean lastNode;
-
- private boolean expanded;
-
private boolean encoded;
- public QueuedData(Object rowKey, boolean lastNode, boolean expanded) {
+ private boolean visited;
+
+ public QueuedData(Object rowKey) {
this.rowKey = rowKey;
- this.lastNode = lastNode;
- this.expanded = expanded;
}
public void setEncoded(boolean encoded) {
@@ -112,12 +108,12 @@
return rowKey;
}
- public boolean isLastNode() {
- return lastNode;
+ public boolean isVisited() {
+ return visited;
}
-
- public boolean isExpanded() {
- return expanded;
+
+ public void makeVisited() {
+ visited = true;
}
}
@@ -216,7 +212,7 @@
writer.startEval();
JSFunction function = new JSFunction("RichFaces.$", component.getClientId(context));
- writer.write(function.toScript() + ".__updateSelection();");
+ writer.write(function.toScript() + ".__updateSelectionFromInput();");
writer.endEval();
} else {
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRenderingContext.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -49,12 +49,20 @@
private static final ComponentAttribute ONNODETOGGLE_ATTRIBUTE = new ComponentAttribute("onnodetoggle").setEventNames("nodetoggle");
+ private static final ComponentAttribute ONBEFORETOGGLE_ATTRIBUTE = new ComponentAttribute("onbeforetoggle").setEventNames("beforetoggle");
+
+ private static final ComponentAttribute ONBEFORENODETOGGLE_ATTRIBUTE = new ComponentAttribute("onbeforenodetoggle").setEventNames("beforenodetoggle");
+
public static final class Handlers extends ScriptStringBase {
private String toggleHandler;
private String nodeToggleHandler;
+ private String beforeToggleHandler;
+
+ private String beforeNodeToggleHandler;
+
protected Object chain(String firstHandler, String secondHandler) {
if (isNullOrEmpty(firstHandler) && isNullOrEmpty(secondHandler)) {
return null;
@@ -68,7 +76,7 @@
return firstHandler;
}
- return new JSFunction("jsf.util.chain", JSReference.THIS, JSReference.EVENT, firstHandler, secondHandler).toScript();
+ return new JSFunction("return jsf.util.chain", JSReference.THIS, JSReference.EVENT, firstHandler, secondHandler).toScript();
}
public void setToggleHandler(String toggleHandler) {
@@ -79,17 +87,49 @@
return toggleHandler;
}
+ public void setNodeToggleHandler(String nodeToggleHandler) {
+ this.nodeToggleHandler = nodeToggleHandler;
+ }
+
public String getNodeToggleHandler() {
return nodeToggleHandler;
}
- public void setNodeToggleHandler(String nodeToggleHandler) {
- this.nodeToggleHandler = nodeToggleHandler;
+ public void setBeforeToggleHandler(String beforeToggleHandler) {
+ this.beforeToggleHandler = beforeToggleHandler;
}
-
+
+ public String getBeforeToggleHandler() {
+ return beforeToggleHandler;
+ }
+
+ public void setBeforeNodeToggleHandler(String beforeNodeToggleHandler) {
+ this.beforeNodeToggleHandler = beforeNodeToggleHandler;
+ }
+
+ public String getBeforeNodeToggleHandler() {
+ return beforeNodeToggleHandler;
+ }
+
public void appendScript(Appendable target) throws IOException {
- Object chain = chain(toggleHandler, nodeToggleHandler);
- ScriptUtils.appendScript(target, chain);
+ Object chainedToggleHandler = chain(toggleHandler, nodeToggleHandler);
+ Object chainedBeforeToggleHandler = chain(beforeToggleHandler, beforeNodeToggleHandler);
+
+ if (chainedToggleHandler != null || chainedBeforeToggleHandler != null) {
+ Map<String,Object> map = new HashMap<String, Object>(2);
+
+ if (chainedToggleHandler != null) {
+ map.put("th", chainedToggleHandler);
+ }
+
+ if (chainedBeforeToggleHandler != null) {
+ map.put("bth", chainedBeforeToggleHandler);
+ }
+
+ ScriptUtils.appendScript(target, map);
+ } else {
+ ScriptUtils.appendScript(target, null);
+ }
}
}
@@ -145,10 +185,20 @@
getOrCreateHandlers(relativeClientId).setToggleHandler(toggleHandler);
}
+ String beforeToggleHandler = (String) RenderKitUtils.getAttributeAndBehaviorsValue(context, treeNode, ONBEFORETOGGLE_ATTRIBUTE);
+ if (!isNullOrEmpty(beforeToggleHandler)) {
+ getOrCreateHandlers(relativeClientId).setBeforeToggleHandler(beforeToggleHandler);
+ }
+
String nodeToggleHandler = (String) RenderKitUtils.getAttributeAndBehaviorsValue(context, tree, ONNODETOGGLE_ATTRIBUTE);
if (!isNullOrEmpty(nodeToggleHandler)) {
getOrCreateHandlers(relativeClientId).setNodeToggleHandler(nodeToggleHandler);
}
+
+ String beforeNodeToggleHandler = (String) RenderKitUtils.getAttributeAndBehaviorsValue(context, tree, ONBEFORENODETOGGLE_ATTRIBUTE);
+ if (!isNullOrEmpty(beforeNodeToggleHandler)) {
+ getOrCreateHandlers(relativeClientId).setBeforeNodeToggleHandler(beforeNodeToggleHandler);
+ }
}
}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeHandler.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.view.facelets;
+
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.richfaces.component.AbstractTree;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TreeHandler extends ComponentHandler {
+
+ private static final MetaRule RULE = new MetaRule() {
+
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) {
+ if (meta.isTargetInstanceOf(AbstractTree.class)) {
+ if ("selectionChangeListener".equals(name)) {
+ return new TreeSelectionChangeListenerExpressionMetadata(attribute);
+ } else if ("toggleListener".equals(name)) {
+ return new TreeToggleListenerExpressionMetadata(attribute);
+ }
+
+ }
+ return null;
+ }
+ };
+
+ public TreeHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset metaRuleset = super.createMetaRuleset(type);
+ metaRuleset.addRule(RULE);
+ return metaRuleset;
+ }
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeNodeHandler.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.view.facelets;
+
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.richfaces.component.AbstractTreeNode;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TreeNodeHandler extends ComponentHandler {
+
+ private static final MetaRule RULE = new MetaRule() {
+
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget meta) {
+ if (meta.isTargetInstanceOf(AbstractTreeNode.class)) {
+ if ("toggleListener".equals(name)) {
+ return new TreeToggleListenerExpressionMetadata(attribute);
+ }
+ }
+ return null;
+ }
+ };
+
+ public TreeNodeHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset metaRuleset = super.createMetaRuleset(type);
+ metaRuleset.addRule(RULE);
+ return metaRuleset;
+ }
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeSelectionChangeListenerExpressionMetadata.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -0,0 +1,31 @@
+package org.richfaces.view.facelets;
+
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.richfaces.event.MethodExpressionTreeSelectionChangeListener;
+import org.richfaces.event.TreeSelectionChangeEvent;
+import org.richfaces.event.TreeSelectionChangeSource;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+final class TreeSelectionChangeListenerExpressionMetadata extends Metadata {
+
+ private static final Class<?>[] SIGNATURE = new Class[] { TreeSelectionChangeEvent.class };
+
+ private final TagAttribute attr;
+
+ TreeSelectionChangeListenerExpressionMetadata(TagAttribute attr) {
+ this.attr = attr;
+ }
+
+ @Override
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((TreeSelectionChangeSource) instance).addTreeSelectionChangeListener(new MethodExpressionTreeSelectionChangeListener(
+ this.attr.getMethodExpression(ctx, null, SIGNATURE)));
+ }
+
+}
\ No newline at end of file
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java (rev 0)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/view/facelets/TreeToggleListenerExpressionMetadata.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -0,0 +1,31 @@
+package org.richfaces.view.facelets;
+
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.TagAttribute;
+
+import org.richfaces.event.MethodExpressionTreeToggleListener;
+import org.richfaces.event.TreeToggleEvent;
+import org.richfaces.event.TreeToggleSource;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+final class TreeToggleListenerExpressionMetadata extends Metadata {
+
+ private static final Class<?>[] SIGNATURE = new Class[] { TreeToggleEvent.class };
+
+ private final TagAttribute attr;
+
+ TreeToggleListenerExpressionMetadata(TagAttribute attr) {
+ this.attr = attr;
+ }
+
+ @Override
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((TreeToggleSource) instance).addTreeToggleListener(new MethodExpressionTreeToggleListener(this.attr
+ .getMethodExpression(ctx, null, SIGNATURE)));
+ }
+
+}
\ No newline at end of file
Modified: trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
===================================================================
--- trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-11-18 18:50:06 UTC (rev 20107)
@@ -46,15 +46,21 @@
this.__initializeChildren(commonOptions);
- var __toggleHandler = (commonOptions.clientEventHandlers || {})[this.getId().substring(commonOptions.treeId.length)];
+ var handlers = (commonOptions.clientEventHandlers || {})[this.getId().substring(commonOptions.treeId.length)] || {};
- if (__toggleHandler) {
- richfaces.Event.bind(this.__rootElt, "toggle", new Function("event", __toggleHandler));
+ if (handlers.bth) {
+ richfaces.Event.bind(this.__rootElt, "beforetoggle", new Function("event", handlers.bth));
}
+
+ if (handlers.th) {
+ richfaces.Event.bind(this.__rootElt, "toggle", new Function("event", handlers.th));
+ }
+
+ this.__addLastNodeClass();
},
destroy: function() {
- this.$super.destroy.call(this);
+ richfaces.BaseComponent.prototype.destroy.call(this);
if (this.parent) {
this.parent.removeChild(this);
@@ -75,6 +81,12 @@
});
},
+ __addLastNodeClass: function() {
+ if (this.__rootElt.next("div").length == 0) {
+ this.__rootElt.addClass("rf-tr-nd-last");
+ }
+ },
+
__getHandle: function() {
return this.__rootElt.find(" > .rf-trn:first > .rf-trn-hnd:first");
},
@@ -163,13 +175,22 @@
},
+ __fireBeforeToggleEvent: function() {
+ return richfaces.Event.callHandler(this.__rootElt, "beforetoggle");
+ },
+
__fireToggleEvent: function() {
- richfaces.Event.fire(this.__rootElt, "toggle");
+ richfaces.Event.callHandler(this.__rootElt, "toggle");
},
__changeToggleState: function(newState) {
if (!this.isLeaf()) {
if (newState ^ this.isExpanded()) {
+
+ if (this.__fireBeforeToggleEvent() === false) {
+ return;
+ }
+
var tree = this.getTree();
switch (tree.getToggleType()) {
@@ -234,10 +255,6 @@
var opts = commonOptions || {};
- if (node.nextAll(".rf-tr-nd:first").length != 0) {
- node.removeClass("rf-tr-nd-last");
- }
-
var parent = node.parent(".rf-tr-nd, .rf-tr");
var idx = node.prevAll(".rf-tr-nd").length;
@@ -247,7 +264,7 @@
var newChild = new richfaces.ui.TreeNode(node[0], opts);
parentNode.addChild(newChild, idx);
- parentNode.getTree().__updateSelection();
+ parentNode.getTree().__updateSelectionFromInput();
};
richfaces.ui.TreeNode.emitToggleEvent = function(nodeId) {
@@ -291,31 +308,52 @@
this.__ajaxSubmitFunction = new Function("event", "source", "params", options.ajaxSubmitFunction);
}
+ if (options.onbeforeselectionchange) {
+ richfaces.Event.bind(this.__treeRootElt, "beforeselectionchange", new Function("event", options.onbeforeselectionchange));
+ }
+
if (options.onselectionchange) {
richfaces.Event.bind(this.__treeRootElt, "selectionchange", new Function("event", options.onselectionchange));
}
+ this.__toggleNodeEvent = options.toggleNodeEvent;
+ if (this.__toggleNodeEvent) {
+ this.__treeRootElt.delegate(".rf-trn", this.__toggleNodeEvent, this, this.__nodeToggleActivated);
+ }
+ if (!this.__toggleNodeEvent || this.__toggleNodeEvent != 'click') {
+ this.__treeRootElt.delegate(".rf-trn-hnd", "click", this, this.__nodeToggleActivated);
+ }
+
+ this.__treeRootElt.delegate(".rf-trn-cnt", "mousedown", this, this.__nodeSelectionActivated);
+
this.__selectionInput = $(" > .rf-tr-sel-inp", this.__treeRootElt);
+ this.__selection = new richfaces.ui.TreeNodeSet(this.__selectionInput.val());
- this.__treeRootElt.delegate(".rf-trn-hnd", "click", this, this.__itemHandleClicked);
- this.__treeRootElt.delegate(".rf-trn-cnt", "mousedown", this, this.__itemContentClicked);
-
- this.__updateSelection();
+ $(document).ready($.proxy(this.__updateSelectionFromInput, this));
},
+ __addLastNodeClass: function() {
+ //stub function overriding parent class method
+ },
+
destroy: function() {
- this.$super.destroy.call(this);
+ richfaces.ui.TreeNode.prototype.destroy.call(this);
- this.__treeRootElt.undelegate(".rf-trn-hnd", "click", this.__itemHandleClicked);
- this.__treeRootElt.undelegate(".rf-trn-cnt", "mousedown", this.__itemContentClicked);
+ if (this.__toggleNodeEvent) {
+ this.__treeRootElt.undelegate(".rf-trn", this.__toggleNodeEvent, this, this.__nodeToggleActivated);
+ }
+ if (!this.__toggleNodeEvent || this.__toggleNodeEvent != 'click') {
+ this.__treeRootElt.undelegate(".rf-trn-hnd", "click", this, this.__nodeToggleActivated);
+ }
+
+ this.__treeRootElt.undelegate(".rf-trn-cnt", "mousedown", this.__nodeSelectionActivated);
this.__treeRootElt = null;
- this.__itemContentClickedHandler = null;
this.__selectionInput = null;
this.__ajaxSubmitFunction = null;
},
- __itemHandleClicked: function(event) {
+ __nodeToggleActivated: function(event) {
var theTree = event.data;
if (isEventForAnotherTree(theTree, this)) {
return;
@@ -325,7 +363,7 @@
treeNode.toggle();
},
- __itemContentClicked: function(event) {
+ __nodeSelectionActivated: function(event) {
var theTree = event.data;
if (isEventForAnotherTree(theTree, this)) {
return;
@@ -365,68 +403,119 @@
return this;
},
- __bindFocusHandler: function(elt) {
- elt.mousedown(this.__itemContentClickedHandler);
- },
-
__isSelected: function(node) {
- return this.__selectedNodeId == node.getId();
+ return this.__selection.contains(node);
},
- __handleSelectionChange: function() {
+ __handleSelectionChange: function(newSelection) {
+ var eventData = {
+ oldSelection: this.__selection.getNodes(),
+ newSelection: newSelection.getNodes()
+ };
+
+ if (richfaces.Event.callHandler(this.__treeRootElt, "beforeselectionchange", eventData) === false) {
+ return;
+ }
+
+ this.__selectionInput.val(newSelection.toString());
+
if (this.getSelectionType() == 'client') {
- this.__updateSelection();
+ this.__updateSelection(newSelection);
} else {
this.__ajaxSubmitFunction(null, this.getId());
}
},
__toggleSelection: function(node) {
- if (this.__isSelected(node)) {
- this.__selectionInput.val("");
- } else {
- this.__selectionInput.val(node.getId());
- }
-
- this.__handleSelectionChange();
+ var newSelection = this.__selection.cloneAndToggle(node);
+ this.__handleSelectionChange(newSelection);
},
__addToSelection: function(node) {
- this.__selectionInput.val(node.getId());
-
- this.__handleSelectionChange();
+ var newSelection = this.__selection.cloneAndAdd(node);
+ this.__handleSelectionChange(newSelection);
},
- __updateSelection: function() {
- var oldSelection = new Array();
- var newSelection = new Array();
+ __updateSelectionFromInput: function() {
+ this.__updateSelection(new richfaces.ui.TreeNodeSet(this.__selectionInput.val()));
+ },
+
+ __updateSelection: function(newSelection) {
+
+ var oldSelection = this.__selection;
- var oldSelectionId = this.__selectedNodeId;
- var newSelectionId = this.__selectionInput.val();
-
- if (oldSelectionId == newSelectionId) {
- return;
+ oldSelection.each(function() {this.__setSelected(false)});
+ newSelection.each(function() {this.__setSelected(true)});
+
+ if (oldSelection.getNodeString() != newSelection.getNodeString()) {
+ richfaces.Event.callHandler(this.__treeRootElt, "selectionchange", {
+ oldSelection: oldSelection.getNodes(),
+ newSelection: newSelection.getNodes()
+ });
}
- if (oldSelectionId) {
- var oldSelectionNode = richfaces.$(oldSelectionId);
- if (oldSelectionNode) {
- oldSelectionNode.__setSelected(false);
- oldSelection.push(oldSelectionNode);
+ this.__selection = newSelection;
+ }
+ });
+
+ richfaces.ui.TreeNodeSet = function() {
+ this.init.apply(this, arguments);
+ };
+
+ //TODO - that's a single-node set, implement multi-node support!
+ $.extend(richfaces.ui.TreeNodeSet.prototype, {
+
+ init: function(nodeId) {
+ this.__nodeId = nodeId;
+ },
+
+ contains: function(node) {
+ if (node.getId) {
+ return this.__nodeId == node.getId();
+ } else {
+ return this.__nodeId == node;
+ }
+ },
+
+ getNodeString: function() {
+ return this.__nodeId;
+ },
+
+ toString: function() {
+ return this.getNodeString();
+ },
+
+ getNodes: function() {
+ if (this.__nodeId) {
+ var node = richfaces.$(this.__nodeId);
+ if (node) {
+ return [node];
+ } else {
+ return null;
}
}
- if (newSelectionId) {
- var newSelectionNode = richfaces.$(newSelectionId);
- if (newSelectionNode) {
- newSelectionNode.__setSelected(true);
- newSelection.push(newSelectionNode);
- }
+ return [];
+ },
+
+ cloneAndAdd: function(node) {
+ return new richfaces.ui.TreeNodeSet(node.getId());
+ },
+
+ cloneAndToggle: function(node) {
+ var nodeId;
+ if (this.contains(node)) {
+ nodeId = "";
+ } else {
+ nodeId = node.getId();
}
-
- this.__selectedNodeId = newSelectionId;
- richfaces.Event.fire(this.__treeRootElt, "selectionchange", {oldSelection: oldSelection, newSelection: newSelection});
+
+ return new richfaces.ui.TreeNodeSet(nodeId);
+ },
+
+ each: function(callback) {
+ $.each(this.getNodes() || [], callback);
}
});
-
+
}(jQuery, RichFaces));
\ No newline at end of file
Modified: trunk/ui/iteration/ui/src/main/templates/tree.template.xml
===================================================================
--- trunk/ui/iteration/ui/src/main/templates/tree.template.xml 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/templates/tree.template.xml 2010-11-18 18:50:06 UTC (rev 20107)
@@ -44,7 +44,7 @@
<cdk:scriptOption attributes="toggleType" defaultValue="SwitchType.DEFAULT" />
<cdk:scriptOption name="selectionType" value="#{getSelectionMode(facesContext, component)}" defaultValue="SwitchType.client" />
<cdk:scriptOption name="ajaxSubmitFunction" value="#{getAjaxSubmitFunction(facesContext, component)}" />
- <cdk:scriptOption attributes="onselectionchange" />
+ <cdk:scriptOption attributes="onselectionchange onbeforeselectionchange toggleNodeEvent" />
<cdk:scriptOption variables="clientEventHandlers" />
</cdk:scriptObject>
Modified: trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml
===================================================================
--- trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml 2010-11-18 18:50:06 UTC (rev 20107)
@@ -21,17 +21,16 @@
<cc:implementation>
<cdk:object name="nodeState" value="#{getNodeState(facesContext)}" type="org.richfaces.renderkit.TreeNodeState" />
+ <cdk:object name="tree" value="#{getTreeComponent(component)}" type="UIComponent" />
<cdk:call expression="addClientEventHandlers(facesContext, component)" />
- <cdk:call expression="addClientEventHandlers(facesContext, component)" />
-
<div class="#{concatClasses('rf-trn', component.attributes['styleClass'], tree.attributes['nodeClass'])}">
<span class="#{concatClasses(nodeState.handleClass, component.attributes['handleClass'], tree.attributes['handleClass'])}"></span>
<span class="rf-trn-cnt">
<cdk:call expression="encodeIcon(facesContext, component)" />
- <span class="#{concatClasses('rf-trn-lbl', component.attributes['labelClass'])}">
+ <span class="#{concatClasses('rf-trn-lbl', component.attributes['labelClass'], tree.attributes['labelClass'])}">
<cdk:body />
</span>
</span>
Modified: trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java
===================================================================
--- trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2010-11-18 17:10:13 UTC (rev 20106)
+++ trunk/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientAndAjaxScript.java 2010-11-18 18:50:06 UTC (rev 20107)
@@ -18,7 +18,7 @@
}
- protected void finishValidation(StringBuffer body) {
+ protected void finishValidation(StringBuilder body) {
// AJAX callback
body.append("if(!").append(DISABLE_AJAX).append("){\n");
body.append(ajaxScript).append(EOL).append("}\n");
14 years, 1 month
JBoss Rich Faces SVN: r20106 - in trunk: examples/iteration-demo/src/main/webapp and 7 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-11-18 12:10:13 -0500 (Thu, 18 Nov 2010)
New Revision: 20106
Added:
trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java
trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java
trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java
trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java
Removed:
trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionEvent.java
trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionListener.java
Modified:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java
trunk/examples/iteration-demo/src/main/webapp/tree.xhtml
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/TreeBean.java
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml
Log:
https://jira.jboss.org/browse/RF-9714
https://jira.jboss.org/browse/RF-9717
Modified: trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java
===================================================================
--- trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java 2010-11-18 17:01:46 UTC (rev 20105)
+++ trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/TreeBean.java 2010-11-18 17:10:13 UTC (rev 20106)
@@ -30,6 +30,7 @@
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
+import javax.faces.event.AjaxBehaviorEvent;
import javax.swing.tree.TreeNode;
import org.richfaces.component.SwitchType;
@@ -96,13 +97,10 @@
}
public Object getNodeData() {
- return nodeData;
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ return facesContext.getApplication().evaluateExpressionGet(facesContext, "#{node}", Object.class);
}
- public void setNodeData(Object nodeData) {
- this.nodeData = nodeData;
- }
-
public Collection<Object> getSelection() {
return selection;
}
@@ -123,4 +121,14 @@
public void setShowCustomClasses(boolean showCustomClasses) {
this.showCustomClasses = showCustomClasses;
}
+
+ public void behaviorToggleListener(AjaxBehaviorEvent event) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ facesContext.addMessage(null, new FacesMessage("Toggle node: " + getNodeData() + ", source is: " + event.getSource()));
+ }
+
+ public void behaviorSelectionChangeListener(AjaxBehaviorEvent event) {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ facesContext.addMessage(event.getComponent().getClientId(facesContext), new FacesMessage("Selection changed, source is: " + event.getSource()));
+ }
}
Modified: trunk/examples/iteration-demo/src/main/webapp/tree.xhtml
===================================================================
--- trunk/examples/iteration-demo/src/main/webapp/tree.xhtml 2010-11-18 17:01:46 UTC (rev 20105)
+++ trunk/examples/iteration-demo/src/main/webapp/tree.xhtml 2010-11-18 17:10:13 UTC (rev 20106)
@@ -32,6 +32,15 @@
<h:body>
<h:outputScript>
+ function nodesArrayToString(nodes) {
+ var result = new Array();
+ jQuery.each(nodes, function(k, v) {
+ result.push(v.getId());
+ });
+
+ return result.join('');
+ }
+
function getNodeStateString(treeNode) {
return treeNode.isLeaf() ?
'leaf'
@@ -47,13 +56,10 @@
function handleNodeSelect(event) {
var treeNode = RichFaces.$(event.target);
- var selectedNodes = event.rf.data.selection;
- var selection = new Array();
- jQuery.each(selectedNodes, function(k, v) {
- selection.push(v.getId());
- });
+ var oldSelectionString = nodesArrayToString(event.rf.data.oldSelection);
+ var newSelectionString = nodesArrayToString(event.rf.data.newSelection);
- RichFaces.log.info('Select event:\n ' + selection.join(''));
+ RichFaces.log.info('Selection changed from: [' + oldSelectionString + '] to: [' + newSelectionString + ']');
}
</h:outputScript>
@@ -79,8 +85,6 @@
<h:panelGroup id="rootNodeGroup">
Root node: #{node.data} -
<h:commandLink value="link" action="#{treeBean.clickNode}">
- <f:setPropertyActionListener value="#{node.data}" target="#{treeBean.nodeData}" />
-
<f:ajax render=":messages" />
</h:commandLink>
</h:panelGroup>
@@ -89,8 +93,6 @@
<h:panelGroup id="childNodeGroup">
#{node.data} -
<h:commandLink value="link" action="#{treeBean.clickNode}">
- <f:setPropertyActionListener value="#{node.data}" target="#{treeBean.nodeData}" />
-
<f:ajax render=":messages" />
</h:commandLink>
</h:panelGroup>
@@ -124,12 +126,29 @@
selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}"
onnodetoggle="handleNodeToggle("#{node.data}", event, false)"
onselectionchange="handleNodeSelect(event)">
-
+
<it:treeNode ontoggle="handleNodeToggle("#{node.data}", event, true)">
#{node.data}
</it:treeNode>
</it:tree>
+ Tree with attached behaviors:
+ <h:messages id="treeBehaviorsMessages" for="behaviorsAttachedTree" />
+ <h:messages id="treeNodeBehaviorsMessages" globalOnly="true" />
+
+ <it:tree id="behaviorsAttachedTree" var="node" value="#{treeBean.rootNodes}"
+ selectionType="#{treeBean.selectionType}" toggleType="#{treeBean.toggleType}">
+
+ <f:ajax event="nodetoggle" listener="#{treeBean.behaviorToggleListener}" render=":form:treeBehaviorsMessages" />
+ <f:ajax event="selectionchange" listener="#{treeBean.behaviorSelectionChangeListener}" render=":form:treeBehaviorsMessages :form:treeNodeBehaviorsMessages" />
+
+ <it:treeNode>
+ #{node.data}
+
+ <f:ajax event="toggle" listener="#{treeBean.behaviorToggleListener}" render=":form:treeNodeBehaviorsMessages" />
+ </it:treeNode>
+ </it:tree>
+
<a4j:log />
</h:form>
</h:body>
Modified: trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/TreeBean.java
===================================================================
--- trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/TreeBean.java 2010-11-18 17:01:46 UTC (rev 20105)
+++ trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/tree/TreeBean.java 2010-11-18 17:10:13 UTC (rev 20106)
@@ -36,7 +36,7 @@
import org.richfaces.demo.tree.model.CD;
import org.richfaces.demo.tree.model.Company;
import org.richfaces.demo.tree.model.Country;
-import org.richfaces.event.TreeSelectionEvent;
+import org.richfaces.event.TreeSelectionChangeEvent;
/**
* @author Ilya Shaikovsky
@@ -88,7 +88,7 @@
return company;
}
- private void selectionListener(TreeSelectionEvent event) {
+ private void selectionListener(TreeSelectionChangeEvent event) {
//TODO: implement when ready
}
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
===================================================================
--- trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-11-18 17:01:46 UTC (rev 20105)
+++ trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-11-18 17:10:13 UTC (rev 20106)
@@ -385,6 +385,7 @@
}
//TODO - create special method for event handlers that will return String?
+ //TODO - add check for 'disabled'?
public static Object getAttributeAndBehaviorsValue(FacesContext facesContext, UIComponent component,
ComponentAttribute componentAttribute) {
if (facesContext == null) {
Copied: trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java (from rev 20105, trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionEvent.java)
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java (rev 0)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeEvent.java 2010-11-18 17:10:13 UTC (rev 20106)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+import java.util.Collection;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TreeSelectionChangeEvent extends FacesEvent {
+
+ private static final long serialVersionUID = 6292604445872458007L;
+
+ private Collection<Object> oldSelection;
+
+ private Collection<Object> newSelection;
+
+ public TreeSelectionChangeEvent(UIComponent component, Collection<Object> oldSelection, Collection<Object> newSelection) {
+ super(component);
+
+ this.oldSelection = oldSelection;
+ this.newSelection = newSelection;
+ }
+
+ @Override
+ public boolean isAppropriateListener(FacesListener listener) {
+ return listener instanceof TreeSelectionChangeListener;
+ }
+
+ @Override
+ public void processListener(FacesListener listener) {
+ ((TreeSelectionChangeListener) listener).processSelection(this);
+ }
+
+ public Collection<Object> getOldSelection() {
+ return oldSelection;
+ }
+
+ public Collection<Object> getNewSelection() {
+ return newSelection;
+ }
+
+}
Copied: trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java (from rev 20105, trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionListener.java)
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java (rev 0)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeListener.java 2010-11-18 17:10:13 UTC (rev 20106)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+import javax.faces.event.FacesListener;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeSelectionChangeListener extends FacesListener {
+
+ public void processSelection(TreeSelectionChangeEvent event);
+
+}
Copied: trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java (from rev 20105, trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionListener.java)
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java (rev 0)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionChangeSource.java 2010-11-18 17:10:13 UTC (rev 20106)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeSelectionChangeSource {
+
+ public void addSelectionChangeListener(TreeSelectionChangeListener listener);
+
+ public void removeSelectionchangeListener(TreeSelectionChangeListener listener);
+
+}
Deleted: trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionEvent.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionEvent.java 2010-11-18 17:01:46 UTC (rev 20105)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionEvent.java 2010-11-18 17:10:13 UTC (rev 20106)
@@ -1,67 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.event;
-
-import java.util.Collection;
-
-import javax.faces.component.UIComponent;
-import javax.faces.event.FacesEvent;
-import javax.faces.event.FacesListener;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class TreeSelectionEvent extends FacesEvent {
-
- private static final long serialVersionUID = 6292604445872458007L;
-
- private Collection<Object> oldSelection;
-
- private Collection<Object> newSelection;
-
- public TreeSelectionEvent(UIComponent component, Collection<Object> oldSelection, Collection<Object> newSelection) {
- super(component);
-
- this.oldSelection = oldSelection;
- this.newSelection = newSelection;
- }
-
- @Override
- public boolean isAppropriateListener(FacesListener listener) {
- return listener instanceof TreeSelectionListener;
- }
-
- @Override
- public void processListener(FacesListener listener) {
- ((TreeSelectionListener) listener).processSelection(this);
- }
-
- public Collection<Object> getOldSelection() {
- return oldSelection;
- }
-
- public Collection<Object> getNewSelection() {
- return newSelection;
- }
-
-}
Deleted: trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionListener.java
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionListener.java 2010-11-18 17:01:46 UTC (rev 20105)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionListener.java 2010-11-18 17:10:13 UTC (rev 20106)
@@ -1,34 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.event;
-
-import javax.faces.event.FacesListener;
-
-/**
- * @author Nick Belaevski
- *
- */
-public interface TreeSelectionListener extends FacesListener {
-
- public void processSelection(TreeSelectionEvent event);
-
-}
Copied: trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java (from rev 20105, trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeSelectionListener.java)
===================================================================
--- trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java (rev 0)
+++ trunk/ui/iteration/api/src/main/java/org/richfaces/event/TreeToggleSource.java 2010-11-18 17:10:13 UTC (rev 20106)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.event;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeToggleSource {
+
+ public void addToggleListener(TreeToggleListener listener);
+
+ public void removeToggleListener(TreeToggleListener listener);
+
+}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-18 17:01:46 UTC (rev 20105)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-18 17:10:13 UTC (rev 20106)
@@ -50,8 +50,8 @@
import org.richfaces.context.ExtendedVisitContext;
import org.richfaces.context.ExtendedVisitContextMode;
import org.richfaces.convert.SequenceRowKeyConverter;
-import org.richfaces.event.TreeSelectionEvent;
-import org.richfaces.event.TreeSelectionListener;
+import org.richfaces.event.TreeSelectionChangeEvent;
+import org.richfaces.event.TreeSelectionChangeListener;
import org.richfaces.model.ExtendedTreeDataModelImpl;
import org.richfaces.model.SwingTreeNodeDataModelImpl;
import org.richfaces.model.TreeDataModel;
@@ -253,8 +253,8 @@
public void broadcast(FacesEvent event) throws AbortProcessingException {
super.broadcast(event);
- if (event instanceof TreeSelectionEvent) {
- TreeSelectionEvent selectionEvent = (TreeSelectionEvent) event;
+ if (event instanceof TreeSelectionChangeEvent) {
+ TreeSelectionChangeEvent selectionEvent = (TreeSelectionChangeEvent) event;
final Collection<Object> newSelection = selectionEvent.getNewSelection();
@@ -325,15 +325,15 @@
return new TreeComponentState();
}
- public void addSelectionListener(TreeSelectionListener listener) {
+ public void addSelectionChangeListener(TreeSelectionChangeListener listener) {
addFacesListener(listener);
}
- public TreeSelectionListener[] getSelectionListeners() {
- return (TreeSelectionListener[]) getFacesListeners(TreeSelectionListener.class);
+ public TreeSelectionChangeListener[] getSelectionChangeListeners() {
+ return (TreeSelectionChangeListener[]) getFacesListeners(TreeSelectionChangeListener.class);
}
- public void removeSelectionListener(TreeSelectionListener listener) {
+ public void removeSelectionChangeListener(TreeSelectionChangeListener listener) {
removeFacesListener(listener);
}
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-11-18 17:01:46 UTC (rev 20105)
+++ trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-11-18 17:10:13 UTC (rev 20106)
@@ -45,7 +45,7 @@
import org.richfaces.component.AbstractTreeNode;
import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.SwitchType;
-import org.richfaces.event.TreeSelectionEvent;
+import org.richfaces.event.TreeSelectionChangeEvent;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
@@ -262,7 +262,7 @@
}
if (newSelection != null) {
- new TreeSelectionEvent(component, Sets.newHashSet(selection), newSelection).queue();
+ new TreeSelectionChangeEvent(component, Sets.newHashSet(selection), newSelection).queue();
}
PartialViewContext pvc = context.getPartialViewContext();
Modified: trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js
===================================================================
--- trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-11-18 17:01:46 UTC (rev 20105)
+++ trunk/ui/iteration/ui/src/main/resources/META-INF/resources/org.richfaces/tree.js 2010-11-18 17:10:13 UTC (rev 20106)
@@ -398,34 +398,34 @@
},
__updateSelection: function() {
- var oldSelection = this.__selectedNodeId;
- var nodeId = this.__selectionInput.val();
+ var oldSelection = new Array();
+ var newSelection = new Array();
- if (oldSelection == nodeId) {
+ var oldSelectionId = this.__selectedNodeId;
+ var newSelectionId = this.__selectionInput.val();
+
+ if (oldSelectionId == newSelectionId) {
return;
}
- if (oldSelection) {
- var oldSelectionNode = richfaces.$(oldSelection);
+ if (oldSelectionId) {
+ var oldSelectionNode = richfaces.$(oldSelectionId);
if (oldSelectionNode) {
oldSelectionNode.__setSelected(false);
+ oldSelection.push(oldSelectionNode);
}
}
- var newSelectionNode;
- var selection = new Array();
-
- if (nodeId) {
- newSelectionNode = richfaces.$(nodeId);
+ if (newSelectionId) {
+ var newSelectionNode = richfaces.$(newSelectionId);
+ if (newSelectionNode) {
+ newSelectionNode.__setSelected(true);
+ newSelection.push(newSelectionNode);
+ }
}
- if (newSelectionNode) {
- newSelectionNode.__setSelected(true);
- selection.push(newSelectionNode);
- }
-
- this.__selectedNodeId = nodeId;
- richfaces.Event.fire(this.__treeRootElt, "selectionchange", {selection: selection});
+ this.__selectedNodeId = newSelectionId;
+ richfaces.Event.fire(this.__treeRootElt, "selectionchange", {oldSelection: oldSelection, newSelection: newSelection});
}
});
Modified: trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml
===================================================================
--- trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml 2010-11-18 17:01:46 UTC (rev 20105)
+++ trunk/ui/iteration/ui/src/main/templates/treeNode.template.xml 2010-11-18 17:10:13 UTC (rev 20106)
@@ -24,6 +24,8 @@
<cdk:call expression="addClientEventHandlers(facesContext, component)" />
+ <cdk:call expression="addClientEventHandlers(facesContext, component)" />
+
<div class="#{concatClasses('rf-trn', component.attributes['styleClass'], tree.attributes['nodeClass'])}">
<span class="#{concatClasses(nodeState.handleClass, component.attributes['handleClass'], tree.attributes['handleClass'])}"></span>
14 years, 1 month