OPENJPA-1844: Localize user facing strings.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1027190 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Richard G. Curtis 2010-10-25 16:46:03 +00:00
parent c8a5f3d91b
commit ae1e715248
4 changed files with 63 additions and 16 deletions

View File

@ -39,6 +39,7 @@ import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import org.apache.openjpa.instrumentation.jmx.DataCacheJMXInstrumentMBean;
import org.apache.openjpa.lib.util.Localizer;
/**
* <pre>
@ -57,6 +58,8 @@ import org.apache.openjpa.instrumentation.jmx.DataCacheJMXInstrumentMBean;
*/
public class DataCachePanel extends JPanel {
private static final long serialVersionUID = 8273595264174478456L;
private static final Localizer _loc = Localizer.forPackage(DataCachePanel.class);
private DataCacheJMXInstrumentMBean _mbean;
private DataCacheTable _model;
private Map<String, JCheckBox> _typesPanelMap = new ConcurrentHashMap<String, JCheckBox>();
@ -74,18 +77,21 @@ public class DataCachePanel extends JPanel {
add(parentTopPanel, BorderLayout.PAGE_START);
// Panel for action buttons
String actions = _loc.get("datacachepanel.titles.actions").getMessage();
JPanel actionsPanel = new JPanel(new GridLayout(1, 3));
actionsPanel.setBorder(new TitledBorder(LineBorder.createGrayLineBorder(), "Actions"));
actionsPanel.setBorder(new TitledBorder(LineBorder.createGrayLineBorder(), actions));
parentTopPanel.add(actionsPanel, -1);
// Create new panel for [N] children checkboxes
// Don't add anything here yet. This will happen dynamically in updateTypesCached
String knownTypes = _loc.get("datacachepanel.titles.types").getMessage();
_typesPanel = new JPanel(new GridLayout());
_typesPanel.setBorder(new TitledBorder(LineBorder.createGrayLineBorder(), "Currently known types"));
_typesPanel.setBorder(new TitledBorder(LineBorder.createGrayLineBorder(), knownTypes));
parentTopPanel.add(_typesPanel, -1);
// create enabled check box to parent
JCheckBox enableStatisticsCheckBox = new JCheckBox("Statistics enabled", mbean.getStatisticsEnabled());
String statsEnabled = _loc.get("datacachepanel.buttons.stats").getMessage();
JCheckBox enableStatisticsCheckBox = new JCheckBox(statsEnabled, mbean.getStatisticsEnabled());
enableStatisticsCheckBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
boolean enable = (e.getStateChange() == ItemEvent.SELECTED);
@ -94,7 +100,8 @@ public class DataCachePanel extends JPanel {
});
// create clear cache button
JButton clear = new JButton("Clear cache");
String clearButton = _loc.get("datacachepanel.buttons.clear").getMessage();
JButton clear = new JButton(clearButton);
clear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
_mbean.clear();
@ -102,7 +109,8 @@ public class DataCachePanel extends JPanel {
});
// create clear cache button
JButton reset = new JButton("Reset statistics");
String resetButton = _loc.get("datacachepanel.buttons.reset").getMessage();
JButton reset = new JButton(resetButton);
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
_mbean.reset();
@ -155,7 +163,6 @@ public class DataCachePanel extends JPanel {
// Unexpected
ex.printStackTrace();
}
}
}
});

View File

@ -31,6 +31,7 @@ import javax.swing.JPanel;
import javax.swing.SwingWorker;
import org.apache.openjpa.instrumentation.jmx.DataCacheJMXInstrumentMBean;
import org.apache.openjpa.lib.util.Localizer;
import com.sun.tools.jconsole.JConsoleContext;
import com.sun.tools.jconsole.JConsolePlugin;
@ -39,6 +40,9 @@ import com.sun.tools.jconsole.JConsolePlugin;
* DataCachePlugin
*/
public class DataCachePlugin extends JConsolePlugin {
private static final Localizer _loc = Localizer.forPackage(DataCachePlugin.class);
private static final String DATACACHE_MBEAN_QUERY_STRING = "org.apache.openjpa:type=DataCache,*";
private Map<String, JPanel> _tabs;
private Map<DataCacheJMXInstrumentMBean, DataCachePanel> _mbeanPanelMap;
@ -66,10 +70,9 @@ public class DataCachePlugin extends JConsolePlugin {
String cfgId = entry.getKey();
String name = m.getCacheName();
// TODO -- should NLSize this tab.
DataCachePanel panel = new DataCachePanel(m);
String key = "DataCache-" + cfgId + "-" + name;
// This 'shouldn't' ever happen... but it will if we have name collisions for one reason or another.
// This "shouldn't" ever happen... but it will if we have name collisions for one reason or another.
while (res.containsKey(key) == true) {
key = key + "_dup";
}
@ -90,18 +93,18 @@ public class DataCachePlugin extends JConsolePlugin {
connections.add(ctx.getMBeanServerConnection());
connections.addAll(MBeanServerFactory.findMBeanServer(null));
if (connections == null || connections.size() == 0) {
System.err
.println("DataCachePlugin found zero from MBeanServerFactory.findMBeanServer(null) using default");
System.err.println(_loc.get("datacacheplugin.zero.mbeanconnections").getMessage());
}
for (MBeanServerConnection server : connections) {
try {
ObjectName generic = new ObjectName("org.apache.openjpa:type=DataCache,*");
ObjectName generic = new ObjectName(DATACACHE_MBEAN_QUERY_STRING);
ObjectName[] objects = server.queryNames(generic, null).toArray(new ObjectName[0]);
if (objects == null || objects.length == 0) {
System.err
.println("No ObjectNames found matching 'org.apache.openjpa:type=DataCache,*' for MBeanServer "
+ server);
String message =
_loc.get("datacacheplugin.zero.mbeans", new Object[] { DATACACHE_MBEAN_QUERY_STRING, server })
.getMessage();
System.err.println(message);
}
for (ObjectName o : objects) {
DataCacheJMXInstrumentMBean bean = JMX.newMBeanProxy(server, o, DataCacheJMXInstrumentMBean.class);

View File

@ -22,13 +22,19 @@ import java.util.List;
import javax.swing.table.AbstractTableModel;
import org.apache.openjpa.lib.util.Localizer;
/**
* DataCacheTable
*/
public class DataCacheTable extends AbstractTableModel {
private static final long serialVersionUID = -117710809875227870L;
// TODO -- should NLSize these column names
private String[] _cols = { "key", "reads", "hits", "writes" };
private static final Localizer _loc = Localizer.forPackage(DataCacheTable.class);
// Column names -- key, reads, hits, writes
private static final String[] _cols =
{ _loc.get("datacachetable.column.key").getMessage(), _loc.get("datacachetable.column.reads").getMessage(),
_loc.get("datacachetable.column.hits").getMessage(), _loc.get("datacachetable.column.writes").getMessage(), };
// row, col
private Object[][] _tableData;

View File

@ -0,0 +1,31 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
datacachetable.column.key=key
datacachetable.column.reads=reads
datacachetable.column.hits=hits
datacachetable.column.writes=writes
datacacheplugin.zero.mbeanconnections=The DataCache JConsole plugin found zero MBeanServer connections. Please ensure \
that the application is running and configured properly.
datacacheplugin.zero.mbeans=The DataCache JConsole plugin found zero MBeans matching the following query string '{0}' \
for MBeanServerConnection '{1}'. Please ensure that the application is running and configured properly.
datacachepanel.titles.actions=Actions
datacachepanel.titles.types=Currently known types
datacachepanel.buttons.stats=Statistics enabled
datacachepanel.buttons.clear=Clear cache
datacachepanel.buttons.reset=Reset statistics