From: dongkyu6 lee Date: Mon, 9 May 2016 08:30:50 +0000 (+0900) Subject: [SRADA-517] Create menu bar X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7651b1dac45aa70bb569592f7f95ad603e311586;p=sdk%2Ftools%2Fdynamic-analyzer.git [SRADA-517] Create menu bar - Seperated to MenuBar and refactoring - Modified save and load feature This needs more test. - Menu - New : Clear tracing data and show feature dialog Load : Load tracing data from zip file Save : Save tracing data to zip file. This menu is enable after tracing. Exit : Exit DA. Change-Id: Ifef1bc8039618c32919ab02efce279dae16b81c2 --- diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StopTraceManager.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StopTraceManager.java index bd8a020..4cade1b 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StopTraceManager.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/control/StopTraceManager.java @@ -25,19 +25,14 @@ */ package org.tizen.dynamicanalyzer.control; -import java.util.List; - import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; import org.tizen.dynamicanalyzer.common.DAResult; import org.tizen.dynamicanalyzer.common.Global; import org.tizen.dynamicanalyzer.common.DAState; import org.tizen.dynamicanalyzer.communicator.DACommunicator; -import org.tizen.dynamicanalyzer.control.ProgressTable.PHASE; -import org.tizen.dynamicanalyzer.control.ProgressTable.STAGE; import org.tizen.dynamicanalyzer.handlers.ReplayManager; import org.tizen.dynamicanalyzer.handlers.UIAction; -import org.tizen.dynamicanalyzer.nl.AnalyzerLabels; +import org.tizen.dynamicanalyzer.nl.MenuBarLabels; import org.tizen.dynamicanalyzer.project.Project; import org.tizen.dynamicanalyzer.shortcut.ShortCutManager; import org.tizen.dynamicanalyzer.swap.communicator.DataChannelThread; @@ -47,6 +42,7 @@ import org.tizen.dynamicanalyzer.swap.logparser.MessageParser; import org.tizen.dynamicanalyzer.ui.info.callstack.CallStackInserter; import org.tizen.dynamicanalyzer.ui.info.screenshot.ScreenshotTimer; import org.tizen.dynamicanalyzer.ui.page.BaseView; +import org.tizen.dynamicanalyzer.ui.page.MenuBar; import org.tizen.dynamicanalyzer.ui.page.UpdateViewTimer; import org.tizen.dynamicanalyzer.ui.timeline.dlog.DADlogReceiver; import org.tizen.dynamicanalyzer.ui.toolbar.Toolbar; @@ -219,25 +215,17 @@ public class StopTraceManager implements Runnable { // set shortcut and toolbar UI as DA state ShortCutManager.getInstance().setEnabled(true); Toolbar.INSTANCE.changeUIState(DAState.getCurrentState()); + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + MenuBar.getInstance().setMenuItemEnable(MenuBarLabels.FILE_SAVE, true); + } + }); + + } }); enableToolBar.start(); } } - - private void setProgressPercent(int percent) { - final int per = percent; - if (progressDlg != null) { - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - progressDlg.setValue(per); - } - }); - } - } - - private void testCancel() throws InterruptedException { - // do nothing - } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/CommandAction.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/CommandAction.java index 97956d3..5a6d36a 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/CommandAction.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/CommandAction.java @@ -40,10 +40,10 @@ import org.tizen.dynamicanalyzer.project.Project; import org.tizen.dynamicanalyzer.shortcut.ShortCutManager; import org.tizen.dynamicanalyzer.swap.logparser.DataManagerRegistry; import org.tizen.dynamicanalyzer.ui.interactive.data.InteractiveDataManager; -import org.tizen.dynamicanalyzer.ui.timeline.TimelinePage; import org.tizen.dynamicanalyzer.ui.toolbar.Toolbar; import org.tizen.dynamicanalyzer.util.Logger; import org.tizen.dynamicanalyzer.utils.AnalyzerUtil; +import org.tizen.dynamicanalyzer.utils.ZipUtils; public class CommandAction { @@ -90,6 +90,54 @@ public class CommandAction { return success; } + + public static boolean saveToZip(String saveFileName) { + Project project = Global.getProject(); + String sourcePath = project.getSavePath(); + + File sourceFolder = new File(sourcePath); + if (!sourceFolder.isDirectory()) { + return false; + } + + try { + ZipUtils.zip(sourcePath, saveFileName); + } + catch(Exception ex) { + return false; + } + + return true; + } + + public static String loadFromZip(String zipfile) { + String output = null; + File zip = new File(zipfile); + + if(!zip.getName().toLowerCase().endsWith(".zip")){ + return null; + } + + File tempDir = new File(PathManager.DA_TEMP_FOLDER_PATH); + output = tempDir.getPath() + File.separator + zip.getName().replace(".zip", ""); + + File outputfoler = new File(output); + + if(outputfoler.exists()) { + outputfoler.delete(); + } + + outputfoler.mkdirs(); + + try { + ZipUtils.unzip(zip, outputfoler, false); + } + catch(Exception ex) { + return null; + } + + return output; + } public static void startTrace(boolean bFromIDE) { // only when trace is not running, trace can be started diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/ExitHandler.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/ExitHandler.java index 3b1c4ce..9cc4270 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/ExitHandler.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/handlers/ExitHandler.java @@ -32,6 +32,7 @@ import org.eclipse.core.commands.ExecutionException; import org.tizen.dynamicanalyzer.common.AnalyzerManager; import org.tizen.dynamicanalyzer.common.DAResult; import org.tizen.dynamicanalyzer.common.DAResult.ErrorCode; +import org.tizen.dynamicanalyzer.common.DAState; import org.tizen.dynamicanalyzer.communicator.DACommunicator; import org.tizen.dynamicanalyzer.communicator.DeviceManager; import org.tizen.dynamicanalyzer.communicator.IDECommunicator; @@ -45,8 +46,15 @@ public class ExitHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { AnalyzerManager.setExit(true); - CommandAction.stopTrace(new DAResult(ErrorCode.ERR_BY_USER_CANCEL), false); - + if(DAState.isRunning()) { + CommandAction.stopTrace(new DAResult(ErrorCode.ERR_BY_USER_CANCEL), false); + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } + SideWorker.INSTANCE.stop(); IDECommunicator.stopIDEcommunicatorThread(); DACommunicator.pullDaemonLog(); diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/MenuBarLabels.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/MenuBarLabels.java new file mode 100644 index 0000000..f6441d9 --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/MenuBarLabels.java @@ -0,0 +1,74 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Dongkye Lee + * Jaeyong Lee + * Gihun Chang + * + * Licensed 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. + * + */ + + +package org.tizen.dynamicanalyzer.nl; + +import org.eclipse.osgi.util.NLS; + +public class MenuBarLabels extends NLS { + + private static final String BUNDLE_NAME = "org.tizen.dynamicanalyzer.nl.MenuBarLabels"; + + public static String FILE; + public static String FILE_NEW; + public static String FILE_LOAD; + public static String FILE_SAVE; + public static String FILE_EXIT; + public static String FILE_LOAD_DIALOG_TITLE; + public static String FILE_SAVE_DIALOG_TITLE; + + public static String ANALYZE; + public static String ANALYZE_SEARCH; + public static String ANALYZE_TARGET; + public static String ANALYZE_SCREENSHOT; + public static String ANALYZE_PREFENCES; + public static String ANALYZE_SET_AS_DEFAULT; + + public static String VIEW; + public static String VIEW_DETAIL; + public static String VIEW_REPORT; + public static String VIEW_STATISTICS; + public static String VIEW_TRACE; + public static String VIEW_FUNCTION_PROFILING; + public static String VIEW_NAVIGATE; + public static String VIEW_ZOOM_IN; + public static String VIEW_ZOOM_OUT; + public static String VIEW_MOVE_LEFT; + public static String VIEW_MOVE_RIGHT; + public static String VIEW_MOVE_FIRST; + public static String VIEW_MOVE_END; + + public static String HELP; + public static String HELP_HOWTO; + public static String HELP_BUGREPORT; + public static String HELP_ABOUT; + + static { + NLS.initializeMessages(BUNDLE_NAME, MenuBarLabels.class); + } + + private MenuBarLabels() { + } +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/MenuBarLabels.properties b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/MenuBarLabels.properties new file mode 100644 index 0000000..aa51fe7 --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/MenuBarLabels.properties @@ -0,0 +1,37 @@ +#File menu +FILE=File +FILE_NEW=New +FILE_LOAD=Load +FILE_SAVE=Save +FILE_EXIT=Exit +FILE_LOAD_DIALOG_TITLE=Load tracing data from zip +FILE_SAVE_DIALOG_TITLE=Save tracing data to zip + +#Analyze Menu +ANALYZE=Analyze +ANALYZE_SEARCH=Search +ANALYZE_TARGET=Target +ANALYZE_SCREENSHOT=Screenshot +ANALYZE_PREFENCES=Preferences +ANALYZE_SET_AS_DEFAULT=Set as default features + +#View Menu +VIEW=View +VIEW_DETAIL=Detail +VIEW_REPORT=Report +VIEW_STATISTICS=Statistics +VIEW_TRACE=Trace +VIEW_FUNCTION_PROFILING=Function Profiling +VIEW_NAVIGATE=Navigate +VIEW_ZOOM_IN=Zoom In +VIEW_ZOOM_OUT=Zoom Out +VIEW_MOVE_LEFT=Move Left +VIEW_MOVE_RIGHT=Move Right +VIEW_MOVE_FIRST=Move First +VIEW_MOVE_END=Move End + +#Help Menu +HELP=Help +HELP_HOWTO=How to use Dynamic Analyzer +HELP_BUGREPORT=Bug Report +HELP_ABOUT=About \ No newline at end of file diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/BaseView.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/BaseView.java index 8acccf2..e04ae81 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/BaseView.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/BaseView.java @@ -33,17 +33,15 @@ import java.util.List; import java.util.Set; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.part.ViewPart; import org.tizen.dynamicanalyzer.annotation.UIMethod; +import org.tizen.dynamicanalyzer.callback.ExecutionCallbackManager; import org.tizen.dynamicanalyzer.common.AnalyzerManager; import org.tizen.dynamicanalyzer.common.DAState; +import org.tizen.dynamicanalyzer.common.PreWindowShellCloseCallback; import org.tizen.dynamicanalyzer.common.path.PathManager; import org.tizen.dynamicanalyzer.communicator.DeviceManager; import org.tizen.dynamicanalyzer.communicator.IDECommunicator; @@ -103,379 +101,28 @@ public class BaseView extends ViewPart { tabView.setTabBGColor(ColorResources.WHITE , ColorResources.WHITE ); createPagesByTarget(null); RunInitializing(); - makeMenuBar(); + MenuBar.getInstance().makeMenuBar(); } - public void makeMenuBar() { - //menubar - final Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell(); - Menu bar = new Menu(shell, SWT.BAR); - shell.setMenuBar(bar); - MenuItem fileItem = new MenuItem(bar, SWT.CASCADE); - fileItem.setText("File"); - MenuItem analyzeItem = new MenuItem(bar, SWT.CASCADE); - analyzeItem.setText("Analyze"); - MenuItem viewItem = new MenuItem(bar, SWT.CASCADE); - viewItem.setText("View"); - MenuItem helpItem = new MenuItem(bar, SWT.CASCADE); - helpItem.setText("Help"); - - - //file menu - Menu fileMenu = new Menu(shell, SWT.DROP_DOWN); - fileItem.setMenu(fileMenu); - - MenuItem fileNew = new MenuItem(fileMenu, SWT.PUSH); - fileNew.setText("New"); -// fileNew.setAccelerator(SWT.MOD1 + 'A'); - fileNew.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem fileLoad = new MenuItem(fileMenu, SWT.PUSH); - fileLoad.setText("Load"); - fileLoad.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem fileSave = new MenuItem(fileMenu, SWT.PUSH); - fileSave.setText("Save"); - fileSave.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem fileExit = new MenuItem(fileMenu, SWT.PUSH); - fileExit.setText("Exit"); - fileExit.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - //analyze menu - Menu analyzeMenu = new Menu(shell, SWT.DROP_DOWN); - analyzeItem.setMenu(analyzeMenu); - - MenuItem analyzeSearchItem = new MenuItem(analyzeMenu, SWT.PUSH); - analyzeSearchItem.setText("Search"); - analyzeSearchItem.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem analyzeTarget = new MenuItem(analyzeMenu, SWT.PUSH); - analyzeTarget.setText("Target"); - analyzeTarget.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem analyzeScreenshot = new MenuItem(analyzeMenu, SWT.PUSH); - analyzeScreenshot.setText("Screenshot"); - analyzeScreenshot.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem analyzePreferences = new MenuItem(analyzeMenu, SWT.PUSH); - analyzePreferences.setText("Preferences"); - analyzePreferences.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem analyzeDefault = new MenuItem(analyzeMenu, SWT.PUSH); - analyzeDefault.setText("Set as default features"); - analyzeDefault.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - - //view menu - Menu viewMenu = new Menu(shell, SWT.DROP_DOWN); - viewItem.setMenu(viewMenu); - - MenuItem viewDetail = new MenuItem(viewMenu, SWT.CHECK); - viewDetail.setText("Detail"); - viewDetail.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem viewReport = new MenuItem(viewMenu, SWT.CASCADE); - viewReport.setText("Report"); - - Menu viewReportMenu = new Menu(shell, SWT.DROP_DOWN); - viewReport.setMenu(viewReportMenu); - - MenuItem viewReportStatistics = new MenuItem(viewReportMenu, SWT.CHECK); - viewReportStatistics.setText("Statistics"); - viewReportStatistics.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem viewReportTrace = new MenuItem(viewReportMenu, SWT.CHECK); - viewReportTrace.setText("Trace"); - viewReportTrace.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem viewReportFunctionprofiling = new MenuItem(viewReportMenu, SWT.CHECK); - viewReportFunctionprofiling.setText("Function Profiling"); - viewReportFunctionprofiling.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem viewNavigate = new MenuItem(viewMenu, SWT.CASCADE); - viewNavigate.setText("Navigate"); - - Menu viewNavigateMenu = new Menu(shell, SWT.DROP_DOWN); - viewNavigate.setMenu(viewNavigateMenu); - - MenuItem viewNavigateZoomin = new MenuItem(viewNavigateMenu, SWT.PUSH); - viewNavigateZoomin.setText("Zoom In"); - viewNavigateZoomin.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem viewNavigateZoomout = new MenuItem(viewNavigateMenu, SWT.PUSH); - viewNavigateZoomout.setText("Zoom Out"); - viewNavigateZoomout.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem viewNavigateMoveleft = new MenuItem(viewNavigateMenu, SWT.PUSH); - viewNavigateMoveleft.setText("Move Left"); - viewNavigateMoveleft.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem viewNavigateMoveright = new MenuItem(viewNavigateMenu, SWT.PUSH); - viewNavigateMoveright.setText("Move Right"); - viewNavigateMoveright.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem viewNavigateMovefirst = new MenuItem(viewNavigateMenu, SWT.PUSH); - viewNavigateMovefirst.setText("Move First"); - viewNavigateMovefirst.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem viewNavigateMoveend = new MenuItem(viewNavigateMenu, SWT.PUSH); - viewNavigateMoveend.setText("Move End"); - viewNavigateMoveend.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - //help menu - Menu helpMenu = new Menu(shell, SWT.DROP_DOWN); - helpItem.setMenu(helpMenu); - - MenuItem helpHowto = new MenuItem(helpMenu, SWT.PUSH); - helpHowto.setText("How to use Dynamic Analyzer"); - helpHowto.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem helpBugreport = new MenuItem(helpMenu, SWT.PUSH); - helpBugreport.setText("Bug Report"); - helpBugreport.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - - MenuItem helpAbout = new MenuItem(helpMenu, SWT.PUSH); - helpAbout.setText("About"); - helpAbout.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - - } - }); - } - - public void RunInitializing(){ + public void RunInitializing(){ // check Tizen SDK path and Platform DA checking AnalyzerManager.setPlatformSDK(PathManager.checkPlatformPlugin()); DAState.changeCurrentState(DAState.INIT); + + // initialize setting data + @SuppressWarnings("unused") SettingDataManager setting = SettingDataManager.INSTANCE; // initialize device connection DeviceManager.init(); - DeviceManager.addDeviceListener(); + DeviceManager.addDeviceListener(); Thread deviceinitthread = new Thread(new Runnable() { public void run() { DeviceManager.loadDevices(); Display.getDefault().asyncExec(new Runnable() { - public void run() { + public void run() { // initialize toolbar control state Toolbar.INSTANCE.updateDeviceCombo(null); Toolbar.INSTANCE.updateAppCombo(true); @@ -520,8 +167,11 @@ public class BaseView extends ViewPart { FlatFeatureDialog featureDialog = new FlatFeatureDialog(shell); // FIXME featureDialog.open(); } - }); + }); + ExecutionCallbackManager.registerCallback( + ExecutionCallbackManager.WINDOWADVISOR_PREWINDOWCLOSE, + new PreWindowShellCloseCallback()); } @Override diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/MenuBar.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/MenuBar.java new file mode 100644 index 0000000..6173922 --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/page/MenuBar.java @@ -0,0 +1,753 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Dongkye Lee + * Jaeyong Lee + * Gihun Chang + * + * Licensed 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. + * + */ + +package org.tizen.dynamicanalyzer.ui.page; + +import java.io.File; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; +import org.tizen.dynamicanalyzer.common.AnalyzerConstants; +import org.tizen.dynamicanalyzer.common.AnalyzerManager; +import org.tizen.dynamicanalyzer.common.DAState; +import org.tizen.dynamicanalyzer.common.Global; +import org.tizen.dynamicanalyzer.database.SqlConnectionManager; +import org.tizen.dynamicanalyzer.database.compatible.DBConverter; +import org.tizen.dynamicanalyzer.handlers.CommandAction; +import org.tizen.dynamicanalyzer.handlers.CommonAction; +import org.tizen.dynamicanalyzer.handlers.UIAction; +import org.tizen.dynamicanalyzer.nl.AnalyzerLabels; +import org.tizen.dynamicanalyzer.nl.MenuBarLabels; +import org.tizen.dynamicanalyzer.project.BinaryInfo; +import org.tizen.dynamicanalyzer.project.Project; +import org.tizen.dynamicanalyzer.setting.UILayoutDataManager; +import org.tizen.dynamicanalyzer.shortcut.ShortCutManager; +import org.tizen.dynamicanalyzer.swap.logparser.DataManagerRegistry; +import org.tizen.dynamicanalyzer.ui.interactive.data.InteractiveDataManager; +import org.tizen.dynamicanalyzer.ui.range.RangeDataManager; +import org.tizen.dynamicanalyzer.ui.range.RangePage; +import org.tizen.dynamicanalyzer.ui.summary.profiling.FunctionUsageProfiler; +import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfileDataMaker; +import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingChildData; +import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingChildDataDBTable; +import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingData; +import org.tizen.dynamicanalyzer.ui.summary.profiling.ProfilingDataDBTable; +import org.tizen.dynamicanalyzer.ui.summary.profiling.WebProfileDataMaker; +import org.tizen.dynamicanalyzer.ui.summary.profiling.WebProfilingData; +import org.tizen.dynamicanalyzer.ui.summary.profiling.WebProfilingDataDBTable; +import org.tizen.dynamicanalyzer.ui.timeline.TimelinePage; +import org.tizen.dynamicanalyzer.ui.toolbar.Toolbar; +import org.tizen.dynamicanalyzer.ui.toolbar.setting.FlatFeatureDialog; +import org.tizen.dynamicanalyzer.ui.userinterface.UIDataManager; +import org.tizen.dynamicanalyzer.util.Logger; +import org.tizen.dynamicanalyzer.util.WorkbenchUtil; +import org.tizen.dynamicanalyzer.utils.AnalyzerUtil; +import org.tizen.dynamicanalyzer.widgets.da.view.DAPageComposite; + +public class MenuBar { + + private static MenuBar instance = new MenuBar(); + private Shell currentShell; + private Menu menubar = null; + + public MenuBar() { + currentShell = WorkbenchUtil.getWorkbenchWindow().getShell(); + } + + public static MenuBar getInstance(){ + return instance; + } + + public void makeMenuBar() { + menubar = new Menu(currentShell, SWT.BAR); + currentShell.setMenuBar(menubar); + MenuItem fileItem = new MenuItem(menubar, SWT.CASCADE); + fileItem.setText(MenuBarLabels.FILE); + MenuItem analyzeItem = new MenuItem(menubar, SWT.CASCADE); + analyzeItem.setText(MenuBarLabels.ANALYZE); + MenuItem viewItem = new MenuItem(menubar, SWT.CASCADE); + viewItem.setText(MenuBarLabels.VIEW); + MenuItem helpItem = new MenuItem(menubar, SWT.CASCADE); + helpItem.setText(MenuBarLabels.HELP); + + //file menu + Menu fileMenu = new Menu(currentShell, SWT.DROP_DOWN); + fileItem.setMenu(fileMenu); + + MenuItem fileNew = new MenuItem(fileMenu, SWT.PUSH); + fileNew.setText(MenuBarLabels.FILE_NEW); +// fileNew.setAccelerator(SWT.MOD1 + 'A'); + fileNew.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + // change UI state + Toolbar.INSTANCE.resetProcessCombo(); + Toolbar.INSTANCE.changeUIState(DAState.PREPARE_START); + ShortCutManager.getInstance().setEnabled(false); + + InteractiveDataManager.getInstance().clear(); + + CommonAction.clear(); + + FlatFeatureDialog featureDialog = new FlatFeatureDialog(currentShell); + featureDialog.open(); + } + }); + + MenuItem fileLoad = new MenuItem(fileMenu, SWT.PUSH); + fileLoad.setText(MenuBarLabels.FILE_LOAD); + fileLoad.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + FileDialog dialog = new FileDialog(currentShell, SWT.OPEN); + dialog.setFilterNames(new String[] {"Zip file"}); + dialog.setFilterExtensions(new String[] {"*.zip"}); + dialog.setText(MenuBarLabels.FILE_LOAD_DIALOG_TITLE); + + Object result = dialog.open(); + if (null != result) { + String decompresspath = CommandAction.loadFromZip((String)result); + if (decompresspath != null && !decompresspath.isEmpty()) { + Project project = Project.getProjectFromFile(decompresspath); + if(project != null) { + Global.setProject(project); + openTraceFile(decompresspath); + } + } + } + } + }); + + MenuItem fileSave = new MenuItem(fileMenu, SWT.PUSH); + fileSave.setText(MenuBarLabels.FILE_SAVE); + fileSave.setEnabled(false); + fileSave.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + Project project = Global.getProject(); + if(project == null) { + return; + } + project.save(); + DataManagerRegistry.saveData(); + + String savefilename = + project.getSavePath().substring(project.getSavePath().lastIndexOf(File.separator) + 1); + + FileDialog dialog = new FileDialog(currentShell, SWT.SAVE); + dialog.setFilterNames(new String[] {"Zip file"}); + dialog.setFilterExtensions(new String[] {"*.zip"}); + dialog.setFileName(savefilename +".zip"); + dialog.setText(MenuBarLabels.FILE_SAVE_DIALOG_TITLE); + + Object result = dialog.open(); + if (null != result) { + if (!CommandAction.saveToZip((String)result)) { + UIAction.showWarning(AnalyzerLabels.SAVE_FAILED); + } + } + } + }); + + MenuItem fileExit = new MenuItem(fileMenu, SWT.PUSH); + fileExit.setText(MenuBarLabels.FILE_EXIT); + fileExit.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + currentShell.close(); + } + }); + + //analyze menu + Menu analyzeMenu = new Menu(currentShell, SWT.DROP_DOWN); + analyzeItem.setMenu(analyzeMenu); + + MenuItem analyzeSearchItem = new MenuItem(analyzeMenu, SWT.PUSH); + analyzeSearchItem.setText(MenuBarLabels.ANALYZE_SEARCH); + analyzeSearchItem.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem analyzeTarget = new MenuItem(analyzeMenu, SWT.PUSH); + analyzeTarget.setText(MenuBarLabels.ANALYZE_TARGET); + analyzeTarget.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem analyzeScreenshot = new MenuItem(analyzeMenu, SWT.PUSH); + analyzeScreenshot.setText(MenuBarLabels.ANALYZE_SCREENSHOT); + analyzeScreenshot.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem analyzePreferences = new MenuItem(analyzeMenu, SWT.PUSH); + analyzePreferences.setText(MenuBarLabels.ANALYZE_PREFENCES); + analyzePreferences.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem analyzeDefault = new MenuItem(analyzeMenu, SWT.PUSH); + analyzeDefault.setText(MenuBarLabels.ANALYZE_SET_AS_DEFAULT); + analyzeDefault.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + + //view menu + Menu viewMenu = new Menu(currentShell, SWT.DROP_DOWN); + viewItem.setMenu(viewMenu); + + MenuItem viewDetail = new MenuItem(viewMenu, SWT.CHECK); + viewDetail.setText(MenuBarLabels.VIEW_DETAIL); + viewDetail.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem viewReport = new MenuItem(viewMenu, SWT.CASCADE); + viewReport.setText(MenuBarLabels.VIEW_REPORT); + + Menu viewReportMenu = new Menu(currentShell, SWT.DROP_DOWN); + viewReport.setMenu(viewReportMenu); + + MenuItem viewReportStatistics = new MenuItem(viewReportMenu, SWT.CHECK); + viewReportStatistics.setText(MenuBarLabels.VIEW_STATISTICS); + viewReportStatistics.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem viewReportTrace = new MenuItem(viewReportMenu, SWT.CHECK); + viewReportTrace.setText(MenuBarLabels.VIEW_TRACE); + viewReportTrace.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem viewReportFunctionprofiling = new MenuItem(viewReportMenu, SWT.CHECK); + viewReportFunctionprofiling.setText(MenuBarLabels.VIEW_FUNCTION_PROFILING); + viewReportFunctionprofiling.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem viewNavigate = new MenuItem(viewMenu, SWT.CASCADE); + viewNavigate.setText(MenuBarLabels.VIEW_NAVIGATE); + + Menu viewNavigateMenu = new Menu(currentShell, SWT.DROP_DOWN); + viewNavigate.setMenu(viewNavigateMenu); + + MenuItem viewNavigateZoomin = new MenuItem(viewNavigateMenu, SWT.PUSH); + viewNavigateZoomin.setText(MenuBarLabels.VIEW_ZOOM_IN); + viewNavigateZoomin.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem viewNavigateZoomout = new MenuItem(viewNavigateMenu, SWT.PUSH); + viewNavigateZoomout.setText(MenuBarLabels.VIEW_ZOOM_OUT); + viewNavigateZoomout.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem viewNavigateMoveleft = new MenuItem(viewNavigateMenu, SWT.PUSH); + viewNavigateMoveleft.setText(MenuBarLabels.VIEW_MOVE_LEFT); + viewNavigateMoveleft.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem viewNavigateMoveright = new MenuItem(viewNavigateMenu, SWT.PUSH); + viewNavigateMoveright.setText(MenuBarLabels.VIEW_MOVE_RIGHT); + viewNavigateMoveright.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem viewNavigateMovefirst = new MenuItem(viewNavigateMenu, SWT.PUSH); + viewNavigateMovefirst.setText(MenuBarLabels.VIEW_MOVE_FIRST); + viewNavigateMovefirst.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem viewNavigateMoveend = new MenuItem(viewNavigateMenu, SWT.PUSH); + viewNavigateMoveend.setText(MenuBarLabels.VIEW_MOVE_END); + viewNavigateMoveend.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + //help menu + Menu helpMenu = new Menu(currentShell, SWT.DROP_DOWN); + helpItem.setMenu(helpMenu); + + MenuItem helpHowto = new MenuItem(helpMenu, SWT.PUSH); + helpHowto.setText(MenuBarLabels.HELP_HOWTO); + helpHowto.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem helpBugreport = new MenuItem(helpMenu, SWT.PUSH); + helpBugreport.setText(MenuBarLabels.HELP_BUGREPORT); + helpBugreport.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + + MenuItem helpAbout = new MenuItem(helpMenu, SWT.PUSH); + helpAbout.setText(MenuBarLabels.HELP_ABOUT); + helpAbout.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + + } + }); + } + + public boolean setMenuItemEnable(String menuName, boolean enable) { + int menulength = menubar.getItems().length; + for(int i = 0 ; i < menulength; i++) { + if(setMenuItemenable(menubar.getItems()[i], menuName, enable) == true) { + return true; + } + } + + Logger.warning("Can't find menu : " + menuName); + return false; + } + + private boolean setMenuItemenable(MenuItem menuitem, String menuName, boolean enable) { + + if(menuitem.getText().equals(menuName)) { + return true; + } + + if(menuitem.getMenu() == null) { + return false; + } + + int menulength = menuitem.getMenu().getItems().length; + + for(int i = 0 ; i < menulength; i++) { + if(setMenuItemenable(menuitem.getMenu().getItems()[i], menuName, enable) == true) { + menuitem.getMenu().getItems()[i].setEnabled(enable); + return true; + } + } + + return false; + } + + private boolean openTraceFile(String tracePath) { + + final Project project = Global.getProject(); + + // establish db connection with new path + SqlConnectionManager.closeConnection(); + SqlConnectionManager.establishConnection(project.getSavePath() + File.separator + + AnalyzerConstants.DATABASE_NAME); + + // convert save file for compatible database + DBConverter converter = new DBConverter(project.getVersion()); + if (!converter.convert()) { + // failed to convert for compatible database + UIAction.showWarning(AnalyzerLabels.OPEN_TRACE_PROGRESS_INVALID); + CommonAction.clear(); + return false; + } else { + // converting is succeeded + // change version of save file to current version + project.upgrade(); + } + + boolean bsuccess = project.openDetail(); + if (!bsuccess) { + UIAction.showWarning(AnalyzerLabels.OPEN_TRACE_PROGRESS_VERSION_INVALID_REMOVE); + CommonAction.clear(); + return false; + } + + if (loadProfilingData(project) && loadProfilingChildData() && loadWebProfilingData()) { + + } else { + UIAction.showWarning(AnalyzerLabels.OPEN_TRACE_PROGRESS_INVALID_REMOVE); + CommonAction.clear(); + return false; + } + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + Toolbar.INSTANCE.setTime(project.getTotalStopTime()); + Toolbar.INSTANCE.setAllControlState(true); + } + }); + + // change tab list and page to be shown + UIAction.setPages(project.getPageTabList()); + + // change chart list in timeline page + UIAction.setCharts(project.getTimelineChartList()); + + // change page + if (RangeDataManager.getInstance().isBeingAnalyzed()) { + DAPageComposite page = AnalyzerManager.getCurrentPage(); + if (page instanceof RangePage) { + AnalyzerUtil.changePage(TimelinePage.pageID); + } + } + + // set dirty of UI layout + UILayoutDataManager.INSTANCE.setDirty(true); + + // open for each PageDataManager + DataManagerRegistry.openData(); + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + UIAction.applyWebProfilingUI(Global.getProject().isWebApplication()); + + DAPageComposite page = AnalyzerManager.getCurrentPage(); + page.updateView(); + } + }); + + return true; + } + + private boolean loadProfilingData(Project project) { + boolean isSuccess = true; + List> profilingDatas = FunctionUsageProfiler.getInstance() + .getProfilingDataTable().getProfilingDataFromDB(); + if (null == profilingDatas) { + Logger.debug("failed - loadProfilingData"); + isSuccess = false; + } else { + for (int i = 0; i < profilingDatas.size(); i++) { + List profilingData = profilingDatas.get(i); + int pid = (Integer) profilingData.get(ProfilingDataDBTable.COLUMN.PID.index); + // possibility of extensions - network, efl, db, etc... + ProfileDataMaker profiler = FunctionUsageProfiler.getInstance() + .getProfileDataMakerByPid(pid); + int profilingDataID = (Integer) profilingData + .get(ProfilingDataDBTable.COLUMN.PROFILING_DATA_ID.index); + byte type = (Byte) profilingData.get(ProfilingDataDBTable.COLUMN.TYPE.index); + int exCount = (Integer) profilingData + .get(ProfilingDataDBTable.COLUMN.EXCLUSIVE_COUNT.index); + int inCount = (Integer) profilingData + .get(ProfilingDataDBTable.COLUMN.INCLUSIVE_COUNT.index); + int callCount = (Integer) profilingData + .get(ProfilingDataDBTable.COLUMN.CALL_COUNT.index); + long inElapsedTime = (Long) profilingData + .get(ProfilingDataDBTable.COLUMN.INCLUSIVE_EXECUTION_TIME.index); + long exElapsedTime = (Long) profilingData + .get(ProfilingDataDBTable.COLUMN.EXCLUSIVE_EXECUTION_TIME.index); + String name; + ProfilingData fupData = null; + int binaryId; + BinaryInfo bInfo = null; + switch (type) { + case ProfilingData.TYPE_APPLICATION: + case ProfilingData.TYPE_DEPENDENTLIBRARY: + case ProfilingData.TYPE_LIBRARY: + binaryId = (Integer) profilingData + .get(ProfilingDataDBTable.COLUMN.BINARY_ID.index); + bInfo = project.getDeviceStatusInfo().getBinaryInfo(binaryId); + name = bInfo.getTargetBinaryPath(); + fupData = new ProfilingData(profilingDataID, name, exCount, inCount, callCount, + inElapsedTime, exElapsedTime, profiler); + break; + case ProfilingData.TYPE_FUNCTION: + int functionId = (Integer) profilingData + .get(ProfilingDataDBTable.COLUMN.FUNCTION_ID.index); + name = project.getFunctionName(functionId); + fupData = new ProfilingData(profilingDataID, name, exCount, inCount, callCount, + inElapsedTime, exElapsedTime, profiler); + break; + default: // never goes here + Logger.error("invalid profiling data type"); + break; + } + + if (null == fupData) { + isSuccess = false; + } else { + if (type == ProfilingData.TYPE_APPLICATION) { + profiler.setAppBin(fupData); + } else if (type == ProfilingData.TYPE_DEPENDENTLIBRARY) { + profiler.setDependentLib(fupData); + } + + profiler.getProfilingDataMap().put(profilingDataID, fupData); + UIDataManager.getInstance().getfunctionProfilingDataChecker() + .addProfilingData(fupData); + // restore total sample count + profiler.setTotalSampleCount(profiler.getTotalSampleCount() + + fupData.getExCount()); + } + } + } + return isSuccess; + } + + private boolean loadProfilingChildData() { + boolean isSuccess = true; + List> profilingChilds = FunctionUsageProfiler.getInstance() + .getProfilingChildDataTable().getProfilingChildDataFromDB(); + if (null == profilingChilds) { + Logger.debug("failed - loadProfilingChildData"); + isSuccess = false; + } else { + int size = profilingChilds.size(); + for (int i = 0; i < size; i++) { + List data = profilingChilds.get(i); + int parentID = (Integer) data + .get(ProfilingChildDataDBTable.COLUMN.PROFILING_DATA_ID.index); + int pid = (Integer) data.get(ProfilingChildDataDBTable.COLUMN.PID.index); + + @SuppressWarnings("unchecked") + List childSeqList = (List) data + .get(ProfilingChildDataDBTable.COLUMN.CHILD_SEQUENCE_ARRAY.index); + + ProfileDataMaker profiler = FunctionUsageProfiler.getInstance() + .getProfileDataMakerByPid(pid); + ProfilingData parent = profiler.getProfilingDataMap().get(parentID); + ProfilingChildData child = parent.getChildData(); + child.getChildren().addAll(childSeqList); + } + } + return isSuccess; + } + + private boolean loadWebProfilingData() { + boolean isSuccess = true; + List> profilingDatas = FunctionUsageProfiler.getInstance() + .getWebProfilingDataTable().getWebProfilingDataFromDB(); + if (null == profilingDatas) { + Logger.debug("failed - loadWebProfilingData"); + isSuccess = false; + } else { + for (int i = 0; i < profilingDatas.size(); i++) { + List profilingData = profilingDatas.get(i); + + int profilingDataID = (Integer) profilingData + .get(WebProfilingDataDBTable.COLUMN.PROFILING_DATA_ID.getIndex()); + int pid = (Integer) profilingData + .get(WebProfilingDataDBTable.COLUMN.PID.getIndex()); + int functionLineNumber = (Integer) profilingData + .get(WebProfilingDataDBTable.COLUMN.FUNCTION_LINE_NUMBER.getIndex()); + String functionName = (String) profilingData + .get(WebProfilingDataDBTable.COLUMN.FUNCTION_NAME.getIndex()); + String functionURL = (String) profilingData + .get(WebProfilingDataDBTable.COLUMN.FUNCTION_URL.getIndex()); + int callCount = (Integer) profilingData + .get(WebProfilingDataDBTable.COLUMN.CALL_COUNT.getIndex()); + long inElapsedTime = (Long) profilingData + .get(WebProfilingDataDBTable.COLUMN.INCLUSIVE_EXECUTION_TIME.getIndex()); + long exElapsedTime = (Long) profilingData + .get(WebProfilingDataDBTable.COLUMN.EXCLUSIVE_EXECUTION_TIME.getIndex()); + + @SuppressWarnings("unchecked") + List childSeqList = (List) profilingData + .get(WebProfilingDataDBTable.COLUMN.CHILD_SEQUENCE_ARRAY.getIndex()); + + // create WebProfilingData + WebProfilingData fupData = new WebProfilingData(profilingDataID, + functionLineNumber, functionName, functionURL, callCount, inElapsedTime, + exElapsedTime, childSeqList); + + // get WebProfileDataMaker + WebProfileDataMaker profiler = FunctionUsageProfiler.getInstance() + .getWebProfileDataMakerByPid(pid); + + // set WebProfilingData + if (functionName.equals(FunctionUsageProfiler.APPLICATION)) { + profiler.setAppBin(fupData); + } + profiler.webProfilingDataMap().put(profilingDataID, fupData); + } + } + return isSuccess; + } +} \ No newline at end of file diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/Toolbar.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/Toolbar.java index 9873c8d..5e7175d 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/Toolbar.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/toolbar/Toolbar.java @@ -26,11 +26,9 @@ package org.tizen.dynamicanalyzer.ui.toolbar; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -79,7 +77,6 @@ import org.tizen.dynamicanalyzer.ui.page.BaseView; import org.tizen.dynamicanalyzer.ui.toolbar.opentrace.OpenTraceDialog; import org.tizen.dynamicanalyzer.ui.toolbar.replayEditor.ReplayEditDialog; import org.tizen.dynamicanalyzer.ui.toolbar.setting.FlatFeatureDialog; -import org.tizen.dynamicanalyzer.ui.toolbar.setting.SettingDialog; import org.tizen.dynamicanalyzer.util.Logger; import org.tizen.dynamicanalyzer.util.WorkbenchUtil; import org.tizen.dynamicanalyzer.workbench.LayoutManager; @@ -89,7 +86,6 @@ import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonRenderer; import org.tizen.dynamicanalyzer.widgets.button.toggle.DACustomToggleButton; import org.tizen.dynamicanalyzer.widgets.combo.DACustomCombo; import org.tizen.dynamicanalyzer.widgets.combo.DACustomComboSelectionListener; -import org.tizen.dynamicanalyzer.widgets.combo.DACustomComboTooltip; import org.tizen.dynamicanalyzer.widgets.da.base.ProgressDialog; import org.tizen.dynamicanalyzer.widgets.timer.IAlarm; import org.tizen.dynamicanalyzer.widgets.timer.TimerClock; @@ -435,8 +431,6 @@ public enum Toolbar { @Override public void handleClickEvent(DACustomButton button) { Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell(); - SettingDialog dialog = new SettingDialog(shell); // FIXME - dialog.open(); FlatFeatureDialog featureDialog = new FlatFeatureDialog(shell); // FIXME featureDialog.open(); } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/utils/ZipUtils.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/utils/ZipUtils.java new file mode 100644 index 0000000..8c7d1ac --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/utils/ZipUtils.java @@ -0,0 +1,202 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Dongkye Lee + * Jaeyong Lee + * Gihun Chang + * + * Licensed 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. + * + */ + +package org.tizen.dynamicanalyzer.utils; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; + +import org.tizen.dynamicanalyzer.util.Logger; + +public class ZipUtils { + + private static final int COMPRESSION_LEVEL = 8; + + private static final int BUFFER_SIZE = 1024 * 2; + + /** + * Compress to output file + * @param sourcePath - Target directory + * @param output - zip file name + * @throws Exception + */ + public static void zip(String sourcePath, String output) throws Exception { + + // If sourcePath is not a directory, make exception. + File sourceFile = new File(sourcePath); + if (!sourceFile.isFile() && !sourceFile.isDirectory()) { + throw new Exception("Can't find directory."); + } + + // + if(!output.toLowerCase().endsWith(".zip") ) { + output += ".zip"; + } + + FileOutputStream fos = null; + BufferedOutputStream bos = null; + ZipOutputStream zos = null; + + try { + fos = new FileOutputStream(output); + bos = new BufferedOutputStream(fos); + zos = new ZipOutputStream(bos); + zos.setLevel(COMPRESSION_LEVEL); // Compression level - Max 9, Default 8 + zipEntry(sourceFile, sourcePath, zos); // make Zip file + zos.finish(); // ZipOutputStream finish + } finally { + if (zos != null) { + zos.close(); + } + if (bos != null) { + bos.close(); + } + if (fos != null) { + fos.close(); + } + } + } + + /** + * Compress + * @param sourceFile + * @param sourcePath + * @param zos + * @throws Exception + */ + private static void zipEntry(File sourceFile, String sourcePath, ZipOutputStream zos) throws Exception { + // If sourceFile is a directory, call zipEntry again. + if (sourceFile.isDirectory()) { + if (sourceFile.getName().equalsIgnoreCase(".metadata")) { // .metadata is unnecessary. + return; + } + File[] fileArray = sourceFile.listFiles(); // children files of sourceFile + for (int i = 0; i < fileArray.length; i++) { + zipEntry(fileArray[i], sourcePath, zos); + } + } else { // sourcehFile is a file + BufferedInputStream bis = null; + try { + String sFilePath = sourceFile.getPath(); + String zipEntryName = sFilePath.substring(sourcePath.length() + 1, sFilePath.length()); + + bis = new BufferedInputStream(new FileInputStream(sourceFile)); + ZipEntry zentry = new ZipEntry(zipEntryName); + zentry.setTime(sourceFile.lastModified()); + zos.putNextEntry(zentry); + + byte[] buffer = new byte[BUFFER_SIZE]; + int cnt = 0; + while ((cnt = bis.read(buffer, 0, BUFFER_SIZE)) != -1) { + zos.write(buffer, 0, cnt); + } + zos.closeEntry(); + } finally { + if (bis != null) { + bis.close(); + } + } + } + } + + /** + * Decompress Zip file + * + * @param zipFile + * @param targetDir + * @param fileNameToLowerCase + * @throws Exception + */ + public static void unzip(File zipFile, File targetDir, boolean fileNameToLowerCase) throws Exception { + FileInputStream fis = null; + ZipInputStream zis = null; + ZipEntry zentry = null; + + try { + fis = new FileInputStream(zipFile); // FileInputStream + zis = new ZipInputStream(fis); // ZipInputStream + + while ((zentry = zis.getNextEntry()) != null) { + String fileNameToUnzip = zentry.getName(); + if (fileNameToLowerCase) { // fileName toLowerCase + fileNameToUnzip = fileNameToUnzip.toLowerCase(); + } + + File targetFile = new File(targetDir, fileNameToUnzip); + + if (zentry.isDirectory()) { + File childFolder = new File(targetFile.getAbsolutePath()); + if (!childFolder.mkdirs()) { + Logger.debug("child directory create failed..."); + } + } else { + File parentFolder = new File(targetFile.getParent()); + if (!parentFolder.mkdirs()) { + Logger.debug("parent directory create failed..."); + } + unzipEntry(zis, targetFile); + } + } + } finally { + if (zis != null) { + zis.close(); + } + if (fis != null) { + fis.close(); + } + } + } + + /** + * Decompress one Zip file + * + * @param zis - Zip Input Stream + * @param filePath + * @return + * @throws Exception + */ + protected static File unzipEntry(ZipInputStream zis, File targetFile) throws Exception { + FileOutputStream fos = null; + try { + fos = new FileOutputStream(targetFile); + + byte[] buffer = new byte[BUFFER_SIZE]; + int len = 0; + while ((len = zis.read(buffer)) != -1) { + fos.write(buffer, 0, len); + } + } finally { + if (fos != null) { + fos.close(); + } + } + return targetFile; + } +} \ No newline at end of file