deprecate translation update

This commit is contained in:
Marcel Haßlinger 2021-11-04 17:41:27 +01:00
parent 568db9fc94
commit 760fc287e9
7 changed files with 53 additions and 53 deletions

View File

@ -9,7 +9,7 @@ import com.intellij.ui.components.JBTextField;
import de.marhali.easyi18n.service.LegacyDataStore; import de.marhali.easyi18n.service.LegacyDataStore;
import de.marhali.easyi18n.model.LegacyKeyedTranslation; import de.marhali.easyi18n.model.LegacyKeyedTranslation;
import de.marhali.easyi18n.model.TranslationDelete; import de.marhali.easyi18n.model.TranslationDelete;
import de.marhali.easyi18n.model.TranslationUpdate; import de.marhali.easyi18n.model.LegacyTranslationUpdate;
import de.marhali.easyi18n.dialog.descriptor.DeleteActionDescriptor; import de.marhali.easyi18n.dialog.descriptor.DeleteActionDescriptor;
import javax.swing.*; import javax.swing.*;
@ -40,7 +40,7 @@ public class EditDialog {
int code = prepare().show(); int code = prepare().show();
if(code == DialogWrapper.OK_EXIT_CODE) { // Edit if(code == DialogWrapper.OK_EXIT_CODE) { // Edit
LegacyDataStore.getInstance(project).processUpdate(new TranslationUpdate(origin, getChanges())); LegacyDataStore.getInstance(project).processUpdate(new LegacyTranslationUpdate(origin, getChanges()));
} else if(code == DeleteActionDescriptor.EXIT_CODE) { // Delete } else if(code == DeleteActionDescriptor.EXIT_CODE) { // Delete
LegacyDataStore.getInstance(project).processUpdate(new TranslationDelete(origin)); LegacyDataStore.getInstance(project).processUpdate(new TranslationDelete(origin));

View File

@ -0,0 +1,42 @@
package de.marhali.easyi18n.model;
import org.jetbrains.annotations.NotNull;
/**
* I18n translation with associated key path (full-key).
* @author marhali
*/
public class KeyedTranslation {
private @NotNull String key;
private @NotNull Translation translation;
public KeyedTranslation(@NotNull String key, @NotNull Translation translation) {
this.key = key;
this.translation = translation;
}
public @NotNull String getKey() {
return key;
}
public void setKey(@NotNull String key) {
this.key = key;
}
public @NotNull Translation getTranslation() {
return translation;
}
public void setTranslation(@NotNull Translation translation) {
this.translation = translation;
}
@Override
public String toString() {
return "KeyedTranslation{" +
"key='" + key + '\'' +
", translation=" + translation +
'}';
}
}

View File

@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull;
* Represents update request to create a new translation. * Represents update request to create a new translation.
* @author marhali * @author marhali
*/ */
public class TranslationCreate extends TranslationUpdate { public class TranslationCreate extends LegacyTranslationUpdate {
public TranslationCreate(@NotNull LegacyKeyedTranslation translation) { public TranslationCreate(@NotNull LegacyKeyedTranslation translation) {
super(null, translation); super(null, translation);
} }

View File

@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull;
* Represents update request to delete a existing translation. * Represents update request to delete a existing translation.
* @author marhali * @author marhali
*/ */
public class TranslationDelete extends TranslationUpdate { public class TranslationDelete extends LegacyTranslationUpdate {
public TranslationDelete(@NotNull LegacyKeyedTranslation translation) { public TranslationDelete(@NotNull LegacyKeyedTranslation translation) {
super(translation, null); super(translation, null);
} }

View File

@ -1,46 +1,4 @@
package de.marhali.easyi18n.model; package de.marhali.easyi18n.model;
import org.jetbrains.annotations.Nullable;
/**
* Represents an update for a translated I18n-Key. Supports key creation, manipulation and deletion.
* @author marhali
*/
public class TranslationUpdate { public class TranslationUpdate {
private final @Nullable LegacyKeyedTranslation origin;
private final @Nullable LegacyKeyedTranslation change;
public TranslationUpdate(@Nullable LegacyKeyedTranslation origin, @Nullable LegacyKeyedTranslation change) {
this.origin = origin;
this.change = change;
}
public LegacyKeyedTranslation getOrigin() {
return origin;
}
public LegacyKeyedTranslation getChange() {
return change;
}
public boolean isCreation() {
return origin == null;
}
public boolean isDeletion() {
return change == null;
}
public boolean isKeyChange() {
return origin != null && change != null && !origin.getKey().equals(change.getKey());
}
@Override
public String toString() {
return "TranslationUpdate{" +
"origin=" + origin +
", change=" + change +
'}';
}
} }

View File

@ -2,7 +2,7 @@ package de.marhali.easyi18n.model.table;
import de.marhali.easyi18n.model.LocalizedNode; import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.model.LegacyKeyedTranslation; import de.marhali.easyi18n.model.LegacyKeyedTranslation;
import de.marhali.easyi18n.model.TranslationUpdate; import de.marhali.easyi18n.model.LegacyTranslationUpdate;
import de.marhali.easyi18n.model.Translations; import de.marhali.easyi18n.model.Translations;
import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.Nls;
@ -23,14 +23,14 @@ public class TableModelTranslator implements TableModel {
private final List<String> locales; private final List<String> locales;
private final List<String> fullKeys; private final List<String> fullKeys;
private final Consumer<TranslationUpdate> updater; private final Consumer<LegacyTranslationUpdate> updater;
/** /**
* @param translations Translations instance * @param translations Translations instance
* @param searchQuery Search / filter param * @param searchQuery Search / filter param
* @param updater Consumer which can be called on cell change / update * @param updater Consumer which can be called on cell change / update
*/ */
public TableModelTranslator(Translations translations, String searchQuery, Consumer<TranslationUpdate> updater) { public TableModelTranslator(Translations translations, String searchQuery, Consumer<LegacyTranslationUpdate> updater) {
this.translations = translations; this.translations = translations;
this.locales = translations.getLocales(); this.locales = translations.getLocales();
this.updater = updater; this.updater = updater;
@ -108,7 +108,7 @@ public class TableModelTranslator implements TableModel {
} }
} }
TranslationUpdate update = new TranslationUpdate(new LegacyKeyedTranslation(key, messages), LegacyTranslationUpdate update = new LegacyTranslationUpdate(new LegacyKeyedTranslation(key, messages),
new LegacyKeyedTranslation(newKey, messages)); new LegacyKeyedTranslation(newKey, messages));
updater.accept(update); updater.accept(update);

View File

@ -10,7 +10,7 @@ import de.marhali.easyi18n.io.TranslatorIO;
import de.marhali.easyi18n.model.DataSynchronizer; import de.marhali.easyi18n.model.DataSynchronizer;
import de.marhali.easyi18n.model.LegacyKeyedTranslation; import de.marhali.easyi18n.model.LegacyKeyedTranslation;
import de.marhali.easyi18n.model.TranslationDelete; import de.marhali.easyi18n.model.TranslationDelete;
import de.marhali.easyi18n.model.TranslationUpdate; import de.marhali.easyi18n.model.LegacyTranslationUpdate;
import de.marhali.easyi18n.util.IOUtil; import de.marhali.easyi18n.util.IOUtil;
import de.marhali.easyi18n.util.TranslationsUtil; import de.marhali.easyi18n.util.TranslationsUtil;
@ -113,9 +113,9 @@ public class LegacyDataStore {
/** /**
* Processes the provided update. Updates translation instance and propagates changes. See {@link DataSynchronizer} * Processes the provided update. Updates translation instance and propagates changes. See {@link DataSynchronizer}
* @param update The update to process. For more information see {@link TranslationUpdate} * @param update The update to process. For more information see {@link LegacyTranslationUpdate}
*/ */
public void processUpdate(TranslationUpdate update) { public void processUpdate(LegacyTranslationUpdate update) {
if(update.isDeletion() || update.isKeyChange()) { // Delete origin i18n key if(update.isDeletion() || update.isKeyChange()) { // Delete origin i18n key
String originKey = update.getOrigin().getKey(); String originKey = update.getOrigin().getKey();
List<String> sections = TranslationsUtil.getSections(originKey); List<String> sections = TranslationsUtil.getSections(originKey);