Search in sources :

Example 1 with SelectedItemProperty

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

the class ConfigureDeviceOptionsStep method attachBindingsAndValidators.

private void attachBindingsAndValidators() {
    final AvdDeviceData deviceModel = getModel().getDeviceData();
    myBindings.bindTwoWay(new TextProperty(myDeviceName), deviceModel.name());
    myBindings.bind(deviceModel.diagonalScreenSize(), myDiagScreenSizeAdapter);
    myBindings.bind(deviceModel.screenResolutionWidth(), myScreenResWidthAdapter);
    myBindings.bind(deviceModel.screenResolutionHeight(), myScreenResHeightAdapter);
    myBindings.bindTwoWay(myRamField.storage(), deviceModel.ramStorage());
    myBindings.bindTwoWay(new SelectedProperty(myHasHardwareButtons), deviceModel.hasHardwareButtons());
    myBindings.bindTwoWay(new SelectedProperty(myHasHardwareKeyboard), deviceModel.hasHardwareKeyboard());
    myBindings.bindTwoWay(new SelectedItemProperty<>(myNavigationControlsCombo), deviceModel.navigation());
    myBindings.bindTwoWay(new SelectedProperty(myIsScreenRound), deviceModel.isScreenRound());
    myBindings.bindTwoWay(new SelectedProperty(mySupportsLandscape), deviceModel.supportsLandscape());
    myBindings.bindTwoWay(new SelectedProperty(mySupportsPortrait), deviceModel.supportsPortrait());
    myBindings.bindTwoWay(new SelectedProperty(myHasBackFacingCamera), deviceModel.hasBackCamera());
    myBindings.bindTwoWay(new SelectedProperty(myHasFrontFacingCamera), deviceModel.hasFrontCamera());
    myBindings.bindTwoWay(new SelectedProperty(myHasAccelerometer), deviceModel.hasAccelerometer());
    myBindings.bindTwoWay(new SelectedProperty(myHasGyroscope), deviceModel.hasGyroscope());
    myBindings.bindTwoWay(new SelectedProperty(myHasGps), deviceModel.hasGps());
    myBindings.bindTwoWay(new SelectedProperty(myHasProximitySensor), deviceModel.hasProximitySensor());
    myBindings.bindTwoWay(new SelectedItemProperty<>(myCustomSkinPath.getComboBox()), deviceModel.customSkinFile());
    SelectedItemProperty<IdDisplay> selectedDeviceType = new SelectedItemProperty<>(myDeviceTypeComboBox);
    myBindings.bindTwoWay(selectedDeviceType, deviceModel.deviceType());
    myListeners.receive(selectedDeviceType, idDisplayOptional -> {
        if (idDisplayOptional.isPresent()) {
            IdDisplay selectedType = idDisplayOptional.get();
            getModel().getDeviceData().isWear().set(selectedType.equals(SystemImage.WEAR_TAG));
            getModel().getDeviceData().isTv().set(selectedType.equals(SystemImage.TV_TAG));
            myIsScreenRound.setEnabled(selectedType.equals(SystemImage.WEAR_TAG));
            myIsScreenRound.setSelected(getModel().getDeviceData().isScreenRound().get());
        }
    });
    myValidatorPanel.registerValidator(deviceModel.name().isEmpty().not(), "Please write a name for the new device.");
    myValidatorPanel.registerValidator(myDiagScreenSizeAdapter.inSync().and(deviceModel.diagonalScreenSize().isEqualTo(myDiagScreenSizeAdapter)), "Please enter a non-zero positive floating point value for the screen size.");
    myValidatorPanel.registerValidator(myScreenResWidthAdapter.inSync().and(deviceModel.screenResolutionWidth().isEqualTo(myScreenResWidthAdapter)), "Please enter a valid value for the screen width.");
    myValidatorPanel.registerValidator(myScreenResHeightAdapter.inSync().and(deviceModel.screenResolutionHeight().isEqualTo(myScreenResHeightAdapter)), "Please enter a valid value for the screen height.");
    myValidatorPanel.registerValidator(deviceModel.ramStorage(), value -> (value.getSize() > 0) ? Result.OK : new Result(Validator.Severity.ERROR, "Please specify a non-zero amount of RAM."));
    myValidatorPanel.registerValidator(deviceModel.screenDpi().isGreaterThan(0), "The given resolution and screen size specified have a DPI that is too low.");
    myValidatorPanel.registerValidator(deviceModel.supportsLandscape().or(deviceModel.supportsPortrait()), "A device must support at least one orientation (Portrait or Landscape).");
    myValidatorPanel.registerValidator(deviceModel.customSkinFile(), value -> {
        File skinPath = value.orElse(null);
        if (skinPath != null && !FileUtil.filesEqual(skinPath, AvdWizardUtils.NO_SKIN) && !skinPath.getPath().equals(skinPath.getName())) {
            File layoutFile = new File(skinPath, SdkConstants.FN_SKIN_LAYOUT);
            if (!layoutFile.isFile()) {
                return new Result(Validator.Severity.ERROR, "The skin directory does not point to a valid skin.");
            }
        }
        return Result.OK;
    });
    myValidatorPanel.registerValidator(getModel().getDeviceData().compatibleSkinSize(), Validator.Severity.WARNING, "The selected skin is not large enough to view the entire screen.");
}
Also used : SelectedItemProperty(com.android.tools.idea.ui.properties.swing.SelectedItemProperty) IdDisplay(com.android.sdklib.repository.IdDisplay) File(java.io.File) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty) Result(com.android.tools.idea.ui.validation.Validator.Result)

Example 2 with SelectedItemProperty

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

the class ConfigureAvdOptionsStep method bindComponents.

private void bindComponents() {
    myBindings.bindTwoWay(new TextProperty(myAvdDisplayName), getModel().avdDisplayName());
    myBindings.bind(new TextProperty(myAvdId), new StringExpression(getModel().avdDisplayName()) {

        @NotNull
        @Override
        public String get() {
            String displayName = getModel().avdDisplayName().get();
            getModel().avdId().set(StringUtil.isNotEmpty(displayName) ? AvdWizardUtils.cleanAvdName(connection, displayName, !displayName.equals(myOriginalName)) : "");
            return getModel().avdId().get();
        }
    });
    myBindings.bindTwoWay(new TextProperty(mySystemImageName), getModel().systemImageName());
    myBindings.bindTwoWay(new TextProperty(mySystemImageDetails), getModel().systemImageDetails());
    myBindings.bindTwoWay(new SelectedProperty(myQemu2CheckBox), getModel().useQemu2());
    myBindings.bindTwoWay(new SelectedItemProperty<Integer>(myCoreCount), getModel().cpuCoreCount());
    myBindings.bindTwoWay(myRamStorage.storage(), getModel().getAvdDeviceData().ramStorage());
    myBindings.bindTwoWay(myVmHeapStorage.storage(), getModel().vmHeapStorage());
    myBindings.bindTwoWay(myInternalStorage.storage(), getModel().internalStorage());
    myBindings.bindTwoWay(myBuiltInSdCardStorage.storage(), new OptionalToValuePropertyAdapter<Storage>(getModel().sdCardStorage()));
    myBindings.bindTwoWay(new SelectedItemProperty<GpuMode>(myHostGraphics), getModel().hostGpuMode());
    myBindings.bindTwoWay(new SelectedProperty(myDeviceFrameCheckbox), getModel().hasDeviceFrame());
    myBindings.bindTwoWay(new SelectedItemProperty<File>(mySkinComboBox.getComboBox()), getModel().getAvdDeviceData().customSkinFile());
    myOrientationToggle.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            ScreenOrientation orientation = myOrientationToggle.getSelectedElement();
            if (orientation == null) {
                getModel().selectedAvdOrientation().set(ScreenOrientation.PORTRAIT);
            } else {
                getModel().selectedAvdOrientation().set(orientation);
            }
        }
    });
    FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, true);
        }
    };
    fileChooserDescriptor.setHideIgnored(false);
    myExternalSdCard.addBrowseFolderListener("Select SD Card", "Select an existing SD card image", myProject, fileChooserDescriptor);
    myBindings.bindTwoWay(new TextProperty(myExternalSdCard.getTextField()), getModel().externalSdCardLocation());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(new SelectedItemProperty<AvdCamera>(myFrontCameraCombo)), getModel().selectedFrontCamera());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdCamera>(new SelectedItemProperty<AvdCamera>(myBackCameraCombo)), getModel().selectedBackCamera());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdNetworkSpeed>(new SelectedItemProperty<AvdNetworkSpeed>(mySpeedCombo)), getModel().selectedNetworkSpeed());
    myBindings.bindTwoWay(new OptionalToValuePropertyAdapter<AvdNetworkLatency>(new SelectedItemProperty<AvdNetworkLatency>(myLatencyCombo)), getModel().selectedNetworkLatency());
    myBindings.bindTwoWay(new SelectedProperty(myEnableComputerKeyboard), getModel().enableHardwareKeyboard());
    myBindings.bindTwoWay(new SelectedProperty(myExternalRadioButton), getModel().useExternalSdCard());
    myBindings.bindTwoWay(new SelectedProperty(myBuiltInRadioButton), getModel().useBuiltInSdCard());
    myCheckSdForChanges = true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GpuMode(com.android.sdklib.internal.avd.GpuMode) ListSelectionEvent(javax.swing.event.ListSelectionEvent) NotNull(org.jetbrains.annotations.NotNull) TextProperty(com.android.tools.idea.ui.properties.swing.TextProperty) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ListSelectionListener(javax.swing.event.ListSelectionListener) ScreenOrientation(com.android.resources.ScreenOrientation) SelectedItemProperty(com.android.tools.idea.ui.properties.swing.SelectedItemProperty) StringExpression(com.android.tools.idea.ui.properties.expressions.string.StringExpression) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) SelectedProperty(com.android.tools.idea.ui.properties.swing.SelectedProperty)

Example 3 with SelectedItemProperty

use of com.android.tools.idea.ui.properties.swing.SelectedItemProperty 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

SelectedItemProperty (com.android.tools.idea.ui.properties.swing.SelectedItemProperty)3 TextProperty (com.android.tools.idea.ui.properties.swing.TextProperty)3 File (java.io.File)3 SelectedProperty (com.android.tools.idea.ui.properties.swing.SelectedProperty)2 NotNull (org.jetbrains.annotations.NotNull)2 ScreenOrientation (com.android.resources.ScreenOrientation)1 GpuMode (com.android.sdklib.internal.avd.GpuMode)1 IdDisplay (com.android.sdklib.repository.IdDisplay)1 AndroidSourceSet (com.android.tools.idea.npw.project.AndroidSourceSet)1 StringExpression (com.android.tools.idea.ui.properties.expressions.string.StringExpression)1 IconProperty (com.android.tools.idea.ui.properties.swing.IconProperty)1 VisibleProperty (com.android.tools.idea.ui.properties.swing.VisibleProperty)1 Validator (com.android.tools.idea.ui.validation.Validator)1 Result (com.android.tools.idea.ui.validation.Validator.Result)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PopupHandler (com.intellij.ui.PopupHandler)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1