From 0e4a3ca7da6e9d340f491ac1bb96fafa4732d1e1 Mon Sep 17 00:00:00 2001 From: Ali Azam Rana <85216275+alirana01@users.noreply.github.com> Date: Thu, 7 Sep 2023 11:14:57 +0200 Subject: [PATCH] Exported strings to the messages file for dynamic language --- .../espressif/idf/ui/gcov/GcovFileView.java | 38 +++++++++---------- .../com/espressif/idf/ui/gcov/Messages.java | 31 +++++++++++++++ .../espressif/idf/ui/gcov/messages.properties | 8 ++++ 3 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/Messages.java create mode 100644 bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/messages.properties diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/GcovFileView.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/GcovFileView.java index 9bfad66db..06141725c 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/GcovFileView.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/GcovFileView.java @@ -7,7 +7,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.text.Collator; -import java.text.SimpleDateFormat; +import java.text.DateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -55,9 +55,9 @@ import com.espressif.idf.core.util.IDFUtil; /** - * Gcov file view that can be opened by right clicking on the project. - * It is used to show the gcno/gcda files as one unit for the selected project - * User can launch the eclipse's default gcov viewer by double clicking on the entries + * Gcov file view that can be opened by right clicking on the project. It is used to show the gcno/gcda files as one + * unit for the selected project User can launch the eclipse's default gcov viewer by double clicking on the entries + * * @author Ali Azam Rana * */ @@ -76,7 +76,8 @@ public void createPartControl(Composite parent) table.setLinesVisible(true); table.setHeaderVisible(true); - String[] titles = { "File Name", "Path", "Last Modified GCNO", "Last Modified GCDA", "Size GCNO", "Size GCDA" }; + String[] titles = { Messages.TableCol_FileName, Messages.TableCol_Path, Messages.TableCol_LastModifiedGCNO, + Messages.TableCol_LastModifiedGCDA, Messages.TableCol_SizeGCNO, Messages.TableCol_SizeGCDA }; for (int i = 0; i < titles.length; i++) { TableColumn column = new TableColumn(table, SWT.NONE); @@ -93,7 +94,7 @@ public void handleEvent(Event event) Point pt = new Point(event.x, event.y); TableItem item = table.getItem(pt); IFile file = (IFile) item.getData(); - + if (item != null && file != null) { try @@ -150,7 +151,7 @@ private void refreshList() ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getSelectionService(); IStructuredSelection structuredSelection = (IStructuredSelection) selectionService - .getSelection("org.eclipse.ui.navigator.ProjectExplorer"); + .getSelection("org.eclipse.ui.navigator.ProjectExplorer"); //$NON-NLS-1$ if (structuredSelection != null && !structuredSelection.isEmpty()) { @@ -166,7 +167,7 @@ private void refreshList() { setSelectedProject(GcovUtility.getSelectedProject()); } - + // If no project is selected, ask the user to choose one if (getSelectedProject() == null) { @@ -175,7 +176,7 @@ private void refreshList() PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), new org.eclipse.ui.model.WorkbenchLabelProvider()); dialog.setElements(root.getProjects()); - dialog.setTitle("Select a Project"); + dialog.setTitle(Messages.Dialog_SelectProject_Title); // only continue if the user pressed "OK" if (dialog.open() != Window.OK) @@ -203,49 +204,48 @@ public boolean visit(IResource resource) if ("gcno".equals(file.getFileExtension())) { String parentDir = file.getParent().getRawLocation().toString(); - String partnerFile = parentDir + "/" - + file.getName().substring(0, file.getName().indexOf(".gcno")) + ".gcda"; + String partnerFile = parentDir + "/" //$NON-NLS-1$ + + file.getName().substring(0, file.getName().indexOf(".gcno")) + ".gcda"; //$NON-NLS-1$ //$NON-NLS-2$ if (Files.exists(Paths.get(partnerFile))) { TableItem item = new TableItem(table, SWT.NONE); Image image = PlatformUI.getWorkbench().getEditorRegistry() .getImageDescriptor(file.getName()).createImage(); item.setImage(0, image); - item.setText(0, file.getName().substring(0, file.getName().indexOf(".gcno"))); + item.setText(0, file.getName().substring(0, file.getName().indexOf(".gcno"))); //$NON-NLS-1$ item.setText(1, file.getParent().getFullPath().toString()); // gcno IFileInfo fileInfo = EFS.getLocalFileSystem().getStore(file.getLocationURI()) .fetchInfo(); - SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); - String date = sdf.format(new Date(fileInfo.getLastModified())); + String date = DateFormat.getDateTimeInstance().format(new Date(fileInfo.getLastModified())); item.setText(2, date); // gcda fileInfo = EFS.getLocalFileSystem().getStore(Path.fromOSString(partnerFile)) .fetchInfo(); - item.setText(3, sdf.format(new Date(fileInfo.getLastModified()))); + item.setText(3, DateFormat.getDateTimeInstance().format(new Date(fileInfo.getLastModified()))); java.nio.file.Path path = Paths.get(file.getRawLocationURI()); try { long size = Files.size(path); - item.setText(4, String.valueOf(size) + " bytes"); + item.setText(4, String.valueOf(size) + " bytes"); //$NON-NLS-1$ } catch (Exception e) { - item.setText(4, "Unknown"); + item.setText(4, Messages.Table_Unknown); } path = Paths.get(partnerFile); try { long size = Files.size(path); - item.setText(5, String.valueOf(size) + " bytes"); + item.setText(5, String.valueOf(size) + " bytes"); //$NON-NLS-1$ } catch (Exception e) { - item.setText(5, "Unknown"); + item.setText(5, Messages.Table_Unknown); } item.setData(file); diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/Messages.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/Messages.java new file mode 100644 index 000000000..36bd05bba --- /dev/null +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/Messages.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright 2023 Espressif Systems (Shanghai) PTE LTD. All rights reserved. + * Use is subject to license terms. + *******************************************************************************/ +package com.espressif.idf.ui.gcov; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS +{ + private static final String BUNDLE_NAME = "com.espressif.idf.ui.gcov.messages"; //$NON-NLS-1$ + + public static String TableCol_FileName; + public static String TableCol_Path; + public static String TableCol_LastModifiedGCNO; + public static String TableCol_LastModifiedGCDA; + public static String TableCol_SizeGCNO; + public static String TableCol_SizeGCDA; + public static String Dialog_SelectProject_Title; + public static String Table_Unknown; + + static + { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() + { + } +} diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/messages.properties b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/messages.properties new file mode 100644 index 000000000..5faa6467e --- /dev/null +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/gcov/messages.properties @@ -0,0 +1,8 @@ +TableCol_FileName=File Name +TableCol_Path=Path +TableCol_LastModifiedGCNO=Last Modified GCNO +TableCol_LastModifiedGCDA=Last Modified GCDA +TableCol_SizeGCNO=Size GCNO +TableCol_SizeGCDA=Size GCDA +Dialog_SelectProject_Title=Select a Project +Table_Unknown=Unknown