Example #1
0
 /**
  * Adjusts the field list so that only the selected fields are read.
  *
  * @param readFunction
  */
 private void setFieldList(JCoFunction readFunction) {
   int length = 0;
   JCoTable fields = readFunction.getTableParameterList().getTable("FIELDS"); // $NON-NLS-1$
   fields.clear();
   if (selectedFields.isEmpty()) {
     for (final ITableField field : structure.getFieldList()) {
       length += field.getLength();
       fields.appendRow();
       fields.setValue("FIELDNAME", field.getFieldName()); // $NON-NLS-1$
     }
   } else {
     for (final String field : selectedFields) {
       try {
         length += structure.getField(field).getLength();
         fields.appendRow();
         fields.setValue("FIELDNAME", field); // $NON-NLS-1$
       } catch (FieldNotFoundException e) {
         throw new IllegalArgumentException(
             MessageFormat.format(Messages.TableReader_UnknownField, field), e);
       }
     }
   }
   if (length > 512) {
     throw new IllegalArgumentException(Messages.TableReader_ResultTooLong);
   }
 }
Example #2
0
 /**
  * Adds a field to the list of fields to retrieve.
  *
  * @param field the descriptor of the field to add
  * @throws FieldNotFoundException
  */
 public void addField(ITableField field) throws FieldNotFoundException {
   structure.getField(field.getFieldName()); // to ensure that the field exists
   selectedFields.add(field.getFieldName());
 }
Example #3
0
 /**
  * Adds a field to the list of fields to retrieve.
  *
  * @param fieldName the name of the field to add
  * @throws FieldNotFoundException
  */
 public void addField(String fieldName) throws FieldNotFoundException {
   structure.getField(fieldName); // to ensure that the field exists
   selectedFields.add(fieldName);
 }
  public void showMenu(MouseEvent e) {
    boolean isRegex = columnObj.isRegEx();

    JPopupMenu menu = new JPopupMenu("Popup");
    JMenuItem item = new JMenuItem(columnObj.getVisibleName());

    item.setEnabled(false);
    menu.add(item);
    menu.addSeparator();

    if (isRegex) {
      JMenu submenu = new JMenu("Regex");

      item = new JMenuItem("Edit");
      item.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              javax.swing.SwingUtilities.invokeLater(
                  new Runnable() {
                    public void run() {
                      String newValue =
                          MoreHelp.showPlainInputMessage(
                              "Regular expression for the \""
                                  + columnObj.getVisibleName()
                                  + "\" column",
                              "Edit Regex",
                              columnObj.getRegExData().getRegExString());
                      columnObj.getRegExData().setRegExString(newValue);
                      saveAndReloadTableSettings(); // TODO do we need it?
                    }
                  });
            }
          });

      submenu.add(item);

      item = new JCheckBoxMenuItem("Case sensitive");
      item.setSelected(columnObj.getRegExData().isRegExCaseSensitive());
      item.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              columnObj
                  .getRegExData()
                  .setRegExCaseSensitive(!columnObj.getRegExData().isRegExCaseSensitive());
            }
          });

      submenu.add(item);

      menu.add(submenu);
    }

    item = new JMenuItem("Rename");
    item.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String newValue =
                MoreHelp.showPlainInputMessage(
                    "Rename the \"" + columnObj.getDefaultVisibleName() + "\" column",
                    "Rename column name",
                    columnObj.getVisibleName());
            if (newValue.isEmpty()) {
              newValue = columnObj.getDefaultVisibleName();
            }
            columnObj.setVisibleName(newValue);
            saveAndReloadTableSettings();
          }
        });
    menu.add(item);

    item = new JMenuItem("Hide");
    item.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            columnObj.setVisible(false);
            saveAndReloadTableSettings();
          }
        });
    menu.add(item);

    item = new JMenuItem("Disable");
    item.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            javax.swing.SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    String[] msgOptions = {"OK", "CANCEL"};
                    if (MoreHelp.askConfirmMessage(
                            "Disabling a column",
                            "Are you sure you want to disable the \""
                                + columnObj.getVisibleName()
                                + "\"? This column may not be populated when it is disabled (if it needs additional resources)",
                            msgOptions)
                        == JOptionPane.YES_OPTION) {
                      columnObj.setEnabled(false);
                      saveAndReloadTableSettings();
                    }
                  }
                });
          }
        });
    menu.add(item);

    JMenu subMenuVisibleCols = new JMenu("Visbile columns");
    item = new JMenuItem("Make all visible");
    item.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            for (Iterator<TableStructure> iterator =
                    tableHelper
                        .getTableHeaderColumnsDetails()
                        .getAllColumnsDefinitionList()
                        .iterator();
                iterator.hasNext(); ) {
              final TableStructure columnDefinition = iterator.next();
              if (columnDefinition.isEnabled() && !columnDefinition.isVisible()) {
                columnDefinition.setVisible(true);
              }
            }
            saveAndReloadTableSettings();
          }
        });
    subMenuVisibleCols.add(item);

    JMenu subMenuEnabledCols = new JMenu("Enabled columns");
    item = new JMenuItem("Make all enabled");
    item.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            for (Iterator<TableStructure> iterator =
                    tableHelper
                        .getTableHeaderColumnsDetails()
                        .getAllColumnsDefinitionList()
                        .iterator();
                iterator.hasNext(); ) {
              final TableStructure columnDefinition = iterator.next();
              if (!columnDefinition.isEnabled()) {
                columnDefinition.setEnabled(true);
                columnDefinition.setVisible(true);
              }
            }
            saveAndReloadTableSettings();
          }
        });
    subMenuEnabledCols.add(item);

    for (Iterator<TableStructure> iterator =
            tableHelper.getTableHeaderColumnsDetails().getAllColumnsDefinitionList().iterator();
        iterator.hasNext(); ) {
      final TableStructure columnDefinition = iterator.next();

      if (columnDefinition.isEnabled()) {
        JMenuItem visibleItem = new JCheckBoxMenuItem(columnDefinition.getVisibleName());
        visibleItem.setSelected(columnDefinition.isVisible());
        visibleItem.addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                columnDefinition.setVisible(!columnDefinition.isVisible());
                saveAndReloadTableSettings();
              }
            });
        subMenuVisibleCols.add(visibleItem);
      }

      JMenuItem enabledItem = new JCheckBoxMenuItem(columnDefinition.getVisibleName());
      enabledItem.setSelected(columnDefinition.isEnabled());
      enabledItem.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              columnDefinition.setEnabled(!columnDefinition.isEnabled());
              columnDefinition.setVisible(
                  true); // when a field is enabled, then it becomes visible automatically
              javax.swing.SwingUtilities.invokeLater(
                  new Runnable() {
                    public void run() {
                      if (columnDefinition.isEnabled())
                        MoreHelp.showMessage(
                            "The new field might not have been populated previously. It will be populated for the new messages.");
                    }
                  });
              saveAndReloadTableSettings();
            }
          });
      subMenuEnabledCols.add(enabledItem);
    }

    menu.add(subMenuVisibleCols);
    menu.add(subMenuEnabledCols);

    menu.show(e.getComponent(), e.getX(), e.getY());
  }