public static synchronized ExceptionHandler getDefaultInstance() { if (defaultInstance == null) { defaultInstance = new ExceptionHandler(); setExceptionLogging(DataFXConfiguration.getInstance().isExceptionLoggingActive()); } return defaultInstance; }
public static synchronized DataFXConfiguration getInstance() { if(instance == null) { instance = new DataFXConfiguration(); } return instance; } }
public Document getConfigurationDocument() { if(configurationDocument == null) { configurationDocument = readDataFXConfiguration(); } return configurationDocument; }
private static void onUncaughtException(Thread thread, Throwable throwable) { if (!ExceptionHandler.isLogException()) { LOGGER.log(Level.SEVERE, "Uncaught throwable in " + thread.getName(), throwable); } ExceptionHandler.getDefaultInstance().setException(throwable); }
/** * default constructor */ private EventSystem() { consumers = FXCollections.observableHashMap(); asyncConsumers = FXCollections.observableHashMap(); exceptionHandler = ExceptionHandler.getDefaultInstance(); executor = ObservableExecutor.getDefaultInstance(); }
private void handleActionWithExceptionHandler(String id) { try { handle(id); } catch (VetoException | FlowException e) { getExceptionHandler().setException(e); } }
public FlowHandler(Flow flow, ViewFlowContext flowContext, ViewConfiguration viewConfiguration) { this(flow, flowContext, viewConfiguration, ExceptionHandler.getDefaultInstance()); }
public static void setExceptionLogging(boolean log) { if (log) { getDefaultInstance().exceptionProperty().addListener(getLoggerListener()); } else { getDefaultInstance().exceptionProperty().removeListener(getLoggerListener()); } logException = log; }
public void setException(Throwable exception) { if(Platform.isFxApplicationThread()) { exceptionProperty().set(exception); } else { try { ConcurrentUtils.runAndWait(() -> exceptionProperty().set(exception)); } catch (InterruptedException | ExecutionException e) { LOGGER.log(Level.SEVERE, "Can't handle exception in JavaFX Application Thread!", e); LOGGER.log(Level.SEVERE, "Initial exception: ", exception); } } }
@Override public boolean offer(Runnable runnable) { if (defaultExecutor.getPoolSize() < DataFXConfiguration.getInstance().getDefaultThreadMaxSize()) { return false; } return super.offer(runnable); } };
public Throwable getException() { return exceptionProperty().get(); }
public List<Element> getElements(String tagName) { NodeList nodes = getConfigurationDocument().getElementsByTagName(tagName); List<Element> ret = new ArrayList<>(); for (int temp = 0; temp < nodes.getLength(); temp++) { Node node = nodes.item(temp); ret.add((Element) node); } return ret; }
/** * Execute the given service at some time in the future. * * @param <T> The return type for the service * @param service the service. * @return a worker that can be used to check the state of the service and * receive the result of it. */ public <T> Worker<T> submit(Service<T> service) { service.setExecutor(executor); currentServices.add(service); if(exceptionHandler != null) { exceptionHandler.observeWorker(service); } service.start(); return service; }
private void handleBackActionWithExceptionHandler() { try { navigateBack(); } catch (VetoException | FlowException e) { getExceptionHandler().setException(e); } } }
public ObservableExecutor(Executor executor) { this(executor, ExceptionHandler.getDefaultInstance()); }
public <T> void observeWorker(Worker<T> worker) { worker.exceptionProperty().addListener((ob, ol, e) -> setException(e)); }
/** * This methods creates a tab that contains the given view. * By doing so the metadata of the view will be bound to the tab properties. * So the text and icon of the tab can be changed by the view. * * @param context the context of the view. This includes the view and its controller instance * so that all needed informations are part of the context */ public <T> Tab createTab(ViewContext<T> context) { return createTab(context, ExceptionHandler.getDefaultInstance()); }
public void attachLinkEventHandler(MenuItem menuItem, Class<?> controllerClass) { handler.attachAction(menuItem, () -> { try { navigate(controllerClass); } catch (Exception e) { getExceptionHandler().setException(e); } }); }
public static <T> List<TableColumn<T, ?>> createColumns(Class<T> entityType) { return createColumns(entityType, ExceptionHandler.getDefaultInstance()); }
public void attachLinkEventHandler(Node node, Class<?> controllerClass) { handler.attachAction(node, () -> { try { navigate(controllerClass); } catch (Exception e) { getExceptionHandler().setException(e); } }); }