Java 类com.intellij.util.CatchingConsumer 实例源码

项目:TheRPlugin    文件:TheRPackagesUtil.java   
public static void fetchPackageDetails(@NotNull final String packageName, @NotNull final CatchingConsumer<String, Exception> consumer) {
  ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
    @Override
    public void run() {
      try {
        final String details = loadPackageDetails(packageName);
        consumer.consume(formatDetails(packageName, details));
      }
      catch (ExecutionException e) {
        consumer.consume(e);
      }
    }
  });
}
项目:intellij-ce-playground    文件:ManagePackagesDialog.java   
@Override
public void valueChanged(ListSelectionEvent event) {
  myOptionsCheckBox.setEnabled(myPackages.getSelectedIndex() >= 0);
  myVersionCheckBox.setEnabled(myPackages.getSelectedIndex() >= 0);
  myOptionsCheckBox.setSelected(false);
  myVersionCheckBox.setSelected(false);
  myVersionComboBox.setEnabled(false);
  myOptionsField.setEnabled(false);
  myDescriptionTextArea.setText("<html><body style='text-align: center;padding-top:20px;'>Loading...</body></html>");
  final Object pyPackage = myPackages.getSelectedValue();
  if (pyPackage instanceof RepoPackage) {
    final String packageName = ((RepoPackage)pyPackage).getName();
    mySelectedPackageName = packageName;
    myVersionComboBox.removeAllItems();
    if (myVersionCheckBox.isEnabled()) {
      myController.fetchPackageVersions(packageName, new CatchingConsumer<List<String>, Exception>() {
        @Override
        public void consume(final List<String> releases) {
          ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override
            public void run() {
              if (myPackages.getSelectedValue() == pyPackage) {
                myVersionComboBox.removeAllItems();
                for (String release : releases) {
                  myVersionComboBox.addItem(release);
                }
              }
            }
          }, ModalityState.any());
        }

        @Override
        public void consume(Exception e) {
          LOG.info("Error retrieving releases", e);
        }
      });
    }
    myInstallButton.setEnabled(!myCurrentlyInstalling.contains(packageName));

    myController.fetchPackageDetails(packageName, new CatchingConsumer<String, Exception>() {
      @Override
      public void consume(final String details) {
        UIUtil.invokeLaterIfNeeded(new Runnable() {
          @Override
          public void run() {
            if (myPackages.getSelectedValue() == pyPackage) {
              myDescriptionTextArea.setText(details);
              myDescriptionTextArea.setCaretPosition(0);
            }/* else {
               do nothing, because other package gets selected
            }*/
          }
        });
      }

      @Override
      public void consume(Exception exception) {
        myDescriptionTextArea.setText("No information available");
        LOG.info("Error retrieving package details", exception);
      }
    });
  }
  else {
    myInstallButton.setEnabled(false);
    myDescriptionTextArea.setText("");
  }
}
项目:intellij-ce-playground    文件:InstalledPackagesPanel.java   
private void setLatestVersionsForInstalledPackages() {
  final PackageManagementServiceEx serviceEx = getServiceEx();
  if (serviceEx == null) {
    return;
  }
  int packageCount = myPackagesTableModel.getRowCount();
  if (packageCount == 0) {
    onUpdateFinished();
  }
  final AtomicInteger inProgressPackageCount = new AtomicInteger(packageCount);
  for (int i = 0; i < packageCount; ++i) {
    final int finalIndex = i;
    final InstalledPackage pkg = getInstalledPackageAt(finalIndex);
    serviceEx.fetchLatestVersion(pkg, new CatchingConsumer<String, Exception>() {

      private void decrement() {
        if (inProgressPackageCount.decrementAndGet() == 0) {
          onUpdateFinished();
        }
      }

      @Override
      public void consume(Exception e) {
        UIUtil.invokeLaterIfNeeded(new Runnable() {
          @Override
          public void run() {
            decrement();
          }
        });
      }

      @Override
      public void consume(@Nullable final String latestVersion) {
        UIUtil.invokeLaterIfNeeded(new Runnable() {
          @Override
          public void run() {
            if (finalIndex < myPackagesTableModel.getRowCount()) {
              InstalledPackage p = getInstalledPackageAt(finalIndex);
              if (pkg == p) {
                myPackagesTableModel.setValueAt(latestVersion, finalIndex, 2);
              }
            }
            decrement();
          }
        });
      }
    });
  }
}
项目:intellij-ce-playground    文件:PyCondaManagementService.java   
@Override
public void fetchPackageVersions(String packageName, CatchingConsumer<List<String>, Exception> consumer) {
  final List<String> versions = PyCondaPackageService.getInstance().getPackageVersions(packageName);
  Collections.sort(versions, Collections.reverseOrder(new PackageVersionComparator()));
  consumer.consume(versions);
}
项目:TheRPlugin    文件:TheRPackageManagementService.java   
@Override
public void fetchPackageVersions(String s, CatchingConsumer<List<String>, Exception> consumer) {
  consumer.consume(ContainerUtil.<String>emptyList());
}
项目:TheRPlugin    文件:TheRPackageManagementService.java   
@Override
public void fetchPackageDetails(String packageName, CatchingConsumer<String, Exception> consumer) {
  TheRPackagesUtil.fetchPackageDetails(packageName, consumer);
}
项目:consulo    文件:ManagePackagesDialog.java   
@Override
public void valueChanged(ListSelectionEvent event) {
  myOptionsCheckBox.setEnabled(myPackages.getSelectedIndex() >= 0);
  myVersionCheckBox.setEnabled(myPackages.getSelectedIndex() >= 0);
  myOptionsCheckBox.setSelected(false);
  myVersionCheckBox.setSelected(false);
  myVersionComboBox.setEnabled(false);
  myOptionsField.setEnabled(false);
  myDescriptionTextArea.setText("<html><body style='text-align: center;padding-top:20px;'>Loading...</body></html>");
  final Object pyPackage = myPackages.getSelectedValue();
  if (pyPackage instanceof RepoPackage) {
    final String packageName = ((RepoPackage)pyPackage).getName();
    mySelectedPackageName = packageName;
    myVersionComboBox.removeAllItems();
    if (myVersionCheckBox.isEnabled()) {
      myController.fetchPackageVersions(packageName, new CatchingConsumer<List<String>, Exception>() {
        @Override
        public void consume(final List<String> releases) {
          ApplicationManager.getApplication().invokeLater(() -> {
            if (myPackages.getSelectedValue() == pyPackage) {
              myVersionComboBox.removeAllItems();
              for (String release : releases) {
                myVersionComboBox.addItem(release);
              }
            }
          }, ModalityState.any());
        }

        @Override
        public void consume(Exception e) {
          LOG.info("Error retrieving releases", e);
        }
      });
    }
    myInstallButton.setEnabled(!myCurrentlyInstalling.contains(packageName));

    myController.fetchPackageDetails(packageName, new CatchingConsumer<String, Exception>() {
      @Override
      public void consume(final String details) {
        UIUtil.invokeLaterIfNeeded(() -> {
          if (myPackages.getSelectedValue() == pyPackage) {
            myDescriptionTextArea.setText(details);
            myDescriptionTextArea.setCaretPosition(0);
          }/* else {
             do nothing, because other package gets selected
          }*/
        });
      }

      @Override
      public void consume(Exception exception) {
        UIUtil.invokeLaterIfNeeded(() -> myDescriptionTextArea.setText("No information available"));
        LOG.info("Error retrieving package details", exception);
      }
    });
  }
  else {
    myInstallButton.setEnabled(false);
    myDescriptionTextArea.setText("");
  }
}
项目:consulo    文件:InstalledPackagesPanel.java   
private void setLatestVersionsForInstalledPackages() {
  final PackageManagementServiceEx serviceEx = getServiceEx();
  if (serviceEx == null) {
    return;
  }
  int packageCount = myPackagesTableModel.getRowCount();
  if (packageCount == 0) {
    onUpdateFinished();
  }
  final AtomicInteger inProgressPackageCount = new AtomicInteger(packageCount);
  for (int i = 0; i < packageCount; ++i) {
    final int finalIndex = i;
    final InstalledPackage pkg = getInstalledPackageAt(finalIndex);
    serviceEx.fetchLatestVersion(pkg, new CatchingConsumer<String, Exception>() {

      private void decrement() {
        if (inProgressPackageCount.decrementAndGet() == 0) {
          onUpdateFinished();
        }
      }

      @Override
      public void consume(Exception e) {
        UIUtil.invokeLaterIfNeeded(() -> decrement());
      }

      @Override
      public void consume(@Nullable final String latestVersion) {
        UIUtil.invokeLaterIfNeeded(() -> {
          if (finalIndex < myPackagesTableModel.getRowCount()) {
            InstalledPackage p = getInstalledPackageAt(finalIndex);
            if (pkg == p) {
              myPackagesTableModel.setValueAt(latestVersion, finalIndex, 2);
            }
          }
          decrement();
        });
      }
    });
  }
}
项目:intellij-ce-playground    文件:PackageManagementService.java   
public abstract void fetchPackageVersions(String packageName, CatchingConsumer<List<String>, Exception> consumer);
项目:intellij-ce-playground    文件:PackageManagementService.java   
public abstract void fetchPackageDetails(String packageName, CatchingConsumer<String, Exception> consumer);
项目:intellij-ce-playground    文件:PackageManagementServiceEx.java   
public abstract void fetchLatestVersion(@NotNull InstalledPackage pkg, @NotNull final CatchingConsumer<String, Exception> consumer);
项目:consulo    文件:PackageManagementService.java   
public abstract void fetchPackageVersions(String packageName, CatchingConsumer<List<String>, Exception> consumer);
项目:consulo    文件:PackageManagementService.java   
public abstract void fetchPackageDetails(String packageName, CatchingConsumer<String, Exception> consumer);
项目:consulo    文件:PackageManagementServiceEx.java   
public abstract void fetchLatestVersion(@Nonnull InstalledPackage pkg, @Nonnull final CatchingConsumer<String, Exception> consumer);