Skip to content
Snippets Groups Projects
Commit 6b39bfd7 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

code: refactoring and clean up

parent 1af0f261
No related branches found
No related tags found
No related merge requests found
package cz.it4i.fiji.haas_spim_benchmark.core;
package cz.it4i.fiji.commons;
import java.io.Closeable;
import java.lang.Thread.UncaughtExceptionHandler;
......
......@@ -22,11 +22,11 @@ import org.scijava.widget.TextWidget;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.it4i.fiji.commons.UncaughtExceptionHandlerDecorator;
import cz.it4i.fiji.haas_spim_benchmark.core.AuthFailExceptionHandler;
import cz.it4i.fiji.haas_spim_benchmark.core.AuthenticationExceptionHandler;
import cz.it4i.fiji.haas_spim_benchmark.core.Constants;
import cz.it4i.fiji.haas_spim_benchmark.core.NotConnectedExceptionHandler;
import cz.it4i.fiji.haas_spim_benchmark.core.UncaughtExceptionHandlerDecorator;
import cz.it4i.fiji.haas_spim_benchmark.core.WindowCloseableAdapter;
import cz.it4i.fiji.haas_spim_benchmark.ui.BenchmarkSPIMWindow;
......@@ -64,10 +64,12 @@ public class ManageSPIMBenchmark implements Command {
@Override
public void run() {
if (log.isDebugEnabled()) {
log.debug("DefaultUncaughtExceptionHandler() = {} ", Thread.getDefaultUncaughtExceptionHandler());
log.debug("DefaultUncaughtExceptionHandler() = {} ", Thread
.getDefaultUncaughtExceptionHandler());
}
final UncaughtExceptionHandlerDecorator uehd = UncaughtExceptionHandlerDecorator.setDefaultHandler();
final UncaughtExceptionHandlerDecorator uehd =
UncaughtExceptionHandlerDecorator.setDefaultHandler();
final WindowCloseableAdapter wca = new WindowCloseableAdapter();
uehd.registerHandler(new AuthenticationExceptionHandler(wca));
uehd.registerHandler(new NotConnectedExceptionHandler(wca));
......@@ -88,7 +90,9 @@ public class ManageSPIMBenchmark implements Command {
final BenchmarkSPIMWindow dialog = new BenchmarkSPIMWindow(null,
new BenchmarkSPIMParametersImpl(userName, password, Constants.PHONE,
email, workingDirPath)) {
email, workingDirPath))
{
@Override
public void dispose() {
super.dispose();
......
package cz.it4i.fiji.haas_spim_benchmark.ui;
import java.awt.Window;
......@@ -12,6 +13,7 @@ import javax.swing.WindowConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cz.it4i.fiji.commons.UncaughtExceptionHandlerDecorator;
import cz.it4i.fiji.haas.ui.CloseableControl;
import cz.it4i.fiji.haas.ui.InitiableControl;
import cz.it4i.fiji.haas.ui.JavaFXRoutines;
......@@ -20,7 +22,6 @@ import cz.it4i.fiji.haas.ui.ProgressDialog;
import cz.it4i.fiji.haas_spim_benchmark.core.AuthFailExceptionHandler;
import cz.it4i.fiji.haas_spim_benchmark.core.FXFrameExecutorService;
import cz.it4i.fiji.haas_spim_benchmark.core.TaskComputation;
import cz.it4i.fiji.haas_spim_benchmark.core.UncaughtExceptionHandlerDecorator;
import cz.it4i.fiji.haas_spim_benchmark.core.WindowCloseableAdapter;
import cz.it4i.fiji.haas_spim_benchmark.ui.TaskComputationAdapter.ObservableLog;
import javafx.fxml.FXML;
......@@ -29,8 +30,13 @@ import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
public class TaskComputationControl extends TabPane implements CloseableControl, InitiableControl {
public final static Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.TaskComputationControl.class);
public class TaskComputationControl extends TabPane implements CloseableControl,
InitiableControl
{
public final static Logger log = LoggerFactory.getLogger(
cz.it4i.fiji.haas_spim_benchmark.ui.TaskComputationControl.class);
private TaskComputationAdapter adapter;
......@@ -44,33 +50,33 @@ public class TaskComputationControl extends TabPane implements CloseableControl,
private Window rootWindow;
public TaskComputationControl(TaskComputation computation) {
public TaskComputationControl(final TaskComputation computation) {
JavaFXRoutines.initRootAndController("TaskComputationView.fxml", this);
this.computation = computation;
}
@Override
public void init(Window parameter) {
public void init(final Window parameter) {
this.rootWindow = parameter;
wsExecutorService = Executors.newSingleThreadExecutor(
UncaughtExceptionHandlerDecorator.createThreadFactory(
new AuthFailExceptionHandler(new WindowCloseableAdapter(rootWindow))));
wsExecutorService.execute(() -> {
ProgressDialog dialog = ModalDialogs.doModal(new ProgressDialog(parameter, "Updating infos..."),
WindowConstants.DO_NOTHING_ON_CLOSE);
final ProgressDialog dialog = ModalDialogs.doModal(new ProgressDialog(
parameter, "Updating infos..."), WindowConstants.DO_NOTHING_ON_CLOSE);
try {
adapter = new TaskComputationAdapter(computation);
adapter.init();
} finally {
}
finally {
dialog.done();
}
remoteFilesInfo.setFiles(adapter.getOutputs());
remoteFilesInfo.init(parameter);
Collection<Runnable> runs = new LinkedList<>();
for (ObservableLog observableLog : adapter.getLogs()) {
LogViewControl logViewControl = new LogViewControl();
final Collection<Runnable> runs = new LinkedList<>();
for (final ObservableLog observableLog : adapter.getLogs()) {
final LogViewControl logViewControl = new LogViewControl();
logViewControl.setObservable(observableLog.getContent());
runs.add(() -> addTab(observableLog.getName(), logViewControl));
}
......@@ -78,20 +84,20 @@ public class TaskComputationControl extends TabPane implements CloseableControl,
});
}
private void addTab(String title, Node control) {
Tab t = new Tab(title);
private void addTab(final String title, final Node control) {
final Tab t = new Tab(title);
t.setClosable(false);
HBox hbox = new HBox();
final HBox hbox = new HBox();
HBox.setHgrow(control, Priority.ALWAYS);
hbox.getChildren().add(control);
t.setContent(hbox);
getTabs().add(t);
}
@Override
public void close() {
adapter.close();
wsExecutorService.shutdown();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment