001package conexp.fx.gui.dataset; 002 003/* 004 * #%L 005 * Concept Explorer FX 006 * %% 007 * Copyright (C) 2010 - 2023 Francesco Kriegel 008 * %% 009 * This program is free software: you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as 011 * published by the Free Software Foundation, either version 3 of the 012 * License, or (at your option) any later version. 013 * 014 * This program is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public 020 * License along with this program. If not, see 021 * <http://www.gnu.org/licenses/gpl-3.0.html>. 022 * #L% 023 */ 024 025import java.io.File; 026import java.util.ArrayList; 027import java.util.HashSet; 028import java.util.List; 029import java.util.Set; 030 031import conexp.fx.core.util.FileFormat; 032import conexp.fx.gui.ConExpFX; 033import javafx.beans.binding.Bindings; 034import javafx.beans.property.BooleanProperty; 035import javafx.beans.property.SimpleBooleanProperty; 036import javafx.beans.property.SimpleStringProperty; 037import javafx.beans.property.StringProperty; 038import javafx.geometry.Insets; 039import javafx.geometry.Pos; 040import javafx.scene.control.ContentDisplay; 041import javafx.scene.control.Control; 042import javafx.scene.control.Hyperlink; 043import javafx.scene.control.Label; 044import javafx.scene.control.ProgressIndicator; 045import javafx.scene.control.TreeItem; 046import javafx.scene.image.Image; 047import javafx.scene.image.ImageView; 048import javafx.scene.layout.HBox; 049 050public abstract class Dataset { 051 052 public final class DatasetTreeItem extends TreeItem<Control> { 053 054 public DatasetTreeItem(ConExpFX.DatasetTreeView treeView) { 055 super(); 056 final Label label = new Label(id.get()); 057 label.textProperty().bind( 058 Bindings.createStringBinding(() -> id.get() + (unsavedChanges.get() ? "*" : ""), id, unsavedChanges)); 059 label.setStyle("-fx-font-weight: bold;"); 060 final ProgressIndicator progressIndicator = new ProgressIndicator(); 061 progressIndicator.setMinSize(12, 12); 062 progressIndicator.setMaxSize(12, 12); 063 progressIndicator.setPadding(new Insets(0d)); 064 progressIndicator.progressProperty().bind( 065 Bindings.createDoubleBinding( 066 () -> ConExpFX.instance.executor.datasetProgressBinding(Dataset.this).get() == 1d ? 1d : -1d, 067 ConExpFX.instance.executor.datasetProgressBinding(Dataset.this))); 068 progressIndicator.visibleProperty().bind(progressIndicator.progressProperty().lessThan(1d)); 069 this.setValue(label); 070 final Hyperlink closeLink = new Hyperlink("x"); 071 closeLink.setOnAction(e -> treeView.close(Dataset.this)); 072 closeLink.setPadding(new Insets(0)); 073 final HBox hBox = new HBox(closeLink, progressIndicator); 074 hBox.setSpacing(4d); 075 hBox.setAlignment(Pos.CENTER); 076 label.setGraphic(hBox); 077 label.setContentDisplay(ContentDisplay.RIGHT); 078 this.setGraphic(new ImageView(new Image(ConExpFX.class.getResourceAsStream("image/context.gif")))); 079 views.forEach(view -> getChildren().add(view.getTreeItem())); 080 actions.forEach(action -> { 081 this.getChildren().add(action.getTreeItem()); 082 }); 083 } 084 085 public final Dataset getDataset() { 086 return Dataset.this; 087 } 088 089 } 090 091 public File file; 092 public FileFormat format; 093 public final StringProperty id = new SimpleStringProperty(""); 094 public final BooleanProperty unsavedChanges = new SimpleBooleanProperty(false); 095 public final List<DatasetView<?>> views = new ArrayList<DatasetView<?>>(); 096 public final Set<String> defaultActiveViews = new HashSet<String>(); 097 public final List<DatasetAction> actions = new ArrayList<DatasetAction>(); 098 public final Dataset parent; 099 public Dataset.DatasetTreeItem treeItem; 100 101 protected Dataset(final Dataset parent) { 102 super(); 103 this.parent = parent; 104 } 105 106 public Dataset(final Dataset parent, final File file, final FileFormat format) { 107 this(parent); 108 this.file = file; 109 this.format = format; 110 this.id.set(file.getName()); 111 } 112 113 public final Dataset.DatasetTreeItem getTreeItem() { 114 return treeItem; 115 } 116 117 public final void addToTree(final ConExpFX.DatasetTreeView treeView) { 118 this.treeItem = new Dataset.DatasetTreeItem(treeView); 119 treeView.getParentItem(Dataset.this).getChildren().add(treeItem); 120 treeView.getParentItem(Dataset.this).setExpanded(true); 121 treeItem.setExpanded(true); 122// views.forEach(view -> { 123// if (defaultActiveViews.contains(view.getId())) 124// treeView.getSelectionModel().select(view.getTreeItem()); 125// }); 126 } 127 128 public abstract void save(); 129 130 public abstract void saveAs(); 131 132 public abstract void export(); 133 134 public abstract void close(); 135 136}