From 70ee80667479550ab1958db034803f430a1f44b9 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 23 Apr 2016 19:12:55 +0300 Subject: [PATCH] [no commit message] --- numass-viewer/build.gradle | 4 +- .../numass/viewer/MainViewerController.java | 79 ++++------- .../inr/numass/viewer/MspViewController.java | 126 +++++++----------- .../viewer/NumassLoaderTreeBuilder.java | 94 +++++++------ .../src/main/resources/fxml/MainView.fxml | 1 + 5 files changed, 127 insertions(+), 177 deletions(-) diff --git a/numass-viewer/build.gradle b/numass-viewer/build.gradle index 1e6305c4..0b45e7da 100644 --- a/numass-viewer/build.gradle +++ b/numass-viewer/build.gradle @@ -5,13 +5,13 @@ if (!hasProperty('mainClass')) { } mainClassName = mainClass -version = "0.2.5" +version = "0.3.0" description = "The viewer for numass data" dependencies { compile project(':numass-main') - compile project(':dataforge-storage') +// compile project(':dataforge-storage') compile project(':numass-storage') compile project(':dataforge-fx') compile 'com.jcraft:jsch:0.1.53' diff --git a/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java b/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java index 580f05af..cfa08df4 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java @@ -27,11 +27,9 @@ import java.io.File; import java.net.URL; import java.util.Optional; import java.util.ResourceBundle; -import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Platform; -import javafx.concurrent.Task; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; @@ -150,67 +148,40 @@ public class MainViewerController implements Initializable { }); } - private class DirectoryLoadTask extends Task { - - private final String uri; - - public DirectoryLoadTask(String uri) { - this.uri = uri; - } - - @Override - protected Void call() throws Exception { - updateTitle("Load storage (" + uri + ")"); - updateProgress(-1, 1); - updateMessage("Building numass storage tree..."); - try { - NumassStorage root = NumassStorage.buildNumassRoot(uri, true, false); - setRootStorage(root); - Platform.runLater(() -> storagePathLabel.setText("Storage: " + uri)); - } catch (StorageException ex) { - updateProgress(0, 1); - updateMessage("Failed to load storage " + uri); - Logger.getLogger(MainViewerController.class.getName()).log(Level.SEVERE, null, ex); - } - return null; - } - - } - private Context getContext() { return GlobalContext.instance(); } public void setRootStorage(NumassStorage root) { -// Task fillTask = new StorageDataFillTask(root); -// postTask(fillTask); -// Viewer.runTask(fillTask); - getContext().processManager().post("viewer.storage.load", new Consumer() { - @Override - public void accept(ProcessManager.Callback callback) { - callback.updateTitle("Fill data to UI (" + root.getName() + ")"); - callback.updateProgress(-1, 1); - callback.updateMessage("Loading numass storage tree..."); - - new NumassLoaderTreeBuilder().build(getContext(), numassLoaderDataTree, root, (NumassData loader) -> { - NumassLoaderViewComponent component = new NumassLoaderViewComponent(getContext()); - component.loadData(loader); - numassLoaderViewContainer.getChildren().clear(); - numassLoaderViewContainer.getChildren().add(component); - AnchorPane.setTopAnchor(component, 0.0); - AnchorPane.setRightAnchor(component, 0.0); - AnchorPane.setLeftAnchor(component, 0.0); - AnchorPane.setBottomAnchor(component, 0.0); - numassLoaderViewContainer.requestLayout(); - }); + getContext().processManager().cleanup(); + getContext().processManager().post("viewer.storage.load", (ProcessManager.Callback callback) -> { + callback.updateTitle("Fill data to UI (" + root.getName() + ")"); +// callback.updateProgress(-1, 1); + Platform.runLater(() -> statusBar.setProgress(-1)); - callback.updateProgress(0, 1); - callback.updateMessage("Numass storage tree loaded."); + callback.updateMessage("Loading numass storage tree..."); + try { + new NumassLoaderTreeBuilder().build(callback, numassLoaderDataTree, root, (NumassData loader) -> { + NumassLoaderViewComponent component = new NumassLoaderViewComponent(getContext()); + component.loadData(loader); + numassLoaderViewContainer.getChildren().clear(); + numassLoaderViewContainer.getChildren().add(component); + AnchorPane.setTopAnchor(component, 0.0); + AnchorPane.setRightAnchor(component, 0.0); + AnchorPane.setLeftAnchor(component, 0.0); + AnchorPane.setBottomAnchor(component, 0.0); + numassLoaderViewContainer.requestLayout(); + }); + } catch (StorageException ex) { + Logger.getLogger(MainViewerController.class.getName()).log(Level.SEVERE, null, ex); } - } - ); + +// callback.updateProgress(1, 1); + Platform.runLater(() -> statusBar.setProgress(0)); + callback.updateMessage("Numass storage tree loaded."); + }); mspController = new MspViewController(getContext(), mspPlotPane); mspController.fillMspData(root); diff --git a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java index e8b753d0..72e98ba0 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java @@ -21,6 +21,9 @@ package inr.numass.viewer; * and open the template in the editor. */ import hep.dataforge.context.Context; +import hep.dataforge.context.DFProcess; +import hep.dataforge.context.ProcessManager; +import hep.dataforge.exceptions.StorageException; import hep.dataforge.points.DataPoint; import hep.dataforge.points.MapPoint; import hep.dataforge.plots.PlotUtils; @@ -33,9 +36,11 @@ import hep.dataforge.storage.api.Storage; import hep.dataforge.values.Value; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.StreamSupport; import javafx.application.Platform; -import javafx.concurrent.Task; import javafx.scene.layout.AnchorPane; import org.slf4j.LoggerFactory; @@ -46,7 +51,6 @@ import org.slf4j.LoggerFactory; */ public class MspViewController { - private final AnchorPane mspPlotPane; private final Context context; @@ -75,8 +79,8 @@ public class MspViewController { PlotUtils.setXAxis(frame, "time", null, "time"); StreamSupport.stream(mspData.spliterator(), false) - .sorted((DynamicPlottable o1, DynamicPlottable o2) -> - Integer.valueOf(o1.getName()).compareTo(Integer.valueOf(o2.getName()))).forEach((pl) -> frame.add(pl)); + .sorted((DynamicPlottable o1, DynamicPlottable o2) + -> Integer.valueOf(o1.getName()).compareTo(Integer.valueOf(o2.getName()))).forEach((pl) -> frame.add(pl)); Platform.runLater(() -> { PlotContainer container = PlotContainer.anchorTo(mspPlotPane); container.setPlot(frame); @@ -85,91 +89,57 @@ public class MspViewController { public void fillMspData(Storage rootStorage) { if (rootStorage != null) { - MspDataFillTask fillTask = new MspDataFillTask(rootStorage); - if (callback != null) { - callback.postTask(fillTask); - } - Viewer.runTask(fillTask); - } - } + context.processManager().post("viewer.msp.fill", (ProcessManager.Callback callback) -> { + try { +// callback.updateTitle("Fill msp data (" + rootStorage.getName() + ")"); - private class MspDataFillTask extends Task { - - private final Storage storage; - - public MspDataFillTask(Storage storage) { - this.storage = storage; - } - - @Override - protected Void call() throws Exception { - updateTitle("Fill msp data (" + storage.getName() + ")"); - MspDataLoadTask loadTask = new MspDataLoadTask(storage); - if (callback != null) { - callback.postTask(loadTask); - } - Viewer.runTask(loadTask); - List mspData = loadTask.get(); - - DynamicPlottableSet plottables = new DynamicPlottableSet(); - - for (DataPoint point : mspData) { - for (String name : point.names()) { - if (!name.equals("timestamp")) { - if (!plottables.hasPlottable(name)) { - plottables.addPlottable(new DynamicPlottable(name, name)); + callback.updateTitle("Load msp data (" + rootStorage.getName() + ")"); + List mspData = new ArrayList<>(); + DataPoint last = null; + for (String loaderName : rootStorage.loaders().keySet()) { + if (loaderName.startsWith("msp")) { + try (final PointLoader mspLoader = (PointLoader) rootStorage.getLoader(loaderName)) { + mspLoader.open(); + callback.updateMessage("Loading mass spectrometer data from " + mspLoader.getName()); + for (DataPoint dp : mspLoader.asDataSet()) { + mspData.add(dp); + last = dp; + } + if (last != null) { + mspData.add(terminatorPoint(last)); + } + } catch (Exception ex) { + LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex); + } } } - } - plottables.put(point); - } + callback.updateMessage("Loading msp data finished"); +// return mspData; +// List mspData = (List) loadProcess.getTask().get(); - updateMspPane(plottables); - return null; - } + if (!mspData.isEmpty()) { + DynamicPlottableSet plottables = new DynamicPlottableSet(); - } - - private class MspDataLoadTask extends Task> { - - private final Storage storage; - - public MspDataLoadTask(Storage storage) { - this.storage = storage; - } - - @Override - protected List call() throws Exception { - updateTitle("Load msp data (" + storage.getName() + ")"); - List mspData = new ArrayList<>(); - DataPoint last = null; - for (String loaderName : storage.loaders().keySet()) { - if (loaderName.startsWith("msp")) { - try (PointLoader mspLoader = (PointLoader) storage.getLoader(loaderName)) { - mspLoader.open(); - updateMessage("Loading mass spectrometer data from " + mspLoader.getName()); - updateProgress(-1, 1); - for (DataPoint dp : mspLoader.asDataSet()) { - mspData.add(dp); - last = dp; + for (DataPoint point : mspData) { + for (String name : point.names()) { + if (!name.equals("timestamp")) { + if (!plottables.hasPlottable(name)) { + plottables.addPlottable(new DynamicPlottable(name, name)); + } + } + } + plottables.put(point); } - if (last != null) { - mspData.add(terminatorPoint(last)); - } - } catch (Exception ex) { - LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex); + + updateMspPane(plottables); } + } catch (StorageException ex) { + throw new RuntimeException(ex); } - } - - updateMessage("Loading msp data finished"); - updateProgress(0, 1); - return mspData; + }); } - } - /** * Create a null value point to terminate msp series * diff --git a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java index 05d9b128..45bd663a 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java @@ -15,7 +15,6 @@ */ package inr.numass.viewer; -import hep.dataforge.context.Context; import hep.dataforge.context.ProcessManager; import hep.dataforge.exceptions.StorageException; import hep.dataforge.storage.api.Loader; @@ -48,56 +47,61 @@ public class NumassLoaderTreeBuilder { // this.rootStorage = rootStorage; // this.numassViewBuilder = numassViewBuilder; // } - public void build(Context context, + public void build(ProcessManager.Callback callback, TreeTableView numassLoaderDataTree, NumassStorage rootStorage, - Consumer numassViewBuilder) { + Consumer numassViewBuilder) throws StorageException { - context.processManager().post("viewer.storage.load.buildTree", (ProcessManager.Callback callback) -> { - try { - callback.updateTitle("Load numass data (" + rootStorage.getName() + ")"); - TreeItem root = buildNode(rootStorage, numassViewBuilder, callback); - root.setExpanded(true); +// callback.updateTitle("Load numass data (" + rootStorage.getName() + ")"); + TreeItem root = buildNode(rootStorage, numassViewBuilder, callback); + root.setExpanded(true); // numassLoaderDataTree.setShowRoot(true); - Platform.runLater(() -> { - numassLoaderDataTree.setRoot(root); + Platform.runLater(() -> { + numassLoaderDataTree.setRoot(root); - TreeTableColumn numassLoaderNameColumn = new TreeTableColumn<>("name"); + TreeTableColumn numassLoaderNameColumn = new TreeTableColumn<>("name"); - numassLoaderNameColumn.setCellValueFactory( - (TreeTableColumn.CellDataFeatures param) -> new SimpleStringProperty(param.getValue().getValue().getName())); + numassLoaderNameColumn.setCellValueFactory( + (TreeTableColumn.CellDataFeatures param) -> new SimpleStringProperty(param.getValue().getValue().getName())); - TreeTableColumn numassLoaderTimeColumn = new TreeTableColumn<>("time"); - numassLoaderTimeColumn.setCellValueFactory( - (TreeTableColumn.CellDataFeatures param) -> new SimpleStringProperty(param.getValue().getValue().getTime())); + TreeTableColumn numassLoaderTimeColumn = new TreeTableColumn<>("time"); + numassLoaderTimeColumn.setCellValueFactory( + (TreeTableColumn.CellDataFeatures param) -> new SimpleStringProperty(param.getValue().getValue().getTime())); - TreeTableColumn nummassLoaderDescriptionColumn = new TreeTableColumn<>("description"); - nummassLoaderDescriptionColumn.setCellValueFactory( - (TreeTableColumn.CellDataFeatures param) -> new SimpleStringProperty(param.getValue().getValue().getDescription())); + TreeTableColumn nummassLoaderDescriptionColumn = new TreeTableColumn<>("description"); + nummassLoaderDescriptionColumn.setCellValueFactory( + (TreeTableColumn.CellDataFeatures param) -> new SimpleStringProperty(param.getValue().getValue().getDescription())); - numassLoaderDataTree.getColumns().setAll(numassLoaderNameColumn, numassLoaderTimeColumn, nummassLoaderDescriptionColumn); + numassLoaderDataTree.getColumns().setAll(numassLoaderNameColumn, numassLoaderTimeColumn, nummassLoaderDescriptionColumn); - numassLoaderDataTree.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> { - if (e.getClickCount() == 2) { - TreeItemValue value = numassLoaderDataTree.getFocusModel().getFocusedCell().getTreeItem().getValue(); - if (value.isLoader()) { - numassViewBuilder.accept(value.getLoader()); - } - } - }); - numassLoaderTimeColumn.setVisible(false); - nummassLoaderDescriptionColumn.setVisible(false); - }); - } catch (StorageException ex) { - throw new RuntimeException(ex); - } + numassLoaderDataTree.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> { + if (e.getClickCount() == 2) { + TreeItemValue value = numassLoaderDataTree.getFocusModel().getFocusedCell().getTreeItem().getValue(); + if (value.isLoader()) { + numassViewBuilder.accept(value.getLoader()); + } + } + }); + numassLoaderTimeColumn.setVisible(false); + nummassLoaderDescriptionColumn.setVisible(false); }); } private TreeItem buildNode(NumassStorage storage, Consumer numassViewBuilder, ProcessManager.Callback callback) throws StorageException { +// CompletableFuture> future = CompletableFuture.supplyAsync(() -> { +// try { +// TreeItem node = new TreeItem<>(buildValue(storage)); +// node.getChildren().setAll(buildChildren(storage, numassViewBuilder, callback)); +// return node; +// } catch (StorageException ex) { +// throw new RuntimeException(ex); +// } +// }); +// callback.getProcess().addChild(storage.getName(), future); +// return future.join(); TreeItem node = new TreeItem<>(buildValue(storage)); node.getChildren().setAll(buildChildren(storage, numassViewBuilder, callback)); return node; @@ -110,16 +114,18 @@ public class NumassLoaderTreeBuilder { for (Storage subStorage : storage.shelves().values()) { if (subStorage instanceof NumassStorage) { NumassStorage numassSubStorage = (NumassStorage) subStorage; - list.add(buildNode(numassSubStorage, numassViewBuilder, callback)); + TreeItem childNode = buildNode(numassSubStorage, numassViewBuilder, callback); + if (!childNode.isLeaf()) { + list.add(buildNode(numassSubStorage, numassViewBuilder, callback)); + } } } callback.updateMessage("Building storage " + storage.getName()); - - double counter = 0; + callback.updateProgress(-1, 1); + callback.updateProgress(0, storage.loaders().size()); for (Loader loader : storage.loaders().values()) { callback.updateMessage("Building numass data loader " + loader.getName()); - callback.updateProgress(counter, storage.loaders().size()); if (loader instanceof NumassData) { NumassData numassLoader = (NumassData) loader; @@ -135,17 +141,19 @@ public class NumassLoaderTreeBuilder { // }); list.add(numassLoaderTreeItem); } - counter++; + callback.changeProgress(1, 0); } + callback.updateMessage("Loading legacy DAT files"); + callback.updateProgress(-1, 1); + List legacyFiles = storage.legacyFiles(); + callback.updateProgress(0, legacyFiles.size()); //adding legacy data files - counter = 0; - for (NumassData legacyDat : storage.legacyFiles()) { + for (NumassData legacyDat : legacyFiles) { callback.updateMessage("Loading numass DAT file " + legacyDat.getName()); - callback.updateProgress(counter, storage.loaders().size()); TreeItem numassLoaderTreeItem = new TreeItem<>(buildValue(legacyDat)); + callback.changeProgress(1, 0); list.add(numassLoaderTreeItem); - counter++; } return list; diff --git a/numass-viewer/src/main/resources/fxml/MainView.fxml b/numass-viewer/src/main/resources/fxml/MainView.fxml index 00cbd8fd..3ed5e6c7 100644 --- a/numass-viewer/src/main/resources/fxml/MainView.fxml +++ b/numass-viewer/src/main/resources/fxml/MainView.fxml @@ -30,6 +30,7 @@ limitations under the License. +