Search in sources :

Example 1 with PhoneGapTargets

use of com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapTargets in project intellij-plugins by JetBrains.

the class PhoneGapRunConfigurationEditor method createEditor.

@NotNull
@Override
protected JComponent createEditor() {
    myExecutablePathField = PhoneGapUtil.createPhoneGapExecutableTextField(myProject);
    myWorkDirField = PhoneGapUtil.createPhoneGapWorkingDirectoryField(myProject);
    myPlatformField = new ComboBoxWithMoreOption(getDefaultPlatforms(), getNonDefaultPlatforms());
    myCommand = new ComboBox();
    myEnvComponent = new EnvironmentVariablesTextFieldWithBrowseButton();
    myEnvComponent.setPassParentEnvs(true);
    myHasTarget = new JBCheckBox("Specify target");
    myTarget = new PhoneGapTargetsPanel();
    myExtraArgsTextField = new JBTextField(15);
    myCommand.setMinimumAndPreferredWidth(200);
    myPlatformField.setMinimumAndPreferredWidth(200);
    myTarget.getTargetsField().setMinimumAndPreferredWidth(myPlatformField.getPreferredSize().width);
    myTarget.setDataProvider(new ReloadableComboBoxPanel.DataProvider<String>() {

        @NotNull
        @Override
        public Set<String> getCachedValues() {
            return ContainerUtil.newHashOrEmptySet(null);
        }

        @Override
        public void updateValuesAsynchronously() {
            if (!myTarget.isEnabled()) {
                processEmpty();
                return;
            }
            final String platform = getPlatformAsCodeFromField();
            final String command = (String) myCommand.getSelectedItem();
            final PhoneGapTargets targetsProvider = PhoneGapTargets.createTargetsList(myProject, platform);
            if (targetsProvider == null) {
                processEmpty();
                return;
            }
            ApplicationManager.getApplication().executeOnPooledThread(() -> {
                final String currentText = myTarget.getTargetsField().getText();
                final Set<String> targets = ContainerUtil.newLinkedHashSet(PhoneGapTargets.listTargets(targetsProvider, command));
                if (!StringUtil.isEmpty(currentText) && !targets.contains(currentText)) {
                    targets.add(currentText);
                }
                UIUtil.invokeLaterIfNeeded(() -> myTarget.onUpdateValues(targets));
            });
        }

        private void processEmpty() {
            myTarget.onUpdateValues(ContainerUtil.newHashOrEmptySet(null));
        }
    });
    setListenerForPlatforms();
    setListenerForCommand();
    setListenerForHasTarget();
    setListenerForExecutablePath();
    setCommandList();
    return FormBuilder.createFormBuilder().addLabeledComponent(PhoneGapBundle.message("phonegap.conf.executable.name"), myExecutablePathField).addLabeledComponent(PhoneGapBundle.message("phonegap.conf.work.dir.name"), myWorkDirField).addLabeledComponent(ExecutionBundle.message("environment.variables.component.title"), myEnvComponent).addLabeledComponent("Command:", myCommand).addLabeledComponent("Platform:", myPlatformField).addLabeledComponent(PhoneGapBundle.message("phonegap.conf.extra.args.name"), myExtraArgsTextField).addLabeledComponent(myHasTarget, myTarget.getMainPanel()).getPanel();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ComboBox(com.intellij.openapi.ui.ComboBox) JBTextField(com.intellij.ui.components.JBTextField) NotNull(org.jetbrains.annotations.NotNull) JBCheckBox(com.intellij.ui.components.JBCheckBox) ReloadableComboBoxPanel(com.intellij.util.ui.ReloadableComboBoxPanel) EnvironmentVariablesTextFieldWithBrowseButton(com.intellij.execution.configuration.EnvironmentVariablesTextFieldWithBrowseButton) PhoneGapTargets(com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapTargets) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PhoneGapTargets (com.github.masahirosuzuka.PhoneGapIntelliJPlugin.commandLine.PhoneGapTargets)1 EnvironmentVariablesTextFieldWithBrowseButton (com.intellij.execution.configuration.EnvironmentVariablesTextFieldWithBrowseButton)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 JBCheckBox (com.intellij.ui.components.JBCheckBox)1 JBTextField (com.intellij.ui.components.JBTextField)1 ReloadableComboBoxPanel (com.intellij.util.ui.ReloadableComboBoxPanel)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 NotNull (org.jetbrains.annotations.NotNull)1