|
41 | 41 | import com.microsoft.azuretools.azurecommons.helpers.Nullable; |
42 | 42 | import com.microsoft.azuretools.azurecommons.helpers.StringHelper; |
43 | 43 | import com.microsoft.tooling.msservices.components.DefaultLoader; |
44 | | -import org.apache.commons.lang.StringUtils; |
| 44 | +import rx.subjects.BehaviorSubject; |
45 | 45 |
|
46 | 46 | import javax.swing.*; |
47 | 47 | import javax.swing.event.DocumentEvent; |
48 | 48 | import javax.swing.event.DocumentListener; |
49 | 49 | import javax.swing.table.TableColumn; |
50 | 50 | import java.awt.*; |
51 | | -import java.awt.event.ActionEvent; |
52 | | -import java.awt.event.ActionListener; |
53 | | -import java.awt.event.ItemEvent; |
54 | | -import java.awt.event.ItemListener; |
| 51 | +import java.awt.event.*; |
55 | 52 | import java.beans.PropertyChangeEvent; |
56 | 53 | import java.beans.PropertyChangeListener; |
57 | | -import java.io.*; |
58 | 54 | import java.util.ArrayList; |
59 | 55 | import java.util.List; |
60 | 56 | import java.util.Map; |
61 | | -import java.util.Properties; |
| 57 | +import java.util.concurrent.TimeUnit; |
62 | 58 |
|
63 | 59 | public class SparkSubmissionContentPanel extends JPanel{ |
64 | 60 | public SparkSubmissionContentPanel(@NotNull Project project, @Nullable CallBack updateCallBack){ |
@@ -148,6 +144,9 @@ public SparkSubmitModel getSubmitModel() { |
148 | 144 | private JRadioButton localArtifactRadioButton; |
149 | 145 | private final JLabel[] errorMessageLabels = new JLabel[5]; |
150 | 146 | private SparkSubmissionAdvancedConfigDialog advancedConfigDialog; |
| 147 | + private JButton advancedConfigButton= new JButton("Advanced configuration"); |
| 148 | + |
| 149 | + private BehaviorSubject<String> clusterSelectedSubject = BehaviorSubject.create(); |
151 | 150 |
|
152 | 151 | /** |
153 | 152 | * Apply the parameters in new SubmitModel |
@@ -176,6 +175,15 @@ private void initialize() { |
176 | 175 | initializeModel(); |
177 | 176 | updateTableColumn(); |
178 | 177 | loadParameter(submitModel.getSubmissionParameter()); |
| 178 | + |
| 179 | + addContainerListener(new ContainerAdapter() { |
| 180 | + @Override |
| 181 | + public void componentRemoved(ContainerEvent e) { |
| 182 | + cleanUp(); |
| 183 | + |
| 184 | + super.componentRemoved(e); |
| 185 | + } |
| 186 | + }); |
179 | 187 | } |
180 | 188 |
|
181 | 189 | private void loadParameter(SparkSubmissionParameter parameter) { |
@@ -237,6 +245,7 @@ private void initializeModel() { |
237 | 245 | submitModel.setClusterComboBoxModel(cachedClusters); |
238 | 246 | clustersListComboBox.getComboBox().setModel(submitModel.getClusterComboBoxModel()); |
239 | 247 | clustersListComboBox.getButton().setEnabled(true); |
| 248 | + clusterSelectedSubject.onNext((String) clustersListComboBox.getComboBox().getSelectedItem()); |
240 | 249 | }); |
241 | 250 |
|
242 | 251 | selectedArtifactComboBox.setModel(submitModel.getArtifactComboBoxModel()); |
@@ -290,12 +299,14 @@ public void actionPerformed(ActionEvent e) { |
290 | 299 | clustersListComboBox.getComboBox().addPropertyChangeListener(new PropertyChangeListener() { |
291 | 300 | @Override |
292 | 301 | public void propertyChange(PropertyChangeEvent evt) { |
293 | | - if (evt.getPropertyName() == "model" && evt.getNewValue() instanceof DefaultComboBoxModel) { |
| 302 | + if (evt.getPropertyName().equals("model") && evt.getNewValue() instanceof DefaultComboBoxModel) { |
294 | 303 | int size = ((DefaultComboBoxModel) evt.getNewValue()).getSize(); |
295 | 304 | setVisibleForFixedErrorMessageLabel(ErrorMessageLabelTag.ClusterName.ordinal(), size <= 0); |
296 | 305 | } |
297 | 306 | } |
298 | 307 | }); |
| 308 | + clustersListComboBox.getComboBox().addItemListener(ev -> |
| 309 | + clusterSelectedSubject.onNext(ev.getStateChange() == ItemEvent.SELECTED ? ev.getItem().toString() : null)); |
299 | 310 |
|
300 | 311 | add(clustersListComboBox, |
301 | 312 | new GridBagConstraints(1, displayLayoutCurrentRow, |
@@ -652,34 +663,35 @@ private void addReferencedJarsLineItem() { |
652 | 663 | } |
653 | 664 |
|
654 | 665 | private void addAdvancedConfigLineItem() { |
655 | | - JButton advancedConfigButton = new JButton("Advanced configuration"); |
| 666 | + advancedConfigButton.setEnabled(false); |
656 | 667 | advancedConfigButton.setToolTipText("Specify advanced configuration, for example, enabling Spark remote debug"); |
657 | 668 |
|
| 669 | + clusterSelectedSubject |
| 670 | + .throttleWithTimeout(200, TimeUnit.MILLISECONDS) |
| 671 | + .subscribe(cluster -> advancedConfigButton.setEnabled(cluster != null)); |
| 672 | + |
658 | 673 | add(advancedConfigButton, |
659 | 674 | new GridBagConstraints(0, ++displayLayoutCurrentRow, |
660 | 675 | 0, 1, |
661 | 676 | 1, 0, |
662 | 677 | GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, |
663 | 678 | new Insets(margin, margin, 0, 0), 0, 0)); |
664 | 679 |
|
665 | | - advancedConfigButton.addActionListener(new ActionListener() { |
666 | | - @Override |
667 | | - public void actionPerformed(ActionEvent e) { |
668 | | - advancedConfigDialog = new SparkSubmissionAdvancedConfigDialog( |
669 | | - submitModel, |
670 | | - submitModel.getAdvancedConfigModel(), |
671 | | - new CallBack() { |
672 | | - @Override |
673 | | - public void run() { |
674 | | - if (null != advancedConfigDialog){ |
675 | | - submitModel.setAdvancedConfigModel(advancedConfigDialog.getAdvancedConfigModel()); |
676 | | - } |
677 | | - } |
| 680 | + advancedConfigButton.addActionListener(e -> { |
| 681 | + // Read the current panel setting into current model |
| 682 | + SparkSubmitModel currentModel = new SparkSubmitModel(submitModel.getProject(), constructSubmissionParameter()); |
| 683 | + |
| 684 | + advancedConfigDialog = new SparkSubmissionAdvancedConfigDialog( |
| 685 | + currentModel, |
| 686 | + submitModel.getAdvancedConfigModel(), |
| 687 | + () -> { |
| 688 | + if (null != advancedConfigDialog){ |
| 689 | + submitModel.setAdvancedConfigModel(advancedConfigDialog.getAdvancedConfigModel()); |
678 | 690 | } |
679 | | - ); |
680 | | - advancedConfigDialog.setModal(true); |
681 | | - advancedConfigDialog.setVisible(true); |
682 | | - } |
| 691 | + } |
| 692 | + ); |
| 693 | + advancedConfigDialog.setModal(true); |
| 694 | + advancedConfigDialog.setVisible(true); |
683 | 695 | }); |
684 | 696 | } |
685 | 697 |
|
@@ -722,4 +734,8 @@ private void setStatusForMessageLabel(@NotNull int label, @NotNull boolean isVis |
722 | 734 | private void setStatusForMessageLabel(@NotNull int label, @NotNull boolean isVisible, @Nullable String message) { |
723 | 735 | setStatusForMessageLabel(label, isVisible, message, false); |
724 | 736 | } |
| 737 | + |
| 738 | + public void cleanUp() { |
| 739 | + clusterSelectedSubject.onCompleted(); |
| 740 | + } |
725 | 741 | } |
0 commit comments