<commit_before>/*******************************************************************************
 * Copyright (c) 2012-2016 <NAME>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   <NAME>. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.ide.ext.java.client.navigation.filestructure;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.dom.client.DoubleClickEvent;
import com.google.gwt.event.dom.client.DoubleClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.ide.api.project.node.Node;
import org.eclipse.che.ide.api.project.node.interceptor.NodeInterceptor;
import org.eclipse.che.ide.ext.java.client.JavaLocalizationConstant;
import org.eclipse.che.ide.ext.java.client.navigation.factory.NodeFactory;
import org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit;
import org.eclipse.che.ide.ui.smartTree.KeyboardNavigationHandler;
import org.eclipse.che.ide.ui.smartTree.NodeUniqueKeyProvider;
import org.eclipse.che.ide.ui.smartTree.Tree;
import org.eclipse.che.ide.ui.smartTree.NodeLoader;
import org.eclipse.che.ide.ui.smartTree.NodeStorage;
import org.eclipse.che.ide.ui.window.Window;

import javax.validation.constraints.NotNull;
import java.util.Collections;

import static org.eclipse.che.ide.ui.smartTree.SelectionModel.Mode.SINGLE;

/**
 * Implementation of {@link FileStructure} view.
 *
 * @author <NAME>
 */
@Singleton
final class FileStructureImpl extends Window implements FileStructure {
    interface FileStructureImplUiBinder extends UiBinder<Widget, FileStructureImpl> {
    }

    private static FileStructureImplUiBinder UI_BINDER = GWT.create(FileStructureImplUiBinder.class);

    @UiField
    DockLayoutPanel treeContainer;
    @UiField
    Label           showInheritedLabel;

    private final NodeFactory              nodeFactory;
    private final JavaLocalizationConstant locale;
    private final Tree                     tree;

    private ActionDelegate delegate;

    @Inject
    public FileStructureImpl(NodeFactory nodeFactory, JavaLocalizationConstant locale) {
        super(false);
        this.nodeFactory = nodeFactory;
        this.locale = locale;
        setWidget(UI_BINDER.createAndBindUi(this));

        NodeStorage storage = new NodeStorage(new NodeUniqueKeyProvider() {
            @Override
            public String getKey(@NotNull Node item) {
                return String.valueOf(item.hashCode());
            }
        });
        NodeLoader loader = new NodeLoader(Collections.<NodeInterceptor>emptySet());
        tree = new Tree(storage, loader);
        tree.setAutoExpand(true);
        tree.getSelectionModel().setSelectionMode(SINGLE);

        KeyboardNavigationHandler handler = new KeyboardNavigationHandler() {
            @Override
            public void onEnter(NativeEvent evt) {
                hide();
            }
        };
        tree.addDomHandler(new DoubleClickHandler() {
            @Override
            public void onDoubleClick(DoubleClickEvent event) {
                hide();
            }
        }, DoubleClickEvent.getType());

        handler.bind(tree);

        treeContainer.add(tree);
    }


    /** {@inheritDoc} */
    @Override
    public void setStructure(CompilationUnit compilationUnit, boolean showInheritedMembers) {
        showInheritedLabel.setText(showInheritedMembers ? locale.hideInheritedMembersLabel() : locale.showInheritedMembersLabel());
        tree.getNodeStorage().clear();
        tree.getNodeStorage().add(nodeFactory.create(compilationUnit.getTypes().get(0), compilationUnit, showInheritedMembers, false));
    }<commit_msg>Avoid collapsing non-leaf nodes when double click performed<commit_after>/*******************************************************************************
 * Copyright (c) 2012-2016 <NAME>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.ide.ext.java.client.navigation.filestructure;

import com.google.common.base.Predicate;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.dom.client.DoubleClickEvent;
import com.google.gwt.event.dom.client.DoubleClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.ide.api.project.node.Node;
import org.eclipse.che.ide.api.project.node.interceptor.NodeInterceptor;
import org.eclipse.che.ide.ext.java.client.JavaLocalizationConstant;
import org.eclipse.che.ide.ext.java.client.navigation.factory.NodeFactory;
import org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit;
import org.eclipse.che.ide.ui.smartTree.KeyboardNavigationHandler;
import org.eclipse.che.ide.ui.smartTree.NodeUniqueKeyProvider;
import org.eclipse.che.ide.ui.smartTree.Tree;
import org.eclipse.che.ide.ui.smartTree.NodeLoader;
import org.eclipse.che.ide.ui.smartTree.NodeStorage;
import org.eclipse.che.ide.ui.window.Window;

import javax.validation.constraints.NotNull;
import java.util.Collections;

import static com.google.common.collect.Iterables.all;
import static org.eclipse.che.ide.ui.smartTree.SelectionModel.Mode.SINGLE;

/**
 * Implementation of {@link FileStructure} view.
 *
 * @author <NAME>
 */
@Singleton
final class FileStructureImpl extends Window implements FileStructure {
    interface FileStructureImplUiBinder extends UiBinder<Widget, FileStructureImpl> {
    }

    private static FileStructureImplUiBinder UI_BINDER = GWT.create(FileStructureImplUiBinder.class);

    @UiField
    DockLayoutPanel treeContainer;
    @UiField
    Label           showInheritedLabel;

    private final NodeFactory              nodeFactory;
    private final JavaLocalizationConstant locale;
    private final Tree                     tree;

    private ActionDelegate delegate;

    private Predicate<Node> LEAFS = new Predicate<Node>() {
        @Override
        public boolean apply(Node input) {
            return input.isLeaf();
        }
    };

    @Inject
    public FileStructureImpl(NodeFactory nodeFactory, JavaLocalizationConstant locale) {
        super(false);
        this.nodeFactory = nodeFactory;
        this.locale = locale;
        setWidget(UI_BINDER.createAndBindUi(this));

        NodeStorage storage = new NodeStorage(new NodeUniqueKeyProvider() {
            @Override
            public String getKey(@NotNull Node item) {
                return String.valueOf(item.hashCode());
            }
        });
        NodeLoader loader = new NodeLoader(Collections.<NodeInterceptor>emptySet());
        tree = new Tree(storage, loader);
        tree.setAutoExpand(true);
        tree.getSelectionModel().setSelectionMode(SINGLE);

        KeyboardNavigationHandler handler = new KeyboardNavigationHandler() {
            @Override
            public void onEnter(NativeEvent evt) {
                hide();
            }
        };
        tree.addDomHandler(new DoubleClickHandler() {
            @Override
            public void onDoubleClick(DoubleClickEvent event) {
                if (all(tree.getSelectionModel().getSelectedNodes(), LEAFS)) {
                    hide();
                }
            }
        }, DoubleClickEvent.getType());

        handler.bind(tree);

        treeContainer.add(tree);
    }


    /** {@inheritDoc} */
    @Override
    public void setStructure(CompilationUnit compilationUnit, boolean showInheritedMembers) {
        showInheritedLabel.setText(showInheritedMembers ? locale.hideInheritedMembersLabel() : locale.showInheritedMembersLabel());
        tree.getNodeStorage().clear();
        tree.getNodeStorage().add(nodeFactory.create(compilationUnit.getTypes().get(0), compilationUnit, showInheritedMembers, false));
    }
{'fraction_non_alphanumeric': 0.1334987033487428, 'fraction_numerical': 0.0029315593640771224, 'mean_word_length': 3.551051821446896, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '7327862', 'n_tokens_mistral': 2447, 'n_tokens_neox': 2387, 'n_words': 452}