From 299853a08abeb9c8e7e01ab72cd8cbbfb598f1af Mon Sep 17 00:00:00 2001 From: greatim Date: Thu, 28 Aug 2014 16:23:23 +0900 Subject: [PATCH] SAVE: add to save rest of data add mechanism to save the data that cannot be inserted to database at runtime Change-Id: I8ba758e0bc55e963ace1c390ac8f33618866d8a9 Signed-off-by: greatim --- .../handlers/CommandActionHandler.java | 61 ++++++++++++++++++++++ .../tizen/dynamicanalyzer/nl/AnalyzerLabels.java | 1 + .../dynamicanalyzer/nl/AnalyzerLabels.properties | 1 + .../swap/logparser/DataManagerRegistry.java | 6 +++ .../dynamicanalyzer/ui/toolbar/SaveAsDialog.java | 60 +++------------------ .../dynamicanalyzer/ui/toolbar/ToolbarArea.java | 8 +++ 6 files changed, 84 insertions(+), 53 deletions(-) create mode 100644 org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/CommandActionHandler.java diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/CommandActionHandler.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/CommandActionHandler.java new file mode 100644 index 0000000..8189a8e --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/CommandActionHandler.java @@ -0,0 +1,61 @@ +package org.tizen.dynamicanalyzer.handlers; + +import java.io.File; + +import org.tizen.dynamicanalyzer.common.AnalyzerConstants; +import org.tizen.dynamicanalyzer.common.AnalyzerManager; +import org.tizen.dynamicanalyzer.common.path.PathManager; +import org.tizen.dynamicanalyzer.database.SqlConnectionManager; +import org.tizen.dynamicanalyzer.project.Project; +import org.tizen.dynamicanalyzer.sql.SqlManager; +import org.tizen.dynamicanalyzer.swap.logparser.DataManagerRegistry; +import org.tizen.dynamicanalyzer.swap.logparser.PageDataManager; +import org.tizen.dynamicanalyzer.util.Logger; +import org.tizen.dynamicanalyzer.utils.AnalyzerUtil; + +public class CommandActionHandler { + public static boolean save(String saveFileName) { + Project project = AnalyzerManager.getProject(); + String sourcePath = project.getSavePath(); + String targetPath = PathManager.DA_SAVE_PATH + File.separator + + saveFileName; + + // save rest data before closing connection to db + DataManagerRegistry.saveData(); + + SqlManager.getInstance().closeConnection(); + SqlConnectionManager.closeConnection(); + + File sourceFolder = new File(sourcePath); + if (!sourceFolder.isDirectory()) { + if (!sourceFolder.mkdirs()) { + Logger.debug("source directory create failed..."); + return false; + } + } + + File targetFolder = new File(targetPath); + if (!targetFolder.isDirectory()) { + if (!targetFolder.mkdirs()) { + Logger.debug("target directory create failed..."); + return false; + } + } + AnalyzerUtil.copyDirectory(sourceFolder, targetFolder); + project.setSavePath(targetPath); + + boolean success = AnalyzerUtil.deleteFile(new File(sourcePath)); + if (success) { + // add snapshot model update + Logger.debug("save complete!!"); //$NON-NLS-1$ + } else { + Logger.debug("save fail..."); //$NON-NLS-1$ + } + + // establish db connection with new path + SqlConnectionManager.establishConnection(project.getSavePath() + + File.separator + AnalyzerConstants.DATABASE_NAME); + + return success; + } +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.java index 2e1f711..b33c154 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.java @@ -167,6 +167,7 @@ public class AnalyzerLabels extends NLS { public static String FIND_DLG_WHOLE_WORD; public static String SAVE_TRACE_DLG_SAVE_FILE_NAME; + public static String SAVE_FAILED; public static String OPEN_TRACE_PROGRESS_LOADING; public static String OPEN_TRACE_PROGRESS_VERSION_INVALID; diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.properties b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.properties index d1d3556..b5e23f1 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.properties +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.properties @@ -142,6 +142,7 @@ FIND_DLG_CASE_SENSITIVE=Case sensitive FIND_DLG_WHOLE_WORD=Whole word SAVE_TRACE_DLG_SAVE_FILE_NAME=Enter save file name +SAVE_FAILED=Failed to save the tracing result PATH_WARNING=Please install the Tizen SDK OS_WARNING=Current OS not supported. Please check your OS. diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/logparser/DataManagerRegistry.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/logparser/DataManagerRegistry.java index 940e7dd..93bb98e 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/logparser/DataManagerRegistry.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/logparser/DataManagerRegistry.java @@ -76,6 +76,12 @@ public class DataManagerRegistry { entry.getValue().updateLog(pack); } } + + public static void saveData() { + for (Map.Entry entry : dataManagers.entrySet()) { + entry.getValue().saveData(null); + } + } public static void openData() { for (Map.Entry entry : dataManagers.entrySet()) { diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/SaveAsDialog.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/SaveAsDialog.java index 32399f4..3e0d3da 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/SaveAsDialog.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/SaveAsDialog.java @@ -26,8 +26,6 @@ package org.tizen.dynamicanalyzer.ui.toolbar; -import java.io.File; - import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; @@ -43,20 +41,16 @@ import org.eclipse.swt.widgets.Shell; import org.tizen.dynamicanalyzer.appearance.DesignConstants; import org.tizen.dynamicanalyzer.common.AnalyzerConstants; import org.tizen.dynamicanalyzer.common.AnalyzerManager; -import org.tizen.dynamicanalyzer.common.path.PathManager; import org.tizen.dynamicanalyzer.constant.CommonConstants; -import org.tizen.dynamicanalyzer.database.SqlConnectionManager; import org.tizen.dynamicanalyzer.nl.AnalyzerLabels; import org.tizen.dynamicanalyzer.nl.WidgetLabels; import org.tizen.dynamicanalyzer.project.Project; import org.tizen.dynamicanalyzer.resources.ColorResources; import org.tizen.dynamicanalyzer.resources.FontResources; import org.tizen.dynamicanalyzer.resources.ImageResources; -import org.tizen.dynamicanalyzer.sql.SqlManager; import org.tizen.dynamicanalyzer.util.CommonUtil; import org.tizen.dynamicanalyzer.util.Logger; import org.tizen.dynamicanalyzer.util.WorkbenchUtil; -import org.tizen.dynamicanalyzer.utils.AnalyzerUtil; import org.tizen.dynamicanalyzer.widgets.button.DACustomButton; import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonClickEventListener; import org.tizen.dynamicanalyzer.widgets.da.base.DAButton; @@ -160,7 +154,7 @@ public class SaveAsDialog extends DAMessageBox { cancelButton.setText(WidgetLabels.CANCEL); cancelButton.addClickListener(cancelButtonListener); - saveFileName = getSaveFileName(); + saveFileName = getDefaultSaveFileName(); if (null == saveFileName) { // create warning message box Logger.debug("save file name is null"); @@ -173,6 +167,10 @@ public class SaveAsDialog extends DAMessageBox { return true; } + + public String getSaveFileName() { + return saveFileName; + } private DACustomButtonClickEventListener okButtonListener = new DACustomButtonClickEventListener() { @@ -185,9 +183,7 @@ public class SaveAsDialog extends DAMessageBox { saveFileName = old.substring(0, MAX_SAVE_FILE_NAME_LENGTH - 1); } - if (executeSaveTrace()) { - result = AnalyzerConstants.SUCCESS; - } + result = AnalyzerConstants.SUCCESS; shell.dispose(); } }; @@ -216,7 +212,7 @@ public class SaveAsDialog extends DAMessageBox { } }; - private String getSaveFileName() { + private String getDefaultSaveFileName() { Project project = AnalyzerManager.getProject(); String sourcePath = project.getSavePath(); String[] splitSourcePath = null; @@ -246,48 +242,6 @@ public class SaveAsDialog extends DAMessageBox { return saveFileName; } - private boolean executeSaveTrace() { - Project project = AnalyzerManager.getProject(); - String sourcePath = project.getSavePath(); - String targetPath = PathManager.DA_SAVE_PATH + File.separator - + saveFileName; - - SqlManager.getInstance().closeConnection(); - SqlConnectionManager.closeConnection(); - - File sourceFolder = new File(sourcePath); - if (!sourceFolder.isDirectory()) { - if (!sourceFolder.mkdirs()) { - Logger.debug("source directory create failed..."); - return false; - } - } - - File targetFolder = new File(targetPath); - if (!targetFolder.isDirectory()) { - if (!targetFolder.mkdirs()) { - Logger.debug("target directory create failed..."); - return false; - } - } - AnalyzerUtil.copyDirectory(sourceFolder, targetFolder); - project.setSavePath(targetPath); - - boolean success = AnalyzerUtil.deleteFile(new File(sourcePath)); - if (success) { - // add snapshot model update - Logger.debug("save complete!!"); //$NON-NLS-1$ - } else { - Logger.debug("save fail..."); //$NON-NLS-1$ - } - - // establish db connection with new path - SqlConnectionManager.establishConnection(project.getSavePath() - + File.separator + AnalyzerConstants.DATABASE_NAME); - - return success; - } - private boolean checkValidFileName(String str) { if (str == null || str.contains("\\") //$NON-NLS-1$ diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/ToolbarArea.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/ToolbarArea.java index ee31bf2..d4cc79c 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/ToolbarArea.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/ToolbarArea.java @@ -48,6 +48,7 @@ import org.tizen.dynamicanalyzer.common.AnalyzerManager; import org.tizen.dynamicanalyzer.common.GlobalInformation; import org.tizen.dynamicanalyzer.communicator.DACommunicator; import org.tizen.dynamicanalyzer.constant.CommonConstants; +import org.tizen.dynamicanalyzer.handlers.CommandActionHandler; import org.tizen.dynamicanalyzer.handlers.ReplayTraceHandler; import org.tizen.dynamicanalyzer.model.DeviceInfo; import org.tizen.dynamicanalyzer.nl.AnalyzerLabels; @@ -378,6 +379,13 @@ public class ToolbarArea { SaveAsDialog dialog = new SaveAsDialog(shell); Object result = dialog.open(); if (null != result) { + if (!CommandActionHandler.save(dialog.getSaveFileName())) { + DADialog warninglog = new DADialog(shell, SWT.NONE); + warninglog.setIcon(ImageResources.DIALOG_WARNING_ICON); + warninglog.setMessage(AnalyzerLabels.SAVE_FAILED); + warninglog.open(); + } + button.setButtonEnabled(false); } } -- 2.7.4