Skip to content

Commit

Permalink
Background indicator progress in now properly changed
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-inv committed Mar 2, 2018
1 parent a793437 commit 6d3c8a8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void actionPerformed(AnActionEvent e) {
private void showDataSourceSelectionPopup(AnActionEvent e, Project project, DbDataSource targetDataSource, List<DbDataSource> referenceDataSources) {
final JBList<DbDataSource> 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()
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ private boolean areElementsOfOneDataSource(Project project, List<DbElement> dbEl

private static class GenerateChangeLogTask extends Task.Backgroundable {

private List<DbElement> dbElements;
private DbDataSource dataSource;
private final List<DbElement> dbElements;
private final DbDataSource dataSource;
private String changeLog;

GenerateChangeLogTask(@Nullable Project project, List<DbElement> dbElements, DbDataSource dataSource) {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -45,6 +49,8 @@ public String generateChangeLog(List<DbElement> dbElements, DbDataSource dataSou
PrintStream printStream = new PrintStream(byteStream, true, "utf-8");
GuardedRef<DatabaseConnection> connectionRef = acquireConnection(dataSource)
) {
startIndicatorProgress();

Database referenceDatabase = getDatabase(connectionRef);

GenerateChangeLogCommand command = new GenerateChangeLogCommand();
Expand All @@ -57,6 +63,8 @@ public String generateChangeLog(List<DbElement> dbElements, DbDataSource dataSou
command.execute();

generatedChangeLog = new String(byteStream.toByteArray(), StandardCharsets.UTF_8);

finishIndicatorProgress();
} catch (ProcessCanceledException processCanceledEx) {
throw processCanceledEx;
} catch (Exception e) {
Expand Down Expand Up @@ -85,6 +93,8 @@ public String generateDiff(DbDataSource target, DbDataSource reference) {
GuardedRef<DatabaseConnection> targetConnectionRef = acquireConnection(target);
GuardedRef<DatabaseConnection> referenceConnectionRef = acquireConnection(reference)
) {
startIndicatorProgress();

Database targetDatabase = getDatabase(targetConnectionRef);
Database referenceDatabase = getDatabase(referenceConnectionRef);

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 6d3c8a8

Please sign in to comment.