public boolean checkFields() throws FieldValueException {
    FieldsChecking.checkAllRequiredFields(this);

    Date validFrom = validFromField.getDate();

    Date validTo = validToField.getDateAcceptEmpty();
    if (validTo != null) {
      if (validFrom.after(validTo)) {
        throw new FieldValueException(
            "<USER>'Valid From' should not be later than 'Valid To'</USER>");
      }
    }

    FacilityValue seaport = (FacilityValue) seaportCombo.getSelectedItem();

    Seaport2FixpointValue seaport2Fixpoint = (Seaport2FixpointValue) getModel();
    seaport2Fixpoint.setSeaportId(seaport.getId().longValue());
    seaport2Fixpoint.setValidityStart(validFrom);
    seaport2Fixpoint.setValidityEnd(validTo);

    Object selectedFixpoint = fixpointCombo.getSelectedItem();
    if (selectedFixpoint instanceof FacilityValue) {
      FacilityValue fixpoint = (FacilityValue) selectedFixpoint;
      seaport2Fixpoint.setFixpointId(fixpoint.getId());
      seaport2Fixpoint.setActive(true);
    } else {
      seaport2Fixpoint.setFixpointId(null);
      seaport2Fixpoint.setActive(false);
    }

    // Nicht verwendet.
    return true;
  }
  private void checkDates() throws FieldValueException {
    Date from = durationFromTextField.getDate();
    Date to = durationToTextField.getDate();

    checkValidToDate(from, to);
    ((BargeTariffValue) getModel()).setDurationFrom(from);
    ((BargeTariffValue) getModel()).setDurationTo(to);
  }
 protected void generateReport() {
   log.debug("Generating");
   MainFrame.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
   CurrencyValue currency = currencyBox.getSelectedCurrency();
   String[] platformRefs = null;
   boolean imp = false;
   boolean exp = false;
   Date from = fromField.getDateOrNull();
   Date to = toField.getDateOrNull();
   Object[] cs = platformChooser.getSelectedPlatforms().toArray(new String[0]);
   if (cs.length > 0) platformRefs = new String[cs.length];
   for (int i = 0, n = cs.length; i < n; i++) {
     platformRefs[i] = (String) cs[i];
     // platformRefs[i] = ((FacilityValue)cs[i]).getReference();
   }
   imp = this.importBox.isSelected();
   exp = this.exportBox.isSelected();
   try {
     // @war-pp
     if (typeBox.getSelectedItem().equals("ICC Manual Tracing Report")) {
       byte[] pdfStream =
           ReportService.getInstance()
               .getICCManualTracingReport(platformRefs, typeBox.getSelectedItem().toString());
       if (pdfStream != null) ReportFrame.openIccManualReport(pdfStream, "ICCManualTracingReport");
       else showInformationMessage("No data found "); // @war
     } else {
       byte[] pdfStream =
           ReportService.getInstance()
               .getCCReport(
                   from,
                   to,
                   currency,
                   platformRefs,
                   imp,
                   exp,
                   typeBox.getSelectedItem().toString());
       ReportFrame.openReport(
           pdfStream,
           typeBox.getSelectedItem().equals("Activity Report")
               ? "ActivityReport"
               : "PreliminaryReport");
     }
   } catch (Exception e) {
     log.error(this, e);
     MainFrame.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
     MainFrame.handleException("Could not create " + typeBox.getSelectedItem(), e);
   }
   MainFrame.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 }
 private void fillFields(ValueObject valueObject) {
   setTitle(valueObject);
   if (!valueObject.getClientValueObjectProxy().isNew()) {
     idTextField.setText(((BargeTariffValue) valueObject).getId().toString());
     durationFromTextField.setDate(
         new java.sql.Date(((BargeTariffValue) valueObject).getDurationFrom().getTime()));
     durationToTextField.setDate(
         new java.sql.Date(((BargeTariffValue) valueObject).getDurationTo().getTime()));
     importCheckBox.setSelected(((BargeTariffValue) valueObject).getIsImport());
     vendor.setText(((BargeTariffValue) valueObject).getVendorName());
     facility.setText(((BargeTariffValue) valueObject).getFacilityName());
     currency.setSelectedCurrencyId(model.getCurrencyId());
     currency.setEnabled(false);
   }
   copyButton.setEnabled(!model.getClientValueObjectProxy().isNew());
   valueObject.getClientValueObjectProxy().setChanged(false);
 }
  public CCReportPane() {
    super(new GridBagLayout());
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    fromField = new DateJTextField((TextFieldChangeListener) null);
    fromField.setColumns(6);
    fromField.setMinimumSize(fromField.getPreferredSize());

    JLabel fromLabel = new JLabel("From");
    fromLabel.setLabelFor(fromField);
    fromLabel.setDisplayedMnemonic('F');

    toField = new DateJTextField((TextFieldChangeListener) null);
    toField.setColumns(6);
    toField.setMinimumSize(toField.getPreferredSize());

    JLabel toLabel = new JLabel("To");
    toLabel.setLabelFor(toField);
    toLabel.setDisplayedMnemonic('T');

    platformChooser = new CcPlatformChooser();

    JLabel ccLabel = new JLabel("CC");
    ccLabel.setLabelFor(platformChooser.getCcComboBox());
    ccLabel.setDisplayedMnemonic('C');

    JLabel platformLabel = new JLabel("Platforms");
    platformLabel.setLabelFor(platformChooser.getPlatformList());
    platformLabel.setDisplayedMnemonic('P');

    DefaultComboBoxModel boxModel = new DefaultComboBoxModel();
    boxModel.addElement("Activity Report");

    // boxModel.addElement("Preliminary Report");
    boxModel.addElement("ICC Manual Tracing Report"); // @war-pp
    typeBox = new ContextJComboBox(boxModel);

    JLabel typeLabel = new JLabel("Report Type");
    typeLabel.setLabelFor(typeBox);
    typeLabel.setDisplayedMnemonic('R');

    importBox = new JCheckBox();

    JLabel importLabel = new JLabel("Import");
    importLabel.setLabelFor(importBox);
    importLabel.setDisplayedMnemonic('I');

    exportBox = new JCheckBox();

    JLabel exportLabel = new JLabel("Export");
    exportLabel.setLabelFor(exportBox);
    exportLabel.setDisplayedMnemonic('E');

    currencyBox = new CurrencyBox();
    currencyBox.setToolTipText("The currency for reported amounts of money");

    JLabel currencyLabel = new JLabel("Currency");
    currencyLabel.setToolTipText("The currency for reported amounts of money");
    currencyLabel.setLabelFor(currencyBox);
    currencyLabel.setDisplayedMnemonic('U');

    // @war-pp
    ActionListener actionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            if (typeBox.getSelectedItem().equals("ICC Manual Tracing Report")) {
              toField.setEnabled(false);
              fromField.setEnabled(false);
              importBox.setEnabled(false);
              // System.out.println("ANWAR     ---------"+importBox.isEnabled());
              exportBox.setEnabled(false);
              currencyBox.setEnabled(false);

            } else {
              toField.setEnabled(true);
              fromField.setEnabled(true);
              importBox.setEnabled(true);
              exportBox.setEnabled(true);
              currencyBox.setEnabled(true);
            }
          }
        };

    // @war-pp
    typeBox.addActionListener(actionListener); // @war-pp

    generateReportButton = new JButton("Get Report");
    generateReportButton.setToolTipText("Creates the report and opens it");
    generateReportButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            generateReport();
          }
        });

    Insets insets = new Insets(5, 0, 0, 0);

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(fromLabel, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(fromField, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(toLabel, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 1;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(toField, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 2;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(ccLabel, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 2;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(platformChooser.getCcComboBox(), constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 3;
    constraints.anchor = GridBagConstraints.NORTHWEST;
    constraints.insets = insets;
    add(platformLabel, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 3;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.weightx = 1.0;
    constraints.weighty = 1.0;
    constraints.insets = insets;
    add(new MetaScrollPane(platformChooser.getPlatformList()), constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 4;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(typeLabel, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(typeBox, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 5;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(importLabel, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 5;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(importBox, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 6;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(exportLabel, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 6;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(exportBox, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 7;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(currencyLabel, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 7;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = insets;
    add(currencyBox, constraints);

    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 8;
    constraints.gridwidth = 2;
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.insets = new Insets(15, 0, 0, 0);
    add(generateReportButton, constraints);
  }
  public void initComponents() {

    allowedRoles = new String[] {"*"};
    idLabel = new JLabel("ID");
    vendorLabel = new JLabel("Vendor");
    currencyLabel = new JLabel("Currency");
    facilityLabel = new JLabel("Facility");

    modifyJButton = new TooltipJButton("modify");
    modifyJButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            modifyTableContent();
          }
        });
    modifyJButton.setBounds(420, 90, 75, 20);

    vendorLookup = new TooltipJButton("Lookup");
    vendorLookup.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            vendorSearch();
          }
        });
    facilityLookup = new TooltipJButton("Lookup");
    facilityLookup.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            facilitySearch();
          }
        });
    copyButton = new TooltipJButton("copy");
    copyButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            copy();
          }
        });
    importLabel = new JLabel("import");
    durationFromLabel = new JLabel("Valid From");
    durationToLabel = new JLabel("Valid To");
    idTextField = new ContextJTextField(this);
    vendor = new ContextJTextField(this, true);
    currency = new CurrencyBox(this, true);

    facility = new ContextJTextField(this, true);
    durationFromTextField = new DateJTextField(this, true);
    mandatoryFields.add(durationFromTextField);
    durationToTextField = new DateJTextField(this, true);
    mandatoryFields.add(durationToTextField);
    bargeTariffTable = new ComposedContextJTable();
    bargeTariffTable.setColorable(true);
    importCheckBox = new ImportExportPane(this);

    mandatoryFields.add(vendor);
    mandatoryFields.add(currency);
    mandatoryFields.add(facility);
    mandatoryFields.add(durationFromTextField);
    mandatoryFields.add(durationToTextField);

    scrollpane = new JScrollPane();
    scrollpane.setBounds(10, 120, 490, 200);

    bargeTariffTable.setBounds(0, 0, 400, 400);

    idLabel.setBounds(10, 10, 40, 20);
    idTextField.setBounds(100, 10, 100, 20);
    durationFromLabel.setBounds(10, 35, 80, 20);
    durationFromTextField.setBounds(100, 35, 100, 20);
    durationToLabel.setBounds(10, 60, 80, 20);
    durationToTextField.setBounds(100, 60, 100, 20);

    // importLabel.setBounds(10, 90, 40, 20);
    importCheckBox.setBounds(10, 90, 200, 25);

    vendorLabel.setBounds(220, 10, 80, 20);
    vendor.setBounds(300, 10, 100, 20);
    vendorLookup.setBounds(420, 10, 80, 20);

    currencyLabel.setBounds(220, 60, 80, 20);
    currency.setBounds(300, 60, 100, 20);

    facilityLabel.setBounds(220, 35, 80, 20);
    facility.setBounds(300, 35, 100, 20);
    facilityLookup.setBounds(420, 35, 80, 20);

    copyButton.setBounds(345, 90, 75, 20);
    panel.setLayout(null);
    panel.setSize(700, 215);
    panel.setMinimumSize(new Dimension(700, 130));
    panel.add(idLabel);
    panel.add(idTextField);
    panel.add(durationFromLabel);
    panel.add(durationFromTextField);
    panel.add(durationToLabel);
    panel.add(durationToTextField);
    panel.add(importLabel);
    panel.add(importCheckBox);
    panel.add(vendorLabel);
    panel.add(vendor);
    panel.add(vendorLookup);
    panel.add(currencyLabel);
    panel.add(currency);
    panel.add(facilityLabel);
    panel.add(facility);
    panel.add(facilityLookup);
    panel.add(copyButton);
    panel.add(modifyJButton);

    // tabbed pane
    tabPane = new JTabbedPane();
    tabPane.setBounds(10, 175, 870, 200);
    tabPane.add("Tarifflines", scrollpane);

    // VERSION_TOGGLE Tariff.2ExtraSurcharges Start ----------
    if (ResourceUtil.getBoolean("Tariff.2ExtraSurcharges")) {
      surchargesPanel = new SurchargesPanel((Tariff) getModel());
      tabPane.add("Surcharges", surchargesPanel);
    }
    // VERSION_TOGGLE Tariff.2ExtraSurcharges End ----------

    scrollpane.getViewport().add(bargeTariffTable);
    JSplitPane splitp = new JSplitPane();
    splitp.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitp.setLeftComponent(panel);
    splitp.setRightComponent(tabPane);
    splitp.setDividerSize(0);
    getContentPane().add(splitp);
    pack();
  }
  private void initComponents(Seaport2FixpointValue seaport2Fixpoint) {
    seaportCombo = new ContextJComboBox(this, true);
    seaportCombo.setName("Seaport");
    mandatoryFields.add(seaportCombo);
    try {
      String regionID =
          ParameterService.getInstance()
              .getParameterValue(Constants.PARAM_SEAPORT_REGION_FOR_FIXPOINT_MAPPING);

      List seaports = new ArrayList();
      if (seaport2Fixpoint.getClientValueObjectProxy().isNew()) {
        // Die Leer-auswahl nur beim Einfuegen anzeigen.
        seaports.add("-- Select --");
      }
      seaports.addAll(
          FacilityService.getInstance()
              .findFacilitiesByTypeAndRegion(
                  Constants.FACILITY_TYPE_SEAPORT, Long.parseLong(regionID)));
      seaportCombo.setModel(new DefaultComboBoxModel(seaports.toArray()));
    } catch (Exception x) {
      log.error(
          "Exception while retrieving seaport list for seaport2fixpoint table.\n "
              + "Parameter '"
              + Constants.PARAM_SEAPORT_REGION_FOR_FIXPOINT_MAPPING
              + "' not set?",
          x);
    }
    setSelectedItem(seaportCombo, seaport2Fixpoint.getSeaportId());

    JLabel seaportLabel = new JLabel(seaportCombo.getName());
    seaportLabel.setLabelFor(seaportCombo);
    seaportLabel.setDisplayedMnemonic('S');

    fixpointCombo = new ContextJComboBox(this);
    fixpointCombo.setName("Fixpoint");
    mandatoryFields.add(fixpointCombo);
    try {
      List fixpoints = new ArrayList();
      fixpoints.add("-- n/a --");
      fixpoints.addAll(
          FacilityService.getInstance().findFacilitiesByType(Constants.FACILITY_TYPE_FIXPOINT));
      fixpointCombo.setModel(new DefaultComboBoxModel(fixpoints.toArray()));
    } catch (Exception e) {
      log.error("Exception while retrieving fixpoint list: ", e);
    }
    if (seaport2Fixpoint.getFixpointId() != null) {
      // D.h. seaport2Fixpoint.isActive().
      setSelectedItem(fixpointCombo, seaport2Fixpoint.getFixpointId().longValue());
    }

    JLabel fixpointLabel = new JLabel(fixpointCombo.getName());
    fixpointLabel.setLabelFor(fixpointCombo);
    fixpointLabel.setDisplayedMnemonic('F');

    validFromField = new DateJTextField(this);
    validFromField.setName("Valid From");
    validFromField.setDate(seaport2Fixpoint.getValidityStart());
    validFromField.setRequired(true);
    mandatoryFields.add(validFromField);

    JLabel validFromLabel = new JLabel(validFromField.getName());
    validFromLabel.setLabelFor(validFromField);
    validFromLabel.setDisplayedMnemonic('F');

    validToField = new DateJTextField(this);
    validToField.setName("Valid To");
    validToField.setDate(seaport2Fixpoint.getValidityEnd());
    // VERSION_TOGGLE ValidityModification.enabled Start ----------
    if (!ResourceUtil.getBoolean("ValidityModification.enabled")) {
      validToField.setRequired(true);
      mandatoryFields.add(validToField);
    }
    // VERSION_TOGGLE ValidityModification.enabled End ----------

    JLabel validToLabel = new JLabel(validToField.getName());
    validToLabel.setLabelFor(validToField);
    validToLabel.setDisplayedMnemonic('T');

    // Durch die Vorbelgung soll das Objekt noch nicht speicherbar sein.
    seaport2Fixpoint.getClientValueObjectProxy().setChanged(false);

    setTitle("Fixpoints");
    setMaximizable(false);

    getContentPane().setLayout(new GridBagLayout());
    ((JComponent) getContentPane()).setBorder(BorderFactory.createEmptyBorder(15, 15, 10, 15));

    GridBagConstraints constraints = new GridBagConstraints();

    // Spalte 1.

    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = new Insets(0, 0, 5, 0);
    getContentPane().add(seaportLabel, constraints);

    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.anchor = GridBagConstraints.WEST;
    getContentPane().add(validFromLabel, constraints);

    constraints.gridx = 0;
    constraints.gridy = 2;
    constraints.anchor = GridBagConstraints.WEST;
    getContentPane().add(validToLabel, constraints);

    constraints.gridx = 0;
    constraints.gridy = 3;
    constraints.anchor = GridBagConstraints.WEST;
    getContentPane().add(fixpointLabel, constraints);

    // Spalte 2.

    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.weightx = 1.0;
    getContentPane().add(seaportCombo, constraints);

    constraints.gridx = 1;
    constraints.gridy = 1;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.weightx = 1.0;
    getContentPane().add(validFromField, constraints);

    constraints.gridx = 1;
    constraints.gridy = 2;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.weightx = 1.0;
    getContentPane().add(validToField, constraints);

    constraints.gridx = 1;
    constraints.gridy = 3;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.weightx = 1.0;
    getContentPane().add(fixpointCombo, constraints);

    pack();
  }