Пример #1
0
 protected void adjustMainGrid(final JXTable grid) {
   grid.getColumnExt("Salida")
       .setCellRenderer(new DefaultTableRenderer(new Renderers.ToHourConverter()));
   // grid.getColumnExt("Cerrado").setCellRenderer(new DefaultTableRenderer(new
   // Renderers.ToHourConverter()));
   grid.getColumnExt("Regreso")
       .setCellRenderer(new DefaultTableRenderer(new Renderers.ToHourConverter()));
 }
 private void forwardEventToButton(MouseEvent e) {
   if (e.getID() == e.MOUSE_CLICKED) {
     JXTable table = ((JXTable) e.getSource());
     Integer row = table.rowAtPoint(e.getPoint());
     table.getColumnExt("Parameter Object").setVisible(true);
     this.parent.actionHandler.goToParameter((Parameter) table.getValueAt(row, 5));
   }
   return;
 }
  @Override
  public void actionPerformed(ActionEvent evt) {
    if (evt.getActionCommand().equals("SearchDB")) {
      searchDatabaseForMatches();
    } else if (evt.getActionCommand().equals("Finish")) {
      commit();
    } else if (evt.getActionCommand().equals("Cancel")) {
      containerFrame.dispose();
    } else if (evt.getActionCommand().equals("DefineByPattern")) {
      fillTableByPattern();
    } else if (evt.getActionCommand().equals("IncludeExcludeSubObjects")) {
      table.getColumnExt("SubObjectColumn").setVisible(this.chkIncludeSubobjects.isSelected());
    } else if (evt.getActionCommand().equals("SetDefaults")) {

      /*MVCArrayList<ControlledVoc> objectdic = Dictionary.getMutableDictionary("objectTypeDictionary");
      for(ControlledVoc item : objectdic)
      {
      	if(item.getNormal().equals("Site"))
      	{
      		defaultEntitiesDialog.setDefaultValues(item);
      	}
      }*/

      defaultEntitiesDialog.setVisible(true);

      if (defaultEntitiesDialog == null) {
        defaultEntitiesDialog = new DefaultEntityParametersDialog(containerFrame);
      }

    } else if (evt.getActionCommand().equals("GenerateMissing")) {
      if (model.areThereEmptyCells(this.chkIncludeSubobjects.isSelected())) {
        Alert.message(
            containerFrame,
            "Missing entries",
            "You must provide titles for all entities in the table.");
        return;
      }

      searchDatabaseForMatches();

      if (!model.areThereMissingEntites(true)) {
        Alert.message(containerFrame, "Nothing to do", "There are no entities to create!");
        return;
      }

      Object[] options = {"Yes", "No", "Cancel"};
      int n =
          JOptionPane.showOptionDialog(
              this,
              "You are about to create basic database entities for all the red crosses in the table.\n"
                  + "Are you sure you want to continue?",
              "Confirmation",
              JOptionPane.YES_NO_CANCEL_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              options,
              options[2]);

      if (n == JOptionPane.OK_OPTION) {
        model.generateMissingEntities(
            this.chkIncludeSubobjects.isSelected(), this.defaultEntitiesDialog);
      }

      return;
    }
  }
  /** Initialize the GUI */
  private void init() {
    setLayout(new BorderLayout(0, 0));

    JPanel panelMain = new JPanel();
    add(panelMain, BorderLayout.CENTER);
    panelMain.setLayout(new MigLayout("", "[grow]", "[grow]"));

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    panelMain.add(scrollPane, "cell 0 0,grow");

    table =
        new JXTable() {
          private static final long serialVersionUID = 1L;

          public void changeSelection(
              final int row, final int column, boolean toggle, boolean extend) {
            super.changeSelection(row, column, toggle, extend);
            if (table.isCellEditable(row, column)) {
              editCellAt(row, column);
            }
          }
        };

    table.setHorizontalScrollEnabled(true);
    table.setColumnControlVisible(true);
    model = new SeriesIdentityTableModel(containerFrame);

    SeriesIdentityTableCellRenderer renderer = new SeriesIdentityTableCellRenderer();

    table.setModel(model);

    table.getColumn(3).setCellRenderer(renderer);
    table.getColumn(4).setCellRenderer(renderer);
    table.getColumn(5).setCellRenderer(renderer);
    table.getColumn(6).setCellRenderer(renderer);
    table.getColumn(7).setCellRenderer(renderer);
    table.getColumn(8).setCellRenderer(renderer);
    table.getColumnExt(4).setIdentifier("SubObjectColumn");
    table.getColumnExt("SubObjectColumn").setVisible(false);

    table
        .getColumnModel()
        .addColumnModelListener(
            new TableColumnModelListener() {

              @Override
              public void columnAdded(TableColumnModelEvent arg0) {

                chkIncludeSubobjects.setSelected(table.getColumnExt("SubObjectColumn").isVisible());
              }

              @Override
              public void columnMarginChanged(ChangeEvent arg0) {
                // TODO Auto-generated method stub

              }

              @Override
              public void columnMoved(TableColumnModelEvent arg0) {
                // TODO Auto-generated method stub

              }

              @Override
              public void columnRemoved(TableColumnModelEvent arg0) {
                chkIncludeSubobjects.setSelected(table.getColumnExt("SubObjectColumn").isVisible());
              }

              @Override
              public void columnSelectionChanged(ListSelectionEvent arg0) {
                // TODO Auto-generated method stub

              }
            });

    scrollPane.setViewportView(table);

    JPanel panelButton = new JPanel();
    add(panelButton, BorderLayout.SOUTH);
    panelButton.setLayout(new MigLayout("", "[grow][][]", "[grow][grow][][][]"));

    model.addTableModelListener(this);

    JPanel panel = new JPanel();
    panelButton.add(panel, "cell 0 1 1 2,grow");
    panel.setLayout(new MigLayout("", "[31px][162px]", "[16px][][]"));

    JLabel lblKey = new JLabel("Key:");
    panel.add(lblKey, "cell 0 0,alignx left,aligny top");

    JLabel lblPresentIn = new JLabel("= Present in database");
    lblPresentIn.setFont(new Font("Dialog", Font.PLAIN, 12));
    lblPresentIn.setIcon(Builder.getIcon("found.png", 16));
    panel.add(lblPresentIn, "flowy,cell 1 0,alignx left,aligny top");

    JLabel lblAbsentFrom = new JLabel("= Absent from database");
    lblAbsentFrom.setFont(new Font("Dialog", Font.PLAIN, 12));
    lblAbsentFrom.setIcon(Builder.getIcon("missing.png", 16));
    panel.add(lblAbsentFrom, "cell 1 1,alignx left,aligny top");

    JLabel lblNotYet = new JLabel("= Not yet searched");
    lblNotYet.setFont(new Font("Dialog", Font.PLAIN, 12));
    lblNotYet.setIcon(Builder.getIcon("wait.png", 16));
    panel.add(lblNotYet, "cell 1 2,alignx left,aligny top");

    JPanel panel_1 = new JPanel();
    panelButton.add(panel_1, "cell 1 1 2 2,alignx right,growy");
    panel_1.setLayout(new MigLayout("", "[116px,fill]", "[22px][][][]"));

    JButton btnSearchDB = new JButton("Search Database");
    btnSearchDB.setFont(new Font("Dialog", Font.BOLD, 9));
    panel_1.add(btnSearchDB, "cell 0 0,alignx left,aligny top");
    btnSearchDB.setActionCommand("SearchDB");

    JButton btnDefineByPattern = new JButton("Define names by pattern");
    btnDefineByPattern.setFont(new Font("Dialog", Font.BOLD, 9));
    panel_1.add(btnDefineByPattern, "cell 0 1,alignx left,aligny top");
    btnDefineByPattern.setActionCommand("DefineByPattern");

    JButton btnGenerateMissing = new JButton("Generate missing entities");
    btnGenerateMissing.setActionCommand("GenerateMissing");
    btnGenerateMissing.addActionListener(this);

    JButton btnSetDefaults = new JButton("Set default parameters");
    btnSetDefaults.setActionCommand("SetDefaults");
    btnSetDefaults.addActionListener(this);
    btnSetDefaults.setFont(new Font("Dialog", Font.BOLD, 9));
    panel_1.add(btnSetDefaults, "cell 0 2");

    btnGenerateMissing.setFont(new Font("Dialog", Font.BOLD, 9));
    panel_1.add(btnGenerateMissing, "flowy,cell 0 3");
    btnDefineByPattern.addActionListener(this);
    btnSearchDB.addActionListener(this);

    chkIncludeSubobjects = new JCheckBox("Include sub-objects in import");
    chkIncludeSubobjects.addActionListener(this);
    chkIncludeSubobjects.setActionCommand("IncludeExcludeSubObjects");
    panelButton.add(chkIncludeSubobjects, "cell 0 3");

    chckbxOpenSeriesIn = new JCheckBox("Open series in editor when finished");
    chckbxOpenSeriesIn.setSelected(true);
    panelButton.add(chckbxOpenSeriesIn, "cell 0 4");
  }
  @SuppressWarnings("unchecked")
  private void initComponents() {
    org.jdesktop.application.ResourceMap resourceMap =
        org.jdesktop.application.Application.getInstance(
                insalmo_instream_gui.InsalmoInstreamApp.class)
            .getContext()
            .getResourceMap(ShowErrorsWarnings.class);

    // CLOSE
    closeButton.setName("closeButton");
    closeButton.setText(resourceMap.getString("closeButton.text"));
    closeButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            closeButtonActionPerfomed(evt);
          }
        });

    showErrorWarningsPanel = new javax.swing.JPanel();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setName("showErrorsWarnings");

    // ERROR/WARNING TABLE
    errorTable = this.createXTable();
    errorTable.setName("errorTable");
    errorTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    DefaultTableModel dataModel =
        new DefaultTableModel() {
          Class[] types =
              new Class[] {
                java.lang.String.class,
                java.lang.String.class,
                java.lang.String.class,
                java.lang.String.class,
                java.lang.String.class,
                Parameter.class
              };
          boolean[] canEdit = new boolean[] {false, false, false, false, false, false};

          public Class getColumnClass(int columnIndex) {
            return types[columnIndex];
          }

          public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
          }
        };
    dataModel.setColumnIdentifiers(
        new String[] {"", "Parameter", "Value", "Location", "Message", "Parameter Object"});
    for (Parameter p : this.openProject.getErrors()) {
      String filename;
      if (p.getSource().getClass().equals(SetupParameters.class)) {
        filename = ((SetupParameters) p.getSource()).getFileName();
      } else {
        filename = "Experiment.Setup";
      }
      dataModel.addRow(
          new Object[] {
            "Error",
            p.getParameterName(),
            p.getParameterValue(),
            filename,
            p.getValidationMessage(),
            p
          });
    }
    for (Parameter p : this.openProject.getWarnings()) {
      String filename;
      if (p.getSource().getClass().equals(SetupParameters.class)) {
        filename = ((SetupParameters) p.getSource()).getFileName();
      } else {
        filename = "Experiment.Setup";
      }
      dataModel.addRow(
          new Object[] {
            "Warning",
            p.getParameterName(),
            p.getParameterValue(),
            filename,
            p.getValidationMessage(),
            p
          });
    }
    errorTable.setModel(dataModel);
    errorTable.getColumnExt("Parameter Object").setVisible(false);
    errorTable.addMouseListener(
        new MouseListener() {
          public void mouseClicked(MouseEvent e) {
            forwardEventToButton(e);
          }

          public void mouseEntered(MouseEvent e) {}

          public void mouseExited(MouseEvent e) {}

          public void mousePressed(MouseEvent e) {}

          public void mouseReleased(MouseEvent e) {}
        });
    tableScrollPane.setViewportView(errorTable);

    // LABEL
    errorLabel.setText(resourceMap.getString("errorLabel.text"));

    javax.swing.GroupLayout showErrorWarningsTypeLayout =
        new javax.swing.GroupLayout(showErrorWarningsPanel);
    showErrorWarningsPanel.setLayout(showErrorWarningsTypeLayout);
    showErrorWarningsTypeLayout.setHorizontalGroup(
        showErrorWarningsTypeLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                showErrorWarningsTypeLayout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        showErrorWarningsTypeLayout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(errorLabel)
                            .addComponent(tableScrollPane)
                            .addComponent(closeButton))
                    .addContainerGap()));
    showErrorWarningsTypeLayout.setVerticalGroup(
        showErrorWarningsTypeLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                showErrorWarningsTypeLayout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(errorLabel)
                    .addComponent(tableScrollPane)
                    .addComponent(closeButton)
                    .addContainerGap()));

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(
                        showErrorWarningsPanel,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)
                    .addContainerGap()));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(
                        showErrorWarningsPanel,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    pack();
  }
Пример #6
0
 public static void showOnlyThisColumns(JXTable table, Object[] columns) {
   for (Object tableColumns : columns) {
     table.getColumnExt(tableColumns).setVisible(true);
   }
   //    updateColumnsSize();
 }