use of au.gov.asd.tac.constellation.views.attributeeditor.editors.AttributeValueEditorFactory in project constellation by constellation-app.
the class AttributeEditorPanel method createAttributeTitlePane.
/**
* Creates individual TitledPane within header title panes.
*
* @param attribute the attribute to display.
* @param values the different values available for the attribute.
* @param longestTitledWidth the width of the longest title in the pane.
* @param hidden is the pane currently hidden.
* @return a new TitledPane.
*/
public TitledPane createAttributeTitlePane(final AttributeData attribute, final Object[] values, final double longestTitledWidth, final boolean hidden) {
final String attributeTitle = attribute.getAttributeName();
final int spacing = 5;
final int buttonSize = 45;
final GridPane gridPane = new GridPane();
gridPane.setHgap(spacing);
final double titleWidth = longestTitledWidth + spacing;
final AttributeTitledPane attributePane;
if (!attribute.isKey()) {
attributePane = new AttributeTitledPane(e -> deleteAttributeAction(attribute.getElementType(), attributeTitle), e -> modifyAttributeAction(attribute));
} else {
attributePane = new AttributeTitledPane();
}
attributePane.setHidden(hidden);
gridPane.prefWidthProperty().bind(attributePane.widthProperty());
if (attribute.getDataType().equals(ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME)) {
attributePane.addMenuItem("Update time-zone of selection", e -> updateTimeZoneAction(attribute));
}
final boolean multiValue = values != null && values.length > 1;
if (attribute.isKey()) {
final String colour;
if (hidden) {
final ConstellationColor hiddenColour = ConstellationColor.fromHtmlColor(prefs.get(AttributePreferenceKey.HIDDEN_ATTRIBUTE_COLOUR, HIDDEN_ATTRIBUTE_COLOUR));
final ConstellationColor keyColour = ConstellationColor.fromHtmlColor(prefs.get(AttributePreferenceKey.PRIMARY_KEY_ATTRIBUTE_COLOUR, PRIMARY_KEY_ATTRIBUTE_COLOUR));
colour = (ConstellationColor.getColorValue(hiddenColour.getRed() * 0.5F + keyColour.getRed() * 0.5F, hiddenColour.getGreen() * 0.5F + keyColour.getGreen() * 0.5F, hiddenColour.getBlue() * 0.5F + keyColour.getBlue() * 0.5F, 1F)).getHtmlColor();
} else {
colour = prefs.get(AttributePreferenceKey.PRIMARY_KEY_ATTRIBUTE_COLOUR, PRIMARY_KEY_ATTRIBUTE_COLOUR);
}
attributePane.setStyle(JavafxStyleManager.CSS_BASE_STYLE_PREFIX + colour + SeparatorConstants.SEMICOLON);
} else if (!attribute.isSchema()) {
final String colour;
if (hidden) {
final ConstellationColor hiddenColour = ConstellationColor.fromHtmlColor(prefs.get(AttributePreferenceKey.HIDDEN_ATTRIBUTE_COLOUR, HIDDEN_ATTRIBUTE_COLOUR));
final ConstellationColor customColour = ConstellationColor.fromHtmlColor(prefs.get(AttributePreferenceKey.CUSTOM_ATTRIBUTE_COLOUR, CUSTOM_ATTRIBUTE_COLOUR));
colour = (ConstellationColor.getColorValue(hiddenColour.getRed() * 0.5F + customColour.getRed() * 0.5F, hiddenColour.getGreen() * 0.5F + customColour.getGreen() * 0.5F, hiddenColour.getBlue() * 0.5F + customColour.getBlue() * 0.5F, 1F)).getHtmlColor();
} else {
colour = prefs.get(AttributePreferenceKey.CUSTOM_ATTRIBUTE_COLOUR, CUSTOM_ATTRIBUTE_COLOUR);
}
attributePane.setStyle(JavafxStyleManager.CSS_BASE_STYLE_PREFIX + colour + SeparatorConstants.SEMICOLON);
} else if (hidden) {
final String hiddenColour = prefs.get(AttributePreferenceKey.HIDDEN_ATTRIBUTE_COLOUR, HIDDEN_ATTRIBUTE_COLOUR);
attributePane.setStyle(JavafxStyleManager.CSS_BASE_STYLE_PREFIX + hiddenColour + SeparatorConstants.SEMICOLON);
} else {
final String schemaColour = prefs.get(AttributePreferenceKey.SCHEMA_ATTRIBUTE_COLOUR, SCHEMA_ATTRIBUTE_COLOUR);
attributePane.setStyle(JavafxStyleManager.CSS_BASE_STYLE_PREFIX + schemaColour + SeparatorConstants.SEMICOLON);
}
if (!multiValue) {
attributePane.setCollapsible(false);
} else {
createMultiValuePane(attribute, attributePane, values);
}
final Text attributeTitleText = createAttributeTitleLabel(attributeTitle);
attributeTitleText.getStyleClass().add("attributeName");
attributeTitleText.setTextAlignment(TextAlignment.RIGHT);
// Value TextField
final Node attributeValueNode = createAttributeValueNode(values, attribute, attributePane, multiValue);
// Edit Button
final Button editButton = new Button("Edit");
editButton.setAlignment(Pos.CENTER);
editButton.setMinWidth(buttonSize);
final AttributeValueEditorFactory<?> editorFactory = AttributeValueEditorFactory.getEditFactory(attribute.getDataType());
if (editorFactory == null || values == null) {
editButton.setDisable(true);
} else {
editButton.setOnMouseClicked(event -> getEditValueHandler(attribute, editorFactory, values));
attributeValueNode.setOnMouseClicked(event -> {
if (event.getButton() == MouseButton.PRIMARY && event.isStillSincePress()) {
getEditValueHandler(attribute, editorFactory, values);
}
});
}
// If we don't do anything here, right-clicking on the Node will produce two context menus:
// the one the Node has by default, and the one we added to the AttributeTitledPane.
// We'll consume the context menu event so it doesn't bubble up to the TitledPane.
// Ditto for the button.
attributeValueNode.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, Event::consume);
editButton.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, Event::consume);
// Title
final ColumnConstraints titleConstraint = new ColumnConstraints(titleWidth);
titleConstraint.setHalignment(HPos.RIGHT);
// Value
final ColumnConstraints valueConstraint = new ColumnConstraints();
valueConstraint.setHalignment(HPos.CENTER);
valueConstraint.setHgrow(Priority.ALWAYS);
valueConstraint.setFillWidth(true);
// EditButton
final ColumnConstraints editConstraint = new ColumnConstraints(buttonSize);
editConstraint.setHalignment(HPos.RIGHT);
gridPane.getColumnConstraints().addAll(titleConstraint, valueConstraint, editConstraint);
gridPane.add(attributeTitleText, 0, 0);
gridPane.add(attributeValueNode, 1, 0);
gridPane.add(editButton, 2, 0);
attributePane.setAlignment(Pos.CENTER_RIGHT);
attributePane.setGraphic(gridPane);
attributePane.setTooltip(new Tooltip(attribute.getAttributeDescription()));
attributePane.setExpanded(attribute.isKeepExpanded());
attributePane.setOnDragDetected(event -> {
final Dragboard db = attributePane.startDragAndDrop(TransferMode.COPY);
final ClipboardContent content = new ClipboardContent();
final String data = String.format("%s:%s", attribute.getElementType().getShortLabel(), attribute.getAttributeName());
content.put(ATTRIBUTE_NAME_DATA_FORMAT, data);
content.putString(String.format("Attribute.Name=%s", data));
db.setContent(content);
event.consume();
});
return attributePane;
}
Aggregations