JavaFXContentEditorPresentationDelegate.java

  1. /*
  2.  * #%L
  3.  * *********************************************************************************************************************
  4.  *
  5.  * NorthernWind - lightweight CMS
  6.  * http://northernwind.tidalwave.it - git clone git@bitbucket.org:tidalwave/northernwind-rca-src.git
  7.  * %%
  8.  * Copyright (C) 2013 - 2021 Tidalwave s.a.s. (http://tidalwave.it)
  9.  * %%
  10.  * *********************************************************************************************************************
  11.  *
  12.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  13.  * the License. You may obtain a copy of the License at
  14.  *
  15.  *     http://www.apache.org/licenses/LICENSE-2.0
  16.  *
  17.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  18.  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
  19.  * specific language governing permissions and limitations under the License.
  20.  *
  21.  * *********************************************************************************************************************
  22.  *
  23.  *
  24.  * *********************************************************************************************************************
  25.  * #L%
  26.  */
  27. package it.tidalwave.northernwind.rca.ui.impl.javafx.contenteditor;

  28. import javax.annotation.Nonnull;
  29. import javafx.collections.FXCollections;
  30. import javafx.fxml.FXML;
  31. import javafx.event.EventHandler;
  32. import javafx.scene.control.Button;
  33. import javafx.scene.control.TableView;
  34. import javafx.scene.control.TextField;
  35. import javafx.scene.web.WebEvent;
  36. import javafx.scene.web.WebView;
  37. import javafx.scene.layout.Pane;
  38. import it.tidalwave.role.ui.PresentationModel;
  39. import it.tidalwave.role.ui.javafx.JavaFXBinder;
  40. import it.tidalwave.northernwind.rca.ui.contenteditor.ContentEditorPresentation;
  41. import lombok.RequiredArgsConstructor;
  42. import lombok.extern.slf4j.Slf4j;

  43. /***********************************************************************************************************************
  44.  *
  45.  * @author Fabrizio Giudici
  46.  *
  47.  **********************************************************************************************************************/
  48. @RequiredArgsConstructor @Slf4j
  49. public class JavaFXContentEditorPresentationDelegate implements ContentEditorPresentation
  50.   {
  51.     @Nonnull
  52.     private final JavaFXBinder binder;

  53.     @FXML
  54.     private Pane contentEditor;

  55.     @FXML
  56.     private WebView contentWebView;

  57.     @FXML
  58.     private TableView<PresentationModel> contentEditorProperties;

  59.     @FXML
  60.     private TextField contentTitle;

  61.     @FXML
  62.     private Button btOpenExternalEditor;

  63.     @FXML
  64.     private Button btOpenExternalEditorBrowser;

  65.     private final EventHandler<WebEvent<String>> clickHijacker = event -> log.debug("hijacked click: {}", event);

  66.     public void initialize()
  67.       {
  68.         contentWebView.getEngine().setOnAlert(clickHijacker);
  69.       }

  70.     @Override
  71.     public void bind (final @Nonnull Bindings bindings)
  72.       {
  73.         binder.bindBidirectionally(contentTitle.textProperty(), bindings.title);
  74.         binder.bind(btOpenExternalEditor, bindings.openExternalEditorAction);
  75.         binder.bind(btOpenExternalEditorBrowser, bindings.openExternalEditorBrowserAction);
  76.       }

  77.     @Override
  78.     public void showUp()
  79.       {
  80.         // never used
  81.       }

  82.     @Override
  83.     public void clear()
  84.       {
  85.         contentWebView.getEngine().loadContent("");
  86.         // FIXME: binder.unbind(contentEditorProperties)
  87.         contentEditorProperties.setItems(FXCollections.<PresentationModel>emptyObservableList());
  88.       }

  89.     @Override
  90.     public void populateDocument (final @Nonnull String url)
  91.       {
  92.         contentWebView.getEngine().load(url);
  93.       }

  94.     @Override
  95.     public void populateProperties (final @Nonnull PresentationModel pm)
  96.       {
  97.         binder.bind(contentEditorProperties, pm);
  98.       }
  99.   }