Search in sources :

Example 6 with KnownDockerImages

use of com.microsoft.azure.docker.model.KnownDockerImages in project azure-tools-for-java by Microsoft.

the class AzureConfigureDockerContainerStep method doValidate.

private ValidationInfo doValidate(Boolean shakeOnError) {
    if (dockerContainerNameTextField.getText() == null || dockerContainerNameTextField.getText().equals("") || !AzureDockerValidationUtils.validateDockerContainerName(dockerContainerNameTextField.getText())) {
        ValidationInfo info = new ValidationInfo("Please name your Docker container", dockerContainerNameTextField);
        dockerContainerNameLabel.setVisible(true);
        setDialogButtonsState(false);
        if (shakeOnError)
            model.getSelectDockerWizardDialog().DialogShaker(info);
        return info;
    }
    dockerContainerNameLabel.setVisible(false);
    dockerImageDescription.dockerContainerName = dockerContainerNameTextField.getText();
    dockerContainerNameLabel.setVisible(false);
    if (predefinedDockerfileRadioButton.isSelected()) {
        KnownDockerImages dockerfileImage = (KnownDockerImages) dockerfileComboBox.getSelectedItem();
        if (dockerfileImage == null) {
            ValidationInfo info = new ValidationInfo("Please select a Docker image type form the list", dockerfileComboBox);
            setDialogButtonsState(false);
            if (shakeOnError)
                model.getSelectDockerWizardDialog().DialogShaker(info);
            return info;
        }
        dockerImageDescription.predefinedDockerfile = dockerfileImage.name();
        if (dockerImageDescription.artifactPath != null) {
            dockerImageDescription.dockerfileContent = dockerfileImage.getDockerfileContent().replace(KnownDockerImages.DOCKER_ARTIFACT_FILENAME, new File(dockerImageDescription.artifactPath).getName());
        }
    }
    if (customDockerfileRadioButton.isSelected()) {
        String dockerfileName = customDockerfileBrowseButton.getText();
        if (dockerfileName == null || dockerfileName.equals("") || Files.notExists(Paths.get(dockerfileName))) {
            ValidationInfo info = new ValidationInfo("Dockerfile not found", customDockerfileBrowseButton);
            customDockerfileBrowseLabel.setVisible(true);
            setDialogButtonsState(false);
            if (shakeOnError)
                model.getSelectDockerWizardDialog().DialogShaker(info);
            return info;
        }
        dockerImageDescription.predefinedDockerfile = null;
        try {
            dockerImageDescription.dockerfileContent = new String(Files.readAllBytes(Paths.get(customDockerfileBrowseButton.getText())));
            customDockerfileBrowseLabel.setVisible(true);
        } catch (Exception e) {
            customDockerfileBrowseLabel.setVisible(true);
            setDialogButtonsState(false);
            String errTitle = "Error reading Dockerfile content";
            String msg = "An error occurred while attempting to get the content of " + customDockerfileBrowseButton.getText() + "\n" + e.getMessage();
            if (AzureDockerUtils.DEBUG)
                e.printStackTrace();
            LOGGER.error("doValidate", e);
            PluginUtil.displayErrorDialog(errTitle, msg);
            return new ValidationInfo(errTitle, customDockerfileBrowseButton);
        }
    }
    if (dockerContainerPortSettings.getText() == null || dockerContainerPortSettings.getText().equals("") || AzureDockerValidationUtils.validateDockerPortSettings(dockerContainerPortSettings.getText()) == null) {
        ValidationInfo info = new ValidationInfo("Invalid port settings", dockerContainerPortSettings);
        if (shakeOnError)
            model.getSelectDockerWizardDialog().DialogShaker(info);
        dockerContainerPortSettingsLabel.setVisible(true);
        setDialogButtonsState(false);
        return info;
    }
    dockerImageDescription.dockerPortSettings = dockerContainerPortSettings.getText();
    setDialogButtonsState(true);
    return null;
}
Also used : ValidationInfo(com.intellij.openapi.ui.ValidationInfo) KnownDockerImages(com.microsoft.azure.docker.model.KnownDockerImages) File(java.io.File)

Aggregations

KnownDockerImages (com.microsoft.azure.docker.model.KnownDockerImages)6 File (java.io.File)2 ValidationInfo (com.intellij.openapi.ui.ValidationInfo)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 Text (org.eclipse.swt.widgets.Text)1