Search in sources :

Example 1 with VisibleProperty

use of com.android.tools.idea.ui.properties.swing.VisibleProperty in project android by JetBrains.

the class ModelWizardDialog method createJButtonForAction.

@Override
protected JButton createJButtonForAction(Action action) {
    final JButton button = super.createJButtonForAction(action);
    if (action instanceof ModelWizardDialogAction) {
        ModelWizardDialogAction wizardAction = (ModelWizardDialogAction) action;
        myBindings.bind(new EnabledProperty(button), wizardAction.shouldBeEnabled());
        myBindings.bind(new VisibleProperty(button), wizardAction.shouldBeVisible());
        myListeners.receiveAndFire(wizardAction.shouldBeDefault(), isDefault -> {
            JRootPane rootPane = getRootPane();
            if (rootPane != null && isDefault) {
                rootPane.setDefaultButton(button);
            }
        });
    }
    return button;
}
Also used : VisibleProperty(com.android.tools.idea.ui.properties.swing.VisibleProperty) EnabledProperty(com.android.tools.idea.ui.properties.swing.EnabledProperty)

Example 2 with VisibleProperty

use of com.android.tools.idea.ui.properties.swing.VisibleProperty in project android by JetBrains.

the class ConfigureTemplateParametersStep method onEntering.

@Override
protected void onEntering() {
    // The Model TemplateHandle may have changed, rebuild the panel
    resetPanel();
    final TemplateHandle templateHandle = getModel().getTemplateHandle();
    ApplicationManager.getApplication().invokeLater(() -> {
        // We want to set the label's text AFTER the wizard has been packed. Otherwise, its
        // width calculation gets involved and can really stretch out some wizards if the label is
        // particularly long (see Master/Detail Activity for example).
        myTemplateDescriptionLabel.setText(WizardUtils.toHtmlString(Strings.nullToEmpty(templateHandle.getMetadata().getDescription())));
    }, ModalityState.any());
    final IconProperty thumb = new IconProperty(myTemplateThumbLabel);
    BoolProperty thumbVisibility = new VisibleProperty(myTemplateThumbLabel);
    myBindings.bind(thumb, new Expression<Optional<Icon>>(myThumbPath) {

        @NotNull
        @Override
        public Optional<Icon> get() {
            return myThumbnailsCache.getUnchecked(new File(templateHandle.getRootPath(), myThumbPath.get()));
        }
    });
    myBindings.bind(thumbVisibility, new Expression<Boolean>(thumb) {

        @NotNull
        @Override
        public Boolean get() {
            return thumb.get().isPresent();
        }
    });
    myThumbPath.set(getDefaultThumbnailPath());
    final TextProperty parameterDescription = new TextProperty(myParameterDescriptionLabel);
    myBindings.bind(new VisibleProperty(myFooterSeparator), new Expression<Boolean>(parameterDescription) {

        @NotNull
        @Override
        public Boolean get() {
            return !parameterDescription.get().isEmpty();
        }
    });
    Module module = myFacet == null ? null : myFacet.getModule();
    final Collection<Parameter> parameters = templateHandle.getMetadata().getParameters();
    for (final Parameter parameter : parameters) {
        RowEntry row = createRowForParameter(module, parameter);
        final ObservableValue<?> property = row.getProperty();
        if (property != null) {
            property.addListener(sender -> {
                if (myEvaluationState != EvaluationState.EVALUATING) {
                    myUserValues.put(parameter, property.get());
                    enqueueEvaluateParameters();
                }
            });
            final ActionGroup resetParameterGroup = new ActionGroup() {

                @NotNull
                @Override
                public AnAction[] getChildren(@Nullable AnActionEvent e) {
                    return new AnAction[] { new ResetParameterAction(parameter) };
                }
            };
            row.getComponent().addMouseListener(new PopupHandler() {

                @Override
                public void invokePopup(Component comp, int x, int y) {
                    ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UNKNOWN, resetParameterGroup).getComponent().show(comp, x, y);
                }
            });
        }
        myParameterRows.put(parameter, row);
        row.addToPanel(myParametersPanel);
    }
    if (mySourceSets.size() > 1) {
        RowEntry row = new RowEntry<>("Target Source Set", new SourceSetComboProvider(mySourceSets));
        row.setEnabled(mySourceSets.size() > 1);
        row.addToPanel(myParametersPanel);
        //noinspection unchecked
        SelectedItemProperty<AndroidSourceSet> sourceSet = (SelectedItemProperty<AndroidSourceSet>) row.getProperty();
        // SourceSetComboProvider always sets this
        assert sourceSet != null;
        myBindings.bind(getModel().getSourceSet(), new OptionalToValuePropertyAdapter<>(sourceSet));
        sourceSet.addListener(sender -> enqueueEvaluateParameters());
    }
    myValidatorPanel.registerValidator(myInvalidParameterMessage, message -> (message.isEmpty() ? Validator.Result.OK : new Validator.Result(Validator.Severity.ERROR, message)));
    // TODO: This code won't be needed until we migrate this enough to support
    // NewAndroidApplication/template.xml and NewAndroidLibrary/template.xml
    // Add it in then. Probably we can add an optional validator API to ComponentProvider? Then we
    // could move this code into EnumComboProvider and it won't be a hack anymore.
    //
    // if (value instanceof ApiComboBoxItem) {
    //  ApiComboBoxItem selectedItem = (ApiComboBoxItem)value;
    //
    //  if (minApi != null && selectedItem.minApi > minApi.getFeatureLevel()) {
    //    setErrorHtml(String.format("The \"%s\" option for %s requires a minimum API level of %d",
    //                               selectedItem.label, param.name, selectedItem.minApi));
    //    return false;
    //  }
    //  if (buildApi != null && selectedItem.minBuildApi > buildApi) {
    //    setErrorHtml(String.format("The \"%s\" option for %s requires a minimum API level of %d",
    //                               selectedItem.label, param.name, selectedItem.minBuildApi));
    //    return false;
    //  }
    //}
    evaluateParameters();
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) NotNull(org.jetbrains.annotations.NotNull) IconProperty(com.android.tools.idea.ui.properties.swing.IconProperty) VisibleProperty(com.android.tools.idea.ui.properties.swing.VisibleProperty) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) SelectedItemProperty(com.android.tools.idea.ui.properties.swing.SelectedItemProperty) Module(com.intellij.openapi.module.Module) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) Validator(com.android.tools.idea.ui.validation.Validator) AndroidSourceSet(com.android.tools.idea.npw.project.AndroidSourceSet)

Aggregations

VisibleProperty (com.android.tools.idea.ui.properties.swing.VisibleProperty)2 AndroidSourceSet (com.android.tools.idea.npw.project.AndroidSourceSet)1 EnabledProperty (com.android.tools.idea.ui.properties.swing.EnabledProperty)1 IconProperty (com.android.tools.idea.ui.properties.swing.IconProperty)1 SelectedItemProperty (com.android.tools.idea.ui.properties.swing.SelectedItemProperty)1 TextProperty (com.android.tools.idea.ui.properties.swing.TextProperty)1 Validator (com.android.tools.idea.ui.validation.Validator)1 Module (com.intellij.openapi.module.Module)1 PopupHandler (com.intellij.ui.PopupHandler)1 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1