Search in sources :

Example 11 with SchemaTransactionType

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

the class TransactionTypeNodeProvider method setContent.

@Override
public void setContent(final Tab tab) {
    GraphManager.getDefault().addGraphManagerListener(this);
    final VBox filterBox = addFilter();
    treeView.setShowRoot(false);
    treeView.getSelectionModel().selectedItemProperty().addListener(event -> {
        detailsView.getChildren().clear();
        // Display the relevant fg and colored bg icons.
        final TreeItem<SchemaTransactionType> item = treeView.getSelectionModel().getSelectedItem();
        if (item != null) {
            final SchemaTransactionType transactionType = item.getValue();
            final Rectangle colorRectangle = getSquare(transactionType.getColor().getJavaFXColor());
            final GridPane grid = new GridPane();
            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);
            Label nameLabel = new Label(transactionType.getName());
            nameLabel.setWrapText(true);
            grid.add(boldLabel("Name:"), 0, 0);
            grid.add(nameLabel, 1, 0);
            Label descriptionLabel = new Label(transactionType.getDescription());
            descriptionLabel.setWrapText(true);
            grid.add(boldLabel("Description:"), 0, 1);
            grid.add(descriptionLabel, 1, 1);
            Label colorLabel = new Label(transactionType.getColor().toString());
            colorLabel.setWrapText(true);
            grid.add(boldLabel("Color:"), 0, 2);
            grid.add(colorLabel, 1, 2);
            Label styleLabel = new Label(transactionType.getStyle().toString());
            styleLabel.setWrapText(true);
            grid.add(boldLabel("Style:"), 0, 3);
            grid.add(styleLabel, 1, 3);
            Label directedLabel = new Label(transactionType.isDirected().toString());
            directedLabel.setWrapText(true);
            grid.add(boldLabel("Directed:"), 0, 4);
            grid.add(directedLabel, 1, 4);
            Label hierarchyLabel = new Label(transactionType.getHierachy());
            hierarchyLabel.setWrapText(true);
            grid.add(boldLabel("Hierarchy:"), 0, 5);
            grid.add(hierarchyLabel, 1, 5);
            int gridPosition = 5;
            for (String property : transactionType.getProperties().keySet()) {
                final Object propertyValue = transactionType.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(colorRectangle, 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 : GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) ColumnConstraints(javafx.scene.layout.ColumnConstraints) Node(javafx.scene.Node) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) Rectangle(javafx.scene.shape.Rectangle) Label(javafx.scene.control.Label) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) VBox(javafx.scene.layout.VBox) StackPane(javafx.scene.layout.StackPane)

Example 12 with SchemaTransactionType

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

the class TransactionTypeNodeProvider method createNode.

/**
 * Recursively create a tree of vertex types.
 * <p>
 * getSuperType() points to the parent. If getSuperType() points to itself,
 * the vertex type is a root.
 *
 * @param txtype
 * @return
 */
private TreeItem<SchemaTransactionType> createNode(final SchemaTransactionType txtype) {
    final TreeItem<SchemaTransactionType> ti = new TreeItem<SchemaTransactionType>(txtype) {

        // We cache whether the vertextype is a leaf or not.
        private boolean isLeaf;

        // We do the children and leaf testing only once, and then set these
        // booleans to false so that we do not check again during this
        // run.
        private boolean isFirstTimeChildren = true;

        private boolean isFirstTimeLeaf = true;

        @Override
        public ObservableList<TreeItem<SchemaTransactionType>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this));
            }
            return super.getChildren();
        }

        /**
         * A vertextype is not a leaf if another vertextype refers to it as
         * a supertype.
         *
         * @return
         */
        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                isLeaf = false;
                if (getValue() != null) {
                    final boolean foundChild = transactionTypes.stream().anyMatch(transactionType -> transactionType.getSuperType() == getValue() && transactionType != getValue());
                    isLeaf = !foundChild;
                }
            }
            return isLeaf;
        }

        private ObservableList<TreeItem<SchemaTransactionType>> buildChildren(final TreeItem<SchemaTransactionType> item) {
            final SchemaTransactionType value = item.getValue();
            final ObservableList<TreeItem<SchemaTransactionType>> children = FXCollections.observableArrayList();
            if (value == null) {
                // Any vertextype that points to itself is in the root layer.
                for (final SchemaTransactionType transactionType : transactionTypes) {
                    if ((transactionType.getSuperType() == transactionType) && (isFilterMatchCurrentNode(transactionType) || filterText.getText().isEmpty())) {
                        children.add(createNode(transactionType));
                    }
                }
            } else {
                for (final SchemaTransactionType transactionType : transactionTypes) {
                    if ((transactionType.getSuperType() == value && transactionType != value) && (isFilterMatchCurrentNode(transactionType) || filterText.getText().isEmpty())) {
                        children.add(createNode(transactionType));
                    }
                }
            }
            return children;
        }
    };
    if (txtype != null) {
        ti.setGraphic(getSquare(txtype.getColor().getJavaFXColor()));
    }
    return ti;
}
Also used : SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) TreeItem(javafx.scene.control.TreeItem)

Example 13 with SchemaTransactionType

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

the class CompleteGraphBuilderPlugin 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 14 with SchemaTransactionType

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

the class GetTypeDescription method callService.

@Override
public void callService(final PluginParameters parameters, final InputStream in, final OutputStream out) throws IOException {
    final String typeName = parameters.getStringValue(TYPE_PARAMETER_ID);
    if (!SchemaVertexTypeUtilities.getDefaultType().equals(SchemaVertexTypeUtilities.getType(typeName))) {
        final SchemaVertexType vertexType = SchemaVertexTypeUtilities.getType(typeName);
        final ObjectMapper mapper = new ObjectMapper();
        final ObjectNode root = mapper.createObjectNode();
        root.put("name", vertexType.getName());
        if (vertexType.getDescription() != null) {
            root.put("description", vertexType.getDescription());
        }
        if (vertexType.getColor() != null) {
            root.put("color", vertexType.getColor().toString());
        }
        if (vertexType.getForegroundIcon() != null) {
            root.put("foregroundIcon", vertexType.getForegroundIcon().toString());
        }
        if (vertexType.getBackgroundIcon() != null) {
            root.put("backgroundIcon", vertexType.getBackgroundIcon().toString());
        }
        if (vertexType.getDetectionRegex() != null) {
            root.put("detectionRegex", vertexType.getDetectionRegex().pattern());
        }
        if (vertexType.getValidationRegex() != null) {
            root.put("validationRegex", vertexType.getValidationRegex().pattern());
        }
        root.put("properties", vertexType.getProperties().toString());
        root.put("super_type", vertexType.getSuperType().getName());
        root.put("top_level_type", vertexType.getTopLevelType().getName());
        root.put("hierarchy", vertexType.getHierachy());
        mapper.writeValue(out, root);
    } else if (!SchemaTransactionTypeUtilities.getDefaultType().equals(SchemaTransactionTypeUtilities.getType(typeName))) {
        final SchemaTransactionType transactionType = SchemaTransactionTypeUtilities.getType(typeName);
        final ObjectMapper mapper = new ObjectMapper();
        final ObjectNode root = mapper.createObjectNode();
        root.put("name", transactionType.getName());
        if (transactionType.getDescription() != null) {
            root.put("description", transactionType.getDescription());
        }
        if (transactionType.getColor() != null) {
            root.put("color", transactionType.getColor().toString());
        }
        if (transactionType.getStyle() != null) {
            root.put("style", transactionType.getStyle().toString());
        }
        if (transactionType.isDirected() != null) {
            root.put("directed", transactionType.isDirected().toString());
        }
        root.put("properties", transactionType.getProperties().toString());
        root.put("super_type", transactionType.getSuperType().getName());
        root.put("top_level_type", transactionType.getTopLevelType().getName());
        root.put("hierarchy", transactionType.getHierachy());
        mapper.writeValue(out, root);
    } else {
        throw new IllegalArgumentException(String.format("The type '%s' is unknown.", typeName));
    }
}
Also used : SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 15 with SchemaTransactionType

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

the class CreateTransactionTypePlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
    final String name = parameters.getStringValue(NAME_PARAMETER_ID);
    if (name == null) {
        throw new IllegalArgumentException("A name must be supplied");
    }
    final String description = parameters.getStringValue(DESCRIPTION_PARAMETER_ID);
    if (description == null) {
        throw new IllegalArgumentException("A description must be supplied");
    }
    final ConstellationColor color = parameters.getColorValue(COLOR_PARAMETER_ID);
    final String lsName = parameters.getStringValue(LINE_STYLE_PARAMETER_ID);
    final LineStyle lineStyle = LineStyle.valueOf(lsName);
    final boolean directed = parameters.getBooleanValue(DIRECTED_PARAMETER_ID);
    final String stype = parameters.getStringValue(SUPER_TYPE_PARAMETER_ID);
    final SchemaTransactionType superType = stype != null ? SchemaTransactionTypeUtilities.getType(stype) : null;
    final String otype = parameters.getStringValue(OVERRIDDEN_TYPE_PARAMETER_ID);
    final SchemaTransactionType overridenType = otype != null ? SchemaTransactionTypeUtilities.getType(otype) : null;
    final boolean incomplete = parameters.getBooleanValue(INCOMPLETE_PARAMETER_ID);
    final Map<String, String> properties = null;
    final SchemaTransactionType stt = new SchemaTransactionType(name, description, color, lineStyle, directed, superType, overridenType, properties, incomplete);
    SchemaTransactionTypeUtilities.addCustomType(stt, true);
}
Also used : ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) LineStyle(au.gov.asd.tac.constellation.utilities.visual.LineStyle)

Aggregations

SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)29 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)11 ArrayList (java.util.ArrayList)11 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)10 SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)8 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)7 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)5 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)4 Map (java.util.Map)4 RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)3 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)3 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)3 SchemaVertexTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities)3 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)3 SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)3 List (java.util.List)3 Graph (au.gov.asd.tac.constellation.graph.Graph)2 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)2