Search in sources :

Example 1 with SchemaConcept

use of au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept in project constellation by constellation-app.

the class AttributeNodeProvider method getSchemaInfo.

private List<AttributeEntry> getSchemaInfo(final Graph graph) {
    final List<AttributeEntry> attrs = new ArrayList<>();
    final Schema schema = graph.getSchema();
    final SchemaFactory factory = schema.getFactory();
    // Get the keys for each element type.
    final Map<GraphElementType, List<String>> elementKeys = new HashMap<>();
    for (final GraphElementType et : new GraphElementType[] { GraphElementType.VERTEX, GraphElementType.TRANSACTION }) {
        final List<SchemaAttribute> keys = factory.getKeyAttributes(et);
        final List<String> keyLabels = keys.stream().map(key -> key.getName()).collect(Collectors.toList());
        elementKeys.put(et, keyLabels);
    }
    for (final GraphElementType et : GraphElementType.values()) {
        final Map<String, SchemaAttribute> attrsMap = factory.getRegisteredAttributes(et);
        attrsMap.values().stream().forEach(schemaAttribute -> {
            final int keyIx = elementKeys.containsKey(schemaAttribute.getElementType()) ? elementKeys.get(schemaAttribute.getElementType()).indexOf(schemaAttribute.getName()) : -1;
            final Collection<SchemaConcept> concepts = SchemaConceptUtilities.getAttributeConcepts(schemaAttribute);
            final StringBuilder categories = new StringBuilder();
            for (SchemaConcept concept : concepts) {
                categories.append(concept.getName()).append(",");
            }
            if (categories.length() > 0) {
                categories.deleteCharAt(categories.length() - 1);
            }
            attrs.add(new AttributeEntry(schemaAttribute, categories.toString(), keyIx));
        });
    }
    return attrs;
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Pos(javafx.geometry.Pos) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) GraphManagerListener(au.gov.asd.tac.constellation.graph.manager.GraphManagerListener) VBox(javafx.scene.layout.VBox) SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Graph(au.gov.asd.tac.constellation.graph.Graph) Insets(javafx.geometry.Insets) Map(java.util.Map) ServiceProvider(org.openide.util.lookup.ServiceProvider) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) TableView(javafx.scene.control.TableView) UserInterfaceIconProvider(au.gov.asd.tac.constellation.utilities.icon.UserInterfaceIconProvider) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) SchemaConceptUtilities(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConceptUtilities) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Collection(java.util.Collection) StaticResource(org.netbeans.api.annotations.common.StaticResource) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) Priority(javafx.scene.layout.Priority) List(java.util.List) ToggleGroup(javafx.scene.control.ToggleGroup) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) RadioButton(javafx.scene.control.RadioButton) ImageView(javafx.scene.image.ImageView) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) ObservableList(javafx.collections.ObservableList) Image(javafx.scene.image.Image) HashMap(java.util.HashMap) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) ArrayList(java.util.ArrayList) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 2 with SchemaConcept

use of au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept in project constellation by constellation-app.

the class VertexTypeNodeProvider method newActiveGraph.

@Override
public void newActiveGraph(final Graph graph) {
    // TODO: if the old graph and the new graph have the same schema, don't recalculate.
    Platform.runLater(() -> {
        detailsView.getChildren().clear();
        final Label nameLabel = new Label("No type selected");
        detailsView.getChildren().add(nameLabel);
        vertexTypes.clear();
        if (graph != null && graph.getSchema() != null && GraphNode.getGraphNode(graph) != null) {
            final SchemaFactory schemaFactory = graph.getSchema().getFactory();
            final Set<Class<? extends SchemaConcept>> concepts = schemaFactory.getRegisteredConcepts();
            schemaLabel.setText(String.format("%s - %s", schemaFactory.getLabel(), GraphNode.getGraphNode(graph).getDisplayName()));
            vertexTypes.addAll(SchemaVertexTypeUtilities.getTypes(concepts));
            Collections.sort(vertexTypes, (final SchemaVertexType a, final SchemaVertexType b) -> a.getName().compareToIgnoreCase(b.getName()));
        } else {
            schemaLabel.setText("No schema available");
        }
        populateTree();
    });
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) Label(javafx.scene.control.Label) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)

Example 3 with SchemaConcept

use of au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept 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 4 with SchemaConcept

use of au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept 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 5 with SchemaConcept

use of au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept in project constellation by constellation-app.

the class TransactionTypeNodeProvider method newActiveGraph.

@Override
public void newActiveGraph(final Graph graph) {
    // TODO: if the old graph and the new graph have the same schema, don't recalculate.
    Platform.runLater(() -> {
        detailsView.getChildren().clear();
        final Label nameLabel = new Label("No type selected");
        detailsView.getChildren().add(nameLabel);
        transactionTypes.clear();
        if (graph != null && graph.getSchema() != null && GraphNode.getGraphNode(graph) != null) {
            final SchemaFactory schemaFactory = graph.getSchema().getFactory();
            final Set<Class<? extends SchemaConcept>> concepts = schemaFactory.getRegisteredConcepts();
            schemaLabel.setText(String.format("%s - %s", schemaFactory.getLabel(), GraphNode.getGraphNode(graph).getDisplayName()));
            transactionTypes.addAll(SchemaTransactionTypeUtilities.getTypes(concepts));
            Collections.sort(transactionTypes, (final SchemaTransactionType a, final SchemaTransactionType b) -> a.getName().compareToIgnoreCase(b.getName()));
        } else {
            schemaLabel.setText("No schema available");
        }
        populateTree();
    });
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) Label(javafx.scene.control.Label) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)

Aggregations

SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)7 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)4 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)4 SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)4 ArrayList (java.util.ArrayList)4 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)3 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)3 Label (javafx.scene.control.Label)3 Graph (au.gov.asd.tac.constellation.graph.Graph)2 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 SchemaAttribute (au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)2 Insets (javafx.geometry.Insets)2 ImageView (javafx.scene.image.ImageView)2 HBox (javafx.scene.layout.HBox)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)1 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)1 GraphManagerListener (au.gov.asd.tac.constellation.graph.manager.GraphManagerListener)1 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)1 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)1 SchemaConceptUtilities (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConceptUtilities)1