Search in sources :

Example 11 with SchemaAttribute

use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.

the class AttributeEditorPanel method createHeaderTitledPane.

private TitledPane createHeaderTitledPane(final HeadingType headingType, final StringProperty title, final VBox container) {
    final TitledPane result = new TitledPane();
    result.setContent(container);
    final BorderPane headerGraphic = new BorderPane();
    final HBox optionsButtons = new HBox(5);
    optionsButtons.setPadding(new Insets(2));
    final Text heading = new Text();
    heading.textProperty().bind(title);
    heading.setStyle("-fx-font-weight:bold;");
    heading.setFill(Color.web("#e0e0e0"));
    final ToggleButton showAllToggle = new ToggleButton("Show all");
    showAllToggle.setAlignment(Pos.CENTER);
    showAllToggle.setTextAlignment(TextAlignment.CENTER);
    showAllToggle.setStyle("-fx-background-insets: 0, 0; -fx-padding: 0");
    showAllToggle.setPrefSize(60, 12);
    showAllToggle.setPadding(new Insets(5));
    showAllToggle.setTooltip(new Tooltip("Show hidden attributes"));
    final String key;
    final GraphElementType elementType;
    switch(headingType) {
        case GRAPH:
            key = AttributePreferenceKey.GRAPH_SHOW_ALL;
            elementType = GraphElementType.GRAPH;
            break;
        case NODE:
            key = AttributePreferenceKey.NODE_SHOW_ALL;
            elementType = GraphElementType.VERTEX;
            break;
        case TRANSACTION:
            key = AttributePreferenceKey.TRANSACTION_SHOW_ALL;
            elementType = GraphElementType.TRANSACTION;
            break;
        default:
            key = "";
            elementType = null;
            break;
    }
    showAllToggle.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> prefs.putBoolean(key, newValue));
    showAllToggle.setSelected(prefs.getBoolean(key, false));
    final Button addMenu = new Button(null, new ImageView(UserInterfaceIconProvider.ADD.buildImage(16)));
    addMenu.setAlignment(Pos.CENTER);
    addMenu.setTextAlignment(TextAlignment.CENTER);
    addMenu.setStyle("-fx-background-color: #666666; -fx-background-radius: 2; -fx-background-insets: 0, 0; -fx-padding: 0");
    addMenu.setPrefSize(18, 12);
    addMenu.setPadding(new Insets(5));
    addMenu.setTooltip(new Tooltip("Add an attribute"));
    final ContextMenu addContextMenu = new ContextMenu();
    addMenu.setOnMouseClicked((final MouseEvent event) -> {
        event.consume();
        addContextMenu.getItems().clear();
        if (elementType != null) {
            final Graph currentGraph = GraphManager.getDefault().getActiveGraph();
            if (currentGraph != null) {
                final Map<String, Set<SchemaAttribute>> categoryAttributes = new TreeMap<>();
                final Set<SchemaAttribute> otherAttributes = new TreeSet<>();
                final ReadableGraph rg = currentGraph.getReadableGraph();
                try {
                    if (currentGraph.getSchema() != null) {
                        final SchemaFactory schemaFactory = currentGraph.getSchema().getFactory();
                        for (final SchemaAttribute attribute : schemaFactory.getRegisteredAttributes(elementType).values()) {
                            if (attribute.get(rg) == Graph.NOT_FOUND) {
                                final Collection<SchemaConcept> concepts = SchemaConceptUtilities.getAttributeConcepts(attribute);
                                if (CollectionUtils.isEmpty(concepts)) {
                                    otherAttributes.add(attribute);
                                } else {
                                    for (final SchemaConcept concept : concepts) {
                                        Set<SchemaAttribute> attributeNames = categoryAttributes.get(concept.getName());
                                        if (attributeNames == null) {
                                            attributeNames = new TreeSet<>();
                                            categoryAttributes.put(concept.getName(), attributeNames);
                                        }
                                        attributeNames.add(attribute);
                                    }
                                }
                            }
                        }
                    }
                } finally {
                    rg.release();
                }
                for (final Entry<String, Set<SchemaAttribute>> entry : categoryAttributes.entrySet()) {
                    final Menu submenu = new Menu(entry.getKey());
                    submenu.setStyle("-fx-text-fill: white;");
                    for (final SchemaAttribute attribute : entry.getValue()) {
                        final MenuItem item = new MenuItem(attribute.getName());
                        item.setOnAction((ActionEvent event1) -> PluginExecution.withPlugin(new AddAttributePlugin(attribute)).executeLater(currentGraph));
                        submenu.getItems().add(item);
                    }
                    addContextMenu.getItems().add(submenu);
                }
                if (!otherAttributes.isEmpty()) {
                    final Menu otherSubmenu = new Menu("Other");
                    for (final SchemaAttribute attribute : otherAttributes) {
                        final MenuItem item = new MenuItem(attribute.getName());
                        item.setOnAction((final ActionEvent event1) -> PluginExecution.withPlugin(new AddAttributePlugin(attribute)).executeLater(currentGraph));
                        otherSubmenu.getItems().add(item);
                    }
                    addContextMenu.getItems().add(otherSubmenu);
                }
                final MenuItem customAttribute = new MenuItem("Custom");
                customAttribute.setStyle("-fx-text-fill: white;");
                customAttribute.setOnAction(ev -> createAttributeAction(elementType));
                addContextMenu.getItems().add(customAttribute);
            }
        }
        addContextMenu.show(addMenu, event.getScreenX(), event.getScreenY());
    });
    final Button editKeyButton = new Button(null, new ImageView(UserInterfaceIconProvider.KEY.buildImage(16)));
    editKeyButton.setAlignment(Pos.CENTER);
    editKeyButton.setTextAlignment(TextAlignment.CENTER);
    editKeyButton.setStyle("-fx-background-color: #666666; -fx-background-radius: 2; -fx-background-insets: 0, 0; -fx-padding: 0");
    editKeyButton.setPrefSize(18, 12);
    editKeyButton.setPadding(new Insets(5));
    editKeyButton.setTooltip(new Tooltip("Edit primary key"));
    if (elementType != GraphElementType.GRAPH) {
        editKeyButton.setOnMouseClicked((MouseEvent event) -> {
            event.consume();
            editKeysAction(elementType);
        });
    } else {
        editKeyButton.setVisible(false);
    }
    optionsButtons.maxHeightProperty().bind(addMenu.heightProperty());
    optionsButtons.getChildren().addAll(showAllToggle, addMenu, editKeyButton);
    headerGraphic.setLeft(heading);
    headerGraphic.setRight(optionsButtons);
    headerGraphic.prefWidthProperty().bind(scrollPane.widthProperty().subtract(45));
    BorderPane.setMargin(heading, new Insets(2, 0, 0, 0));
    BorderPane.setMargin(optionsButtons, Insets.EMPTY);
    result.setGraphic(headerGraphic);
    result.setId("heading");
    result.setExpanded(false);
    return result;
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) BorderPane(javafx.scene.layout.BorderPane) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) ActionEvent(javafx.event.ActionEvent) ObservableValue(javafx.beans.value.ObservableValue) ContextMenu(javafx.scene.control.ContextMenu) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) MouseButton(javafx.scene.input.MouseButton) Button(javafx.scene.control.Button) ToggleButton(javafx.scene.control.ToggleButton) TreeSet(java.util.TreeSet) ImageView(javafx.scene.image.ImageView) Menu(javafx.scene.control.Menu) ContextMenu(javafx.scene.control.ContextMenu) TitledPane(javafx.scene.control.TitledPane) SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) ToggleButton(javafx.scene.control.ToggleButton) MouseEvent(javafx.scene.input.MouseEvent) Tooltip(javafx.scene.control.Tooltip) Text(javafx.scene.text.Text) CheckMenuItem(javafx.scene.control.CheckMenuItem) MenuItem(javafx.scene.control.MenuItem) TreeMap(java.util.TreeMap) Graph(au.gov.asd.tac.constellation.graph.Graph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 12 with SchemaAttribute

use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.

the class PrimaryKeyDefaultGetter method getDefaultValue.

@Override
public Object getDefaultValue() {
    final ReadableGraph rg = GraphManager.getDefault().getActiveGraph().getReadableGraph();
    List<SchemaAttribute> keys = new ArrayList<>();
    try {
        if (rg.getSchema() != null) {
            keys = rg.getSchema().getFactory().getKeyAttributes(elementType);
        }
    } finally {
        rg.release();
    }
    return keys.stream().map(s -> s.getName()).collect(Collectors.toList());
}
Also used : List(java.util.List) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Collectors(java.util.stream.Collectors) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) ArrayList(java.util.ArrayList) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ArrayList(java.util.ArrayList) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 13 with SchemaAttribute

use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.

the class SchemaFactory method ensureKeyAttributes.

/**
 * Set the vertex and transactions primary keys on a graph.
 *
 * @param graph The {@link GraphWriteMethods} that will have its primary
 * keys * set.
 */
public final void ensureKeyAttributes(final GraphWriteMethods graph) {
    for (final GraphElementType elementType : new GraphElementType[] { GraphElementType.VERTEX, GraphElementType.TRANSACTION }) {
        final List<SchemaAttribute> keys = getKeyAttributes(elementType);
        final int[] attrIds = new int[keys.size()];
        for (int i = 0; i < keys.size(); i++) {
            attrIds[i] = keys.get(i).ensure(graph);
        }
        graph.setPrimaryKey(elementType, attrIds);
    }
}
Also used : SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Example 14 with SchemaAttribute

use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.

the class SchemaFactory method ensureAttribute.

/**
 * Ensure that an {@link Attribute} is created on a graph. If the specified
 * attribute is registered to this SchemaFactory, the attribute will be
 * created on the specified graph and returned, otherwise the error value
 * {@link Graph#NOT_FOUND} will be returned.
 *
 * @param graph the {@link GraphWriteMethods} to add the attribute to.
 * @param schemaAttribute the {@link SchemaAttribute} to ensure
 * @param boundBySchema if true, and the specified attribute is not
 * registered to this {@link SchemaFactory}, then this method will return
 * {@link GraphConstants#NOT_FOUND}, otherwise the attribute will be created
 * regardless
 *
 * @return an int representing the ensured attribute.
 */
public final int ensureAttribute(final GraphWriteMethods graph, final SchemaAttribute schemaAttribute, final boolean boundBySchema) {
    int attribute = schemaAttribute.get(graph);
    if (attribute == Graph.NOT_FOUND) {
        final SchemaAttribute registeredAttribute = getRegisteredAttributes(schemaAttribute.getElementType()).get(schemaAttribute.getName());
        if (boundBySchema && registeredAttribute == null) {
            return Graph.NOT_FOUND;
        }
        attribute = graph.addAttribute(schemaAttribute.getElementType(), schemaAttribute.getAttributeType(), schemaAttribute.getName(), schemaAttribute.getDescription(), schemaAttribute.getDefault(), schemaAttribute.getAttributeMergerId());
        graph.setAttributeIndexType(attribute, schemaAttribute.getIndexType());
    }
    return attribute;
}
Also used : SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 15 with SchemaAttribute

use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.

the class VisualSchemaV4UpdateProvider method schemaUpdate.

@Override
protected void schemaUpdate(StoreGraph graph) {
    boolean updateVertexKeys = false;
    // update vertex identifier attribute
    if (VisualConcept.VertexAttribute.IDENTIFIER.get(graph) == Graph.NOT_FOUND) {
        updateVertexKeys = true;
    }
    // update vertex label attribute
    final int oldVertexLabelAttributeId = graph.getAttribute(GraphElementType.VERTEX, LABEL_ATTRIBUTE_NAME);
    if (oldVertexLabelAttributeId != GraphConstants.NOT_FOUND) {
        graph.setPrimaryKey(GraphElementType.VERTEX);
        final int newVertexLabelAttributeId = VisualConcept.VertexAttribute.LABEL.ensure(graph);
        final int vertexIdentiferAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
        for (int vertexPosition = 0; vertexPosition < graph.getVertexCount(); vertexPosition++) {
            final int vertexId = graph.getVertex(vertexPosition);
            final String labelValue = graph.getStringValue(oldVertexLabelAttributeId, vertexId);
            graph.setStringValue(newVertexLabelAttributeId, vertexId, labelValue);
            if (graph.getStringValue(vertexIdentiferAttributeId, vertexId) == null) {
                graph.setStringValue(vertexIdentiferAttributeId, vertexId, labelValue);
            }
        }
        graph.removeAttribute(oldVertexLabelAttributeId);
        updateVertexKeys = true;
    }
    // update vertex keys and complete vertices
    if (updateVertexKeys) {
        final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.VERTEX);
        final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
        graph.setPrimaryKey(GraphElementType.VERTEX, keyAttributeIds);
    }
    // update vertex labels
    final int vertexBottomLabelsAttributeId = VisualConcept.GraphAttribute.BOTTOM_LABELS.get(graph);
    if (vertexBottomLabelsAttributeId != GraphConstants.NOT_FOUND) {
        final GraphLabel label = new GraphLabel(VisualConcept.VertexAttribute.LABEL.getName(), graph.getSchema().getFactory().getVertexLabelColor());
        graph.setObjectValue(vertexBottomLabelsAttributeId, 0, new GraphLabels(Arrays.asList(label)));
    }
    boolean updateTransactionKeys = false;
    // update transaction identifier attribute
    if (VisualConcept.TransactionAttribute.IDENTIFIER.get(graph) == Graph.NOT_FOUND) {
        updateTransactionKeys = true;
    }
    final int oldTransactionUniqueIdAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, UNIQUE_ID_ATTRIBUTE_NAME);
    if (oldTransactionUniqueIdAttributeId != GraphConstants.NOT_FOUND) {
        graph.setPrimaryKey(GraphElementType.TRANSACTION);
        final int newTransactionIdentifierAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(graph);
        for (int transactionPosition = 0; transactionPosition < graph.getTransactionCount(); transactionPosition++) {
            final int transactionId = graph.getTransaction(transactionPosition);
            final String uniqueIdValue = graph.getStringValue(oldTransactionUniqueIdAttributeId, transactionId);
            graph.setStringValue(newTransactionIdentifierAttributeId, transactionId, uniqueIdValue);
        }
        graph.removeAttribute(oldTransactionUniqueIdAttributeId);
        updateTransactionKeys = true;
    }
    // update transaction label attribute
    final int oldTransactionLabelAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, LABEL_ATTRIBUTE_NAME);
    if (oldTransactionLabelAttributeId != GraphConstants.NOT_FOUND) {
        graph.setPrimaryKey(GraphElementType.TRANSACTION);
        final int newTransactionLabelAttributeId = VisualConcept.TransactionAttribute.LABEL.ensure(graph);
        final int transactionIdentiferAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(graph);
        for (int transactionPosition = 0; transactionPosition < graph.getTransactionCount(); transactionPosition++) {
            final int transactionId = graph.getTransaction(transactionPosition);
            final String labelValue = graph.getStringValue(oldTransactionLabelAttributeId, transactionId);
            graph.setStringValue(newTransactionLabelAttributeId, transactionId, labelValue);
            if (graph.getStringValue(transactionIdentiferAttributeId, transactionId) == null) {
                graph.setStringValue(transactionIdentiferAttributeId, transactionId, labelValue);
            }
        }
        graph.removeAttribute(oldTransactionLabelAttributeId);
        updateTransactionKeys = true;
    }
    // update transaction keys and complete transactions
    if (updateTransactionKeys) {
        final List<SchemaAttribute> keyAttributes = graph.getSchema().getFactory().getKeyAttributes(GraphElementType.TRANSACTION);
        final int[] keyAttributeIds = keyAttributes.stream().map(keyAttribute -> keyAttribute.ensure(graph)).mapToInt(keyAttributeId -> keyAttributeId).toArray();
        graph.setPrimaryKey(GraphElementType.TRANSACTION, keyAttributeIds);
    }
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) UpdateProvider(au.gov.asd.tac.constellation.graph.versioning.UpdateProvider) Arrays(java.util.Arrays) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) SchemaUpdateProvider(au.gov.asd.tac.constellation.graph.versioning.SchemaUpdateProvider) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) VisualSchemaFactory(au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaFactory) SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) GraphConstants(au.gov.asd.tac.constellation.graph.GraphConstants) Graph(au.gov.asd.tac.constellation.graph.Graph) List(java.util.List) SchemaFactoryUtilities(au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel) ServiceProvider(org.openide.util.lookup.ServiceProvider) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Aggregations

SchemaAttribute (au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)17 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)9 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)7 ArrayList (java.util.ArrayList)6 Graph (au.gov.asd.tac.constellation.graph.Graph)5 List (java.util.List)5 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)3 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)3 SchemaFactoryUtilities (au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities)3 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)3 Attribute (au.gov.asd.tac.constellation.graph.Attribute)2 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)2 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)2 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)2 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)2 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)2 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)2 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)2 VisualSchemaFactory (au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaFactory)2 SchemaUpdateProvider (au.gov.asd.tac.constellation.graph.versioning.SchemaUpdateProvider)2