Skip to content

Commit

Permalink
PluginInstaller: make it as singleton instance
Browse files Browse the repository at this point in the history
- Download remote plugin list when requested and keep it during session.

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
  • Loading branch information
miurahr committed Apr 13, 2022
1 parent 2e65928 commit 6249163
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 174 deletions.
2 changes: 1 addition & 1 deletion src/org/omegat/core/threads/PluginDownloadThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void run() {
} else if (!checksum.equals(calculateSha256(temporaryFilePath))) {
Log.log("Checksum error of plugin file.");
} else {
PluginInstaller.install(temporaryFilePath, true);
PluginInstaller.getInstance().install(temporaryFilePath, true);
}
} catch (IOException | NoSuchAlgorithmException e) {
e.printStackTrace();
Expand Down
77 changes: 0 additions & 77 deletions src/org/omegat/gui/dialogs/ChoosePluginFile.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package org.omegat.gui.preferences.view;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.DefaultTableModel;
Expand All @@ -47,7 +46,7 @@ public class PluginInfoTableModel extends DefaultTableModel {
private final List<PluginInformation> listPlugins;

public PluginInfoTableModel() {
listPlugins = new ArrayList<>(PluginInstaller.getPluginInformations().values());
listPlugins = PluginInstaller.getInstance().getPluginList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
glossaries, and translation leveraging into updated projects.
Copyright (C) 2016 Aaron Madlon-Kay
2022 Hiroshi Miura
Home page: http://www.omegat.org/
Support center: https://omegat.org/support
Expand All @@ -25,34 +26,28 @@

package org.omegat.gui.preferences.view;

import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;

import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URL;

import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.table.TableRowSorter;

import org.omegat.core.Core;
import org.omegat.core.data.PluginInformation;
import org.omegat.core.threads.PluginDownloadThread;
import org.omegat.gui.dialogs.ChoosePluginFile;
import org.omegat.gui.preferences.BasePreferencesController;
import org.omegat.util.Log;
import org.omegat.util.OStrings;
import org.omegat.util.PluginInstaller;
import org.omegat.util.gui.TableColumnSizer;

/**
* @author Aaron Madlon-Kay
*/
public class PluginsPreferencesController extends BasePreferencesController {

public static final String PLUGINS_WIKI_URL = "https://sourceforge.net/p/omegat/wiki/Plugins/";
private PluginsPreferencesPanel panel;
private PluginDetailsPane pluginDetailsPane;
private PluginDetailHeader pluginDetailHeader;
Expand Down Expand Up @@ -130,8 +125,7 @@ final void selectRowAction(ListSelectionEvent evt) {
}
setRestartRequired(true);
});
StringBuilder detailTextBuilder = new StringBuilder(formatDetailText(model.getItemAt(rowIndex)));
pluginDetailsPane.setText(detailTextBuilder.toString());
pluginDetailsPane.setText(formatDetailText(model.getItemAt(rowIndex)));
}
}

Expand All @@ -149,7 +143,7 @@ private void initGui() {
pluginDetailsPane = new PluginDetailsPane();
panel.panelPluginDetails.add(pluginDetailHeader);
panel.panelPluginDetails.add(pluginDetailsPane);
panel.scrollTable.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS);
panel.scrollTable.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
panel.scrollTable.getViewport().setViewSize(new Dimension(250, 350));

PluginInfoTableModel model = (PluginInfoTableModel) panel.tablePluginsInfo.getModel();
Expand All @@ -158,16 +152,6 @@ private void initGui() {
panel.tablePluginsInfo.getSelectionModel().addListSelectionListener(this::selectRowAction);
panel.tablePluginsInfo.setPreferredScrollableViewportSize(panel.tablePluginsInfo.getPreferredSize());
TableColumnSizer.autoSize(panel.tablePluginsInfo, 0, true);

panel.installPluginsButton.setText(OStrings.getString("PREFS_PLUGINS_INSTALL_FROM_DISK"));
panel.installPluginsButton.addActionListener(e -> {
ChoosePluginFile choosePluginFile = new ChoosePluginFile();
if (JFileChooser.APPROVE_OPTION == choosePluginFile.showOpenDialog(Core.getMainWindow().getApplicationFrame())) {
if (PluginInstaller.install(choosePluginFile.getSelectedFile(), false)) {
setRestartRequired(true);
}
}
});
}

@Override
Expand Down
36 changes: 0 additions & 36 deletions src/org/omegat/gui/preferences/view/PluginsPreferencesPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,6 @@
<Property name="axis" type="int" value="3"/>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="panelInfo">

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
<SubComponents>
<Component class="javax.swing.Box$Filler" name="filler1">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[32767, 5]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 5]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 5]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.VerticalStrut"/>
</AuxValues>
</Component>
<Component class="javax.swing.JButton" name="installPluginsButton">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/omegat/Bundle.properties" key="PREFS_PLUGINS_INSTALL_FROM_DISK" replaceFormat="OStrings.getString(&quot;{key}&quot;)"/>
</Property>
<Property name="alignmentY" type="float" value="0.0"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="installPluginsButtonActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
Expand Down
24 changes: 0 additions & 24 deletions src/org/omegat/gui/preferences/view/PluginsPreferencesPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package org.omegat.gui.preferences.view;

import javax.swing.JPanel;
import org.omegat.util.OStrings;

/**
* @author Aaron Madlon-Kay
Expand All @@ -48,9 +47,6 @@ public PluginsPreferencesPanel() {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

panelInfo = new javax.swing.JPanel();
filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 5), new java.awt.Dimension(0, 5), new java.awt.Dimension(32767, 5));
installPluginsButton = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
panelPluginsInfo = new javax.swing.JPanel();
scrollTable = new javax.swing.JScrollPane();
Expand All @@ -61,19 +57,6 @@ private void initComponents() {
setMinimumSize(new java.awt.Dimension(250, 200));
setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));

panelInfo.add(filler1);

org.openide.awt.Mnemonics.setLocalizedText(installPluginsButton, OStrings.getString("PREFS_PLUGINS_INSTALL_FROM_DISK")); // NOI18N
installPluginsButton.setAlignmentY(0.0F);
installPluginsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
installPluginsButtonActionPerformed(evt);
}
});
panelInfo.add(installPluginsButton);

add(panelInfo);

jPanel1.setMaximumSize(new java.awt.Dimension(65534, 600));
jPanel1.setMinimumSize(new java.awt.Dimension(200, 23));
jPanel1.setLayout(new java.awt.GridLayout(1, 2));
Expand All @@ -96,15 +79,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
add(jPanel1);
}// </editor-fold>//GEN-END:initComponents

private void installPluginsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_installPluginsButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_installPluginsButtonActionPerformed

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.Box.Filler filler1;
javax.swing.JButton installPluginsButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel panelInfo;
javax.swing.JPanel panelPluginDetails;
private javax.swing.JPanel panelPluginsInfo;
javax.swing.JScrollPane scrollTable;
Expand Down

0 comments on commit 6249163

Please sign in to comment.