From 6d3c8a896afbc73897683913b50f85256be43d9b Mon Sep 17 00:00:00 2001 From: iman89 Date: Fri, 2 Mar 2018 19:00:03 +0300 Subject: [PATCH] Background indicator progress in now properly changed --- .../liquigen/CompareDatabaseAction.java | 8 ++--- .../liquigen/GenerateChangesetAction.java | 6 ++-- .../plugins/liquigen/LiquibaseWrapper.java | 32 ++++++++++++++++++- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/alivanov/intellij/plugins/liquigen/CompareDatabaseAction.java b/src/main/java/com/alivanov/intellij/plugins/liquigen/CompareDatabaseAction.java index d15756a..53c4b4c 100644 --- a/src/main/java/com/alivanov/intellij/plugins/liquigen/CompareDatabaseAction.java +++ b/src/main/java/com/alivanov/intellij/plugins/liquigen/CompareDatabaseAction.java @@ -54,7 +54,7 @@ public void actionPerformed(AnActionEvent e) { private void showDataSourceSelectionPopup(AnActionEvent e, Project project, DbDataSource targetDataSource, List referenceDataSources) { final JBList list = new JBList<>(JBList.createDefaultListModel(referenceDataSources)); - list.getEmptyText().setText(LIQUIGEN_NO_DATA_SOURCES_FOUND); + list.setEmptyText(LIQUIGEN_NO_DATA_SOURCES_FOUND); list.setCellRenderer(new DataSourceCellRenderer()); JBPopup popup = JBPopupFactory.getInstance() @@ -79,8 +79,8 @@ private void generateDiffChangeLog(Project project, DbDataSource targetDataSourc private static class CompareDatabaseTask extends Task.Backgroundable { - private DbDataSource targetDataSource; - private DbDataSource referenceDataSource; + private final DbDataSource targetDataSource; + private final DbDataSource referenceDataSource; private String changeLog; CompareDatabaseTask(@Nullable Project project, @Nls @NotNull String title, DbDataSource targetDataSource, DbDataSource referenceDataSource) { @@ -91,8 +91,6 @@ private static class CompareDatabaseTask extends Task.Backgroundable { @Override public void run(@NotNull ProgressIndicator indicator) { - indicator.setText(LIQUIGEN_BACKGROUND_TASK_NAME); - final LiquibaseWrapper liquibaseWrapper = new LiquibaseWrapper(getProject()); changeLog = liquibaseWrapper.generateDiff(targetDataSource, referenceDataSource); } diff --git a/src/main/java/com/alivanov/intellij/plugins/liquigen/GenerateChangesetAction.java b/src/main/java/com/alivanov/intellij/plugins/liquigen/GenerateChangesetAction.java index 2742398..4adad22 100644 --- a/src/main/java/com/alivanov/intellij/plugins/liquigen/GenerateChangesetAction.java +++ b/src/main/java/com/alivanov/intellij/plugins/liquigen/GenerateChangesetAction.java @@ -62,8 +62,8 @@ private boolean areElementsOfOneDataSource(Project project, List dbEl private static class GenerateChangeLogTask extends Task.Backgroundable { - private List dbElements; - private DbDataSource dataSource; + private final List dbElements; + private final DbDataSource dataSource; private String changeLog; GenerateChangeLogTask(@Nullable Project project, List dbElements, DbDataSource dataSource) { @@ -74,8 +74,6 @@ private static class GenerateChangeLogTask extends Task.Backgroundable { @Override public void run(@NotNull ProgressIndicator indicator) { - indicator.setText(LIQUIGEN_BACKGROUND_TASK_NAME); - final LiquibaseWrapper liquibaseWrapper = new LiquibaseWrapper(getProject()); changeLog = liquibaseWrapper.generateChangeLog(dbElements, dataSource); } diff --git a/src/main/java/com/alivanov/intellij/plugins/liquigen/LiquibaseWrapper.java b/src/main/java/com/alivanov/intellij/plugins/liquigen/LiquibaseWrapper.java index 0263fc5..7032b20 100644 --- a/src/main/java/com/alivanov/intellij/plugins/liquigen/LiquibaseWrapper.java +++ b/src/main/java/com/alivanov/intellij/plugins/liquigen/LiquibaseWrapper.java @@ -10,6 +10,8 @@ import com.intellij.database.psi.DbNamespaceImpl; import com.intellij.database.util.GuardedRef; import com.intellij.openapi.progress.ProcessCanceledException; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressIndicatorProvider; import com.intellij.openapi.project.Project; import liquibase.command.GenerateChangeLogCommand; import liquibase.database.Database; @@ -29,9 +31,11 @@ import java.util.Set; import java.util.stream.Collectors; +import static com.alivanov.intellij.plugins.liquigen.Constants.LIQUIGEN_BACKGROUND_TASK_NAME; + class LiquibaseWrapper { - private Project project; + private final Project project; LiquibaseWrapper(Project project) { this.project = project; @@ -45,6 +49,8 @@ public String generateChangeLog(List dbElements, DbDataSource dataSou PrintStream printStream = new PrintStream(byteStream, true, "utf-8"); GuardedRef connectionRef = acquireConnection(dataSource) ) { + startIndicatorProgress(); + Database referenceDatabase = getDatabase(connectionRef); GenerateChangeLogCommand command = new GenerateChangeLogCommand(); @@ -57,6 +63,8 @@ public String generateChangeLog(List dbElements, DbDataSource dataSou command.execute(); generatedChangeLog = new String(byteStream.toByteArray(), StandardCharsets.UTF_8); + + finishIndicatorProgress(); } catch (ProcessCanceledException processCanceledEx) { throw processCanceledEx; } catch (Exception e) { @@ -85,6 +93,8 @@ public String generateDiff(DbDataSource target, DbDataSource reference) { GuardedRef targetConnectionRef = acquireConnection(target); GuardedRef referenceConnectionRef = acquireConnection(reference) ) { + startIndicatorProgress(); + Database targetDatabase = getDatabase(targetConnectionRef); Database referenceDatabase = getDatabase(referenceConnectionRef); @@ -99,6 +109,8 @@ public String generateDiff(DbDataSource target, DbDataSource reference) { command.execute(); diffChangeLog = new String(byteStream.toByteArray(), StandardCharsets.UTF_8); + + finishIndicatorProgress(); } catch (ProcessCanceledException processCanceledEx) { throw processCanceledEx; } catch (Exception e) { @@ -143,4 +155,22 @@ private DiffOutputControl createDefaultDiffOutputControl() { return diffOutputControl; } + + private void startIndicatorProgress() { + ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator(); + + if (indicator != null) { + indicator.setText(LIQUIGEN_BACKGROUND_TASK_NAME); + indicator.setIndeterminate(true); + } + } + + private void finishIndicatorProgress() { + ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator(); + + if (indicator != null) { + indicator.setIndeterminate(false); + indicator.setFraction(1.0); + } + } }