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);
}
};
}
Aggregations