Search in sources :

Example 81 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method doFillTable.

private void doFillTable() {
    Map<SubscriptionDetail, List<ResourceGroup>> srgMap = AzureModel.getInstance().getSubscriptionToResourceGroupMap();
    Map<ResourceGroup, List<WebApp>> rgwaMap = AzureModel.getInstance().getResourceGroupToWebAppMap();
    Map<ResourceGroup, List<AppServicePlan>> rgaspMap = AzureModel.getInstance().getResourceGroupToAppServicePlanMap();
    if (srgMap == null)
        throw new NullPointerException("srgMap is null");
    if (rgwaMap == null)
        throw new NullPointerException("rgwaMap is null");
    if (rgaspMap == null)
        throw new NullPointerException("rgaspMap is null");
    cleanTable();
    DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
    for (SubscriptionDetail sd : srgMap.keySet()) {
        if (!sd.isSelected())
            continue;
        Map<String, WebAppUtils.AspDetails> aspMap = new HashMap<>();
        try {
            for (ResourceGroup rg : srgMap.get(sd)) {
                for (AppServicePlan asp : rgaspMap.get(rg)) {
                    aspMap.put(asp.id(), new WebAppUtils.AspDetails(asp, rg));
                }
            }
        } catch (NullPointerException npe) {
            LOGGER.error("NPE while initializing App Service Plan map", npe);
        }
        for (ResourceGroup rg : srgMap.get(sd)) {
            for (WebApp wa : rgwaMap.get(rg)) {
                if (wa.javaVersion() != JavaVersion.OFF) {
                    tableModel.addRow(new String[] { wa.name(), wa.javaVersion().toString(), wa.javaContainer() + " " + wa.javaContainerVersion(), wa.resourceGroupName() });
                } else {
                    tableModel.addRow(new String[] { wa.name(), "Off", "N/A", wa.resourceGroupName() });
                }
                WebAppDetails webAppDetails = new WebAppDetails();
                webAppDetails.webApp = wa;
                webAppDetails.subscriptionDetail = sd;
                webAppDetails.resourceGroup = rg;
                webAppDetails.appServicePlan = aspMap.get(wa.appServicePlanId()).getAsp();
                webAppDetails.appServicePlanResourceGroup = aspMap.get(wa.appServicePlanId()).getRg();
                webAppWebAppDetailsMap.put(wa.name(), webAppDetails);
            }
        }
    }
    table.setModel(tableModel);
    if (tableModel.getRowCount() > 0)
        tableModel.fireTableDataChanged();
}
Also used : WebAppDetails(com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails) HashMap(java.util.HashMap) DefaultTableModel(javax.swing.table.DefaultTableModel) WebAppUtils(com.microsoft.azuretools.utils.WebAppUtils) AppServicePlan(com.microsoft.azure.management.appservice.AppServicePlan) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) List(java.util.List) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) WebApp(com.microsoft.azure.management.appservice.WebApp)

Example 82 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method deploy.

private void deploy() {
    DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
    int selectedRow = table.getSelectedRow();
    WebAppDetails wad = webAppWebAppDetailsMap.get(tableModel.getValueAt(selectedRow, 0));
    WebApp webApp = wad.webApp;
    boolean isDeployToRoot = deployToRootCheckBox.isSelected();
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Deploy Web App Progress", true) {

        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            AzureDeploymentProgressNotification azureDeploymentProgressNotification = new AzureDeploymentProgressNotification(project);
            try {
                progressIndicator.setIndeterminate(true);
                PublishingProfile pp = webApp.getPublishingProfile();
                Date startDate = new Date();
                azureDeploymentProgressNotification.notifyProgress(webApp.name(), startDate, null, 5, "Deploying Web App...");
                WebAppUtils.deployArtifact(artifact.getName(), artifact.getOutputFilePath(), pp, isDeployToRoot, new UpdateProgressIndicator(progressIndicator));
                String sitePath = buildSiteLink(wad.webApp, isDeployToRoot ? null : artifact.getName());
                progressIndicator.setText("Checking Web App availability...");
                progressIndicator.setText2("Link: " + sitePath);
                azureDeploymentProgressNotification.notifyProgress(webApp.name(), startDate, sitePath, 75, "Checking Web App availability...");
                int stepLimit = 5;
                int sleepMs = 2000;
                // to make warn up cancelable
                Thread thread = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            for (int step = 0; step < stepLimit; ++step) {
                                if (WebAppUtils.isUrlAccessible(sitePath)) {
                                    // warm up
                                    break;
                                }
                                Thread.sleep(sleepMs);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            LOGGER.error("deploy::warmup", e);
                        }
                    }
                });
                thread.start();
                while (thread.isAlive()) {
                    if (progressIndicator.isCanceled())
                        return;
                    else
                        Thread.sleep(sleepMs);
                }
                azureDeploymentProgressNotification.notifyProgress(webApp.name(), startDate, sitePath, 100, message("runStatus"));
                showLink(sitePath);
            } catch (IOException | InterruptedException ex) {
                ex.printStackTrace();
                //LOGGER.error("deploy", ex);
                ApplicationManager.getApplication().invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        ErrorWindow.show(project, ex.getMessage(), "Deploy Web App Error");
                    }
                });
            }
        }
    });
}
Also used : WebAppDetails(com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails) Task(com.intellij.openapi.progress.Task) DefaultTableModel(javax.swing.table.DefaultTableModel) AzureDeploymentProgressNotification(com.microsoft.intellij.deploy.AzureDeploymentProgressNotification) Date(java.util.Date) CanceledByUserException(com.microsoft.azuretools.utils.CanceledByUserException) IOException(java.io.IOException) UpdateProgressIndicator(com.microsoft.azuretools.ijidea.utility.UpdateProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) UpdateProgressIndicator(com.microsoft.azuretools.ijidea.utility.UpdateProgressIndicator) PublishingProfile(com.microsoft.azure.management.appservice.PublishingProfile) WebApp(com.microsoft.azure.management.appservice.WebApp)

Example 83 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project azure-tools-for-java by Microsoft.

the class SubscriptionsDialog method doOKAction.

@Override
protected void doOKAction() {
    DefaultTableModel model = (DefaultTableModel) table.getModel();
    int rc = model.getRowCount();
    int unselectedCount = 0;
    for (int ri = 0; ri < rc; ++ri) {
        boolean selected = (boolean) model.getValueAt(ri, 0);
        if (!selected)
            unselectedCount++;
    }
    if (unselectedCount == rc) {
        JOptionPane.showMessageDialog(contentPane, "Please select at least one subscription", "Subscription dialog info", JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    for (int ri = 0; ri < rc; ++ri) {
        boolean selected = (boolean) model.getValueAt(ri, 0);
        this.sdl.get(ri).setSelected(selected);
    }
    super.doOKAction();
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel)

Example 84 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project azure-tools-for-java by Microsoft.

the class WebAppDeployDialog method deleteAppService.

private void deleteAppService() {
    DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
    int selectedRow = table.getSelectedRow();
    if (selectedRow >= 0) {
        String appServiceName = (String) tableModel.getValueAt(selectedRow, 0);
        WebAppDetails wad = webAppWebAppDetailsMap.get(appServiceName);
        int choice = JOptionPane.showOptionDialog(WebAppDeployDialog.this.getContentPane(), "Do you really want to delete the App Service '" + appServiceName + "'?", "Delete App Service", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (choice == JOptionPane.NO_OPTION) {
            return;
        }
        AppInsightsClient.createByType(AppInsightsClient.EventType.WebApp, appServiceName, "Delete");
        try {
            ProgressManager.getInstance().run(new Task.Modal(project, "Delete App Service Progress", true) {

                @Override
                public void run(ProgressIndicator progressIndicator) {
                    try {
                        progressIndicator.setIndeterminate(true);
                        progressIndicator.setText("Deleting App Service...");
                        WebAppUtils.deleteAppService(wad);
                        ApplicationManager.getApplication().invokeAndWait(new Runnable() {

                            @Override
                            public void run() {
                                tableModel.removeRow(selectedRow);
                                tableModel.fireTableDataChanged();
                                editorPaneAppServiceDetails.setText("");
                            }
                        });
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        //LOGGER.error("deleteAppService : Task.Modal ", ex);
                        ApplicationManager.getApplication().invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                ErrorWindow.show(project, ex.getMessage(), "Delete App Service Error");
                            }
                        });
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            //LOGGER.error("deleteAppService", e);
            ErrorWindow.show(project, e.getMessage(), "Delete App Service Error");
        }
    }
}
Also used : WebAppDetails(com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails) Task(com.intellij.openapi.progress.Task) UpdateProgressIndicator(com.microsoft.azuretools.ijidea.utility.UpdateProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DefaultTableModel(javax.swing.table.DefaultTableModel) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) CanceledByUserException(com.microsoft.azuretools.utils.CanceledByUserException) IOException(java.io.IOException)

Example 85 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project azure-tools-for-java by Microsoft.

the class SubscriptionsDialog method createUIComponents.

private void createUIComponents() {
    DefaultTableModel model = new SubscriptionTableModel();
    model.addColumn("");
    model.addColumn("Subscription name");
    model.addColumn("Subscription ID");
    table = new JBTable();
    table.setModel(model);
    TableColumn column = table.getColumnModel().getColumn(0);
    column.setMinWidth(23);
    column.setMaxWidth(23);
    table.setRowSelectionAllowed(false);
    table.setCellSelectionEnabled(false);
    AnActionButton refreshAction = new AnActionButton("Refresh", AllIcons.Actions.Refresh) {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            AppInsightsClient.createByType(AppInsightsClient.EventType.Subscription, "", "Refresh", null);
            refreshSubscriptions();
        }
    };
    ToolbarDecorator tableToolbarDecorator = ToolbarDecorator.createDecorator(table).disableUpDownActions().addExtraActions(refreshAction);
    panelTable = tableToolbarDecorator.createPanel();
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) TableColumn(javax.swing.table.TableColumn) AnActionButton(com.intellij.ui.AnActionButton)

Aggregations

DefaultTableModel (javax.swing.table.DefaultTableModel)139 JTable (javax.swing.JTable)18 Dimension (java.awt.Dimension)14 Vector (java.util.Vector)14 JScrollPane (javax.swing.JScrollPane)14 TableColumn (javax.swing.table.TableColumn)12 JBTable (com.intellij.ui.table.JBTable)10 Point (java.awt.Point)10 ActionEvent (java.awt.event.ActionEvent)9 JPanel (javax.swing.JPanel)9 ListSelectionEvent (javax.swing.event.ListSelectionEvent)9 ListSelectionListener (javax.swing.event.ListSelectionListener)9 JButton (javax.swing.JButton)8 ActionListener (java.awt.event.ActionListener)7 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)6 Color (java.awt.Color)6 ArrayList (java.util.ArrayList)6 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5