private void writeClipMenuItemChildren(TreeItem<Clip> parentTreeItem, Menu parentMenu) { List<TreeItem<Clip>> children = parentTreeItem.getChildren(); for (TreeItem<Clip> child : children) { if (child.getValue().isGroup()) { Menu menu = new Menu(child.getValue().getName()); parentMenu.getItems().add(menu); writeClipMenuItemChildren(child, menu); } else { MenuItem menuItem = new MenuItem(child.getValue().getName()); parentMenu.getItems().add(menuItem); menuItem.setOnAction( event -> { insertClip(child.getValue()); }); } } }
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); }