You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by GitBox <gi...@apache.org> on 2021/05/28 10:45:54 UTC

[GitHub] [wicket] martin-g commented on a change in pull request #471: WICKET-6888 ToggleableDataTable

martin-g commented on a change in pull request #471:
URL: https://github.com/apache/wicket/pull/471#discussion_r641454216



##########
File path: wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/toggle/ToggleColumn.java
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.toggle;
+
+import org.apache.wicket.ClassAttributeModifier;
+import org.apache.wicket.Component;
+import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
+import org.apache.wicket.extensions.markup.html.repeater.data.toggle.IToggleable;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
+import java.util.Set;
+
+/**
+ * A column displaying the toggleable rows.
+ *
+ * @param <T> The model object type
+ * @param <S> the type of the sorting parameter
+ * @author Roland Kurucz
+ */
+public class ToggleColumn<T, S> extends AbstractColumn<T, S> {
+
+    private IToggleable<T> dataTable;
+
+    public ToggleColumn(final IModel<String> displayModel) {
+        super(displayModel);
+    }
+
+    @Override
+    public void populateItem(final Item<ICellPopulator<T>> cellItem, final String componentId, final IModel<T> rowModel) {
+        final Component toggleComponent = newToggleComponent(componentId, rowModel);
+        toggleComponent.add(new ClassAttributeModifier() {
+            @Override
+            protected Set<String> update(Set<String> oldClasses) {
+                final T object = rowModel.getObject();
+                if (dataTable.isToggleable(object)) {
+                    oldClasses.add("toggleable");

Review comment:
       The CSS class names should be constructed with `CssUtils.key(Class scope, String facet)` helper method.
   See https://github.com/apache/wicket/blob/8bbf158ebc4d12f3b317c0d607200441c0767162/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AutoLabelResolver.java#L78-L79 for example.
   This way the chance to conflict with application defined CSS classes is much smaller.

##########
File path: wicket-examples/src/main/java/org/apache/wicket/examples/repeater/repeater.css
##########
@@ -72,3 +72,16 @@ col.yellow {
 col.brown {
 	background-color: #CC6633;
 }
+
+.toggleable {

Review comment:
       See my comment about CSS class names below.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org