You have to enable presentation in update()
method of your action, where should you check whether the input is valid for your case.
@Override
public void update(@NotNull AnActionEvent e) {
final Presentation presentation = e.getPresentation();
final Project project = e.getProject();
if (project == null) {
presentation.setEnabledAndVisible(false);
return;
}
presentation.setEnabledAndVisible(true);
}
You can check the source code of Eclipser plugin, where you will find an elaborate example of the implementation.