/**
   * Create a new AddToDoItemDialog
   *
   * @param renderer the ListCellRenderer to use in order to display the offenders
   */
  public AddToDoItemDialog(ListCellRenderer renderer) {
    super(Translator.localize("dialog.title.add-todo-item"), Dialog.OK_CANCEL_OPTION, true);

    headLineTextField = new JTextField(TEXT_COLUMNS);
    priorityComboBox = new JComboBox(PRIORITIES);
    moreinfoTextField = new JTextField(TEXT_COLUMNS);
    descriptionTextArea = new JTextArea(TEXT_ROWS, TEXT_COLUMNS);

    DefaultListModel dlm = new DefaultListModel();
    Object[] offObj = TargetManager.getInstance().getModelTargets().toArray();
    for (int i = 0; i < offObj.length; i++) {
      if (offObj[i] != null) {
        dlm.addElement(offObj[i]);
      }
    }

    offenderList = new JList(dlm);
    offenderList.setCellRenderer(renderer);
    JScrollPane offenderScroll = new JScrollPane(offenderList);
    offenderScroll.setOpaque(true);

    JLabel headlineLabel = new JLabel(Translator.localize("label.headline"));
    JLabel priorityLabel = new JLabel(Translator.localize("label.priority"));
    JLabel moreInfoLabel = new JLabel(Translator.localize("label.more-info-url"));
    JLabel offenderLabel = new JLabel(Translator.localize("label.offenders"));
    priorityComboBox.setSelectedItem(PRIORITIES[0]);

    JPanel panel = new JPanel(new LabelledLayout(getLabelGap(), getComponentGap()));

    headlineLabel.setLabelFor(headLineTextField);
    panel.add(headlineLabel);
    panel.add(headLineTextField);

    priorityLabel.setLabelFor(priorityComboBox);
    panel.add(priorityLabel);
    panel.add(priorityComboBox);

    moreInfoLabel.setLabelFor(moreinfoTextField);
    panel.add(moreInfoLabel);
    panel.add(moreinfoTextField);

    offenderLabel.setLabelFor(offenderScroll);
    panel.add(offenderLabel);
    panel.add(offenderScroll);

    descriptionTextArea.setLineWrap(true); // MVW - Issue 2422
    descriptionTextArea.setWrapStyleWord(true); // MVW - Issue 2422
    descriptionTextArea.setText(Translator.localize("label.enter-todo-item") + "\n");
    descriptionTextArea.setMargin(new Insets(INSET_PX, INSET_PX, INSET_PX, INSET_PX));
    JScrollPane descriptionScroller = new JScrollPane(descriptionTextArea);
    descriptionScroller.setPreferredSize(descriptionTextArea.getPreferredSize());
    panel.add(descriptionScroller);

    setContent(panel);
  }
  /**
   * Reads the informations defined as TaggedValues
   *
   * @param manager the profile manager which will be used to resolve dependencies
   */
  private void loadModel() {
    synchronized (packageLock) {
      if (profilePackages == null) {
        try {
          if (modelFile != null) {
            profilePackages = new FileModelLoader().loadModel(reference);
          } else {
            profilePackages = new URLModelLoader().loadModel(reference);
          }
        } catch (ProfileException e1) {
          LOG.log(Level.SEVERE, "Exception loading profile " + reference.getPath(), e1);
          profilePackages = Collections.emptySet();
          return;
        }
      }

      Collection packagesInProfile = filterPackages(profilePackages);

      for (Object obj : packagesInProfile) {
        // if there is only one package in the model,
        // we should suppose it's the profile model,
        // if there is more than one, we take the ones
        // marked as <<profile>>
        if (Model.getFacade().isAModelElement(obj)
            && (Model.getFacade().isAProfile(obj) || (packagesInProfile.size() == 1))) {

          // load profile name
          String name = Model.getFacade().getName(obj);
          if (name != null) {
            displayName = name;
          } else {
            if (displayName == null) {
              displayName = Translator.localize("misc.profile.unnamed");
            }
          }
          LOG.log(Level.INFO, "profile {0}", displayName);

          loadDependentProfiles(obj);
        }
      }

      loadFigNodes(packagesInProfile);
    }
  }
/** The dialog to enter a new ToDoItem. */
public class AddToDoItemDialog extends ArgoDialog {

  ////////////////////////////////////////////////////////////////
  // constants
  private static final String[] PRIORITIES = {
    Translator.localize("misc.level.high"),
    Translator.localize("misc.level.medium"),
    Translator.localize("misc.level.low"),
  };
  private static final int TEXT_ROWS = 8;
  private static final int TEXT_COLUMNS = 30;
  /** Insets in pixels */
  private static final int INSET_PX = 3;

  ////////////////////////////////////////////////////////////////
  // instance variables
  private JTextField headLineTextField;
  private JComboBox priorityComboBox;
  private JTextField moreinfoTextField;
  private JList offenderList;
  private JTextArea descriptionTextArea;

  /**
   * Create a new AddToDoItemDialog
   *
   * @param renderer the ListCellRenderer to use in order to display the offenders
   */
  public AddToDoItemDialog(ListCellRenderer renderer) {
    super(Translator.localize("dialog.title.add-todo-item"), Dialog.OK_CANCEL_OPTION, true);

    headLineTextField = new JTextField(TEXT_COLUMNS);
    priorityComboBox = new JComboBox(PRIORITIES);
    moreinfoTextField = new JTextField(TEXT_COLUMNS);
    descriptionTextArea = new JTextArea(TEXT_ROWS, TEXT_COLUMNS);

    DefaultListModel dlm = new DefaultListModel();
    Object[] offObj = TargetManager.getInstance().getModelTargets().toArray();
    for (int i = 0; i < offObj.length; i++) {
      if (offObj[i] != null) {
        dlm.addElement(offObj[i]);
      }
    }

    offenderList = new JList(dlm);
    offenderList.setCellRenderer(renderer);
    JScrollPane offenderScroll = new JScrollPane(offenderList);
    offenderScroll.setOpaque(true);

    JLabel headlineLabel = new JLabel(Translator.localize("label.headline"));
    JLabel priorityLabel = new JLabel(Translator.localize("label.priority"));
    JLabel moreInfoLabel = new JLabel(Translator.localize("label.more-info-url"));
    JLabel offenderLabel = new JLabel(Translator.localize("label.offenders"));
    priorityComboBox.setSelectedItem(PRIORITIES[0]);

    JPanel panel = new JPanel(new LabelledLayout(getLabelGap(), getComponentGap()));

    headlineLabel.setLabelFor(headLineTextField);
    panel.add(headlineLabel);
    panel.add(headLineTextField);

    priorityLabel.setLabelFor(priorityComboBox);
    panel.add(priorityLabel);
    panel.add(priorityComboBox);

    moreInfoLabel.setLabelFor(moreinfoTextField);
    panel.add(moreInfoLabel);
    panel.add(moreinfoTextField);

    offenderLabel.setLabelFor(offenderScroll);
    panel.add(offenderLabel);
    panel.add(offenderScroll);

    descriptionTextArea.setLineWrap(true); // MVW - Issue 2422
    descriptionTextArea.setWrapStyleWord(true); // MVW - Issue 2422
    descriptionTextArea.setText(Translator.localize("label.enter-todo-item") + "\n");
    descriptionTextArea.setMargin(new Insets(INSET_PX, INSET_PX, INSET_PX, INSET_PX));
    JScrollPane descriptionScroller = new JScrollPane(descriptionTextArea);
    descriptionScroller.setPreferredSize(descriptionTextArea.getPreferredSize());
    panel.add(descriptionScroller);

    setContent(panel);
  }

  /*
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  @Override
  public void actionPerformed(ActionEvent e) {
    super.actionPerformed(e);
    if (e.getSource() == getOkButton()) {
      doAdd();
    }
  }

  private void doAdd() {
    Designer designer = Designer.theDesigner();
    String headline = headLineTextField.getText();
    int priority = ToDoItem.HIGH_PRIORITY;
    switch (priorityComboBox.getSelectedIndex()) {
      case 0:
        priority = ToDoItem.HIGH_PRIORITY;
        break;
      case 1:
        priority = ToDoItem.MED_PRIORITY;
        break;
      case 2:
        priority = ToDoItem.LOW_PRIORITY;
        break;
    }
    String desc = descriptionTextArea.getText();
    String moreInfoURL = moreinfoTextField.getText();
    ListSet newOffenders = new ListSet();
    for (int i = 0; i < offenderList.getModel().getSize(); i++) {
      newOffenders.add(offenderList.getModel().getElementAt(i));
    }
    ToDoItem item = new UMLToDoItem(designer, headline, priority, desc, moreInfoURL, newOffenders);
    designer.getToDoList().addElement(item); // ? inform()
    Designer.firePropertyChange(Designer.MODEL_TODOITEM_ADDED, null, item);
  }
}
  private CrOCL generateCriticFromComment(Object critique) {
    String ocl = "" + Model.getFacade().getBody(critique);
    String headline = null;
    String description = null;
    int priority = ToDoItem.HIGH_PRIORITY;
    List<Decision> supportedDecisions = new ArrayList<Decision>();
    List<String> knowledgeTypes = new ArrayList<String>();
    String moreInfoURL = null;

    Collection tags = Model.getFacade().getTaggedValuesCollection(critique);
    boolean i18nFound = false;

    for (Object tag : tags) {
      if (Model.getFacade().getTag(tag).toLowerCase().equals("i18n")) {
        i18nFound = true;
        String i18nSource = Model.getFacade().getValueOfTag(tag);
        headline = Translator.localize(i18nSource + "-head");
        description = Translator.localize(i18nSource + "-desc");
        moreInfoURL = Translator.localize(i18nSource + "-moreInfoURL");
      } else if (!i18nFound && Model.getFacade().getTag(tag).toLowerCase().equals("headline")) {
        headline = Model.getFacade().getValueOfTag(tag);
      } else if (!i18nFound && Model.getFacade().getTag(tag).toLowerCase().equals("description")) {
        description = Model.getFacade().getValueOfTag(tag);
      } else if (Model.getFacade().getTag(tag).toLowerCase().equals("priority")) {
        priority = str2Priority(Model.getFacade().getValueOfTag(tag));
      } else if (Model.getFacade().getTag(tag).toLowerCase().equals("supporteddecision")) {
        String decStr = Model.getFacade().getValueOfTag(tag);

        StringTokenizer st = new StringTokenizer(decStr, ",;:");

        while (st.hasMoreTokens()) {
          Decision decision = str2Decision(st.nextToken().trim().toLowerCase());

          if (decision != null) {
            supportedDecisions.add(decision);
          }
        }
      } else if (Model.getFacade().getTag(tag).toLowerCase().equals("knowledgetype")) {
        String ktStr = Model.getFacade().getValueOfTag(tag);

        StringTokenizer st = new StringTokenizer(ktStr, ",;:");

        while (st.hasMoreTokens()) {
          String knowledge = str2KnowledgeType(st.nextToken().trim().toLowerCase());

          if (knowledge != null) {
            knowledgeTypes.add(knowledge);
          }
        }
      } else if (!i18nFound && Model.getFacade().getTag(tag).toLowerCase().equals("moreinfourl")) {
        moreInfoURL = Model.getFacade().getValueOfTag(tag);
      }
    }

    LOG.log(Level.FINE, "OCL-Critic: {0}", ocl);

    try {
      return new CrOCL(
          ocl, headline, description, priority, supportedDecisions, knowledgeTypes, moreInfoURL);
    } catch (InvalidOclException e) {
      LOG.log(Level.SEVERE, "Invalid OCL in XMI!", e);
      return null;
    }
  }