Author: ivaynberg
Date: Mon Jul 12 23:21:06 2010
New Revision: 963524
URL: http://svn.apache.org/viewvc?rev=963524&view=rev
Log:
WICKET-2943 introduce Component#onInitialize()
Added:
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/ComponentInitializationTest.java
(with props)
Modified:
wicket/branches/wicket-1.4.x/wicket/.settings/org.eclipse.jdt.core.prefs
wicket/branches/wicket-1.4.x/wicket/.settings/org.eclipse.jdt.ui.prefs
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Component.java
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
Modified:
wicket/branches/wicket-1.4.x/wicket/.settings/org.eclipse.jdt.core.prefs
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/.settings/org.eclipse.jdt.core.prefs?rev=963524&r1=963523&r2=963524&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/.settings/org.eclipse.jdt.core.prefs
(original)
+++ wicket/branches/wicket-1.4.x/wicket/.settings/org.eclipse.jdt.core.prefs
Mon Jul 12 23:21:06 2010
@@ -1,4 +1,4 @@
-#Wed Aug 26 08:15:28 PDT 2009
+#Sat Jun 26 11:21:27 PDT 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
@@ -90,6 +90,7 @@ org.eclipse.jdt.core.compiler.problem.va
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
@@ -100,6 +101,7 @@ org.eclipse.jdt.core.formatter.alignment
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=16
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
@@ -146,10 +148,15 @@ org.eclipse.jdt.core.formatter.comment.i
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
org.eclipse.jdt.core.formatter.comment.line_length=100
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
org.eclipse.jdt.core.formatter.compact_else_if=true
org.eclipse.jdt.core.formatter.continuation_indentation=1
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_t...@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_t...@formatter\:on
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
@@ -162,6 +169,10 @@ org.eclipse.jdt.core.formatter.indent_sw
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
org.eclipse.jdt.core.formatter.indentation.size=4
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do
not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do
not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do
not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert
@@ -330,6 +341,8 @@ org.eclipse.jdt.core.formatter.insert_sp
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do
not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do
not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do
not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=true
+org.eclipse.jdt.core.formatter.join_wrapped_lines=true
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
@@ -342,7 +355,9 @@ org.eclipse.jdt.core.formatter.number_of
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
org.eclipse.jdt.core.formatter.tabulation.char=tab
org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=false
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
org.eclipse.jdt.core.incompatibleJDKLevel=ignore
org.eclipse.jdt.core.incompleteClasspath=error
Modified: wicket/branches/wicket-1.4.x/wicket/.settings/org.eclipse.jdt.ui.prefs
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/.settings/org.eclipse.jdt.ui.prefs?rev=963524&r1=963523&r2=963524&view=diff
==============================================================================
--- wicket/branches/wicket-1.4.x/wicket/.settings/org.eclipse.jdt.ui.prefs
(original)
+++ wicket/branches/wicket-1.4.x/wicket/.settings/org.eclipse.jdt.ui.prefs Mon
Jul 12 23:21:06 2010
@@ -1,4 +1,4 @@
-#Wed Aug 01 11:37:07 CEST 2007
+#Sat Jun 26 11:21:27 PDT 2010
comment_clear_blank_lines=false
comment_format_comments=true
comment_format_header=true
@@ -11,7 +11,7 @@ comment_new_line_for_parameter=true
comment_separate_root_tags=true
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
-formatter_profile=_wicket
+formatter_profile=_Wicket
formatter_settings_version=11
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0"
encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="false"
context\="gettercomment_context" deleted\="false" description\="Comment for
getter method" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment"
name\="gettercomment">/**\r\n * Gets ${bare_field_name}.\r\n * @return
${bare_field_name}\r\n */</template><template autoinsert\="false"
context\="settercomment_context" deleted\="false" description\="Comment for
setter method" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.settercomment"
name\="settercomment">/**\r\n * Sets ${bare_field_name}.\r\n * @param ${param}
${bare_field_name}\r\n */</template><template autoinsert\="false"
context\="constructorcomment_context" deleted\="false" description\="Comment
for created constructors" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment"
name\="constructorcomment">/**\r\n * Construct.\r\n
* ${tags}\r\n */</template><template autoinsert\="false"
context\="filecomment_context" deleted\="false" description\="Comment for
created Java files" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.filecomment"
name\="filecomment"/><template autoinsert\="false"
context\="typecomment_context" deleted\="false" description\="Comment for
created types" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.typecomment"
name\="typecomment">/**\r\n * @author ${user}\r\n * ${tags}\r\n
*/</template><template autoinsert\="true" context\="fieldcomment_context"
deleted\="false" description\="Comment for fields" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment"
name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true"
context\="methodcomment_context" deleted\="false" description\="Comment for
non-overriding methods" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment"
name\="methodcomment">/**\r\n * ${tags}
\r\n */</template><template autoinsert\="false"
context\="overridecomment_context" deleted\="false" description\="Comment for
overriding methods" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment"
name\="overridecomment">/**\r\n * ${see_to_overridden}\r\n
*/</template><template autoinsert\="false" context\="newtype_context"
deleted\="false" description\="Newly created files" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">/*\r\n *
Licensed to the Apache Software Foundation (ASF) under one or more\r\n *
contributor license agreements. See the NOTICE file distributed with\r\n *
this work for additional information regarding copyright ownership.\r\n * The
ASF licenses this file to You under the Apache License, Version 2.0\r\n * (the
"License"); you may not use this file except in compliance with\r\n * the
License. You may obtain a copy of the License at\r\n *\r\n *
http\://www.apache.org/licenses/LICENSE-2.0\r\
n *\r\n * Unless required by applicable law or agreed to in writing,
software\r\n * distributed under the License is distributed on an "AS IS"
BASIS,\r\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.\r\n * See the License for the specific language governing permissions
and\r\n * limitations under the License.\r\n
*/\r\n${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template
autoinsert\="false" context\="catchblock_context" deleted\="false"
description\="Code in new catch blocks" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">throw
new RuntimeException(${exception_var});</template><template autoinsert\="false"
context\="methodbody_context" deleted\="false" description\="Code in created
method stubs" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.methodbody"
name\="methodbody">${body_statement}</template><template autoinsert\="false"
context\="c
onstructorbody_context" deleted\="false" description\="Code in created
constructor stubs" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody"
name\="constructorbody">${body_statement}</template><template
autoinsert\="true" context\="getterbody_context" deleted\="false"
description\="Code in created getters" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.getterbody"
name\="getterbody">return ${field};</template><template autoinsert\="true"
context\="setterbody_context" deleted\="false" description\="Code in created
setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody"
name\="setterbody">${field} \= ${param};</template><template autoinsert\="true"
context\="classbody_context" deleted\="false" description\="Code in new class
type bodies" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.classbody"
name\="classbody">\r\n</template><template autoinsert\="true"
context\="interfacebody_context" deleted\="false"
description\="Code in new interface type bodies" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody"
name\="interfacebody">\r\n</template><template autoinsert\="true"
context\="enumbody_context" deleted\="false" description\="Code in new enum
type bodies" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.enumbody"
name\="enumbody">\r\n</template><template autoinsert\="true"
context\="annotationbody_context" deleted\="false" description\="Code in new
annotation type bodies" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody"
name\="annotationbody">\r\n</template><template autoinsert\="true"
context\="delegatecomment_context" deleted\="false" description\="Comment for
delegate methods" enabled\="true"
id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment"
name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n
*/</template></templates>
Modified:
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Component.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Component.java?rev=963524&r1=963523&r2=963524&view=diff
==============================================================================
---
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Component.java
(original)
+++
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/Component.java
Mon Jul 12 23:21:06 2010
@@ -632,6 +632,10 @@ public abstract class Component implemen
/** True when a component is being removed from the hierarchy */
protected static final int FLAG_REMOVING_FROM_HIERARCHY = 0x200000;
+ /** True when a component has been initialized, had {...@link
#onInitialize()} called */
+ protected static final int FLAG_INITIALIZED = 0x400000;
+
+
private static final int FLAG_BEFORE_RENDERING_SUPER_CALL_VERIFIED =
0x1000000;
/**
@@ -922,8 +926,8 @@ public abstract class Component implemen
final IDebugSettings debugSettings =
Application.get().getDebugSettings();
if (debugSettings.isLinePreciseReportingOnNewComponentEnabled())
{
- setMetaData(CONSTRUCTED_AT_KEY, Strings.toString(this,
new MarkupException(
- "constructed")));
+ setMetaData(CONSTRUCTED_AT_KEY,
+ Strings.toString(this, new
MarkupException("constructed")));
}
if (model != null)
@@ -3226,9 +3230,13 @@ public abstract class Component implemen
final Page page = findPage();
if (page == null)
{
- return new StringBuffer("[Component id =
").append(getId()).append(
- ", page = <No Page>, path =
").append(getPath()).append(".").append(
-
Classes.simpleName(getClass())).append("]").toString();
+ return new StringBuffer("[Component id =
").append(getId())
+ .append(", page = <No Page>, path = ")
+ .append(getPath())
+ .append(".")
+ .append(Classes.simpleName(getClass()))
+ .append("]")
+ .toString();
}
else
{
@@ -3932,6 +3940,35 @@ public abstract class Component implemen
}
/**
+ * Used to call {...@link #onInitialize()}
+ */
+ void initialize()
+ {
+ if (!getFlag(FLAG_INITIALIZED))
+ {
+ onInitialize();
+ setFlag(FLAG_INITIALIZED, true);
+ }
+ }
+
+ /**
+ * This method is meant to be used as an alternative to initialize
components. Usually the
+ * component's constructor is used for this task, but sometimes a
component cannot be
+ * initialized in isolation, it may need to access its parent component
or its markup in order
+ * to fully initialize. This method is invoked once per component's
lifecycle when a path exists
+ * from this component to the {...@link Page} thus providing the
component with an atomic callback
+ * when the component's environment is built out.
+ *
+ * <p>
+ * It is safe to use {...@link #getPage()} in this method
+ * </p>
+ */
+ protected void onInitialize()
+ {
+ }
+
+
+ /**
* Called to notify the component it is being removed from the
component hierarchy
*
* Overrides of this method MUST call the super implementation, the
most logical place to do
Modified:
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java?rev=963524&r1=963523&r2=963524&view=diff
==============================================================================
---
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
(original)
+++
wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/MarkupContainer.java
Mon Jul 12 23:21:06 2010
@@ -348,8 +348,9 @@ public abstract class MarkupContainer ex
{
try
{
- return
getApplication().getMarkupSettings().getMarkupCache().getMarkupStream(this,
- false, throwException);
+ return getApplication().getMarkupSettings()
+ .getMarkupCache()
+ .getMarkupStream(this, false, throwException);
}
catch (MarkupException ex)
{
@@ -400,6 +401,20 @@ public abstract class MarkupContainer ex
return getPage().getMarkupType();
}
+ @Override
+ final void initialize()
+ {
+ super.initialize();
+ visitChildren(new IVisitor<Component>()
+ {
+ public Object component(Component component)
+ {
+ component.initialize();
+ return CONTINUE_TRAVERSAL;
+ }
+ });
+ }
+
/**
* THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT.
*
@@ -944,8 +959,13 @@ public abstract class MarkupContainer ex
final IDebugSettings debugSettings =
Application.get().getDebugSettings();
if (debugSettings.isLinePreciseReportingOnAddComponentEnabled())
{
- component.setMetaData(ADDED_AT_KEY,
Strings.toString(component, new MarkupException(
- "added")));
+ component.setMetaData(ADDED_AT_KEY,
+ Strings.toString(component, new
MarkupException("added")));
+ }
+
+ if (page != null)
+ {
+ component.initialize();
}
if (page != null)
Added:
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/ComponentInitializationTest.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/ComponentInitializationTest.java?rev=963524&view=auto
==============================================================================
---
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/ComponentInitializationTest.java
(added)
+++
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/ComponentInitializationTest.java
Mon Jul 12 23:21:06 2010
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket;
+
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.WebPage;
+
+/**
+ * Tests {...@link Component#onInitialize()} contract
+ *
+ * @author igor
+ */
+public class ComponentInitializationTest extends WicketTestCase
+{
+ public void testPropagation()
+ {
+ Page page = new TestPage();
+
+ TestComponent t1 = new TestComponent("t1");
+ TestComponent t2 = new TestComponent("t2");
+ TestComponent t3 = new TestComponent("t3");
+ TestComponent t4 = new TestComponent("t4");
+
+ // as soon as we add to page child should be initialized
+ page.add(t1);
+ assertEquals(1, t1.getCount());
+
+ // unless the page is available no initialization takes place
+ t2.add(t3);
+ assertEquals(0, t2.getCount());
+ assertEquals(0, t3.getCount());
+
+ // initialization cascades from initialized
+ t1.add(t2);
+ assertEquals(1, t1.getCount());
+ assertEquals(1, t2.getCount());
+ assertEquals(1, t3.getCount());
+
+ // test intialization when adding to removed components
+ page.remove(t1);
+ t3.add(t4);
+ assertEquals(0, t4.getCount());
+
+ // test initialization when readding a component with
uninitialized children
+ page.add(t1);
+ assertEquals(1, t4.getCount());
+
+
+ }
+
+
+ public void testAtomicity()
+ {
+ Page page = new TestPage();
+
+ TestComponent t1 = new TestComponent("t1");
+ TestComponent t2 = new TestComponent("t2");
+ TestComponent t3 = new TestComponent("t3");
+
+ t1.add(t2);
+ t2.add(t3);
+
+ page.add(t1);
+
+ assertEquals(1, t1.getCount());
+ assertEquals(1, t2.getCount());
+ assertEquals(1, t3.getCount());
+
+ // test moving
+ page.add(t3);
+ assertEquals(1, t3.getCount());
+
+ // test removal and readdition
+ page.remove(t1);
+ assertEquals(1, t1.getCount());
+ page.add(t1);
+ assertEquals(1, t1.getCount());
+ assertEquals(1, t2.getCount());
+ }
+
+
+ private static class TestPage extends WebPage
+ {
+
+ }
+
+ private static class TestComponent extends WebMarkupContainer
+ {
+ private int count = 0;
+
+ public TestComponent(String id)
+ {
+ super(id);
+ }
+
+ @Override
+ protected void onInitialize()
+ {
+ count++;
+ }
+
+ public int getCount()
+ {
+ return count;
+ }
+
+
+ }
+}
Propchange:
wicket/branches/wicket-1.4.x/wicket/src/test/java/org/apache/wicket/ComponentInitializationTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain