Search in sources :

Example 1 with FileChooser

use of com.intellij.openapi.fileChooser.FileChooser in project intellij-community by JetBrains.

the class StudyNewProjectPanel method setupBrowseButton.

private void setupBrowseButton() {
    if (SystemInfo.isMac && !UIUtil.isUnderDarcula())
        myBrowseButton.putClientProperty("JButton.buttonType", null);
    myBrowseButton.setIcon(InteractiveLearningIcons.InterpreterGear);
    final FileChooserDescriptor fileChooser = new FileChooserDescriptor(true, false, false, true, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return file.isDirectory() || StudyUtils.isZip(file.getName());
        }

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            return StudyUtils.isZip(file.getName());
        }
    };
    myBrowseButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final BaseListPopupStep<String> popupStep = new BaseListPopupStep<String>("", "Add local course", LOGIN_TO_STEPIC) {

                @Override
                public PopupStep onChosen(final String selectedValue, boolean finalChoice) {
                    return doFinalStep(() -> {
                        if ("Add local course".equals(selectedValue)) {
                            Project[] projects = ProjectManager.getInstance().getOpenProjects();
                            FileChooser.chooseFile(fileChooser, null, projects.length == 0 ? null : projects[0].getBaseDir(), file -> {
                                String fileName = file.getPath();
                                int oldSize = myAvailableCourses.size();
                                CourseInfo courseInfo = myGenerator.addLocalCourse(fileName);
                                if (courseInfo != null) {
                                    if (oldSize != myAvailableCourses.size()) {
                                        myCoursesComboBox.addItem(courseInfo);
                                    }
                                    myCoursesComboBox.setSelectedItem(courseInfo);
                                    setOK();
                                } else {
                                    setError(INVALID_COURSE);
                                    myCoursesComboBox.removeAllItems();
                                    myCoursesComboBox.addItem(CourseInfo.INVALID_COURSE);
                                    for (CourseInfo course : myAvailableCourses) {
                                        myCoursesComboBox.addItem(course);
                                    }
                                    myCoursesComboBox.setSelectedItem(CourseInfo.INVALID_COURSE);
                                }
                            });
                        } else if (LOGIN_TO_STEPIC.equals(selectedValue)) {
                            showLoginDialog(true, "Signing In And Getting Stepik Course List");
                        }
                    });
                }
            };
            final ListPopup popup = JBPopupFactory.getInstance().createListPopup(popupStep);
            popup.showInScreenCoordinates(myBrowseButton, myBrowseButton.getLocationOnScreen());
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) ActionListener(java.awt.event.ActionListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) StudyUtils(com.jetbrains.edu.learning.StudyUtils) DefaultProjectFactory(com.intellij.openapi.project.DefaultProjectFactory) ArrayList(java.util.ArrayList) FacetValidatorsManager(com.intellij.facet.ui.FacetValidatorsManager) DefaultProjectFactoryImpl(com.intellij.openapi.project.DefaultProjectFactoryImpl) ProjectManager(com.intellij.openapi.project.ProjectManager) StudyProjectGenerator(com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator) Project(com.intellij.openapi.project.Project) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AncestorEvent(javax.swing.event.AncestorEvent) ComboBox(com.intellij.openapi.ui.ComboBox) ProgressManager(com.intellij.openapi.progress.ProgressManager) InteractiveLearningIcons(icons.InteractiveLearningIcons) com.jetbrains.edu.learning.stepic(com.jetbrains.edu.learning.stepic) StringUtil(com.intellij.openapi.util.text.StringUtil) ValidationResult(com.intellij.facet.ui.ValidationResult) FixedSizeButton(com.intellij.openapi.ui.FixedSizeButton) ActionEvent(java.awt.event.ActionEvent) SystemInfo(com.intellij.openapi.util.SystemInfo) JBScrollPane(com.intellij.ui.components.JBScrollPane) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) java.awt(java.awt) ListPopup(com.intellij.openapi.ui.popup.ListPopup) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) AncestorListenerAdapter(com.intellij.ui.AncestorListenerAdapter) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo) PopupStep(com.intellij.openapi.ui.popup.PopupStep) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PanelWithAnchor(com.intellij.ui.PanelWithAnchor) LabeledComponent(com.intellij.openapi.ui.LabeledComponent) NotNull(org.jetbrains.annotations.NotNull) FileChooser(com.intellij.openapi.fileChooser.FileChooser) Course(com.jetbrains.edu.learning.courseFormat.Course) javax.swing(javax.swing) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ActionEvent(java.awt.event.ActionEvent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) ActionListener(java.awt.event.ActionListener) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep)

Aggregations

FacetValidatorsManager (com.intellij.facet.ui.FacetValidatorsManager)1 ValidationResult (com.intellij.facet.ui.ValidationResult)1 AllIcons (com.intellij.icons.AllIcons)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 FileChooser (com.intellij.openapi.fileChooser.FileChooser)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 DefaultProjectFactory (com.intellij.openapi.project.DefaultProjectFactory)1 DefaultProjectFactoryImpl (com.intellij.openapi.project.DefaultProjectFactoryImpl)1 Project (com.intellij.openapi.project.Project)1 ProjectManager (com.intellij.openapi.project.ProjectManager)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 FixedSizeButton (com.intellij.openapi.ui.FixedSizeButton)1 LabeledComponent (com.intellij.openapi.ui.LabeledComponent)1 VerticalFlowLayout (com.intellij.openapi.ui.VerticalFlowLayout)1 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)1 ListPopup (com.intellij.openapi.ui.popup.ListPopup)1 PopupStep (com.intellij.openapi.ui.popup.PopupStep)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1 SystemInfo (com.intellij.openapi.util.SystemInfo)1