2727import com .github .mfl28 .boundingboxeditor .model .io .results .*;
2828import com .github .mfl28 .boundingboxeditor .model .io .services .*;
2929import com .github .mfl28 .boundingboxeditor .ui .*;
30+ import com .github .mfl28 .boundingboxeditor .ui .settings .InferenceSettingsView ;
3031import com .github .mfl28 .boundingboxeditor .ui .settings .SettingsDialogView ;
3132import com .github .mfl28 .boundingboxeditor .ui .statusevents .BoundingBoxPredictionSuccessfulEvent ;
3233import com .github .mfl28 .boundingboxeditor .ui .statusevents .ImageAnnotationsImportingSuccessfulEvent ;
4142import javafx .beans .value .ObservableValue ;
4243import javafx .collections .ListChangeListener ;
4344import javafx .concurrent .WorkerStateEvent ;
45+ import javafx .event .ActionEvent ;
4446import javafx .scene .Cursor ;
4547import javafx .scene .control .ButtonBar ;
4648import javafx .scene .control .ButtonType ;
@@ -180,14 +182,33 @@ public Controller(final Stage mainStage) {
180182 public void onRegisterSettingsAction () {
181183 final SettingsDialogView settingsDialog = view .getSettingsDialog ();
182184 settingsDialog .getInferenceSettings ()
183- .setDisplayedSettingsFromConfig (model .getBoundingBoxPredictorClientConfig ());
184- // TODO: update predictor config
185+ .setDisplayedSettingsFromPredictorClientConfig (model .getBoundingBoxPredictorClientConfig ());
186+ settingsDialog .getInferenceSettings ()
187+ .setDisplayedSettingsFromPredictorConfig (model .getBoundingBoxPredictorConfig ());
188+
185189 settingsDialog .showAndWait ();
186190 }
187191
188- public void onRegisterSettingsApplyAction () {
192+ public void onRegisterSettingsApplyAction (ActionEvent event , ButtonType buttonType ) {
193+ final InferenceSettingsView inferenceSettingsView = view .getSettingsDialog ().getInferenceSettings ();
194+
195+ if (buttonType .equals (ButtonType .OK )) {
196+ if (inferenceSettingsView .getInferenceEnabledControl ().isSelected () &&
197+ inferenceSettingsView .getSelectedModelLabel ().getText ().equals ("None" )) {
198+ MainView .displayErrorAlert ("Settings Application Error" , "Please select a model or disable inference." );
199+ event .consume ();
200+ return ;
201+ }
202+ }
203+
189204 view .getSettingsDialog ().getInferenceSettings ()
190- .applyDisplayedSettingsToConfig (model .getBoundingBoxPredictorClientConfig ());
205+ .applyDisplayedSettingsToPredictorClientConfig (model .getBoundingBoxPredictorClientConfig ());
206+ view .getSettingsDialog ().getInferenceSettings ()
207+ .applyDisplayedSettingsToPredictorConfig (model .getBoundingBoxPredictorConfig ());
208+
209+ if (buttonType .equals (ButtonType .APPLY )) {
210+ event .consume ();
211+ }
191212 }
192213
193214 /**
@@ -206,8 +227,6 @@ public void onRegisterOpenImageFolderAction() {
206227 public void onRegisterPerformCurrentImageBoundingBoxPredictionAction () {
207228 if (model .containsImageFiles ()) {
208229 initiateBoundingBoxPrediction (model .getCurrentImageFile ());
209- } else {
210- // TODO: Error handling
211230 }
212231 }
213232
@@ -286,7 +305,7 @@ public void onRegisterImportAnnotationsAction(ImageAnnotationLoadStrategy.Type l
286305 public void onRegisterModelNameFetchingAction () {
287306 modelNameFetchService .reset ();
288307 final BoundingBoxPredictorClientConfig clientConfig = new BoundingBoxPredictorClientConfig ();
289- view .getSettingsDialog ().getInferenceSettings ().applyDisplayedSettingsToConfig (clientConfig );
308+ view .getSettingsDialog ().getInferenceSettings ().applyDisplayedSettingsToPredictorClientConfig (clientConfig );
290309 modelNameFetchService .setClientConfig (clientConfig );
291310 modelNameFetchService .restart ();
292311 }
@@ -585,6 +604,13 @@ public Model getModel() {
585604 return model ;
586605 }
587606
607+ public void onRegisterSettingsCancelCloseAction () {
608+ view .getSettingsDialog ().getInferenceSettings ()
609+ .setDisplayedSettingsFromPredictorClientConfig (model .getBoundingBoxPredictorClientConfig ());
610+ view .getSettingsDialog ().getInferenceSettings ()
611+ .setDisplayedSettingsFromPredictorConfig (model .getBoundingBoxPredictorConfig ());
612+ }
613+
588614 IoMetaData getIoMetaData () {
589615 return ioMetaData ;
590616 }
@@ -633,7 +659,8 @@ private void onBoundingBoxPredictionSucceeded(WorkerStateEvent event) {
633659 final BoundingBoxPredictionResult predictionResult = boundingBoxPredictorService .getValue ();
634660
635661 if (predictionResult .getNrSuccessfullyProcessedItems () != 0 ) {
636- model .updateFromImageAnnotationData (predictionResult .getImageAnnotationData ());
662+ model .updateFromImageAnnotationData (predictionResult .getImageAnnotationData (),
663+ predictionResult .getOperationType ());
637664 view .getStatusBar ().setStatusEvent (new BoundingBoxPredictionSuccessfulEvent (predictionResult ));
638665 }
639666
@@ -651,8 +678,10 @@ private void onBoundingBoxPredictionSucceeded(WorkerStateEvent event) {
651678 }
652679
653680 if (!predictionResult .getErrorTableEntries ().isEmpty ()) {
681+ UiUtils .closeProgressDialog (view .getBoundingBoxPredictorProgressDialog ());
654682 MainView .displayIOResultErrorInfoAlert (predictionResult );
655683 } else if (predictionResult .getNrSuccessfullyProcessedItems () == 0 ) {
684+ UiUtils .closeProgressDialog (view .getBoundingBoxPredictorProgressDialog ());
656685 MainView .displayErrorAlert ("Bounding Box Prediction Error" ,
657686 "Could not predict any bounding boxes." );
658687 }
@@ -724,7 +753,7 @@ private void onModelNameFetchingSucceeded(WorkerStateEvent workerStateEvent) {
724753 .ifPresent (s -> view .getSettingsDialog ().getInferenceSettings ().getSelectedModelLabel ().setText (s ));
725754
726755 } else {
727- MainView .displayErrorAlert ( "Model Name Fetching Error" , "The server did not report any models." );
756+ MainView .displayIOResultErrorInfoAlert ( result );
728757 }
729758 }
730759
@@ -825,11 +854,11 @@ private void onValidFilesPresentHandler(boolean keepCategories) {
825854 }
826855
827856 private void onAnnotationImportSucceeded (WorkerStateEvent workerStateEvent ) {
828- ImageAnnotationImportResult loadResult = annotationImportService .getValue ();
857+ ImageAnnotationImportResult importResult = annotationImportService .getValue ();
829858
830- if (loadResult .getNrSuccessfullyProcessedItems () != 0 ) {
831- model .updateFromImageAnnotationData (loadResult .getImageAnnotationData ());
832- view .getStatusBar ().setStatusEvent (new ImageAnnotationsImportingSuccessfulEvent (loadResult ));
859+ if (importResult .getNrSuccessfullyProcessedItems () != 0 ) {
860+ model .updateFromImageAnnotationData (importResult .getImageAnnotationData (), importResult . getOperationType ());
861+ view .getStatusBar ().setStatusEvent (new ImageAnnotationsImportingSuccessfulEvent (importResult ));
833862 }
834863
835864 updateViewFileExplorerFileInfoElements ();
@@ -845,10 +874,10 @@ private void onAnnotationImportSucceeded(WorkerStateEvent workerStateEvent) {
845874 view .getObjectTree ().refresh ();
846875 }
847876
848- if (!loadResult .getErrorTableEntries ().isEmpty ()) {
877+ if (!importResult .getErrorTableEntries ().isEmpty ()) {
849878 UiUtils .closeProgressDialog (view .getAnnotationImportProgressDialog ());
850- MainView .displayIOResultErrorInfoAlert (loadResult );
851- } else if (loadResult .getNrSuccessfullyProcessedItems () == 0 ) {
879+ MainView .displayIOResultErrorInfoAlert (importResult );
880+ } else if (importResult .getNrSuccessfullyProcessedItems () == 0 ) {
852881 UiUtils .closeProgressDialog (view .getAnnotationImportProgressDialog ());
853882 MainView .displayErrorAlert (ANNOTATION_IMPORT_ERROR_TITLE ,
854883 ANNOTATION_IMPORT_ERROR_NO_VALID_FILES_CONTENT );
@@ -1106,6 +1135,9 @@ private void setUpModelListeners() {
11061135 });
11071136
11081137 view .getStatusBar ().savedStatusProperty ().bind (model .savedProperty ());
1138+
1139+ view .getEditor ().getEditorToolBar ().getPredictButton ()
1140+ .visibleProperty ().bind (model .getBoundingBoxPredictorConfig ().inferenceEnabledProperty ());
11091141 }
11101142
11111143 private List <File > getImageFilesFromDirectory (File directory ) throws IOException {
0 commit comments