public FilePopupMenu( final FileChooser chooser, FileChooserStyle chooserStyle, final FilePopupMenuCallback callback) { super(chooserStyle.popupMenuStyleName); this.chooser = chooser; this.style = chooserStyle; this.callback = callback; delete = new MenuItem(CONTEXT_MENU_DELETE.get(), style.iconTrash); newDirectory = new MenuItem(CONTEXT_MENU_NEW_DIRECTORY.get(), style.iconFolderNew); showInExplorer = new MenuItem(CONTEXT_MENU_SHOW_IN_EXPLORER.get()); addToFavorites = new MenuItem(CONTEXT_MENU_ADD_TO_FAVORITES.get(), style.iconFolderStar); removeFromFavorites = new MenuItem(CONTEXT_MENU_REMOVE_FROM_FAVORITES.get(), style.iconFolderStar); delete.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { DialogUtils.showOptionDialog( chooser.getStage(), POPUP_TITLE.get(), trashAvailable ? CONTEXT_MENU_MOVE_TO_TRASH_WARNING.get() : CONTEXT_MENU_DELETE_WARNING.get(), OptionDialogType.YES_NO, new OptionDialogAdapter() { @Override public void yes() { try { boolean success = callback.delete(file); if (success == false) DialogUtils.showErrorDialog(getStage(), POPUP_DELETE_FILE_FAILED.get()); } catch (IOException e) { DialogUtils.showErrorDialog(getStage(), POPUP_DELETE_FILE_FAILED.get(), e); e.printStackTrace(); } chooser.refresh(); } }); } }); newDirectory.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { callback.showNewDirDialog(); } }); showInExplorer.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { try { if (file.isDirectory()) Desktop.getDesktop().open(file.file()); else Desktop.getDesktop().open(file.parent().file()); } catch (IOException e) { e.printStackTrace(); } } }); addToFavorites.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { chooser.addFavorite(file); } }); removeFromFavorites.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { chooser.removeFavorite(file); } }); }
public void fileDeleterChanged(boolean trashAvailable) { this.trashAvailable = trashAvailable; delete.setText(trashAvailable ? CONTEXT_MENU_MOVE_TO_TRASH.get() : CONTEXT_MENU_DELETE.get()); }