Java Code Examples for javafx.collections.ObservableList#sort()

The following examples show how to use javafx.collections.ObservableList#sort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeDetailPaneController.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void setFocusNode(final Node node, DataHolder options) {
    xpathAttributesTableView.setItems(getAttributes(node));
    if (node == null) {
        additionalInfoListView.setItems(FXCollections.emptyObservableList());
        return;
    }
    DesignerBindings bindings = languageBindingsProperty().getOrElse(DefaultDesignerBindings.getInstance());
    ObservableList<AdditionalInfo> additionalInfo = FXCollections.observableArrayList(bindings.getAdditionalInfo(node));
    additionalInfo.sort(Comparator.comparing(AdditionalInfo::getSortKey));
    additionalInfoListView.setItems(LiveList.map(additionalInfo, AdditionalInfo::getDisplayString));
}
 
Example 2
Source File: NodeDetailPaneController.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Gets the XPath attributes of the node for display within a listview.
 */
private ObservableList<Attribute> getAttributes(Node node) {
    if (node == null) {
        xpathAttributesTableView.setPlaceholder(new Label("Select a node to show its attributes"));
        return FXCollections.emptyObservableList();
    }

    ObservableList<Attribute> result = FXCollections.observableArrayList();
    Iterator<Attribute> attributeAxisIterator = node.getXPathAttributesIterator();
    while (attributeAxisIterator.hasNext()) {
        Attribute attribute = attributeAxisIterator.next();

        if (!(isHideCommonAttributes() && IGNORABLE_ATTRIBUTES.contains(attribute.getName()))) {

            try {
                result.add(attribute);
            } catch (Exception ignored) {
                // some attributes throw eg numberformat exceptions
            }

        }
    }

    result.sort(Comparator.comparing(Attribute::getName));
    xpathAttributesTableView.setPlaceholder(new Label("No available attributes"));
    return result;
}
 
Example 3
Source File: TreeFileItem.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Builds tree item children.
 *
 * @return tree item children
 */
private ObservableList<TreeFileItem> buildChildren() {
  if (file != null && file.isDirectory()) {
    File[] files = file.listFiles();
    if (files != null) {
      ObservableList<TreeFileItem> children = FXCollections.observableArrayList();
      for (File f : files) {
        if (!f.isHidden() && (f.isDirectory() || FS.isAssemblyFile(f))) {
          children.add(new TreeFileItem(f, false, expanded));
        }
      }
      // sort children
      children.sort(new Comparator<TreeFileItem>() {
        @Override
        public int compare(TreeFileItem p, TreeFileItem q) {
          String fn = p.getFile().getName().toString();
          String qn = q.getFile().getName().toString();
          boolean pd = p.getFile().isDirectory();
          boolean qd = q.getFile().isDirectory();
          if (pd && !qd)
            return -1;
          else if (!pd && qd)
            return 1;
          else
            return fn.compareToIgnoreCase(qn);
        }
      });
      return children;
    }
  }
  return FXCollections.emptyObservableList();
}
 
Example 4
Source File: BattleLogController.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * 集計する
 */
private void aggregate() {
    String name = this.aggregateType.getSelectionModel()
            .getSelectedItem();
    ObservableList<BattleLogDetailAggregate> items = FXCollections.observableArrayList();
    ObservableList<PieChart.Data> value = FXCollections.observableArrayList();
    if (name != null) {
        Function<BattleLogDetail, ?> getter = this.aggregateTypeMap.get(name);
        Map<String, Long> result = this.filteredDetails.stream()
                .map(getter)
                .map(String::valueOf)
                .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
        double total = result.values().stream()
                .mapToLong(Long::longValue)
                .sum();
        for (Entry<String, Long> entry : result.entrySet()) {
            String type = entry.getKey();
            if (type.isEmpty()) {
                type = "(空白)";
            }
            // テーブル行
            BattleLogDetailAggregate row = new BattleLogDetailAggregate();
            row.setName(type);
            row.setCount(entry.getValue());
            row.setRatio(entry.getValue() / total * 100);
            items.add(row);
            // チャート
            value.add(new PieChart.Data(type, entry.getValue()));
        }
        items.sort(Comparator.comparing(BattleLogDetailAggregate::getName));
        value.sort(Comparator.comparing(PieChart.Data::getPieValue).reversed());
    }
    this.aggregate.setItems(items);
    this.chart.setTitle(name);
    this.chart.setData(value);
}
 
Example 5
Source File: PropertyDialog.java    From logbook-kai with MIT License 5 votes vote down vote up
private ObservableList<Item> getProperties(T bean) {
    ObservableList<Item> properties = BeanPropertyUtils.getProperties(bean);
    List<String> fields = Arrays.stream(bean.getClass().getDeclaredFields())
            .map(Field::getName)
            .collect(Collectors.toList());
    properties.sort(Comparator.comparing(p -> fields.indexOf(((BeanProperty) p).getName())));
    return properties;
}
 
Example 6
Source File: WidgetInfoDialog.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private Tab createPVs(final Collection<NameStateValue> pvs)
{
    // Use text field to allow users to copy the name, value to clipboard
    final TableColumn<NameStateValue, String> name = new TableColumn<>(Messages.WidgetInfoDialog_Name);
    name.setCellFactory(col -> new ReadOnlyTextCell<>());
    name.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().name));

    final TableColumn<NameStateValue, String> state = new TableColumn<>(Messages.WidgetInfoDialog_State);
    state.setCellFactory(col -> new ReadOnlyTextCell<>());
    state.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().state));

    final TableColumn<NameStateValue, String> path = new TableColumn<>(Messages.WidgetInfoDialog_Path);
    path.setCellFactory(col -> new ReadOnlyTextCell<>());
    path.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().path));

    final TableColumn<NameStateValue, String> value = new TableColumn<>(Messages.WidgetInfoDialog_Value);
    value.setCellFactory(col -> new AlarmColoredCell());
    value.setCellValueFactory(param ->
    {
        String text;
        final VType vtype = param.getValue().value;
        if (vtype == null)
            text = Messages.WidgetInfoDialog_Disconnected;
        else
        {   // Formatting arrays can be very slow,
            // so only show the basic type info
            if (vtype instanceof VNumberArray)
                text = vtype.toString();
            else
                text = VTypeUtil.getValueString(vtype, true);
            final Alarm alarm = Alarm.alarmOf(vtype);
            if (alarm != null  &&  alarm.getSeverity() != AlarmSeverity.NONE)
                text = text + " [" + alarm.getSeverity().toString() + ", " +
                                     alarm.getName() + "]";
        }
        return new ReadOnlyStringWrapper(text);
    });

    final ObservableList<NameStateValue> pv_data = FXCollections.observableArrayList(pvs);
    pv_data.sort((a, b) -> a.name.compareTo(b.name));
    final TableView<NameStateValue> table = new TableView<>(pv_data);
    table.getColumns().add(name);
    table.getColumns().add(state);
    table.getColumns().add(value);
    table.getColumns().add(path);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    return new Tab(Messages.WidgetInfoDialog_TabPVs, table);
}
 
Example 7
Source File: ProjectsComboBox.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 4 votes vote down vote up
ProjectsComboBox(FileEditorManager fileEditorManager) {
	getStyleClass().add("projects-combo-box");
	setFocusTraversable(false);
	setVisibleRowCount(30);
	setButtonCell(new ProjectButtonCell());
	setCellFactory(listView -> new ProjectListCell());

	// let this control grow horizontally
	setMaxWidth(Double.MAX_VALUE);

	// update tooltip
	valueProperty().addListener((observer, oldProject, newProject) -> {
		setTooltip((newProject != null) ? new Tooltip(newProject.getAbsolutePath()) : null);
	});

	// add items
	ObservableList<File> projects = ProjectManager.getProjects();
	projects.sort(PROJECT_COMPARATOR);
	getItems().add(OPEN_FOLDER);
	getItems().addAll(projects);

	// set active project
	setValue(ProjectManager.getActiveProject());

	// listen to selection changes
	getSelectionModel().selectedItemProperty().addListener((observer, oldProject, newProject) -> {
		if (inSelectionChange)
			return;

		if (newProject == ProjectManager.getActiveProject())
			return;

		Platform.runLater(() -> {
			inSelectionChange = true;
			try {
				if (newProject == OPEN_FOLDER) {
					// closing last active project automatically selects this item
					// --> activate first project
					if (oldProject != null && !getItems().contains(oldProject)) {
						ProjectManager.setActiveProject((getItems().size() > 1) ? getItems().get(1) : null);
						return;
					}

					getSelectionModel().select(oldProject);

					if (fileEditorManager.canOpenAnotherProject())
						ProjectManager.openProject(getScene().getWindow());
				} else {
					if (fileEditorManager.canOpenAnotherProject())
						ProjectManager.setActiveProject(newProject);
					else
						getSelectionModel().select(oldProject);
				}
			} finally {
				inSelectionChange = false;
			}
		});
	});

	// listen to projects changes and update combo box
	projects.addListener((ListChangeListener<File>) change -> {
		while (change.next()) {
			if (change.wasAdded()) {
				for (File addedProject : change.getAddedSubList())
					Utils.addSorted(getItems(), addedProject, PROJECT_COMPARATOR);
			}
			if (change.wasRemoved())
				getItems().removeAll(change.getRemoved());
		}
	});

	// listen to active project change and update combo box value
	ProjectManager.activeProjectProperty().addListener((observer, oldProject, newProject) -> {
		setValue(newProject);
	});
}
 
Example 8
Source File: TreeNode.java    From jmonkeybuilder with Apache License 2.0 2 votes vote down vote up
/**
 * Handle the result context menu.
 *
 * @param nodeTree the node tree.
 * @param items    the result items.
 */
@FxThread
public void handleResultContextMenu(@NotNull final NodeTree<?> nodeTree,
                                    @NotNull final ObservableList<MenuItem> items) {
    items.sort(ACTION_COMPARATOR);
}