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);
}
Aggregations