Example #1
0
  /**
   * Create a visualization of the mapping showing what columns the file had and what isatab fields
   * each of these columns have been mapped to
   *
   * @param sequence - sequence of assay processing.
   * @param nameOfFileBeingMapped - name to save the mapping visualization as.
   * @param mapping - Mappings for each isatab file to the incoming column name(s) and any literals.
   * @return JLayeredPane containing the GUI to display the mapping visualization.
   */
  private JLayeredPane createMappingVisualization(
      final int sequence,
      final String nameOfFileBeingMapped,
      Map<MappingField, List<String>> mapping) {

    JPanel visContainer = new JPanel();
    visContainer.setLayout(new BoxLayout(visContainer, BoxLayout.PAGE_AXIS));
    visContainer.setSize(
        new Dimension((int) (menuPanels.getWidth() * 0.80), (int) (menuPanels.getHeight() * 0.90)));

    Tree t = null;

    GenerateMappingView gmv = new GenerateMappingView(nameOfFileBeingMapped, mapping);
    File treeFile = gmv.generateView();

    try {
      t = (Tree) new TreeMLReader().readGraph(treeFile);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // create a new treemap
    final TreeView tview =
        new TreeView(
            t,
            new Dimension(
                (int) (menuPanels.getWidth() * 0.80), (int) (menuPanels.getHeight() * 0.90)));

    tview.setBackground(UIHelper.BG_COLOR);
    tview.setForeground(UIHelper.GREY_COLOR);

    visContainer.add(tview);

    JLabel help_section = new JLabel(mappingVisualisationHelp);
    visContainer.add(help_section);

    ImageIcon crumb = ((sequence - 1) == -1) ? breadcrumb4 : breadcrumb6;

    final JLayeredPane finalPanel =
        getGeneralLayout(mappingOverviewHeader, crumb, "", visContainer, getHeight());

    final MouseListener[] listeners = new MouseListener[2];

    listeners[0] =
        new MouseAdapter() {

          public void mouseEntered(MouseEvent mouseEvent) {
            backButton.setIcon(backOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            backButton.setIcon(back);
          }

          public void mousePressed(MouseEvent mouseEvent) {
            backButton.setIcon(back);

            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    HistoryComponent hc = previousPage.pop();
                    setCurrentPage(hc.getDisplayComponent());
                    assignListenerToLabel(backButton, hc.getListeners()[0]);
                    assignListenerToLabel(nextButton, hc.getListeners()[1]);
                  }
                });
          }
        };

    assignListenerToLabel(backButton, listeners[0]);

    listeners[1] =
        new MouseAdapter() {

          public void mouseEntered(MouseEvent mouseEvent) {
            nextButton.setIcon(nextOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            nextButton.setIcon(next);
          }

          public void mousePressed(MouseEvent mouseEvent) {
            nextButton.setIcon(next);
            Thread performMappingProcess =
                new Thread(
                    new Runnable() {
                      public void run() {
                        try {
                          if (sequence <= assaysToBeDefined.size() - 1) {
                            AssaySelection aso = assaysToBeDefined.get(sequence);
                            String nextMeasurement = aso.getMeasurement();
                            String nextTechnology = aso.getTechnology();
                            setCurrentPage(
                                createMappings(
                                    sequence,
                                    getTableReferenceObject(nextTechnology, nextMeasurement),
                                    fileColumns,
                                    nameOfFileBeingMapped,
                                    reader));
                          } else {
                            setCurrentPage(createSaveMappings());
                          }
                        } catch (BiffException e) {
                          setCurrentPage(lastPage);
                          log.error(e.getMessage());
                        } catch (IOException e) {
                          setCurrentPage(lastPage);
                          log.error(e.getMessage());
                        } catch (NoAvailableLoaderException e) {
                          setCurrentPage(lastPage);
                          log.error(e.getMessage());
                        }
                      }
                    });
            lastPage = currentPage;
            setCurrentPage(workingProgressScreen);
            performMappingProcess.start();
          }
        };

    assignListenerToLabel(nextButton, listeners[1]);
    return finalPanel;
  }
Example #2
0
  /**
   * Create JPanel allowing users to map a column to an ISATAB column in the sample or assay files.
   *
   * @param sequence - which sequence we are currently in with respect to defining the mappings. -1
   *     = defining sample file.
   * @param tableReference - TableReferenceObject to be used for the definition.
   * @param columnsToBeMappedTo - array of strings representing header value to be mapped to.
   * @param fileName - name of file being mapped
   * @param readerToUse - type of reader to use, @see FileLoader.CSV_READER_TXT,
   *     FileLoader.CSV_READER_CSV or FileLoader.SHEET_READER
   * @return JPanel containing the GUI to allow for mappings!
   */
  private JLayeredPane createMappings(
      final int sequence,
      final TableReferenceObject tableReference,
      final String[] columnsToBeMappedTo,
      final String fileName,
      final int readerToUse)
      throws BiffException, IOException, NoAvailableLoaderException {

    fixedMappings = sequence == -1 ? new HashMap<String, MappedElement>() : fixedMappings;

    final MappingEntryGUI mappingTableGUI =
        new MappingEntryGUI(
            tableReference,
            columnsToBeMappedTo,
            fileName,
            readerToUse,
            preExistingMapping,
            fixedMappings);
    mappingTableGUI.performPreliminaryLoading();
    mappingTableGUI.createGUI();
    mappingTableGUI.setSize(
        new Dimension((int) (menuPanels.getWidth() * 0.80), (int) (menuPanels.getHeight() * 0.90)));
    mappingTableGUI.setBorder(null);

    ImageIcon crumb = sequence == -1 ? breadcrumb3 : breadcrumb5;

    final JLayeredPane finalPanel =
        getGeneralLayout(
            performMappingHeader,
            crumb,
            getDescriptiveStringForFile(fileBeingMapped, sequence),
            mappingTableGUI,
            getHeight());

    final MouseListener[] listeners = new MouseListener[2];

    listeners[0] =
        new MouseAdapter() {

          public void mouseEntered(MouseEvent mouseEvent) {
            backButton.setIcon(backOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            backButton.setIcon(back);
          }

          public void mousePressed(MouseEvent mouseEvent) {
            backButton.setIcon(back);
            HistoryComponent hc = previousPage.pop();
            setCurrentPage(hc.getDisplayComponent());
            assignListenerToLabel(backButton, hc.getListeners()[0]);
            assignListenerToLabel(nextButton, hc.getListeners()[1]);
          }
        };

    assignListenerToLabel(backButton, listeners[0]);

    listeners[1] =
        new MouseAdapter() {

          public void mouseEntered(MouseEvent mouseEvent) {
            nextButton.setIcon(nextOver);
          }

          public void mouseExited(MouseEvent mouseEvent) {
            nextButton.setIcon(next);
          }

          public void mousePressed(MouseEvent mouseEvent) {
            // call mapping function!
            Thread mappingThread =
                new Thread(
                    new Runnable() {
                      public void run() {

                        final MappingLogic mu =
                            new MappingLogic(
                                mappingTableGUI.getTreeInfo(),
                                tableReference,
                                readerToUse,
                                mapToBlankFields);

                        TableReferenceObject populatedTRO = mu.doMapping(fileName, readerToUse);

                        // whenever we create the mappings now, we now add the mappings in a Map
                        // which
                        // point to the populated TROs for each of the assays to be defined and the
                        // study
                        // sample file to be defined!
                        if (sequence == -1) {
                          fixedMappings.put(
                              "Sample Name", mappingTableGUI.getMappingNodeForField("Sample Name"));
                          definitions.put(MappingObject.STUDY_SAMPLE, populatedTRO);
                        } else {
                          assaySelections.put(
                              populatedTRO.getTableName(), assaysToBeDefined.get(sequence));
                          definitions.put(populatedTRO.getTableName(), populatedTRO);
                        }

                        // at this point, we want to populate a Map relating field names
                        // with ISAFieldMappings for output at a later stage in XML format.
                        mappingsToSave.putAll(mappingTableGUI.createMappingRefs());

                        nextButton.setIcon(next);
                        previousPage.push(new HistoryComponent(finalPanel, listeners));

                        SwingUtilities.invokeLater(
                            new Runnable() {
                              public void run() {
                                setCurrentPage(
                                    createMappingVisualization(
                                        sequence + 1, fileName, mu.getVisMapping()));
                              }
                            });
                      }
                    });

            setCurrentPage(workingProgressScreen);
            mappingThread.start();
          }
        };

    assignListenerToLabel(nextButton, listeners[1]);

    return finalPanel;
  }