diff --git a/core/src/main/java/info/openrocket/core/material/Material.java b/core/src/main/java/info/openrocket/core/material/Material.java index 767c1606c..390e86268 100644 --- a/core/src/main/java/info/openrocket/core/material/Material.java +++ b/core/src/main/java/info/openrocket/core/material/Material.java @@ -134,11 +134,11 @@ public abstract class Material implements Comparable, Groupable, GroupableEditing application materials will not affect existing rocket designs.
Editing document materials does affect the rocket design using the material. matedtpan.dlg.RemoveUsedMaterial.Application.title = Material used by component(s) matedtpan.dlg.RemoveUsedMaterial.Application.msg = The material is currently used in the following designs and components:
%s
The material will be converted from an Application material to a Document material. matedtpan.dlg.RemoveUsedMaterial.Document.title = Cannot remove material diff --git a/swing/src/main/java/info/openrocket/swing/gui/dialogs/preferences/MaterialEditPanel.java b/swing/src/main/java/info/openrocket/swing/gui/dialogs/preferences/MaterialEditPanel.java index c9863f1f0..46a4ef7dd 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/dialogs/preferences/MaterialEditPanel.java +++ b/swing/src/main/java/info/openrocket/swing/gui/dialogs/preferences/MaterialEditPanel.java @@ -184,8 +184,7 @@ public class MaterialEditPanel extends JPanel { return; sel = table.convertRowIndexToModel(sel); Material m = getMaterial(sel); - boolean isDocumentMaterialPrior = m.isDocumentMaterial(); - + CustomMaterialDialog dialog; if (m.isUserDefined()) { dialog = new CustomMaterialDialog( @@ -206,13 +205,36 @@ public class MaterialEditPanel extends JPanel { if (!dialog.getOkClicked()) { return; } - // Remove the original material + // Remove the original material from the database removeMaterial(m, false); - // Add the edited material + // Get the edited material Material mat = dialog.getMaterial(); mat.setDocumentMaterial(!dialog.isAddSelected()); - addMaterial(mat); + + // Document materials can be edited no strings attached + if (m.isDocumentMaterial()) { + // Load the old material with the new values, so that we don't mess up the references in the components + // that used the old component. + m.loadFrom(mat); + + // Add the "new" material to the database (this could be another database type as before, so we had to + // first remove the old one and then re-add it) + addMaterial(m); + } + // Editing application materials will not affect existing rocket designs + else { + // If the application material was already in use, add the old application material as a document material + Map> components = getComponentsThatUseMaterial(m); + if (!components.isEmpty()) { + for (OpenRocketDocument doc: components.keySet()) { + doc.getDocumentPreferences().addMaterial(m); + } + } + + // Add the new material to the database + addMaterial(mat); + } model.fireTableDataChanged(); setButtonStates();