/**
   * Creates the map area basket panel.
   *
   * @return the j panel
   */
  private JPanel createMapAreaBasketPanel() {
    JPanel panel = userInterfaceFactory.createPanel();
    GridBagConstraints panelGC = userInterfaceFactory.createGridBagConstraints();

    String mapAreaBasketLabelText =
        RIFJobSubmissionToolMessages.getMessage("mapAreaListSelectionPanel.mapAreaBasket.label");
    JLabel mapAreaBasketLabel = userInterfaceFactory.createLabel(mapAreaBasketLabelText);
    userInterfaceFactory.setBoldFont(mapAreaBasketLabel);
    panel.add(mapAreaBasketLabel, panelGC);

    panelGC.gridy++;
    panelGC.fill = GridBagConstraints.BOTH;
    panelGC.weightx = 1.0;
    panelGC.weighty = 1.0;

    JScrollPane selectedItemsStatusScrollPane =
        userInterfaceFactory.createScrollPane(selectedItemsStatusTextArea);
    panel.add(selectedItemsStatusScrollPane, panelGC);

    panelGC.gridy++;
    panelGC.fill = GridBagConstraints.NONE;
    panelGC.weightx = 0;
    panelGC.weighty = 0;
    panelGC.anchor = GridBagConstraints.SOUTHEAST;
    panel.add(createBasketControlButtonsPanel(), panelGC);

    return panel;
  }
  /** Builds the ui. */
  private void buildUI() {

    panel.removeAll();
    GridBagConstraints panelGC = userInterfaceFactory.createGridBagConstraints();

    String currentSelectionAreaTitleText =
        RIFJobSubmissionToolMessages.getMessage("mapAreaListSelectionPanel.title");
    JLabel currentSelectionAreaTitleLabel =
        userInterfaceFactory.createLabel(currentSelectionAreaTitleText);
    String currentSelectionAreaTitleToolTipText =
        RIFJobSubmissionToolMessages.getMessage("mapAreaListSelectionPanel.title.toolTip");
    currentSelectionAreaTitleLabel.setToolTipText(currentSelectionAreaTitleToolTipText);
    userInterfaceFactory.setBoldFont(currentSelectionAreaTitleLabel);
    panel.add(currentSelectionAreaTitleLabel, panelGC);

    panelGC.gridy++;
    panelGC.fill = GridBagConstraints.BOTH;
    panelGC.weightx = 1;
    panelGC.weighty = 0.8;
    panel.add(createMainPanel(), panelGC);

    panelGC.gridy++;
    panelGC.fill = GridBagConstraints.HORIZONTAL;
    panelGC.weightx = 1;
    panelGC.weighty = 0;
    panel.add(createMapAreaBasketPanel(), panelGC);

    updateBasketStatusPanel();
  }
  /**
   * Creates the main panel.
   *
   * @return the j panel
   */
  private JPanel createMainPanel() {

    JPanel panel = userInterfaceFactory.createPanel();
    GridBagConstraints panelGC = userInterfaceFactory.createGridBagConstraints();
    panelGC.fill = GridBagConstraints.BOTH;
    panelGC.weightx = 1;
    panelGC.weighty = 1;
    panel.add(viewPanel, panelGC);

    /*
    		panelGC.gridx++;
    		panelGC.weightx = 0.3;
    		panel.add(createMapDisplayPanel(), panelGC);
    */
    return panel;
  }
  /**
   * Instantiates a new map area list selection panel.
   *
   * @param parentDialog the parent dialog
   * @param rifSession the rif session
   */
  public MapAreaListSelectionPanel(JDialog parentDialog, RIFStudySubmissionToolSession rifSession) {

    this.parentDialog = parentDialog;
    this.rifSession = rifSession;
    this.userInterfaceFactory = rifSession.getUIFactory();

    String noDataDisplayedText =
        RIFJobSubmissionToolMessages.getMessage("mapAreaListSelectionPanel.noDataDisplayed");
    noDataDisplayedPanel =
        new NoDataAvailablePanel(userInterfaceFactory, noDataDisplayedText, true);

    mapAreaSelectionTableView = new MapAreaSelectionTableView(parentDialog, rifSession, true);
    // mapAreaSelectionTableView.updateDisplay();
    viewPanel = userInterfaceFactory.createBorderLayoutPanel();
    selectedItemsStatusTextArea = userInterfaceFactory.createNonEditableTextArea(4, 30);

    // mapImagePanel = new MapImagePanel();
    panel = userInterfaceFactory.createPanel();

    basketControlButtonPanel = new ListEditingButtonPanel(userInterfaceFactory);
  }
  /**
   * Instantiates a new work flow progress panel.
   *
   * @param userInterfaceFactory the user interface factory
   */
  public WorkFlowProgressPanel(UserInterfaceFactory userInterfaceFactory) {

    panel = userInterfaceFactory.createPanel();
    panelGC = userInterfaceFactory.createGridBagConstraints();
    panelGC.fill = GridBagConstraints.NONE;
    panelGC.insets = new Insets(5, 0, 0, 0);
    panelGC.weightx = 0;
    panelGC.ipadx = 5;
    panelGC.ipady = 5;

    String selectStudyLabelText =
        RIFStudySubmissionActivityStep.CREATE_OR_COPY_STUDY_STEP.getName();
    selectStudy = new WorkFlowStep(selectStudyLabelText);

    String describeStudyLabelText = RIFStudySubmissionActivityStep.DESCRIBE_STUDY.getName();
    describeStudy = new WorkFlowStep(describeStudyLabelText);

    String selectStudyAreaLabelText = RIFStudySubmissionActivityStep.CHOOSE_STUDY_AREA.getName();
    selectStudyArea = new WorkFlowStep(selectStudyAreaLabelText);

    String selectComparisonAreaLabelText =
        RIFStudySubmissionActivityStep.CHOOSE_COMPARISON_AREA.getName();
    selectComparisonArea = new WorkFlowStep(selectComparisonAreaLabelText);

    String selectInvestigationsLabelText =
        RIFStudySubmissionActivityStep.SPECIFY_INVESTIGATIONS.getName();
    selectInvestigations = new WorkFlowStep(selectInvestigationsLabelText);

    String specifyReportingOptionsLabelText =
        RIFStudySubmissionActivityStep.SPECIFY_REPORTS.getName();
    specifyReportingOptions = new WorkFlowStep(specifyReportingOptionsLabelText);

    String previewLabelText = RIFStudySubmissionActivityStep.PREVIEW.getName();
    showPreview = new WorkFlowStep(previewLabelText);

    panel.setBorder(LineBorder.createGrayLineBorder());

    selectStudyArea();
  }
  /** Export map areas. */
  private void exportMapAreas() {

    JFileChooser fileChooser = userInterfaceFactory.createFileChooser();
    XMLFileFilter xmlFileFilter = new XMLFileFilter();
    fileChooser.setFileFilter(xmlFileFilter);
    int result = fileChooser.showSaveDialog(parentDialog);
    if (result != JFileChooser.APPROVE_OPTION) {
      return;
    }

    File selectedFile = XMLFileFilter.ensureFileEndsWithXML(fileChooser.getSelectedFile());
    ArrayList<MapArea> mapAreasToWrite = currentMapAreaSelectionBasket.getMapAreas();
    MapAreaListWriter mapAreaListWriter = new MapAreaListWriter();

    try {
      mapAreaListWriter.writeFile(selectedFile, mapAreasToWrite);
    } catch (RIFServiceException rifServiceException) {
      ErrorDialog.showError(parentDialog, rifServiceException.getErrorMessages());
    }
  }
  /** Import map areas. */
  private void importMapAreas() {

    JFileChooser fileChooser = userInterfaceFactory.createFileChooser();
    XMLFileFilter xmlFileFilter = new XMLFileFilter();
    fileChooser.setFileFilter(xmlFileFilter);
    int result = fileChooser.showOpenDialog(parentDialog);
    if (result != JFileChooser.APPROVE_OPTION) {
      return;
    }

    File selectedFile = fileChooser.getSelectedFile();

    MapAreaListReader mapAreaListReader = new MapAreaListReader();
    try {
      mapAreaListReader.readFile(selectedFile);
      ArrayList<MapArea> mapAreasToAdd = mapAreaListReader.getMapAreas();
      currentMapAreaSelectionBasket.addMapAreas(mapAreasToAdd);
    } catch (RIFServiceException rifServiceException) {
      ErrorDialog.showError(parentDialog, rifServiceException.getErrorMessages());
    }
  }