use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.
the class VertexTypeNodeProvider method isFilterMatchAnyChildNodes.
private boolean isFilterMatchAnyChildNodes(SchemaVertexType treeItem) {
boolean found = false;
final List<SchemaVertexType> children = vertexTypes.stream().filter(vertexType -> vertexType.getSuperType() == treeItem && vertexType != treeItem).collect(Collectors.toList());
for (SchemaVertexType child : children) {
found = isFilterMatchCurrentNodeOrAnyChildren(child);
if (found) {
break;
}
}
return found;
}
use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.
the class VertexTypeNodeProvider 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 vxtype
* @return
*/
private TreeItem<SchemaVertexType> createNode(final SchemaVertexType vxtype) {
return new TreeItem<SchemaVertexType>(vxtype) {
// 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<SchemaVertexType>> 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 = vertexTypes.stream().anyMatch(vertexType -> vertexType.getSuperType() == getValue() && vertexType != getValue());
isLeaf = !foundChild;
}
}
return isLeaf;
}
private ObservableList<TreeItem<SchemaVertexType>> buildChildren(final TreeItem<SchemaVertexType> item) {
final SchemaVertexType value = item.getValue();
final ObservableList<TreeItem<SchemaVertexType>> children = FXCollections.observableArrayList();
if (value == null) {
// Any vertextype that points to itself is in the root layer.
for (final SchemaVertexType vertexType : vertexTypes) {
if ((vertexType.getSuperType() == vertexType) && (isFilterMatchCurrentNodeOrAnyChildren(vertexType) || filterText.getText().isEmpty())) {
children.add(createNode(vertexType));
}
}
} else {
for (final SchemaVertexType vertexType : vertexTypes) {
if ((vertexType.getSuperType() == value && vertexType != value) && (isFilterMatchCurrentNodeOrAnyChildren(vertexType) || filterText.getText().isEmpty())) {
children.add(createNode(vertexType));
}
}
}
return children;
}
};
}
use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType 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.type.SchemaVertexType in project constellation by constellation-app.
the class SchemaElementTypeNGTest method testGetColor.
/**
* Test of getColor method, of class SchemaElementType.
*/
@Test
public void testGetColor() {
SchemaElementType<SchemaVertexType> instance = SchemaVertexType.unknownType();
ConstellationColor expResult = ConstellationColor.GREY;
ConstellationColor result = instance.getColor();
assertEquals(result, expResult);
}
use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType 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));
}
}
Aggregations