protected boolean askReloadFromDisk(final VirtualFile file, final Document document) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (!isDocumentUnsaved(document)) return true;

    String message = UIBundle.message("file.cache.conflict.message.text", file.getPresentableUrl());
    if (ApplicationManager.getApplication().isUnitTestMode()) throw new RuntimeException(message);
    final DialogBuilder builder = new DialogBuilder((Project) null);
    builder.setCenterPanel(new JLabel(message, Messages.getQuestionIcon(), SwingConstants.CENTER));
    builder.addOkAction().setText(UIBundle.message("file.cache.conflict.load.fs.changes.button"));
    builder
        .addCancelAction()
        .setText(UIBundle.message("file.cache.conflict.keep.memory.changes.button"));
    builder.addAction(
        new AbstractAction(UIBundle.message("file.cache.conflict.show.difference.button")) {
          @Override
          public void actionPerformed(ActionEvent e) {
            String title =
                UIBundle.message(
                    "file.cache.conflict.for.file.dialog.title", file.getPresentableUrl());
            final ProjectEx project =
                (ProjectEx) ProjectLocator.getInstance().guessProjectForFile(file);

            SimpleDiffRequest request = new SimpleDiffRequest(project, title);
            FileType fileType = file.getFileType();
            String fsContent = LoadTextUtil.loadText(file).toString();
            request.setContents(
                new SimpleContent(fsContent, fileType),
                new DocumentContent(project, document, fileType));
            request.setContentTitles(
                UIBundle.message("file.cache.conflict.diff.content.file.system.content"),
                UIBundle.message("file.cache.conflict.diff.content.memory.content"));
            DialogBuilder diffBuilder = new DialogBuilder(project);
            DiffPanelImpl diffPanel =
                (DiffPanelImpl)
                    DiffManager.getInstance()
                        .createDiffPanel(diffBuilder.getWindow(), project, diffBuilder, null);
            diffPanel.getOptions().setShowSourcePolicy(DiffPanelOptions.ShowSourcePolicy.DONT_SHOW);
            diffBuilder.setCenterPanel(diffPanel.getComponent());
            diffBuilder.setDimensionServiceKey("FileDocumentManager.FileCacheConflict");
            diffPanel.setDiffRequest(request);
            diffBuilder
                .addOkAction()
                .setText(UIBundle.message("file.cache.conflict.save.changes.button"));
            diffBuilder.addCancelAction();
            diffBuilder.setTitle(title);
            if (diffBuilder.show() == DialogWrapper.OK_EXIT_CODE) {
              builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE);
            }
          }
        });
    builder.setTitle(UIBundle.message("file.cache.conflict.dialog.title"));
    builder.setButtonsAlignment(SwingConstants.CENTER);
    builder.setHelpId("reference.dialogs.fileCacheConflict");
    return builder.show() == 0;
  }
示例#2
0
 public static void showPathsInDialog(
     @NotNull Project project,
     @NotNull Collection<String> absolutePaths,
     @NotNull String title,
     @Nullable String description) {
   DialogBuilder builder = new DialogBuilder(project);
   builder.setCenterPanel(new GitSimplePathsBrowser(project, absolutePaths));
   if (description != null) {
     builder.setNorthPanel(new MultiLineLabel(description));
   }
   builder.addOkAction();
   builder.setTitle(title);
   builder.show();
 }
 private void showDirDiffDialog(
     @NotNull FilePath path,
     @Nullable String hash1,
     @Nullable String hash2,
     @NotNull List<Change> diff) {
   DialogBuilder dialogBuilder = new DialogBuilder(myProject);
   String title;
   if (hash2 != null) {
     if (hash1 != null) {
       title =
           String.format(
               "Difference between %s and %s in %s",
               GitUtil.getShortHash(hash1), GitUtil.getShortHash(hash2), path.getName());
     } else {
       title =
           String.format("Initial commit %s in %s", GitUtil.getShortHash(hash2), path.getName());
     }
   } else {
     LOG.assertTrue(hash1 != null, "hash1 and hash2 can't both be null. Path: " + path);
     title =
         String.format(
             "Difference between %s and local version in %s",
             GitUtil.getShortHash(hash1), path.getName());
   }
   dialogBuilder.setTitle(title);
   dialogBuilder.setActionDescriptors(
       new DialogBuilder.ActionDescriptor[] {new DialogBuilder.CloseDialogAction()});
   final ChangesBrowser changesBrowser =
       new ChangesBrowser(
           myProject,
           null,
           diff,
           null,
           false,
           true,
           null,
           ChangesBrowser.MyUseCase.COMMITTED_CHANGES,
           null);
   changesBrowser.setChangesToDisplay(diff);
   dialogBuilder.setCenterPanel(changesBrowser);
   dialogBuilder.show();
 }
  @Nullable
  private DependencyOnPlugin editPluginDependency(
      @NotNull JComponent parent, @NotNull final DependencyOnPlugin original) {
    List<String> pluginIds = new ArrayList<String>(getPluginNameByIdMap().keySet());
    if (!original.getPluginId().isEmpty() && !pluginIds.contains(original.getPluginId())) {
      pluginIds.add(original.getPluginId());
    }
    Collections.sort(
        pluginIds,
        new Comparator<String>() {
          @Override
          public int compare(String o1, String o2) {
            return getPluginNameById(o1).compareToIgnoreCase(getPluginNameById(o2));
          }
        });

    final ComboBox pluginChooser = new ComboBox(ArrayUtilRt.toStringArray(pluginIds), 250);
    pluginChooser.setRenderer(
        new ListCellRendererWrapper<String>() {
          @Override
          public void customize(
              JList list, String value, int index, boolean selected, boolean hasFocus) {
            setText(getPluginNameById(value));
          }
        });
    new ComboboxSpeedSearch(pluginChooser) {
      @Override
      protected String getElementText(Object element) {
        return getPluginNameById((String) element);
      }
    };
    pluginChooser.setSelectedItem(original.getPluginId());

    final JBTextField minVersionField =
        new JBTextField(StringUtil.notNullize(original.getMinVersion()));
    final JBTextField maxVersionField =
        new JBTextField(StringUtil.notNullize(original.getMaxVersion()));
    final JBTextField channelField = new JBTextField(StringUtil.notNullize(original.getChannel()));
    minVersionField.getEmptyText().setText("<any>");
    minVersionField.setColumns(10);
    maxVersionField.getEmptyText().setText("<any>");
    maxVersionField.setColumns(10);
    channelField.setColumns(10);
    JPanel panel =
        FormBuilder.createFormBuilder()
            .addLabeledComponent("Plugin:", pluginChooser)
            .addLabeledComponent("Minimum version:", minVersionField)
            .addLabeledComponent("Maximum version:", maxVersionField)
            .addLabeledComponent("Channel:", channelField)
            .getPanel();
    final DialogBuilder dialogBuilder =
        new DialogBuilder(parent).title("Required Plugin").centerPanel(panel);
    dialogBuilder.setPreferredFocusComponent(pluginChooser);
    pluginChooser.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            dialogBuilder.setOkActionEnabled(
                !StringUtil.isEmpty((String) pluginChooser.getSelectedItem()));
          }
        });
    if (dialogBuilder.show() == DialogWrapper.OK_EXIT_CODE) {
      return new DependencyOnPlugin(
          ((String) pluginChooser.getSelectedItem()),
          StringUtil.nullize(minVersionField.getText().trim()),
          StringUtil.nullize(maxVersionField.getText().trim()),
          StringUtil.nullize(channelField.getText().trim()));
    }
    return null;
  }