Search in sources :

Example 51 with JBScrollPane

use of com.intellij.ui.components.JBScrollPane in project azure-tools-for-java by Microsoft.

the class SparkSubmissionToolWindowProcessor method initialize.

public void initialize() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    UISettings.getInstance().addUISettingsListener(new UISettingsListener() {

        @Override
        public void uiSettingsChanged(UISettings uiSettings) {
            synchronized (this) {
                for (IHtmlElement htmlElement : cachedInfo) {
                    htmlElement.ChangeTheme();
                }
                setToolWindowText(parserHtmlElementList(cachedInfo));
            }
        }
    }, ApplicationManager.getApplication());
    fontFace = jEditorPanel.getFont().getFamily();
    JPanel jPanel = new JPanel();
    jPanel.setLayout(new GridBagLayout());
    jEditorPanel.setMargin(new Insets(0, 10, 0, 0));
    JBScrollPane scrollPane = new JBScrollPane(jEditorPanel);
    stopButton = new JButton(PluginUtil.getIcon(CommonConst.StopIconPath));
    stopButton.setDisabledIcon(PluginUtil.getIcon(CommonConst.StopDisableIconPath));
    stopButton.setEnabled(false);
    stopButton.setToolTipText("stop execution of current application");
    stopButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DefaultLoader.getIdeHelper().executeOnPooledThread(new Runnable() {

                @Override
                public void run() {
                    if (clusterDetail != null) {
                        AppInsightsClient.create(HDInsightBundle.message("SparkSubmissionStopButtionClickEvent"), null);
                        try {
                            HttpResponse deleteResponse = SparkBatchSubmission.getInstance().killBatchJob(SparkSubmitHelper.getLivyConnectionURL(clusterDetail), batchId);
                            if (deleteResponse.getCode() == 201 || deleteResponse.getCode() == 200) {
                                jobStatusManager.setJobKilled();
                                setInfo("========================Stop application successfully=======================");
                            } else {
                                setError(String.format("Error : Failed to stop spark application. error code : %d, reason :  %s.", deleteResponse.getCode(), deleteResponse.getContent()));
                            }
                        } catch (IOException exception) {
                            setError("Error : Failed to stop spark application. exception : " + exception.toString());
                        }
                    }
                }
            });
        }
    });
    openSparkUIButton = new JButton(PluginUtil.getIcon(CommonConst.OpenSparkUIIconPath));
    openSparkUIButton.setDisabledIcon(PluginUtil.getIcon(CommonConst.OpenSparkUIDisableIconPath));
    openSparkUIButton.setEnabled(false);
    openSparkUIButton.setToolTipText("open the corresponding Spark UI page");
    openSparkUIButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (Desktop.isDesktopSupported()) {
                try {
                    if (jobStatusManager.isApplicationGenerated()) {
                        String connectionURL = clusterDetail.getConnectionUrl();
                        String sparkApplicationUrl = clusterDetail.isEmulator() ? String.format(yarnRunningUIEmulatorUrlFormat, ((EmulatorClusterDetail) clusterDetail).getSparkHistoryEndpoint(), jobStatusManager.getApplicationId()) : String.format(yarnRunningUIUrlFormat, connectionURL, jobStatusManager.getApplicationId());
                        Desktop.getDesktop().browse(new URI(sparkApplicationUrl));
                    }
                } catch (Exception browseException) {
                    DefaultLoader.getUIHelper().showError("Failed to browse spark application yarn url", "Spark Submission");
                }
            }
        }
    });
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
    buttonPanel.add(stopButton);
    buttonPanel.add(openSparkUIButton);
    GridBagConstraints c00 = new GridBagConstraints();
    c00.fill = GridBagConstraints.VERTICAL;
    c00.weighty = 1;
    c00.gridx = 0;
    c00.gridy = 0;
    jPanel.add(buttonPanel, c00);
    GridBagConstraints c10 = new GridBagConstraints();
    c10.fill = GridBagConstraints.BOTH;
    c10.weightx = 1;
    c10.weighty = 1;
    c10.gridx = 1;
    c10.gridy = 0;
    jPanel.add(scrollPane, c10);
    toolWindow.getComponent().add(jPanel);
    jEditorPanel.setEditable(false);
    jEditorPanel.setOpaque(false);
    jEditorPanel.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"));
    jEditorPanel.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        String protocol = e.getURL().getProtocol();
                        if (protocol.equals("https") || protocol.equals("http")) {
                            Desktop.getDesktop().browse(e.getURL().toURI());
                        } else if (protocol.equals("file")) {
                            String path = e.getURL().getFile();
                            File localFile = new File(path);
                            File parentFile = localFile.getParentFile();
                            if (parentFile.exists() && parentFile.isDirectory()) {
                                Desktop.getDesktop().open(parentFile);
                            }
                        }
                    } catch (Exception exception) {
                        DefaultLoader.getUIHelper().showError(exception.getMessage(), "Open Local Folder Error");
                    }
                }
            }
        }
    });
    PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            if (ApplicationManager.getApplication().isDispatchThread()) {
                changeSupportHandler(evt);
            } else {
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {

                        @Override
                        public void run() {
                            changeSupportHandler(evt);
                        }
                    });
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }

        private void changeSupportHandler(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("toolWindowText")) {
                jEditorPanel.setText(evt.getNewValue().toString());
            } else if (evt.getPropertyName().equals("isStopButtonEnable")) {
                stopButton.setEnabled(Boolean.parseBoolean(evt.getNewValue().toString()));
            } else if (evt.getPropertyName().equals("isBrowserButtonEnable")) {
                openSparkUIButton.setEnabled(Boolean.parseBoolean(evt.getNewValue().toString()));
            }
        }
    };
    jEditorPanel.addPropertyChangeListener(propertyChangeListener);
    changeSupport = new PropertyChangeSupport(jEditorPanel);
    changeSupport.addPropertyChangeListener(propertyChangeListener);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) PropertyChangeSupport(java.beans.PropertyChangeSupport) URI(java.net.URI) UISettings(com.intellij.ide.ui.UISettings) HyperlinkListener(javax.swing.event.HyperlinkListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) HttpResponse(com.microsoft.azure.hdinsight.sdk.common.HttpResponse) IOException(java.io.IOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ActionListener(java.awt.event.ActionListener) UISettingsListener(com.intellij.ide.ui.UISettingsListener) File(java.io.File) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Aggregations

JBScrollPane (com.intellij.ui.components.JBScrollPane)51 ActionEvent (java.awt.event.ActionEvent)7 Nullable (org.jetbrains.annotations.Nullable)7 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 JBList (com.intellij.ui.components.JBList)6 ListSelectionEvent (javax.swing.event.ListSelectionEvent)6 ListSelectionListener (javax.swing.event.ListSelectionListener)5 JBTable (com.intellij.ui.table.JBTable)4 Tree (com.intellij.ui.treeStructure.Tree)4 java.awt (java.awt)4 MouseEvent (java.awt.event.MouseEvent)4 List (java.util.List)4 javax.swing (javax.swing)4 TreePath (javax.swing.tree.TreePath)4 NotNull (org.jetbrains.annotations.NotNull)4 Module (com.intellij.openapi.module.Module)3 Project (com.intellij.openapi.project.Project)3 VerticalFlowLayout (com.intellij.openapi.ui.VerticalFlowLayout)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3