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