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;
}
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;
}
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 };
}
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);
}
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;
}
Aggregations