private static DialogBuilder createChangeInfoDialog(
      Project project, @NotNull CCNewProjectPanel panel) {
    DialogBuilder builder = new DialogBuilder(project);

    builder.setTitle(ACTION_TEXT);
    JPanel changeInfoPanel = panel.getMainPanel();
    changeInfoPanel.setMinimumSize(JBUI.size(400, 300));
    builder.setCenterPanel(changeInfoPanel);

    return builder;
  }
  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;
  }
예제 #3
0
  public ImportFileDialog(final String defaultValue, final DialogBuilder dialogBuilder) {
    setLayout(new GridBagLayout());

    _importDir = defaultValue;

    final GridBagConstraints c = new GridBagConstraints();
    c.gridy = 1;
    c.insets = new Insets(5, 5, 5, 5);
    c.anchor = GridBagConstraints.NORTHWEST;

    _dialogBuilder = dialogBuilder;

    final Component label = new JLabel("Import BugCollection from: ");

    c.weightx = 0;
    c.gridwidth = 2;
    add(label, c);
    _importFile = new JTextField("");
    _importFile.setEditable(false);
    _importFile.setPreferredSize(new Dimension(200, 20));
    c.weightx = 1;
    c.gridwidth = 1;
    add(_importFile, c);

    final AbstractButton browseButton = new JButton("Browse");
    browseButton.addActionListener(new MyFileChooserActionListener());
    c.weightx = 0;
    add(browseButton, c);

    c.gridx = GridBagConstraints.RELATIVE;
    c.gridy = 2;
    c.gridheight = 2;

    dialogBuilder.setCenterPanel(this);

    _importFile.getDocument().addDocumentListener(new MyDocumentAdapter());
    if (!_importFile.getText().isEmpty()) {
      _selectedFile = new File(_importFile.getText());
    }
    _importFile.addHierarchyListener(
        new HierarchyListener() {
          public void hierarchyChanged(final HierarchyEvent e) {
            if (_importFile.isVisible()) {
              _dialogBuilder.setOkActionEnabled(validateFile(_importFile.getDocument()));
            }
          }
        });
    _dialogBuilder.setOkActionEnabled(_selectedFile != null && _selectedFile.isDirectory());
  }
 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();
 }
  public void setActions(
      final DialogBuilder builder,
      MergePanel2 mergePanel,
      final Convertor<DialogWrapper, Boolean> preOkHook) {
    builder.removeAllActions(); // otherwise dialog will get default actions (OK, Cancel)

    if (myOkButtonPresentation != null) {
      if (builder.getOkAction() == null) {
        builder.addOkAction();
      }

      configureAction(builder, builder.getOkAction(), myOkButtonPresentation);
      builder.setOkOperation(
          new Runnable() {
            @Override
            public void run() {
              if (preOkHook != null && !preOkHook.convert(builder.getDialogWrapper())) return;
              myOkButtonPresentation.run(builder.getDialogWrapper());
            }
          });
    }

    if (myCancelButtonPresentation != null) {
      if (builder.getCancelAction() == null) {
        builder.addCancelAction();
      }

      configureAction(builder, builder.getCancelAction(), myCancelButtonPresentation);
      builder.setCancelOperation(
          new Runnable() {
            @Override
            public void run() {
              myCancelButtonPresentation.run(builder.getDialogWrapper());
            }
          });
    }

    if (getMergeContent() != null && mergePanel.getMergeList() != null) {
      new AllResolvedListener(mergePanel, builder.getDialogWrapper());
    }
  }
  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    if (project == null) {
      return;
    }
    Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course == null) {
      return;
    }

    CCNewProjectPanel panel =
        new CCNewProjectPanel(
            course.getName(),
            Course.getAuthorsString(course.getAuthors()),
            course.getDescription());
    DialogBuilder builder = createChangeInfoDialog(project, panel);
    if (builder.showAndGet()) {
      course.setAuthors(panel.getAuthors());
      course.setName(panel.getName());
      course.setDescription(panel.getDescription());
      ProjectView.getInstance(project).refresh();
    }
  }
예제 #7
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 static void configureAction(
      DialogBuilder builder,
      DialogBuilder.CustomizableAction customizableAction,
      ActionButtonPresentation presentation) {
    customizableAction.setText(presentation.getName());

    String actionName = presentation.getName();
    final int index = actionName.indexOf('&');
    final char mnemonic;
    if (index >= 0 && index < actionName.length() - 1) {
      mnemonic = actionName.charAt(index + 1);
      actionName = actionName.substring(0, index) + actionName.substring(index + 1);
    } else {
      mnemonic = 0;
    }
    final Action action =
        ((DialogBuilder.ActionDescriptor) customizableAction).getAction(builder.getDialogWrapper());
    action.putValue(Action.NAME, actionName);
    if (mnemonic > 0) {
      action.putValue(Action.MNEMONIC_KEY, Integer.valueOf(mnemonic));
    }
  }
  @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;
  }
  public void show(DiffRequest request) {
    Collection hints = request.getHints();
    boolean shouldOpenDialog = shouldOpenDialog(hints);
    if (shouldOpenDialog) {
      final DialogBuilder builder = new DialogBuilder(request.getProject());
      DiffPanelImpl diffPanel =
          createDiffPanelIfShouldShow(request, builder.getWindow(), builder, true);
      if (diffPanel == null) {
        Disposer.dispose(builder);
        return;
      }
      if (hints.contains(DiffTool.HINT_DIFF_IS_APPROXIMATE)) {
        diffPanel.setPatchAppliedApproximately(); // todo read only and not variants
      }
      final Runnable onOkRunnable = request.getOnOkRunnable();
      if (onOkRunnable != null) {
        builder.setOkOperation(
            new Runnable() {
              @Override
              public void run() {
                builder.getDialogWrapper().close(0);
                onOkRunnable.run();
              }
            });
      } else {
        builder.removeAllActions();
      }
      builder.setCenterPanel(diffPanel.getComponent());
      builder.setPreferredFocusComponent(diffPanel.getPreferredFocusedComponent());
      builder.setTitle(request.getWindowTitle());
      builder.setDimensionServiceKey(request.getGroupKey());

      new AnAction() {
        public void actionPerformed(final AnActionEvent e) {
          builder.getDialogWrapper().close(0);
        }
      }.registerCustomShortcutSet(
          new CustomShortcutSet(
              KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")),
          diffPanel.getComponent());
      showDiffDialog(builder, hints);
    } else {
      final FrameWrapper frameWrapper =
          new FrameWrapper(request.getProject(), request.getGroupKey());
      DiffPanelImpl diffPanel =
          createDiffPanelIfShouldShow(request, frameWrapper.getFrame(), frameWrapper, true);
      if (diffPanel == null) {
        Disposer.dispose(frameWrapper);
        return;
      }
      if (hints.contains(DiffTool.HINT_DIFF_IS_APPROXIMATE)) {
        diffPanel.setPatchAppliedApproximately();
      }
      frameWrapper.setTitle(request.getWindowTitle());
      DiffUtil.initDiffFrame(
          diffPanel.getProject(), frameWrapper, diffPanel, diffPanel.getComponent());

      new AnAction() {
        public void actionPerformed(final AnActionEvent e) {
          frameWrapper.getFrame().dispose();
        }
      }.registerCustomShortcutSet(
          new CustomShortcutSet(
              KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")),
          diffPanel.getComponent());

      frameWrapper.show();
    }
  }
 static void showDiffDialog(DialogBuilder builder, Collection hints) {
   builder.showModal(!hints.contains(DiffTool.HINT_SHOW_NOT_MODAL_DIALOG));
 }