use of au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.EditOperation in project constellation by constellation-app.
the class AttributeEditorPanel method modifyAttributeAction.
private void modifyAttributeAction(final AttributeData attr) {
final EditOperation editOperation = new ModifyAttributeEditOperation(attr);
final List<String> extantAttributeNames = currentAttributeNames.get(attr.getElementType());
final ValueValidator<AttributePrototype> validator = v -> extantAttributeNames.contains(v.getAttributeName()) && !attr.getAttributeName().equals(v.getAttributeName()) ? "An attribute with that name already exists." : null;
final AbstractEditor<AttributePrototype> editor = ATTRIBUTE_EDITOR_FACTORY.createEditor(editOperation, validator, String.format("Modify %s attribute %s", attr.getElementType().getShortLabel(), attr.getAttributeName()), attr);
((AttributeEditor) editor).setGraphElementType(attr.getElementType());
((AttributeEditor) editor).setTypeModifiable(false);
final AttributeEditorDialog dialog = new AttributeEditorDialog(false, editor);
dialog.showDialog();
}
use of au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.EditOperation in project constellation by constellation-app.
the class AttributeEditorPanel method createAttributeAction.
private void createAttributeAction(final GraphElementType elementType) {
final EditOperation editOperation = new CreateAttributeEditOperation();
final List<String> extantAttributeNames = currentAttributeNames.get(elementType);
final ValueValidator<AttributePrototype> validator = v -> extantAttributeNames.contains(v.getAttributeName()) ? "An attribute with that name already exists." : null;
final AbstractEditor<AttributePrototype> editor = ATTRIBUTE_EDITOR_FACTORY.createEditor(editOperation, validator, String.format("Create %s attribute", elementType.getShortLabel()), AttributePrototype.getBlankPrototype(elementType));
((AttributeEditor) editor).setGraphElementType(elementType);
((AttributeEditor) editor).setTypeModifiable(true);
final AttributeEditorDialog dialog = new AttributeEditorDialog(false, editor);
dialog.showDialog();
}
use of au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.EditOperation in project constellation by constellation-app.
the class AttributeEditorPanel method editKeysAction.
private void editKeysAction(final GraphElementType elementType) {
final List<String> currentKeyAttributes = new ArrayList<>();
final List<String> allAttributes = new ArrayList<>();
final Graph graph = GraphManager.getDefault().getActiveGraph();
if (graph != null) {
final ReadableGraph rg = graph.getReadableGraph();
try {
int[] keys = rg.getPrimaryKey(elementType);
for (int key : keys) {
currentKeyAttributes.add(rg.getAttributeName(key));
}
for (int i = 0; i < rg.getAttributeCount(elementType); i++) {
allAttributes.add(rg.getAttributeName(rg.getAttribute(elementType, i)));
}
} finally {
rg.release();
}
final EditOperation editOperation = new PrimaryKeyEditOperation(elementType);
final DefaultGetter<List<String>> defaultGetter = new PrimaryKeyDefaultGetter(elementType);
final AbstractEditor<List<String>> editor = LIST_SELECTION_EDITOR_FACTORY.createEditor(editOperation, defaultGetter, String.format("Edit primary key for %ss", elementType.getShortLabel()), currentKeyAttributes);
((ListSelectionEditor) editor).setPossibleItems(allAttributes);
final AttributeEditorDialog dialog = new AttributeEditorDialog(true, editor);
dialog.showDialog();
}
}
use of au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.EditOperation in project constellation by constellation-app.
the class AttributeEditorPanel method updateTimeZoneAction.
private void updateTimeZoneAction(final AttributeData attr) {
final EditOperation editOperation = zoneId -> PluginExecution.withPlugin(new UpdateTimeZonePlugin((ZoneId) zoneId, attr)).executeLater(GraphManager.getDefault().getActiveGraph());
final AbstractEditor<ZoneId> editor = UPDATE_TIME_ZONE_EDITOR_FACTORY.createEditor(editOperation, String.format("Set time-zone for attribute %s", attr.getAttributeName()), TimeZone.getTimeZone(ZoneOffset.UTC).toZoneId());
final AttributeEditorDialog dialog = new AttributeEditorDialog(true, editor);
dialog.showDialog();
}
use of au.gov.asd.tac.constellation.views.attributeeditor.editors.operations.EditOperation in project constellation by constellation-app.
the class AttributeEditorPanel method createColourMenuItem.
private MenuItem createColourMenuItem(final String itemName, final String correspondingPreference, final Color color) {
final HBox schemaMenuNode = new HBox(CELL_ITEM_SPACING);
final MenuItem schemaMenuItem = new MenuItem(null, schemaMenuNode);
final Rectangle schemaMenuRect = new Rectangle(20, 20);
final Text schemaMenuText = new Text(itemName);
schemaMenuText.setStyle("-fx-fill: white; -fx-font-smoothing-type:lcd;");
schemaMenuNode.getChildren().addAll(schemaMenuRect, schemaMenuText);
schemaMenuRect.setFill(color);
schemaMenuRect.setStroke(Color.LIGHTGREY);
schemaMenuItem.setOnAction(e -> {
final EditOperation editOperation = value -> prefs.put(correspondingPreference, ((ConstellationColor) value).getHtmlColor());
// return type of createEditor will actually be AbstractEditor<ConstellationColor>
@SuppressWarnings("unchecked") final AbstractEditor<ConstellationColor> editor = ((AbstractEditorFactory<ConstellationColor>) AttributeValueEditorFactory.getEditFactory(ColorAttributeDescription.ATTRIBUTE_NAME)).createEditor(editOperation, String.format("for %s", itemName), ConstellationColor.fromFXColor(color));
final AttributeEditorDialog dialog = new AttributeEditorDialog(false, editor);
dialog.showDialog();
});
return schemaMenuItem;
}
Aggregations