Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #95 from leotilli/disable_import_subscription_empt…
Browse files Browse the repository at this point in the history
…y_path

[Android] Disable import button. Fixes issue #83.
  • Loading branch information
avranju committed Jan 15, 2015
2 parents 558dc08 + c4304f3 commit 571d531
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.microsoftopentechnologies.intellij.forms;

import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import com.microsoftopentechnologies.intellij.helpers.azure.AzureRestAPIManager;
import com.microsoftopentechnologies.intellij.helpers.LinkListener;
import com.microsoftopentechnologies.intellij.helpers.UIHelper;
import com.microsoftopentechnologies.intellij.helpers.azure.AzureRestAPIManager;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand Down Expand Up @@ -74,8 +75,10 @@ public boolean isFileSelectable(VirtualFile file) {
FileChooser.chooseFile(fileChooserDescriptor, null, null, new Consumer<VirtualFile>() {
@Override
public void consume(VirtualFile virtualFile) {
if (virtualFile != null)
if (virtualFile != null) {
txtFile.setText(virtualFile.getPath());
importButton.setEnabled(true);
}
}
});
}
Expand All @@ -89,13 +92,11 @@ public void actionPerformed(ActionEvent actionEvent) {
}
});


importButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (new File(txtFile.getText()).exists()) {
try {

form.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

AzureRestAPIManager.getManager().loadSubscriptionFile(txtFile.getText());
Expand All @@ -106,21 +107,39 @@ public void actionPerformed(ActionEvent actionEvent) {

form.setVisible(false);
form.dispose();


} catch (Throwable e) {
form.setCursor(Cursor.getDefaultCursor());
UIHelper.showException("Error: " + e.getMessage(), e);
}
}
}
});

DocumentListener documentListener = new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
importButton.setEnabled(txtFile.getText() != null && !txtFile.getText().trim().isEmpty());
}

@Override
public void removeUpdate(DocumentEvent e) {
importButton.setEnabled(txtFile.getText() != null && !txtFile.getText().trim().isEmpty());
}

@Override
public void changedUpdate(DocumentEvent e) {
importButton.setEnabled(txtFile.getText() != null && !txtFile.getText().trim().isEmpty());
}
};

txtFile.getDocument().addDocumentListener(documentListener);

importButton.setEnabled(false);
}

private Runnable onSubscriptionLoaded;

public void setOnSubscriptionLoaded(Runnable onSubscriptionLoaded) {
this.onSubscriptionLoaded = onSubscriptionLoaded;
}

}
}

0 comments on commit 571d531

Please sign in to comment.