Search in sources :

Example 1 with WidgetCreator

use of com.android.tools.idea.uibuilder.mockup.editor.creators.WidgetCreator in project android by JetBrains.

the class ExtractWidgetTool method createAnActionButton.

@NotNull
private AnAction createAnActionButton(@NotNull final CreatorAction creatorAction, boolean viewGroupOnly) {
    return new AnAction(creatorAction.myTitle, creatorAction.myTitle, creatorAction.myIcon) {

        @Override
        public void update(AnActionEvent e) {
            Mockup mockup = myMockupEditor.getMockup();
            if (viewGroupOnly && (mockup == null || !canAddChild(creatorAction, mockup.getComponent()))) {
                e.getPresentation().setEnabledAndVisible(false);
            } else {
                e.getPresentation().setEnabledAndVisible(true);
            }
        }

        @Override
        public void actionPerformed(AnActionEvent e) {
            Mockup mockup = myMockupEditor.getMockup();
            ScreenView currentScreenView = mySurface.getCurrentScreenView();
            if (mockup == null) {
                myMockupEditor.showError("Cannot create a widget from an empty mockup");
                LOGGER.warn("MockupEditor has no associated mockup");
                return;
            }
            if (currentScreenView == null) {
                myMockupEditor.showError("The designer is not ready to create a new widget");
                LOGGER.warn("The DesignSurface does not have a current screen view");
                return;
            }
            WidgetCreator creator = WidgetCreatorFactory.create(creatorAction.myAndroidClassName, mockup, currentScreenView.getModel(), currentScreenView, mySelection);
            executeCreator(creator);
        }
    };
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) Mockup(com.android.tools.idea.uibuilder.mockup.Mockup) WidgetCreator(com.android.tools.idea.uibuilder.mockup.editor.creators.WidgetCreator) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Mockup (com.android.tools.idea.uibuilder.mockup.Mockup)1 WidgetCreator (com.android.tools.idea.uibuilder.mockup.editor.creators.WidgetCreator)1 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)1 NotNull (org.jetbrains.annotations.NotNull)1