Search in sources :

Example 26 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class VertexTypeNodeProvider method setContent.

@Override
public void setContent(final Tab tab) {
    GraphManager.getDefault().addGraphManagerListener(this);
    final VBox filterBox = addFilter();
    treeView.setShowRoot(false);
    treeView.setOnDragDetected(event -> {
        final Dragboard db = treeView.startDragAndDrop(TransferMode.COPY);
        final ClipboardContent content = new ClipboardContent();
        final TreeItem<SchemaVertexType> selectedItem = treeView.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            final SchemaVertexType vxtype = selectedItem.getValue();
            final String value = String.format("Type:%s", vxtype.getName());
            content.put(VERTEX_DATA_FORMAT, value);
            content.putString(String.format("%s=%s", SchemaVertexType.class.getSimpleName(), value));
        } else {
            content.putString("");
        }
        db.setContent(content);
        event.consume();
    });
    treeView.getSelectionModel().selectedItemProperty().addListener(event -> {
        detailsView.getChildren().clear();
        // Display the relevant fg and colored bg icons.
        final TreeItem<SchemaVertexType> item = treeView.getSelectionModel().getSelectedItem();
        if (item != null) {
            final SchemaVertexType vertexType = item.getValue();
            final Color color = vertexType.getColor().getJavaFXColor();
            // Background icon, sized, clipped, colored.
            final ImageView bg = new ImageView(backgroundIcons.get(vertexType));
            bg.setFitWidth(LARGE_ICON_IMAGE_SIZE);
            bg.setPreserveRatio(true);
            bg.setSmooth(true);
            final ImageView clip = new ImageView(bg.getImage());
            clip.setFitWidth(LARGE_ICON_IMAGE_SIZE);
            clip.setPreserveRatio(true);
            clip.setSmooth(true);
            bg.setClip(clip);
            final ColorAdjust adjust = new ColorAdjust();
            adjust.setSaturation(-1);
            final ColorInput ci = new ColorInput(0, 0, LARGE_ICON_IMAGE_SIZE, LARGE_ICON_IMAGE_SIZE, color);
            final Blend blend = new Blend(BlendMode.MULTIPLY, adjust, ci);
            bg.setEffect(blend);
            // Foreground icon, sized.
            final ImageView fg = new ImageView(foregroundIcons.get(vertexType));
            fg.setFitWidth(LARGE_ICON_IMAGE_SIZE);
            fg.setPreserveRatio(true);
            fg.setSmooth(true);
            // Combine foreground and background icons.
            final Group iconGroup = new Group(bg, fg);
            final GridPane grid = new GridPane();
            grid.setMaxWidth(detailsView.widthProperty().doubleValue());
            grid.setPadding(new Insets(0, 0, 0, 5));
            grid.setHgap(2);
            final ColumnConstraints col0 = new ColumnConstraints();
            col0.setHgrow(Priority.ALWAYS);
            final ColumnConstraints col1 = new ColumnConstraints();
            col1.setPercentWidth(75);
            grid.getColumnConstraints().addAll(col0, col1);
            final Label nameLabel = new Label(vertexType.getName());
            nameLabel.setWrapText(true);
            grid.add(boldLabel("Name:"), 0, 0);
            grid.add(nameLabel, 1, 0);
            final Label descriptionLabel = new Label(vertexType.getDescription());
            descriptionLabel.setWrapText(true);
            grid.add(boldLabel("Description:"), 0, 1);
            grid.add(descriptionLabel, 1, 1);
            final Label colorLabel = new Label(vertexType.getColor().toString());
            colorLabel.setWrapText(true);
            grid.add(boldLabel("Color:"), 0, 2);
            grid.add(colorLabel, 1, 2);
            final Label foregroundIconLabel = new Label(vertexType.getForegroundIcon().getName());
            foregroundIconLabel.setWrapText(true);
            grid.add(boldLabel("Foreground Icon:"), 0, 3);
            grid.add(foregroundIconLabel, 1, 3);
            final Label backgroundIconLabel = new Label(vertexType.getBackgroundIcon().getName());
            backgroundIconLabel.setWrapText(true);
            grid.add(boldLabel("Background Icon:"), 0, 4);
            grid.add(backgroundIconLabel, 1, 4);
            if (vertexType.getValidationRegex() != null) {
                final Label validationLabel = new Label(vertexType.getValidationRegex().toString());
                validationLabel.setWrapText(true);
                grid.add(boldLabel("Validation Regex:"), 0, 5);
                grid.add(validationLabel, 1, 5);
            }
            if (vertexType.getDetectionRegex() != null) {
                final Label detectionLabel = new Label(vertexType.getDetectionRegex().toString());
                detectionLabel.setWrapText(true);
                grid.add(boldLabel("Detection Regex:"), 0, 6);
                grid.add(detectionLabel, 1, 6);
            }
            final Label hierarchyLabel = new Label(vertexType.getHierachy());
            hierarchyLabel.setWrapText(true);
            grid.add(boldLabel("Hierarchy:"), 0, 7);
            grid.add(hierarchyLabel, 1, 7);
            int gridPosition = 7;
            for (String property : vertexType.getProperties().keySet()) {
                final Object propertyValue = vertexType.getProperty(property);
                if (propertyValue != null) {
                    gridPosition++;
                    Label propertyLabel = new Label(propertyValue.toString());
                    propertyLabel.setWrapText(true);
                    grid.add(boldLabel(property + SeparatorConstants.COLON), 0, gridPosition);
                    grid.add(propertyLabel, 1, gridPosition);
                }
            }
            for (final Node child : grid.getChildren()) {
                final Integer column = GridPane.getColumnIndex(child);
                final Integer row = GridPane.getRowIndex(child);
                if ((column > 0 && row != null && child instanceof Label) && (isFilterMatchText(((Label) child).getText()))) {
                    child.getStyleClass().add("schemaview-highlight-blue");
                }
            }
            detailsView.getChildren().addAll(iconGroup, grid);
        }
    });
    final VBox contentBox = new VBox(schemaLabel, filterBox, treeView, detailsView);
    VBox.setVgrow(treeView, Priority.ALWAYS);
    detailsView.prefHeightProperty().bind(contentBox.heightProperty().multiply(0.4));
    final StackPane contentNode = new StackPane(contentBox);
    newActiveGraph(GraphManager.getDefault().getActiveGraph());
    Platform.runLater(() -> tab.setContent(contentNode));
}
Also used : Group(javafx.scene.Group) ToggleGroup(javafx.scene.control.ToggleGroup) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Blend(javafx.scene.effect.Blend) ClipboardContent(javafx.scene.input.ClipboardContent) ColumnConstraints(javafx.scene.layout.ColumnConstraints) Color(javafx.scene.paint.Color) Node(javafx.scene.Node) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) Label(javafx.scene.control.Label) ColorAdjust(javafx.scene.effect.ColorAdjust) ImageView(javafx.scene.image.ImageView) VBox(javafx.scene.layout.VBox) Dragboard(javafx.scene.input.Dragboard) StackPane(javafx.scene.layout.StackPane) ColorInput(javafx.scene.effect.ColorInput)

Example 27 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class IdentifierInconsistentWithTypeRuleNGTest method testExecuteRuleInValidIdentifierAndUnknownType.

/**
 * Test of executeRule method, of class IdentifierInconsistentWithTypeRule.
 *
 * Return false when the identifier is valid and type is Unknown
 */
@Test
public void testExecuteRuleInValidIdentifierAndUnknownType() {
    final StoreGraph graph = new StoreGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    final int vx0 = graph.addVertex();
    final String identifierName = "A";
    // Set identifer and verify correct setup
    final int identifierAttr = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
    graph.setStringValue(identifierAttr, vx0, identifierName);
    assertEquals(graph.getObjectValue(identifierAttr, vx0), identifierName);
    final SchemaVertexType type = SchemaVertexType.unknownType();
    // Ensure there is a type attribute on the graph and check its value
    final int typeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
    graph.setObjectValue(typeAttr, vx0, type);
    assertEquals(graph.getObjectValue(typeAttr, vx0), type);
    // Running rule on vertex
    final IdentifierInconsistentWithTypeRule instance = new IdentifierInconsistentWithTypeRule();
    final boolean expResult = false;
    final boolean result = instance.executeRule(graph, vx0);
    assertEquals(result, expResult);
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 28 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class IdentifierInconsistentWithTypeRuleNGTest method testExecuteRuleInValidIdentifierAndValidType.

/**
 * Test of executeRule method, of class IdentifierInconsistentWithTypeRule.
 *
 * Return true when the identifier and type doesn't match
 */
@Test
public void testExecuteRuleInValidIdentifierAndValidType() {
    final StoreGraph graph = new StoreGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
    final int vx0 = graph.addVertex();
    final String identifierName = "A";
    // Set identifer and verify correct setup
    final int identifierAttr = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
    graph.setStringValue(identifierAttr, vx0, identifierName);
    assertEquals(graph.getObjectValue(identifierAttr, vx0), identifierName);
    final SchemaVertexType type = AnalyticConcept.VertexType.COUNTRY;
    // Ensure there is a type attribute on the graph and check its value
    final int typeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
    graph.setObjectValue(typeAttr, vx0, type);
    assertEquals(graph.getObjectValue(typeAttr, vx0), type);
    // Running rule on vertex
    final IdentifierInconsistentWithTypeRule instance = new IdentifierInconsistentWithTypeRule();
    final boolean expResult = true;
    final boolean result = instance.executeRule(graph, vx0);
    assertEquals(result, expResult);
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 29 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class SmallWorldGraphBuilderPlugin method updateParameters.

@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
    final List<String> nAttributes = new ArrayList<>();
    final List<String> tAttributes = new ArrayList<>();
    final List<String> nChoices = new ArrayList<>();
    final List<String> tChoices = new ArrayList<>();
    if (graph != null) {
        final Set<Class<? extends SchemaConcept>> concepts = graph.getSchema().getFactory().getRegisteredConcepts();
        final Collection<SchemaVertexType> nodeTypes = SchemaVertexTypeUtilities.getTypes(concepts);
        for (final SchemaVertexType type : nodeTypes) {
            nAttributes.add(type.getName());
        }
        nAttributes.sort(String::compareTo);
        final Collection<SchemaTransactionType> transactionTypes = SchemaTransactionTypeUtilities.getTypes(concepts);
        for (final SchemaTransactionType type : transactionTypes) {
            tAttributes.add(type.getName());
        }
        tAttributes.sort(String::compareTo);
        nChoices.add(nAttributes.get(0));
        tChoices.add(tAttributes.get(0));
    }
    if (parameters != null && parameters.getParameters() != null) {
        // NODE_TYPES_PARAMETER will always be of type MultiChoiceParameter
        @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> nAttribute = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(NODE_TYPES_PARAMETER_ID);
        // TRANSACTION_TYPES_PARAMETER will always be of type MultiChoiceParameter
        @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> tAttribute = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
        MultiChoiceParameterType.setOptions(nAttribute, nAttributes);
        MultiChoiceParameterType.setOptions(tAttribute, tAttributes);
        MultiChoiceParameterType.setChoices(nAttribute, nChoices);
        MultiChoiceParameterType.setChoices(tAttribute, tChoices);
    }
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)

Example 30 with SchemaVertexType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.

the class PreferentialAttachmentGraphBuilderPlugin method updateParameters.

@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
    final List<String> nAttributes = new ArrayList<>();
    final List<String> tAttributes = new ArrayList<>();
    final List<String> nChoices = new ArrayList<>();
    final List<String> tChoices = new ArrayList<>();
    if (graph != null) {
        final Set<Class<? extends SchemaConcept>> concepts = graph.getSchema().getFactory().getRegisteredConcepts();
        final Collection<SchemaVertexType> nodeTypes = SchemaVertexTypeUtilities.getTypes(concepts);
        for (final SchemaVertexType type : nodeTypes) {
            nAttributes.add(type.getName());
        }
        nAttributes.sort(String::compareTo);
        final Collection<SchemaTransactionType> transactionTypes = SchemaTransactionTypeUtilities.getTypes(concepts);
        for (final SchemaTransactionType type : transactionTypes) {
            tAttributes.add(type.getName());
        }
        tAttributes.sort(String::compareTo);
        nChoices.add(nAttributes.get(0));
        tChoices.add(tAttributes.get(0));
    }
    if (parameters != null && parameters.getParameters() != null) {
        // NODE_TYPES_PARAMETER will always be of type MultiChoiceParameter
        @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> nAttribute = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(NODE_TYPES_PARAMETER_ID);
        // TRANSACTION_TYPES_PARAMETER will always be of type MultiChoiceParameter
        @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> tAttribute = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
        MultiChoiceParameterType.setOptions(nAttribute, nAttributes);
        MultiChoiceParameterType.setOptions(tAttribute, tAttributes);
        MultiChoiceParameterType.setChoices(nAttribute, nChoices);
        MultiChoiceParameterType.setChoices(tAttribute, tChoices);
    }
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)

Aggregations

SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)30 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)9 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)8 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)6 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)6 Map (java.util.Map)6 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)5 SchemaVertexTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities)5 List (java.util.List)5 Test (org.testng.annotations.Test)5 Graph (au.gov.asd.tac.constellation.graph.Graph)4 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)4 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)4 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)4 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)3 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)3 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)3 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)3