deprecate legacy data system

This commit is contained in:
Marcel Haßlinger 2021-11-02 16:41:02 +01:00
parent de88d0d96c
commit befdea277b
17 changed files with 38 additions and 32 deletions

View File

@ -4,7 +4,7 @@ import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.service.LegacyDataStore;
import org.jetbrains.annotations.NotNull;
@ -23,6 +23,6 @@ public class ReloadAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
DataStore.getInstance(e.getProject()).reloadFromDisk();
LegacyDataStore.getInstance(e.getProject()).reloadFromDisk();
}
}

View File

@ -7,7 +7,7 @@ import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.components.JBTextField;
import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.service.LegacyDataStore;
import de.marhali.easyi18n.model.KeyedTranslation;
import de.marhali.easyi18n.model.TranslationCreate;
@ -57,7 +57,7 @@ public class AddDialog {
});
TranslationCreate creation = new TranslationCreate(new KeyedTranslation(keyTextField.getText(), messages));
DataStore.getInstance(project).processUpdate(creation);
LegacyDataStore.getInstance(project).processUpdate(creation);
}
private DialogBuilder prepare() {
@ -75,7 +75,7 @@ public class AddDialog {
JPanel valuePanel = new JPanel(new GridLayout(0, 1, 2, 2));
valueTextFields = new HashMap<>();
for(String locale : DataStore.getInstance(project).getTranslations().getLocales()) {
for(String locale : LegacyDataStore.getInstance(project).getTranslations().getLocales()) {
JBLabel localeLabel = new JBLabel(locale);
JBTextField localeText = new JBTextField();
localeLabel.setLabelFor(localeText);

View File

@ -6,7 +6,7 @@ import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.components.JBTextField;
import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.service.LegacyDataStore;
import de.marhali.easyi18n.model.KeyedTranslation;
import de.marhali.easyi18n.model.TranslationDelete;
import de.marhali.easyi18n.model.TranslationUpdate;
@ -40,10 +40,10 @@ public class EditDialog {
int code = prepare().show();
if(code == DialogWrapper.OK_EXIT_CODE) { // Edit
DataStore.getInstance(project).processUpdate(new TranslationUpdate(origin, getChanges()));
LegacyDataStore.getInstance(project).processUpdate(new TranslationUpdate(origin, getChanges()));
} else if(code == DeleteActionDescriptor.EXIT_CODE) { // Delete
DataStore.getInstance(project).processUpdate(new TranslationDelete(origin));
LegacyDataStore.getInstance(project).processUpdate(new TranslationDelete(origin));
}
}
@ -74,7 +74,7 @@ public class EditDialog {
JPanel valuePanel = new JPanel(new GridLayout(0, 1, 2, 2));
valueTextFields = new HashMap<>();
for(String locale : DataStore.getInstance(project).getTranslations().getLocales()) {
for(String locale : LegacyDataStore.getInstance(project).getTranslations().getLocales()) {
JBLabel localeLabel = new JBLabel(locale);
JBTextField localeText = new JBTextField(this.origin.getTranslations().get(locale));
localeLabel.setLabelFor(localeText);

View File

@ -5,7 +5,7 @@ import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.project.Project;
import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.service.LegacyDataStore;
import de.marhali.easyi18n.service.SettingsService;
import org.jetbrains.annotations.NotNull;
@ -39,7 +39,7 @@ public class KeyAnnotator {
searchKey = searchKey.substring(1);
}
LocalizedNode node = DataStore.getInstance(project).getTranslations().getNode(searchKey);
LocalizedNode node = LegacyDataStore.getInstance(project).getTranslations().getNode(searchKey);
if(node == null) { // Unknown translation. Just ignore it
return;

View File

@ -29,7 +29,7 @@ public class KeyCompletionProvider extends CompletionProvider<CompletionParamete
return;
}
DataStore store = DataStore.getInstance(project);
LegacyDataStore store = LegacyDataStore.getInstance(project);
String previewLocale = SettingsService.getInstance(project).getState().getPreviewLocale();
String pathPrefix = SettingsService.getInstance(project).getState().getPathPrefix();

View File

@ -8,7 +8,7 @@ import de.marhali.easyi18n.dialog.AddDialog;
import de.marhali.easyi18n.dialog.EditDialog;
import de.marhali.easyi18n.model.KeyedTranslation;
import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.service.LegacyDataStore;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -52,7 +52,7 @@ public class KeyReference extends PsiReferenceBase<PsiElement> {
@Override
public void navigate(boolean requestFocus) {
LocalizedNode node = DataStore.getInstance(getProject()).getTranslations().getNode(getKey());
LocalizedNode node = LegacyDataStore.getInstance(getProject()).getTranslations().getNode(getKey());
if(node != null) {
new EditDialog(getProject(), new KeyedTranslation(getKey(), node.getValue())).showAndHandle();

View File

@ -5,7 +5,7 @@ import com.intellij.psi.*;
import com.intellij.util.ProcessingContext;
import de.marhali.easyi18n.editor.KeyReference;
import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.service.LegacyDataStore;
import de.marhali.easyi18n.service.SettingsService;
import org.jetbrains.annotations.NotNull;
@ -38,7 +38,7 @@ public class GenericKeyReferenceContributor extends PsiReferenceContributor {
return PsiReference.EMPTY_ARRAY;
}
if(DataStore.getInstance(element.getProject()).getTranslations().getNode(value) == null) {
if(LegacyDataStore.getInstance(element.getProject()).getTranslations().getNode(value) == null) {
if(!KeyReference.isReferencable(value)) { // Creation policy
return PsiReference.EMPTY_ARRAY;
}

View File

@ -6,7 +6,7 @@ import com.intellij.psi.*;
import com.intellij.util.ProcessingContext;
import de.marhali.easyi18n.editor.KeyReference;
import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.service.LegacyDataStore;
import de.marhali.easyi18n.service.SettingsService;
import org.jetbrains.annotations.NotNull;
@ -45,7 +45,7 @@ public class KotlinKeyReferenceContributor extends PsiReferenceContributor {
return PsiReference.EMPTY_ARRAY;
}
if(DataStore.getInstance(element.getProject()).getTranslations().getNode(value) == null) {
if(LegacyDataStore.getInstance(element.getProject()).getTranslations().getNode(value) == null) {
return PsiReference.EMPTY_ARRAY;
}

View File

@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable;
* Interface to communicate data changes between data store and ui components.
* @author marhali
*/
@Deprecated
public interface DataSynchronizer {
/**

View File

@ -6,6 +6,7 @@ import java.util.Map;
* Translated messages for a dedicated key.
* @author marhali
*/
@Deprecated // Might be deprecated
public class KeyedTranslation {
private String key;

View File

@ -11,6 +11,7 @@ import java.util.*;
* Represents structured tree view for translated messages.
* @author marhali
*/
@Deprecated
public class LocalizedNode {
public static final String ROOT_KEY = "root";

View File

@ -12,6 +12,7 @@ import java.util.List;
* Represents translation state instance. IO operations will be based on this file.
* @author marhali
*/
@Deprecated
public class Translations {
public static Translations empty() {

View File

@ -27,9 +27,10 @@ import java.util.function.Consumer;
* Factory service to manage localized messages for multiple projects at once.
* @author marhali
*/
public class DataStore {
@Deprecated
public class LegacyDataStore {
private static final Map<Project, DataStore> INSTANCES = new WeakHashMap<>();
private static final Map<Project, LegacyDataStore> INSTANCES = new WeakHashMap<>();
private final Project project;
private final List<DataSynchronizer> synchronizer;
@ -37,18 +38,18 @@ public class DataStore {
private Translations translations;
private String searchQuery;
public static DataStore getInstance(@NotNull Project project) {
DataStore store = INSTANCES.get(project);
public static LegacyDataStore getInstance(@NotNull Project project) {
LegacyDataStore store = INSTANCES.get(project);
if(store == null) {
store = new DataStore(project);
store = new LegacyDataStore(project);
INSTANCES.put(project, store);
}
return store;
}
private DataStore(@NotNull Project project) {
private LegacyDataStore(@NotNull Project project) {
this.project = project;
this.synchronizer = new ArrayList<>();
this.translations = Translations.empty();

View File

@ -4,7 +4,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.table.JBTable;
import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.service.LegacyDataStore;
import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.model.DataSynchronizer;
import de.marhali.easyi18n.model.Translations;
@ -54,7 +54,7 @@ public class TableView implements DataSynchronizer {
if(row >= 0) {
String fullPath = String.valueOf(table.getValueAt(row, 0));
LocalizedNode node = DataStore.getInstance(project).getTranslations().getNode(fullPath);
LocalizedNode node = LegacyDataStore.getInstance(project).getTranslations().getNode(fullPath);
if(node != null) {
new EditDialog(project, new KeyedTranslation(fullPath, node.getValue())).showAndHandle();
@ -67,7 +67,7 @@ public class TableView implements DataSynchronizer {
for (int selectedRow : table.getSelectedRows()) {
String fullPath = String.valueOf(table.getValueAt(selectedRow, 0));
DataStore.getInstance(project).processUpdate(
LegacyDataStore.getInstance(project).processUpdate(
new TranslationDelete(new KeyedTranslation(fullPath, null)));
}
};
@ -78,7 +78,7 @@ public class TableView implements DataSynchronizer {
@Nullable String searchQuery, @Nullable String scrollTo) {
table.setModel(new TableModelTranslator(translations, searchQuery, update ->
DataStore.getInstance(project).processUpdate(update)));
LegacyDataStore.getInstance(project).processUpdate(update)));
if(scrollTo != null) {
int row = -1;

View File

@ -8,7 +8,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.treeStructure.Tree;
import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.service.LegacyDataStore;
import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.model.DataSynchronizer;
import de.marhali.easyi18n.model.Translations;
@ -100,7 +100,7 @@ public class TreeView implements DataSynchronizer {
if(node.getUserObject() instanceof PresentationData) {
String fullPath = TreeUtil.getFullPath(path);
LocalizedNode localizedNode = DataStore.getInstance(project).getTranslations().getNode(fullPath);
LocalizedNode localizedNode = LegacyDataStore.getInstance(project).getTranslations().getNode(fullPath);
if(localizedNode != null) {
new EditDialog(project,new KeyedTranslation(fullPath, localizedNode.getValue())).showAndHandle();
@ -120,7 +120,7 @@ public class TreeView implements DataSynchronizer {
for (TreePath path : tree.getSelectionPaths()) {
String fullPath = TreeUtil.getFullPath(path);
DataStore.getInstance(project).processUpdate(
LegacyDataStore.getInstance(project).processUpdate(
new TranslationDelete(new KeyedTranslation(fullPath, null)));
}
};

View File

@ -11,6 +11,7 @@ import java.util.List;
* Utility tool to support the translations instance
* @author marhali
*/
@Deprecated // SectionUtil
public class TranslationsUtil {
/**

View File

@ -10,7 +10,7 @@
<depends optional="true" config-file="de.marhali.easyi18n-kotlin.xml">org.jetbrains.kotlin</depends>
<extensions defaultExtensionNs="com.intellij">
<toolWindow id="Easy I18n" anchor="bottom" factoryClass="de.marhali.easyi18n.TranslatorToolWindowFactory" />
<toolWindow id="Easy I18n" anchor="bottom" factoryClass="de.marhali.easyi18n.service.TranslatorToolWindowFactory" />
<projectService serviceImplementation="de.marhali.easyi18n.service.SettingsService" />
<completion.contributor language="any"