/**
   * Set up the comparators for each column, so the user can modify sort order by clicking the
   * column labels.
   *
   * @param comparatorChooser The comparator chooser controlling the sort order.
   */
  @SuppressWarnings("unchecked")
  protected void setupComparatorChooser(TableComparatorChooser<BibtexEntry> comparatorChooser) {
    // First column:
    java.util.List<Comparator<BibtexEntry>> comparators =
        comparatorChooser.getComparatorsForColumn(0);
    comparators.clear();

    comparators = comparatorChooser.getComparatorsForColumn(1);
    comparators.clear();

    // Icon columns:
    for (int i = 2; i < PAD; i++) {
      comparators = comparatorChooser.getComparatorsForColumn(i);
      comparators.clear();
      if (i == FILE_COL) comparators.add(new IconComparator(new String[] {GUIGlobals.FILE_FIELD}));
      else if (i == URL_COL) comparators.add(new IconComparator(new String[] {"url"}));
    }
    // Remaining columns:
    for (int i = PAD; i < PAD + fields.length; i++) {
      comparators = comparatorChooser.getComparatorsForColumn(i);
      comparators.clear();
      comparators.add(new FieldComparator(fields[i - PAD]));
    }

    sortedEntries.getReadWriteLock().writeLock().lock();
    comparatorChooser.appendComparator(PAD, 0, false);
    sortedEntries.getReadWriteLock().writeLock().unlock();
  }
  /**
   * This test currently fails in the graph publisher implementation because we don't support
   * merging events in GraphDependenciesListEventPublisher.
   */
  public void testMergingListEvents() {
    CompositeList<String> compositeList = new CompositeList<String>();
    ListConsistencyListener<String> listConsistencyListener =
        ListConsistencyListener.install(compositeList);
    listConsistencyListener.setPreviousElementTracked(false);
    EventList<String> source = compositeList.createMemberList();
    source.add("C");
    source.add("A");
    source.add("B");

    SortedList<String> forwardSource = SortedList.create(source);
    SortedList<String> reverseSource =
        new SortedList<String>(source, GlazedLists.reverseComparator());
    compositeList.addMemberList(forwardSource);
    compositeList.addMemberList(source);
    compositeList.addMemberList(reverseSource);

    assertEquals(compositeList, GlazedListsTests.stringToList("ABCCABCBA"));

    source.add(1, "D");
    assertEquals(compositeList, GlazedListsTests.stringToList("ABCDCDABDCBA"));

    source.removeAll(GlazedListsTests.stringToList("AC"));
    assertEquals(compositeList, GlazedListsTests.stringToList("BDDBDB"));

    source.clear();
    assertEquals(compositeList, GlazedListsTests.stringToList(""));

    source.addAll(GlazedListsTests.stringToList("CADB"));
    assertEquals(compositeList, GlazedListsTests.stringToList("ABCDCADBDCBA"));
  }
 /**
  * Selects the specified search category. If the selected category is changed, this method updates
  * the sorted list.
  */
 @Override
 public void setSelectedCategory(SearchCategory selectedCategory) {
   if (this.selectedCategory != selectedCategory) {
     this.selectedCategory = selectedCategory;
     // Dispose of existing visible and sorted lists.
     if (visibleResultList != null) {
       visibleResultList.dispose();
       sortedResultList.dispose();
     }
     // Update visible and sorted lists.
     EventList<VisualSearchResult> filteredList = getCategorySearchResults(selectedCategory);
     sortedResultList = GlazedListsFactory.sortedList(filteredList, null);
     visibleResultList = GlazedListsFactory.filterList(sortedResultList, new VisibleMatcher());
     sortedResultList.setComparator(
         (sortOption != null) ? SortFactory.getSortComparator(sortOption) : null);
   }
 }
Exemplo n.º 4
0
  @Test
  public void serverCpuUsageGlazedListQuery() {

    StatefulKnowledgeSession ksession = createKnowledgeSession();

    Server winServer = new Server("winServer", 4, 4096, 2048, 25);
    FactHandle winServerFactHandle = ksession.insert(winServer);

    Server ubuntuServer = new Server("ubuntuServer", 4, 2048, 1024, 70);
    FactHandle ubuntuServerFactHandle = ksession.insert(ubuntuServer);

    Server debianServer = new Server("debianServer", 4, 2048, 1024, 10);
    ksession.insert(debianServer);

    GlazedListViewChangedEventListener listener = new GlazedListViewChangedEventListener();
    LiveQuery query = ksession.openLiveQuery("serverCpuUsage", new Object[] {20}, listener);

    SortedList<Row> serverSortedList =
        new SortedList<Row>(
            listener,
            new Comparator<Row>() {
              public int compare(Row r1, Row r2) {
                Server server1 = (Server) r1.get("$server");
                Server server2 = (Server) r2.get("$server");
                return (server1.getCpuUsage() - server2.getCpuUsage());
              }
            });

    System.out.println(
        "#######################################################################################");
    for (Row row : serverSortedList) {
      System.out.println(row.get("$server"));
    }

    assertEquals(10, ((Server) serverSortedList.get(0).get("$server")).getCpuUsage());

    ubuntuServer.setCpuUsage(13);
    ksession.update(ubuntuServerFactHandle, ubuntuServer);

    System.out.println(
        "#######################################################################################");
    for (Row row : serverSortedList) {
      System.out.println(row.get("$server"));
    }

    assertEquals(10, ((Server) serverSortedList.get(0).get("$server")).getCpuUsage());
    assertEquals(13, ((Server) serverSortedList.get(1).get("$server")).getCpuUsage());

    ubuntuServer.setCpuUsage(5);
    ksession.update(ubuntuServerFactHandle, ubuntuServer);
    winServer.setCpuUsage(0);
    ksession.update(winServerFactHandle, winServer);

    System.out.println(
        "#######################################################################################");
    for (Row row : serverSortedList) {
      System.out.println(row.get("$server"));
    }

    assertEquals(0, ((Server) serverSortedList.get(0).get("$server")).getCpuUsage());
    assertEquals(5, ((Server) serverSortedList.get(1).get("$server")).getCpuUsage());
    assertEquals(10, ((Server) serverSortedList.get(2).get("$server")).getCpuUsage());

    query.close();
    ksession.dispose();
  }
 /** Sets the sort option. This method updates the sorted list by changing the sort comparator. */
 @Override
 public void setSortOption(SortOption sortOption) {
   this.sortOption = sortOption;
   sortedResultList.setComparator(
       (sortOption != null) ? SortFactory.getSortComparator(sortOption) : null);
 }