示例#1
0
 /**
  * This method is activated on the Keystrokes we are listening to in this implementation. Here it
  * listens for Copy and Paste ActionCommands. Selections comprising non-adjacent cells result in
  * invalid selection and then copy action cannot be performed. Paste is done by aligning the upper
  * left corner of the selection with the 1st element in the current selection of the JTable.
  */
 public void actionPerformed(ActionEvent e) {
   if (e.getActionCommand().compareTo("Copy") == 0) {
     StringBuffer sbf = new StringBuffer();
     // Check to ensure we have selected only a contiguous block of
     // cells
     int numcols = jTable1.getSelectedColumnCount();
     int numrows = jTable1.getSelectedRowCount();
     int[] rowsselected = jTable1.getSelectedRows();
     int[] colsselected = jTable1.getSelectedColumns();
     if (!((numrows - 1 == rowsselected[rowsselected.length - 1] - rowsselected[0]
             && numrows == rowsselected.length)
         && (numcols - 1 == colsselected[colsselected.length - 1] - colsselected[0]
             && numcols == colsselected.length))) {
       JOptionPane.showMessageDialog(
           null, "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE);
       return;
     }
     for (int i = 0; i < numrows; i++) {
       for (int j = 0; j < numcols; j++) {
         sbf.append(jTable1.getValueAt(rowsselected[i], colsselected[j]));
         if (j < numcols - 1) sbf.append("\t");
       }
       sbf.append("\n");
     }
     stsel = new StringSelection(sbf.toString());
     system = Toolkit.getDefaultToolkit().getSystemClipboard();
     system.setContents(stsel, stsel);
   }
   if (e.getActionCommand().compareTo("Paste") == 0) {
     System.out.println("Trying to Paste");
     int startRow = (jTable1.getSelectedRows())[0];
     int startCol = (jTable1.getSelectedColumns())[0];
     try {
       String trstring =
           (String) (system.getContents(this).getTransferData(DataFlavor.stringFlavor));
       System.out.println("String is:" + trstring);
       StringTokenizer st1 = new StringTokenizer(trstring, "\n");
       for (int i = 0; st1.hasMoreTokens(); i++) {
         rowstring = st1.nextToken();
         StringTokenizer st2 = new StringTokenizer(rowstring, "\t");
         for (int j = 0; st2.hasMoreTokens(); j++) {
           value = (String) st2.nextToken();
           if (startRow + i < jTable1.getRowCount() && startCol + j < jTable1.getColumnCount())
             jTable1.setValueAt(value, startRow + i, startCol + j);
           System.out.println(
               "Putting " + value + "at row = " + startRow + i + "column = " + startCol + j);
         }
       }
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
 }
示例#2
0
 protected void exportSelectedRowsAndClose() {
   int[] selectedRows = timeTable.getSelectedRows();
   Vector selectedNodes = new Vector();
   for (int i = 0; i < selectedRows.length; i++) {
     int row = selectedRows[i];
     selectedNodes.add(getMindMapNode(row));
   }
   // create new map:
   MindMap newMap = getMindMapController().newMap();
   MindMapController newMindMapController = (MindMapController) newMap.getModeController();
   // Tools.BooleanHolder booleanHolder = new Tools.BooleanHolder();
   // booleanHolder.setValue(false);
   for (Iterator iter = selectedNodes.iterator(); iter.hasNext(); ) {
     MindMapNode node = (MindMapNode) iter.next();
     // MindMapNode newNode = newMindMapController.addNewNode(
     // newMap.getRootNode(), 0, booleanHolder);
     // // copy style:
     // freemind.controller.actions.generated.instance.Pattern pattern =
     // StylePatternFactory.createPatternFromNode(node);
     // newMindMapController.applyPattern(newNode, pattern);
     // // copy text:
     // newMindMapController.setNodeText(newNode, node.getText());
     MindMapNode copy = node.shallowCopy();
     if (copy != null) {
       newMindMapController.insertNodeInto(copy, newMap.getRootNode());
     }
   }
   disposeDialog();
 }
示例#3
0
 /** Return a list of the plot indices of any selected rows. */
 public int[] getSelectedIndices() {
   int[] rows = table.getSelectedRows();
   if (rows.length == 0) {
     return null;
   }
   return rows;
 }
    /**
     * Create a Transferable to use as the source for a data transfer.
     *
     * @param c The component holding the data to be transfered. This argument is provided to enable
     *     sharing of TransferHandlers by multiple components.
     * @return The representation of the data to be transfered.
     */
    protected Transferable createTransferable(JComponent c) {
      Object[] values = null;
      if (c instanceof JList) {
        values = ((JList) c).getSelectedValues();
      } else if (c instanceof JTable) {
        JTable table = (JTable) c;
        int[] rows = table.getSelectedRows();
        if (rows != null) {
          values = new Object[rows.length];
          for (int i = 0; i < rows.length; i++) {
            values[i] = table.getValueAt(rows[i], 0);
          }
        }
      }
      if (values == null || values.length == 0) {
        return null;
      }

      StringBuffer plainBuf = new StringBuffer();
      StringBuffer htmlBuf = new StringBuffer();

      htmlBuf.append("<html>\n<body>\n<ul>\n");

      for (Object obj : values) {
        String val = ((obj == null) ? "" : obj.toString());
        plainBuf.append(val + "\n");
        htmlBuf.append("  <li>" + val + "\n");
      }

      // remove the last newline
      plainBuf.deleteCharAt(plainBuf.length() - 1);
      htmlBuf.append("</ul>\n</body>\n</html>");

      return new FileTransferable(plainBuf.toString(), htmlBuf.toString(), values);
    }
 /** @see com.ixora.rms.ui.artefacts.ArtefactSelectorPanel#handleRemoveArtefact() */
 protected void handleRemoveArtefact() {
   try {
     JTable table = getJTableArtefacts();
     int[] sel = table.getSelectedRows();
     if (Utils.isEmptyArray(sel)) {
       return;
     }
     for (int idx : sel) {
       DashboardInfo gi = (DashboardInfo) table.getModel().getValueAt(idx, 1);
       DashboardMap map = fDashboardRepository.getDashboardMap(fContext);
       if (map == null) {
         logger.error("Couldn't find query gruop map for context: " + this.fContext);
         return;
       }
       // ask for confitmation
       if (!UIUtils.getBooleanOkCancelInput(
           this.fViewContainer.getAppFrame(),
           MessageRepository.get(Msg.TITLE_CONFIRM_REMOVE_DASHBOARD),
           MessageRepository.get(
               Msg.TEXT_CONFIRM_REMOVE_DASHBOARD, new String[] {gi.getTranslatedName()}))) {
         return;
       }
       // remove the dashboard only for the current fSUOVersion
       map.remove(gi.getDashboard().getName(), fSUOVersion);
       fDashboardRepository.setDashboardMap(fContext, map);
       fDashboardRepository.save();
       // update model
       fSessionData.getDashboardHelper().removeDashboard(fContext, gi.getDashboard().getName());
       // refresh table model
       refreshTableModel();
     }
   } catch (Exception ex) {
     UIExceptionMgr.userException(ex);
   }
 }
  /**
   * Exports the given table to the given text file.
   *
   * @param fileName Name of the file
   * @param table Table to export
   * @throws IOException Thrown if an error occurs while writing to the file.
   */
  public void export(String fileName, JTable table) throws IOException {
    BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));

    // Export selected rows
    int[] rows = table.getSelectedRows();

    // Export entire table if there is no selection
    if (rows == null || rows.length < 1) {
      rows = new int[table.getRowCount()];
      for (int i = 0; i < rows.length; i++) {
        rows[i] = i;
      }
    }

    // Write headers
    for (int col = 0; col < table.getColumnCount(); col++) {
      bw.write(LINE_COMMENT);
      bw.write(table.getColumnName(col));
      if (col != table.getColumnCount()) bw.write(COL_DELIMITER);
    }
    bw.write(ROW_DELIMITER);

    // Write table content
    for (int row : rows) {
      for (int col = 0; col < table.getColumnCount(); col++) {
        Object o = table.getValueAt(row, col);
        if (o != null) bw.write(o.toString());
        if (col != table.getColumnCount()) bw.write(COL_DELIMITER);
      }
      bw.write(ROW_DELIMITER);
    }

    bw.close();
  }
示例#7
0
  public void selectionChanged() {
    int[] selRows = dataTable.getSelectedRows();
    boolean hasSelection = (selRows != null && selRows.length != 0);
    removeAction.setEnabled(hasSelection);

    frame.setRemoveActionEnabled(this, hasSelection);
  }
 private static void drawSelection(JTable table, int column, Graphics g, final int width) {
   int y = 0;
   final int[] rows = table.getSelectedRows();
   final int height = table.getRowHeight();
   for (int row : rows) {
     final TableCellRenderer renderer = table.getCellRenderer(row, column);
     final Component component =
         renderer.getTableCellRendererComponent(
             table, table.getValueAt(row, column), false, false, row, column);
     g.translate(0, y);
     component.setBounds(0, 0, width, height);
     boolean wasOpaque = false;
     if (component instanceof JComponent) {
       final JComponent j = (JComponent) component;
       if (j.isOpaque()) wasOpaque = true;
       j.setOpaque(false);
     }
     component.paint(g);
     if (wasOpaque) {
       ((JComponent) component).setOpaque(true);
     }
     y += height;
     g.translate(0, -y);
   }
 }
示例#9
0
  public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();

    if (o instanceof JMenuItem) {
      for (int i = 0; i < markItems.length; i++) {
        if (markItems[i] == o) {
          synchronized (alerts) {
            markAlerts(table.getSelectedRows(), i);
          }
          table.repaint();
          return;
        }
      }

      if (o == deleteAlerts) {
        deleteSelectedAlerts();
      } else if (o == deleteAlertsForHost) {
        deleteAlertsForHost();
      } else if (o == deleteAlertTypeForHost) {
        deleteAlertTypeForHost();
      } else if (o == moveToDetails) {
        moveToDetails();
      }
    }
  }
  /** Invoked when removing selected reading list is required. */
  private void onRemoveReadingList() {
    int[] rows = tblReadingLists.getSelectedRows();
    boolean haveFeeds = false;
    for (int i = 0; !haveFeeds && i < rows.length; i++) {
      int row = rows[i];
      haveFeeds = readingListsModel.getLists()[row].getFeeds().length > 0;
    }

    boolean delete = true;
    if (haveFeeds) {
      String msg =
          rows.length == 1
              ? Strings.message("guide.dialog.readinglists.has.feeds")
              : Strings.message("guide.dialog.readinglists.have.feeds");

      delete =
          JOptionPane.showConfirmDialog(
                  this,
                  msg,
                  Strings.message("guide.dialog.delete.readinglist"),
                  JOptionPane.YES_NO_OPTION)
              == JOptionPane.YES_OPTION;
    }

    if (delete) readingListsModel.removeRows(rows);
  }
示例#11
0
  public void unlinkTrees() { // reuse previous PartitionTreePrior
    int[] selRows = dataTable.getSelectedRows();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      PartitionTreeModel model = partition.getPartitionTreeModel();
      if (!model.getName().equals(partition.getName())
          && partition.getTraitType() == null) { // not a trait
        PartitionTreeModel newTree = new PartitionTreeModel(options, partition);

        // this prevents partition not broken, and used for unsharing tree prior only,
        // because sharing uses shareSameTreePrior, unsharing uses getPartitionTreePrior
        //                newTree.setPartitionTreePrior(newPrior); // important

        partition.setPartitionTreeModel(newTree);
      }
    }

    options.linkTreePriors(frame.getCurrentPartitionTreePrior());

    modelsChanged();

    fireDataChanged();
    options.taxonSets.clear();
    options.taxonSetsMono.clear();
    repaint();
  }
示例#12
0
  public void linkClocks() { // keep previous PartitionTreePrior for reuse
    int[] selRows = dataTable.getSelectedRows();

    List<PartitionData> selectedPartitionData = new ArrayList<PartitionData>();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      if (!selectedPartitionData.contains(partition)) selectedPartitionData.add(partition);
    }
    Object[] modelArray = options.getPartitionClockModels(selectedPartitionData).toArray();

    if (selectClockDialog == null) {
      selectClockDialog = new SelectClockDialog(frame);
    }

    int result = selectClockDialog.showDialog(modelArray);
    if (result != JOptionPane.CANCEL_OPTION) {
      PartitionClockModel model = selectClockDialog.getModel();
      if (selectClockDialog.getMakeCopy()) {
        model.setName(selectClockDialog.getName());
      }

      for (PartitionData partition : selectedPartitionData) {
        partition.setPartitionClockModel(model);
      }
    }

    modelsChanged();

    fireDataChanged();
    repaint();
  }
示例#13
0
  public void removeSelection() {
    int[] selRows = dataTable.getSelectedRows();
    Set<PartitionData> partitionsToRemove = new HashSet<PartitionData>();
    for (int row : selRows) {
      partitionsToRemove.add(options.dataPartitions.get(row));
    }

    // TODO: would probably be a good idea to check if the user wants to remove the last partition
    options.dataPartitions.removeAll(partitionsToRemove);

    //        if (options.allowDifferentTaxa && options.dataPartitions.size() < 2) {
    //            uncheckAllowDifferentTaxa();
    //        }

    if (options.getNonTraitsDataList().size() == 0) {
      // all data partitions removed so reset the taxa
      options.reset();
      useStarBEASTCheck.setSelected(false);
      frame.statusLabel.setText("");
      frame.setAllOptions();
      frame.getExportAction().setEnabled(false);
    }

    dataTableModel.fireTableDataChanged();

    fireDataChanged();
  }
示例#14
0
 private void removeSelectedRows() {
   DefaultTableModel model = (DefaultTableModel) jtable.getModel();
   int[] rows = jtable.getSelectedRows();
   for (int i = 0; i < rows.length; i++) {
     model.removeRow(rows[i] - i);
   }
 }
示例#15
0
  public void removeSelection() {
    int[] selRows = dataTable.getSelectedRows();
    Set<AbstractPartitionData> partitionsToRemove = new HashSet<AbstractPartitionData>();
    for (int row : selRows) {
      partitionsToRemove.add(options.dataPartitions.get(row));
    }

    boolean hasIdenticalTaxa =
        options.hasIdenticalTaxa(); // need to check this before removing partitions

    // TODO: would probably be a good idea to check if the user wants to remove the last partition
    options.dataPartitions.removeAll(partitionsToRemove);

    if (options.dataPartitions.size() == 0) {
      // all data partitions removed so reset the taxa
      options.reset();
      useStarBEASTCheck.setSelected(false);
      frame.setupStarBEAST(false);
      frame.statusLabel.setText("");
      frame.setAllOptions();
      frame.getExportAction().setEnabled(false);
    } else if (!hasIdenticalTaxa) {
      options.updateTaxonList();
    }

    dataTableModel.fireTableDataChanged();

    fireDataChanged();
  }
示例#16
0
 private void btnMessageWaehlenClicked() {
   int selectedRow[] = _tblMessages.getSelectedRows();
   if (selectedRow.length != 0) {
     String title = (String) _tblMessages.getValueAt(selectedRow[0], 0);
     String message = (String) _tblMessages.getValueAt(selectedRow[0], 1);
     _ctrl.selectedMessage(new DTOMessage(title, message, null, ""));
   }
 }
示例#17
0
 private void removeSelectedParameters() {
   int[] selRows = parametersTable.getSelectedRows();
   List<Parameter> parametersToRemove = new ArrayList<Parameter>();
   for (int row : selRows) {
     parametersToRemove.add((Parameter) parametersTable.getValueAt(row, 0));
   }
   removeParameters(parametersToRemove);
 }
示例#18
0
 private void removeIndexnode() {
   int[] togo = nodesTable.getSelectedRows();
   LinkedList<IndexNode> goodbye = new LinkedList<IndexNode>();
   for (int i : togo) {
     goodbye.add(comm.getRegisteredIndexNodes().get(nodesTable.convertRowIndexToModel(i)));
   }
   for (IndexNode n : goodbye) comm.deregisterIndexNode(n);
 }
示例#19
0
 public void clearData() {
   table.setRowSelectionInterval(0, table.getRowCount() - 1);
   int[] selectedRows = table.getSelectedRows();
   DefaultTableModel model = (DefaultTableModel) table.getModel();
   for (int i = selectedRows.length - 1; i >= 0; i--) {
     model.removeRow(selectedRows[i]);
   }
 }
示例#20
0
 public void jTable1_keyPressed(KeyEvent e) {
   if (e.getKeyCode() == 127) {
     int[] selected = jTable1.getSelectedRows();
     for (int i = selected.length - 1; i >= 0; i--) {
       model.removeRow(selected[i]);
       model.fireTableDataChanged();
     }
   }
 }
 /**
  * Devuelve el numero de la fila seleccionada
  *
  * @return int Numero de la fila seleccionada
  */
 public ArrayList getExpedienteSeleccionado() {
   ArrayList listaNumExp = new ArrayList();
   int filas[] = expedientesTable.getSelectedRows();
   for (int i = 0; i < filas.length; i++) {
     Vector fila = (Vector) modelo.getDataVector().elementAt(filas[i]);
     listaNumExp.add((String) fila.elementAt(0));
   }
   return listaNumExp;
 }
  private String extractContent(
      DataGridPanel grid, String delimiter, boolean saveHeader, boolean ecloseWithDowbleQuotes) {
    JTable _table = grid.getTable();

    int numcols = _table.getSelectedColumnCount();
    int numrows = _table.getSelectedRowCount();

    if (numcols > 0 && numrows > 0) {
      StringBuffer sbf = new StringBuffer();
      int[] rowsselected = _table.getSelectedRows();
      int[] colsselected = _table.getSelectedColumns();

      if (saveHeader) {
        // put header name list
        for (int j = 0; j < numcols; j++) {
          String text =
              (String)
                  _table
                      .getTableHeader()
                      .getColumnModel()
                      .getColumn(colsselected[j])
                      .getHeaderValue();
          sbf.append(text);
          if (j < numcols - 1) sbf.append(delimiter);
        }
        sbf.append("\n");
      }

      // put content
      for (int i = 0; i < numrows; i++) {
        for (int j = 0; j < numcols; j++) {
          Object value = _table.getValueAt(rowsselected[i], colsselected[j]);
          String _value = "";
          if (value != null) {
            _value = value.toString();
          }
          if (ecloseWithDowbleQuotes) {
            sbf.append("\"").append(_value).append("\"");
          } else {
            sbf.append(_value);
          }

          if (j < numcols - 1) sbf.append(delimiter);
        }
        sbf.append("\n");
      }

      //            StringSelection stsel = new StringSelection(sbf.toString());
      //            Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard();
      //            system.setContents(stsel, stsel);
      return sbf.toString();
    }

    return null;
  }
示例#23
0
  public void valueChanged(ListSelectionEvent e) {

    JTable table = statTable.getTable();

    int[] selRow = table.getSelectedRows();

    // exit if initing or nothing selected
    if (isIniting() || selRow.length == 0) return;

    if (getProbCalc().getProbMode() == ProbabilityCalculatorViewD.PROB_INTERVAL) {
      // System.out.println(Arrays.toString(selectedRow));
      String lowStr = (String) table.getModel().getValueAt(selRow[0], 0);
      String highStr = (String) table.getModel().getValueAt(selRow[selRow.length - 1], 0);
      int low = Integer.parseInt(lowStr);
      int high = Integer.parseInt(highStr);
      // System.out.println(low + " , " + high);
      ((ProbabilityCalculatorViewD) getProbCalc()).setInterval(low, high);
    } else if (getProbCalc().getProbMode() == ProbabilityCalculatorViewD.PROB_LEFT) {
      String lowStr = (String) statTable.getTable().getModel().getValueAt(0, 0);
      String highStr =
          (String) statTable.getTable().getModel().getValueAt(selRow[selRow.length - 1], 0);
      int low = Integer.parseInt(lowStr);
      int high = Integer.parseInt(highStr);
      // System.out.println(low + " , " + high);
      ((ProbabilityCalculatorViewD) getProbCalc()).setInterval(low, high);

      // adjust the selection
      table.getSelectionModel().removeListSelectionListener(this);
      if (isCumulative()) {
        // single row selected
        table.changeSelection(selRow[selRow.length - 1], 0, false, false);
      } else {
        // select multiple rows: first up to selected
        table.changeSelection(0, 0, false, false);
        table.changeSelection(selRow[selRow.length - 1], 0, false, true);
        table.scrollRectToVisible(table.getCellRect(selRow[selRow.length - 1], 0, true));
      }
      table.getSelectionModel().addListSelectionListener(this);
    } else if (getProbCalc().getProbMode() == ProbabilityCalculatorView.PROB_RIGHT) {
      String lowStr = (String) statTable.getTable().getModel().getValueAt(selRow[0], 0);
      int maxRow = statTable.getTable().getRowCount() - 1;
      String highStr = (String) statTable.getTable().getModel().getValueAt(maxRow, 0);
      int low = Integer.parseInt(lowStr);
      int high = Integer.parseInt(highStr);
      // System.out.println(low + " , " + high);
      ((ProbabilityCalculatorViewD) getProbCalc()).setInterval(low, high);

      table.getSelectionModel().removeListSelectionListener(this);
      table.changeSelection(maxRow, 0, false, false);
      table.changeSelection(selRow[0], 0, false, true);
      // table.scrollRectToVisible(table.getCellRect(selRow[0], 0, true));
      table.getSelectionModel().addListSelectionListener(this);
    }
  }
示例#24
0
 public Object[] getSelectedRows() {
   int[] rows = table.getSelectedRows();
   Object[] rowsSel = new Object[rows.length];
   for (int i = 0; i < rowsSel.length; i++) {
     rowsSel[i] = ((Vector) tableModel.getDataVector().get(rows[i])).toArray();
     if (((Object[]) rowsSel[i])[0] instanceof MarkedItem) {
       ((Object[]) rowsSel[i])[0] = ((MarkedItem) ((Object[]) rowsSel[i])[0]).item;
     }
   }
   return rowsSel;
 }
示例#25
0
 /** Sets the values of the selected cells to the textfield content. */
 private void fillTextIntoTable() {
   if (tblIntermed != null) {
     final int[] x = tblIntermed.getSelectedColumns();
     final int[] y = tblIntermed.getSelectedRows();
     for (final int i : y) {
       for (final int j : x) {
         tblIntermed.setValueAt(jTextField1.getText(), i, j);
       }
     }
   }
 }
示例#26
0
  public List<Ticket> getSelectedTickets() {
    int[] selectedRows = table.getSelectedRows();

    ArrayList<Ticket> tickets = new ArrayList<Ticket>(selectedRows.length);

    for (int i = 0; i < selectedRows.length; i++) {
      Ticket ticket = (Ticket) tableModel.getRowData(selectedRows[i]);
      tickets.add(ticket);
    }
    return tickets;
  }
示例#27
0
  private void deleteSelectedAlerts() {
    long[] alertsIds = null;

    if (JOptionPane.showConfirmDialog(this, "Delete " + table.getSelectedRowCount() + " Alerts?")
        != JOptionPane.YES_OPTION) {
      return;
    }

    synchronized (alerts) {
      deleteAlerts(table.getSelectedRows());
    }
  }
示例#28
0
 /**
  * DOCUMENT ME!
  *
  * @param evt DOCUMENT ME!
  */
 private void jButton1ActionPerformed(
     final java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed
   if (tblIntermed != null) {
     final int[] x = tblIntermed.getSelectedColumns();
     final int[] y = tblIntermed.getSelectedRows();
     for (final int i : y) {
       for (final int j : x) {
         tblIntermed.setValueAt(null, i, j);
       }
     }
   }
 } // GEN-LAST:event_jButton1ActionPerformed
示例#29
0
 public ArrayList<File> getSelectedFiles(JTable tblParent) {
   ArrayList<File> aRet = new ArrayList<File>();
   int aSelected[] = tblParent.getSelectedRows();
   for (int iSelectedRow : aSelected) {
     int iRow = tblParent.convertRowIndexToModel(iSelectedRow);
     if (iRow >= 0) {
       File fNext = allFiles.get(iRow);
       aRet.add(fNext);
     }
   }
   return aRet;
 }
示例#30
0
  public void linkTrees() { // keep previous PartitionTreePrior for reuse
    int[] selRows = dataTable.getSelectedRows();

    List<AbstractPartitionData> selectedPartitionData = new ArrayList<AbstractPartitionData>();
    for (int row : selRows) {
      AbstractPartitionData partition = options.dataPartitions.get(row);

      if (!selectedPartitionData.contains(partition)) selectedPartitionData.add(partition);
    }

    if (selectedPartitionData.size() > 1) {
      if (!options.hasIdenticalTaxa(selectedPartitionData)) {
        String errMsg = "To share a tree, partitions need to have identical taxa.";
        if (selectedPartitionData.get(0).getDataType().getType() == DataType.MICRO_SAT)
          errMsg += "\nThe data must be all diploid or all haploid when you want to link the tree.";
        JOptionPane.showMessageDialog(
            this, errMsg, "Illegal Configuration", JOptionPane.ERROR_MESSAGE);
        return;
      }
    }

    Object[] treeArray = options.getPartitionTreeModels(selectedPartitionData).toArray();

    if (selectTreeDialog == null) {
      selectTreeDialog = new SelectTreeDialog(frame);
    }

    int result = selectTreeDialog.showDialog(treeArray);
    if (result != JOptionPane.CANCEL_OPTION) {
      PartitionTreeModel model = selectTreeDialog.getTree();
      if (selectTreeDialog.getMakeCopy()) {
        model.setName(selectTreeDialog.getName());
      }
      PartitionTreePrior prior = model.getPartitionTreePrior();
      options.linkTreePriors(prior);

      for (AbstractPartitionData partition : selectedPartitionData) {
        partition.setPartitionTreeModel(model);
      }

      for (Taxa taxa :
          options.taxonSets) { // Issue 454: all the taxon sets are deleted when link/unlink tree
        PartitionTreeModel prevModel = options.taxonSetsTreeModel.get(taxa);
        if (prevModel != model) options.taxonSetsTreeModel.put(taxa, model);
      }
    }

    modelsChanged();

    fireDataChanged();
    repaint();
  }