-
- filteredFeatureChoice.addItemListener(listener);
-
- }
-
- /**
- * Refreshes the display to show any filters currently configured for the
- * selected feature type (editable, with 'remove' option), plus one extra row
- * for adding a condition. This should be called on change of selected feature
- * type, or after a filter has been removed, added or amended.
- */
- protected void refreshFiltersDisplay()
- {
- /*
- * clear the panel and list of filter conditions
- */
- chooseFiltersPanel.removeAll();
- filters.clear();
-
- /*
- * look up attributes known for feature type
- */
- String selectedType = (String) filteredFeatureChoice.getSelectedItem();
- List<String> attNames = FeatureAttributes.getInstance().getAttributes(
- selectedType);
-
- /*
- * if this feature type has filters set, load them first
- */
- KeyedMatcherSetI featureFilters = fr.getFeatureFilter(selectedType);
- filtersAsText.setText("");
- if (featureFilters != null)
- {
- filtersAsText.setText(featureFilters.toString());
- if (!featureFilters.isAnded())
- {
- orFilters.setSelected(true);
- }
- featureFilters.getMatchers().forEach(matcher -> filters.add(matcher));
- }
-
- /*
- * and an empty filter for the user to populate (add)
- */
- KeyedMatcherI noFilter = new KeyedMatcher("", Condition.values()[0], "");
- filters.add(noFilter);
-
- /*
- * render the conditions in rows, each in its own JPanel
- */
- int filterIndex = 0;
- for (KeyedMatcherI filter : filters)
- {
- String key = filter.getKey();
- Condition condition = filter.getMatcher()
- .getCondition();
- String pattern = filter.getMatcher().getPattern();
- JPanel row = addFilter(key, attNames, condition, pattern, filterIndex);
- chooseFiltersPanel.add(row);
- filterIndex++;
- }
-
- filtersPane.validate();
- filtersPane.repaint();
- }
-
- /**
- * A helper method that constructs a panel with one filter condition:
- * <ul>
- * <li>a drop-down list of attribute names to choose from</li>
- * <li>a drop-down list of conditions to choose from</li>
- * <li>a text field for input of a match pattern</li>
- * <li>optionally, a 'remove' button</li>
- * </ul>
- * If attribute, condition or pattern are not null, they are set as defaults
- * for the input fields. The 'remove' button is added unless the pattern is
- * null or empty (incomplete filter condition).
- *
- * @param attribute
- * @param attNames
- * @param cond
- * @param pattern
- * @param filterIndex
- * @return
- */
- protected JPanel addFilter(String attribute, List<String> attNames,
- Condition cond, String pattern, int filterIndex)
- {
- JPanel filterRow = new JPanel(new FlowLayout(FlowLayout.LEFT));
- filterRow.setBackground(Color.white);
-
- /*
- * inputs for attribute, condition, pattern
- */
- /*
- * drop-down choice of attribute, with description as a tooltip
- * if we can obtain it
- */
- String featureType = (String) filteredFeatureChoice.getSelectedItem();
- final JComboBox<String> attCombo = populateAttributesDropdown(
- featureType, attNames);
- JComboBox<Condition> condCombo = new JComboBox<>();
- JTextField patternField = new JTextField(8);
-
- /*
- * action handlers that validate and (if valid) apply changes
- */
- ActionListener actionListener = new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- if (attCombo.getSelectedItem() != null)
- {
- if (validateFilter(patternField, condCombo))
- {
- updateFilter(attCombo, condCombo, patternField, filterIndex);
- filtersChanged();
- }
- }
- }
- };
- ItemListener itemListener = new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- actionListener.actionPerformed(null);
- }
- };
-
- if ("".equals(attribute))
- {
- attCombo.setSelectedItem(null);
- }
- else
- {
- attCombo.setSelectedItem(attribute);
- }
- attCombo.addItemListener(itemListener);
-
- filterRow.add(attCombo);
-
- /*
- * drop-down choice of test condition
- */
- for (Condition c : Condition.values())
- {
- condCombo.addItem(c);
- }
- if (cond != null)