summaryrefslogtreecommitdiff
path: root/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.java
diff options
context:
space:
mode:
Diffstat (limited to 'python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.java')
-rw-r--r--python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.java b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.java
new file mode 100644
index 000000000000..4e7deedf7e47
--- /dev/null
+++ b/python/edu/course-creator/src/org/jetbrains/plugins/coursecreator/ui/CreateCourseArchivePanel.java
@@ -0,0 +1,65 @@
+package org.jetbrains.plugins.coursecreator.ui;
+
+import com.intellij.icons.AllIcons;
+import com.intellij.openapi.fileChooser.FileChooserDescriptor;
+import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.TextFieldWithBrowseButton;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+
+public class CreateCourseArchivePanel extends JPanel {
+ private JPanel myPanel;
+ private JTextField myNameField;
+ private TextFieldWithBrowseButton myLocationField;
+ private JLabel myErrorIcon;
+ private JLabel myErrorLabel;
+ private CreateCourseArchiveDialog myDlg;
+
+ public CreateCourseArchivePanel(@NotNull final Project project, CreateCourseArchiveDialog dlg) {
+ setLayout(new BorderLayout());
+ add(myPanel, BorderLayout.CENTER);
+ myErrorIcon.setIcon(AllIcons.Actions.Lightning);
+ setState(false);
+ myDlg = dlg;
+ myNameField.setText("course");
+ myLocationField.setText(project.getBasePath());
+ FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
+ myLocationField.addBrowseFolderListener("Choose location folder", null, project, descriptor);
+ myLocationField.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String location = myLocationField.getText();
+ File file = new File(location);
+ if (!file.exists() || !file.isDirectory()) {
+ myDlg.enableOKAction(false);
+ setError("Invalid location");
+ }
+ myDlg.enableOKAction(true);
+ }
+ });
+ }
+
+ private void setState(boolean isVisible) {
+ myErrorIcon.setVisible(isVisible);
+ myErrorLabel.setVisible(isVisible);
+ }
+
+ private void setError(String message) {
+ myErrorLabel.setText(message);
+ setState(true);
+ }
+
+ public String getZipName() {
+ return myNameField.getText();
+ }
+
+ public String getLocationPath() {
+ return myLocationField.getText();
+ }
+}