Adds tabbed panel method to hide tab if it is empty.

https://github.com/BentoBoxWorld/BentoBox/issues/896
This commit is contained in:
tastybento 2019-08-17 19:08:00 -07:00
parent 612683f728
commit 33b4c70f25
4 changed files with 25 additions and 4 deletions

View File

@ -47,6 +47,7 @@ public class IslandSettingsCommand extends CompositeCommand {
.tab(2, new SettingsTab(getWorld(), user, island, Flag.Type.SETTING))
.startingSlot(1)
.size(54)
.hideIfEmpty()
.build().openPanel();
return true;
}

View File

@ -83,6 +83,11 @@ public class TabbedPanel extends Panel implements PanelListener {
// Get the tab
Tab tab = tpb.getTabs().get(activeTab);
// Remove any tabs that have no items, if required
if (tpb.isHideIfEmpty()) {
tpb.getTabs().values().removeIf(t -> !t.equals(tab) && !t.getPanelItems().stream().anyMatch(Objects::nonNull));
}
// Set up the tabbed header
setupHeader(tab, items);
@ -127,7 +132,9 @@ public class TabbedPanel extends Panel implements PanelListener {
// Add icons
for (Entry<Integer, Tab> tabPanel : tpb.getTabs().entrySet()) {
// Add the icon to the top row
if (tabPanel.getValue().getPermission().isEmpty() || tpb.getUser().hasPermission(tabPanel.getValue().getPermission()) || tpb.getUser().isOp()) {
if (tabPanel.getValue().getPermission().isEmpty()
|| tpb.getUser().hasPermission(tabPanel.getValue().getPermission())
|| tpb.getUser().isOp()) {
PanelItem activeIcon = tabPanel.getValue().getIcon();
// Set the glow of the active tab
activeIcon.setGlow(tabPanel.getValue().equals(tab));

View File

@ -22,6 +22,7 @@ public class TabbedPanelBuilder {
private int startingSlot;
private World world;
private User user;
private boolean hideIfEmpty;
/**
* Forces panel to be a specific number of slots.
@ -79,6 +80,14 @@ public class TabbedPanelBuilder {
return this;
}
/**
* Hides the panel from view if there are no panel items in it
* @return TabbedPanelBuilder
*/
public TabbedPanelBuilder hideIfEmpty() {
this.hideIfEmpty = true;
return this;
}
/**
* Build the panel
* @return Panel
@ -126,6 +135,13 @@ public class TabbedPanelBuilder {
return user;
}
/**
* @return the hideIfEmpty
*/
public boolean isHideIfEmpty() {
return hideIfEmpty;
}
}

View File

@ -1,6 +1,3 @@
/**
*
*/
package world.bentobox.bentobox.api.panels;
import static org.junit.Assert.assertEquals;