Search in sources :

Example 16 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class CreateRedisCacheForm method createDialogArea.

/**
     * Create contents of the dialog.
     * 
     * @param parent
     */
@Override
protected Control createDialogArea(Composite parent) {
    resourceBundle = MessageHandler.getResourceBundle(MODULE_NAME);
    if (resourceBundle == null) {
        return null;
    }
    setTitle(MessageHandler.getResourceString(resourceBundle, DIALOG_TITLE));
    setMessage(MessageHandler.getResourceString(resourceBundle, DIALOG_MESSAGE));
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    GridLayout glContainer = new GridLayout(4, false);
    glContainer.horizontalSpacing = LAYOUT_SPACING;
    glContainer.verticalSpacing = LAYOUT_SPACING;
    container.setLayout(glContainer);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    Label lblDnsName = new Label(container, SWT.NONE);
    lblDnsName.setText(MessageHandler.getResourceString(resourceBundle, LABEL_DNS_NAME));
    txtDnsName = new Text(container, SWT.BORDER);
    txtDnsName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    decoratorDnsName = new ControlDecoration(txtDnsName, SWT.CENTER);
    decoratorDnsName.setDescriptionText(MessageHandler.getResourceString(resourceBundle, DECORACTOR_DNS));
    FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
    if (fieldDecoration != null) {
        Image image = fieldDecoration.getImage();
        decoratorDnsName.setImage(image);
    }
    Label lblDnsSuffix = new Label(container, SWT.NONE);
    lblDnsSuffix.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    lblDnsSuffix.setText(MessageHandler.getResourceString(resourceBundle, LABEL_DNS_SUFFIX));
    Label lblSubscription = new Label(container, SWT.NONE);
    lblSubscription.setText(MessageHandler.getResourceString(resourceBundle, LABEL_SUBSCRIPTION));
    cbSubs = new Combo(container, SWT.READ_ONLY);
    cbSubs.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    Label lblResourceGroup = new Label(container, SWT.NONE);
    lblResourceGroup.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
    lblResourceGroup.setText(MessageHandler.getResourceString(resourceBundle, LABEL_RESOURCE_GRP));
    rdoCreateNew = new Button(container, SWT.RADIO);
    rdoCreateNew.setText(MessageHandler.getResourceString(resourceBundle, RADIOBUTTON_NEW_GRP));
    rdoCreateNew.setSelection(true);
    txtNewResGrpName = new Text(container, SWT.BORDER);
    txtNewResGrpName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    txtNewResGrpName.setEnabled(true);
    rdoUseExisting = new Button(container, SWT.RADIO);
    rdoUseExisting.setText(MessageHandler.getResourceString(resourceBundle, RADIOBUTTON_USE_EXIST_GRP));
    rdoUseExisting.setSelection(false);
    cbUseExisting = new Combo(container, SWT.READ_ONLY);
    cbUseExisting.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    cbUseExisting.add(MessageHandler.getResourceString(resourceBundle, LOADING));
    cbUseExisting.select(0);
    cbUseExisting.setEnabled(false);
    Label lblLocation = new Label(container, SWT.NONE);
    lblLocation.setText(MessageHandler.getResourceString(resourceBundle, LABEL_LOCTION));
    cbLocations = new Combo(container, SWT.READ_ONLY);
    cbLocations.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    cbLocations.add(MessageHandler.getResourceString(resourceBundle, LOADING));
    cbLocations.select(0);
    cbLocations.setEnabled(false);
    Label lblPricingTier = new Label(container, SWT.READ_ONLY);
    lblPricingTier.setText(MessageHandler.getResourceString(resourceBundle, LABEL_PRICING));
    cbPricetiers = new Combo(container, SWT.READ_ONLY);
    cbPricetiers.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    if (skus.keySet().size() > 0) {
        for (String price : skus.keySet()) {
            cbPricetiers.add(price);
        }
        cbPricetiers.select(0);
        selectedPriceTierValue = cbPricetiers.getText();
    }
    Link lnkPrice = new Link(container, SWT.NONE);
    lnkPrice.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
    lnkPrice.setText(MessageHandler.getResourceString(resourceBundle, LINK_PRICE));
    lnkPrice.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            try {
                PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(event.text));
            } catch (Exception ex) {
                LOG.log(MessageHandler.getCommonStr(OPEN_BROWSER_ERROR), ex);
            }
        }
    });
    chkUnblockPort = new Button(container, SWT.CHECK);
    chkUnblockPort.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
    chkUnblockPort.setText(MessageHandler.getResourceString(resourceBundle, CHECKBOX_SSL));
    this.setHelpAvailable(false);
    txtDnsName.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent arg0) {
            dnsNameValue = txtDnsName.getText();
            if (dnsNameValue.length() > REDIS_CACHE_MAX_NAME_LENGTH || !dnsNameValue.matches(DNS_NAME_REGEX)) {
                decoratorDnsName.show();
            } else {
                decoratorDnsName.hide();
            }
            validateFields();
        }
    });
    for (SubscriptionDetail sub : selectedSubscriptions) {
        cbSubs.add(String.format(SUBS_COMBO_ITEMS_FORMAT, sub.getSubscriptionName(), sub.getSubscriptionId()));
    }
    cbSubs.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            currentSub = selectedSubscriptions.get(cbSubs.getSelectionIndex());
            if (loaded) {
                fillLocationsAndResourceGrps(currentSub);
            }
            validateFields();
        }
    });
    if (selectedSubscriptions.size() > 0) {
        cbSubs.select(0);
    }
    rdoCreateNew.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            txtNewResGrpName.setEnabled(true);
            cbUseExisting.setEnabled(false);
            newResGrp = true;
            selectedResGrpValue = txtNewResGrpName.getText();
            validateFields();
        }
    });
    rdoUseExisting.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            txtNewResGrpName.setEnabled(false);
            cbUseExisting.setEnabled(true);
            if (loaded) {
                newResGrp = false;
                selectedResGrpValue = sortedGroups.get(cbUseExisting.getSelectionIndex());
                validateFields();
            }
        }
    });
    txtNewResGrpName.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent arg0) {
            selectedResGrpValue = txtNewResGrpName.getText();
            validateFields();
        }
    });
    cbUseExisting.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedResGrpValue = cbUseExisting.getText();
            validateFields();
        }
    });
    cbLocations.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedLocationValue = sortedLocations.get(cbLocations.getSelectionIndex()).name();
            validateFields();
        }
    });
    cbPricetiers.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedPriceTierValue = cbPricetiers.getText();
            validateFields();
        }
    });
    chkUnblockPort.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Button btn = (Button) e.getSource();
            if (btn.getSelection()) {
                noSSLPort = true;
            } else {
                noSSLPort = false;
            }
        }
    });
    DefaultLoader.getIdeHelper().runInBackground(null, MessageHandler.getResourceString(resourceBundle, LOADING_LOCATION_AND_GRPS), false, true, MessageHandler.getResourceString(resourceBundle, LOADING_LOCATION_AND_GRPS), new Runnable() {

        @Override
        public void run() {
            try {
                AzureModelController.updateSubscriptionMaps(null);
                DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        fillLocationsAndResourceGrps(currentSub);
                        cbLocations.setEnabled(true);
                        loaded = true;
                        validateFields();
                    }
                });
            } catch (Exception ex) {
                LOG.log(MessageHandler.getCommonStr(LOAD_LOCATION_AND_RESOURCE_ERROR), ex);
            }
        }
    });
    return area;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) IOException(java.io.IOException) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) Link(org.eclipse.swt.widgets.Link)

Example 17 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class AppServiceCreateDialog method fillAppServicePlans.

protected void fillAppServicePlans() {
    DefaultComboBoxModel<SubscriptionDetail> cbModelSub = (DefaultComboBoxModel<SubscriptionDetail>) comboBoxSubscription.getModel();
    SubscriptionDetail sd = (SubscriptionDetail) cbModelSub.getSelectedItem();
    if (sd == null) {
        // empty
        System.out.println("No subscription is selected");
        return;
    }
    List<ResourceGroup> rgl = AzureModel.getInstance().getSubscriptionToResourceGroupMap().get(sd);
    if (rgl == null) {
        System.out.println("rgl is null");
        return;
    }
    DefaultComboBoxModel<AppServicePlanAdapter> cbModel = new DefaultComboBoxModel<AppServicePlanAdapter>();
    for (ResourceGroup rg : rgl) {
        List<AppServicePlan> aspl = AzureModel.getInstance().getResourceGroupToAppServicePlanMap().get(rg);
        for (AppServicePlan asp : aspl) {
            if (asp.pricingTier().toSkuDescription().tier().compareToIgnoreCase("dynamic") == 0) {
                continue;
            }
            cbModel.addElement(new AppServicePlanAdapter(asp));
        }
    }
    comboBoxAppServicePlan.setModel(cbModel);
}
Also used : SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan)

Example 18 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class AppServiceCreateDialog method doValidate.

@Nullable
@Override
protected ValidationInfo doValidate() {
    model.collectData();
    String webappName = model.webAppName;
    if (webappName.length() > 60 || !webappName.matches("^[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9]$")) {
        StringBuilder builder = new StringBuilder();
        builder.append("The name can contain letters, numbers and hyphens but the first and last characters must be a letter or number. ");
        builder.append("The length can be between 2 and 60 characters. ");
        return new ValidationInfo(builder.toString(), textFieldWebappName);
    } else {
        for (List<WebApp> wal : AzureModel.getInstance().getResourceGroupToWebAppMap().values()) {
            for (WebApp wa : wal) {
                if (wa.name().toLowerCase().equals(webappName.toLowerCase())) {
                    return new ValidationInfo("The name is already taken", textFieldWebappName);
                }
            }
        }
    }
    if (model.subscriptionDetail == null) {
        return new ValidationInfo("Select a valid subscription.", comboBoxSubscription);
    }
    if (model.isAppServicePlanCreateNew) {
        if (model.appServicePlanNameCreateNew.isEmpty()) {
            return new ValidationInfo("Enter a valid App Service Plan name.", textFieldAppServicePlanName);
        } else {
            if (!model.appServicePlanNameCreateNew.matches("^[A-Za-z0-9-]*[A-Za-z0-9-]$")) {
                return new ValidationInfo("App Service Plan name can only include alphanumeric characters and hyphens.", textFieldAppServicePlanName);
            }
            // App service plan name must be unuque in each subscription
            SubscriptionDetail sd = model.subscriptionDetail;
            List<ResourceGroup> rgl = AzureModel.getInstance().getSubscriptionToResourceGroupMap().get(sd);
            for (ResourceGroup rg : rgl) {
                List<AppServicePlan> aspl = AzureModel.getInstance().getResourceGroupToAppServicePlanMap().get(rg);
                for (AppServicePlan asp : aspl) {
                    if (asp.name().toLowerCase().equals(model.appServicePlanNameCreateNew.toLowerCase())) {
                        return new ValidationInfo("App service plan name must be unuque in each subscription.", textFieldAppServicePlanName);
                    }
                }
            }
        }
        if (model.appServicePlanLocationCreateNew == null) {
            return new ValidationInfo("Select a valid App Service Plan Location.", comboBoxAppServicePlanLocation);
        }
        if (model.appServicePricingTierCreateNew == null) {
            return new ValidationInfo("Select a valid App Service Plan PricingTier.", comboBoxAppServicePlanPricingTier);
        }
    } else {
        if (model.appServicePlan == null) {
            return new ValidationInfo("Select a valid App Service Plan.", comboBoxResourceGroup);
        }
    }
    if (model.isResourceGroupCreateNew) {
        if (model.resourceGroupNameCreateNew.isEmpty()) {
            return new ValidationInfo("Enter a valid resource group name", textFieldResourceGroupName);
        } else {
            if (!model.resourceGroupNameCreateNew.matches("^[A-Za-z0-9-_()\\.]*[A-Za-z0-9-_()]$")) {
                return new ValidationInfo("Resounce group name can only include alphanumeric characters, periods, underscores, hyphens, and parenthesis and can't end in a period.", textFieldResourceGroupName);
            }
            for (List<ResourceGroup> rgl : AzureModel.getInstance().getSubscriptionToResourceGroupMap().values()) {
                for (ResourceGroup rg : rgl) {
                    if (rg.name().toLowerCase().equals(model.resourceGroupNameCreateNew.toLowerCase())) {
                        return new ValidationInfo("The name is already taken", textFieldResourceGroupName);
                    }
                }
            }
        }
    } else {
        if (model.resourceGroup == null) {
            return new ValidationInfo("Select a valid resource group.", comboBoxResourceGroup);
        }
    }
    ValidationInfo res = validateJdkTab();
    if (res != null)
        return res;
    return super.doValidate();
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) WebApp(com.microsoft.azure.management.appservice.WebApp) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class AppServiceCreateDialog method fillAppServicePlanLocations.

protected void fillAppServicePlanLocations() {
    try {
        DefaultComboBoxModel<SubscriptionDetail> cbModelSub = (DefaultComboBoxModel<SubscriptionDetail>) comboBoxSubscription.getModel();
        SubscriptionDetail sd = (SubscriptionDetail) cbModelSub.getSelectedItem();
        if (sd == null) {
            // empty
            System.out.println("No subscription is selected");
            return;
        }
        Map<SubscriptionDetail, List<Location>> sdlocMap = AzureModel.getInstance().getSubscriptionToLocationMap();
        List<Location> locl = sdlocMap.get(sd);
        DefaultComboBoxModel<LocationAdapter> cbModel = new DefaultComboBoxModel<LocationAdapter>();
        cbModel.addElement(new NullLocationAdapter());
        for (Location l : locl) {
            cbModel.addElement(new LocationAdapter(l));
        }
        comboBoxAppServicePlanLocation.setModel(cbModel);
    } catch (Exception ex) {
        ex.printStackTrace();
        LOGGER.error("fillAppServicePlanLocations@AppServiceCreateDialog", ex);
    }
}
Also used : SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) IOException(java.io.IOException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException) CloudException(com.microsoft.azure.CloudException) Location(com.microsoft.azure.management.resources.Location)

Example 20 with SubscriptionDetail

use of com.microsoft.azuretools.authmanage.models.SubscriptionDetail in project azure-tools-for-java by Microsoft.

the class SrvPriSettingsDialog method createDialogArea.

/**
     * Create contents of the dialog.
     * @param parent
     */
@Override
protected Control createDialogArea(Composite parent) {
    setTitle("Create Authentication Files");
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    Label lblInfo = new Label(container, SWT.WRAP);
    GridData gd_lblInfo = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    gd_lblInfo.heightHint = 82;
    lblInfo.setLayoutData(gd_lblInfo);
    lblInfo.setText("A new Active Directory service principal representing this IDE will be created as needed and as allowed by your access permissions.\nThe service principal will be granted Contributor-level access to each selected subscription.");
    Label lblNewLabel = new Label(container, SWT.NONE);
    lblNewLabel.setEnabled(true);
    lblNewLabel.setText("Select the subscriptions to create credentials for:");
    table = new Table(container, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION);
    table.setEnabled(true);
    GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_table.heightHint = 300;
    table.setLayoutData(gd_table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableColumn tblclmnSubscriptionName = new TableColumn(table, SWT.NONE);
    tblclmnSubscriptionName.setWidth(250);
    tblclmnSubscriptionName.setText("Subscription Name");
    TableColumn tblclmnSubscriptionId = new TableColumn(table, SWT.NONE);
    tblclmnSubscriptionId.setWidth(300);
    tblclmnSubscriptionId.setText("Subscription ID");
    for (SubscriptionDetail sd : sdl) {
        TableItem item = new TableItem(table, SWT.NULL);
        item.setText(new String[] { sd.getSubscriptionName(), sd.getSubscriptionId() });
        item.setChecked(sd.isSelected());
    }
    Group grpDestinationFolder = new Group(container, SWT.NONE);
    grpDestinationFolder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    grpDestinationFolder.setText("Destination folder:");
    grpDestinationFolder.setLayout(new GridLayout(2, false));
    textDestinationFolderPath = new Text(grpDestinationFolder, SWT.BORDER | SWT.READ_ONLY);
    textDestinationFolderPath.setEditable(false);
    textDestinationFolderPath.setEnabled(true);
    textDestinationFolderPath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    String initDirPath = System.getProperty("user.home");
    textDestinationFolderPath.setText(initDirPath);
    dirDialog = new DirectoryDialog(this.getShell());
    dirDialog.setFilterPath(initDirPath);
    dirDialog.setText("Select Destination Folder");
    Button btnBrowse = new Button(grpDestinationFolder, SWT.NONE);
    btnBrowse.setEnabled(true);
    btnBrowse.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String path = dirDialog.open();
            if (path == null)
                return;
            textDestinationFolderPath.setText(path);
        }
    });
    btnBrowse.setText("...");
    return area;
}
Also used : Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TableItem(org.eclipse.swt.widgets.TableItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Aggregations

SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)52 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)17 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)13 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)13 IOException (java.io.IOException)9 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)7 Location (com.microsoft.azure.management.resources.Location)7 List (java.util.List)7 WebApp (com.microsoft.azure.management.appservice.WebApp)5 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Azure (com.microsoft.azure.management.Azure)4 Subscription (com.microsoft.azure.management.resources.Subscription)4 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)4 HashMap (java.util.HashMap)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridData (org.eclipse.swt.layout.GridData)4 Label (org.eclipse.swt.widgets.Label)4 AccessTokenAzureManager (com.microsoft.azuretools.sdkmanage.AccessTokenAzureManager)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3