Example usage for org.eclipse.jface.dialogs IMessageProvider ERROR

List of usage examples for org.eclipse.jface.dialogs IMessageProvider ERROR

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IMessageProvider ERROR.

Prototype

int ERROR

To view the source code for org.eclipse.jface.dialogs IMessageProvider ERROR.

Click Source Link

Document

Constant for an error message (value 3).

Usage

From source file:com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerConfigPage.java

License:Open Source License

private boolean validateDockerVMSize() {
    // Docker virtual machine size
    String vmSize = (String) dockerHostVMSizeComboBox.getText();
    if (vmSize == null || vmSize.isEmpty()) {
        hostDetailsTabFolder.setSelection(0);
        String errMsg = "Virtual machine size not set";
        errDispatcher.addMessage("dockerHostVMSizeComboBox", errMsg, null, IMessageProvider.ERROR,
                dockerHostVMSizeComboBox);
        setErrorMessage(errMsg);/*from   w w w.  j a  v  a2  s.  co m*/
        return false;
    } else {
        newHost.hostVM.vmSize = vmSize;
        errDispatcher.removeMessage("dockerHostVMSizeComboBox", dockerHostVMSizeComboBox);
        setErrorMessage(null);
        return true;
    }
}

From source file:com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerConfigPage.java

License:Open Source License

private boolean validateDockerRG() {
    // Docker resource group name
    if (dockerHostNewRGRadioButton.getSelection()) {
        // New resource group
        String rgName = dockerHostRGTextField.getText();
        if (rgName == null || rgName.isEmpty()
                || !AzureDockerValidationUtils.validateDockerHostResourceGroupName(rgName)) {
            hostDetailsTabFolder.setSelection(1);
            errDispatcher.addMessage("dockerHostRGTextField",
                    AzureDockerValidationUtils.getDockerHostResourceGroupNameTip(), null,
                    IMessageProvider.ERROR, dockerHostRGTextField);
            setErrorMessage("Invalid resource group name");
            return false;
        } else {// ww w . j a va 2  s .c  om
            errDispatcher.removeMessage("dockerHostRGTextField", dockerHostRGTextField);
            setErrorMessage(null);
            newHost.hostVM.resourceGroupName = rgName;
            return true;
        }
    } else {
        // Existing resource group
        String rgName = (String) dockerHostSelectRGComboBox.getText();
        if (rgName == null || rgName.isEmpty()) {
            hostDetailsTabFolder.setSelection(1);
            String errMsg = "Resource group not set";
            errDispatcher.addMessage("dockerHostSelectRGComboBox", errMsg, null, IMessageProvider.ERROR,
                    dockerHostSelectRGComboBox);
            setErrorMessage(errMsg);
            return false;
        } else {
            // Add "@" to mark this as an existing resource group
            newHost.hostVM.resourceGroupName = rgName + "@";
            errDispatcher.removeMessage("dockerHostSelectRGComboBox", dockerHostSelectRGComboBox);
            setErrorMessage(null);
            return true;
        }
    }
}

From source file:com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerConfigPage.java

License:Open Source License

private boolean validateDockerVnet() {
    // Docker virtual network name
    if (dockerHostNewVNetRadioButton.getSelection()) {
        // New virtual network
        String vnetName = dockerHostNewVNetNameTextField.getText();
        if (vnetName == null || vnetName.isEmpty()
                || !AzureDockerValidationUtils.validateDockerVnetName(vnetName)) {
            hostDetailsTabFolder.setSelection(2);
            errDispatcher.addMessage("dockerHostNewVNetNameTextField",
                    AzureDockerValidationUtils.getDockerVnetNameTip(), null, IMessageProvider.ERROR,
                    dockerHostNewVNetNameTextField);
            setErrorMessage("Invalid network name");
            return false;
        } else {/*from   www  . jav a 2 s. c  o  m*/
            errDispatcher.removeMessage("dockerHostNewVNetNameTextField", dockerHostNewVNetNameTextField);
            setErrorMessage(null);

            String vnetAddrSpace = dockerHostNewVNetAddrSpaceTextField.getText();
            if (vnetAddrSpace == null || vnetAddrSpace.isEmpty()
                    || !AzureDockerValidationUtils.validateDockerVnetAddrSpace(vnetAddrSpace)) {
                hostDetailsTabFolder.setSelection(2);
                errDispatcher.addMessage("dockerHostNewVNetAddrSpaceTextField",
                        AzureDockerValidationUtils.getDockerVnetAddrspaceTip(), null, IMessageProvider.ERROR,
                        dockerHostNewVNetAddrSpaceTextField);
                setErrorMessage("Invalid address space");
                return false;
            } else {
                errDispatcher.removeMessage("dockerHostNewVNetAddrSpaceTextField",
                        dockerHostNewVNetAddrSpaceTextField);
                setErrorMessage(null);
                newHost.hostVM.vnetName = vnetName;
                newHost.hostVM.vnetAddressSpace = vnetAddrSpace;
                newHost.hostVM.subnetName = "subnet1";
                return true;
            }
        }
    } else {
        // Existing virtual network and subnet
        AzureDockerVnet vnet = (AzureDockerVnet) dockerHostSelectVnetComboBox
                .getData(dockerHostSelectVnetComboBox.getText());
        if (vnet == null || vnet.name == null || vnet.name.isEmpty()) {
            hostDetailsTabFolder.setSelection(2);
            String errMsg = "Network not set";
            errDispatcher.addMessage("dockerHostSelectVnetComboBox", errMsg, null, IMessageProvider.ERROR,
                    dockerHostSelectVnetComboBox);
            setErrorMessage(errMsg);
            return false;
        } else {
            errDispatcher.removeMessage("dockerHostSelectVnetComboBox", dockerHostSelectVnetComboBox);
            setErrorMessage(null);
            String subnet = (String) dockerHostSelectSubnetComboBox.getText();
            if (subnet == null || subnet.isEmpty()) {
                hostDetailsTabFolder.setSelection(2);
                errDispatcher.addMessage("dockerHostSelectSubnetComboBox",
                        AzureDockerValidationUtils.getDockerVnetAddrspaceTip(), null, IMessageProvider.ERROR,
                        dockerHostSelectSubnetComboBox);
                setErrorMessage("Subnet not set");
                return false;
            } else {
                errDispatcher.removeMessage("dockerHostSelectSubnetComboBox", dockerHostSelectSubnetComboBox);
                setErrorMessage(null);
                // Add "@resourceGroupName" to mark this as an existing virtual
                // network
                newHost.hostVM.vnetName = vnet.name + "@" + vnet.resourceGroup;
                newHost.hostVM.vnetAddressSpace = vnet.addrSpace;
                newHost.hostVM.subnetName = subnet;
                return true;
            }
        }
    }
}

From source file:com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerConfigPage.java

License:Open Source License

private boolean validateDockerStorage() {
    // Docker storage account
    String vmSize = (String) dockerHostVMSizeComboBox.getText();
    String storageName;//from ww w  . j  a v a 2  s .  c o  m
    if (dockerHostNewStorageRadioButton.getSelection()) {
        // New storage account
        storageName = dockerNewStorageTextField.getText();
        if (storageName == null || storageName.isEmpty() || vmSize == null || vmSize.isEmpty()
                || !AzureDockerValidationUtils.validateDockerHostStorageName(storageName,
                        getCurrentSubscription())) {
            hostDetailsTabFolder.setSelection(3);
            errDispatcher.addMessage("dockerNewStorageTextField",
                    AzureDockerValidationUtils.getDockerHostStorageNameTip(), null, IMessageProvider.ERROR,
                    dockerNewStorageTextField);
            setErrorMessage("Invalid storage account name");
            return false;
        } else {
            errDispatcher.removeMessage("dockerNewStorageTextField", dockerNewStorageTextField);
            setErrorMessage(null);
            newHost.hostVM.storageAccountName = storageName;
            newHost.hostVM.storageAccountType = AzureDockerUtils.getStorageTypeForVMSize(vmSize);
            return true;
        }
    } else {
        // Existing resource group
        storageName = (String) dockerSelectStorageComboBox.getText();
        if (storageName == null || storageName.isEmpty() || vmSize == null || vmSize.isEmpty()) {
            hostDetailsTabFolder.setSelection(3);
            String errMsg = "Storage account not set";
            errDispatcher.addMessage("dockerSelectStorageComboBox", errMsg, null, IMessageProvider.ERROR,
                    dockerSelectStorageComboBox);
            setErrorMessage(errMsg);
            return false;
        } else {
            errDispatcher.removeMessage("dockerSelectStorageComboBox", dockerSelectStorageComboBox);
            setErrorMessage(null);
            // Add "@" to mark this as an existing storage account
            newHost.hostVM.storageAccountName = storageName + "@";
            newHost.hostVM.storageAccountType = AzureDockerUtils.getStorageTypeForVMSize(vmSize);
            return true;
        }
    }
}

From source file:com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerLoginPage.java

License:Open Source License

private void initUIMainContainer(Composite mainContainer) {
    dockerHostImportKeyvaultCredsRadioButton.addSelectionListener(new SelectionAdapter() {
        @Override//from   ww w.  j av a 2 s.com
        public void widgetSelected(SelectionEvent e) {
            dockerHostImportKeyvaultComboBox.setEnabled(true);
            dockerHostUsernameTextField.setEnabled(false);
            dockerHostFirstPwdField.setEnabled(false);
            dockerHostSecondPwdField.setEnabled(false);
            dockerHostNoSshRadioButton.setEnabled(false);
            dockerHostAutoSshRadioButton.setEnabled(false);
            dockerHostImportSshRadioButton.setEnabled(false);
            dockerHostImportSSHTextField.setEnabled(false);
            dockerHostImportSSHBrowseButton.setEnabled(false);
            dockerHostNoTlsRadioButton.setEnabled(false);
            dockerHostAutoTlsRadioButton.setEnabled(false);
            dockerHostImportTlsRadioButton.setEnabled(false);
            dockerHostImportTLSTextField.setEnabled(false);
            dockerHostImportTLSBrowseButton.setEnabled(false);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostImportKeyvaultComboBox.setEnabled(false);
    for (AzureDockerCertVault certVault : dockerManager.getDockerKeyVaults()) {
        dockerHostImportKeyvaultComboBox.add(certVault.name);
        dockerHostImportKeyvaultComboBox.setData(certVault.name, certVault);
    }
    if (dockerManager.getDockerKeyVaults().size() > 0) {
        dockerHostImportKeyvaultComboBox.select(0);
    }
    dockerHostImportKeyvaultComboBox.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setPageComplete(doValidate());
        }
    });
    dockerHostNewCredsRadioButton.setSelection(true);
    dockerHostNewCredsRadioButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostImportKeyvaultComboBox.setEnabled(false);

            dockerHostUsernameTextField.setEnabled(true);
            dockerHostFirstPwdField.setEnabled(true);
            dockerHostSecondPwdField.setEnabled(true);
            dockerHostNoSshRadioButton.setEnabled(true);
            dockerHostAutoSshRadioButton.setEnabled(true);
            dockerHostImportSshRadioButton.setEnabled(true);
            if (dockerHostImportSshRadioButton.getSelection()) {
                dockerHostImportSSHTextField.setEnabled(true);
                dockerHostImportSSHBrowseButton.setEnabled(true);
            }
            dockerDaemonPortTextField.setEnabled(true);
            dockerHostNoTlsRadioButton.setEnabled(true);
            dockerHostAutoTlsRadioButton.setEnabled(true);
            dockerHostImportTlsRadioButton.setEnabled(true);
            if (dockerHostImportTlsRadioButton.getSelection()) {
                dockerHostImportTLSTextField.setEnabled(true);
                dockerHostImportTLSBrowseButton.setEnabled(true);
            }
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostUsernameTextField.setText(newHost.certVault.vmUsername);
    dockerHostUsernameTextField.setToolTipText(AzureDockerValidationUtils.getDockerHostUserNameTip());
    dockerHostUsernameTextField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerHostUserName(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerHostUsernameTextField", dockerHostUsernameTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostUsernameTextField",
                        AzureDockerValidationUtils.getDockerHostUserNameTip(), null, IMessageProvider.ERROR,
                        dockerHostUsernameTextField);
                setErrorMessage("Invalid user name");
                setPageComplete(false);
            }
        }
    });
    dockerHostFirstPwdField.setToolTipText(AzureDockerValidationUtils.getDockerHostPasswordTip());
    dockerHostFirstPwdField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent event) {
            String text = ((Text) event.getSource()).getText();
            if (text == null || text.isEmpty() || AzureDockerValidationUtils.validateDockerHostPassword(text)) {
                errDispatcher.removeMessage("dockerHostFirstPwdField", dockerHostFirstPwdField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostFirstPwdField",
                        AzureDockerValidationUtils.getDockerHostPasswordTip(), null, IMessageProvider.ERROR,
                        dockerHostFirstPwdField);
                setErrorMessage("Invalid password");
                setPageComplete(false);
            }
        }
    });
    dockerHostSecondPwdField.setToolTipText(AzureDockerValidationUtils.getDockerHostPasswordTip());
    dockerHostSecondPwdField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent event) {
            String pwd1 = dockerHostFirstPwdField.getText();
            String pwd2 = ((Text) event.getSource()).getText();
            if ((pwd1 == null && pwd2 == null) || pwd2.equals(pwd1)) {
                errDispatcher.removeMessage("dockerHostFirstPwdField", dockerHostFirstPwdField);
                errDispatcher.removeMessage("dockerHostSecondPwdField", dockerHostSecondPwdField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostSecondPwdField",
                        AzureDockerValidationUtils.getDockerHostPasswordTip(), null, IMessageProvider.ERROR,
                        dockerHostSecondPwdField);
                setErrorMessage("Invalid confirmation password");
                setPageComplete(false);
            }
        }
    });
    dockerHostNoSshRadioButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostPwdLabel.setText("(Required)");
            dockerHostImportSSHTextField.setEnabled(false);
            dockerHostImportSSHBrowseButton.setEnabled(false);
            errDispatcher.removeMessage("dockerHostImportSSHTextField", dockerHostImportSSHTextField);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostAutoSshRadioButton.setSelection(true);
    dockerHostAutoSshRadioButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostPwdLabel.setText("(Optional)");
            dockerHostImportSSHTextField.setEnabled(false);
            dockerHostImportSSHBrowseButton.setEnabled(false);
            errDispatcher.removeMessage("dockerHostImportSSHTextField", dockerHostImportSSHTextField);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostImportSshRadioButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostPwdLabel.setText("(Optional)");
            dockerHostImportSSHTextField.setEnabled(true);
            dockerHostImportSSHBrowseButton.setEnabled(true);
            setPageComplete(doValidate());
        }
    });
    dockerHostImportSSHTextField.setEnabled(false);
    dockerHostImportSSHTextField.setToolTipText(AzureDockerValidationUtils.getDockerHostSshDirectoryTip());
    dockerHostImportSSHTextField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils
                    .validateDockerHostSshDirectory(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerHostImportSSHTextField", dockerHostImportSSHTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostImportSSHTextField",
                        AzureDockerValidationUtils.getDockerHostSshDirectoryTip(), null, IMessageProvider.ERROR,
                        dockerHostImportSSHTextField);
                setErrorMessage("SSH key files not found in the specified directory");
                setPageComplete(false);
            }
        }
    });
    dockerHostImportSSHBrowseButton.setEnabled(false);
    dockerHostImportSSHBrowseButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog directoryDialog = new DirectoryDialog(dockerHostImportSSHBrowseButton.getShell());
            directoryDialog.setText("Select SSH Keys Directory");
            directoryDialog.setFilterPath(System.getProperty("user.home"));
            String path = directoryDialog.open();
            if (path == null) {
                return;
            }
            dockerHostImportSSHTextField.setText(path);
            setPageComplete(doValidate());
        }
    });
    dockerDaemonPortTextField.setText(newHost.port);
    dockerDaemonPortTextField.setToolTipText(AzureDockerValidationUtils.getDockerHostPortTip());
    dockerDaemonPortTextField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerHostPort(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerDaemonPortTextField", dockerDaemonPortTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerDaemonPortTextField",
                        AzureDockerValidationUtils.getDockerHostPortTip(), null, IMessageProvider.ERROR,
                        dockerDaemonPortTextField);
                setErrorMessage("Invalid Docker daemon port setting");
                setPageComplete(false);
            }
        }
    });
    dockerHostNoTlsRadioButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostImportTLSTextField.setEnabled(false);
            dockerHostImportTLSBrowseButton.setEnabled(false);
            errDispatcher.removeMessage("dockerHostImportTLSTextField", dockerHostImportTLSTextField);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostAutoTlsRadioButton.setSelection(true);
    dockerHostAutoTlsRadioButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostImportTLSTextField.setEnabled(false);
            dockerHostImportTLSBrowseButton.setEnabled(false);
            errDispatcher.removeMessage("dockerHostImportTLSTextField", dockerHostImportTLSTextField);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });
    dockerHostImportTlsRadioButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostImportTLSTextField.setEnabled(true);
            dockerHostImportTLSBrowseButton.setEnabled(true);
            setPageComplete(doValidate());
        }
    });
    dockerHostImportTLSTextField.setEnabled(false);
    dockerHostImportTLSTextField.setToolTipText(AzureDockerValidationUtils.getDockerHostTlsDirectoryTip());
    dockerHostImportTLSTextField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils
                    .validateDockerHostTlsDirectory(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerHostImportTLSTextField", dockerHostImportTLSTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostImportTLSTextField",
                        AzureDockerValidationUtils.getDockerHostTlsDirectoryTip(), null, IMessageProvider.ERROR,
                        dockerHostImportTLSTextField);
                setErrorMessage("TLS certificate files not found in the specified directory");
                setPageComplete(false);
            }
        }
    });
    dockerHostImportTLSBrowseButton.setEnabled(false);
    dockerHostImportTLSBrowseButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog directoryDialog = new DirectoryDialog(dockerHostImportTLSBrowseButton.getShell());
            directoryDialog.setText("Select TLS Certificate Directory");
            directoryDialog.setFilterPath(System.getProperty("user.home"));
            String path = directoryDialog.open();
            if (path == null) {
                return;
            }
            dockerHostImportTLSTextField.setText(path);
            setPageComplete(doValidate());
        }
    });
    dockerHostSaveCredsCheckBox.setSelection(true);
    dockerHostSaveCredsCheckBox.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerHostNewKeyvaultTextField.setEnabled(dockerHostSaveCredsCheckBox.getSelection());
            setPageComplete(doValidate());
        }
    });
    dockerHostNewKeyvaultTextField.setText(newHost.certVault.name);
    dockerHostNewKeyvaultTextField.setToolTipText(AzureDockerValidationUtils.getDockerHostKeyvaultNameTip());
    dockerHostNewKeyvaultTextField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerHostKeyvaultName(((Text) event.getSource()).getText(),
                    dockerManager, false)) {
                errDispatcher.removeMessage("dockerHostNewKeyvaultTextField", dockerHostNewKeyvaultTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerHostNewKeyvaultTextField",
                        AzureDockerValidationUtils.getDockerHostPortTip(), null, IMessageProvider.ERROR,
                        dockerHostNewKeyvaultTextField);
                setErrorMessage("Invalid key vault name");
                setPageComplete(false);
            }
        }
    });

}

From source file:com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerLoginPage.java

License:Open Source License

public boolean doValidate() {
    if (dockerHostImportKeyvaultCredsRadioButton.getSelection()) {
        // read key vault secrets and set the credentials for the new host
        AzureDockerCertVault certVault = null;
        if (dockerHostImportKeyvaultComboBox.getItemCount() > 0) {
            certVault = (AzureDockerCertVault) dockerHostImportKeyvaultComboBox
                    .getData(dockerHostImportKeyvaultComboBox.getText());
        }/*from ww  w . java 2  s  .  com*/
        if (certVault == null) {
            errDispatcher.addMessage("dockerHostImportKeyvaultComboBox",
                    AzureDockerValidationUtils.getDockerHostKeyvaultNameTip(), null, IMessageProvider.ERROR,
                    dockerHostImportKeyvaultComboBox);
            setErrorMessage("No Key Vault found");
            return false;
        } else {
            errDispatcher.removeMessage("dockerHostImportKeyvaultComboBox", dockerHostImportKeyvaultComboBox);
            setErrorMessage(null);
            newHost.certVault.name = certVault.name;
            newHost.certVault.resourceGroupName = certVault.resourceGroupName;
            newHost.certVault.region = certVault.region;
            newHost.certVault.uri = certVault.uri;
            AzureDockerCertVaultOps.copyVaultLoginCreds(newHost.certVault, certVault);
            AzureDockerCertVaultOps.copyVaultSshKeys(newHost.certVault, certVault);
            AzureDockerCertVaultOps.copyVaultTlsCerts(newHost.certVault, certVault);
            // create a weak link (resource tag) between the virtual machine and
            // the key vault
            // we will not create/update the key vault unless the user checks
            // the specific option
            newHost.certVault.hostName = null;
            newHost.hasKeyVault = true;
        }
    } else {
        // reset key vault info
        newHost.hasKeyVault = false;
        newHost.certVault.name = null;
        newHost.certVault.uri = null;

        // User name
        String vmUsername = dockerHostUsernameTextField.getText();
        if (vmUsername == null || vmUsername.isEmpty()
                || !AzureDockerValidationUtils.validateDockerHostUserName(vmUsername)) {
            errDispatcher.addMessage("dockerHostUsernameTextField",
                    AzureDockerValidationUtils.getDockerHostUserNameTip(), null, IMessageProvider.ERROR,
                    dockerHostUsernameTextField);
            setErrorMessage("Invalid user name");
            credsTabfolder.setSelection(0);
            return false;
        } else {
            errDispatcher.removeMessage("dockerHostUsernameTextField", dockerHostUsernameTextField);
            setErrorMessage(null);
            newHost.certVault.vmUsername = vmUsername;
        }

        // Password login
        String vmPwd1 = dockerHostFirstPwdField.getText();
        String vmPwd2 = dockerHostSecondPwdField.getText();
        if ((dockerHostNoSshRadioButton.getSelection() || (vmPwd1 != null && !vmPwd1.isEmpty())
                || (vmPwd2 != null && !vmPwd2.isEmpty()))
                && (vmPwd1.isEmpty() || vmPwd2.isEmpty() || !vmPwd1.equals(vmPwd2)
                        || !AzureDockerValidationUtils.validateDockerHostPassword(vmPwd1))) {
            errDispatcher.addMessage("dockerHostFirstPwdField",
                    AzureDockerValidationUtils.getDockerHostPasswordTip(), null, IMessageProvider.ERROR,
                    dockerHostFirstPwdField);
            setErrorMessage("Invalid password");
            credsTabfolder.setSelection(0);
            return false;
        } else {
            errDispatcher.removeMessage("dockerHostFirstPwdField", dockerHostFirstPwdField);
            errDispatcher.removeMessage("dockerHostSecondPwdField", dockerHostSecondPwdField);
            setErrorMessage(null);
            if (vmPwd1 == null || vmPwd1.isEmpty()) {
                newHost.certVault.vmPwd = null;
                newHost.hasPwdLogIn = false;
            } else {
                newHost.certVault.vmPwd = vmPwd1;
                newHost.hasPwdLogIn = true;
            }
        }

        if (dockerHostNoSshRadioButton.getSelection()) {
            newHost.hasSSHLogIn = false;
            newHost.certVault.sshKey = null;
            newHost.certVault.sshPubKey = null;
        }

        // SSH key auto generated
        if (dockerHostAutoSshRadioButton.getSelection()) {
            AzureDockerCertVault certVault = AzureDockerCertVaultOps.generateSSHKeys(null,
                    "SSH keys for " + newHost.name);
            AzureDockerCertVaultOps.copyVaultSshKeys(newHost.certVault, certVault);
            newHost.hasSSHLogIn = true;
        }

        // SSH key imported from local file directory
        if (dockerHostImportSshRadioButton.getSelection()) {
            String sshPath = dockerHostImportSSHTextField.getText();
            if (sshPath == null || sshPath.isEmpty()
                    || !AzureDockerValidationUtils.validateDockerHostSshDirectory(sshPath)) {
                errDispatcher.addMessage("dockerHostImportSSHTextField",
                        AzureDockerValidationUtils.getDockerHostSshDirectoryTip(), null, IMessageProvider.ERROR,
                        dockerHostImportSSHTextField);
                setErrorMessage("SSH key files not found in the specified directory");
                credsTabfolder.setSelection(0);
                return false;
            } else {
                try {
                    AzureDockerCertVault certVault = AzureDockerCertVaultOps.getSSHKeysFromLocalFile(sshPath);
                    AzureDockerCertVaultOps.copyVaultSshKeys(newHost.certVault, certVault);
                    newHost.hasSSHLogIn = true;
                } catch (Exception e) {
                    errDispatcher.addMessage("dockerHostImportSSHTextField",
                            AzureDockerValidationUtils.getDockerHostPasswordTip(), null, IMessageProvider.ERROR,
                            dockerHostImportSSHTextField);
                    setErrorMessage("Unexpected error reading SSH key files from specified directory: "
                            + e.getMessage());
                    return false;
                }
                errDispatcher.removeMessage("dockerHostImportSSHTextField", dockerHostImportSSHTextField);
                setErrorMessage(null);
            }
        }

        // No Docker daemon security
        if (dockerHostNoTlsRadioButton.getSelection()) {
            newHost.isTLSSecured = false;
        }

        // TLS certs auto generated
        if (dockerHostAutoTlsRadioButton.getSelection()) {
            errDispatcher.removeMessage("dockerHostImportTLSTextField", dockerHostImportTLSTextField);
            setErrorMessage(null);
            AzureDockerCertVault certVault = AzureDockerCertVaultOps
                    .generateTLSCerts("TLS certs for " + newHost.name);
            AzureDockerCertVaultOps.copyVaultTlsCerts(newHost.certVault, certVault);
            newHost.isTLSSecured = true;
        }

        // TLS certs imported from local file directory
        if (dockerHostImportTlsRadioButton.getSelection()) {
            String tlsPath = dockerHostImportTLSTextField.getText();
            if (tlsPath == null || tlsPath.isEmpty()
                    || !AzureDockerValidationUtils.validateDockerHostTlsDirectory(tlsPath)) {
                errDispatcher.addMessage("dockerHostImportTLSTextField",
                        AzureDockerValidationUtils.getDockerHostTlsDirectoryTip(), null, IMessageProvider.ERROR,
                        dockerHostImportTLSTextField);
                setErrorMessage("TLS certificate files not found in the specified directory");
                credsTabfolder.setSelection(1);
                return false;
            } else {
                errDispatcher.removeMessage("dockerHostImportTLSTextField", dockerHostImportTLSTextField);
                setErrorMessage(null);
                AzureDockerCertVault certVault = AzureDockerCertVaultOps.getTLSCertsFromLocalFile(tlsPath);
                AzureDockerCertVaultOps.copyVaultTlsCerts(newHost.certVault, certVault);
                newHost.isTLSSecured = true;
            }
        }

    }

    // Docker daemon port settings
    String port = dockerDaemonPortTextField.getText();
    if (port == null || port.isEmpty() || !AzureDockerValidationUtils.validateDockerHostPort(port)) {
        errDispatcher.addMessage("dockerDaemonPortTextField", AzureDockerValidationUtils.getDockerHostPortTip(),
                null, IMessageProvider.ERROR, dockerDaemonPortTextField);
        setErrorMessage("Invalid Docker daemon port setting");
        credsTabfolder.setSelection(1);
        return false;
    } else {
        errDispatcher.removeMessage("dockerDaemonPortTextField", dockerDaemonPortTextField);
        setErrorMessage(null);
        newHost.port = dockerDaemonPortTextField.getText();
    }

    // create new key vault for storing the credentials
    if (dockerHostSaveCredsCheckBox.getSelection()) {
        String newKeyvault = dockerHostNewKeyvaultTextField.getText();
        if (newKeyvault == null || newKeyvault.isEmpty() || !AzureDockerValidationUtils
                .validateDockerHostKeyvaultName(newKeyvault, dockerManager, true)) {
            errDispatcher.addMessage("dockerHostNewKeyvaultTextField",
                    AzureDockerValidationUtils.getDockerHostPortTip(), null, IMessageProvider.ERROR,
                    dockerHostNewKeyvaultTextField);
            setErrorMessage("Invalid Key Vault name");
            return false;
        } else {
            errDispatcher.removeMessage("dockerHostNewKeyvaultTextField", dockerHostNewKeyvaultTextField);
            setErrorMessage(null);
            newHost.hasKeyVault = true;
            newHost.certVault.name = dockerHostNewKeyvaultTextField.getText();
            newHost.certVault.hostName = (newHost.name != null) ? newHost.name : null;
            newHost.certVault.region = (newHost.hostVM.region != null) ? newHost.hostVM.region : null;
            newHost.certVault.resourceGroupName = (newHost.hostVM.resourceGroupName != null)
                    ? newHost.hostVM.resourceGroupName
                    : null;
            newHost.certVault.uri = (newHost.hostVM.region != null && newHost.hostVM.resourceGroupName != null)
                    ? "https://" + newHost.certVault.name + ".vault.azure.net"
                    : null;
        }
    } else {
        errDispatcher.removeMessage("dockerHostNewKeyvaultTextField", dockerHostNewKeyvaultTextField);
        setErrorMessage(null);
        newHost.certVault.hostName = null;
    }

    return true;
}

From source file:com.microsoft.azuretools.docker.ui.wizards.publish.AzureConfigureDockerContainerStep.java

License:Open Source License

private void initUIMainContainer(Composite mainContainer) {

    dockerContainerNameTextField.setText(dockerImageDescription.dockerContainerName);
    dockerContainerNameTextField.setToolTipText(AzureDockerValidationUtils.getDockerContainerNameTip());
    dockerContainerNameTextField.addModifyListener(new ModifyListener() {
        @Override//from   w  ww .  j a va 2s  . c o  m
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerContainerName(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerContainerNameTextField", dockerContainerNameTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerContainerNameTextField",
                        AzureDockerValidationUtils.getDockerContainerNameTip(), null, IMessageProvider.ERROR,
                        dockerContainerNameTextField);
                setErrorMessage("Invalid Docker container name");
                setPageComplete(false);
            }
        }
    });

    predefinedDockerfileRadioButton.setSelection(true);
    predefinedDockerfileRadioButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerfileComboBox.setEnabled(true);
            customDockerfileTextField.setEnabled(false);
            customDockerfileBrowseButton.setEnabled(false);
            errDispatcher.removeMessage("customDockerfileTextField", customDockerfileTextField);
            setErrorMessage(null);
            setPageComplete(doValidate());
        }
    });

    int idx = 0;
    boolean selected = false;
    for (KnownDockerImages predefinedImage : dockerManager.getDefaultDockerImages()) {
        // Add predefined images that can run .WAR as default
        if (!predefinedImage.isCanRunJarFile()) {
            dockerfileComboBox.add(predefinedImage.getName());
            dockerfileComboBox.setData(predefinedImage.getName(), predefinedImage);
            if (dockerImageDescription.predefinedDockerfile != null
                    && dockerImageDescription.predefinedDockerfile.equals(predefinedImage)) {
                dockerfileComboBox.select(idx);
                selected = true;
            }
            idx++;
        }
    }
    if (!selected) {
        dockerfileComboBox.select(0);
    }
    dockerfileComboBox.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerContainerPortSettings.setText(getDefaultPortMapping(
                    (KnownDockerImages) dockerfileComboBox.getData(dockerfileComboBox.getText())));
            setPageComplete(doValidate());
        }
    });

    customDockerfileRadioButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dockerfileComboBox.setEnabled(false);
            customDockerfileTextField.setEnabled(true);
            customDockerfileBrowseButton.setEnabled(true);
            setPageComplete(doValidate());
        }
    });

    customDockerfileTextField.setToolTipText(AzureDockerValidationUtils.getDockerfilePathTip());
    customDockerfileTextField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerfilePath(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("customDockerfileTextField", customDockerfileTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("customDockerfileTextField",
                        AzureDockerValidationUtils.getDockerfilePathTip(), null, IMessageProvider.ERROR,
                        customDockerfileTextField);
                setErrorMessage("Invalid Dockerfile location");
                setPageComplete(false);
            }
        }
    });
    customDockerfileBrowseButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialog = new FileDialog(customDockerfileBrowseButton.getShell(), SWT.OPEN);
            fileDialog.setText("Select Custom Dockerfile");
            fileDialog.setFilterPath(System.getProperty("user.home"));
            fileDialog.setFilterExtensions(new String[] { "Dockerfile", "*.*" });
            String path = fileDialog.open();
            if (path == null) {
                return;
            }
            customDockerfileTextField.setText(path);
            setPageComplete(doValidate());
        }
    });

    dockerContainerPortSettings.setText(getDefaultPortMapping(
            (KnownDockerImages) dockerfileComboBox.getData(dockerfileComboBox.getText())));
    dockerContainerPortSettings.setToolTipText(AzureDockerValidationUtils.getDockerPortSettingsTip());
    dockerContainerPortSettings.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils
                    .validateDockerPortSettings(((Text) event.getSource()).getText()) != null) {
                errDispatcher.removeMessage("dockerContainerPortSettings", dockerContainerPortSettings);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerContainerPortSettings",
                        AzureDockerValidationUtils.getDockerPortSettingsTip(), null, IMessageProvider.ERROR,
                        dockerContainerPortSettings);
                setErrorMessage("Invalid Docker container port settings");
                setPageComplete(false);
            }
        }
    });
}

From source file:com.microsoft.azuretools.docker.ui.wizards.publish.AzureConfigureDockerContainerStep.java

License:Open Source License

public boolean doValidate() {
    if (dockerContainerNameTextField.getText() == null || dockerContainerNameTextField.getText().equals("")
            || !AzureDockerValidationUtils
                    .validateDockerContainerName(dockerContainerNameTextField.getText())) {
        errDispatcher.addMessage("dockerContainerNameTextField",
                AzureDockerValidationUtils.getDockerContainerNameTip(), null, IMessageProvider.ERROR,
                dockerContainerNameTextField);
        setErrorMessage("Invalid Docker container name");
        return false;
    } else {/*  ww  w  . jav a 2s  .  co m*/
        errDispatcher.removeMessage("dockerContainerNameTextField", dockerContainerNameTextField);
        setErrorMessage(null);
        dockerImageDescription.dockerContainerName = dockerContainerNameTextField.getText();
    }

    if (predefinedDockerfileRadioButton.getSelection()) {
        KnownDockerImages dockerfileImage = (KnownDockerImages) dockerfileComboBox
                .getData(dockerfileComboBox.getText());
        if (dockerfileImage == null) {
            errDispatcher.addMessage("dockerfileComboBox", "Missing predefined Dockerfile options", null,
                    IMessageProvider.ERROR, dockerfileComboBox);
            setErrorMessage("Invalid Dockerfile selection");
            return false;
        } else {
            errDispatcher.removeMessage("dockerfileComboBox", dockerfileComboBox);
            setErrorMessage(null);
            dockerImageDescription.predefinedDockerfile = dockerfileImage.name();
            if (dockerImageDescription.artifactPath != null) {
                dockerImageDescription.dockerfileContent = dockerfileImage.getDockerfileContent().replace(
                        KnownDockerImages.DOCKER_ARTIFACT_FILENAME,
                        new File(dockerImageDescription.artifactPath).getName());
            }
        }
    }

    if (customDockerfileRadioButton.getSelection()) {
        String dockerfileName = customDockerfileTextField.getText();
        if (dockerfileName == null || dockerfileName.equals("") || Files.notExists(Paths.get(dockerfileName))) {
            errDispatcher.addMessage("customDockerfileTextField",
                    AzureDockerValidationUtils.getDockerfilePathTip(), null, IMessageProvider.ERROR,
                    customDockerfileTextField);
            setErrorMessage("Invalid Docker container name");
            return false;
        } else {
            try {
                dockerImageDescription.dockerfileContent = new String(
                        Files.readAllBytes(Paths.get(dockerfileName)));
            } catch (Exception e) {
                errDispatcher.addMessage("customDockerfileTextField",
                        AzureDockerValidationUtils.getDockerfilePathTip(), null, IMessageProvider.ERROR,
                        customDockerfileTextField);
                setErrorMessage("Error reading Dockerfile content");
                return false;
            }
            errDispatcher.removeMessage("customDockerfileTextField", customDockerfileTextField);
            setErrorMessage(null);
            dockerImageDescription.predefinedDockerfile = null;
        }
    }

    if (dockerContainerPortSettings.getText() == null || dockerContainerPortSettings.getText().equals("")
            || AzureDockerValidationUtils
                    .validateDockerPortSettings(dockerContainerPortSettings.getText()) == null) {
        errDispatcher.addMessage("dockerContainerPortSettings",
                AzureDockerValidationUtils.getDockerPortSettingsTip(), null, IMessageProvider.ERROR,
                dockerContainerPortSettings);
        setErrorMessage("Invalid Docker container port settings");
        return false;
    } else {
        errDispatcher.removeMessage("dockerContainerPortSettings", dockerContainerPortSettings);
        setErrorMessage(null);
        dockerImageDescription.dockerPortSettings = dockerContainerPortSettings.getText();
    }

    return true;
}

From source file:com.microsoft.azuretools.docker.ui.wizards.publish.AzureSelectDockerHostPage.java

License:Open Source License

private void initUIMainContainer(Composite mainContainer) {

    dockerImageNameTextField.setText(dockerImageDescription.dockerImageName);
    dockerImageNameTextField.setToolTipText(AzureDockerValidationUtils.getDockerImageNameTip());
    dockerImageNameTextField.addModifyListener(new ModifyListener() {
        @Override/*w w  w. ja v a2 s.co m*/
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerImageName(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerImageNameTextField", dockerImageNameTextField);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerImageNameTextField",
                        AzureDockerValidationUtils.getDockerImageNameTip(), null, IMessageProvider.ERROR,
                        dockerImageNameTextField);
                setErrorMessage("Invalid Docker image name");
                setPageComplete(false);
            }
        }
    });

    String artifactPath;
    if (project != null) {
        try {
            String projectName = project.getName();
            artifactPath = project.getLocation() + "/" + projectName + ".war";
        } catch (Exception ignored) {
            artifactPath = "";
        }
    } else {
        artifactPath = "";
    }

    if (artifactPath == null || artifactPath.isEmpty() || !Files.isRegularFile(Paths.get(artifactPath))) {
        errDispatcher.addMessage("dockerArtifactPathTextField",
                AzureDockerValidationUtils.getDockerArtifactPathTip(), null, IMessageProvider.ERROR,
                dockerArtifactPathTextField);
        setErrorMessage("Invalid artifact path");
    } else {
        dockerArtifactPathTextField.setText(artifactPath);
    }
    dockerArtifactPathTextField.setToolTipText(AzureDockerValidationUtils.getDockerArtifactPathTip());
    dockerArtifactPathTextField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent event) {
            if (AzureDockerValidationUtils.validateDockerArtifactPath(((Text) event.getSource()).getText())) {
                errDispatcher.removeMessage("dockerArtifactPathTextField", dockerArtifactPathTextField);
                String artifactFileName = new File(((Text) event.getSource()).getText()).getName();
                wizard.setPredefinedDockerfileOptions(artifactFileName);
                setErrorMessage(null);
                setPageComplete(doValidate());
            } else {
                errDispatcher.addMessage("dockerArtifactPathTextField",
                        AzureDockerValidationUtils.getDockerArtifactPathTip(), null, IMessageProvider.ERROR,
                        dockerArtifactPathTextField);
                setErrorMessage("Invalid artifact path");
                setPageComplete(false);
            }
        }
    });

    dockerArtifactPathBrowseButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialog = new FileDialog(dockerArtifactPathBrowseButton.getShell(), SWT.OPEN);
            fileDialog.setText("Select Artifact .WAR or .JAR");
            fileDialog.setFilterPath(System.getProperty("user.home"));
            fileDialog.setFilterExtensions(new String[] { "*.war;*.jar", "*.jar", "*.*" });
            String path = fileDialog.open();
            if (path == null
                    || (!path.toLowerCase().contains(".war") && !path.toLowerCase().contains(".jar"))) {
                return;
            }
            dockerArtifactPathTextField.setText(path);
            String artifactFileName = new File(path).getName();
            wizard.setPredefinedDockerfileOptions(artifactFileName);
            setPageComplete(doValidate());
        }
    });

    TableViewerColumn colHostName = createTableViewerColumn(dockerHostsTableViewer, "Name", 150, 1);
    colHostName.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ((DockerHost) element).name;
        }
    });
    TableViewerColumn colHostState = createTableViewerColumn(dockerHostsTableViewer, "State", 80, 2);
    colHostState.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            DockerHost dockerHost = (DockerHost) element;
            return dockerHost.hostVM.state != null ? dockerHost.hostVM.state.toString() : "TO_BE_CREATED";
        }
    });
    TableViewerColumn colHostOS = createTableViewerColumn(dockerHostsTableViewer, "OS", 200, 3);
    colHostOS.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ((DockerHost) element).hostOSType.toString();
        }
    });
    TableViewerColumn colHostApiUrl = createTableViewerColumn(dockerHostsTableViewer, "API URL", 250, 4);
    colHostApiUrl.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return ((DockerHost) element).apiUrl.toString();
        }
    });
    dockerHostsTableViewer.setContentProvider(new ArrayContentProvider());
    dockerHostsList = new ArrayList<>();
    dockerHostsTableViewer.setInput(dockerHostsList);
    refreshDockerHostsTable(mainContainer);
    if (!dockerHostsList.isEmpty()) {
        if (dockerHostsTableSelection == null) {
            dockerHostsTable.select(0);
            dockerHostsTable.getItem(0).setChecked(true);
            dockerHostsTableSelection = new DockerHostsTableSelection();
            dockerHostsTableSelection.row = 0;
            dockerHostsTableSelection.host = (DockerHost) dockerHostsTable.getItem(0).getData();
        } else {
            dockerHostsTable.select(dockerHostsTableSelection.row);
            dockerHostsTable.getItem(dockerHostsTableSelection.row).setChecked(true);
        }
    } else {
        dockerHostsTableSelection = null;
        setPageComplete(false);
    }

    dockerHostsTable.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.CHECK) {
                DockerHost dockerHost = (DockerHost) ((TableItem) e.item).getData();
                if (dockerHostsTableSelection == null || dockerHostsTableSelection.host != dockerHost) {
                    dockerHostsTableSelection = new DockerHostsTableSelection();
                    dockerHostsTableSelection.row = dockerHostsTable.indexOf((TableItem) e.item);
                    dockerHostsTableSelection.host = dockerHost;
                    for (TableItem tableItem : dockerHostsTable.getItems()) {
                        if (tableItem != ((TableItem) e.item) && tableItem.getChecked()) {
                            tableItem.setChecked(false);
                        }
                    }
                    dockerHostsTable.redraw();
                } else {
                    dockerHostsTableSelection = null;
                }
                setPageComplete(doValidate());
            }
        }
    });

    dockerHostsRefreshButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            AzureDockerUIResources.updateAzureResourcesWithProgressDialog(mainContainer.getShell(), project);
            refreshDockerHostsTable(mainContainer);
            setPageComplete(doValidate());
        }
    });

    dockerHostsViewButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int idx = dockerHostsTable.getSelectionIndex();
            if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
                DockerHost dockerHost = (DockerHost) dockerHostsTable
                        .getItem(dockerHostsTable.getSelectionIndex()).getData();
                if (dockerHost != null) {
                    AzureViewDockerDialog viewDockerDialog = new AzureViewDockerDialog(mainContainer.getShell(),
                            project, dockerHost, dockerManager);
                    viewDockerDialog.open();

                    if (viewDockerDialog.getInternalExitCode() == AzureViewDockerDialog.UPDATE_EXIT_CODE) {
                        if (dockerHost != null && !dockerHost.isUpdating) {
                            AzureDockerUIResources.updateDockerHost(PluginUtil.getParentShell(), project,
                                    new EditableDockerHost(dockerHost), dockerManager, true);
                        } else {
                            PluginUtil.displayErrorDialog(mainContainer.getShell(),
                                    "Error: Invalid Edit Selection",
                                    "The selected Docker host can not be edited at this time!");
                        }
                    }
                    setPageComplete(doValidate());
                }
            }
        }
    });

    dockerHostsAddButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            AzureNewDockerWizard newDockerWizard = new AzureNewDockerWizard(project, dockerManager);
            WizardDialog createNewDockerHostDialog = new WizardDialog(mainContainer.getShell(),
                    newDockerWizard);
            if (createNewDockerHostDialog.open() == Window.OK) {
                DockerHost host = newDockerWizard.getDockerHost();
                dockerImageDescription.host = host;
                dockerImageDescription.hasNewDockerHost = true;
                dockerImageDescription.sid = host.sid;

                AzureDockerPreferredSettings dockerPrefferedSettings = dockerManager
                        .getDockerPreferredSettings();
                if (dockerPrefferedSettings == null) {
                    dockerPrefferedSettings = new AzureDockerPreferredSettings();
                }
                dockerPrefferedSettings.region = host.hostVM.region;
                dockerPrefferedSettings.vmSize = host.hostVM.vmSize;
                dockerPrefferedSettings.vmOS = host.hostOSType.name();
                dockerManager.setDockerPreferredSettings(dockerPrefferedSettings);

                dockerHostsList.add(0, host);

                dockerHostsTable.setEnabled(false);
                dockerHostsRefreshButton.setEnabled(false);
                dockerHostsAddButton.setEnabled(false);
                dockerHostsDeleteButton.setEnabled(false);
                dockerHostsEditButton.setEnabled(false);
                dockerHostsTableViewer.refresh();
                dockerHostsTable.getItem(0).setChecked(true);
                dockerHostsTable.select(0);
            }
            setPageComplete(doValidate());
        }
    });

    dockerHostsDeleteButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            //dockerHostsList
            int idx = dockerHostsTable.getSelectionIndex();

            if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
                DockerHost deleteHost = (DockerHost) dockerHostsTable.getItem(idx).getData();
                if (deleteHost != null) {
                    Azure azureClient = dockerManager.getSubscriptionsMap().get(deleteHost.sid).azureClient;
                    int option = AzureDockerUIResources.deleteAzureDockerHostConfirmationDialog(
                            mainContainer.getShell(), azureClient, deleteHost);

                    if (option != 1 && option != 2) {
                        if (AzureDockerUtils.DEBUG)
                            System.out.format("User canceled delete Docker host op: %d\n", option);
                        return;
                    }
                    dockerHostsList.remove(deleteHost);
                    if (dockerHostsTableSelection != null && dockerHostsTableSelection.row == idx) {
                        dockerHostsTableSelection = null;
                    }
                    dockerHostsTableViewer.refresh();

                    AzureDockerUIResources.deleteDockerHost(mainContainer.getShell(), project, azureClient,
                            deleteHost, option, new Runnable() {
                                @Override
                                public void run() {
                                    dockerManager.getDockerHostsList().remove(deleteHost);
                                    dockerManager.refreshDockerHostDetails();
                                    DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
                                        @Override
                                        public void run() {
                                            refreshDockerHostsTable(mainContainer);
                                        }
                                    });
                                }
                            });
                }
                setPageComplete(doValidate());
            }
        }
    });

    dockerHostsEditButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            int idx = dockerHostsTable.getSelectionIndex();
            if (idx >= 0 && dockerHostsTable.getItem(idx) != null) {
                DockerHost updateHost = (DockerHost) dockerHostsTable.getItem(idx).getData();
                if (updateHost != null && !updateHost.isUpdating) {
                    AzureDockerUIResources.updateDockerHost(PluginUtil.getParentShell(), project,
                            new EditableDockerHost(updateHost), dockerManager, true);
                } else {
                    PluginUtil.displayErrorDialog(mainContainer.getShell(), "Error: Invalid Edit Selection",
                            "The selected Docker host can not be edited at this time!");
                }
            }
            setPageComplete(doValidate());
        }
    });
}

From source file:com.microsoft.azuretools.docker.ui.wizards.publish.AzureSelectDockerHostPage.java

License:Open Source License

public boolean doValidate() {
    if (dockerImageNameTextField.getText() == null || dockerImageNameTextField.getText().equals("")) {
        errDispatcher.addMessage("dockerImageNameTextField", AzureDockerValidationUtils.getDockerImageNameTip(),
                null, IMessageProvider.ERROR, dockerImageNameTextField);
        setErrorMessage("Invalid Docker image name");
        return false;
    } else {// ww w .  j a  v  a 2  s . c  o m
        errDispatcher.removeMessage("dockerImageNameTextField", dockerImageNameTextField);
        setErrorMessage(null);
        dockerImageDescription.dockerImageName = dockerImageNameTextField.getText();
        wizard.setDockerContainerName(
                AzureDockerUtils.getDefaultDockerContainerName(dockerImageDescription.dockerImageName));
    }

    String artifactPath = dockerArtifactPathTextField.getText();
    if (artifactPath == null || !AzureDockerValidationUtils.validateDockerArtifactPath(artifactPath)) {
        errDispatcher.addMessage("dockerArtifactPathTextField",
                AzureDockerValidationUtils.getDockerArtifactPathTip(), null, IMessageProvider.ERROR,
                dockerArtifactPathTextField);
        setErrorMessage("Invalid artifact path");
        return false;
    } else {
        String artifactFileName = new File(artifactPath).getName();
        dockerImageDescription.artifactName = artifactFileName.indexOf(".") > 0
                ? artifactFileName.substring(0, artifactFileName.lastIndexOf("."))
                : "";
        if (dockerImageDescription.artifactName.isEmpty()) {
            errDispatcher.addMessage("dockerArtifactPathTextField",
                    AzureDockerValidationUtils.getDockerArtifactPathTip(), null, IMessageProvider.ERROR,
                    dockerArtifactPathTextField);
            setErrorMessage("Invalid artifact path: missing file name");
            return false;
        }
        dockerImageDescription.artifactPath = artifactPath;
        dockerImageDescription.hasRootDeployment = artifactFileName.toLowerCase().matches(".*.jar");
        errDispatcher.removeMessage("dockerArtifactPathTextField", dockerArtifactPathTextField);
        setErrorMessage(null);
    }

    if (dockerHostsTableSelection == null && !dockerImageDescription.hasNewDockerHost) {
        String errMsg = "Missing check for the Docker host to publish into";
        errDispatcher.addMessage("dockerHostsTable", errMsg, null, IMessageProvider.ERROR, dockerHostsTable);
        setErrorMessage(errMsg);
        return false;
    } else {
        errDispatcher.removeMessage("dockerHostsTable", dockerHostsTable);
        setErrorMessage(null);
        dockerImageDescription.dockerImageName = dockerImageNameTextField.getText();
    }

    if (!dockerImageDescription.hasNewDockerHost) {
        dockerImageDescription.host = dockerHostsTableSelection.host;
        dockerImageDescription.sid = dockerImageDescription.host.sid;
    }

    return true;
}