[Title] save as featur added
authorLee <jy.exe.lee@samsung.com>
Tue, 31 Jul 2012 09:24:52 +0000 (18:24 +0900)
committerLee <jy.exe.lee@samsung.com>
Tue, 31 Jul 2012 09:24:52 +0000 (18:24 +0900)
[Type] new feature
[Module] Dynamic Analyzer
[Priority] normal
[CQ#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/constants/AnalyzerConstants.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/views/CoolbarArea.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/AboutDialog.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/SaveAsDialog.java [new file with mode: 0644]

index d0171a0..189eca7 100644 (file)
@@ -155,8 +155,8 @@ public class AnalyzerConstants {
 \r
     /* save return values */\r
     public static final int ERROR_EXTENSION_FAIL = -1;\r
-    public static final int SUCCESS = 0;\r
-    public static final int ERROR_SAVE_FAIL = 1;\r
+    public static final int SUCCESS = 1;\r
+    public static final int ERROR_SAVE_FAIL = 0;\r
 \r
     /* data size */\r
     public static final int INSERT_DATA_PACKAGE_SIZE = 80;\r
index 3bdd055..03a278f 100755 (executable)
@@ -31,7 +31,6 @@ import org.tizen.dynamicanalyzer.StateManager;
 import org.tizen.dynamicanalyzer.constants.AnalyzerConstants;
 import org.tizen.dynamicanalyzer.constants.DesignConstants;
 import org.tizen.dynamicanalyzer.handlers.ReplayTraceHandler;
-import org.tizen.dynamicanalyzer.handlers.SaveTraceHandler;
 import org.tizen.dynamicanalyzer.handlers.StartStopTraceHandler;
 import org.tizen.dynamicanalyzer.model.AppDesktopInfo;
 import org.tizen.dynamicanalyzer.model.Project;
@@ -44,6 +43,7 @@ import org.tizen.dynamicanalyzer.ui.renderers.TitleComboRenderer;
 import org.tizen.dynamicanalyzer.ui.widgets.AboutDialog;
 import org.tizen.dynamicanalyzer.ui.widgets.ConfigurationDialog;
 import org.tizen.dynamicanalyzer.ui.widgets.OpenTraceDialog;
+import org.tizen.dynamicanalyzer.ui.widgets.SaveAsDialog;
 import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
 import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
 import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonClickEventListener;
@@ -328,11 +328,13 @@ public class CoolbarArea {
 
                                        @Override
                                        public void handleClickEvent(DACustomButton button) {
-                                               int result = AnalyzerUtil
-                                                               .executeCommand(SaveTraceHandler.ID);
+                                               Shell shell = AnalyzerUtil.getWorkbenchWindow().getShell();
+                                               SaveAsDialog dialog = new SaveAsDialog(shell);
+                                               int result = dialog.run();
                                                if (AnalyzerConstants.SUCCESS == result) {
                                                        button.setEnabled(false);
                                                }
+                                               System.out.println("exit");
                                        }
                                });
 
@@ -403,8 +405,8 @@ public class CoolbarArea {
                                                AnalyzerManager.getCurrentPage().setSourceView(
                                                                toggle.isToggled());
 
-//                                             System.out.println(SymbolNameDemangler
-//                                                             .nameDemangle("_ZN3Osp4Base7Runtime14IEventListenerC1Ev"));
+                                               // System.out.println(SymbolNameDemangler
+                                               // .nameDemangle("_ZN3Osp4Base7Runtime14IEventListenerC1Ev"));
 
                                                // theme test
                                                // if (toggle.isToggled()) {
@@ -881,8 +883,6 @@ public class CoolbarArea {
        public void setAppComboText(String text) {
                AppDesktopInfo appInfo = DACommunicator.getAppDesktopInfoByName(text);
                if (null != appInfo) {
-                       System.out.println("combo set communicator appinfo :" //$NON-NLS-1$
-                                       + appInfo.getName() + " exec : " + appInfo.getExecPath()); //$NON-NLS-1$
                        DACommunicator.setSelectedApp(appInfo);
                        appCombo.setText(text);
                }
index 5fd56cd..d358dab 100644 (file)
@@ -54,8 +54,7 @@ public class AboutDialog {
                // shell = new DAWindow(parent, SWT.APPLICATION_MODAL);
                shell = new Shell(parent, SWT.APPLICATION_MODAL | SWT.TITLE);
                shell.setSize(446, 153);
-               FormLayout shellLayout = new FormLayout();
-               shell.setLayout(shellLayout);
+               shell.setLayout(new FormLayout());
                shell.setText(AnalyzerLabels.ABOUT);
 
                Composite base = new Composite(shell, SWT.NONE);
diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/SaveAsDialog.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/SaveAsDialog.java
new file mode 100644 (file)
index 0000000..b3f716d
--- /dev/null
@@ -0,0 +1,250 @@
+package org.tizen.dynamicanalyzer.ui.widgets;
+
+import java.io.File;
+
+import org.eclipse.jface.window.ApplicationWindow;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.tizen.dynamicanalyzer.AnalyzerManager;
+import org.tizen.dynamicanalyzer.ColorResources;
+import org.tizen.dynamicanalyzer.constants.AnalyzerConstants;
+import org.tizen.dynamicanalyzer.model.Project;
+import org.tizen.dynamicanalyzer.model.SnapshotData;
+import org.tizen.dynamicanalyzer.uirecorder.RecorderXml;
+import org.tizen.dynamicanalyzer.utils.AnalyzerUtil;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButton;
+import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonClickEventListener;
+
+public class SaveAsDialog extends ApplicationWindow {
+
+       private int result = 0;
+       private Text textBox = null;
+       private Shell shell = null;
+       private String saveFileName = null;
+       private DAButton okButton = null;
+       private boolean block = false;
+
+       private static IExceptionHandler exceptionHandler = new DefaultExceptionHandler();
+
+       public SaveAsDialog(Shell parentShell) {
+               super(parentShell);
+               shell = new Shell(parentShell, SWT.TITLE | SWT.APPLICATION_MODAL);
+       }
+
+       public int run() {
+               block = true;
+               shell.setLayout(new FormLayout());
+               shell.setSize(325, 110);
+               shell.setBackground(ColorResources.DIALOG_BG_UPPER);
+
+               Label label = new Label(shell, SWT.TRANSPARENT);
+               FormData data = new FormData();
+               data.top = new FormAttachment(0, 11);
+               data.left = new FormAttachment(0, 12);
+               data.height = 15;
+               data.width = 150;
+               label.setLayoutData(data);
+               label.setText("Enter the save file name");
+               label.setBackground(ColorResources.DIALOG_BG_UPPER);
+
+               textBox = new Text(shell, SWT.SINGLE);
+               data = new FormData();
+               data.top = new FormAttachment(label, 10);
+               data.left = new FormAttachment(0, 9);
+               data.height = 22;
+               data.width = 200;
+               textBox.setLayoutData(data);
+               textBox.setBackground(ColorResources.VIEW_BG_COLOR);
+               textBox.addKeyListener(new KeyListener() {
+
+                       @Override
+                       public void keyReleased(KeyEvent e) {
+                               // TODO Auto-generated method stub
+                               if (!checkValidFileName(textBox.getText())) {
+                                       okButton.setEnabled(false);
+                               } else {
+                                       okButton.setEnabled(true);
+                               }
+                       }
+
+                       @Override
+                       public void keyPressed(KeyEvent e) {
+                               // TODO Auto-generated method stub
+
+                       }
+               });
+
+               okButton = new DAButton(shell, SWT.NONE);
+               data = new FormData();
+               data.top = new FormAttachment(label, 10);
+               data.left = new FormAttachment(textBox, 9);
+               data.height = 28;
+               data.width = 90;
+               okButton.setLayoutData(data);
+               okButton.setText("OK");
+               okButton.addClickListener(okButtonListener);
+
+               saveFileName = getSaveFileName();
+               if (null == saveFileName) {
+                       // create warning message box
+                       return result;
+               } else {
+                       textBox.setText(saveFileName);
+                       String textString = textBox.getText();
+                       textBox.setSelection(0, textString.length());
+               }
+
+               shell.open();
+               if (block) {
+                       runEventLoop(shell);
+               }
+
+               shell.dispose();
+               return result;
+       }
+
+       private DACustomButtonClickEventListener okButtonListener = new DACustomButtonClickEventListener() {
+
+               @Override
+               public void handleClickEvent(DACustomButton button) {
+                       saveFileName = textBox.getText();
+                       if (executeSaveTrace()) {
+                               result = AnalyzerConstants.SUCCESS;
+                       }
+                       shell.dispose();
+               }
+       };
+
+       private String getSaveFileName() {
+               Project project = AnalyzerManager.getProject();
+               String sourcePath = project.getSavePath();
+               String[] splitSourcePath = null;
+               if (AnalyzerUtil.isWin()) {
+                       splitSourcePath = sourcePath.split("\\\\"); //$NON-NLS-1$
+               } else if (AnalyzerUtil.isMac()) {
+                       splitSourcePath = sourcePath.split("\\/"); //$NON-NLS-1$
+               } else {
+                       splitSourcePath = sourcePath.split("\\/"); //$NON-NLS-1$
+               }
+
+               String saveFileName = new String(
+                               splitSourcePath[splitSourcePath.length - 1]);
+               if (null == saveFileName || saveFileName.isEmpty()) {
+                       return null;
+               }
+               return saveFileName;
+       }
+
+       private boolean executeSaveTrace() {
+               Project project = AnalyzerManager.getProject();
+               String sourcePath = project.getSavePath();
+
+               String targetPath = AnalyzerConstants.DYNAMIC_ANALYZER_SAVE_PATH
+                               + File.separator + saveFileName;
+               String targetImagePath = targetPath + File.separator
+                               + AnalyzerConstants.IMAGE_FOLDER_NAME;
+
+               File targetFolder = new File(targetImagePath);
+               if (!targetFolder.isDirectory()) {
+                       targetFolder.mkdirs();
+               }
+               String targetFilePath = targetPath + File.separator
+                               + AnalyzerConstants.DATABASE_NAME;
+               String sourceFilePath = sourcePath + File.separator
+                               + AnalyzerConstants.DATABASE_NAME;
+               AnalyzerUtil.copyFile(sourceFilePath, targetFilePath);
+
+               String sourceUIRecorderPath = sourcePath + File.separator
+                               + RecorderXml.xmlFileName;
+               String targetUIRecorderPath = targetPath + File.separator
+                               + RecorderXml.xmlFileName;
+               if (new File(sourceUIRecorderPath).exists()) {
+                       AnalyzerUtil.copyFile(sourceUIRecorderPath, targetUIRecorderPath);
+               }
+
+               project.setSavePath(targetPath);
+
+               // delete source file and folder
+               // save trace callstack
+               String sourceImgFolder = sourcePath
+                               + AnalyzerConstants.IMAGE_FOLDER_NAME;
+               AnalyzerUtil.saveTraceImage(sourceImgFolder, targetImagePath);
+               try {
+                       project.closeConnection();
+                       boolean success = AnalyzerUtil.deleteFile(new File(sourcePath));
+                       AnalyzerManager.removeFromProjectList(sourcePath);
+                       if (success) {
+                               // add snapshot model update
+                               SnapshotData.getInstance().update();
+                               System.out.println("save complete!!"); //$NON-NLS-1$
+                       } else {
+                               System.out.println("save fail..."); //$NON-NLS-1$
+                               return false;
+                       }
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       return false;
+               }
+               return true;
+       }
+
+       private boolean checkValidFileName(String str) {
+               if (str == null || str.isEmpty() || str.contains("\\")
+                               || str.contains("/") || str.contains(":") || str.contains("*")
+                               || str.contains("\\?") || str.contains("\"")
+                               || str.contains("<") || str.contains(">") || str.contains("|")) {
+                       return false;
+               }
+               return true;
+       }
+
+       private void runEventLoop(Shell loopShell) {
+
+               // Use the display provided by the shell if possible
+               Display display;
+               if (shell == null) {
+                       display = Display.getCurrent();
+               } else {
+                       display = loopShell.getDisplay();
+               }
+
+               while (loopShell != null && !loopShell.isDisposed()) {
+                       try {
+                               if (!display.readAndDispatch()) {
+                                       display.sleep();
+                               }
+                       } catch (Throwable e) {
+                               exceptionHandler.handleException(e);
+                       }
+               }
+               if (!display.isDisposed())
+                       display.update();
+       }
+
+       private static class DefaultExceptionHandler implements IExceptionHandler {
+               /*
+                * (non-Javadoc)
+                * 
+                * @see
+                * org.eclipse.jface.window.Window.IExceptionHandler#handleException
+                * (java.lang.Throwable)
+                */
+               public void handleException(Throwable t) {
+                       if (t instanceof ThreadDeath) {
+                               // Don't catch ThreadDeath as this is a normal occurrence when
+                               // the thread dies
+                               throw (ThreadDeath) t;
+                       }
+                       // Try to keep running.
+                       t.printStackTrace();
+               }
+       }
+}