public void validate(T value) {
   LOG.trace("Validating {}", value);
   if (validator.isValid(value)) {
     validationState.set(ValidationState.VALID);
   } else {
     validationState.set(ValidationState.INVALID);
   }
 }
Esempio n. 2
0
 public void refreshPreview() {
   XHTMLCodeEditor xhtmlCodeEditor = (XHTMLCodeEditor) currentEditor.getValue();
   if (xhtmlCodeEditor != null && currentXHTMLResource.get() != null) {
     try {
       currentXHTMLResource.get().setData(xhtmlCodeEditor.getCode().getBytes("UTF-8"));
     } catch (UnsupportedEncodingException e) {
       // never happens
     }
     needsRefresh.setValue(true);
     needsRefresh.setValue(false);
   }
 }
Esempio n. 3
0
  private RegisterStage(@NotNull final Account account) {
    super(StageStyle.DECORATED);

    accountProperty.setValue(account);

    final String formResource;

    if (account.isLocked()) {
      if (account.memberOf(AccountGroup.INVEST)) {
        formResource = "LockedInvestmentRegisterPane.fxml";
      } else {
        formResource = "LockedBasicRegisterPane.fxml";
      }
    } else {
      if (account.memberOf(AccountGroup.INVEST)) {
        formResource = "InvestmentRegisterPane.fxml";
      } else {
        formResource = "BasicRegisterPane.fxml";
      }
    }

    controller =
        FXMLUtils.loadFXML(
            scene -> setScene(new Scene((Parent) scene)), formResource, ResourceUtils.getBundle());

    getScene().getStylesheets().addAll(MainApplication.DEFAULT_CSS);

    double minWidth = Double.MAX_VALUE;
    double minHeight = Double.MAX_VALUE;

    for (final Screen screen : Screen.getScreens()) {
      minWidth = Math.min(minWidth, screen.getVisualBounds().getWidth());
      minHeight = Math.min(minHeight, screen.getVisualBounds().getHeight());
    }

    setWidth(minWidth * SCALE_FACTOR);
    setHeight(minHeight * SCALE_FACTOR);

    // Push the account to the controller at the end of the application thread
    Platform.runLater(() -> controller.accountProperty().setValue(account));

    updateTitle(account);

    StageUtils.addBoundsListener(this, account.getUuid());

    registerStageListProperty.get().add(this);

    setOnHidden(event -> registerStageListProperty.get().remove(RegisterStage.this));
  }
Esempio n. 4
0
 private void beautifyOrRepairHTML(String mode) {
   logger.info("beautifying html");
   try {
     CodeEditor editor = currentEditor.getValue();
     EditorPosition currentCursorPosition = editor.getEditorCursorPosition();
     String code = editor.getCode();
     if (currentEditorIsXHTML.get()) {
       try {
         Resource resource = currentXHTMLResource.get();
         resource.setData(code.getBytes("UTF-8"));
         switch (mode) {
           case "format":
             code = formatAsXHTML(code);
             break;
           case "repair":
             code = repairXHTML(code);
             break;
         }
         resource.setData(code.getBytes("UTF-8"));
       } catch (UnsupportedEncodingException e) {
         // never happens
       }
     }
     editor.setCode(code);
     editor.setEditorCursorPosition(currentCursorPosition);
     editor.scrollTo(currentCursorPosition);
     book.setBookIsChanged(true);
   } catch (IOException | JDOMException e) {
     logger.error("", e);
     Dialogs.create()
         .owner(tabPane)
         .title("Formatierung nicht möglich")
         .message(
             "Kann Datei nicht formatieren. Bitte die Fehlermeldung an den Hersteller weitergeben.")
         .showException(e);
   }
 }
Esempio n. 5
0
  public boolean splitXHTMLFile() {
    boolean result = false;
    if (currentEditor.getValue().getMediaType().equals(MediaType.XHTML)) {
      XHTMLCodeEditor xhtmlCodeEditor = (XHTMLCodeEditor) currentEditor.getValue();
      EditorPosition pos = xhtmlCodeEditor.getEditorCursorPosition();
      XMLTagPair pair =
          xhtmlCodeEditor.findSurroundingTags(
              token -> {
                String type = token.getType();
                if ("tag".equals(type)) {
                  String content = token.getContent();
                  if ("head".equals(content) || "body".equals(content) || "html".equals(content)) {
                    return true;
                  }
                }
                return false;
              });
      if (pair == null
          || "head".equals(pair.getTagName())
          || "html".equals(pair.getTagName())
          || StringUtils.isEmpty(pair.getTagName())) {
        Dialogs.create()
            .owner(tabPane)
            .title("Teilung nicht möglich")
            .message(
                "Kann Datei nicht an dieser Position teilen. Eine Teilung ist nur innerhalb des XHTML-Bodys möglich.")
            .showWarning();
        return false;
      }
      logger.debug("umgebendes pair " + pair);
      // wir sind innerhalb des Body
      int index = xhtmlCodeEditor.getIndexFromPosition(pos);
      try {
        String originalCode = xhtmlCodeEditor.getCode();
        org.jdom2.Document originalDocument = XHTMLUtils.parseXHTMLDocument(originalCode);
        List<Content> originalHeadContent = getOriginalHeadContent(originalDocument);

        byte[] frontPart = originalCode.substring(0, index).getBytes("UTF-8");
        Resource oldResource = currentXHTMLResource.getValue();
        oldResource.setData(frontPart);
        HtmlCleanerBookProcessor processor = new HtmlCleanerBookProcessor();
        processor.processResource(oldResource);
        xhtmlCodeEditor.setCode(new String(oldResource.getData(), "UTF-8"));

        byte[] backPart =
            originalCode.substring(index, originalCode.length() - 1).getBytes("UTF-8");
        String fileName = book.getNextStandardFileName(MediaType.XHTML);
        Resource resource = MediaType.XHTML.getResourceFactory().createResource("Text/" + fileName);
        byte[] backPartXHTML = XHTMLUtils.repairWithHead(backPart, originalHeadContent);
        resource.setData(backPartXHTML);

        int spineIndex = book.getSpine().getResourceIndex(oldResource);
        book.addSpineResource(resource, spineIndex + 1);
        openFileInEditor(resource, MediaType.XHTML);

        bookBrowserManager.refreshBookBrowser();
        needsRefresh.setValue(true);
        needsRefresh.setValue(false);
      } catch (IOException | JDOMException | ResourceDataException e) {
        logger.error("", e);
        Dialogs.create()
            .owner(tabPane)
            .title("Teilung nicht möglich")
            .message("Kann Datei nicht teilen. Bitte Fehlermeldung an den Hersteller übermitteln.")
            .showException(e);
      }

      result = true;
    }
    return result;
  }
Esempio n. 6
0
 public ReadOnlyObjectProperty<Resource> currentXMLResourceProperty() {
   return currentXMLResource.getReadOnlyProperty();
 }
Esempio n. 7
0
 public Resource getCurrentXMLResource() {
   return currentXMLResource.get();
 }
Esempio n. 8
0
 public ReadOnlyObjectProperty<Resource> currentSearchableResourceProperty() {
   return currentSearchableResource.getReadOnlyProperty();
 }
Esempio n. 9
0
 public Resource getCurrentSearchableResource() {
   return currentSearchableResource.get();
 }
Esempio n. 10
0
  public void openFileInEditor(Resource resource, MediaType mediaType)
      throws IllegalArgumentException {
    if (!isTabAlreadyOpen(resource)) {
      Tab tab = new Tab();
      tab.setClosable(true);
      if (resource == null) {
        Dialogs.create()
            .owner(tabPane)
            .title("Datei nicht vorhanden")
            .message(
                "Die angeforderte Datei ist nicht vorhanden und kann deshalb nicht geöffnet werden.")
            .showError();
        return;
      }
      tab.setText(resource.getFileName());
      resource
          .hrefProperty()
          .addListener(
              (observable, oldValue, newValue) -> {
                tab.setText(resource.getFileName());
              });

      String content = "";
      try {
        content = new String(resource.getData(), resource.getInputEncoding());
      } catch (IOException e) {
        logger.error("", e);
      }

      CodeEditor editor;
      if (mediaType.equals(MediaType.CSS)) {
        editor = new CssCodeEditor();
        editor.setContextMenu(contextMenuCSS);
      } else if (mediaType.equals(MediaType.XHTML)) {
        editor = new XHTMLCodeEditor();
        editor.setContextMenu(contextMenuXHTML);
      } else if (mediaType.equals(MediaType.XML)) {
        editor = new XMLCodeEditor();
        editor.setContextMenu(contextMenuXML);
      } else {
        throw new IllegalArgumentException("no editor for mediatype " + mediaType.getName());
      }

      tab.setContent((Node) editor);
      tab.setUserData(resource);
      tabPane.getTabs().add(tab);
      tabPane.getSelectionModel().select(tab);

      final String code = content;
      editor
          .stateProperty()
          .addListener(
              new ChangeListener<Worker.State>() {
                @Override
                public void changed(
                    ObservableValue<? extends Worker.State> observable,
                    Worker.State oldValue,
                    Worker.State newValue) {
                  if (newValue.equals(Worker.State.SUCCEEDED)) {
                    openingEditorTab = true;
                    editor.setCode(code);
                    editor.setCodeEditorSize(
                        ((AnchorPane) editor).getWidth() - 20,
                        ((AnchorPane) editor).getHeight() - 20);
                    ((AnchorPane) editor)
                        .widthProperty()
                        .addListener(
                            new ChangeListener<Number>() {
                              @Override
                              public void changed(
                                  ObservableValue<? extends Number> observable,
                                  Number oldValue,
                                  Number newValue) {
                                editor.setCodeEditorSize(
                                    newValue.doubleValue() - 20,
                                    ((AnchorPane) editor).getHeight() - 20);
                              }
                            });
                    ((AnchorPane) editor)
                        .heightProperty()
                        .addListener(
                            new ChangeListener<Number>() {
                              @Override
                              public void changed(
                                  ObservableValue<? extends Number> observable,
                                  Number oldValue,
                                  Number newValue) {
                                editor.setCodeEditorSize(
                                    ((AnchorPane) editor).getWidth() - 20,
                                    newValue.doubleValue() - 20);
                              }
                            });
                    editor.setCodeEditorSize(
                        ((AnchorPane) editor).getWidth() - 20,
                        ((AnchorPane) editor).getHeight() - 20);
                    ((AnchorPane) editor)
                        .widthProperty()
                        .addListener(
                            new ChangeListener<Number>() {
                              @Override
                              public void changed(
                                  ObservableValue<? extends Number> observable,
                                  Number oldValue,
                                  Number newValue) {
                                editor.setCodeEditorSize(
                                    newValue.doubleValue() - 20,
                                    ((AnchorPane) editor).getHeight() - 20);
                              }
                            });
                    ((AnchorPane) editor)
                        .heightProperty()
                        .addListener(
                            new ChangeListener<Number>() {
                              @Override
                              public void changed(
                                  ObservableValue<? extends Number> observable,
                                  Number oldValue,
                                  Number newValue) {
                                editor.setCodeEditorSize(
                                    ((AnchorPane) editor).getWidth() - 20,
                                    newValue.doubleValue() - 20);
                              }
                            });
                    openingEditorTab = false;
                  }
                }
              });

      editor
          .cursorPositionProperty()
          .addListener(
              (observable, oldValue, newValue) -> {
                cursorPosLabelProperty.set(newValue.getLine() + ":" + newValue.getColumn());
              });

      editor
          .codeProperty()
          .addListener(
              (observable1, oldValue, newValue) -> {
                if (openingEditorTab) {
                  return;
                }
                if (currentEditor.getValue().getMediaType().equals(MediaType.XHTML)) {
                  try {
                    currentXHTMLResource.get().setData(newValue.getBytes("UTF-8"));
                  } catch (UnsupportedEncodingException e) {
                    // never happens
                  }
                } else if (currentEditor.getValue().getMediaType().equals(MediaType.CSS)) {
                  try {
                    currentCssResource.get().setData(newValue.getBytes("UTF-8"));
                  } catch (UnsupportedEncodingException e) {
                    // never happens
                  }
                } else if (currentEditor.getValue().getMediaType().equals(MediaType.XML)) {
                  try {
                    currentXMLResource.get().setData(newValue.getBytes("UTF-8"));
                    if (((XMLResource) resource).isValidXML()
                        && MediaType.OPF.equals(resource.getMediaType())) {
                      PackageDocumentReader.read(resource, book);
                    }
                  } catch (JDOMException | IOException e) {
                    logger.error("", e);
                  }
                }

                if (scheduledService.getState().equals(Worker.State.READY)) {
                  scheduledService.start();
                } else {
                  scheduledService.restart();
                }
                book.setBookIsChanged(true);
              });
    }
  }
Esempio n. 11
0
  public void init() {
    currentEditor.addListener(
        (observable, oldValue, newValue) -> {
          canUndo.unbind();
          canRedo.unbind();
          if (newValue != null) {
            currentEditorIsXHTML.setValue(
                currentEditor.getValue().getMediaType().equals(MediaType.XHTML));
            canUndo.bind(currentEditor.getValue().canUndoProperty());
            canRedo.bind(currentEditor.getValue().canRedoProperty());
          } else {
            currentEditorIsXHTML.setValue(false);
            canUndo.setValue(false);
            canRedo.setValue(false);
          }
        });

    MenuItem separatorItem = new SeparatorMenuItem();
    // Html menu
    contextMenuXHTML = new ContextMenu();
    contextMenuXHTML.setAutoFix(true);
    contextMenuXHTML.setAutoHide(true);

    Menu clipsItem = new Menu("Clips");
    clipManager
        .getClipsRoot()
        .addEventHandler(
            TreeItem.<Clip>childrenModificationEvent(),
            event -> {
              clipsItem.getItems().clear();
              writeClipMenuItemChildren(clipManager.getClipsRoot(), clipsItem);
            });
    contextMenuXHTML.getItems().add(clipsItem);
    contextMenuXHTML.getItems().add(separatorItem);

    MenuItem itemRepairHTML = new MenuItem("HTML reparieren");
    itemRepairHTML.setOnAction(
        e -> {
          beautifyOrRepairHTML("repair");
        });
    contextMenuXHTML.getItems().add(itemRepairHTML);

    MenuItem itemBeautifyHTML = new MenuItem("HTML formatieren");
    itemBeautifyHTML.setOnAction(
        e -> {
          beautifyOrRepairHTML("format");
        });
    contextMenuXHTML.getItems().add(itemBeautifyHTML);

    contextMenuXHTML.getItems().add(separatorItem);

    MenuItem openInExternalBrowserItem = new MenuItem("In externem Browser öffnen");
    openInExternalBrowserItem.setOnAction(
        e -> {
          openInExternalBrowser(currentEditor);
        });
    contextMenuXHTML.getItems().add(openInExternalBrowserItem);

    // XML menu
    contextMenuXML = new ContextMenu();
    contextMenuXML.setAutoFix(true);
    contextMenuXML.setAutoHide(true);

    MenuItem generateUuidMenuItem = new MenuItem("Neue UUID generieren");
    generateUuidMenuItem.setOnAction(
        e -> {
          book.getMetadata().generateNewUuid();
          bookBrowserManager.refreshOpf();
        });
    contextMenuXML.getItems().add(generateUuidMenuItem);
    currentXMLResource.addListener(
        new ChangeListener<Resource>() {
          @Override
          public void changed(
              ObservableValue<? extends Resource> observable,
              Resource oldValue,
              Resource newValue) {
            if (newValue != null
                && currentXMLResource.get().mediaTypeProperty().getValue().equals(MediaType.OPF)) {
              generateUuidMenuItem.visibleProperty().setValue(true);
            } else {
              generateUuidMenuItem.visibleProperty().setValue(false);
            }
          }
        });

    MenuItem separatorItem2 = new SeparatorMenuItem();
    contextMenuXML.getItems().add(separatorItem2);
    separatorItem2.visibleProperty().bind(generateUuidMenuItem.visibleProperty());

    MenuItem itemRepairXML = new MenuItem("XML reparieren");
    itemRepairXML.setOnAction(
        e -> {
          beautifyOrRepairXML("repair");
        });
    contextMenuXML.getItems().add(itemRepairXML);

    MenuItem itemBeautifyXML = new MenuItem("XML formatieren");
    itemBeautifyXML.setOnAction(
        e -> {
          beautifyOrRepairXML("format");
        });
    contextMenuXML.getItems().add(itemBeautifyXML);

    // css menu
    contextMenuCSS = new ContextMenu();
    contextMenuCSS.setAutoFix(true);
    contextMenuCSS.setAutoHide(true);
    MenuItem formatCSSOneLineItem = new MenuItem("Styles in je einer Zeile formatieren");
    formatCSSOneLineItem.setOnAction(e -> beautifyCSS("one_line"));
    contextMenuCSS.getItems().add(formatCSSOneLineItem);

    MenuItem formatCSSMultipleLinesItem = new MenuItem("Styles in mehreren Zeilen formatieren");
    formatCSSMultipleLinesItem.setOnAction(e -> beautifyCSS("multiple_lines"));
    contextMenuCSS.getItems().add(formatCSSMultipleLinesItem);
  }
Esempio n. 12
0
 public final TableRow getTableRow() {
   return tableRow.get();
 }
Esempio n. 13
0
 private void setTableRow(TableRow value) {
   tableRow.set(value);
 }
 public final ReadOnlyObjectProperty<ValidationState> validationStateProperty() {
   return validationState.getReadOnlyProperty();
 }
 public void makeNotValidated() {
   LOG.trace("Making state {}", ValidationState.NOT_VALIDATED);
   validationState.set(ValidationState.NOT_VALIDATED);
 }
Esempio n. 16
0
 public ReadOnlyObjectProperty<Account> accountProperty() {
   return accountProperty.getReadOnlyProperty();
 }