Beispiel #1
0
    private String cutString(final String text, final double value) {
      final FontMetrics m = getFontMetrics(getFont());
      final Graphics g = getGraphics();

      if (m.getStringBounds(text, g).getWidth() < value) return text;

      final String dots = "...";
      final double dotsWidth = m.getStringBounds(dots, g).getWidth();
      if (dotsWidth >= value) {
        return dots;
      }

      for (int i = 1; i < text.length(); i++) {
        if ((m.getStringBounds(text, 0, i, g).getWidth() + dotsWidth) >= value) {
          if (i < 2) return dots;
          return text.substring(0, i - 1) + dots;
        }
      }
      return text;
    }
  public CopiesPanel(final Project project) {
    myProject = project;
    myConnection = myProject.getMessageBus().connect(myProject);
    myVcs = SvnVcs.getInstance(myProject);
    myCurrentInfoList = null;

    final Runnable focus =
        new Runnable() {
          @Override
          public void run() {
            IdeFocusManager.getInstance(myProject).requestFocus(myRefreshLabel, true);
          }
        };
    final Runnable refreshView =
        new Runnable() {
          @Override
          public void run() {
            final List<WCInfo> infoList = myVcs.getWcInfosWithErrors();
            final boolean hasErrors = !myVcs.getSvnFileUrlMapping().getErrorRoots().isEmpty();
            final List<WorkingCopyFormat> supportedFormats = getSupportedFormats();
            Runnable runnable =
                new Runnable() {
                  @Override
                  public void run() {
                    if (myCurrentInfoList != null) {
                      final List<OverrideEqualsWrapper<WCInfo>> newList =
                          ObjectsConvertor.convert(
                              infoList,
                              new Convertor<WCInfo, OverrideEqualsWrapper<WCInfo>>() {
                                @Override
                                public OverrideEqualsWrapper<WCInfo> convert(WCInfo o) {
                                  return new OverrideEqualsWrapper<WCInfo>(
                                      InfoEqualityPolicy.getInstance(), o);
                                }
                              },
                              ObjectsConvertor.NOT_NULL);

                      if (Comparing.haveEqualElements(newList, myCurrentInfoList)) {
                        myRefreshLabel.setEnabled(true);
                        return;
                      }
                      myCurrentInfoList = newList;
                    }
                    Collections.sort(infoList, WCComparator.getInstance());
                    updateList(infoList, supportedFormats);
                    myRefreshLabel.setEnabled(true);
                    showErrorNotification(hasErrors);
                    SwingUtilities.invokeLater(focus);
                  }
                };
            ApplicationManager.getApplication().invokeLater(runnable, ModalityState.NON_MODAL);
          }
        };
    final Consumer<Boolean> refreshOnPooled =
        new Consumer<Boolean>() {
          @Override
          public void consume(Boolean somethingNew) {
            if (Boolean.TRUE.equals(somethingNew)) {
              if (ApplicationManager.getApplication().isUnitTestMode()) {
                refreshView.run();
              } else {
                ApplicationManager.getApplication().executeOnPooledThread(refreshView);
              }
            } else {
              ApplicationManager.getApplication()
                  .invokeLater(
                      new Runnable() {
                        @Override
                        public void run() {
                          myRefreshLabel.setEnabled(true);
                        }
                      },
                      ModalityState.NON_MODAL);
            }
          }
        };
    myConnection.subscribe(SvnVcs.ROOTS_RELOADED, refreshOnPooled);

    final JPanel holderPanel = new JPanel(new BorderLayout());
    FontMetrics fm = holderPanel.getFontMetrics(holderPanel.getFont());
    myTextHeight = (int) (fm.getHeight() * 1.3);
    myPanel = new JPanel(new GridBagLayout());
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(myPanel, BorderLayout.NORTH);
    holderPanel.add(panel, BorderLayout.WEST);
    myRefreshLabel =
        new MyLinkLabel(
            myTextHeight,
            "Refresh",
            new LinkListener() {
              @Override
              public void linkSelected(LinkLabel aSource, Object aLinkData) {
                if (myRefreshLabel.isEnabled()) {
                  myVcs.invokeRefreshSvnRoots();
                  myRefreshLabel.setEnabled(false);
                }
              }
            });
    final JScrollPane pane = ScrollPaneFactory.createScrollPane(holderPanel);
    myHolder = pane;
    final JScrollBar vBar = pane.getVerticalScrollBar();
    vBar.setBlockIncrement(vBar.getBlockIncrement() * 5);
    vBar.setUnitIncrement(vBar.getUnitIncrement() * 5);
    myHolder.setBorder(null);
    setFocusableForLinks(myRefreshLabel);
    refreshOnPooled.consume(true);
    initView();
  }