Search in sources :

Example 1 with TypeChooser

use of com.intellij.util.xml.TypeChooser in project intellij-community by JetBrains.

the class AddDomElementAction method getChildren.

@NotNull
public AnAction[] getChildren(@Nullable AnActionEvent e) {
    Project project = e == null ? null : e.getProject();
    if (project == null)
        return AnAction.EMPTY_ARRAY;
    DomCollectionChildDescription[] descriptions = getDomCollectionChildDescriptions(e);
    final List<AnAction> actions = new ArrayList<>();
    for (DomCollectionChildDescription description : descriptions) {
        final TypeChooser chooser = DomManager.getDomManager(project).getTypeChooserManager().getTypeChooser(description.getType());
        for (Type type : chooser.getChooserTypes()) {
            final Class<?> rawType = ReflectionUtil.getRawType(type);
            String name = TypePresentationService.getService().getTypePresentableName(rawType);
            Icon icon = null;
            if (!showAsPopup() || descriptions.length == 1) {
                //          if (descriptions.length > 1) {
                icon = ElementPresentationManager.getIconForClass(rawType);
            //          }
            }
            actions.add(createAddingAction(e, ApplicationBundle.message("action.add") + " " + name, icon, type, description));
        }
    }
    if (actions.size() > 1 && showAsPopup()) {
        ActionGroup group = new ActionGroup() {

            @Override
            @NotNull
            public AnAction[] getChildren(@Nullable AnActionEvent e) {
                return actions.toArray(new AnAction[actions.size()]);
            }
        };
        return new AnAction[] { new ShowPopupAction(group) };
    } else {
        if (actions.size() > 1) {
            actions.add(Separator.getInstance());
        } else if (actions.size() == 1) {
        }
    }
    return actions.toArray(new AnAction[actions.size()]);
}
Also used : ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) Type(java.lang.reflect.Type) TypeChooser(com.intellij.util.xml.TypeChooser) DomCollectionChildDescription(com.intellij.util.xml.reflect.DomCollectionChildDescription) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Project (com.intellij.openapi.project.Project)1 TypeChooser (com.intellij.util.xml.TypeChooser)1 DomCollectionChildDescription (com.intellij.util.xml.reflect.DomCollectionChildDescription)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1