Optimize structure and add documentation

This commit is contained in:
Marcel Haßlinger 2021-03-14 14:28:00 +01:00
parent f97c184d5e
commit 73e4298f4b
40 changed files with 178 additions and 350 deletions

View File

@ -7,18 +7,21 @@ import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content; import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory; import com.intellij.ui.content.ContentFactory;
import de.marhali.easyi18n.data.DataStore; import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.service.WindowManager;
import de.marhali.easyi18n.ui.action.*; import de.marhali.easyi18n.ui.action.*;
import de.marhali.easyi18n.ui.panel.TableView; import de.marhali.easyi18n.ui.tabs.TableView;
import de.marhali.easyi18n.ui.panel.TreeView; import de.marhali.easyi18n.ui.tabs.TreeView;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
/**
* Tool window factory which will represent the entire ui for this plugin.
* @author marhali
*/
public class TranslatorToolWindowFactory implements ToolWindowFactory { public class TranslatorToolWindowFactory implements ToolWindowFactory {
@Override @Override
@ -51,10 +54,6 @@ public class TranslatorToolWindowFactory implements ToolWindowFactory {
store.addSynchronizer(treeView); store.addSynchronizer(treeView);
store.addSynchronizer(tableView); store.addSynchronizer(tableView);
try {
store.reloadFromDisk(); store.reloadFromDisk();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }

View File

@ -1,31 +0,0 @@
package de.marhali.easyi18n.io;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import java.io.File;
/**
* Singleton service for file io operations.
* @author marhali
*/
public class Filer {
private static Filer INSTANCE;
private final Project project;
public static Filer getInstance(Project project) {
return INSTANCE == null ? INSTANCE = new Filer(project) : INSTANCE;
}
private Filer(Project project) {
this.project = project;
}
public VirtualFile getFile() {
VirtualFile vfs = LocalFileSystem.getInstance().findFileByIoFile(new File(project.getBasePath() + "/src/lang/de.json"));
return vfs;
}
}

View File

@ -1,6 +1,6 @@
package de.marhali.easyi18n.io.translator; package de.marhali.easyi18n.io;
import de.marhali.easyi18n.data.Translations; import de.marhali.easyi18n.model.Translations;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -1,12 +1,13 @@
package de.marhali.easyi18n.io.translator; package de.marhali.easyi18n.io.implementation;
import com.google.gson.*; import com.google.gson.*;
import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import de.marhali.easyi18n.data.LocalizedNode; import de.marhali.easyi18n.io.TranslatorIO;
import de.marhali.easyi18n.data.Translations; import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.model.Translations;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -1,11 +1,12 @@
package de.marhali.easyi18n.io.translator; package de.marhali.easyi18n.io.implementation;
import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import de.marhali.easyi18n.data.LocalizedNode; import de.marhali.easyi18n.io.TranslatorIO;
import de.marhali.easyi18n.data.Translations; import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.model.Translations;
import de.marhali.easyi18n.util.TranslationsUtil; import de.marhali.easyi18n.util.TranslationsUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -1,7 +1,5 @@
package de.marhali.easyi18n.model; package de.marhali.easyi18n.model;
import de.marhali.easyi18n.data.Translations;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View File

@ -1,4 +1,4 @@
package de.marhali.easyi18n.data; package de.marhali.easyi18n.model;
import de.marhali.easyi18n.util.MapUtil; import de.marhali.easyi18n.util.MapUtil;

View File

@ -1,9 +1,10 @@
package de.marhali.easyi18n.data; package de.marhali.easyi18n.model;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
/** /**
* Represents the persistent settings which can be configured.
* @author marhali * @author marhali
*/ */
public class SettingsState { public class SettingsState {

View File

@ -1,4 +1,4 @@
package de.marhali.easyi18n.data; package de.marhali.easyi18n.model;
import de.marhali.easyi18n.util.TranslationsUtil; import de.marhali.easyi18n.util.TranslationsUtil;
@ -14,8 +14,11 @@ import java.util.List;
*/ */
public class Translations { public class Translations {
private @NotNull List<String> locales; @NotNull
private @NotNull LocalizedNode nodes; private final List<String> locales;
@NotNull
private final LocalizedNode nodes;
/** /**
* Constructs a new translation state instance. * Constructs a new translation state instance.

View File

@ -1,9 +1,9 @@
package de.marhali.easyi18n.model.table; package de.marhali.easyi18n.model.table;
import de.marhali.easyi18n.data.LocalizedNode; import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.model.KeyedTranslation; import de.marhali.easyi18n.model.KeyedTranslation;
import de.marhali.easyi18n.model.TranslationUpdate; import de.marhali.easyi18n.model.TranslationUpdate;
import de.marhali.easyi18n.data.Translations; import de.marhali.easyi18n.model.Translations;
import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.Nls;

View File

@ -4,9 +4,9 @@ import com.intellij.ide.projectView.PresentationData;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.ui.JBColor; import com.intellij.ui.JBColor;
import de.marhali.easyi18n.SettingsService; import de.marhali.easyi18n.service.SettingsService;
import de.marhali.easyi18n.data.LocalizedNode; import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.data.Translations; import de.marhali.easyi18n.model.Translations;
import de.marhali.easyi18n.util.TranslationsUtil; import de.marhali.easyi18n.util.TranslationsUtil;
import de.marhali.easyi18n.util.UiUtil; import de.marhali.easyi18n.util.UiUtil;

View File

@ -1,18 +1,20 @@
package de.marhali.easyi18n.data; package de.marhali.easyi18n.service;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import de.marhali.easyi18n.SettingsService; import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.io.translator.TranslatorIO; import de.marhali.easyi18n.model.Translations;
import de.marhali.easyi18n.io.TranslatorIO;
import de.marhali.easyi18n.model.DataSynchronizer; import de.marhali.easyi18n.model.DataSynchronizer;
import de.marhali.easyi18n.model.KeyedTranslation; import de.marhali.easyi18n.model.KeyedTranslation;
import de.marhali.easyi18n.model.TranslationDelete; import de.marhali.easyi18n.model.TranslationDelete;
import de.marhali.easyi18n.model.TranslationUpdate; import de.marhali.easyi18n.model.TranslationUpdate;
import de.marhali.easyi18n.util.IOUtil; import de.marhali.easyi18n.util.IOUtil;
import de.marhali.easyi18n.util.TranslationsUtil; import de.marhali.easyi18n.util.TranslationsUtil;
import org.jetbrains.annotations.NotNull;
import java.io.IOException; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -40,11 +42,18 @@ public class DataStore {
this.synchronizer = new ArrayList<>(); this.synchronizer = new ArrayList<>();
} }
/**
* Registers a new synchronizer which will receive {@link #translations} updates.
* @param synchronizer Synchronizer. See {@link DataSynchronizer}
*/
public void addSynchronizer(DataSynchronizer synchronizer) { public void addSynchronizer(DataSynchronizer synchronizer) {
this.synchronizer.add(synchronizer); this.synchronizer.add(synchronizer);
} }
public void reloadFromDisk() throws IOException { /**
* Loads all translations from disk and overrides current {@link #translations} state.
*/
public void reloadFromDisk() {
String localesPath = SettingsService.getInstance(project).getState().getLocalesPath(); String localesPath = SettingsService.getInstance(project).getState().getLocalesPath();
if(localesPath == null || localesPath.isEmpty()) { if(localesPath == null || localesPath.isEmpty()) {
@ -60,11 +69,20 @@ public class DataStore {
// Propagate changes // Propagate changes
synchronizer.forEach(synchronizer -> synchronizer.synchronize(translations, searchQuery)); synchronizer.forEach(synchronizer -> synchronizer.synchronize(translations, searchQuery));
} else {
// If state cannot be loaded from disk, show empty instance
this.translations = new Translations(new ArrayList<>(),
new LocalizedNode(LocalizedNode.ROOT_KEY, new ArrayList<>()));
} }
}); });
} }
} }
/**
* Saves the current translation state to disk. See {@link TranslatorIO#save(Translations, String, Consumer)}
* @param callback Complete callback. Indicates if operation was successful(true) or not
*/
public void saveToDisk(@NotNull Consumer<Boolean> callback) { public void saveToDisk(@NotNull Consumer<Boolean> callback) {
String localesPath = SettingsService.getInstance(project).getState().getLocalesPath(); String localesPath = SettingsService.getInstance(project).getState().getLocalesPath();
@ -76,11 +94,19 @@ public class DataStore {
io.save(translations, localesPath, callback); io.save(translations, localesPath, callback);
} }
public void searchBeyKey(String fullPath) { /**
* Propagates provided search string to all synchronizer to display only relevant keys
* @param fullPath Full i18n key (e.g. user.username.title). Can be null to display all keys
*/
public void searchBeyKey(@Nullable String fullPath) {
// Use synchronizer to propagate search instance to all views // Use synchronizer to propagate search instance to all views
synchronizer.forEach(synchronizer -> synchronizer.synchronize(translations, this.searchQuery = fullPath)); synchronizer.forEach(synchronizer -> synchronizer.synchronize(translations, this.searchQuery = fullPath));
} }
/**
* 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}
*/
public void processUpdate(TranslationUpdate update) { public void processUpdate(TranslationUpdate 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();
@ -120,6 +146,9 @@ public class DataStore {
}); });
} }
/**
* @return Current translation state
*/
public Translations getTranslations() { public Translations getTranslations() {
return translations; return translations;
} }

View File

@ -1,11 +1,11 @@
package de.marhali.easyi18n; package de.marhali.easyi18n.service;
import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State; import com.intellij.openapi.components.State;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import de.marhali.easyi18n.data.SettingsState; import de.marhali.easyi18n.model.SettingsState;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -1,9 +1,9 @@
package de.marhali.easyi18n; package de.marhali.easyi18n.service;
import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindow;
import de.marhali.easyi18n.ui.panel.TableView; import de.marhali.easyi18n.ui.tabs.TableView;
import de.marhali.easyi18n.ui.panel.TreeView; import de.marhali.easyi18n.ui.tabs.TreeView;
public class WindowManager { public class WindowManager {

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.marhali.easyi18n.ui.ActionsToolbar">
<grid id="27dc6" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<vspacer id="c33fe">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>

View File

@ -1,6 +0,0 @@
package de.marhali.easyi18n.ui;
import javax.swing.*;
public class ActionsToolbar {
}

View File

@ -4,7 +4,7 @@ import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.AnActionEvent;
import de.marhali.easyi18n.WindowManager; import de.marhali.easyi18n.service.WindowManager;
import de.marhali.easyi18n.ui.dialog.AddDialog; import de.marhali.easyi18n.ui.dialog.AddDialog;
import de.marhali.easyi18n.util.TreeUtil; import de.marhali.easyi18n.util.TreeUtil;
@ -12,6 +12,10 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
/**
* Add translation action.
* @author marhai
*/
public class AddAction extends AnAction { public class AddAction extends AnAction {
public AddAction() { public AddAction() {

View File

@ -4,12 +4,14 @@ import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.AnActionEvent;
import de.marhali.easyi18n.data.DataStore; import de.marhali.easyi18n.service.DataStore;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.IOException; /**
* Reload translations action.
* @author marhali
*/
public class ReloadAction extends AnAction { public class ReloadAction extends AnAction {
public ReloadAction() { public ReloadAction() {
@ -18,10 +20,6 @@ public class ReloadAction extends AnAction {
@Override @Override
public void actionPerformed(@NotNull AnActionEvent e) { public void actionPerformed(@NotNull AnActionEvent e) {
try {
DataStore.getInstance(e.getProject()).reloadFromDisk(); DataStore.getInstance(e.getProject()).reloadFromDisk();
} catch (IOException ioException) {
ioException.printStackTrace();
}
} }
} }

View File

@ -16,6 +16,10 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.function.Consumer; import java.util.function.Consumer;
/**
* Search translations by key action.
* @author marhali
*/
public class SearchAction extends AnAction implements CustomComponentAction { public class SearchAction extends AnAction implements CustomComponentAction {
private final Consumer<String> searchCallback; private final Consumer<String> searchCallback;

View File

@ -6,6 +6,10 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
import de.marhali.easyi18n.ui.dialog.SettingsDialog; import de.marhali.easyi18n.ui.dialog.SettingsDialog;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/**
* Plugin settings action.
* @author marhali
*/
public class SettingsAction extends AnAction { public class SettingsAction extends AnAction {
public SettingsAction() { public SettingsAction() {

View File

@ -1,4 +1,4 @@
package de.marhali.easyi18n.ui.action; package de.marhali.easyi18n.ui.action.treeview;
import com.intellij.icons.AllIcons; import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnAction;

View File

@ -1,4 +1,4 @@
package de.marhali.easyi18n.ui.action; package de.marhali.easyi18n.ui.action.treeview;
import com.intellij.icons.AllIcons; import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnAction;

View File

@ -7,7 +7,7 @@ import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.components.JBTextField; import com.intellij.ui.components.JBTextField;
import de.marhali.easyi18n.data.DataStore; import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.model.KeyedTranslation; import de.marhali.easyi18n.model.KeyedTranslation;
import de.marhali.easyi18n.model.TranslationCreate; import de.marhali.easyi18n.model.TranslationCreate;
@ -18,7 +18,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* * Create translation dialog.
* @author marhali * @author marhali
*/ */
public class AddDialog { public class AddDialog {

View File

@ -6,7 +6,7 @@ import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.components.JBTextField; import com.intellij.ui.components.JBTextField;
import de.marhali.easyi18n.data.DataStore; import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.model.KeyedTranslation; import de.marhali.easyi18n.model.KeyedTranslation;
import de.marhali.easyi18n.model.TranslationDelete; import de.marhali.easyi18n.model.TranslationDelete;
import de.marhali.easyi18n.model.TranslationUpdate; import de.marhali.easyi18n.model.TranslationUpdate;
@ -18,6 +18,10 @@ import java.awt.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/**
* Edit translation dialog.
* @author marhali
*/
public class EditDialog { public class EditDialog {
private final Project project; private final Project project;

View File

@ -8,12 +8,11 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBTextField; import com.intellij.ui.components.JBTextField;
import de.marhali.easyi18n.SettingsService; import de.marhali.easyi18n.service.SettingsService;
import de.marhali.easyi18n.data.DataStore; import de.marhali.easyi18n.service.DataStore;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.IOException;
/** /**
* Plugin configuration dialog. * Plugin configuration dialog.
@ -39,11 +38,7 @@ public class SettingsDialog {
SettingsService.getInstance(project).getState().setPreviewLocale(previewText.getText()); SettingsService.getInstance(project).getState().setPreviewLocale(previewText.getText());
// Reload instance // Reload instance
try {
DataStore.getInstance(project).reloadFromDisk(); DataStore.getInstance(project).reloadFromDisk();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }

View File

@ -1,130 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.marhali.easyi18n.ui.panel.TestPanel">
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="empty"/>
<children>
<grid id="2384b" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2226" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Label"/>
</properties>
</component>
<vspacer id="f5394">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="298a2" class="javax.swing.JTextField" binding="textField1" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
<scrollpane id="a867e">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="e3db9" layout-manager="GridLayoutManager" row-count="9" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints/>
<properties/>
<border type="none"/>
<children>
<component id="519ad" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Label"/>
</properties>
</component>
<vspacer id="3f792">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="da2f8" class="javax.swing.JTextField" binding="textField2" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="47bfb" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Label"/>
</properties>
</component>
<component id="a0189" class="javax.swing.JTextField" binding="textField3" default-binding="true">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="5ba8a" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Label"/>
</properties>
</component>
<component id="79bc7" class="javax.swing.JTextField" binding="textField4" default-binding="true">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="532d3" class="javax.swing.JLabel">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Label"/>
</properties>
</component>
<component id="ddee" class="javax.swing.JTextField" binding="textField5" default-binding="true">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</scrollpane>
</children>
</grid>
</form>

View File

@ -1,12 +0,0 @@
package de.marhali.easyi18n.ui.panel;
import javax.swing.*;
public class TestPanel {
private JPanel panel1;
private JTextField textField1;
private JTextField textField2;
private JTextField textField3;
private JTextField textField4;
private JTextField textField5;
}

View File

@ -1,4 +1,4 @@
package de.marhali.easyi18n.ui.panel; package de.marhali.easyi18n.ui.renderer;
import com.intellij.ui.JBColor; import com.intellij.ui.JBColor;

View File

@ -1,4 +1,4 @@
package de.marhali.easyi18n.ui.panel; package de.marhali.easyi18n.ui.renderer;
import com.intellij.ide.util.treeView.NodeRenderer; import com.intellij.ide.util.treeView.NodeRenderer;
import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.ItemPresentation;
@ -11,6 +11,11 @@ import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeCellRenderer;
import java.awt.*; import java.awt.*;
/**
* Similar to {@link NodeRenderer} but will will override {@link #getPresentation(Object)} to
* make {@link ItemPresentation} visible.
* @author marhali
*/
public class TreeRenderer extends NodeRenderer { public class TreeRenderer extends NodeRenderer {
@Override @Override

View File

@ -1,65 +0,0 @@
package de.marhali.easyi18n.ui.table;
import org.jetbrains.annotations.Nls;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
public class CustomTableModel implements TableModel {
@Override
public int getRowCount() {
return 2;
}
@Override
public int getColumnCount() {
return 3;
}
@Nls
@Override
public String getColumnName(int columnIndex) {
switch (columnIndex) {
case 0:
return "<html><b>key</b></html>";
case 1:
return "de";
case 2:
return "en";
}
return null;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
return String.class;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return columnIndex == 0 ? "key" : "val";
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
}
@Override
public void addTableModelListener(TableModelListener l) {
}
@Override
public void removeTableModelListener(TableModelListener l) {
}
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.marhali.easyi18n.ui.panel.TableView"> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.marhali.easyi18n.ui.tabs.TableView">
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>

View File

@ -1,24 +1,31 @@
package de.marhali.easyi18n.ui.panel; package de.marhali.easyi18n.ui.tabs;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.table.JBTable; import com.intellij.ui.table.JBTable;
import de.marhali.easyi18n.data.DataStore;
import de.marhali.easyi18n.data.LocalizedNode; import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.model.DataSynchronizer; import de.marhali.easyi18n.model.DataSynchronizer;
import de.marhali.easyi18n.data.Translations; import de.marhali.easyi18n.model.Translations;
import de.marhali.easyi18n.model.KeyedTranslation; import de.marhali.easyi18n.model.KeyedTranslation;
import de.marhali.easyi18n.model.TranslationDelete; import de.marhali.easyi18n.model.TranslationDelete;
import de.marhali.easyi18n.model.table.TableModelTranslator; import de.marhali.easyi18n.model.table.TableModelTranslator;
import de.marhali.easyi18n.ui.dialog.EditDialog; import de.marhali.easyi18n.ui.dialog.EditDialog;
import de.marhali.easyi18n.ui.listener.DeleteKeyListener; import de.marhali.easyi18n.ui.listener.DeleteKeyListener;
import de.marhali.easyi18n.ui.listener.PopupClickListener; import de.marhali.easyi18n.ui.listener.PopupClickListener;
import de.marhali.easyi18n.ui.renderer.TableRenderer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import javax.swing.*; import javax.swing.*;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
/**
* Shows translation state as table.
* @author marhali
*/
public class TableView implements DataSynchronizer { public class TableView implements DataSynchronizer {
private final Project project; private final Project project;

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.marhali.easyi18n.ui.panel.TreeView"> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.marhali.easyi18n.ui.tabs.TreeView">
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>

View File

@ -1,4 +1,4 @@
package de.marhali.easyi18n.ui.panel; package de.marhali.easyi18n.ui.tabs;
import com.intellij.ide.projectView.PresentationData; import com.intellij.ide.projectView.PresentationData;
import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.ActionManager;
@ -6,18 +6,19 @@ import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.ui.treeStructure.Tree; import com.intellij.ui.treeStructure.Tree;
import de.marhali.easyi18n.data.DataStore; import de.marhali.easyi18n.service.DataStore;
import de.marhali.easyi18n.data.LocalizedNode; import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.model.DataSynchronizer; import de.marhali.easyi18n.model.DataSynchronizer;
import de.marhali.easyi18n.data.Translations; import de.marhali.easyi18n.model.Translations;
import de.marhali.easyi18n.model.KeyedTranslation; import de.marhali.easyi18n.model.KeyedTranslation;
import de.marhali.easyi18n.model.TranslationDelete; import de.marhali.easyi18n.model.TranslationDelete;
import de.marhali.easyi18n.model.tree.TreeModelTranslator; import de.marhali.easyi18n.model.tree.TreeModelTranslator;
import de.marhali.easyi18n.ui.action.CollapseTreeViewAction; import de.marhali.easyi18n.ui.action.treeview.CollapseTreeViewAction;
import de.marhali.easyi18n.ui.action.ExpandTreeViewAction; import de.marhali.easyi18n.ui.action.treeview.ExpandTreeViewAction;
import de.marhali.easyi18n.ui.dialog.EditDialog; import de.marhali.easyi18n.ui.dialog.EditDialog;
import de.marhali.easyi18n.ui.listener.DeleteKeyListener; import de.marhali.easyi18n.ui.listener.DeleteKeyListener;
import de.marhali.easyi18n.ui.listener.PopupClickListener; import de.marhali.easyi18n.ui.listener.PopupClickListener;
import de.marhali.easyi18n.ui.renderer.TreeRenderer;
import de.marhali.easyi18n.util.TreeUtil; import de.marhali.easyi18n.util.TreeUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -28,6 +29,10 @@ import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
/**
* Show translation state as tree.
* @author marhali
*/
public class TreeView implements DataSynchronizer { public class TreeView implements DataSynchronizer {
private final Project project; private final Project project;

View File

@ -2,9 +2,9 @@ package de.marhali.easyi18n.util;
import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
import de.marhali.easyi18n.io.translator.JsonTranslatorIO; import de.marhali.easyi18n.io.implementation.JsonTranslatorIO;
import de.marhali.easyi18n.io.translator.PropertiesTranslatorIO; import de.marhali.easyi18n.io.implementation.PropertiesTranslatorIO;
import de.marhali.easyi18n.io.translator.TranslatorIO; import de.marhali.easyi18n.io.TranslatorIO;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -1,6 +1,6 @@
package de.marhali.easyi18n.util; package de.marhali.easyi18n.util;
import de.marhali.easyi18n.data.LocalizedNode; import de.marhali.easyi18n.model.LocalizedNode;
import java.util.List; import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
@ -11,6 +11,11 @@ import java.util.TreeMap;
*/ */
public class MapUtil { public class MapUtil {
/**
* Converts the provided list into a tree map.
* @param list List of nodes
* @return TreeMap based on node key and node object
*/
public static TreeMap<String, LocalizedNode> convertToTreeMap(List<LocalizedNode> list) { public static TreeMap<String, LocalizedNode> convertToTreeMap(List<LocalizedNode> list) {
TreeMap<String, LocalizedNode> map = new TreeMap<>(); TreeMap<String, LocalizedNode> map = new TreeMap<>();

View File

@ -7,8 +7,17 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
/**
* Utility tool to support the translations instance
* @author marhali
*/
public class TranslationsUtil { public class TranslationsUtil {
/**
* Retrieve all sections for the specified path (mostly fullPath)
* @param path The path
* @return Sections. E.g. input user.username.title -> Output: [user, username, title]
*/
public static @NotNull List<String> getSections(@NotNull String path) { public static @NotNull List<String> getSections(@NotNull String path) {
if(!path.contains(".")) { if(!path.contains(".")) {
return new ArrayList<>(Collections.singletonList(path)); return new ArrayList<>(Collections.singletonList(path));
@ -17,6 +26,11 @@ public class TranslationsUtil {
return new ArrayList<>(Arrays.asList(path.split("\\."))); return new ArrayList<>(Arrays.asList(path.split("\\.")));
} }
/**
* Concatenate the given sections to a single string.
* @param sections The sections
* @return Full path. E.g. input [user, username, title] -> Output: user.username.title
*/
public static @NotNull String sectionsToFullPath(@NotNull List<String> sections) { public static @NotNull String sectionsToFullPath(@NotNull List<String> sections) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();

View File

@ -1,14 +1,22 @@
package de.marhali.easyi18n.util; package de.marhali.easyi18n.util;
import com.intellij.ide.projectView.PresentationData; import com.intellij.ide.projectView.PresentationData;
import de.marhali.easyi18n.data.LocalizedNode; import de.marhali.easyi18n.model.LocalizedNode;
import de.marhali.easyi18n.model.tree.TreeModelTranslator;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
/**
* Swing tree utility
* @author marhali
*/
public class TreeUtil { public class TreeUtil {
/**
* Constructs the full path for a given {@link TreePath}
* @param path TreePath
* @return Full key (e.g user.username.title)
*/
public static String getFullPath(TreePath path) { public static String getFullPath(TreePath path) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();

View File

@ -8,6 +8,11 @@ import java.util.Map;
*/ */
public class UiUtil { public class UiUtil {
/**
* Generates a html compliant string which shows all defined translations
* @param messages Contains locales with desired translation
* @return String with html format
*/
public static String generateHtmlTooltip(Map<String, String> messages) { public static String generateHtmlTooltip(Map<String, String> messages) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();

View File

@ -9,6 +9,6 @@
<extensions defaultExtensionNs="com.intellij"> <extensions defaultExtensionNs="com.intellij">
<toolWindow id="Translator" anchor="bottom" factoryClass="de.marhali.easyi18n.TranslatorToolWindowFactory" /> <toolWindow id="Translator" anchor="bottom" factoryClass="de.marhali.easyi18n.TranslatorToolWindowFactory" />
<projectService serviceImplementation="de.marhali.easyi18n.SettingsService" /> <projectService serviceImplementation="de.marhali.easyi18n.service.SettingsService" />
</extensions> </extensions>
</idea-plugin> </idea-plugin>