11package com.longforus.mvpautocodeplus.config
22
3- import com.intellij.icons.AllIcons
43import com.intellij.ide.BrowserUtil
4+ import com.intellij.ide.util.TreeClassChooserFactory
55import com.intellij.openapi.components.ServiceManager
6- import com.intellij.openapi.fileChooser.FileChooserDescriptor
76import com.intellij.openapi.options.SearchableConfigurable
87import com.intellij.openapi.project.Project
98import com.intellij.openapi.project.ProjectManager
10- import com.intellij.openapi.ui.Messages
119import com.longforus.mvpautocodeplus.*
1210import com.longforus.mvpautocodeplus.ui.ConfigForm
11+ import javax.swing.JButton
1312import javax.swing.JComponent
13+ import javax.swing.JTextField
1414
1515/* *
1616 * Created by XQ Yang on 2018/6/25 14:12.
@@ -25,15 +25,15 @@ class ConfigComponent : SearchableConfigurable {
2525
2626 private val mCp: ConfigForm by lazy { ConfigForm () }
2727 private val state: PersistentState by lazy { ServiceManager .getService(PersistentState ::class .java) }
28- private val fcd = FileChooserDescriptor (true , false , false , false , false , false )
2928
30- private val project : Project by lazy {
29+ private val mProject : Project by lazy {
3130 if (ProjectManager .getInstance().openProjects.isNotEmpty()) {
3231 ProjectManager .getInstance().openProjects[0 ]
3332 } else {
3433 ProjectManager .getInstance().defaultProject
3534 }
3635 }
36+ private val classChooserFactory by lazy { TreeClassChooserFactory .getInstance(mProject) }
3737
3838 override fun isModified (): Boolean {
3939 return mCp.tv_v_name.text != state.getValue(SUPER_VIEW ) ||
@@ -61,28 +61,41 @@ class ConfigComponent : SearchableConfigurable {
6161 state.setValue(COMMENT_AUTHOR , mCp.et_comment_author.text)
6262 }
6363
64+
6465 override fun createComponent (): JComponent ? {
65- val value = state.getValue(SUPER_VIEW )
66- mCp.tv_v_name.text = value
67- // TODO: 2018/7/2 实现class选择 http://www.jetbrains.org/intellij/sdk/docs/user_interface_components/file_and_class_choosers.html?search=File
68- // val dialogImpl = FileChooserDialogImpl(fcd, project)
69- // val split = value?.split(";")
70- // project.projectFile.findChild()
71- mCp.btn_view_select.addActionListener {
72- // val choose = dialogImpl.choose(project, null)
73- Messages .showMessageDialog(" 还没有找到合适的方法来实现class的选择" , " 待开发" , AllIcons .General .ErrorDialog )
74- }
66+ mCp.tv_v_name.text = state.getValue(SUPER_VIEW )
67+ setClassChooser(mCp.btn_view_select, " Select Super View Interface" , mCp.tv_v_name)
7568 mCp.tv_p_name.text = state.getValue(SUPER_PRESENTER )
69+ setClassChooser(mCp.btn_p_select, " Select Super Presenter Interface" , mCp.tv_p_name)
7670 mCp.tv_m_name.text = state.getValue(SUPER_MODEL )
71+ setClassChooser(mCp.btn_m_select, " Select Super Model Interface" , mCp.tv_m_name)
7772 mCp.tv_view_activity.text = state.getValue(SUPER_VIEW_ACTIVITY )
73+ setClassChooser(mCp.btn_view_a_select, " Select View extends super Activity" , mCp.tv_view_activity, true )
7874 mCp.tv_view_fragment.text = state.getValue(SUPER_VIEW_FRAGMENT )
75+ setClassChooser(mCp.btn_view_f_select, " Select View extends super Fragment" , mCp.tv_view_fragment, true )
7976 mCp.tv_presenter_impl.text = state.getValue(SUPER_PRESENTER_IMPL )
77+ setClassChooser(mCp.btn_pi_select, " Select Presenter extends super Class" , mCp.tv_presenter_impl, true )
8078 mCp.tv_model_impl.text = state.getValue(SUPER_MODEL_IMPL )
79+ setClassChooser(mCp.btn_mi_select, " Select Model extends super Class" , mCp.tv_model_impl, true )
8180 mCp.et_comment_author.text = state.getValue(COMMENT_AUTHOR )
8281 mCp.lk_look_detail.setListener({ _, _ ->
8382 BrowserUtil .browse(" https://github.com/longforus/MvpAutoCodePlus/blob/master/README.md" )
8483 }, " https://github.com/longforus" )
8584 return mCp.mPanel
8685 }
8786
87+ private fun setClassChooser (jButton : JButton ? , title : String , tv : JTextField ? , append : Boolean = false) {
88+ jButton?.addActionListener {
89+ val projectScopeChooser = classChooserFactory.createProjectScopeChooser(title)
90+ projectScopeChooser.showDialog()
91+ if (projectScopeChooser.selected != null ) {
92+ if (append && ! tv?.text.isNullOrEmpty()) {
93+ tv?.text = " ${tv?.text} ;${projectScopeChooser.selected.qualifiedName} "
94+ } else {
95+ tv?.text = projectScopeChooser.selected.qualifiedName
96+ }
97+ }
98+ }
99+ }
100+
88101}
0 commit comments