use of com.microsoft.azuretools.core.components.AzureWizardDialog 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);
}
});
}
use of com.microsoft.azuretools.core.components.AzureWizardDialog in project azure-tools-for-java by Microsoft.
the class AzureDockerUIResources method publish2DockerHostContainer.
public static void publish2DockerHostContainer(Shell shell, IProject project, DockerHost host) {
try {
AzureDockerUIResources.createArtifact(shell, project);
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;
}
DockerHost dockerHost = (host != null) ? host : (dockerManager.getDockerPreferredSettings() != null) ? dockerManager.getDockerHostForURL(dockerManager.getDockerPreferredSettings().dockerApiName) : null;
AzureDockerImageInstance dockerImageDescription = dockerManager.getDefaultDockerImageDescription(project.getName(), dockerHost);
AzureSelectDockerWizard selectDockerWizard = new AzureSelectDockerWizard(project, dockerManager, dockerImageDescription);
WizardDialog selectDockerHostDialog = new AzureWizardDialog(shell, selectDockerWizard);
if (dockerHost != null) {
selectDockerWizard.selectDefaultDockerHost(dockerHost, true);
}
if (selectDockerHostDialog.open() == Window.OK) {
try {
String url = selectDockerWizard.deploy();
if (AzureDockerUtils.DEBUG)
System.out.println("Web app published at: " + url);
} catch (Exception ex) {
PluginUtil.displayErrorDialogAndLog(shell, "Unexpected error detected while publishing to a Docker container", ex.getMessage(), ex);
log.log(Level.SEVERE, "publish2DockerHostContainer: " + ex.getMessage(), ex);
}
}
} catch (Exception e) {
log.log(Level.SEVERE, "publish2DockerHostContainer: " + e.getMessage(), e);
e.printStackTrace();
}
}
use of com.microsoft.azuretools.core.components.AzureWizardDialog in project azure-tools-for-java by Microsoft.
the class CreateArmVMAction method actionPerformed.
@Override
public void actionPerformed(NodeActionEvent e) {
SignInCommandHandler.requireSignedIn(PluginUtil.getParentShell(), () -> {
CreateVMWizard createVMWizard = new CreateVMWizard((VMArmModule) e.getAction().getNode());
WizardDialog dialog = new AzureWizardDialog(PluginUtil.getParentShell(), createVMWizard);
dialog.setTitle("Create new Virtual Machine");
dialog.create();
dialog.open();
});
}
use of com.microsoft.azuretools.core.components.AzureWizardDialog 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();
}
}
Aggregations