Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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 com.jfoenix.controls;
import com.jfoenix.assets.JFoenixResources;
import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject;
import com.jfoenix.skins.JFXTreeTableViewSkin;
import com.jfoenix.utils.JFXUtilities;
import javafx.application.Platform;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.Skin;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.input.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
/**
* JFXTreeTableView is the material design implementation of table view.
*
* @author Shadi Shaheen
* @version 1.0
* @since 2016-03-09 DOC: not completed
*/
public class JFXTreeTableView> extends TreeTableView {
private TreeItem originalRoot;
private boolean internalSetRoot = false;
/**
* {@inheritDoc}
*/
public JFXTreeTableView() {
init();
}
/**
* {@inheritDoc}
*/
public JFXTreeTableView(TreeItem root) {
super(root);
originalRoot = root;
init();
}
/**
* propagate any mouse event on the tree table view to its parent
*/
public void propagateMouseEventsToParent() {
this.addEventHandler(MouseEvent.ANY, e -> {
e.consume();
this.getParent().fireEvent(e);
});
}
/**
* {@inheritDoc}
*/
@Override
protected Skin createDefaultSkin() {
return new JFXTreeTableViewSkin<>(this);
}
protected void init() {
this.getStyleClass().add(DEFAULT_STYLE_CLASS);
this.setRowFactory(param -> new JFXTreeTableRow<>());
this.getSelectionModel().selectedItemProperty().addListener((o, oldVal, newVal) -> {
if (newVal != null && newVal.getValue() != null) {
itemWasSelected = true;
}
});
this.predicate.addListener(observable -> filter(getPredicate()));
this.sceneProperty().addListener(observable -> {
if (getScene() == null) {
threadPool.shutdownNow();
} else if (threadPool.isTerminated()) {
threadPool = createThreadPool();
}
});
this.rootProperty().addListener(observable -> {
if (getRoot() != null) {
setCurrentItemsCount(count(getRoot()));
}
if (!internalSetRoot) {
originalRoot = getRoot();
reGroup();
}
});
// compute the current items count
setCurrentItemsCount(count(getRoot()));
}
private static final String DEFAULT_STYLE_CLASS = "jfx-tree-table-view";
private static final String USER_AGENT_STYLESHEET = JFoenixResources.load("css/controls/jfx-tree-table-view.css").toExternalForm();
/**
* {@inheritDoc}
*/
@Override
public String getUserAgentStylesheet() {
return USER_AGENT_STYLESHEET;
}
@Override
public int getTreeItemLevel(TreeItem node) {
final TreeItem root = getRoot();
if (node == null) {
return -1;
}
if (node == root) {
return 0;
}
int level = 0;
TreeItem parent = node.getParent();
while (parent != null) {
level++;
if (parent == root) {
break;
}
// handle group nodes
if (parent.getValue() != null
&& parent.getValue() instanceof RecursiveTreeObject
&& ((RecursiveTreeObject) parent.getValue()).getGroupedColumn() != null) {
level--;
}
parent = parent.getParent();
}
return level;
}
/*
* clear selection before sorting as it's bugged in java
*/
private boolean itemWasSelected = false;
/**
* {@inheritDoc}
*/
@Override
public void sort() {
getSelectionModel().clearSelection();
super.sort();
if (itemWasSelected) {
getSelectionModel().select(0);
}
}
// Allows for multiple column Grouping based on the order of the TreeTableColumns
// in this observableArrayList.
private ObservableList> groupOrder = FXCollections.observableArrayList();
final ObservableList> getGroupOrder() {
return groupOrder;
}
// lock is used to force mutual exclusion while group/ungroup operation
private final Lock lock = new ReentrantLock(true);
BiConsumer