diff --git a/src/main/java/com/namics/oss/magnolia/appbuilder/action/importexport/ExportAppActionDefinition.java b/src/main/java/com/namics/oss/magnolia/appbuilder/action/importexport/ExportAppActionDefinition.java index 86f696c..9b6b377 100644 --- a/src/main/java/com/namics/oss/magnolia/appbuilder/action/importexport/ExportAppActionDefinition.java +++ b/src/main/java/com/namics/oss/magnolia/appbuilder/action/importexport/ExportAppActionDefinition.java @@ -8,6 +8,7 @@ import com.namics.oss.magnolia.appbuilder.MgnlIcon; import com.namics.oss.magnolia.appbuilder.action.AppActionDefinition; import com.namics.oss.magnolia.appbuilder.action.AvailabilityDefinitionBuilder; +import com.namics.oss.magnolia.appbuilder.action.rule.HasValueContextRule; import com.namics.oss.magnolia.appbuilder.action.rule.JcrIsNotDeletedRuleDefinition; import com.namics.oss.magnolia.appbuilder.action.rule.PermissionRequiredRuleDefinition; @@ -21,6 +22,7 @@ public ConfiguredActionDefinition action() { definition.setIcon(MgnlIcon.EXPORT); definition.setLabel("actions.export"); definition.setAvailability(new AvailabilityDefinitionBuilder() + .rule(new HasValueContextRule.Definition()) .rule(new JcrIsNotDeletedRuleDefinition()) .rule(new PermissionRequiredRuleDefinition(Permission.READ)) .build() diff --git a/src/main/java/com/namics/oss/magnolia/appbuilder/action/rule/HasValueContextRule.java b/src/main/java/com/namics/oss/magnolia/appbuilder/action/rule/HasValueContextRule.java new file mode 100644 index 0000000..7bbbf61 --- /dev/null +++ b/src/main/java/com/namics/oss/magnolia/appbuilder/action/rule/HasValueContextRule.java @@ -0,0 +1,31 @@ +package com.namics.oss.magnolia.appbuilder.action.rule; + +import info.magnolia.ui.ValueContext; +import info.magnolia.ui.api.availability.AvailabilityRule; +import info.magnolia.ui.api.availability.AvailabilityRuleType; +import info.magnolia.ui.api.availability.ConfiguredAvailabilityRuleDefinition; + +import java.util.Collection; + +import javax.inject.Inject; + +public class HasValueContextRule implements AvailabilityRule { + private final ValueContext valueContext; + + @Inject + public HasValueContextRule(final ValueContext valueContext) { + this.valueContext = valueContext; + } + + @Override + public boolean isAvailable(final Collection itemIds) { + return valueContext.getSingle().isPresent(); + } + + @AvailabilityRuleType("hasValueContextRule") + public static class Definition extends ConfiguredAvailabilityRuleDefinition { + public Definition() { + setImplementationClass(HasValueContextRule.class); + } + } +}