Search in sources :

Example 1 with AttributeValueEditorFactory

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;
}
Also used : HPos(javafx.geometry.HPos) StackPane(javafx.scene.layout.StackPane) SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) ScrollPane(javafx.scene.control.ScrollPane) Map(java.util.Map) ZonedDateTimeAttributeDescription(au.gov.asd.tac.constellation.graph.attribute.ZonedDateTimeAttributeDescription) ZoneOffset(java.time.ZoneOffset) ValueValidator(au.gov.asd.tac.constellation.graph.attribute.interaction.ValueValidator) UserInterfaceIconProvider(au.gov.asd.tac.constellation.utilities.icon.UserInterfaceIconProvider) EditOperation(au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.EditOperation) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) Event(javafx.event.Event) Set(java.util.Set) Rectangle(javafx.scene.shape.Rectangle) KeyEvent(javafx.scene.input.KeyEvent) ZoneId(java.time.ZoneId) Platform(javafx.application.Platform) PluginInfo(au.gov.asd.tac.constellation.plugins.PluginInfo) AbstractEditorFactory(au.gov.asd.tac.constellation.views.attributeeditor.editors.AbstractEditorFactory) ModifyAttributeEditOperation(au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.ModifyAttributeEditOperation) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) AttributeValueTranslator(au.gov.asd.tac.constellation.graph.attribute.interaction.AttributeValueTranslator) StringProperty(javafx.beans.property.StringProperty) NbPreferences(org.openide.util.NbPreferences) CreateAttributeEditOperation(au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.CreateAttributeEditOperation) GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) MouseButton(javafx.scene.input.MouseButton) AttributeValueEditOperation(au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.AttributeValueEditOperation) ColumnConstraints(javafx.scene.layout.ColumnConstraints) ColorAttributeDescription(au.gov.asd.tac.constellation.graph.schema.visual.attribute.ColorAttributeDescription) AttributeValueEditorFactory(au.gov.asd.tac.constellation.views.attributeeditor.editors.AttributeValueEditorFactory) FXCollections(javafx.collections.FXCollections) TooltipPane(au.gov.asd.tac.constellation.utilities.tooltip.TooltipPane) TreeSet(java.util.TreeSet) TransferMode(javafx.scene.input.TransferMode) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Graph(au.gov.asd.tac.constellation.graph.Graph) Dragboard(javafx.scene.input.Dragboard) DefaultGetter(au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.DefaultGetter) PluginTags(au.gov.asd.tac.constellation.plugins.templates.PluginTags) TextAlignment(javafx.scene.text.TextAlignment) StringUtilities(au.gov.asd.tac.constellation.utilities.text.StringUtilities) GridPane(javafx.scene.layout.GridPane) Color(javafx.scene.paint.Color) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) TitledPane(javafx.scene.control.TitledPane) ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) Node(javafx.scene.Node) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Preferences(java.util.prefs.Preferences) Menu(javafx.scene.control.Menu) ContextMenuEvent(javafx.scene.input.ContextMenuEvent) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) SelectionMode(javafx.scene.control.SelectionMode) TreeMap(java.util.TreeMap) ImageView(javafx.scene.image.ImageView) ObservableValue(javafx.beans.value.ObservableValue) Button(javafx.scene.control.Button) TimeZoneEditorFactory(au.gov.asd.tac.constellation.views.attributeeditor.editors.TimeZoneEditorFactory) Pos(javafx.geometry.Pos) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ListCell(javafx.scene.control.ListCell) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) CheckMenuItem(javafx.scene.control.CheckMenuItem) PluginType(au.gov.asd.tac.constellation.plugins.PluginType) VBox(javafx.scene.layout.VBox) PrimaryKeyEditOperation(au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.PrimaryKeyEditOperation) KeyCombination(javafx.scene.input.KeyCombination) ContextMenu(javafx.scene.control.ContextMenu) AbstractAttributeInteraction(au.gov.asd.tac.constellation.graph.attribute.interaction.AbstractAttributeInteraction) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) MenuItem(javafx.scene.control.MenuItem) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) TimeZone(java.util.TimeZone) Collection(java.util.Collection) Text(javafx.scene.text.Text) Priority(javafx.scene.layout.Priority) List(java.util.List) ToggleButton(javafx.scene.control.ToggleButton) DataFormat(javafx.scene.input.DataFormat) Entry(java.util.Map.Entry) ClipboardContent(javafx.scene.input.ClipboardContent) JavafxStyleManager(au.gov.asd.tac.constellation.utilities.javafx.JavafxStyleManager) ListSelectionEditor(au.gov.asd.tac.constellation.views.attributeeditor.editors.ListSelectionEditorFactory.ListSelectionEditor) UpdateTimeZonePlugin(au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.UpdateTimeZonePlugin) ListView(javafx.scene.control.ListView) AttributeEditor(au.gov.asd.tac.constellation.views.attributeeditor.editors.AttributeEditorFactory.AttributeEditor) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) MouseEvent(javafx.scene.input.MouseEvent) HashMap(java.util.HashMap) ClipboardUtilities(au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.ClipboardUtilities) HashSet(java.util.HashSet) FontUtilities(au.gov.asd.tac.constellation.utilities.font.FontUtilities) Insets(javafx.geometry.Insets) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) Tooltip(javafx.scene.control.Tooltip) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) SchemaConceptUtilities(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConceptUtilities) KeyCode(javafx.scene.input.KeyCode) PrimaryKeyDefaultGetter(au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.PrimaryKeyDefaultGetter) MenuBar(javafx.scene.control.MenuBar) AbstractEditor(au.gov.asd.tac.constellation.views.attributeeditor.editors.AbstractEditorFactory.AbstractEditor) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) AttributeEditorFactory(au.gov.asd.tac.constellation.views.attributeeditor.editors.AttributeEditorFactory) ListSelectionEditorFactory(au.gov.asd.tac.constellation.views.attributeeditor.editors.ListSelectionEditorFactory) ActionEvent(javafx.event.ActionEvent) Collections(java.util.Collections) ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) GridPane(javafx.scene.layout.GridPane) ColumnConstraints(javafx.scene.layout.ColumnConstraints) ClipboardContent(javafx.scene.input.ClipboardContent) Node(javafx.scene.Node) Tooltip(javafx.scene.control.Tooltip) Text(javafx.scene.text.Text) MouseButton(javafx.scene.input.MouseButton) Button(javafx.scene.control.Button) ToggleButton(javafx.scene.control.ToggleButton) Event(javafx.event.Event) KeyEvent(javafx.scene.input.KeyEvent) ContextMenuEvent(javafx.scene.input.ContextMenuEvent) MouseEvent(javafx.scene.input.MouseEvent) ActionEvent(javafx.event.ActionEvent) Dragboard(javafx.scene.input.Dragboard)

Aggregations

Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)1 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 ZonedDateTimeAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.ZonedDateTimeAttributeDescription)1 AbstractAttributeInteraction (au.gov.asd.tac.constellation.graph.attribute.interaction.AbstractAttributeInteraction)1 AttributeValueTranslator (au.gov.asd.tac.constellation.graph.attribute.interaction.AttributeValueTranslator)1 ValueValidator (au.gov.asd.tac.constellation.graph.attribute.interaction.ValueValidator)1 ClipboardUtilities (au.gov.asd.tac.constellation.graph.interaction.plugins.clipboard.ClipboardUtilities)1 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)1 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)1 SchemaAttribute (au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)1 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)1 SchemaConceptUtilities (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConceptUtilities)1 ColorAttributeDescription (au.gov.asd.tac.constellation.graph.schema.visual.attribute.ColorAttributeDescription)1 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)1 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)1 PluginInfo (au.gov.asd.tac.constellation.plugins.PluginInfo)1 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)1 PluginType (au.gov.asd.tac.constellation.plugins.PluginType)1