<commit_before>package org.jboss.as.console.client.tools;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.google.gwt.cell.client.ActionCell;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.http.client.URL;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.CellList;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.domain.model.SimpleCallback;
import org.jboss.as.console.client.widgets.ContentDescription;
import org.jboss.as.console.client.widgets.tables.ViewLinkCell;
import org.jboss.as.console.mbui.widgets.AddressUtils;
import org.jboss.as.console.mbui.widgets.ModelNodeCellTable;
import org.jboss.as.console.mbui.widgets.ModelNodeColumn;
import org.jboss.as.console.mbui.widgets.ModelNodeForm;
import org.jboss.as.console.mbui.widgets.ModelNodeFormBuilder;
import org.jboss.ballroom.client.rbac.SecurityContext;
import org.jboss.ballroom.client.widgets.forms.FormValidation;
import org.jboss.ballroom.client.widgets.tables.DefaultPager;
import org.jboss.ballroom.client.widgets.tools.ToolButton;
import org.jboss.ballroom.client.widgets.tools.ToolStrip;
import org.jboss.ballroom.client.widgets.window.DefaultWindow;
import org.jboss.ballroom.client.widgets.window.DialogueOptions;
import org.jboss.ballroom.client.widgets.window.Feedback;
import org.jboss.ballroom.client.widgets.window.WindowContentBuilder;
import org.jboss.dmr.client.ModelNode;
import org.jboss.dmr.client.Property;

/**
 * @author <NAME>
 * @since 24/07/14
 */
public class ChildView {

    private ModelNode currentAddress;

    private BrowserNavigation presenter;
    private ModelNodeCellTable table;
    private ListDataProvider<ModelNode> dataProvider;
    private SingleSelectionModel<ModelNode> selectionModel;
    private HTML header;
    private ToolStrip tools;
    private ModelBrowserView.ChildInformation childInformation;

    Widget asWidget() {

        VerticalPanel layout = new VerticalPanel();
        layout.setStyleName("fill-layout-width");

        tools = new ToolStrip();
        tools.addToolButtonRight(new ToolButton(Console.CONSTANTS.common_label_add(), new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {

                // onAdd singleton we need to request the specific type to be added

                int i=1;
                List<Property> addressTuple = currentAddress.asPropertyList();
                final ModelNode addressPrefix = new ModelNode();
                Property denominator = null;
                for(Property tuple : addressTuple)
                {
                    if(i==addressTuple.size())
                    {
                        denominator = tuple;
                        break;
                    }
                    else
                    {
                        addressPrefix.add(tuple.getName(), tuple.getValue());
                    }

                    i++;
                }

                final String denominatorType = denominator.getName();
                if(childInformation.isSingleton(denominatorType))
                {
                    Set<String> allowedSubResources = childInformation.getSingletons().get(denominatorType)!=null ?
                            new HashSet<String>(childInformation.getSingletons().get(denominatorType)) :
                            new HashSet<String>();

                    // filter existing resources
                    for(ModelNode existing : dataProvider.getList())
                    {
                        allowedSubResources.remove(existing.asString());
                    }

                    if(allowedSubResources.size()>0) {
                        SingletonDialog dialog = new SingletonDialog(
                                allowedSubResources,
                                new SimpleCallback<String>() {

                                    @Override
                                    public void onSuccess(String result) {

                                        addressPrefix.add(denominatorType, result);
                                        presenter.onPrepareAddChildResource(addressPrefix, true);
                                    }
                                }
                        );
                        dialog.setWidth(320);
                        dialog.setHeight(240);
                        dialog.center();
                    }
                    else {
                        Feedback.alert(Console.CONSTANTS.availableChildrenTypes(),
                                Console.CONSTANTS.allSingletonsAlreadyAdded());
                    }


                }
                else
                {
                    presenter.onPrepareAddChildResource(currentAddress, false);
                }

            }
        }));

        final ToolButton remove = new ToolButton(Console.CONSTANTS.common_label_delete(), new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                ModelNode selection = selectionModel.getSelectedObject();
                if (selection != null)
                    presenter.onRemoveChildResource(currentAddress, selection);
            }
        });
        tools.addToolButtonRight(remove);
        remove.setEnabled(false);

        table = new ModelNodeCellTable(12);
        table.addColumn(new ModelNodeColumn(new ModelNodeColumn.ValueAdapter() {
            @Override
            public String getValue(ModelNode model) {
                return URL.decodePathSegment(model.asString());
            }
        }), "Child Resource" );


        Column<ModelNode, ModelNode> option = new Column<ModelNode, ModelNode>(
                new ViewLinkCell<ModelNode>(Console.CONSTANTS.common_label_view(), new ActionCell.Delegate<ModelNode>() {
                    @Override
                    public void execute(ModelNode selection) {
                        presenter.onViewChild(currentAddress, selection.asString());
                    }
                })
        ) {
            @Override
            public ModelNode getValue(ModelNode model) {
                return model;
            }
        };<commit_msg>[JBEAP-6811] Resource removed from table remains selected<commit_after>package org.jboss.as.console.client.tools;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.google.gwt.cell.client.ActionCell;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.http.client.URL;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.CellList;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.domain.model.SimpleCallback;
import org.jboss.as.console.client.widgets.ContentDescription;
import org.jboss.as.console.client.widgets.tables.ViewLinkCell;
import org.jboss.as.console.mbui.widgets.AddressUtils;
import org.jboss.as.console.mbui.widgets.ModelNodeCellTable;
import org.jboss.as.console.mbui.widgets.ModelNodeColumn;
import org.jboss.as.console.mbui.widgets.ModelNodeForm;
import org.jboss.as.console.mbui.widgets.ModelNodeFormBuilder;
import org.jboss.ballroom.client.rbac.SecurityContext;
import org.jboss.ballroom.client.widgets.forms.FormValidation;
import org.jboss.ballroom.client.widgets.tables.DefaultPager;
import org.jboss.ballroom.client.widgets.tools.ToolButton;
import org.jboss.ballroom.client.widgets.tools.ToolStrip;
import org.jboss.ballroom.client.widgets.window.DefaultWindow;
import org.jboss.ballroom.client.widgets.window.DialogueOptions;
import org.jboss.ballroom.client.widgets.window.Feedback;
import org.jboss.ballroom.client.widgets.window.WindowContentBuilder;
import org.jboss.dmr.client.ModelNode;
import org.jboss.dmr.client.Property;

/**
 * @author <NAME>
 * @since 24/07/14
 */
public class ChildView {

    private ModelNode currentAddress;

    private BrowserNavigation presenter;
    private ModelNodeCellTable table;
    private ListDataProvider<ModelNode> dataProvider;
    private SingleSelectionModel<ModelNode> selectionModel;
    private HTML header;
    private ToolStrip tools;
    private ModelBrowserView.ChildInformation childInformation;

    Widget asWidget() {

        VerticalPanel layout = new VerticalPanel();
        layout.setStyleName("fill-layout-width");

        tools = new ToolStrip();
        tools.addToolButtonRight(new ToolButton(Console.CONSTANTS.common_label_add(), new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {

                // onAdd singleton we need to request the specific type to be added

                int i=1;
                List<Property> addressTuple = currentAddress.asPropertyList();
                final ModelNode addressPrefix = new ModelNode();
                Property denominator = null;
                for(Property tuple : addressTuple)
                {
                    if(i==addressTuple.size())
                    {
                        denominator = tuple;
                        break;
                    }
                    else
                    {
                        addressPrefix.add(tuple.getName(), tuple.getValue());
                    }

                    i++;
                }

                final String denominatorType = denominator.getName();
                if(childInformation.isSingleton(denominatorType))
                {
                    Set<String> allowedSubResources = childInformation.getSingletons().get(denominatorType)!=null ?
                            new HashSet<String>(childInformation.getSingletons().get(denominatorType)) :
                            new HashSet<String>();

                    // filter existing resources
                    for(ModelNode existing : dataProvider.getList())
                    {
                        allowedSubResources.remove(existing.asString());
                    }

                    if(allowedSubResources.size()>0) {
                        SingletonDialog dialog = new SingletonDialog(
                                allowedSubResources,
                                new SimpleCallback<String>() {

                                    @Override
                                    public void onSuccess(String result) {

                                        addressPrefix.add(denominatorType, result);
                                        presenter.onPrepareAddChildResource(addressPrefix, true);
                                    }
                                }
                        );
                        dialog.setWidth(320);
                        dialog.setHeight(240);
                        dialog.center();
                    }
                    else {
                        Feedback.alert(Console.CONSTANTS.availableChildrenTypes(),
                                Console.CONSTANTS.allSingletonsAlreadyAdded());
                    }


                }
                else
                {
                    presenter.onPrepareAddChildResource(currentAddress, false);
                }

            }
        }));

        final ToolButton remove = new ToolButton(Console.CONSTANTS.common_label_delete(), new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                ModelNode selection = selectionModel.getSelectedObject();
                if (selection != null) {
                    presenter.onRemoveChildResource(currentAddress, selection);
                    selectionModel.clear();
                }
            }
        });
        tools.addToolButtonRight(remove);
        remove.setEnabled(false);

        table = new ModelNodeCellTable(12);
        table.addColumn(new ModelNodeColumn(new ModelNodeColumn.ValueAdapter() {
            @Override
            public String getValue(ModelNode model) {
                return URL.decodePathSegment(model.asString());
            }
        }), "Child Resource" );


        Column<ModelNode, ModelNode> option = new Column<ModelNode, ModelNode>(
                new ViewLinkCell<ModelNode>(Console.CONSTANTS.common_label_view(), new ActionCell.Delegate<ModelNode>() {
                    @Override
                    public void execute(ModelNode selection) {
                        presenter.onViewChild(currentAddress, selection.asString());
                    }
                })
        ) {
            @Override
            public ModelNode getValue(ModelNode model) {
                return model;
            }
        };
{'fraction_non_alphanumeric': 0.0905880657249928, 'fraction_numerical': 0.0025944076102623233, 'mean_word_length': 1.9363097757088448, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '16079', 'n_tokens_mistral': 3655, 'n_tokens_neox': 3385, 'n_words': 559}