@Override
  protected void updateButtons() {
    final CommonActionsPanel p = getActionsPanel();
    if (p != null) {
      boolean someElementSelected;
      if (myTable.isEnabled()) {
        final int index = myTable.getSelectedRow();
        final int size = myTable.getModel().getRowCount();
        someElementSelected = 0 <= index && index < size;
        if (someElementSelected) {
          final boolean downEnable = myTable.getSelectionModel().getMaxSelectionIndex() < size - 1;
          final boolean upEnable = myTable.getSelectionModel().getMinSelectionIndex() > 0;
          final boolean editEnabled = myTable.getSelectedRowCount() == 1;
          p.setEnabled(CommonActionsPanel.Buttons.EDIT, editEnabled);
          p.setEnabled(CommonActionsPanel.Buttons.UP, upEnable);
          p.setEnabled(CommonActionsPanel.Buttons.DOWN, downEnable);
        } else {
          p.setEnabled(CommonActionsPanel.Buttons.EDIT, false);
          p.setEnabled(CommonActionsPanel.Buttons.UP, false);
          p.setEnabled(CommonActionsPanel.Buttons.DOWN, false);
        }
        p.setEnabled(
            CommonActionsPanel.Buttons.ADD, myProducer == null || myProducer.canCreateElement());
      } else {
        someElementSelected = false;
        p.setEnabled(CommonActionsPanel.Buttons.ADD, false);
        p.setEnabled(CommonActionsPanel.Buttons.EDIT, false);
        p.setEnabled(CommonActionsPanel.Buttons.UP, false);
        p.setEnabled(CommonActionsPanel.Buttons.DOWN, false);
      }

      p.setEnabled(CommonActionsPanel.Buttons.REMOVE, someElementSelected);
      updateExtraElementActions(someElementSelected);
    }
  }
Exemplo n.º 2
0
 private void editAction() {
   if (tblMain.getSelectedRowCount() > 0) {
     PropertyForm.start(
         ((InstanceTableModel) tblMain.getModel()).getItem(tblMain.getSelectedRow()));
     refresh();
   }
 }
  /** @return selected principal */
  public Sync4jPrincipal getSelectedPrincipal() {

    int row = table.getSelectedRow();
    int rows = table.getSelectedRowCount();
    Sync4jPrincipal principal = model.principals[row];

    return principal;
  }
Exemplo n.º 4
0
 public boolean validateTabledDocs(Component field) {
   JTable tbl = (JTable) field;
   if (tbl.getSelectedRowCount() == 0) {
     checkFieldsMessages.add("Please select a tabled document!");
     return false;
   }
   return true;
 }
Exemplo n.º 5
0
 @Override
 public void valueChanged(final ListSelectionEvent e) {
   if (tblKassenzeichen.getSelectedRowCount() > 0) {
     btnLoadSelectedKassenzeichen.setEnabled(true);
   } else {
     btnLoadSelectedKassenzeichen.setEnabled(false);
   }
 }
  /** @return principal to delete */
  public Sync4jPrincipal getPrincipalToDelete() {

    int row = table.getSelectedRow();
    int rows = table.getSelectedRowCount();
    Sync4jPrincipal principalToDelete = model.principals[row];

    return principalToDelete;
  }
 @Override
 public void actionPerformed(ActionEvent e) {
   if (ADD_VARIABLE_ACTION.equals(e.getActionCommand())) {
     model.addRow(new String[] {"newKey", "newValue"});
   } else if (REMOVE_VARIABLE_ACTION.equals(e.getActionCommand())) {
     while (table.getSelectedRowCount() > 0) {
       model.removeRow(table.getSelectedRow());
     }
   }
 }
  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;
  }
Exemplo n.º 9
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();
     }
   }
 }
Exemplo n.º 10
0
  private void deleteSelectedAlerts() {
    long[] alertsIds = null;

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

    synchronized (alerts) {
      deleteAlerts(table.getSelectedRows());
    }
  }
    public static Image createImage(final JTable table, int column) {
      final int height =
          Math.max(20, Math.min(100, table.getSelectedRowCount() * table.getRowHeight()));
      final int width = table.getColumnModel().getColumn(column).getWidth();

      final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2 = (Graphics2D) image.getGraphics();

      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));

      drawSelection(table, column, g2, width);
      return image;
    }
Exemplo n.º 12
0
 // for viewing the selected element details in table
 private void view() {
   boolean status = true;
   if (table1.getSelectedRowCount() != 1) {
     status = false;
     new ValidationMSG(this, "Please Select A Row from Table Then Click");
   }
   if (status) {
     rack = rackList.get(table1.getSelectedRow());
     textField1.setText(rack.getRackName());
     textArea1.setText(rack.getRackDesc());
     comboBox1.setSelectedItem(fieldName.getStoreName(rack.getStoreId()));
   }
 }
Exemplo n.º 13
0
 // delete a rack form database
 private void delete() {
   boolean status = true;
   if (table1.getSelectedRowCount() != 1) {
     status = false;
     new ValidationMSG(this, "Please Select A Row from Table Then Click");
   }
   if (status) {
     if (new PromptDailog().getUserResponse()) {
       int id = rackList.get(table1.getSelectedRow()).getRackId();
       dbdelete.deleteRack(id);
       loadTableData();
     }
   }
 }
Exemplo n.º 14
0
  private void delete() {
    boolean status = true;

    if (table1.getSelectedRowCount() < 1) {
      status = false;
      new ValidationMSG(this, "Please Select A Row from Table Then Click");
    }

    if (status) {
      if (new PromptDailog().getUserResponse()) {
        int id = vatList.get(table1.getSelectedRow()).getVatId();
        new DatabaseDelete(connection).deleteVat(id);
        loadTableData();
      }
    }
  }
  /** Copies the selected cells */
  public void copySelected() {
    StringBuffer sbf = new StringBuffer();

    // Check to ensure we have selected only a continguous block of cells
    int numcols = jTable1.getSelectedColumnCount();
    int numrows = jTable1.getSelectedRowCount();
    int[] rowsselected = jTable1.getSelectedRows();
    int[] colsselected = jTable1.getSelectedColumns();

    if (numcols != 0 && numrows != 0) {

      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,
            "You have to select a continuous block of cells",
            "Invalid Copy Selection",
            JOptionPane.ERROR_MESSAGE); // FIX ME???
        return;
      }

      String temp = "";

      for (int l = 0; l < numrows; l++) {
        for (int m = 0; m < numcols; m++) {
          if (jTable1.getValueAt(rowsselected[l], colsselected[m]) != null) {

            sbf.append(jTable1.getValueAt(rowsselected[l], colsselected[m]));

          } else {
            sbf.append("");
          }
          if (m < numcols - 1) {
            sbf.append("\t");
          }
        }
        sbf.append("\n");

        stsel = new StringSelection(sbf.toString());
        system = Toolkit.getDefaultToolkit().getSystemClipboard();
        system.setContents(stsel, stsel);
      }
    }
  }
Exemplo n.º 16
0
 public void actionPerformed(ActionEvent event) {
   if (event.getActionCommand().matches("mainmenu")) {
     update("main");
   } else if (event.getActionCommand().matches("loadShipment")) {
     update("loadShipment");
   } else if (event.getActionCommand().matches("pickup")) {
     if (shipmentTable.getSelectedRowCount() != 0) {
       driverService.pickupShipment(driver, shipmentList.get(shipmentTable.getSelectedRow()));
       update("main");
     }
     update();
   } else if (event.getActionCommand().matches("reportloc")) {
     update("reportloc");
   } else if (event.getActionCommand().matches("report")) {
     driverService.reportLocation(driver, (Location) locationComboBox.getSelectedItem());
     update("main");
   } else if (event.getActionCommand().matches("logout")) {
     loginUserInterface.update("main");
     graphicPanel = null;
   } else if (event.getActionCommand().matches("update")) {
     update();
   }
 }
Exemplo n.º 17
0
  public boolean enterPage(boolean next) {
    DevTableModel tm = (DevTableModel) devTable_.getModel();
    tm.setData(model_);
    try {
      try {
        model_.loadStateLabelsFromHardware(core_);
      } catch (Throwable t) {
        ReportingUtils.logError(t);
      }

      // default the selection to the first row
      if (devTable_.getSelectedRowCount() < 1) {
        TableModel m2 = devTable_.getModel();
        if (0 < m2.getRowCount()) devTable_.setRowSelectionInterval(0, 0);
      }

    } catch (Exception e) {
      ReportingUtils.showError(e);
      return false;
    }

    resetLabels();
    return true;
  }
  /**
   * 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.
   *
   * @param e
   */
  public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().compareTo("Copy") == 0) {
      StringBuffer sbf = new StringBuffer();

      // Check to ensure we have selected only a continguous block of cells
      int numcols = jTable1.getSelectedColumnCount();
      int numrows = jTable1.getSelectedRowCount();
      int[] rowsselected = jTable1.getSelectedRows();
      int[] colsselected = jTable1.getSelectedColumns();

      if (rowsselected.length == 0 || colsselected.length == 0) {
        AppUtility.msgError(frame, "You have to select cells to copy !!");
        return;
      }

      String temp = "";
      for (int l = 0; l < numrows; l++) {
        for (int m = 0; m < numcols; m++) {
          if (jTable1.getValueAt(rowsselected[l], colsselected[m]) != null) {

            sbf.append(jTable1.getValueAt(rowsselected[l], colsselected[m]));

          } else {
            sbf.append("");
          }
          if (m < 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) {

      jTable1
          .getParent()
          .getParent()
          .getParent()
          .setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
      String table = "";

      if (debug) {
        System.out.println("Trying to Paste");
      }
      int startRow = 0; // (jTable1.getSelectedRows())[0];
      int startCol = 0; // (jTable1.getSelectedColumns())[0];

      while (jTable1.getRowCount() > 0) {
        ((DefaultTableModel) jTable1.getModel()).removeRow(0);
      }

      try {
        String trstring =
            (String) (system.getContents(this).getTransferData(DataFlavor.stringFlavor));
        if (debug) {
          System.out.println("String is: " + trstring);
        }
        StringTokenizer st1 = new StringTokenizer(trstring, "\n");

        if (insertRowsWhenPasting) {

          for (int i = 0; i < st1.countTokens(); i++) {
            ((DefaultTableModel) jTable1.getModel()).addRow(new Object[] {null, null});
          }
        }

        for (int i = 0; st1.hasMoreTokens(); i++) {

          rowstring = st1.nextToken();
          StringTokenizer st2 = new StringTokenizer(rowstring, "\t");

          for (int j = 0; st2.hasMoreTokens(); j++) {
            value = st2.nextToken();
            if (j < jTable1.getColumnCount()) {
              jTable1.setValueAt(value, i, j);
            }

            if (debug) {
              System.out.println(
                  "Putting " + value + "at row=" + (startRow + i) + "column=" + (startCol + j));
            }
          }
        }
      } catch (Exception ex) {
        ex.printStackTrace();

        ((DefaultTableModel) jTable1.getModel()).addRow(new Object[] {null, null});
      }

      jTable1
          .getParent()
          .getParent()
          .getParent()
          .setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    }
  }
Exemplo n.º 19
0
 @Override
 public void update(AnActionEvent e) {
   super.update(e);
   e.getPresentation().setEnabled(myTable.getSelectedRowCount() != 0);
 }
    public void setSelected(AnActionEvent event, boolean b) {
      switch (command) {
        case REFRESH_RESULTSET:
          {
            QueryResultPanel resultPanel = getSelectedResultPanel();
            if (isConnected
                && resultPanel instanceof DataGridPanel
                && resultPanel.isRefreshSupported()) {
              try {
                resultPanel.refresh();
              } catch (DBException e) {
              }
            }
            break;
          }
        case CLOSE_PANEL:
          close();
          break;
        case STICKY_OPTION:
          selected ^= true;
          break;
        case EXPORT_DATA:
          {
            QueryResultPanel resultPanel = getSelectedResultPanel();
            if (resultPanel instanceof DataGridPanel) {
              DataGridPanel grid = (DataGridPanel) resultPanel;
              JTable _table = grid.getTable();

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

              if (numcols == 0 && numrows == 0) {
                // nothing to copy
                return;
              }

              ExportSettings settings = new ExportSettings();
              settings.show();
              if (!settings.isOK()) {
                return;
              }

              File fileToSave = null;
              if (settings.saveToFile()) {
                String path = settings.getFilePathToSave();
                if (path == null || path.length() == 0) {
                  Messages.showInfoMessage(
                      "File not specified, content will be saved in Clipboard",
                      "File not specified");
                  //                            } else if (new File(path).getParentFile().exists())
                  // {
                } else {
                  // todo --
                  fileToSave = new File(path);
                }
              }

              String delimiter;
              switch (settings.getDelimiter()) {
                case TAB:
                  delimiter = "\t";
                  break;
                case COMMA:
                  delimiter = ",";
                  break;
                default: //  SEMICOLON:
                  delimiter = ";";
                  break;
              }

              String content =
                  extractContent(
                      grid,
                      delimiter,
                      settings.saveColumnHeaders(),
                      settings.encloseFieldsInDowubleQuotes());
              if (content != null) {
                if (fileToSave != null) {
                  // save in the file
                  try {
                    StringUtils.string2file(content, fileToSave);
                  } catch (IOException e) {
                    Messages.showErrorDialog(e.getMessage(), "Export failed");
                  }
                } else {
                  // save in Clipboard
                  StringSelection stsel = new StringSelection(content);
                  Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard();
                  system.setContents(stsel, stsel);
                }
              }
            }
            break;
          }
      }
      // notifyListeners(command);
    }
 /**
  * Returns the number of selected rows.
  *
  * @return the number of selected rows, 0 if no rows are selected
  */
 public int getNumRowsSelected() {
   return table.getSelectedRowCount();
 }
 @RunsInCurrentThread
 static boolean hasSelection(@Nonnull JTable table) {
   return table.getSelectedRowCount() > 0 || table.getSelectedColumnCount() > 0;
 }