use of blue.library.LibraryTreeItem in project blue by kunstmusik.
the class UserSoundObjectLibrary method buildContextMenu.
public ContextMenu buildContextMenu(TreeView<LibraryItem<SoundObject>> treeView) {
ContextMenu popupMenu = new ContextMenu();
// popupMenu.getItems().add(new MenuItem("Test"));
ObservableList<TreeItem<LibraryItem<SoundObject>>> selectedItems = treeView.getSelectionModel().getSelectedItems();
final ScoreController.ScoreObjectBuffer scoreObjectBuffer = ScoreController.getInstance().getScoreObjectBuffer();
// FOLDER MENU ITEMS
List<MenuItem> folderMenuItems = new ArrayList<>();
MenuItem addFolder = new MenuItem("Add Folder");
addFolder.setOnAction(evt -> {
TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
item.getChildren().add(new LibraryTreeItem(new LibraryItem<>("New Folder")));
});
MenuItem deleteFolder = new MenuItem("Delete Folder");
deleteFolder.setOnAction(evt -> {
TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
item.getParent().getChildren().remove(item);
});
MenuItem paste = new MenuItem("Paste SoundObject");
paste.setOnAction(evt -> {
TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
SoundObject sObj = (SoundObject) scoreObjectBuffer.scoreObjects.get(0).deepCopy();
if (!SoundObjectUtilities.isOrContainsInstance(sObj)) {
item.getChildren().add(new LibraryTreeItem(new LibraryItem<>(sObj)));
}
});
folderMenuItems.add(addFolder);
folderMenuItems.add(deleteFolder);
folderMenuItems.add(paste);
// FOLDER MENU ITEMS
List<MenuItem> sObjMenuItems = new ArrayList<>();
MenuItem cut = new MenuItem("Cut");
cut.setOnAction(evt -> {
TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
SoundObject sObj = item.getValue().getValue();
if (sObj == null) {
return;
}
scoreObjectBuffer.clear();
scoreObjectBuffer.scoreObjects.add(sObj.deepCopy());
scoreObjectBuffer.layerIndexes.add(0);
item.getParent().getChildren().remove(item);
});
MenuItem copy = new MenuItem("Copy");
copy.setOnAction(evt -> {
TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
SoundObject sObj = item.getValue().getValue();
if (sObj == null) {
return;
}
scoreObjectBuffer.clear();
scoreObjectBuffer.scoreObjects.add(sObj.deepCopy());
scoreObjectBuffer.layerIndexes.add(0);
});
MenuItem delete = new MenuItem("Delete");
delete.setOnAction(evt -> {
TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
item.getParent().getChildren().remove(item);
});
sObjMenuItems.add(cut);
sObjMenuItems.add(copy);
sObjMenuItems.add(new SeparatorMenuItem());
sObjMenuItems.add(delete);
popupMenu.getItems().addAll(folderMenuItems);
popupMenu.getItems().addAll(sObjMenuItems);
popupMenu.setOnShowing(evt -> {
if (selectedItems.size() == 1) {
TreeItem<LibraryItem<SoundObject>> item = selectedItems.get(0);
boolean isFolder = item.getValue().getValue() == null;
deleteFolder.setDisable(item == soundObjectLibrary.getRoot());
if (isFolder) {
boolean isScoreObj = scoreObjectBuffer.scoreObjects.size() == 1 && scoreObjectBuffer.scoreObjects.get(0) instanceof SoundObject;
if (isScoreObj) {
SoundObject sObj = (SoundObject) scoreObjectBuffer.scoreObjects.get(0);
paste.setDisable(SoundObjectUtilities.isOrContainsInstance(sObj));
} else {
paste.setDisable(true);
}
}
for (MenuItem menuItem : folderMenuItems) {
menuItem.setVisible(isFolder);
}
for (MenuItem menuItem : sObjMenuItems) {
menuItem.setVisible(!isFolder);
}
}
});
return popupMenu;
}
use of blue.library.LibraryTreeItem in project blue by kunstmusik.
the class SoundObjectImportPane method importSoundObjectToLibrary.
protected void importSoundObjectToLibrary(Library<SoundObject> lib, SoundObject sObj) {
for (TreeItem<LibraryItem<SoundObject>> item : lib.getRoot().getChildren()) {
if (!item.isLeaf() && item.getValue().toString().equals("Imported SoundObjects")) {
item.getChildren().add(new LibraryTreeItem(new LibraryItem<>(sObj)));
return;
}
}
LibraryTreeItem importFolder = new LibraryTreeItem(new LibraryItem<>("Imported SoundObjects"));
importFolder.getChildren().add(new LibraryTreeItem(new LibraryItem<>(sObj)));
lib.getRoot().getChildren().add(importFolder);
}
Aggregations