Example usage for com.intellij.openapi.actionSystem DefaultActionGroup DefaultActionGroup

List of usage examples for com.intellij.openapi.actionSystem DefaultActionGroup DefaultActionGroup

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem DefaultActionGroup DefaultActionGroup.

Prototype

public DefaultActionGroup(@Nullable String shortName, boolean popup) 

Source Link

Usage

From source file:com.android.tools.adtui.workbench.AttachedToolWindow.java

License:Apache License

private void addGearPopupActions(@NotNull DefaultActionGroup group) {
    if (myContent != null) {
        List<AnAction> myExtraGearActions = myContent.getGearActions();
        if (!myExtraGearActions.isEmpty()) {
            group.addAll(myExtraGearActions);
            group.addSeparator();//from   w ww . j  a va2 s. c o m
        }
    }
    DefaultActionGroup attachedSide = new DefaultActionGroup("Attached Side", true);
    attachedSide.add(new TogglePropertyTypeAction(PropertyType.LEFT, "Left"));
    attachedSide.add(new ToggleOppositePropertyTypeAction(PropertyType.LEFT, "Right"));
    attachedSide.add(new SwapAction());
    group.add(attachedSide);
    ActionManager manager = ActionManager.getInstance();
    group.add(new ToggleOppositePropertyTypeAction(PropertyType.AUTO_HIDE,
            manager.getAction(InternalDecorator.TOGGLE_DOCK_MODE_ACTION_ID)));
    group.add(new TogglePropertyTypeAction(PropertyType.FLOATING,
            manager.getAction(InternalDecorator.TOGGLE_FLOATING_MODE_ACTION_ID)));
    group.add(new TogglePropertyTypeAction(PropertyType.SPLIT,
            manager.getAction(InternalDecorator.TOGGLE_SIDE_MODE_ACTION_ID)));
}

From source file:com.android.tools.adtui.workbench.FloatingToolWindow.java

License:Apache License

private void setAdditionalGearPopupActions(@NotNull ToolWindowEx toolWindow) {
    DefaultActionGroup attachedSide = new DefaultActionGroup("Attached Side", true);
    attachedSide.add(new AttachToSideAction(Side.LEFT));
    attachedSide.add(new AttachToSideAction(Side.RIGHT));
    toolWindow.setAdditionalGearActions(new DefaultActionGroup(attachedSide));
}

From source file:com.android.tools.idea.configurations.ActivityMenuAction.java

License:Apache License

@Override
@NotNull//ww  w  . j av  a2 s  .c  om
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
    DefaultActionGroup group = new DefaultActionGroup("Activity", true);

    Configuration configuration = myRenderContext.getConfiguration();
    if (configuration != null) {
        String activity = configuration.getActivity();
        String currentFqcn = null;
        if (activity != null && !activity.isEmpty()) {
            int dotIndex = activity.indexOf('.');
            if (dotIndex <= 0) {
                String pkg = ManifestInfo.get(myRenderContext.getModule()).getPackage();
                activity = pkg + (dotIndex == -1 ? "." : "") + activity;
                currentFqcn = activity;
            } else {
                currentFqcn = activity;
            }

            String title = String.format("Open %1$s", activity.substring(activity.lastIndexOf('.') + 1));
            group.add(new ShowActivityAction(myRenderContext, title, activity));
            group.addSeparator();
        }

        // List activities that reference the R.layout.<self> field here
        boolean haveSpecificActivities = false;
        VirtualFile file = configuration.getFile();
        if (file != null) {
            String layoutName = ResourceHelper.getResourceName(file);
            Module module = myRenderContext.getModule();
            Project project = module.getProject();
            String pkg = ManifestInfo.get(module).getPackage();
            String rLayoutFqcn = pkg + '.' + R_CLASS + '.' + ResourceType.LAYOUT.getName();
            PsiClass layoutClass = JavaPsiFacade.getInstance(project).findClass(rLayoutFqcn,
                    GlobalSearchScope.projectScope(project));
            if (layoutClass != null) {
                PsiClass activityBase = JavaPsiFacade.getInstance(project).findClass(CLASS_ACTIVITY,
                        GlobalSearchScope.allScope(project));
                PsiField field = layoutClass.findFieldByName(layoutName, false);
                if (field != null && activityBase != null) {
                    Iterable<PsiReference> allReferences = SearchUtils.findAllReferences(field,
                            GlobalSearchScope.projectScope(project));
                    Iterator<PsiReference> iterator = allReferences.iterator();
                    if (iterator.hasNext()) {
                        PsiReference reference = iterator.next();
                        PsiElement element = reference.getElement();
                        if (element != null) {
                            PsiFile containingFile = element.getContainingFile();
                            if (containingFile instanceof PsiJavaFile) {
                                PsiJavaFile javaFile = (PsiJavaFile) containingFile;
                                for (PsiClass cls : javaFile.getClasses()) {
                                    if (cls.isInheritor(activityBase, false)) {
                                        String fqcn = cls.getQualifiedName();
                                        if (fqcn != null && !fqcn.equals(currentFqcn)) {
                                            String className = cls.getName();
                                            String title = String.format("Associate with %1$s", className);
                                            group.add(new ChooseActivityAction(myRenderContext, title, fqcn));
                                            haveSpecificActivities = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        if (haveSpecificActivities) {
            group.addSeparator();
        }

        group.add(new ChooseActivityAction(myRenderContext, "Associate with other Activity...", null));
    }

    return group;
}

From source file:com.android.tools.idea.configurations.ConfigurationMenuAction.java

License:Apache License

@Override
@NotNull/*from w w w  . j  a va 2s  . c  o  m*/
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
    DefaultActionGroup group = new DefaultActionGroup("Configuration", true);

    VirtualFile virtualFile = myRenderContext.getVirtualFile();
    if (virtualFile != null) {
        Module module = myRenderContext.getModule();
        if (module == null) {
            return group;
        }
        Project project = module.getProject();

        List<VirtualFile> variations = ResourceHelper.getResourceVariations(virtualFile, true);
        if (variations.size() > 1) {
            for (VirtualFile file : variations) {
                String title = String.format("Switch to %1$s", file.getParent().getName());
                group.add(new SwitchToVariationAction(title, project, file, virtualFile == file));
            }
            group.addSeparator();
        }

        boolean haveLandscape = false;
        boolean haveLarge = false;
        for (VirtualFile file : variations) {
            String name = file.getParent().getName();
            if (name.startsWith(FD_RES_LAYOUT)) {
                FolderConfiguration config = FolderConfiguration.getConfigForFolder(name);
                if (config != null) {
                    ScreenOrientationQualifier orientation = config.getScreenOrientationQualifier();
                    if (orientation != null && orientation.getValue() == ScreenOrientation.LANDSCAPE) {
                        haveLandscape = true;
                        if (haveLarge) {
                            break;
                        }
                    }
                    ScreenSizeQualifier size = config.getScreenSizeQualifier();
                    if (size != null && size.getValue() == ScreenSize.XLARGE) {
                        haveLarge = true;
                        if (haveLandscape) {
                            break;
                        }
                    }
                }
            }
        }

        // Create actions for creating "common" versions of a layout (that don't exist),
        // e.g. Create Landscape Version, Create RTL Version, Create XLarge version
        // Do statistics on what is needed!
        if (!haveLandscape) {
            group.add(new CreateVariationAction(myRenderContext, "Create Landscape Variation", "layout-land"));
        }
        if (!haveLarge) {
            group.add(new CreateVariationAction(myRenderContext, "Create layout-xlarge Variation",
                    "layout-xlarge"));
            //group.add(new CreateVariationAction(myRenderContext, "Create layout-sw600dp Variation...", "layout-sw600dp"));
        }
        group.add(new CreateVariationAction(myRenderContext, "Create Other...", null));

        if (myRenderContext.supportsPreviews()) {
            addMultiConfigActions(group);
        }
    }

    return group;
}

From source file:com.android.tools.idea.configurations.DeviceMenuAction.java

License:Apache License

@Override
@NotNull//www  .  ja  v  a  2s .c o m
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
    DefaultActionGroup group = new DefaultActionGroup(null, true);
    Configuration configuration = myRenderContext.getConfiguration();
    if (configuration == null) {
        return group;
    }
    Device current = configuration.getDevice();
    ConfigurationManager configurationManager = configuration.getConfigurationManager();
    List<Device> deviceList = configurationManager.getDevices();

    AndroidFacet facet = AndroidFacet.getInstance(configurationManager.getModule());
    assert facet != null;
    final AvdManager avdManager = facet.getAvdManagerSilently();
    if (avdManager != null) {
        boolean separatorNeeded = false;
        for (AvdInfo avd : avdManager.getValidAvds()) {
            Device device = configurationManager.createDeviceForAvd(avd);
            if (device != null) {
                String avdName = avd.getName();
                boolean selected = current != null && current.getName().equals(avdName);
                group.add(new SetDeviceAction(myRenderContext, avdName, device, selected));
                separatorNeeded = true;
            }
        }

        if (separatorNeeded) {
            group.addSeparator();
        }
    }

    // Group the devices by manufacturer, then put them in the menu.
    // If we don't have anything but Nexus devices, group them together rather than
    // make many manufacturer submenus.
    boolean haveNexus = false;
    if (!deviceList.isEmpty()) {
        Map<String, List<Device>> manufacturers = new TreeMap<String, List<Device>>();
        for (Device device : deviceList) {
            List<Device> devices;
            if (isNexus(device)) {
                haveNexus = true;
            }
            if (manufacturers.containsKey(device.getManufacturer())) {
                devices = manufacturers.get(device.getManufacturer());
            } else {
                devices = new ArrayList<Device>();
                manufacturers.put(device.getManufacturer(), devices);
            }
            devices.add(device);
        }
        List<Device> nexus = new ArrayList<Device>();
        List<Device> generic = new ArrayList<Device>();
        if (haveNexus) {
            // Nexus
            for (List<Device> devices : manufacturers.values()) {
                for (Device device : devices) {
                    if (isNexus(device)) {
                        if (device.getManufacturer().equals(MANUFACTURER_GENERIC)) {
                            generic.add(device);
                        } else {
                            nexus.add(device);
                        }
                    } else {
                        generic.add(device);
                    }
                }
            }
        }

        if (!nexus.isEmpty()) {
            sortNexusList(nexus);
            for (final Device device : nexus) {
                group.add(
                        new SetDeviceAction(myRenderContext, getNexusLabel(device), device, current == device));
            }

            group.addSeparator();
        }

        // Generate the generic menu.
        Collections.reverse(generic);
        for (final Device device : generic) {
            group.add(new SetDeviceAction(myRenderContext, getGenericLabel(device), device, current == device));
        }
    }

    group.addSeparator();
    group.add(new RunAndroidAvdManagerAction("Add Device Definition..."));
    group.addSeparator();
    if (RenderPreviewMode.getCurrent() != RenderPreviewMode.SCREENS) {
        ConfigurationMenuAction.addScreenSizeAction(myRenderContext, group);
    } else {
        ConfigurationMenuAction.addRemovePreviewsAction(myRenderContext, group);
    }

    return group;
}

From source file:com.android.tools.idea.configurations.LocaleMenuAction.java

License:Apache License

@Override
@NotNull/*  ww w  .j  a v  a2  s  . co m*/
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
    DefaultActionGroup group = new DefaultActionGroup(null, true);

    // TODO: Offer submenus, lazily populated, which offer languages either by code or by name.
    // However, this doesn't currently work for the JBPopup dialog we're using as part
    // of the combo action (and using the JBPopup dialog rather than a Swing menu has some
    // other advantages: fitting in with the overall IDE look and feel (e.g. dark colors),
    // allowing typing to filter, etc.

    List<Locale> locales = getRelevantLocales();
    if (locales.size() > 0) {
        group.add(new SetLocaleAction(myRenderContext, getLocaleLabel(Locale.ANY, false), Locale.ANY));
        group.addSeparator();

        Collections.sort(locales, Locale.LANGUAGE_CODE_COMPARATOR);
        for (Locale locale : locales) {
            String title = getLocaleLabel(locale, false);
            group.add(new SetLocaleAction(myRenderContext, title, locale));
        }

        group.addSeparator();
    }

    group.add(new AddTranslationAction());

    if (locales.size() > 1) {
        group.addSeparator();
        if (RenderPreviewMode.getCurrent() != RenderPreviewMode.LOCALES) {
            ConfigurationMenuAction.addLocalePreviewAction(myRenderContext, group, true);
        } else {
            ConfigurationMenuAction.addRemovePreviewsAction(myRenderContext, group);
        }
    }

    return group;
}

From source file:com.android.tools.idea.configurations.OrientationMenuAction.java

License:Apache License

@Override
@NotNull/*  w w w . ja v a 2s .  c o m*/
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
    DefaultActionGroup group = new DefaultActionGroup(null, true);

    Configuration configuration = myRenderContext.getConfiguration();
    if (configuration != null) {
        Device device = configuration.getDevice();
        State current = configuration.getDeviceState();
        if (device != null) {
            List<State> states = device.getAllStates();

            if (states.size() > 1 && current != null) {
                State flip = configuration.getNextDeviceState(current);
                String flipName = flip != null ? flip.getName() : current.getName();
                String title = String.format("Switch to %1$s", flipName);
                group.add(new SetDeviceStateAction(myRenderContext, title, flip == null ? current : flip, false,
                        true));
                group.addSeparator();
            }

            for (State config : states) {
                group.add(new SetDeviceStateAction(myRenderContext, config.getName(), config, config == current,
                        false));
            }
            group.addSeparator();
        }

        group.addSeparator();
        DefaultActionGroup uiModeGroup = new DefaultActionGroup("_UI Mode", true);
        UiMode currentUiMode = configuration.getUiMode();
        for (UiMode uiMode : UiMode.values()) {
            String title = uiMode.getShortDisplayValue();
            boolean checked = uiMode == currentUiMode;
            uiModeGroup.add(new SetUiModeAction(myRenderContext, title, uiMode, checked));
        }
        group.add(uiModeGroup);

        group.addSeparator();
        DefaultActionGroup nightModeGroup = new DefaultActionGroup("_Night Mode", true);
        NightMode currentNightMode = configuration.getNightMode();
        for (NightMode nightMode : NightMode.values()) {
            String title = nightMode.getShortDisplayValue();
            boolean checked = nightMode == currentNightMode;
            nightModeGroup.add(new SetNightModeAction(myRenderContext, title, nightMode, checked));
        }
        group.add(nightModeGroup);
    }

    return group;
}

From source file:com.android.tools.idea.configurations.TargetMenuAction.java

License:Apache License

@Override
@NotNull/*  ww w  .  j  av  a2 s .com*/
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
    DefaultActionGroup group = new DefaultActionGroup(null, true);

    Configuration configuration = myRenderContext.getConfiguration();
    if (configuration == null) {
        return group;
    }
    IAndroidTarget current = configuration.getTarget();
    List<IAndroidTarget> targets = configuration.getConfigurationManager().getTargets();

    boolean haveRecent = false;

    for (int i = targets.size() - 1; i >= 0; i--) {
        IAndroidTarget target = targets.get(i);

        AndroidVersion version = target.getVersion();
        if (version.getApiLevel() >= 7) {
            haveRecent = true;
        } else if (haveRecent) {
            // Don't show ancient rendering targets; they're pretty broken
            // (unless of course all you have are ancient targets)
            break;
        }

        String title = getRenderingTargetLabel(target, false);
        boolean select = current == target;
        group.add(new SetTargetAction(myRenderContext, title, target, select));
    }

    return group;
}

From source file:com.android.tools.idea.ddms.actions.DumpSysActions.java

License:Apache License

public static DefaultActionGroup create(@NotNull Project p, @NotNull final DeviceContext context) {
    DefaultActionGroup group = new DefaultActionGroup("System Information", true) {
        @Override// w w  w.ja va 2s  . c o  m
        public void update(AnActionEvent e) {
            e.getPresentation().setText("System Information");
            e.getPresentation().setIcon(AndroidIcons.Ddms.SysInfo);
            e.getPresentation().setEnabled(context.getSelectedDevice() != null);
        }

        @Override
        public boolean isDumbAware() {
            return true;
        }
    };
    group.add(new MyDumpSysAction(p, context, "activity", "Activity Manager State"));
    group.add(new MyDumpSysAction(p, context, "package", "Package Information"));
    group.add(new MyDumpSysAction(p, context, "meminfo", "Memory Usage"));
    group.add(new MyDumpProcStatsAction(p, context, "procstats", "Memory use over time"));
    group.add(new MyDumpSysAction(p, context, "gfxinfo", "Graphics State"));
    return group;
}

From source file:com.android.tools.idea.gradle.invoker.messages.GradleBuildTreeViewPanel.java

License:Apache License

@Override
protected void fillRightToolbarGroup(DefaultActionGroup group) {
    super.fillRightToolbarGroup(group);
    group.add(new DumbAwareAction("Show Console Output", null, AndroidIcons.GradleConsole) {
        @Override//from   w  w w  .ja  v  a  2s . c  o m
        public void actionPerformed(AnActionEvent e) {
            ToolWindow window = ToolWindowManager.getInstance(myProject)
                    .getToolWindow(GradleConsoleToolWindowFactory.ID);
            if (window != null) {
                window.activate(null, false);
            }
        }

        @Override
        public void update(AnActionEvent e) {
            e.getPresentation().setEnabledAndVisible(true);
        }
    });

    DefaultActionGroup filterGroup = new DefaultActionGroup("GradleBuildMessagesFilter", true) {
        @Override
        public void update(AnActionEvent e) {
            Presentation presentation = e.getPresentation();
            presentation.setDescription("Filter messages to display");
            presentation.setIcon(AllIcons.General.Filter);
        }

        @Override
        public boolean isDumbAware() {
            return true;
        }
    };

    // We could have iterated through ErrorTreeElementKind.values() and have less code, but we want to keep this order:
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.ERROR));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.WARNING));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.INFO));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.NOTE));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.GENERIC));
    group.add(filterGroup);
}