Search in sources :

Example 1 with AzureNewDockerWizard

use of com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerWizard in project azure-tools-for-java by Microsoft.

the class AzureSelectDockerHostPage method initUIMainContainer.

private void initUIMainContainer(Composite mainContainer) {
    dockerImageNameTextField.setText(dockerImageDescription.dockerImageName);
    dockerImageNameTextField.setToolTipText(AzureDockerValidationUtils.getDockerImageNameTip());
    dockerImageNameTextField.addModifyListener(new ModifyListener() {

        @Override
        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());
            sendButtonClickedTelemetry(REFRESH);
        }
    });
    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());
                }
            }
            sendButtonClickedTelemetry(VIEW);
        }
    });
    dockerHostsAddButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            AzureNewDockerWizard newDockerWizard = new AzureNewDockerWizard(project, dockerManager);
            WizardDialog createNewDockerHostDialog = new AzureWizardDialog(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());
            sendButtonClickedTelemetry(ADD);
        }
    });
    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());
            }
            sendButtonClickedTelemetry(DELETE);
        }
    });
    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());
            sendButtonClickedTelemetry(EDIT);
        }
    });
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) TableItem(org.eclipse.swt.widgets.TableItem) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ModifyEvent(org.eclipse.swt.events.ModifyEvent) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Azure(com.microsoft.azure.management.Azure) AzureNewDockerWizard(com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerWizard) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) AzureDockerPreferredSettings(com.microsoft.azure.docker.model.AzureDockerPreferredSettings) AzureViewDockerDialog(com.microsoft.azuretools.docker.ui.dialogs.AzureViewDockerDialog) EditableDockerHost(com.microsoft.azure.docker.model.EditableDockerHost) DockerHost(com.microsoft.azure.docker.model.DockerHost) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog)

Example 2 with AzureNewDockerWizard

use of com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerWizard in project azure-tools-for-java by Microsoft.

the class CreateNewDockerHostAction method actionPerformed.

@Override
public void actionPerformed(NodeActionEvent event) {
    try {
        if (!SignInCommandHandler.doSignIn(PluginUtil.getParentShell()))
            return;
        IProject project;
        Shell shell = PluginUtil.getParentShell();
        try {
            project = AzureDockerUIResources.getCurrentSelectedProject();
        } catch (Exception Ignored) {
            project = null;
        }
        if (project == null) {
            project = (IProject) dockerHostModule.getProject();
        }
        AzureManager azureAuthManager = AuthMethodManager.getInstance().getAzureManager();
        // not signed in
        if (azureAuthManager == null) {
            return;
        }
        AzureDockerHostsManager dockerManager = AzureDockerHostsManager.getAzureDockerHostsManager(azureAuthManager);
        if (!dockerManager.isInitialized()) {
            AzureDockerUIResources.updateAzureResourcesWithProgressDialog(shell, project);
            if (AzureDockerUIResources.CANCELED) {
                return;
            }
            dockerManager = AzureDockerHostsManager.getAzureDockerHostsManagerEmpty(null);
        }
        if (dockerManager.getSubscriptionsMap().isEmpty()) {
            PluginUtil.displayErrorDialog(shell, "Create Docker Host", "Must select an Azure subscription first");
            return;
        }
        AzureNewDockerWizard newDockerWizard = new AzureNewDockerWizard(project, dockerManager);
        WizardDialog createNewDockerHostDialog = new AzureWizardDialog(shell, newDockerWizard);
        if (createNewDockerHostDialog.open() == Window.OK) {
            newDockerWizard.createHost();
        }
    } catch (Exception ex1) {
        log.log(Level.SEVERE, "actionPerformed", ex1);
        ex1.printStackTrace();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) AzureNewDockerWizard(com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerWizard) AzureDockerHostsManager(com.microsoft.azure.docker.AzureDockerHostsManager) AzureWizardDialog(com.microsoft.azuretools.core.components.AzureWizardDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IProject(org.eclipse.core.resources.IProject)

Aggregations

AzureWizardDialog (com.microsoft.azuretools.core.components.AzureWizardDialog)2 AzureNewDockerWizard (com.microsoft.azuretools.docker.ui.wizards.createhost.AzureNewDockerWizard)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 AzureDockerHostsManager (com.microsoft.azure.docker.AzureDockerHostsManager)1 AzureDockerPreferredSettings (com.microsoft.azure.docker.model.AzureDockerPreferredSettings)1 DockerHost (com.microsoft.azure.docker.model.DockerHost)1 EditableDockerHost (com.microsoft.azure.docker.model.EditableDockerHost)1 Azure (com.microsoft.azure.management.Azure)1 AzureViewDockerDialog (com.microsoft.azuretools.docker.ui.dialogs.AzureViewDockerDialog)1 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)1 File (java.io.File)1 IProject (org.eclipse.core.resources.IProject)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)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