<commit_before>/*
 * ******************************************************************************
 *    Copyright 2016-2017 Spectra Logic Corporation. All Rights Reserved.
 *    Licensed under the Apache License, Version 2.0 (the "License"). You may not use
 *    this file except in compliance with the License. A copy of the License is located at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *    or in the "license" file accompanying this file.
 *    This file 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 com.spectralogic.dsbrowser.gui.components.localfiletreetable;

import com.google.common.collect.ImmutableList;
import com.spectralogic.ds3client.Ds3Client;
import com.spectralogic.ds3client.utils.Guard;
import com.spectralogic.dsbrowser.api.injector.Presenter;
import com.spectralogic.dsbrowser.api.services.logging.LogType;
import com.spectralogic.dsbrowser.api.services.logging.LoggingService;
import com.spectralogic.dsbrowser.gui.DeepStorageBrowserPresenter;
import com.spectralogic.dsbrowser.gui.components.ds3panel.Ds3Common;
import com.spectralogic.dsbrowser.gui.components.ds3panel.ds3treetable.Ds3TreeTableItem;
import com.spectralogic.dsbrowser.gui.components.ds3panel.ds3treetable.Ds3TreeTableValue;
import com.spectralogic.dsbrowser.gui.components.ds3panel.ds3treetable.Ds3TreeTableValueCustom;
import com.spectralogic.dsbrowser.gui.services.Workers;
import com.spectralogic.dsbrowser.gui.services.jobService.factories.GetJobFactory;
import com.spectralogic.dsbrowser.gui.services.jobService.factories.PutJobFactory;
import com.spectralogic.dsbrowser.gui.services.sessionStore.Session;
import com.spectralogic.dsbrowser.gui.services.tasks.*;
import com.spectralogic.dsbrowser.gui.util.*;
import com.spectralogic.dsbrowser.gui.util.treeItem.SafeHandler;
import com.spectralogic.dsbrowser.util.GuavaCollectors;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.effect.InnerShadow;
import javafx.scene.input.*;
import javafx.scene.layout.StackPane;
import javafx.util.Pair;
import kotlin.Unit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Stream;

@Presenter
public class LocalFileTreeTablePresenter implements Initializable {

    private final static Logger LOG = LoggerFactory.getLogger(LocalFileTreeTablePresenter.class);
    private static final String LOCAL = "local";

    @FXML
    private TreeTableView<FileTreeModel> treeTable;

    @FXML
    private TreeTableColumn<FileTreeModel, Number> sizeColumn;

    @FXML
    private TreeTableColumn<FileTreeModel, String> dateModified;

    @FXML
    private Button homeButton, refreshButton, toMyComputer, transferButton, parentDirectoryButton, createFolderButton;

    @FXML
    private Tooltip homeButtonTooltip, refreshButtonTooltip, toMyComputerTooltip, transferButtonTooltip, parentDirectoryButtonTooltip, createFolderButtonTooltip;

    @FXML
    private Label localPathIndicator;

    private final ResourceBundle resourceBundle;
    private final Ds3Common ds3Common;
    private final FileTreeTableProvider fileTreeTableProvider;
    private final DataFormat dataFormat;
    private final Workers workers;
    private final LoggingService loggingService;
    private final DeepStorageBrowserPresenter deepStorageBrowserPresenter;
    private final DataFormat local = new DataFormat(LOCAL);
    private final AlertService alert;
    private final DateTimeUtils dateTimeUtils;
    private final PutJobFactory putJobFactory;
    private final GetJobFactory getJobFactory;
    private final FileTreeTableItem.FileTreeTableItemFactory fileTreeTableItemFactory;
    private final GetMediaDeviceTask.GetMediaDeviceTaskFactory getMediaDeviceTaskFactory;

    private String fileRootItem = StringConstants.ROOT_LOCATION;

    private TreeItem<FileTreeModel> lastExpandedNode;

    @Inject
    public LocalFileTreeTablePresenter(final ResourceBundle resourceBundle,
            final Ds3Common ds3Common,
            final FileTreeTableProvider fileTreeTableProvider,
            final DataFormat dataFormat,
            final Workers workers,
            final LoggingService loggingService,
            final PutJobFactory putJobFactory,
            final FileTreeTableItem.FileTreeTableItemFactory fileTreeTableItemFactory,
            final GetJobFactory getJobFactory,
            final DeepStorageBrowserPresenter deepStorageBrowserPresenter,
            final DateTimeUtils dateTimeUtils,
            final AlertService alertService,
            final GetMediaDeviceTask.GetMediaDeviceTaskFactory getMediaDeviceTaskFactory) {
        this.resourceBundle = resourceBundle;
        this.ds3Common = ds3Common;
        this.dateTimeUtils = dateTimeUtils;
        this.fileTreeTableProvider = fileTreeTableProvider;
        this.dataFormat = dataFormat;
        this.workers = workers;
        this.loggingService = loggingService;
        this.fileTreeTableItemFactory = fileTreeTableItemFactory;
        this.deepStorageBrowserPresenter = deepStorageBrowserPresenter;
        this.putJobFactory = putJobFactory;
        this.getJobFactory = getJobFactory;
        this.getMediaDeviceTaskFactory = getMediaDeviceTaskFactory;
        this.alert = alertService;
    }

    @Override
    public void initialize(final URL location, final ResourceBundle resources) {
        try {
            LOG.debug("Initialize...");
            initToolTips();
            initTableView();
            initListeners();
            initProgressAndPathIndicators();
        } catch (final Throwable t) {
            LOG.error("Encountered an error when initializing LocalFileTreeTablePresenter", t);
        }
    }

    private void initToolTips() {
        transferButtonTooltip.setText(resourceBundle.getString("transferButtonTooltip"));
        homeButtonTooltip.setText(resourceBundle.getString("homeButtonTooltip"));
        refreshButtonTooltip.setText(resourceBundle.getString("refreshButtonTooltip"));
        toMyComputerTooltip.setText(resourceBundle.getString("toMyComputerTooltip"));
        parentDirectoryButtonTooltip.setText(resourceBundle.getString("parentDirectoryButtonTooltip"));
        createFolderButtonTooltip.setText(resourceBundle.getString("ds3NewFolderToolTip"));
    }

    private void initTableView() {
        ds3Common.setLocalFileTreeTablePresenter(this);
        treeTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        treeTable.setOnDragEntered(SafeHandler.logHandle(event -> event.acceptTransferModes(TransferMode.COPY)));
        treeTable.setOnDragOver(SafeHandler.logHandle(event -> event.acceptTransferModes(TransferMode.COPY)));
        treeTable.setOnDragDropped(SafeHandler.logHandle(event -> {
            setDragDropEvent(null, event);
            event.consume();
        }));
        dateModified.setComparator(Comparator.comparing(dateTimeUtils::stringAsDate));<commit_msg>Sorts name column case insensitive<commit_after>/*
 * ******************************************************************************
 *    Copyright 2016-2017 Spectra Logic Corporation. All Rights Reserved.
 *    Licensed under the Apache License, Version 2.0 (the "License"). You may not use
 *    this file except in compliance with the License. A copy of the License is located at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *    or in the "license" file accompanying this file.
 *    This file 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 com.spectralogic.dsbrowser.gui.components.localfiletreetable;

import com.google.common.collect.ImmutableList;
import com.spectralogic.ds3client.Ds3Client;
import com.spectralogic.ds3client.utils.Guard;
import com.spectralogic.dsbrowser.api.injector.Presenter;
import com.spectralogic.dsbrowser.api.services.logging.LogType;
import com.spectralogic.dsbrowser.api.services.logging.LoggingService;
import com.spectralogic.dsbrowser.gui.DeepStorageBrowserPresenter;
import com.spectralogic.dsbrowser.gui.components.ds3panel.Ds3Common;
import com.spectralogic.dsbrowser.gui.components.ds3panel.ds3treetable.Ds3TreeTableItem;
import com.spectralogic.dsbrowser.gui.components.ds3panel.ds3treetable.Ds3TreeTableValue;
import com.spectralogic.dsbrowser.gui.components.ds3panel.ds3treetable.Ds3TreeTableValueCustom;
import com.spectralogic.dsbrowser.gui.services.Workers;
import com.spectralogic.dsbrowser.gui.services.jobService.factories.GetJobFactory;
import com.spectralogic.dsbrowser.gui.services.jobService.factories.PutJobFactory;
import com.spectralogic.dsbrowser.gui.services.sessionStore.Session;
import com.spectralogic.dsbrowser.gui.services.tasks.*;
import com.spectralogic.dsbrowser.gui.util.*;
import com.spectralogic.dsbrowser.gui.util.treeItem.SafeHandler;
import com.spectralogic.dsbrowser.util.GuavaCollectors;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.effect.InnerShadow;
import javafx.scene.input.*;
import javafx.scene.layout.StackPane;
import javafx.util.Pair;
import kotlin.Unit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Stream;

@Presenter
public class LocalFileTreeTablePresenter implements Initializable {

    private final static Logger LOG = LoggerFactory.getLogger(LocalFileTreeTablePresenter.class);
    private static final String LOCAL = "local";

    @FXML
    private TreeTableView<FileTreeModel> treeTable;

    @FXML
    private TreeTableColumn<FileTreeModel, Number> sizeColumn;

    @FXML
    private TreeTableColumn<FileTreeModel, String> dateModified;

    @FXML
    private TreeTableColumn<FileTreeModel, String> nameColumn;

    @FXML
    private Button homeButton, refreshButton, toMyComputer, transferButton, parentDirectoryButton, createFolderButton;

    @FXML
    private Tooltip homeButtonTooltip, refreshButtonTooltip, toMyComputerTooltip, transferButtonTooltip, parentDirectoryButtonTooltip, createFolderButtonTooltip;

    @FXML
    private Label localPathIndicator;

    private final ResourceBundle resourceBundle;
    private final Ds3Common ds3Common;
    private final FileTreeTableProvider fileTreeTableProvider;
    private final DataFormat dataFormat;
    private final Workers workers;
    private final LoggingService loggingService;
    private final DeepStorageBrowserPresenter deepStorageBrowserPresenter;
    private final DataFormat local = new DataFormat(LOCAL);
    private final AlertService alert;
    private final DateTimeUtils dateTimeUtils;
    private final PutJobFactory putJobFactory;
    private final GetJobFactory getJobFactory;
    private final FileTreeTableItem.FileTreeTableItemFactory fileTreeTableItemFactory;
    private final GetMediaDeviceTask.GetMediaDeviceTaskFactory getMediaDeviceTaskFactory;

    private String fileRootItem = StringConstants.ROOT_LOCATION;

    private TreeItem<FileTreeModel> lastExpandedNode;

    @Inject
    public LocalFileTreeTablePresenter(final ResourceBundle resourceBundle,
            final Ds3Common ds3Common,
            final FileTreeTableProvider fileTreeTableProvider,
            final DataFormat dataFormat,
            final Workers workers,
            final LoggingService loggingService,
            final PutJobFactory putJobFactory,
            final FileTreeTableItem.FileTreeTableItemFactory fileTreeTableItemFactory,
            final GetJobFactory getJobFactory,
            final DeepStorageBrowserPresenter deepStorageBrowserPresenter,
            final DateTimeUtils dateTimeUtils,
            final AlertService alertService,
            final GetMediaDeviceTask.GetMediaDeviceTaskFactory getMediaDeviceTaskFactory) {
        this.resourceBundle = resourceBundle;
        this.ds3Common = ds3Common;
        this.dateTimeUtils = dateTimeUtils;
        this.fileTreeTableProvider = fileTreeTableProvider;
        this.dataFormat = dataFormat;
        this.workers = workers;
        this.loggingService = loggingService;
        this.fileTreeTableItemFactory = fileTreeTableItemFactory;
        this.deepStorageBrowserPresenter = deepStorageBrowserPresenter;
        this.putJobFactory = putJobFactory;
        this.getJobFactory = getJobFactory;
        this.getMediaDeviceTaskFactory = getMediaDeviceTaskFactory;
        this.alert = alertService;
    }

    @Override
    public void initialize(final URL location, final ResourceBundle resources) {
        try {
            LOG.debug("Initialize...");
            initToolTips();
            initTableView();
            initListeners();
            initProgressAndPathIndicators();
        } catch (final Throwable t) {
            LOG.error("Encountered an error when initializing LocalFileTreeTablePresenter", t);
        }
    }

    private void initToolTips() {
        transferButtonTooltip.setText(resourceBundle.getString("transferButtonTooltip"));
        homeButtonTooltip.setText(resourceBundle.getString("homeButtonTooltip"));
        refreshButtonTooltip.setText(resourceBundle.getString("refreshButtonTooltip"));
        toMyComputerTooltip.setText(resourceBundle.getString("toMyComputerTooltip"));
        parentDirectoryButtonTooltip.setText(resourceBundle.getString("parentDirectoryButtonTooltip"));
        createFolderButtonTooltip.setText(resourceBundle.getString("ds3NewFolderToolTip"));
    }

    private void initTableView() {
        ds3Common.setLocalFileTreeTablePresenter(this);
        treeTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        treeTable.setOnDragEntered(SafeHandler.logHandle(event -> event.acceptTransferModes(TransferMode.COPY)));
        treeTable.setOnDragOver(SafeHandler.logHandle(event -> event.acceptTransferModes(TransferMode.COPY)));
        treeTable.setOnDragDropped(SafeHandler.logHandle(event -> {
            setDragDropEvent(null, event);
            event.consume();
        }));
        dateModified.setComparator(Comparator.comparing(dateTimeUtils::stringAsDate));
        nameColumn.setComparator(Comparator.comparing(String::toLowerCase));
{'fraction_non_alphanumeric': 0.09370887075546197, 'fraction_numerical': 0.0047380889707817845, 'mean_word_length': 4.490245664739884, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, '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': '989354', 'n_tokens_mistral': 3990, 'n_tokens_neox': 3959, 'n_words': 809}