Separated FX fragments from FX windows

This commit is contained in:
Alexander Nozik 2016-10-09 14:04:26 +03:00
parent f9f605bde0
commit 6953869c87
12 changed files with 120 additions and 103 deletions

View File

@ -8,8 +8,8 @@ mainClassName = mainClass
//mainClassName = "inr.numass.readvac.Main"
dependencies {
compile 'commons-cli:commons-cli:1.3'
compile 'de.jensd:shichimifx:1.0.5'
// compile 'commons-cli:commons-cli:1.3'
// compile 'de.jensd:shichimifx:1.0.5'
compile project(':dataforge-control')
compile project(':dataforge-storage')
compile project(':dataforge-plots:plots-jfc')

View File

@ -19,9 +19,11 @@ import ch.qos.logback.classic.Level;
import hep.dataforge.control.connections.Roles;
import hep.dataforge.control.connections.StorageConnection;
import hep.dataforge.exceptions.ControlException;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaUtils;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.commons.StorageFactory;
import hep.dataforge.storage.commons.StorageManager;
import javafx.application.Application;
@ -95,7 +97,15 @@ public class PKT8App extends Application {
// setting up storage connections
if (config.hasNode("storage")) {
config.getNodes("storage").forEach(node -> {
device.connect(new StorageConnection(StorageFactory.buildStorage(device.getContext(), node)), Roles.STORAGE_ROLE);
Storage storage = StorageFactory.buildStorage(device.getContext(), node);
if(config.hasValue("numass.run")){
try {
storage = storage.buildShelf(config.getString("numass.run"), Meta.empty());
} catch (StorageException e) {
throw new RuntimeException(e);
}
}
device.connect(new StorageConnection(storage), Roles.STORAGE_ROLE);
});
}

View File

@ -6,7 +6,8 @@ import hep.dataforge.control.measurements.Measurement;
import hep.dataforge.control.measurements.MeasurementListener;
import hep.dataforge.exceptions.ControlException;
import hep.dataforge.exceptions.MeasurementException;
import hep.dataforge.fx.ConsoleFragment;
import hep.dataforge.fx.fragments.ConsoleFragment;
import hep.dataforge.fx.fragments.FragmentWindow;
import hep.dataforge.values.Value;
import javafx.application.Platform;
import javafx.event.ActionEvent;
@ -59,9 +60,9 @@ public class PKT8Controller implements Initializable, DeviceListener, Measuremen
@Override
public void initialize(URL location, ResourceBundle resources) {
this.consoleFragment = new ConsoleFragment();
consoleFragment.bindTo(consoleButton);
new FragmentWindow(consoleFragment).bindTo(consoleButton);
plotFragment = new PKT8PlotFragment(device);
plotFragment.bindTo(plotButton);
new FragmentWindow(plotFragment).bindTo(plotButton);
sensorColumn.setCellValueFactory(new PropertyValueFactory<>("channel"));
resColumn.setCellValueFactory(new PropertyValueFactory<>("rawString"));

View File

@ -1,47 +1,34 @@
package inr.numass.cryotemp;
import hep.dataforge.fx.FXFragment;
import hep.dataforge.fx.fragments.Fragment;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.Window;
import java.io.IOException;
/**
* Created by darksnake on 07-Oct-16.
*/
public class PKT8PlotFragment extends FXFragment {
public class PKT8PlotFragment extends Fragment {
private final PKT8Device device;
private PKT8PlotController plotController;
public PKT8PlotFragment(PKT8Device device) {
super("PKT8 cryogenic temperature viewer", 600, 400);
this.device = device;
}
public PKT8PlotFragment(Window window, PKT8Device device) {
super(window);
this.device = device;
showingProperty().addListener((observable, oldValue, newValue) -> {
if (device.isMeasuring()) {
if (newValue) {
device.getMeasurement().addListener(plotController);
} else {
device.getMeasurement().removeListener(plotController);
}
}
});
}
@Override
protected Stage buildStage(Parent root) {
Stage stage = new Stage();
Scene scene = new Scene(root, 600, 400);
stage.setTitle("PKT8 cryogenic temperature viewer");
stage.setScene(scene);
stage.setMinHeight(400);
stage.setMinWidth(600);
stage.sizeToScene();
return stage;
}
@Override
protected Parent getRoot() {
protected Parent buildRoot() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/PKT8Plot.fxml"));
plotController = new PKT8PlotController(device);
loader.setController(plotController);
@ -51,20 +38,4 @@ public class PKT8PlotFragment extends FXFragment {
throw new RuntimeException(e);
}
}
@Override
protected void onShow() {
super.onShow();
if (device.isMeasuring()) {
device.getMeasurement().addListener(plotController);
}
}
@Override
protected void onHide() {
super.onHide();
if (device.isMeasuring()) {
device.getMeasurement().removeListener(plotController);
}
}
}

View File

@ -22,7 +22,8 @@ import hep.dataforge.control.connections.StorageConnection;
import hep.dataforge.exceptions.ControlException;
import hep.dataforge.exceptions.PortException;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.fx.ConsoleFragment;
import hep.dataforge.fx.fragments.ConsoleFragment;
import hep.dataforge.fx.fragments.FragmentWindow;
import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.ConfigChangeListener;
import hep.dataforge.meta.Configuration;
@ -124,7 +125,7 @@ public class MspViewController implements Initializable, MspListener {
@Override
public void initialize(URL url, ResourceBundle rb) {
logArea = new ConsoleFragment();
logArea.bindTo(consoleButton);
new FragmentWindow(logArea).bindTo(consoleButton);
fillamentSelector.setItems(FXCollections.observableArrayList(1, 2));
fillamentSelector.setConverter(new StringConverter<Integer>() {
@Override

View File

@ -14,7 +14,8 @@ import hep.dataforge.control.measurements.MeasurementListener;
import hep.dataforge.control.measurements.Sensor;
import hep.dataforge.exceptions.ControlException;
import hep.dataforge.exceptions.MeasurementException;
import hep.dataforge.fx.ConsoleFragment;
import hep.dataforge.fx.fragments.ConsoleFragment;
import hep.dataforge.fx.fragments.FragmentWindow;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.plots.data.TimePlottable;
@ -111,7 +112,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
});
consoleWindow = new ConsoleFragment();
consoleWindow.bindTo(logButton);
new FragmentWindow(consoleWindow).bindTo(logButton);
consoleWindow.hookStd();
}

View File

@ -16,10 +16,11 @@ import hep.dataforge.data.FileDataFactory;
import hep.dataforge.description.ActionDescriptor;
import hep.dataforge.description.DescriptorUtils;
import hep.dataforge.exceptions.NameNotFoundException;
import hep.dataforge.fx.ConsoleFragment;
import hep.dataforge.fx.FXDataOutputPane;
import hep.dataforge.fx.FXReportListener;
import hep.dataforge.fx.configuration.MetaEditor;
import hep.dataforge.fx.fragments.ConsoleFragment;
import hep.dataforge.fx.fragments.FragmentWindow;
import hep.dataforge.fx.work.WorkManagerFragment;
import hep.dataforge.io.IOManager;
import hep.dataforge.io.MetaFileReader;
@ -117,12 +118,12 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
logTab.setContent(logPane.getRoot());
ConsoleFragment consoleWindow = new ConsoleFragment();
consoleWindow.bindTo(consoleButton);
new FragmentWindow(consoleWindow).bindTo(consoleButton);
consoleWindow.addRootLogHandler();
consoleWindow.hookStd();
processWindow = new WorkManagerFragment();
processWindow.bindTo(processButton);
new FragmentWindow(processWindow).bindTo(processButton);
isRunning.addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
runButton.setSelected(newValue);

View File

@ -6,23 +6,15 @@
package inr.numass.scripts
import hep.dataforge.io.MetaStreamReader
import hep.dataforge.io.MetaStreamWriter
import hep.dataforge.io.envelopes.Envelope
import hep.dataforge.io.envelopes.EnvelopeBuilder
import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder
import hep.dataforge.storage.commons.JSONMetaWriter
import hep.dataforge.storage.commons.StorageManager
import java.io.RandomAccessFile;
import java.nio.ByteBuffer
import inr.numass.client.NumassClient
import java.nio.MappedByteBuffer
import java.nio.channels.FileChannel
import hep.dataforge.storage.commons.LoaderFactory
import hep.dataforge.meta.MetaBuilder
import hep.dataforge.storage.commons.StorageManager
import hep.dataforge.tables.MapPoint
import inr.numass.client.NumassClient
new StorageManager().startGlobal();
@ -57,7 +49,7 @@ new NumassClient("127.0.0.1",8335).withCloseable{
.build();
def response = it.sendAndRecieve(bin);
def response = it.respond(bin);
println parser.writeString(response.meta());

View File

@ -8,19 +8,15 @@ package inr.numass.client;
import hep.dataforge.meta.Meta;
import hep.dataforge.storage.commons.StorageManager;
import hep.dataforge.values.Value;
import org.apache.commons.cli.*;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.slf4j.LoggerFactory;
/**
*
* @author Alexander Nozik
*/
public class Cli {
@ -137,8 +133,8 @@ public class Cli {
private static Options buildOptions() {
Options options = new Options();
options.addOption("a", true, "IP address of the server. Default: 192.168.111.1");
options.addOption("p", true, "Server port. Default: 8335");
options.addOption("a", "ip", true, "IP address of the server. Default: 192.168.111.1");
options.addOption("p", "port", true, "Server port. Default: 8335");
return options;
}

View File

@ -15,22 +15,17 @@
*/
package inr.numass.client;
import hep.dataforge.io.envelopes.DefaultEnvelopeReader;
import hep.dataforge.io.envelopes.DefaultEnvelopeWriter;
import hep.dataforge.io.envelopes.Envelope;
import hep.dataforge.io.envelopes.EnvelopeBuilder;
import hep.dataforge.io.envelopes.*;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.storage.commons.MessageFactory;
import hep.dataforge.storage.commons.StorageUtils;
import hep.dataforge.values.Value;
import inr.numass.storage.NumassStorage;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.slf4j.LoggerFactory;
import org.zeroturnaround.zip.ZipUtil;
import java.io.*;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
@ -39,14 +34,11 @@ import java.time.Instant;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.slf4j.LoggerFactory;
import org.zeroturnaround.zip.ZipUtil;
/**
*
* @author darksnake
*/
public class NumassClient extends MessageFactory implements Closeable {
public class NumassClient extends MessageFactory implements AutoCloseable, Responder {
Socket socket;
@ -63,7 +55,8 @@ public class NumassClient extends MessageFactory implements Closeable {
socket.close();
}
public Envelope sendAndRecieve(Envelope message) {
@Override
public Envelope respond(Envelope message) {
try {
write(message, socket.getOutputStream());
return read(socket.getInputStream());
@ -87,17 +80,17 @@ public class NumassClient extends MessageFactory implements Closeable {
}
public Meta getCurrentRun() {
return sendAndRecieve(requestActionBase("numass.run", "get").build()).meta();
return respond(requestActionBase("numass.run", "get").build()).meta();
}
public Meta startRun(String name) {
return sendAndRecieve(requestActionBase("numass.run", "start")
return respond(requestActionBase("numass.run", "start")
.putMetaValue("path", name)
.build()).meta();
}
public Meta resetRun() {
return sendAndRecieve(requestActionBase("numass.run", "reset")
return respond(requestActionBase("numass.run", "reset")
.build()).meta();
}
@ -132,7 +125,7 @@ public class NumassClient extends MessageFactory implements Closeable {
.setData(buffer)
.build();
return sendAndRecieve(bin).meta();
return respond(bin).meta();
} catch (IOException ex) {
return StorageUtils.getErrorMeta(ex);
}
@ -142,7 +135,7 @@ public class NumassClient extends MessageFactory implements Closeable {
* Get state map for given state names from the root state loader. If
* stateNames is empty, return all states.
*
* @param stateName
* @param stateNames
* @return
*/
public Map<String, Value> getStates(String... stateNames) {
@ -152,7 +145,7 @@ public class NumassClient extends MessageFactory implements Closeable {
env.putMetaValue("name", Arrays.asList(stateNames));
}
Meta response = sendAndRecieve(env.build()).meta();
Meta response = respond(env.build()).meta();
if (response.getBoolean("success", true)) {
Map<String, Value> res = new HashMap<>();
response.getNodes("state").stream().forEach((stateMeta) -> {
@ -178,7 +171,7 @@ public class NumassClient extends MessageFactory implements Closeable {
.setValue("value", value)
.build());
return sendAndRecieve(env.build()).meta();
return respond(env.build()).meta();
}
/**
@ -195,7 +188,7 @@ public class NumassClient extends MessageFactory implements Closeable {
.setValue("value", state.getValue())
.build());
});
return sendAndRecieve(env.build()).meta();
return respond(env.build()).meta();
}
public Meta addNote(String text, Instant time) {
@ -204,7 +197,7 @@ public class NumassClient extends MessageFactory implements Closeable {
if (time != null) {
env.putMetaValue("note.time", time);
}
return sendAndRecieve(env.build()).meta();
return respond(env.build()).meta();
}
public Meta getNotes(int limit) {
@ -212,7 +205,7 @@ public class NumassClient extends MessageFactory implements Closeable {
if (limit > 0) {
env.putMetaValue("limit", limit);
}
return sendAndRecieve(env.build()).meta();
return respond(env.build()).meta();
}

View File

@ -0,0 +1,50 @@
package inr.numass.client;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.meta.Meta;
import hep.dataforge.storage.api.Loader;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.commons.AbstractStorage;
import java.io.IOException;
/**
* Created by darksnake on 09-Oct-16.
*/
public class RemoteNumassStorage extends AbstractStorage {
private NumassClient client;
private RemoteNumassStorage(Storage parent, String name, Meta annotation) {
super(parent, name, annotation);
}
public RemoteNumassStorage(String name) {
super(name);
}
private String getIP() {
return meta().getString("numass.server.ip", "192.168.111.1");
}
private int getPort() {
return meta().getInt("numass.server.port", 8335);
}
private NumassClient getClient() throws IOException {
if (client == null) {
client = new NumassClient(getIP(), getPort());
}
return client;
}
@Override
public Loader buildLoader(Meta loaderConfiguration) throws StorageException {
return null;
}
@Override
public Storage buildShelf(String shelfName, Meta shelfConfiguration) throws StorageException {
return new RemoteNumassStorage(this, shelfName, shelfConfiguration);
}
}

View File

@ -19,7 +19,8 @@ import hep.dataforge.computation.ProgressCallback;
import hep.dataforge.context.Context;
import hep.dataforge.context.GlobalContext;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.fx.ConsoleFragment;
import hep.dataforge.fx.fragments.ConsoleFragment;
import hep.dataforge.fx.fragments.FragmentWindow;
import hep.dataforge.fx.work.WorkManagerFragment;
import inr.numass.NumassProperties;
import inr.numass.storage.NumassData;
@ -102,8 +103,8 @@ public class MainViewerController implements Initializable {
public void initialize(URL url, ResourceBundle rb) {
ConsoleFragment consoleFragment = new ConsoleFragment();
consoleFragment.hookStd();
consoleFragment.bindTo(consoleButton);
WorkManagerFragment.attachToContext(GlobalContext.instance()).bindTo(processManagerButton);
new FragmentWindow(consoleFragment).bindTo(consoleButton);
new FragmentWindow(WorkManagerFragment.attachToContext(GlobalContext.instance())).bindTo(processManagerButton);
mspController = new MspViewController(getContext());
this.mspTab.setContent(mspController.getRoot());