-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WICKET-6941 Add visible attribute to AbstractColumn to hide/show columns in DataTable/DataGridView #491
Open
RLStokes
wants to merge
12
commits into
apache:wicket-9.x
Choose a base branch
from
RLStokes:wicket-9.x
base: wicket-9.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+494
−414
Open
WICKET-6941 Add visible attribute to AbstractColumn to hide/show columns in DataTable/DataGridView #491
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4dd4735
WICKET-6941 Add visible attribute to AbstractColumn to hide/show colu…
RLStokes 3cb347a
WICKET-6941 Add visible attribute to AbstractColumn review comments.
RLStokes 84bd802
Merge branch 'apache:wicket-9.x' into wicket-9.x
RLStokes 829ecb3
Merge branch 'apache:wicket-9.x' into wicket-9.x
RLStokes 549b74e
Merge branch 'apache:wicket-9.x' into wicket-9.x
RLStokes 062dd74
Merge branch 'apache:wicket-9.x' into wicket-9.x
RLStokes 45ed67e
Merge branch 'apache:wicket-9.x' into wicket-9.x
RLStokes 0b98ad3
Merge branch 'apache:wicket-9.x' into wicket-9.x
RLStokes 02ebc6d
Merge branch 'apache:wicket-9.x' into wicket-9.x
RLStokes 72304fc
Merge branch 'apache:wicket-9.x' into wicket-9.x
RLStokes 73ef3af
Merge branch 'apache:wicket-9.x' into wicket-9.x
RLStokes c9a1656
Merge branch 'apache:wicket-9.x' into wicket-9.x
RLStokes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 84 additions & 74 deletions
158
...main/java/org/apache/wicket/extensions/markup/html/repeater/data/grid/ICellPopulator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,84 @@ | ||
/* | ||
* 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.extensions.markup.html.repeater.data.grid; | ||
|
||
import org.apache.wicket.markup.repeater.Item; | ||
import org.apache.wicket.model.IDetachable; | ||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.util.io.IClusterable; | ||
|
||
/** | ||
* Represents an object that is capable of populating an {@link Item} container representing a cell | ||
* in a {@link DataGridView} with components. | ||
* <p> | ||
* Example | ||
* <p> | ||
* | ||
* <pre> | ||
* class NamePopulator implements ICellPopulator | ||
* { | ||
* void populateItem(final Item cellItem, final String componentId, final IModel rowModel) { | ||
* User user=(User)rowModel.getObject(cellItem); | ||
* String name=user.getFirstName()+" "+user.getLastName(); | ||
* cellItem.add(new Label(componentId, name); | ||
* }} | ||
* </pre> | ||
* | ||
* In this example the IDataProvider assigned to the DataGridView retrieves User objects from the | ||
* database. The cell populator adds a label to the cell that will display the full name of the | ||
* user. | ||
* | ||
* @see DataGridView | ||
* @see Item | ||
* | ||
* @author Igor Vaynberg (ivaynberg) | ||
* | ||
* @param <T> | ||
* Model object type | ||
*/ | ||
public interface ICellPopulator<T> extends IClusterable, IDetachable | ||
{ | ||
/** | ||
* Method used to populate a cell in the {@link DataGridView} | ||
* | ||
* <b>Implementation MUST add a component to the cellItem using the component id provided by | ||
* componentId argument, otherwise a WicketRuntimeException will be thrown</b> | ||
* | ||
* @param cellItem | ||
* the item representing the current table cell being rendered | ||
* @param componentId | ||
* the id of the component used to render the cell (only one component should be | ||
* added to the cell) | ||
* @param rowModel | ||
* the model of the row item being rendered. this model usually contains the model | ||
* provided by the data provider. | ||
* | ||
* @see Item | ||
*/ | ||
void populateItem(final Item<ICellPopulator<T>> cellItem, final String componentId, | ||
final IModel<T> rowModel); | ||
} | ||
/* | ||
* 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.extensions.markup.html.repeater.data.grid; | ||
|
||
import org.apache.wicket.markup.repeater.Item; | ||
import org.apache.wicket.model.IDetachable; | ||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.util.io.IClusterable; | ||
|
||
/** | ||
* Represents an object that is capable of populating an {@link Item} container representing a cell | ||
* in a {@link DataGridView} with components. | ||
* <p> | ||
* Example | ||
* <p> | ||
* | ||
* <pre> | ||
* class NamePopulator implements ICellPopulator | ||
* { | ||
* void populateItem(final Item cellItem, final String componentId, final IModel rowModel) { | ||
* User user=(User)rowModel.getObject(cellItem); | ||
* String name=user.getFirstName()+" "+user.getLastName(); | ||
* cellItem.add(new Label(componentId, name); | ||
* }} | ||
* </pre> | ||
* | ||
* In this example the IDataProvider assigned to the DataGridView retrieves User objects from the | ||
* database. The cell populator adds a label to the cell that will display the full name of the | ||
* user. | ||
* | ||
* @see DataGridView | ||
* @see Item | ||
* | ||
* @author Igor Vaynberg (ivaynberg) | ||
* | ||
* @param <T> | ||
* Model object type | ||
*/ | ||
public interface ICellPopulator<T> extends IClusterable, IDetachable | ||
{ | ||
/** | ||
* Method used to populate a cell in the {@link DataGridView} | ||
* | ||
* <b>Implementation MUST add a component to the cellItem using the component id provided by | ||
* componentId argument, otherwise a WicketRuntimeException will be thrown</b> | ||
* | ||
* @param cellItem | ||
* the item representing the current table cell being rendered | ||
* @param componentId | ||
* the id of the component used to render the cell (only one component should be | ||
* added to the cell) | ||
* @param rowModel | ||
* the model of the row item being rendered. this model usually contains the model | ||
* provided by the data provider. | ||
* | ||
* @see Item | ||
*/ | ||
void populateItem(final Item<ICellPopulator<T>> cellItem, final String componentId, | ||
final IModel<T> rowModel); | ||
|
||
/** | ||
* Gets whether this column is visible in a {@link DataGridView} | ||
* | ||
* @return true if column is visible | ||
*/ | ||
default boolean isVisible() | ||
{ | ||
return true; | ||
}; | ||
} |
154 changes: 77 additions & 77 deletions
154
...n/java/org/apache/wicket/extensions/markup/html/repeater/data/grid/PropertyPopulator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,77 @@ | ||
/* | ||
* 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.extensions.markup.html.repeater.data.grid; | ||
|
||
import org.apache.wicket.markup.html.basic.Label; | ||
import org.apache.wicket.markup.repeater.Item; | ||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.model.PropertyModel; | ||
|
||
/** | ||
* A convenience implementation of {@link ICellPopulator} that adds a label that will display the | ||
* value of the specified property. Non-string properties will be converted to a string before | ||
* display. | ||
* <p> | ||
* Example | ||
* | ||
* <pre> | ||
* ICellPopulator cityPopulator = new PropertyPopulator("address.city"); | ||
* </pre> | ||
* | ||
* @param <T> | ||
* @author Igor Vaynberg (ivaynberg) | ||
*/ | ||
public class PropertyPopulator<T> implements ICellPopulator<T> | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
private final String property; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param property | ||
* property whose value will be displayed in the cell. uses wicket's | ||
* {@link PropertyModel} notation. | ||
*/ | ||
public PropertyPopulator(final String property) | ||
{ | ||
if (property == null) | ||
{ | ||
throw new IllegalArgumentException("argument [property] cannot be null"); | ||
} | ||
this.property = property; | ||
} | ||
|
||
/** | ||
* @see org.apache.wicket.model.IDetachable#detach() | ||
*/ | ||
@Override | ||
public void detach() | ||
{ | ||
} | ||
|
||
/** | ||
* @see org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator#populateItem(org.apache.wicket.markup.repeater.Item, | ||
* java.lang.String, org.apache.wicket.model.IModel) | ||
*/ | ||
@Override | ||
public void populateItem(final Item<ICellPopulator<T>> cellItem, final String componentId, | ||
final IModel<T> rowModel) | ||
{ | ||
cellItem.add(new Label(componentId, new PropertyModel<>(rowModel, property))); | ||
} | ||
} | ||
/* | ||
* 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.extensions.markup.html.repeater.data.grid; | ||
import org.apache.wicket.markup.html.basic.Label; | ||
import org.apache.wicket.markup.repeater.Item; | ||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.model.PropertyModel; | ||
/** | ||
* A convenience implementation of {@link ICellPopulator} that adds a label that will display the | ||
* value of the specified property. Non-string properties will be converted to a string before | ||
* display. | ||
* <p> | ||
* Example | ||
* | ||
* <pre> | ||
* ICellPopulator cityPopulator = new PropertyPopulator("address.city"); | ||
* </pre> | ||
* | ||
* @param <T> | ||
* @author Igor Vaynberg (ivaynberg) | ||
*/ | ||
public class PropertyPopulator<T> implements ICellPopulator<T> | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
private final String property; | ||
/** | ||
* Constructor | ||
* | ||
* @param property | ||
* property whose value will be displayed in the cell. uses wicket's | ||
* {@link PropertyModel} notation. | ||
*/ | ||
public PropertyPopulator(final String property) | ||
{ | ||
if (property == null) | ||
{ | ||
throw new IllegalArgumentException("argument [property] cannot be null"); | ||
} | ||
this.property = property; | ||
} | ||
/** | ||
* @see org.apache.wicket.model.IDetachable#detach() | ||
*/ | ||
@Override | ||
public void detach() | ||
{ | ||
} | ||
/** | ||
* @see org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator#populateItem(org.apache.wicket.markup.repeater.Item, | ||
* java.lang.String, org.apache.wicket.model.IModel) | ||
*/ | ||
@Override | ||
public void populateItem(final Item<ICellPopulator<T>> cellItem, final String componentId, | ||
final IModel<T> rowModel) | ||
{ | ||
cellItem.add(new Label(componentId, new PropertyModel<>(rowModel, property))); | ||
} | ||
} |
190 changes: 95 additions & 95 deletions
190
...ain/java/org/apache/wicket/extensions/markup/html/repeater/data/table/AbstractColumn.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,95 @@ | ||
/* | ||
* 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.extensions.markup.html.repeater.data.table; | ||
|
||
import org.apache.wicket.Component; | ||
import org.apache.wicket.markup.html.basic.Label; | ||
import org.apache.wicket.model.IModel; | ||
|
||
/** | ||
* A helper implementation for the IColumn interface | ||
* | ||
* @author Igor Vaynberg ( ivaynberg ) | ||
* @param <T> | ||
* the type of the object that will be rendered in this column's cells | ||
* @param <S> | ||
* the type of the sort property | ||
*/ | ||
public abstract class AbstractColumn<T, S> implements IStyledColumn<T, S> | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final IModel<String> displayModel; | ||
|
||
private final S sortProperty; | ||
|
||
/** | ||
* @param displayModel | ||
* model used to generate header text | ||
* @param sortProperty | ||
* sort property this column represents | ||
*/ | ||
public AbstractColumn(final IModel<String> displayModel, final S sortProperty) | ||
{ | ||
this.displayModel = displayModel; | ||
this.sortProperty = sortProperty; | ||
} | ||
|
||
/** | ||
* @param displayModel | ||
* model used to generate header text | ||
*/ | ||
public AbstractColumn(final IModel<String> displayModel) | ||
{ | ||
this(displayModel, null); | ||
} | ||
|
||
/** | ||
* @return returns display model to be used for the header component | ||
*/ | ||
public IModel<String> getDisplayModel() | ||
{ | ||
return displayModel; | ||
} | ||
|
||
@Override | ||
public S getSortProperty() | ||
{ | ||
return sortProperty; | ||
} | ||
|
||
@Override | ||
public Component getHeader(final String componentId) | ||
{ | ||
return new Label(componentId, getDisplayModel()); | ||
} | ||
|
||
@Override | ||
public void detach() | ||
{ | ||
if (displayModel != null) | ||
{ | ||
displayModel.detach(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getCssClass() | ||
{ | ||
return null; | ||
} | ||
} | ||
/* | ||
* 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.extensions.markup.html.repeater.data.table; | ||
|
||
import org.apache.wicket.Component; | ||
import org.apache.wicket.markup.html.basic.Label; | ||
import org.apache.wicket.model.IModel; | ||
|
||
/** | ||
* A helper implementation for the IColumn interface | ||
* | ||
* @author Igor Vaynberg ( ivaynberg ) | ||
* @param <T> | ||
* the type of the object that will be rendered in this column's cells | ||
* @param <S> | ||
* the type of the sort property | ||
*/ | ||
public abstract class AbstractColumn<T, S> implements IStyledColumn<T, S> | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final IModel<String> displayModel; | ||
|
||
private final S sortProperty; | ||
|
||
/** | ||
* @param displayModel | ||
* model used to generate header text | ||
* @param sortProperty | ||
* sort property this column represents | ||
*/ | ||
public AbstractColumn(final IModel<String> displayModel, final S sortProperty) | ||
{ | ||
this.displayModel = displayModel; | ||
this.sortProperty = sortProperty; | ||
} | ||
|
||
/** | ||
* @param displayModel | ||
* model used to generate header text | ||
*/ | ||
public AbstractColumn(final IModel<String> displayModel) | ||
{ | ||
this(displayModel, null); | ||
} | ||
|
||
/** | ||
* @return returns display model to be used for the header component | ||
*/ | ||
public IModel<String> getDisplayModel() | ||
{ | ||
return displayModel; | ||
} | ||
|
||
@Override | ||
public S getSortProperty() | ||
{ | ||
return sortProperty; | ||
} | ||
|
||
@Override | ||
public Component getHeader(final String componentId) | ||
{ | ||
return new Label(componentId, getDisplayModel()); | ||
} | ||
|
||
@Override | ||
public void detach() | ||
{ | ||
if (displayModel != null) | ||
{ | ||
displayModel.detach(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getCssClass() | ||
{ | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
315 changes: 163 additions & 152 deletions
315
...va/org/apache/wicket/extensions/markup/html/repeater/data/table/filter/FilterToolbar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,152 +1,163 @@ | ||
/* | ||
* 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.extensions.markup.html.repeater.data.table.filter; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import org.apache.wicket.Component; | ||
import org.apache.wicket.behavior.Behavior; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractToolbar; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.IStyledColumn; | ||
import org.apache.wicket.markup.ComponentTag; | ||
import org.apache.wicket.markup.html.list.ListItem; | ||
import org.apache.wicket.markup.html.list.ListView; | ||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.util.lang.Args; | ||
import org.apache.wicket.util.string.Strings; | ||
|
||
|
||
/** | ||
* Toolbar that creates a form to hold form components used to filter data in the data table. Form | ||
* components are provided by columns that implement IFilteredColumn. | ||
* | ||
* @author Igor Vaynberg (ivaynberg) | ||
*/ | ||
public class FilterToolbar extends AbstractToolbar | ||
{ | ||
private static final String FILTER_ID = "filter"; | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param table | ||
* data table this toolbar will be added to | ||
* @param form | ||
* the filter form | ||
* @param <T> | ||
* the type of the DataTable's model object | ||
* @param <S> | ||
* the type of the DataTable's sorting parameter | ||
* @param <F> | ||
* the type of filter state object | ||
* | ||
*/ | ||
public <T, S, F> FilterToolbar(final DataTable<T, S> table, final FilterForm<F> form) | ||
{ | ||
super(table); | ||
|
||
Args.notNull(table, "table"); | ||
|
||
IModel<List<IColumn<T, S>>> model = new IModel<>() { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public List<IColumn<T, S>> getObject() { | ||
return new LinkedList<>(table.getColumns()); | ||
} | ||
}; | ||
|
||
// populate the toolbar with components provided by filtered columns | ||
ListView<IColumn<T, S>> filters = new ListView<>("filters", model) | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected void populateItem(ListItem<IColumn<T, S>> item) | ||
{ | ||
final IColumn<T, S> col = item.getModelObject(); | ||
item.setRenderBodyOnly(true); | ||
|
||
Component filter = null; | ||
|
||
if (col instanceof IFilteredColumn) | ||
{ | ||
IFilteredColumn<T, S> filteredCol = (IFilteredColumn<T, S>)col; | ||
filter = filteredCol.getFilter(FILTER_ID, form); | ||
} | ||
|
||
if (filter == null) | ||
{ | ||
filter = new NoFilter(FILTER_ID); | ||
} | ||
else | ||
{ | ||
if (!filter.getId().equals(FILTER_ID)) | ||
{ | ||
throw new IllegalStateException( | ||
"filter component returned with an invalid component id. invalid component id [" + | ||
filter.getId() + | ||
"] required component id [" + | ||
getId() + | ||
"] generating column [" + col + "] "); | ||
} | ||
} | ||
|
||
if (col instanceof IStyledColumn) | ||
{ | ||
filter.add(new Behavior() | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* @see Behavior#onComponentTag(Component, ComponentTag) | ||
*/ | ||
@Override | ||
public void onComponentTag(final Component component, final ComponentTag tag) | ||
{ | ||
String className = ((IStyledColumn<?, S>)col).getCssClass(); | ||
if (!Strings.isEmpty(className)) | ||
{ | ||
tag.append("class", className, " "); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
item.add(filter); | ||
} | ||
}; | ||
filters.setReuseItems(true); | ||
|
||
add(filters); | ||
} | ||
|
||
@Override | ||
protected void onBeforeRender() | ||
{ | ||
if (findParent(FilterForm.class) == null) | ||
{ | ||
throw new IllegalStateException("FilterToolbar must be contained within a FilterForm"); | ||
} | ||
super.onBeforeRender(); | ||
} | ||
|
||
} | ||
/* | ||
* 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.extensions.markup.html.repeater.data.table.filter; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import org.apache.wicket.Component; | ||
import org.apache.wicket.behavior.Behavior; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractToolbar; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.IStyledColumn; | ||
import org.apache.wicket.markup.ComponentTag; | ||
import org.apache.wicket.markup.html.list.ListItem; | ||
import org.apache.wicket.markup.html.list.ListView; | ||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.util.lang.Args; | ||
import org.apache.wicket.util.string.Strings; | ||
|
||
|
||
/** | ||
* Toolbar that creates a form to hold form components used to filter data in the data table. Form | ||
* components are provided by columns that implement IFilteredColumn. | ||
* | ||
* @author Igor Vaynberg (ivaynberg) | ||
*/ | ||
public class FilterToolbar extends AbstractToolbar | ||
{ | ||
private static final String FILTER_ID = "filter"; | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param table | ||
* data table this toolbar will be added to | ||
* @param form | ||
* the filter form | ||
* @param <T> | ||
* the type of the DataTable's model object | ||
* @param <S> | ||
* the type of the DataTable's sorting parameter | ||
* @param <F> | ||
* the type of filter state object | ||
* | ||
*/ | ||
public <T, S, F> FilterToolbar(final DataTable<T, S> table, final FilterForm<F> form) | ||
{ | ||
super(table); | ||
|
||
Args.notNull(table, "table"); | ||
|
||
IModel<List<IColumn<T, S>>> model = new IModel<>() { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public List<IColumn<T, S>> getObject() { | ||
|
||
List<IColumn<T, S>> columnsModels = new LinkedList<>(); | ||
|
||
for (IColumn<T, S> column : table.getColumns()) | ||
{ | ||
if (column.isVisible()) | ||
{ | ||
columnsModels.add(column); | ||
} | ||
} | ||
|
||
return columnsModels; | ||
} | ||
}; | ||
|
||
// populate the toolbar with components provided by filtered columns | ||
ListView<IColumn<T, S>> filters = new ListView<>("filters", model) | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected void populateItem(ListItem<IColumn<T, S>> item) | ||
{ | ||
final IColumn<T, S> col = item.getModelObject(); | ||
item.setRenderBodyOnly(true); | ||
|
||
Component filter = null; | ||
|
||
if (col instanceof IFilteredColumn) | ||
{ | ||
IFilteredColumn<T, S> filteredCol = (IFilteredColumn<T, S>)col; | ||
filter = filteredCol.getFilter(FILTER_ID, form); | ||
} | ||
|
||
if (filter == null) | ||
{ | ||
filter = new NoFilter(FILTER_ID); | ||
} | ||
else | ||
{ | ||
if (!filter.getId().equals(FILTER_ID)) | ||
{ | ||
throw new IllegalStateException( | ||
"filter component returned with an invalid component id. invalid component id [" + | ||
filter.getId() + | ||
"] required component id [" + | ||
getId() + | ||
"] generating column [" + col + "] "); | ||
} | ||
} | ||
|
||
if (col instanceof IStyledColumn) | ||
{ | ||
filter.add(new Behavior() | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* @see Behavior#onComponentTag(Component, ComponentTag) | ||
*/ | ||
@Override | ||
public void onComponentTag(final Component component, final ComponentTag tag) | ||
{ | ||
String className = ((IStyledColumn<?, S>)col).getCssClass(); | ||
if (!Strings.isEmpty(className)) | ||
{ | ||
tag.append("class", className, " "); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
item.add(filter); | ||
} | ||
}; | ||
filters.setReuseItems(true); | ||
|
||
add(filters); | ||
} | ||
|
||
@Override | ||
protected void onBeforeRender() | ||
{ | ||
if (findParent(FilterForm.class) == null) | ||
{ | ||
throw new IllegalStateException("FilterToolbar must be contained within a FilterForm"); | ||
} | ||
super.onBeforeRender(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is the only involved toolbar that needs to be fixed... Did you run
mvn clean install
?