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;
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;
@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");
}
});
AnalyzerManager.getCurrentPage().setSourceView(
toggle.isToggled());
-// System.out.println(SymbolNameDemangler
-// .nameDemangle("_ZN3Osp4Base7Runtime14IEventListenerC1Ev"));
+ // System.out.println(SymbolNameDemangler
+ // .nameDemangle("_ZN3Osp4Base7Runtime14IEventListenerC1Ev"));
// theme test
// if (toggle.isToggled()) {
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);
}
--- /dev/null
+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();
+ }
+ }
+}