2022-01-21 15:44:12 +00:00
|
|
|
// property.rs
|
|
|
|
//
|
|
|
|
// Copyright 2022 Stéphane Cerveau <scerveau@collabora.com>
|
|
|
|
//
|
2022-02-09 10:28:27 +00:00
|
|
|
// This file is part of GraphManager
|
2022-01-21 15:44:12 +00:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
2022-02-09 10:28:27 +00:00
|
|
|
|
2022-02-08 13:53:12 +00:00
|
|
|
use log::info;
|
2022-01-21 15:44:12 +00:00
|
|
|
use std::cell::Ref;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
pub trait PropertyExt {
|
|
|
|
fn hidden_property(&self, name: &str) -> bool {
|
|
|
|
name.starts_with('_')
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add a node property with a name and a value.
|
|
|
|
///
|
|
|
|
fn add_property(&self, name: &str, value: &str);
|
|
|
|
|
2022-02-03 15:09:26 +00:00
|
|
|
/// Add a node property with a name and a value.
|
|
|
|
///
|
|
|
|
fn remove_property(&self, name: &str);
|
|
|
|
|
2022-01-21 15:44:12 +00:00
|
|
|
/// Update the properties.
|
|
|
|
///
|
|
|
|
/// Update the PropertyExt properties.
|
|
|
|
///
|
|
|
|
fn update_properties(&self, new_properties: &HashMap<String, String>) {
|
|
|
|
for (key, value) in new_properties {
|
2022-02-08 13:53:12 +00:00
|
|
|
info!("Updating property name={} value={}", key, value);
|
2022-02-03 15:09:26 +00:00
|
|
|
if value.is_empty() {
|
|
|
|
self.remove_property(key);
|
|
|
|
} else {
|
|
|
|
self.add_property(key, value);
|
|
|
|
}
|
2022-01-21 15:44:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Retrieves properties.
|
|
|
|
///
|
|
|
|
fn properties(&self) -> Ref<HashMap<String, String>>;
|
|
|
|
|
|
|
|
/// Retrieves property with the name.
|
|
|
|
///
|
|
|
|
/// Retrieves node property with the name.
|
|
|
|
///
|
|
|
|
fn property(&self, name: &str) -> Option<String> {
|
|
|
|
if let Some(property) = self.properties().get(name) {
|
|
|
|
return Some(property.clone());
|
|
|
|
}
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|