ProjectGeneratorPeers: difference between createPanel and buildUI

Answered

I'm trying to better understand how the "New Project" dialogs work.

While looking at the sample plugin for AngularJS, I noticed that the constructor for `AngularCLIProjectGeneratorPeer` calls a function called `createPanel()` which looks like it initializes all of the different settings fields that will show up in the project wizard.

What I expected to happen was that when I select my new project type the panel created from `createPanel()` would be displayed. This is not the case though. In order to get the fields to show up I actually had to implement the `buildUI()` function and add the fields again to the setting step

So my question is what is the purpose of the `createPanel()` function and how is it different from `buildUI()`

 

Abridged code looks somethng like for AngularCLIProjectGeneratorPeer

private class AngularCLIProjectGeneratorPeer extends NpmPackageGeneratorPeer {

private TextAccessor myContentRoot;

private SchematicOptionsTextField myOptionsTextField;
private JCheckBox myUseDefaults;

@Override
protected JPanel createPanel() { // result returned from this.getComponent()
final JPanel panel = super.createPanel();

myOptionsTextField = new SchematicOptionsTextField(ProjectManager.getInstance().getDefaultProject(),
Collections.emptyList());
myOptionsTextField.setVariants(Collections.singletonList(new Option("test")));

LabeledComponent component = LabeledComponent.create(
myOptionsTextField, Angular2Bundle.message("angular.action.new-project.label-additional-parameters"));
component.setAnchor((JComponent)panel.getComponent(0));
component.setLabelLocation(BorderLayout.WEST);
panel.add(component);

myUseDefaults = new JCheckBox(Angular2Bundle.message("angular.action.new-project.label-defaults"), true);
panel.add(myUseDefaults);

return panel;
}

@Override
public void buildUI(@NotNull SettingsStep settingsStep) {
super.buildUI(settingsStep);
final ModuleNameLocationSettings field = settingsStep.getModuleNameLocationSettings();
if (field != null) {
myContentRoot = new TextAccessor() {
@Override
public void setText(@NotNull String text) {
field.setModuleContentRoot(text);
}

@Override
@NotNull
public String getText() {
return field.getModuleContentRoot();
}
};
}
settingsStep.addSettingsField(UIUtil.replaceMnemonicAmpersand(
Angular2Bundle.message("angular.action.new-project.label-additional-parameters")), myOptionsTextField);
settingsStep.addSettingsComponent(myUseDefaults);
getPackageField().addSelectionListener(this::nodePackageChanged);
nodePackageChanged(getPackageField().getSelected());
}
}

 

 

0
2 comments

Dosnlinux,

getComponent() method is supposed to create and return a new project settings component which is invoked by the ProjectSettingsStepBase#createAdvancedSettings() - so it provides components used as an Advanced Settings.

buildUI(SettingsStep) is invoked by the ProjectSettingsStepBase#createAndFillContentPanel() to populate following steps of the panel.

In case of the EmptyWebProjectTemplate, buildUI(SettingsStep) uses getComponent() by default.

1

Where do the advanced settings show in the UI?

0

Please sign in to leave a comment.