Search in sources :

Example 1 with SchemaFactory

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

the class AttributeUtilities method getDateTimeAttributes.

/**
 * Return the date time attributes for a {@link GraphElementType} used by a
 * graph
 *
 * @param graph The graph
 * @param graphElementType The element type
 * @return Set of date time attributes used on a given graph
 */
public static Set<String> getDateTimeAttributes(final Graph graph, final GraphElementType graphElementType) {
    final Set<String> datetimeAttributes = new TreeSet<>();
    if (graph != null && graph.getSchema() != null) {
        final SchemaFactory factory = graph.getSchema().getFactory();
        final Map<String, SchemaAttribute> attributesMap = factory.getRegisteredAttributes(graphElementType);
        attributesMap.values().stream().forEach((SchemaAttribute schemaAttribute) -> {
            if (schemaAttribute.getAttributeType().equals(ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME)) {
                datetimeAttributes.add(schemaAttribute.getName());
            }
        });
    }
    return datetimeAttributes;
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) TreeSet(java.util.TreeSet) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 2 with SchemaFactory

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

the class AttributeUtilities method getRegisteredAttributeIdsFromGraph.

/**
 * Return the attribute id's for a {@link GraphElementType} used by a graph
 *
 * @param graph The graph
 * @param graphElementType The element type
 * @return Set of attribute id's being used on a given graph
 */
public static Map<String, Integer> getRegisteredAttributeIdsFromGraph(final GraphReadMethods graph, final GraphElementType graphElementType) {
    final Map<String, Integer> attributeIds = new TreeMap<>();
    final Schema schema = graph.getSchema();
    if (schema != null) {
        final SchemaFactory factory = schema.getFactory();
        final Map<String, SchemaAttribute> attrsMap = factory.getRegisteredAttributes(graphElementType);
        attrsMap.values().stream().forEach(schemaAttribute -> {
            final int attributeId = graph.getAttribute(graphElementType, schemaAttribute.getName());
            if (attributeId != Graph.NOT_FOUND) {
                attributeIds.put(schemaAttribute.getName(), attributeId);
            }
        });
    }
    return attributeIds;
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) TreeMap(java.util.TreeMap) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 3 with SchemaFactory

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

the class NewSchemaGraphAction method getMenuPresenters.

@Override
public JComponent[] getMenuPresenters() {
    menu = new JMenu("New Graph");
    for (final SchemaFactory schemaFactory : SchemaFactoryUtilities.getSchemaFactories().values()) {
        if (isValid(schemaFactory)) {
            if (!ICON_CACHE.containsKey(schemaFactory.getName())) {
                ICON_CACHE.put(schemaFactory.getName(), schemaFactory.getIcon().buildIcon(16));
            }
            final JMenuItem item = new JMenuItem(schemaFactory.getLabel(), ICON_CACHE.get(schemaFactory.getName()));
            item.setToolTipText(schemaFactory.getDescription());
            item.setActionCommand(schemaFactory.getName());
            item.addActionListener((final ActionEvent e) -> new Thread() {

                @Override
                public void run() {
                    setName(GRAPH_ACTION_THREAD_NAME);
                    final Graph graph = new DualGraph(schemaFactory.createSchema());
                    final WritableGraph wg = graph.getWritableGraphNow("New " + schemaFactory.getName(), false);
                    try {
                        graph.getSchema().newGraph(wg);
                    } finally {
                        wg.commit();
                    }
                    final String graphName = schemaFactory.getLabel().trim().toLowerCase();
                    GraphOpener.getDefault().openGraph(graph, graphName);
                }
            }.start());
            menu.add(item);
        }
    }
    menu.addSeparator();
    recreateTemplateMenuItems();
    return new JComponent[] { menu };
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) ActionEvent(java.awt.event.ActionEvent) JComponent(javax.swing.JComponent) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Example 4 with SchemaFactory

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

the class SourcePane method updateDestinationGraphCombo.

/**
 * Helper method to update the destination graph combo box. Also used for
 * value loading when this pane is being initialized.
 */
public final void updateDestinationGraphCombo() {
    // previousDestinationObject is the previously selected item in the combobox
    final ImportDestination<?> previousDestinationObject = graphComboBox.getSelectionModel().getSelectedItem();
    final ObservableList<ImportDestination<?>> destinations = FXCollections.observableArrayList();
    final Map<String, Graph> graphs = GraphManager.getDefault().getAllGraphs();
    final Graph activeGraph = GraphManager.getDefault().getActiveGraph();
    ImportDestination<?> defaultDestination = null;
    for (final Graph graph : graphs.values()) {
        final GraphDestination destination = new GraphDestination(graph);
        destinations.add(destination);
        if (graph == activeGraph) {
            defaultDestination = destination;
        }
    }
    final Map<String, SchemaFactory> schemaFactories = SchemaFactoryUtilities.getSchemaFactories();
    for (final SchemaFactory schemaFactory : schemaFactories.values()) {
        final SchemaDestination destination = new SchemaDestination(schemaFactory);
        destinations.add(destination);
        if (defaultDestination == null) {
            defaultDestination = destination;
        }
    }
    // resets the combo box when set correctly.
    graphComboBox.setItems(destinations);
    graphComboBox.setOnAction((final ActionEvent t) -> importController.setDestination(graphComboBox.getSelectionModel().getSelectedItem()));
    // Select null triggers the combobox to update to the correct value for
    // some unknown reason. Removal will mean that the combobox will
    // not keep it's state when a graph event occurs
    // ClearSelection() did not work to fix this.
    graphComboBox.getSelectionModel().select(null);
    importController.setDestination(previousDestinationObject != null ? previousDestinationObject : defaultDestination);
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Graph(au.gov.asd.tac.constellation.graph.Graph) ActionEvent(javafx.event.ActionEvent)

Example 5 with SchemaFactory

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

the class SchemaDestination method getGraph.

@Override
public Graph getGraph() {
    final SchemaFactory schemaFactory = getDestination();
    final Graph graph = new DualGraph(schemaFactory.createSchema());
    final WritableGraph wg = graph.getWritableGraphNow("New Graph", true);
    try {
        graph.getSchema().newGraph(wg);
    } finally {
        wg.commit();
    }
    return graph;
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Graph(au.gov.asd.tac.constellation.graph.Graph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Aggregations

SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)16 Graph (au.gov.asd.tac.constellation.graph.Graph)6 SchemaAttribute (au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)6 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)4 ArrayList (java.util.ArrayList)4 Attribute (au.gov.asd.tac.constellation.graph.Attribute)3 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)3 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Label (javafx.scene.control.Label)3 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)2 AttributeType (au.gov.asd.tac.constellation.plugins.importexport.AttributeType)2 ImportAttributeDefinition (au.gov.asd.tac.constellation.plugins.importexport.ImportAttributeDefinition)2 ImportDefinition (au.gov.asd.tac.constellation.plugins.importexport.ImportDefinition)2 NewAttribute (au.gov.asd.tac.constellation.plugins.importexport.NewAttribute)2 RowFilter (au.gov.asd.tac.constellation.plugins.importexport.RowFilter)2 SchemaDestination (au.gov.asd.tac.constellation.plugins.importexport.SchemaDestination)2 AttributeTranslator (au.gov.asd.tac.constellation.plugins.importexport.translator.AttributeTranslator)2 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)2