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.
/*
* This file is part of JBizMo, a set of tools, libraries and plug-ins
* for modeling and creating Java-based enterprise applications.
* For more information visit:
*
* http://sourceforge.net/projects/jbizmo/
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.sourceforge.jbizmo.commons.richclient.javafx.tree;
import static net.sourceforge.jbizmo.commons.richclient.javafx.image.ImageLoader.IMG_REFRESH;
import static net.sourceforge.jbizmo.commons.richclient.javafx.image.ImageLoader.IMG_SEARCH;
import static net.sourceforge.jbizmo.commons.richclient.javafx.image.ImageLoader.IMG_STOP;
import static net.sourceforge.jbizmo.commons.richclient.javafx.image.ImageLoader.getImage;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Tab;
import javafx.scene.control.ToolBar;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeView;
import javafx.scene.input.DataFormat;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import net.sourceforge.jbizmo.commons.richclient.format.FormatDTO;
import net.sourceforge.jbizmo.commons.richclient.format.FormatPreferencesManager;
import net.sourceforge.jbizmo.commons.richclient.javafx.control.Action;
import net.sourceforge.jbizmo.commons.richclient.javafx.control.StatusBar;
import net.sourceforge.jbizmo.commons.richclient.javafx.control.View;
import net.sourceforge.jbizmo.commons.richclient.javafx.dialog.DialogButtonType;
import net.sourceforge.jbizmo.commons.richclient.javafx.dialog.DialogUtil;
import net.sourceforge.jbizmo.commons.richclient.javafx.i18n.I18NJavaFX;
import net.sourceforge.jbizmo.commons.richclient.javafx.search.Countable;
import net.sourceforge.jbizmo.commons.richclient.javafx.search.SearchInputDialog;
import net.sourceforge.jbizmo.commons.richclient.search.util.SearchManager;
import net.sourceforge.jbizmo.commons.search.dto.SearchDTO;
import net.sourceforge.jbizmo.commons.search.exception.GeneralSearchException;
/**
*
* Abstract base class for tree views
*
*
* Copyright 2015 (C) by Martin Ganserer
*
* @author Martin Ganserer
* @version 1.0.0
* @param the type of the data objects for the root tree item
*/
public abstract class AbstractTreeView extends Tab implements View, Countable
{
protected FormatDTO userFormat = FormatPreferencesManager.getFormatDTO();
protected SimpleDateFormat dateTimeFormat = new SimpleDateFormat(userFormat.getDateTimeFormat());
protected SimpleDateFormat dateFormat = new SimpleDateFormat(userFormat.getDateFormat());
protected DecimalFormat decimalFormat = new DecimalFormat(userFormat.getDecimalFormat());
protected SearchDTO searchObj = new SearchDTO();
protected ToolBar toolBar;
protected TreeView treeView;
protected Action refreshAction;
protected Action suspendAction;
protected Action searchInputAction;
protected StatusBar statusBar;
protected TreeDataItem dragItem;
private DataFetchTask refreshViewTask;
/**
* @return a list of all items that should be added to the tree
* @throws Exception if data fetch operation has failed
*/
protected abstract List fetchRootItems() throws Exception;
/**
* @param rootTreeItems
*/
public abstract void addRootTreeItems(List rootTreeItems);
/**
* @param item
* @return the context menu for a given tree item
*/
@SuppressWarnings("unused")
public ContextMenu getContextMenuForTreeItem(TreeDataItem item)
{
return null;
}
/**
* @return a search object for advanced search operations or null if this option shouldn't be added
*/
public SearchDTO initAdvancedSearch()
{
return null;
}
/**
* @return the quick search bar or null if this functionality shouldn't be added
*/
protected Node getQuickSearchBar()
{
return null;
}
/**
* @param item
* @return the transfer mode or null if the item shouldn't be dragged
*/
@SuppressWarnings("unused")
public TransferMode startDrag(TreeDataItem item)
{
return null;
}
/**
* Callback method that is called when a drop operation occurred
* @param e
* @param item
*/
@SuppressWarnings("unused")
public void onDragDropped(DragEvent e, TreeDataItem item)
{
}
/**
* @return the ID of the view
*/
public String getViewID()
{
return getClass().getName();
}
/**
* Callback method that is called when a count operation can be invoked
* @return the count result
* @throws Exception if the operation has failed
*/
protected long onPerformCountOperation() throws Exception
{
if(initAdvancedSearch() == null || !searchObj.isCount())
return 0;
try
{
return countData();
}
catch (final GeneralSearchException e)
{
e.printStackTrace();
}
return 0;
}
/**
* Callback method that is called when a data fetch operation starts
*/
protected void onStartSearch()
{
// Remove all existing items from tree view
treeView.setRoot(new TreeDataItem(null, null));
statusBar.showProgress();
statusBar.setText(I18NJavaFX.getInstance().getString("data_fetch_action.status_fetch_data"));
suspendAction.setEnabled(true);
refreshAction.setEnabled(false);
if(searchInputAction != null)
searchInputAction.setEnabled(false);
}
/**
* Callback method that is called as soon as a data fetch operation is finished
* @param itemsFetched
* @param countResult
* @param timeElapsed
*/
protected void onFinishSearch(int itemsFetched, long countResult, long timeElapsed)
{
String statusMessage = "";
suspendAction.setEnabled(false);
refreshAction.setEnabled(true);
if(searchInputAction != null)
searchInputAction.setEnabled(true);
if(searchObj.isCount() && countResult > 0)
{
final ArrayList