Java Code Examples for com.intellij.ui.components.JBLoadingPanel#add()

The following examples show how to use com.intellij.ui.components.JBLoadingPanel#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogviewFactory.java    From logviewer with Apache License 2.0 4 votes vote down vote up
@Override
public void createToolWindowContent(@NotNull final Project project, @NotNull final ToolWindow toolWindow) {

    final File adb = AndroidSdkUtils.getAdb(project);
    ExecutionManager.getInstance(project).getContentManager();

    RunnerLayoutUi layoutUi = RunnerLayoutUi.Factory.getInstance(project).create("LogViewer", TOOL_WINDOW_ID, "Logview Tools", project);

    toolWindow.setIcon(LogviewerPluginIcons.TOOL_ICON);
    toolWindow.setAvailable(true, null);
    toolWindow.setToHideOnEmptyContent(true);
    toolWindow.setTitle(TOOL_WINDOW_ID);


    DeviceContext deviceContext = new DeviceContext();

    Content logcatContent = createLogcatContent(layoutUi, project, deviceContext);
    final LogView logcatView = logcatContent.getUserData(LOG_VIEW_KEY);
    layoutUi.addContent(logcatContent, 0, PlaceInGrid.center, false);

    final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), project);
    loadingPanel.add(layoutUi.getComponent(), BorderLayout.CENTER);

    final ContentManager contentManager = toolWindow.getContentManager();
    Content c = contentManager.getFactory().createContent(loadingPanel, "", true);
    c.putUserData(LOG_VIEW_KEY, logcatView);
    contentManager.addContent(c);
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            logcatView.activate();
        }
    }, project.getDisposed());


    if (adb != null) {
        loadingPanel.setLoadingText("Initializing ADB");
        loadingPanel.startLoading();

        //ListenableFuture<AndroidDebugBridge> future = AdbService.getInstance().getDebugBridge(adb);
        ListenableFuture<AndroidDebugBridge> future = AdbBridgeFactory.getAdb(adb);
        Futures.addCallback(future, new FutureCallback<AndroidDebugBridge>() {
            @Override
            public void onSuccess(@Nullable AndroidDebugBridge bridge) {
                Logger.getInstance(LogviewFactory.class).info("Successfully obtained debug bridge");
                loadingPanel.stopLoading();
            }

            @Override
            public void onFailure(@NotNull Throwable t) {
                loadingPanel.stopLoading();
                Logger.getInstance(LogviewFactory.class).info("Unable to obtain debug bridge", t);
                String msg;
                if (t.getMessage() != null) {
                    msg = t.getMessage();
                } else {
                    msg = String.format("Unable to establish a connection to adb",
                            ApplicationNamesInfo.getInstance().getProductName(), adb.getAbsolutePath());
                }
                Messages.showErrorDialog(msg, "ADB Connection Error");
            }
        }, EdtExecutor.INSTANCE);
    } else {
        logcatView.showHint("No adb connection!.\n\nDrag and drop log files to view them.");
    }
}
 
Example 2
Source File: MainFrame.java    From consulo with Apache License 2.0 4 votes vote down vote up
public MainFrame(@Nonnull VcsLogData logData,
                 @Nonnull VcsLogUiImpl ui,
                 @Nonnull Project project,
                 @Nonnull MainVcsLogUiProperties uiProperties,
                 @Nonnull VcsLog log,
                 @Nonnull VisiblePack initialDataPack) {
  // collect info
  myLogData = logData;
  myUi = ui;
  myLog = log;
  myUiProperties = uiProperties;

  myFilterUi = new VcsLogClassicFilterUi(myUi, logData, myUiProperties, initialDataPack);

  // initialize components
  myGraphTable = new VcsLogGraphTable(ui, logData, initialDataPack);
  myDetailsPanel = new DetailsPanel(logData, ui.getColorManager(), this);

  myChangesBrowser = new RepositoryChangesBrowser(project, null, Collections.emptyList(), null) {
    @Override
    protected void buildToolBar(DefaultActionGroup toolBarGroup) {
      super.buildToolBar(toolBarGroup);
      toolBarGroup.add(ActionManager.getInstance().getAction(VcsLogActionPlaces.VCS_LOG_SHOW_DETAILS_ACTION));
    }
  };
  myChangesBrowser.getViewerScrollPane().setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
  myChangesBrowser.getDiffAction().registerCustomShortcutSet(myChangesBrowser.getDiffAction().getShortcutSet(), getGraphTable());
  myChangesBrowser.getEditSourceAction().registerCustomShortcutSet(CommonShortcuts.getEditSource(), getGraphTable());
  myChangesBrowser.getViewer().setEmptyText("");
  myChangesLoadingPane = new JBLoadingPanel(new BorderLayout(), this, ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS);
  myChangesLoadingPane.add(myChangesBrowser);

  myDetailsSplitter = new OnePixelSplitter(true, "vcs.log.details.splitter.proportion", 0.7f);
  myDetailsSplitter.setFirstComponent(myChangesLoadingPane);
  setupDetailsSplitter(myUiProperties.get(MainVcsLogUiProperties.SHOW_DETAILS));

  myGraphTable.getSelectionModel().addListSelectionListener(new CommitSelectionListenerForDiff());
  myDetailsPanel.installCommitSelectionListener(myGraphTable);
  updateWhenDetailsAreLoaded();

  myTextFilter = myFilterUi.createTextFilter();
  myToolbar = createActionsToolbar();

  ProgressStripe progressStripe =
          new ProgressStripe(setupScrolledGraph(), this, ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS) {
            @Override
            public void updateUI() {
              super.updateUI();
              if (myDecorator != null && myLogData.getProgress().isRunning()) startLoadingImmediately();
            }
          };
  myLogData.getProgress().addProgressIndicatorListener(new VcsLogProgress.ProgressListener() {
    @Override
    public void progressStarted() {
      progressStripe.startLoading();
    }

    @Override
    public void progressStopped() {
      progressStripe.stopLoading();
    }
  }, this);


  JComponent toolbars = new JPanel(new BorderLayout());
  toolbars.add(myToolbar, BorderLayout.NORTH);
  JComponent toolbarsAndTable = new JPanel(new BorderLayout());
  toolbarsAndTable.add(toolbars, BorderLayout.NORTH);
  toolbarsAndTable.add(progressStripe, BorderLayout.CENTER);

  myChangesBrowserSplitter = new OnePixelSplitter(false, "vcs.log.changes.splitter.proportion", 0.7f);
  myChangesBrowserSplitter.setFirstComponent(toolbarsAndTable);
  myChangesBrowserSplitter.setSecondComponent(myDetailsSplitter);

  setLayout(new BorderLayout());
  add(myChangesBrowserSplitter);

  Disposer.register(ui, this);
  myGraphTable.resetDefaultFocusTraversalKeys();
  setFocusCycleRoot(true);
  setFocusTraversalPolicy(new MyFocusPolicy());
}
 
Example 3
Source File: DetailsPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
DetailsPanel(@Nonnull VcsLogData logData,
             @Nonnull VcsLogColorManager colorManager,
             @Nonnull Disposable parent) {
  myLogData = logData;
  myColorManager = colorManager;

  myScrollPane = new JBScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  myMainContentPanel = new ScrollablePanel() {
    @Override
    public boolean getScrollableTracksViewportWidth() {
      boolean expanded = false;
      for (Component c : getComponents()) {
        if (c instanceof CommitPanel && ((CommitPanel)c).isExpanded()) {
          expanded = true;
          break;
        }
      }
      return !expanded;
    }

    @Override
    public Dimension getPreferredSize() {
      Dimension preferredSize = super.getPreferredSize();
      int height = Math.max(preferredSize.height, myScrollPane.getViewport().getHeight());
      JBScrollPane scrollPane = UIUtil.getParentOfType(JBScrollPane.class, this);
      if (scrollPane == null || getScrollableTracksViewportWidth()) {
        return new Dimension(preferredSize.width, height);
      }
      else {
        return new Dimension(Math.max(preferredSize.width, scrollPane.getViewport().getWidth()), height);
      }
    }

    @Override
    public Color getBackground() {
      return CommitPanel.getCommitDetailsBackground();
    }

    @Override
    protected void paintChildren(Graphics g) {
      if (StringUtil.isNotEmpty(myEmptyText.getText())) {
        myEmptyText.paint(this, g);
      }
      else {
        super.paintChildren(g);
      }
    }
  };
  myEmptyText = new StatusText(myMainContentPanel) {
    @Override
    protected boolean isStatusVisible() {
      return StringUtil.isNotEmpty(getText());
    }
  };
  myMainContentPanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));

  myMainContentPanel.setOpaque(false);
  myScrollPane.setViewportView(myMainContentPanel);
  myScrollPane.setBorder(IdeBorderFactory.createEmptyBorder());
  myScrollPane.setViewportBorder(IdeBorderFactory.createEmptyBorder());

  myLoadingPanel = new JBLoadingPanel(new BorderLayout(), parent, ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS) {
    @Override
    public Color getBackground() {
      return CommitPanel.getCommitDetailsBackground();
    }
  };
  myLoadingPanel.add(myScrollPane);

  setLayout(new BorderLayout());
  add(myLoadingPanel, BorderLayout.CENTER);

  myEmptyText.setText("Commit details");
}
 
Example 4
Source File: ParameterInfoTaskRunnerUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static Consumer<Boolean> startProgressAndCreateStopAction(Project project, String progressTitle, AtomicReference<CancellablePromise<?>> promiseRef, Editor editor) {
  AtomicReference<Consumer<Boolean>> stopActionRef = new AtomicReference<>();

  Consumer<Boolean> originalStopAction = (cancel) -> {
    stopActionRef.set(null);
    if (cancel) {
      CancellablePromise<?> promise = promiseRef.get();
      if (promise != null) {
        promise.cancel();
      }
    }
  };

  if (progressTitle == null) {
    stopActionRef.set(originalStopAction);
  }
  else {
    final Disposable disposable = Disposable.newDisposable();
    Disposer.register(project, disposable);

    JBLoadingPanel loadingPanel = new JBLoadingPanel(null, panel -> new LoadingDecorator(panel, disposable, 0, false, new AsyncProcessIcon("ShowParameterInfo")) {
      @Override
      protected NonOpaquePanel customizeLoadingLayer(JPanel parent, JLabel text, AsyncProcessIcon icon) {
        parent.setLayout(new FlowLayout(FlowLayout.LEFT));
        final NonOpaquePanel result = new NonOpaquePanel();
        result.add(icon);
        parent.add(result);
        return result;
      }
    });
    loadingPanel.add(new JBLabel(EmptyIcon.ICON_18));
    loadingPanel.add(new JBLabel(progressTitle));

    ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(loadingPanel, null).setProject(project).setCancelCallback(() -> {
      Consumer<Boolean> stopAction = stopActionRef.get();
      if (stopAction != null) {
        stopAction.accept(true);
      }
      return true;
    });
    JBPopup popup = builder.createPopup();
    Disposer.register(disposable, popup);
    ScheduledFuture<?> showPopupFuture = EdtScheduledExecutorService.getInstance().schedule(() -> {
      if (!popup.isDisposed() && !popup.isVisible() && !editor.isDisposed()) {
        RelativePoint popupPosition = JBPopupFactory.getInstance().guessBestPopupLocation(editor);
        loadingPanel.startLoading();
        popup.show(popupPosition);
      }
    }, ModalityState.defaultModalityState(), DEFAULT_PROGRESS_POPUP_DELAY_MS, TimeUnit.MILLISECONDS);

    stopActionRef.set((cancel) -> {
      try {
        loadingPanel.stopLoading();
        originalStopAction.accept(cancel);
      }
      finally {
        showPopupFuture.cancel(false);
        UIUtil.invokeLaterIfNeeded(() -> {
          if (popup.isVisible()) {
            popup.setUiVisible(false);
          }
          Disposer.dispose(disposable);
        });
      }
    });
  }

  return stopActionRef.get();
}