Ejemplo n.º 1
0
 /**
  * Sets content rules and values according to given task filter.
  *
  * @param taskFilter Task filter to be used for setting content rules and values.
  */
 private void setComponents(AbstractTaskFilter taskFilter) {
   cmbContentRule.removeAllItems();
   Vector contentRules = taskFilter.getContentRules();
   int length = contentRules.size();
   for (int i = 0; i < length; i++) cmbContentRule.addItem(contentRules.get(i));
   cmbContentRule.setSelectedIndex(taskFilter.getContentRule());
   Vector contentValues = taskFilter.getContentValues();
   cmbContent.setEnabled(contentValues != null);
   txtContent.setEnabled(contentValues == null);
   cmbContent.removeAllItems();
   if (contentValues != null) {
     length = contentValues.size();
     String value = taskFilter.getContent();
     for (int i = 0; i < length; i++) {
       cmbContent.addItem(contentValues.get(i));
       if (contentValues.get(i).equals(value)) cmbContent.setSelectedIndex(i);
     }
   } else txtContent.setText(taskFilter.getContent());
 }
Ejemplo n.º 2
0
 /**
  * Method called when OK button was pressed.
  *
  * @param evt Event that invoked this action.
  */
 private void btOKActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btOKActionPerformed
   AbstractTaskFilter newTaskFilter =
       (AbstractTaskFilter) cmbFilterName.getItemAt(cmbFilterName.getSelectedIndex());
   newTaskFilter.setContentRule(cmbContentRule.getSelectedIndex());
   String content = null;
   if (newTaskFilter instanceof DescriptionFilter) content = txtContent.getText();
   if (newTaskFilter instanceof KeywordFilter) content = txtContent.getText();
   if (newTaskFilter instanceof DurationFilter) {
     String text = txtContent.getText();
     long duration;
     try {
       if (text.length() != 8)
         throw new NumberFormatException("Error: invalid task duration specified: " + text);
       duration = Tools.getTime(text);
     } catch (NumberFormatException e) {
       e.printStackTrace();
       JOptionPane.showMessageDialog(
           this,
           Translator.getTranslation("WARNING.INVALID_DURATION"),
           Translator.getTranslation("WARNING.WARNING_TITLE"),
           JOptionPane.WARNING_MESSAGE);
       txtContent.setText(Tools.getTime(0));
       return;
     }
     content = Tools.getTime(duration);
   }
   if (newTaskFilter instanceof PriorityFilter) content = "" + cmbContent.getSelectedIndex();
   if (newTaskFilter instanceof StateFilter) content = "" + cmbContent.getSelectedIndex();
   if (newTaskFilter instanceof PrivateFilter)
     content = Boolean.toString(cmbContent.getSelectedIndex() == 0);
   newTaskFilter.setContent(content);
   if (taskFilter == null) filtersTableModel.addFilter(newTaskFilter);
   else filtersTableModel.replaceFilter(taskFilter, newTaskFilter);
   formWindowClosing(null);
 } // GEN-LAST:event_btOKActionPerformed