public static void selectColumns( @NotNull Project project, @NotNull ListSelectionItemListener<DatabaseTableFieldData> listener) { DataSourceManager dataSourceManager = DataSourceManager.getInstance(project); String dlftDataSourceId = MybatisSetting.getInstance().getDefaultDataSourceId(); DataSource defaultDataSource = dataSourceManager.getDataSourceByID(dlftDataSourceId); final UiComponentFacade uiFacade = UiComponentFacade.getInstance(project); if (defaultDataSource == null) { selectDataSourceAndApply(listener, dataSourceManager, uiFacade); } else { selectTableAndApply(uiFacade, defaultDataSource.getTables(), listener); } }
private static void selectDataSourceAndApply( final ListSelectionItemListener<DatabaseTableFieldData> listener, DataSourceManager dataSourceManager, final UiComponentFacade uiFacade) { uiFacade.selectItems( "[Select Data Source]", dataSourceManager.getDataSources(), new ListSelectionItemListener<DataSource>() { @Override public void apply(DataSource dataSource) { MybatisSetting.getInstance().setDefaultDataSourceId(dataSource.getUniqueId()); selectTableAndApply(uiFacade, dataSource.getTables(), listener); } }, new Function<DataSource, String>() { @Override public String apply(DataSource dataSource) { return dataSource.getName(); } }); }