use of au.gov.asd.tac.constellation.graph.schema.SchemaFactory 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.SchemaFactory in project constellation by constellation-app.
the class NewSchemaGraphAction method recreateTemplateMenuItems.
public static void recreateTemplateMenuItems() {
SwingUtilities.invokeLater(() -> {
final Map<String, String> templates = getTemplateNames();
TEMPLATES_MENU.forEach(item -> menu.remove(item));
TEMPLATES_MENU.clear();
templates.forEach((template, schema) -> {
SchemaFactory factory = SchemaFactoryUtilities.getSchemaFactory(schema);
if (factory != null) {
if (!ICON_CACHE.containsKey(factory.getName())) {
ICON_CACHE.put(factory.getName(), SchemaFactoryUtilities.getSchemaFactory(schema).getIcon().buildIcon(16));
}
JMenuItem item = new JMenuItem(template + " Graph", ICON_CACHE.get(factory.getName()));
item.addActionListener((final ActionEvent e) -> createTemplate(template));
TEMPLATES_MENU.add(item);
}
});
TEMPLATES_MENU.forEach(item -> menu.add(item));
});
}
use of au.gov.asd.tac.constellation.graph.schema.SchemaFactory in project constellation by constellation-app.
the class NewDefaultSchemaGraphAction method recreateAction.
public final void recreateAction() {
template = prefs.get(ApplicationPreferenceKeys.DEFAULT_TEMPLATE, ApplicationPreferenceKeys.DEFAULT_TEMPLATE_DEFAULT);
if (!Objects.equals(template, ApplicationPreferenceKeys.DEFAULT_TEMPLATE_DEFAULT)) {
schemaFactory = null;
putValue(Action.NAME, "New " + template + " Graph");
final SchemaFactory factory = SchemaFactoryUtilities.getSchemaFactory(NewSchemaGraphAction.getTemplateNames().get(template));
if (factory != null) {
final Icon icon16 = SchemaFactoryUtilities.getSchemaFactory(NewSchemaGraphAction.getTemplateNames().get(template)).getIcon().buildIcon(16);
putValue(Action.SMALL_ICON, icon16);
final Icon icon24 = SchemaFactoryUtilities.getSchemaFactory(NewSchemaGraphAction.getTemplateNames().get(template)).getIcon().buildIcon(24);
putValue(Action.LARGE_ICON_KEY, icon24);
return;
}
}
final SchemaFactory[] factories = SchemaFactoryUtilities.getSchemaFactories().values().toArray(new SchemaFactory[0]);
schemaFactory = factories[0];
putValue(Action.NAME, "New " + schemaFactory.getLabel());
putValue(Action.LONG_DESCRIPTION, schemaFactory.getDescription());
final Icon icon16 = schemaFactory.getIcon().buildIcon(16);
putValue(Action.SMALL_ICON, icon16);
final Icon icon24 = schemaFactory.getIcon().buildIcon(24);
putValue(Action.LARGE_ICON_KEY, icon24);
}
use of au.gov.asd.tac.constellation.graph.schema.SchemaFactory 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();
});
}
use of au.gov.asd.tac.constellation.graph.schema.SchemaFactory in project constellation by constellation-app.
the class ImportDelimitedIO method loadParameterFile.
private static void loadParameterFile(final DelimitedImportController importController, final File delimIoDir, final String templName) {
try {
final ObjectMapper mapper = new ObjectMapper();
final JsonNode root = mapper.readTree(new File(delimIoDir, FilenameEncoder.encode(templName) + FileExtensionConstants.JSON));
final JsonNode source = root.get(SOURCE);
final String parser = source.get(PARSER).textValue();
final ImportFileParser ifp = ImportFileParser.getParser(parser);
if (!importController.getImportFileParser().getLabel().equals(parser)) {
final String message = String.format("Template is for a different file Parser '%s'.", parser);
NotifyDisplayer.displayAlert(LOAD_TEMPLATE, "File Parser Mismatch", message, Alert.AlertType.ERROR);
return;
}
importController.setImportFileParser(ifp);
final boolean schemaInit = source.get(SCHEMA_INIT).booleanValue();
importController.setSchemaInitialised(schemaInit);
final boolean filesIncludeHeaders = source.get(FILES_INCLUDE_HEADERS).booleanValue();
importController.setfilesIncludeHeaders(filesIncludeHeaders);
final boolean showAllSchemaAttributes = source.get(SHOW_ALL_SCHEMA_ATTRIBUTES) != null && source.get(SHOW_ALL_SCHEMA_ATTRIBUTES).booleanValue();
importController.setShowAllSchemaAttributes(showAllSchemaAttributes);
final String destination = source.get(DESTINATION).textValue();
final SchemaFactory schemaFactory = SchemaFactoryUtilities.getSchemaFactory(destination);
if (schemaFactory != null) {
importController.setDestination(new SchemaDestination(schemaFactory));
final List<ImportDefinition> definitions = new ArrayList<>();
final ArrayNode definitionsArray = (ArrayNode) root.withArray(DEFINITIONS);
for (final JsonNode definitionNode : definitionsArray) {
final int firstRow = definitionNode.get(FIRST_ROW).intValue();
final RowFilter filter = new RowFilter();
if (definitionNode.has(FILTER)) {
final JsonNode filterNode = definitionNode.get(FILTER);
final String script = filterNode.get(SCRIPT).textValue();
final JsonNode columnsArray = filterNode.withArray(COLUMNS);
final ArrayList<String> columns = new ArrayList<>();
for (final JsonNode column : columnsArray) {
columns.add(column.textValue());
}
filter.setScript(script);
filter.setColumns(columns.toArray(new String[columns.size()]));
}
final ImportDefinition impdef = new ImportDefinition("", firstRow, filter);
final JsonNode attributesNode = definitionNode.get(ATTRIBUTES);
for (final AttributeType attrType : AttributeType.values()) {
final ArrayNode columnArray = (ArrayNode) attributesNode.withArray(attrType.toString());
for (final JsonNode column : columnArray) {
final String columnLabel = column.get(COLUMN_LABEL).textValue();
final String label = column.get(ATTRIBUTE_LABEL).textValue();
if (!importController.hasAttribute(attrType.getElementType(), label)) {
// Manually created attribute.
final String type = column.get(ATTRIBUTE_TYPE).textValue();
final String descr = column.get(ATTRIBUTE_DESCRIPTION).textValue();
final NewAttribute a = new NewAttribute(attrType.getElementType(), type, label, descr);
importController.createManualAttribute(a);
}
final Attribute attribute = importController.getAttribute(attrType.getElementType(), label);
final AttributeTranslator translator = AttributeTranslator.getTranslator(column.get(TRANSLATOR).textValue());
final String args = column.get(TRANSLATOR_ARGS).textValue();
final String defaultValue = column.get(DEFAULT_VALUE).textValue();
final PluginParameters params = translator.createParameters();
translator.setParameterValues(params, args);
final ImportAttributeDefinition iad = new ImportAttributeDefinition(columnLabel, defaultValue, attribute, translator, params);
impdef.addDefinition(attrType, iad);
}
}
definitions.add(impdef);
}
importController.setClearManuallyAdded(false);
try {
((DelimitedImportPane) importController.getStage()).update(importController, definitions);
} finally {
importController.setClearManuallyAdded(true);
}
} else {
final String message = String.format("Can't find schema factory '%s'", destination);
NotifyDisplayer.displayAlert(LOAD_TEMPLATE, "Destination Schema Error", message, Alert.AlertType.ERROR);
}
} catch (final IOException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
Aggregations