Java Code Examples for javafx.scene.control.TreeItem#setGraphic()

The following examples show how to use javafx.scene.control.TreeItem#setGraphic() . 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: MaterialEditorController.java    From OEE-Designer with MIT License 6 votes vote down vote up
private void populateCategories() throws Exception {
	// fetch the categories
	List<String> categories = PersistenceService.instance().fetchMaterialCategories();
	Collections.sort(categories);

	getRootMaterialItem().getChildren().clear();

	for (String category : categories) {
		MaterialNode categoryNode = new MaterialNode(category);
		TreeItem<MaterialNode> categoryItem = new TreeItem<>(categoryNode);
		categoryItem.setGraphic(ImageManager.instance().getImageView(Images.CATEGORY));
		getRootMaterialItem().getChildren().add(categoryItem);
	}

	// refresh tree view
	tvMaterials.setRoot(getRootMaterialItem());

	// also in the drop down
	cbCategories.getItems().clear();
	cbCategories.getItems().addAll(categories);
	tvMaterials.refresh();
}
 
Example 2
Source File: MissionCheck.java    From logbook-kai with MIT License 6 votes vote down vote up
private void setIcon(TreeItem<String> item, Boolean result) {
    GlyphFont fontAwesome = GlyphFontRegistry.font("FontAwesome");

    StackPane pane = new StackPane();
    pane.setPrefWidth(18);

    if (result != null) {
        if (result) {
            pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.CHECK).color(Color.GREEN));
        } else {
            pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.EXCLAMATION).color(Color.RED));
        }
    } else {
        pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.QUESTION).color(Color.GRAY));
    }
    item.setGraphic(pane);
}
 
Example 3
Source File: UomEditorController.java    From OEE-Designer with MIT License 6 votes vote down vote up
@FXML
private void onSaveAllUoms() {
	try {
		// save all modified UOMs
		for (TreeItem<UomNode> modifiedItem : editedUomItems) {
			UomNode node = modifiedItem.getValue();
			UnitOfMeasure saved = (UnitOfMeasure) PersistenceService.instance().save(node.getUnitOfMeasure());
			node.setUnitOfMeasure(saved);
			modifiedItem.setGraphic(ImageManager.instance().getImageView(Images.UOM));
		}
		editedUomItems.clear();

		tvUoms.refresh();

	} catch (Exception e) {
		AppUtils.showErrorDialog(e);
	}
}
 
Example 4
Source File: ReasonEditorController.java    From OEE-Designer with MIT License 6 votes vote down vote up
@FXML
private void onSaveAllReasons() {
	try {
		// current reason could have been edited
		setAttributes(selectedReasonItem);

		// save all modified reasons
		for (TreeItem<ReasonNode> editedReasonItem : editedReasonItems) {
			ReasonNode node = editedReasonItem.getValue();
			Reason saved = (Reason) PersistenceService.instance().save(node.getReason());
			node.setReason(saved);
			editedReasonItem.setGraphic(ImageManager.instance().getImageView(Images.REASON));
		}

		editedReasonItems.clear();
		tvReasons.refresh();

	} catch (Exception e) {
		AppUtils.showErrorDialog(e);
	}
}
 
Example 5
Source File: OpcUaBrowserController.java    From OEE-Designer with MIT License 6 votes vote down vote up
private void showRootNodes() throws Exception {
	TreeItem<OpcUaTreeNode> rootItem = new TreeItem<>();
	tvBrowser.setRoot(rootItem);
	rootItem.setExpanded(true);

	// browse root folder
	List<ReferenceDescription> refs = getApp().getOpcUaClient().browseSynch(Identifiers.RootFolder);

	for (ReferenceDescription ref : refs) {
		// child nodes
		TreeItem<OpcUaTreeNode> childItem = new TreeItem<>(new OpcUaTreeNode(ref));
		ImageView imageView = new ImageView(getNodeImage(ref));
		childItem.setGraphic(imageView);

		rootItem.getChildren().add(childItem);
	}
}
 
Example 6
Source File: CoursesTreeView.java    From iliasDownloaderTool with GNU General Public License v2.0 6 votes vote down vote up
private void setCourses(TreeItem<IliasTreeNode> rootItem, List<? extends IliasTreeNode> kurse) {
	for (IliasTreeNode node : kurse) {
		TreeItem<IliasTreeNode> item = new TreeItem<IliasTreeNode>(node);
		rootItem.getChildren().add(item);

		if (node instanceof IliasFolder) {
			IliasFolder folder = (IliasFolder) node;
			setCourses(item, folder.getChildNodes());
			item.setGraphic(node.getGraphic());
		} else if (node instanceof IliasFile) {
			item.setGraphic(node.getGraphic());
		} else if (node instanceof IliasForum) {
			item.setGraphic(node.getGraphic());
		}
	}
}
 
Example 7
Source File: ReasonSelectorController.java    From OEE-Designer with MIT License 6 votes vote down vote up
private void onSelectReason(TreeItem<ReasonNode> oldItem, TreeItem<ReasonNode> newItem) throws Exception {
	if (newItem == null) {
		return;
	}

	// new attributes
	selectedReason = newItem.getValue().getReason();

	// show the children too
	Set<Reason> children = selectedReason.getChildren();
	List<Reason> sortedChildren = new ArrayList<>(children);
	Collections.sort(sortedChildren);

	boolean hasTreeChildren = newItem.getChildren().size() > 0 ? true : false;

	// check to see if the node's children have been previously shown
	if (!hasTreeChildren) {
		newItem.getChildren().clear();
		for (Reason child : children) {
			TreeItem<ReasonNode> entityItem = new TreeItem<>(new ReasonNode(child));
			newItem.getChildren().add(entityItem);
			entityItem.setGraphic(ImageManager.instance().getImageView(Images.REASON));
		}
	}
	newItem.setExpanded(true);
}
 
Example 8
Source File: MaterialEditorController.java    From OEE-Designer with MIT License 5 votes vote down vote up
private void updateCategory(TreeItem<MaterialNode> materialItem) throws Exception {

		Material material = materialItem.getValue().getMaterial();

		String parentCategory = materialItem.getParent().getValue().getCategory();

		if (!material.getCategory().equals(parentCategory)) {
			// remove from category
			TreeItem<MaterialNode> categoryNode = materialItem.getParent();
			categoryNode.getChildren().remove(materialItem);

			if (categoryNode.getChildren().size() == 0) {
				// remove category too
				categoryNode.getParent().getChildren().remove(categoryNode);
			}

			// add to new category
			TreeItem<MaterialNode> newItem = new TreeItem<>(new MaterialNode(material));
			resetGraphic(newItem);
			ObservableList<TreeItem<MaterialNode>> categoryItems = tvMaterials.getRoot().getChildren();

			TreeItem<MaterialNode> parentItem = null;
			for (TreeItem<MaterialNode> categoryItem : categoryItems) {
				if (categoryItem.getValue().getCategory().equals(material.getCategory())) {
					// existing category
					parentItem = categoryItem;
					break;
				}
			}

			if (parentItem == null) {
				// new category
				parentItem = new TreeItem<>(new MaterialNode(material.getCategory()));
				parentItem.setGraphic(ImageManager.instance().getImageView(Images.CATEGORY));
				tvMaterials.getRoot().getChildren().add(parentItem);
			}
			parentItem.getChildren().add(newItem);
		}
	}
 
Example 9
Source File: UomEditorController.java    From OEE-Designer with MIT License 5 votes vote down vote up
private UnitOfMeasure createUom() {
	UnitOfMeasure uom = null;
	try {
		// new child
		uom = new UnitOfMeasure();
		selectedUomItem = new TreeItem<>(new UomNode(uom));
		selectedUomItem.setGraphic(ImageManager.instance().getImageView(Images.UOM));

		// set the attributes
		setAttributes(selectedUomItem);
		editedUomItems.add(selectedUomItem);

		// category
		String category = uom.getCategory();

		ObservableList<TreeItem<UomNode>> categoryItems = getRootUomItem().getChildren();
		TreeItem<UomNode> parentCategoryItem = null;

		for (TreeItem<UomNode> categoryItem : categoryItems) {
			if (categoryItem.getValue().getCategory().equals(category)) {
				parentCategoryItem = categoryItem;
				break;
			}
		}

		if (parentCategoryItem == null) {
			// new category
			parentCategoryItem = new TreeItem<>(new UomNode(category));
			parentCategoryItem.setGraphic(ImageManager.instance().getImageView(Images.CATEGORY));
			getRootUomItem().getChildren().add(parentCategoryItem);
		}

		parentCategoryItem.getChildren().add(selectedUomItem);
		parentCategoryItem.setExpanded(true);

	} catch (Exception e) {
		AppUtils.showErrorDialog(e);
	}
	return uom;
}
 
Example 10
Source File: MaterialEditorController.java    From OEE-Designer with MIT License 5 votes vote down vote up
private void createMaterial() {
	try {
		// new child
		Material newMaterial = new Material();
		selectedMaterialItem = new TreeItem<>(new MaterialNode(newMaterial));
		addEditedMaterial(selectedMaterialItem);
		resetGraphic(selectedMaterialItem);

		// set attributes from UI
		setAttributes(selectedMaterialItem);

		// category
		String category = newMaterial.getCategory();

		ObservableList<TreeItem<MaterialNode>> categoryItems = getRootMaterialItem().getChildren();
		TreeItem<MaterialNode> parentCategoryItem = null;

		for (TreeItem<MaterialNode> categoryItem : categoryItems) {
			if (categoryItem.getValue().getCategory().equals(category)) {
				parentCategoryItem = categoryItem;
				break;
			}
		}

		if (parentCategoryItem == null) {
			// new category
			parentCategoryItem = new TreeItem<>(new MaterialNode(category));
			parentCategoryItem.setGraphic(ImageManager.instance().getImageView(Images.CATEGORY));
			getRootMaterialItem().getChildren().add(parentCategoryItem);
		}

		parentCategoryItem.getChildren().add(selectedMaterialItem);
		getRootMaterialItem().setExpanded(true);

	} catch (Exception e) {
		AppUtils.showErrorDialog(e);
	}
}
 
Example 11
Source File: OperatorController.java    From OEE-Designer with MIT License 5 votes vote down vote up
private void setEntityGraphic(TreeItem<EntityNode> item) throws Exception {
	ImageView nodeView = null;
	PlantEntity entity = item.getValue().getPlantEntity();
	EntityLevel level = entity.getLevel();

	if (level == null) {
		return;
	}

	switch (level) {
	case AREA:
		nodeView = ImageManager.instance().getImageView(Images.AREA);
		break;
	case ENTERPRISE:
		nodeView = ImageManager.instance().getImageView(Images.ENTERPRISE);
		break;
	case EQUIPMENT:
		nodeView = ImageManager.instance().getImageView(Images.EQUIPMENT);
		break;

	case PRODUCTION_LINE:
		nodeView = ImageManager.instance().getImageView(Images.LINE);
		break;

	case SITE:
		nodeView = ImageManager.instance().getImageView(Images.SITE);
		break;

	case WORK_CELL:
		nodeView = ImageManager.instance().getImageView(Images.CELL);
		break;

	default:
		break;
	}

	item.setGraphic(nodeView);
}
 
Example 12
Source File: DbgView.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
private void createModuleTreeItem(OtpErlangTuple tuple) {
    boolean isExported;
    OtpErlangAtom moduleNameAtom = (OtpErlangAtom) tuple.elementAt(0);
    OtpErlangList exportedFuncs = (OtpErlangList) tuple.elementAt(1);
    OtpErlangList localFuncs = (OtpErlangList) tuple.elementAt(2);

    TreeItem<ModFunc> moduleItem;

    ModFunc module = ModFunc.toModule(moduleNameAtom);
    moduleItem = new TreeItem<ModFunc>(module);
    moduleItem.setGraphic(treeIcon(AwesomeIcon.CUBE));

    ObservableList<TreeItem<ModFunc>> modFuncs = FXCollections.observableArrayList();

    SortedList<TreeItem<ModFunc>> sortedFuncs = new SortedList<TreeItem<ModFunc>>(modFuncs);

    FilteredList<TreeItem<ModFunc>> filteredFuncs = new FilteredList<TreeItem<ModFunc>>(sortedFuncs);

    sortedFuncs.setComparator(treeItemModFuncComparator());

    isExported = true;
    addTreeItems(toModFuncs(moduleNameAtom, exportedFuncs, isExported), modFuncs);

    isExported = false;
    addTreeItems(toModFuncs(moduleNameAtom, localFuncs, isExported), modFuncs);
    functionLists.put(module, filteredFuncs);

    Bindings.bindContentBidirectional(moduleItem.getChildren(), filteredFuncs);

    ArrayList<TreeItem<ModFunc>> treeModulesCopy = new ArrayList<>(treeModules);
    for (TreeItem<ModFunc> treeItem : treeModulesCopy) {
        if(treeItem.getValue().equals(module)) {
            treeModules.remove(treeItem);
        }
    }
    treeModules.add(moduleItem);
}
 
Example 13
Source File: QuestProgress.java    From logbook-kai with MIT License 5 votes vote down vote up
private static void setFilterIcon(TreeItem<String> item) {
    GlyphFont fontAwesome = GlyphFontRegistry.font("FontAwesome");
    StackPane pane = new StackPane();
    pane.setPrefWidth(18);
    pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.FILTER).color(Color.ROYALBLUE));
    item.setGraphic(pane);
}
 
Example 14
Source File: QuestProgress.java    From logbook-kai with MIT License 5 votes vote down vote up
private static void setFilterListIcon(TreeItem<String> item) {
    GlyphFont fontAwesome = GlyphFontRegistry.font("FontAwesome");
    StackPane pane = new StackPane();
    pane.setPrefWidth(18);
    pane.getChildren().add(fontAwesome.create(FontAwesome.Glyph.ANGLE_RIGHT).color(Color.ROYALBLUE));
    item.setGraphic(pane);
}
 
Example 15
Source File: WorkScheduleEditorController.java    From OEE-Designer with MIT License 4 votes vote down vote up
private void resetGraphic(TreeItem<ScheduleNode> scheduleItem) throws Exception {
	scheduleItem.setGraphic(ImageManager.instance().getImageView(Images.SCHEDULE));
}
 
Example 16
Source File: WorkScheduleEditorController.java    From OEE-Designer with MIT License 4 votes vote down vote up
private void addEditedSchedule(TreeItem<ScheduleNode> scheduleItem) throws Exception {
	if (!editedScheduleItems.contains(scheduleItem)) {
		editedScheduleItems.add(scheduleItem);
		scheduleItem.setGraphic(ImageManager.instance().getImageView(Images.CHANGED));
	}
}
 
Example 17
Source File: MaterialEditorController.java    From OEE-Designer with MIT License 4 votes vote down vote up
private boolean setAttributes(TreeItem<MaterialNode> materialItem) throws Exception {
	boolean isDirty = false;

	if (materialItem == null || !materialItem.getValue().isMaterial()) {
		return isDirty;
	}
	Material material = materialItem.getValue().getMaterial();

	// name
	String name = this.tfName.getText().trim();
	if (name.length() == 0) {
		throw new Exception(DesignerLocalizer.instance().getErrorString("no.name"));
	}

	if (!name.equals(material.getName())) {
		material.setName(name);
		isDirty = true;
	}

	// description
	String description = this.taDescription.getText();

	if (description != null && !description.equals(material.getDescription())) {
		material.setDescription(description);
		isDirty = true;
	}

	// category
	String category = this.cbCategories.getSelectionModel().getSelectedItem();
	if (category == null) {
		category = DesignerLocalizer.instance().getLangString("uncategorized");
	}

	if (!category.equals(material.getCategory())) {
		material.setCategory(category);
		isDirty = true;
	}

	if (isDirty) {
		materialItem.setGraphic(ImageManager.instance().getImageView(Images.CHANGED));
		addEditedMaterial(materialItem);
	}
	return isDirty;
}
 
Example 18
Source File: ReasonEditorController.java    From OEE-Designer with MIT License 4 votes vote down vote up
private boolean setAttributes(TreeItem<ReasonNode> reasonItem) throws Exception {
	boolean isDirty = false;

	if (reasonItem == null) {
		return isDirty;
	}
	Reason reason = reasonItem.getValue().getReason();

	// name
	String name = this.tfName.getText().trim();

	if (name.length() == 0) {
		throw new Exception(DesignerLocalizer.instance().getErrorString("no.name"));
	}

	if (!name.equals(reason.getName())) {
		reason.setName(name);
		isDirty = true;
	}

	// description
	String description = this.taDescription.getText();

	if (!description.equals(reason.getDescription())) {
		reason.setDescription(description);
		isDirty = true;
	}

	// loss
	TimeLoss loss = cbLosses.getSelectionModel().getSelectedItem();

	if (loss != null && !loss.equals(reason.getLossCategory())) {
		reason.setLossCategory(loss);
		isDirty = true;
	}

	if (isDirty) {
		reasonItem.setGraphic(ImageManager.instance().getImageView(Images.CHANGED));
		addEditedReason(reasonItem);
	}

	return isDirty;
}
 
Example 19
Source File: MZmineGUIProject.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public void addFile(final RawDataFile rawDataFile) {
  super.addFile(rawDataFile);
  TreeItem<Object> df1 = new TreeItem<>(rawDataFile);
  df1.setGraphic(new ImageView(fileIcon));
  rawDataRootItem.getChildren().add(df1);
}
 
Example 20
Source File: MaterialEditorController.java    From OEE-Designer with MIT License 4 votes vote down vote up
private void onSelectMaterial(TreeItem<MaterialNode> oldItem, TreeItem<MaterialNode> newItem) throws Exception {
	if (newItem == null) {
		return;
	}

	// check for previous edit
	if (oldItem != null && oldItem.getValue().isMaterial()) {
		boolean isChanged = setAttributes(oldItem);

		if (isChanged) {
			oldItem.setGraphic(ImageManager.instance().getImageView(Images.CHANGED));
			tvMaterials.refresh();
		}
	}

	// leaf node is material
	if (newItem.getValue().isMaterial()) {
		// display Material properties
		displayAttributes(newItem.getValue().getMaterial());
		selectedMaterialItem = newItem;
		return;
	} else {
		// category selected
		selectedMaterialItem = null;
	}

	// show the material children too
	List<Material> children = PersistenceService.instance()
			.fetchMaterialsByCategory(newItem.getValue().getCategory());
	Collections.sort(children);

	boolean hasTreeChildren = newItem.getChildren().size() > 0 ? true : false;

	// check to see if the node's children have been previously shown
	if (!hasTreeChildren) {
		newItem.getChildren().clear();
		for (Material child : children) {
			MaterialNode materialNode = new MaterialNode(child);
			TreeItem<MaterialNode> materialItem = new TreeItem<>(materialNode);
			resetGraphic(materialItem);
			newItem.getChildren().add(materialItem);
		}
	}
	newItem.setExpanded(true);
	tvMaterials.refresh();
}