コード例 #1
0
 private void storeComment() {
   if (lastAddedComment != null) {
     projConf.removeComment(lastAddedComment);
   }
   if (projConf.addComment(comment.getText())) {
     lastAddedComment = comment.getText();
   }
 }
コード例 #2
0
  private void setupPanel(CheckinProjectPanel checkinProjectPanel, final EntityRef ref) {
    // replace commit message only if necessary
    String prefix = ref.toString() + ": ";
    String msg = checkinProjectPanel.getCommitMessage();
    if (!msg.startsWith(prefix)) {
      checkinProjectPanel.setCommitMessage(prefix);
    }

    markFixed = new JCheckBox("Mark " + ref.toString() + " as ");
    if (ref.type.equals("defect")) {
      markFixedSelection = new JComboBox();

      markFixed.setEnabled(false);
      markFixedSelection.setEnabled(false);

      JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
      jPanel.add(markFixed);
      jPanel.add(markFixedSelection);
      panel.add(jPanel, BorderLayout.NORTH);

      final EntityService entityService = project.getComponent(EntityService.class);
      EntityListener callback =
          new EntityAdapter() {
            @Override
            public void entityLoaded(Entity entity, Event event) {
              final List<String> allowedTransitions =
                  projConf
                      .getStatusTransitions()
                      .getAllowedTransitions(entity.getPropertyValue("status"));

              Metadata metadata =
                  project.getComponent(MetadataService.class).getEntityMetadata(ref.type);
              final Field field = metadata.getAllFields().get("status");
              final List<String> list =
                  project.getComponent(ProjectListService.class).getProjectList(ref.type, field);

              UIUtil.invokeAndWaitIfNeeded(
                  new Runnable() {
                    public void run() {
                      for (String state : list) {
                        if (allowedTransitions.contains(state)) {
                          markFixedSelection.addItem(state);
                        }
                      }
                      if (markFixedSelection.getItemCount() > 0) {
                        markFixedSelection.setSelectedIndex(0);
                        markFixed.addActionListener(
                            new ActionListener() {
                              public void actionPerformed(ActionEvent actionEvent) {
                                markFixedSelection.setEnabled(markFixed.isSelected());
                              }
                            });
                        markFixed.setEnabled(true);
                        markFixedSelection.setEnabled(true);
                      }
                    }
                  });
            }
          };
      entityService.requestCachedEntity(ref, Arrays.asList("status"), callback);
    }

    comment = new JTextArea();
    comment.setLineWrap(true);
    comment.setWrapStyleWord(true);
    comment.setBorder(BorderFactory.createEtchedBorder());
    comment.getDocument().addDocumentListener(this);

    final List<String> comments = projConf.getComments();
    if (!comments.isEmpty()) {
      Collections.reverse(comments);
      comment.setText(comments.get(0));
    }

    header = new JPanel(new BorderLayout());
    addComment = new JCheckBox("Add comment to " + ref.toString());
    addComment.addActionListener(this);
    header.add(addComment, BorderLayout.WEST);

    DefaultActionGroup group = new DefaultActionGroup();
    group.add(
        new AnAction(
            "Choose Message",
            "Choose Recent Message",
            IconLoader.getIcon("/actions/consoleHistory.png")) {
          public void update(AnActionEvent e) {
            super.update(e);

            e.getPresentation().setEnabled(!comments.isEmpty());
          }

          public void actionPerformed(AnActionEvent e) {
            ContentChooser<String> chooser =
                new ContentChooser<String>(project, "Choose Message", false) {
                  protected void removeContentAt(final String content) {
                    projConf.getComments().remove(content);
                  }

                  protected String getStringRepresentationFor(String content) {
                    return content;
                  }

                  protected List<String> getContents() {
                    return comments;
                  }
                };

            chooser.show();

            if (chooser.isOK()) {
              if (!addComment.isSelected()) {
                addComment.setSelected(true);
                showCommentPane();
              }

              int selectedIndex = chooser.getSelectedIndex();

              if (selectedIndex >= 0) {
                comment.setText(chooser.getAllContents().get(selectedIndex));
              }
            }
          }
        });

    toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
    header.add(toolbar.getComponent(), BorderLayout.EAST);

    panelComment = new JPanel(new BorderLayout());
    panelComment.add(header, BorderLayout.NORTH);
    commentPane = new JBScrollPane(comment);

    panel.add(panelComment, BorderLayout.CENTER);

    // requirement doesn't show up in Idea12 unless explicitly revalidated
    panel.revalidate();
  }