use of org.phoebus.logbook.Property in project phoebus by ControlSystemStudio.
the class LogPropertiesEditorDemo method getDummyLogClient.
private LogClient getDummyLogClient() {
return new LogClient() {
@Override
public LogEntry set(LogEntry log) throws LogbookException {
return null;
}
@Override
public LogEntry getLog(Long logId) {
return null;
}
@Override
public Collection<Attachment> listAttachments(Long logId) {
return null;
}
@Override
public List<LogEntry> findLogs(Map<String, String> map) {
return null;
}
@Override
public Collection<LogEntry> listLogs() {
return null;
}
@Override
public Collection<Property> listProperties() {
Map<String, String> experimentAttributes = new HashMap<>();
experimentAttributes.put("id", "1234");
experimentAttributes.put("type", "XPD xray diffraction");
experimentAttributes.put("scan-id", "6789");
Property experimentProperty = PropertyImpl.of("Experiment", experimentAttributes);
return Arrays.asList(experimentProperty);
}
};
}
use of org.phoebus.logbook.Property in project phoebus by ControlSystemStudio.
the class LogPropertiesController method getProperties.
/**
* @return The list of logentry properties
*/
public List<Property> getProperties() {
List<Property> treeProperties = new ArrayList<>();
treeTableView.getRoot().getChildren().stream().forEach(node -> {
Map<String, String> att = node.getChildren().stream().map(TreeItem::getValue).collect(Collectors.toMap(PropertyTreeNode::getName, PropertyTreeNode::getValue));
Property property = PropertyImpl.of(node.getValue().getName(), att);
treeProperties.add(property);
});
return treeProperties;
}
use of org.phoebus.logbook.Property in project phoebus by ControlSystemStudio.
the class LogPropertiesDemo method start.
@Override
public void start(Stage primaryStage) throws IOException {
Map<String, String> tracAttributes = new HashMap<>();
tracAttributes.put("id", "1234");
tracAttributes.put("URL", "https://trac.epics.org/tickets/1234");
Property track = PropertyImpl.of("Track", tracAttributes);
Map<String, String> experimentAttributes = new HashMap<>();
experimentAttributes.put("id", "1234");
experimentAttributes.put("type", "XPD xray diffraction");
experimentAttributes.put("scan-id", "6789");
Property experimentProperty = PropertyImpl.of("Experiment", experimentAttributes);
Map<String, String> databrowser = new HashMap<>();
databrowser.put("name", "vaccum db");
databrowser.put("file", "sss");
Property resourceProperty = PropertyImpl.of("Resource", databrowser);
Map<String, String> empty = new HashMap<>();
empty.put("name", null);
empty.put("file", "");
Property emptyProperty = PropertyImpl.of("empty", empty);
ResourceBundle resourceBundle = NLS.getMessages(Messages.class);
FXMLLoader loader = new FXMLLoader();
loader.setResources(resourceBundle);
loader.setLocation(this.getClass().getResource("LogProperties.fxml"));
loader.load();
final LogPropertiesController controller = loader.getController();
Node tree = loader.getRoot();
CheckBox checkBox = new CheckBox();
BooleanProperty editable = new SimpleBooleanProperty();
checkBox.selectedProperty().bindBidirectional(editable);
controller.setProperties(Arrays.asList(track, experimentProperty, resourceProperty, emptyProperty));
editable.addListener((observable, oldValue, newValue) -> {
controller.setEditable(newValue);
});
VBox vbox = new VBox();
vbox.getChildren().add(checkBox);
vbox.getChildren().add(tree);
vbox.setPrefHeight(Region.USE_COMPUTED_SIZE);
Scene scene = new Scene(vbox, 400, 200);
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setOnCloseRequest(v -> {
controller.getProperties().stream().forEach(p -> {
System.out.println(p.getName());
p.getAttributes().entrySet().stream().forEach(e -> {
System.out.println(" " + e.getKey() + " : " + e.getValue());
});
});
});
}
use of org.phoebus.logbook.Property in project phoebus by ControlSystemStudio.
the class LogPropertiesController method initialize.
@FXML
public void initialize() {
// Read the attribute types
String url = LogbookUIPreferences.log_attribute_desc;
if (url.isEmpty()) {
final URL resource = getClass().getResource("log_property_attributes.properties");
url = resource.toExternalForm();
}
try (InputStream input = new URL(url).openStream()) {
Properties prop = new Properties();
prop.load(input);
prop.stringPropertyNames().stream().forEach((p) -> {
attributeTypes.put(p.toLowerCase(), prop.getProperty(p).toLowerCase());
});
} catch (IOException ex) {
ex.printStackTrace();
}
// create the property trees
name.setMaxWidth(1f * Integer.MAX_VALUE * 40);
name.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<PropertyTreeNode, String>, ObservableValue<String>>() {
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<PropertyTreeNode, String> p) {
return p.getValue().getValue().nameProperty();
}
});
value.setMaxWidth(1f * Integer.MAX_VALUE * 60);
value.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<PropertyTreeNode, ?>, SimpleObjectProperty<PropertyTreeNode>>() {
public SimpleObjectProperty<PropertyTreeNode> call(TreeTableColumn.CellDataFeatures<PropertyTreeNode, ?> p) {
return p.getValue().getValue().nodeProperty();
}
});
value.setEditable(editable.getValue());
value.setCellFactory(new Callback<TreeTableColumn<PropertyTreeNode, Object>, TreeTableCell<PropertyTreeNode, Object>>() {
@Override
public TreeTableCell<PropertyTreeNode, Object> call(TreeTableColumn<PropertyTreeNode, Object> param) {
return new TreeTableCell<>() {
private TextField textField;
@Override
public void startEdit() {
super.startEdit();
if (textField == null) {
createTextField();
}
setText(null);
setGraphic(textField);
textField.selectAll();
}
@Override
public void cancelEdit() {
super.cancelEdit();
setText(((PropertyTreeNode) getItem()).getValue());
setGraphic(getTreeTableRow().getGraphic());
}
@Override
public void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
} else {
PropertyTreeNode propertyItem = ((PropertyTreeNode) item);
if (attributeTypes.containsKey(propertyItem.getFullQualifiedName().toLowerCase())) {
switch(attributeTypes.get(propertyItem.getFullQualifiedName().toLowerCase())) {
case "url":
final String url = propertyItem.getValue();
final URI uri = URI.create(url);
final Hyperlink urlLink = new Hyperlink(propertyItem.getValue());
// TODO open url in some webclient
urlLink.setOnContextMenuRequested((e) -> {
ContextMenu contextMenu = new ContextMenu();
final List<AppResourceDescriptor> applications = ApplicationService.getApplications(uri);
applications.forEach(app -> {
MenuItem menuItem = new MenuItem(app.getDisplayName());
menuItem.setGraphic(ImageCache.getImageView(app.getIconURL()));
menuItem.setOnAction(actionEvent -> app.create(uri));
contextMenu.getItems().add(menuItem);
});
contextMenu.getItems().add(new SeparatorMenuItem());
MenuItem copyMenuItem = new MenuItem("copy", copy);
copyMenuItem.setOnAction(event -> {
final ClipboardContent content = new ClipboardContent();
content.putString(uri.toString());
Clipboard.getSystemClipboard().setContent(content);
});
contextMenu.getItems().add(copyMenuItem);
urlLink.setContextMenu(contextMenu);
});
setGraphic(urlLink);
break;
case "resource":
final String resourceURL = propertyItem.getValue();
final URI resource = URI.create(resourceURL);
final Hyperlink resourceLink = new Hyperlink(resourceURL);
setGraphic(resourceLink);
// Open resource using the default application
resourceLink.setOnAction((e) -> {
final List<AppResourceDescriptor> applications = ApplicationService.getApplications(resource);
if (!applications.isEmpty()) {
applications.get(0).create(resource);
}
});
resourceLink.setOnContextMenuRequested((e) -> {
ContextMenu contextMenu = new ContextMenu();
final List<AppResourceDescriptor> applications = ApplicationService.getApplications(resource);
applications.forEach(app -> {
MenuItem menuItem = new MenuItem(app.getDisplayName());
menuItem.setGraphic(ImageCache.getImageView(app.getIconURL()));
menuItem.setOnAction(actionEvent -> app.create(resource));
contextMenu.getItems().add(menuItem);
});
contextMenu.getItems().add(new SeparatorMenuItem());
MenuItem copyMenuItem = new MenuItem("copy", copy);
copyMenuItem.setOnAction(event -> {
final ClipboardContent content = new ClipboardContent();
content.putString(resource.toString());
Clipboard.getSystemClipboard().setContent(content);
});
contextMenu.getItems().add(copyMenuItem);
resourceLink.setContextMenu(contextMenu);
});
break;
default:
setGraphic(new Label(propertyItem.getValue()));
}
} else {
setGraphic(new Label(propertyItem.getValue()));
}
}
}
private void createTextField() {
textField = new TextField(getString());
textField.setOnKeyReleased((KeyEvent t) -> {
if (t.getCode() == KeyCode.ENTER) {
((PropertyTreeNode) getItem()).setValue(textField.getText());
commitEdit(getItem());
} else if (t.getCode() == KeyCode.ESCAPE) {
cancelEdit();
}
});
}
private String getString() {
if (getItem() != null && ((PropertyTreeNode) getItem()).getValue() != null) {
return ((PropertyTreeNode) getItem()).getValue();
} else {
return "";
}
}
};
}
});
editable.addListener((observable, oldValue, newValue) -> {
value.setEditable(newValue);
});
// Hide the headers
treeTableView.widthProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
// Get the table header
Pane header = (Pane) treeTableView.lookup("TableHeaderRow");
if (header != null && header.isVisible()) {
header.setMaxHeight(0);
header.setMinHeight(0);
header.setPrefHeight(0);
header.setVisible(false);
header.setManaged(false);
}
}
});
}
use of org.phoebus.logbook.Property in project phoebus by ControlSystemStudio.
the class OlogPropertyTest method testHashCode.
@Test
public void testHashCode() {
Property property1 = new OlogProperty("name1");
Property property2 = new OlogProperty("name2");
assertNotEquals(property1.hashCode(), property2.hashCode());
property2 = new OlogProperty("name1");
assertEquals(property1.hashCode(), property2.hashCode());
assertNotEquals(property1.hashCode(), new Object().hashCode());
}
Aggregations