<commit_before>/**
 * Licensed 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.brixcms.plugin.menu.editor;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.markup.html.tree.AbstractTree;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.ResourceModel;
import org.brixcms.plugin.menu.ManageMenuPanel;
import org.brixcms.plugin.menu.Menu;
import org.brixcms.plugin.menu.Menu.ChildEntry;
import org.brixcms.plugin.menu.editor.cell.SwitcherColumn;
import org.brixcms.plugin.site.picker.reference.ReferenceEditorConfiguration;
import org.brixcms.web.generic.BrixGenericPanel;

import com.inmethod.grid.IGridColumn;
import com.inmethod.grid.SizeUnit;
import com.inmethod.grid.column.editable.EditablePropertyColumn;
import com.inmethod.grid.column.editable.EditablePropertyTreeColumn;
import com.inmethod.grid.column.editable.SubmitCancelColumn;
import com.inmethod.grid.treegrid.TreeGrid;

public class MenuEditor extends BrixGenericPanel<Menu> {
    private MenuTreeModel treeModel;
    private AbstractTree tree;

    private WebMarkupContainer links;

    public MenuEditor(String id) {
        super(id);
    }

    public MenuEditor(String id, IModel<Menu> model) {
        super(id, model);
    }

    @Override
    protected void onBeforeRender() {
        if (!hasBeenRendered()) {
            init();
        }
        super.onBeforeRender();
    }

    @SuppressWarnings("unchecked")
    private void init() {
        treeModel = new MenuTreeModel(getModelObject().getRoot());

        final TreeGrid tg;
        add(tg = new TreeGrid("treeGrid", treeModel, newColumns()) {
            @Override
            protected void onItemSelectionChanged(IModel item, boolean newValue) {
                super.onItemSelectionChanged(item, newValue);

                // if (newValue == false)
                setItemEdit(item, newValue);

                // selectionChanged(getRequestCycle().find(AjaxRequestTarget.class).get());
                // update();
            }

            @Override
            public void setItemEdit(IModel rowModel, boolean edit) {
                if (edit == true) {
                    selectItem(rowModel, true);
                }

                super.setItemEdit(rowModel, edit);
            }
        });
<commit_msg>fix of careless mistake from my previous commit<commit_after>/**
 * Licensed 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.brixcms.plugin.menu.editor;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.extensions.markup.html.tree.AbstractTree;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.ResourceModel;
import org.brixcms.plugin.menu.ManageMenuPanel;
import org.brixcms.plugin.menu.Menu;
import org.brixcms.plugin.menu.Menu.ChildEntry;
import org.brixcms.plugin.menu.editor.cell.SwitcherColumn;
import org.brixcms.plugin.site.picker.reference.ReferenceEditorConfiguration;
import org.brixcms.web.generic.BrixGenericPanel;

import com.inmethod.grid.IGridColumn;
import com.inmethod.grid.SizeUnit;
import com.inmethod.grid.column.editable.EditablePropertyColumn;
import com.inmethod.grid.column.editable.EditablePropertyTreeColumn;
import com.inmethod.grid.column.editable.SubmitCancelColumn;
import com.inmethod.grid.treegrid.TreeGrid;

public class MenuEditor extends BrixGenericPanel<Menu> {
    private MenuTreeModel treeModel;
    private AbstractTree tree;

    private WebMarkupContainer links;

    public MenuEditor(String id) {
        super(id);
    }

    public MenuEditor(String id, IModel<Menu> model) {
        super(id, model);
    }

    @Override
    protected void onBeforeRender() {
        if (!hasBeenRendered()) {
            init();
        }
        super.onBeforeRender();
    }

    @SuppressWarnings("unchecked")
    private void init() {
        treeModel = new MenuTreeModel(getModelObject().getRoot());

        final TreeGrid tg;
        add(tg = new TreeGrid("treeGrid", treeModel, newColumns()) {
            @Override
            protected void onItemSelectionChanged(IModel item, boolean newValue) {
                super.onItemSelectionChanged(item, newValue);

                // if (newValue == false)
                setItemEdit(item, newValue);

                getRequestCycle().find(AjaxRequestTarget.class).ifPresent(t -> selectionChanged(t));
                // update();
            }

            @Override
            public void setItemEdit(IModel rowModel, boolean edit) {
                if (edit == true) {
                    selectItem(rowModel, true);
                }

                super.setItemEdit(rowModel, edit);
            }
        });

{'fraction_non_alphanumeric': 0.09758501724987678, 'fraction_numerical': 0.0013142763265976672, 'mean_word_length': 3.06951871657754, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6348779', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1681, 'n_words': 410}