[Title] added Ramdump modal dialog
authorgiwoong.kim <giwoong.kim@samsung.com>
Mon, 3 Sep 2012 12:04:09 +0000 (21:04 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Mon, 3 Sep 2012 13:39:50 +0000 (22:39 +0900)
[Type] feature
[Module] Emulator / menu
[Priority] major
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase] Ram Dump

tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/SocketCommunicator.java
tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/RamdumpDialog.java [new file with mode: 0644]
tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/SkinDialog.java

index d0513c6585c070aa65e4d227ad66d8383d150ddd..f2dd70b867c9acc58741436c366782e33b447a87 100644 (file)
@@ -86,6 +86,7 @@ import org.tizen.emulator.skin.dbi.RgbType;
 import org.tizen.emulator.skin.dbi.RotationType;
 import org.tizen.emulator.skin.dialog.AboutDialog;
 import org.tizen.emulator.skin.dialog.DetailInfoDialog;
+import org.tizen.emulator.skin.dialog.RamdumpDialog;
 import org.tizen.emulator.skin.exception.ScreenShotException;
 import org.tizen.emulator.skin.image.ImageRegistry;
 import org.tizen.emulator.skin.image.ImageRegistry.IconName;
@@ -1915,10 +1916,19 @@ public class EmulatorSkin {
 
                ramdumpItem.addSelectionListener(new SelectionAdapter() {
                        @Override
-                       public void widgetSelected( SelectionEvent e ) {
+                       public void widgetSelected(SelectionEvent e) {
                                logger.info("Ram dump menu is selected");
 
+                               communicator.setRamdumpFlag(true);
                                communicator.sendToQEMU(SendCommand.RAM_DUMP, null);
+
+                               RamdumpDialog ramdumpDialog;
+                               try {
+                                       ramdumpDialog = new RamdumpDialog(EmulatorSkin.this.shell, communicator, config);
+                                       ramdumpDialog.open();
+                               } catch (IOException ee) {
+                                       logger.log( Level.SEVERE, ee.getMessage(), ee);
+                               }
                        }
                });
 
@@ -2013,7 +2023,17 @@ public class EmulatorSkin {
                /*
                // Force close menu
                final MenuItem forceCloseItem = new MenuItem(menu, SWT.PUSH);
-               forceCloseItem.setText("Force Close");
+               forceCloseItem.setText("&Force Close");
+               //forceCloseItem.setImage(imageRegistry.getIcon(IconName.XXX));
+               forceCloseItem.addSelectionListener( new SelectionAdapter() {
+                       @Override
+                       public void widgetSelected( SelectionEvent e ) {
+                               logger.info("Force close is selected");
+
+                               //TODO : y or n popup
+                               System.exit(-1);
+                       }
+               });
                */
 
                new MenuItem( menu, SWT.SEPARATOR );
index f6fec2b3a19ae98946525bcce1086bb408375acf..ce7d54e11e6fa5cc00450d03d9daf1fa4e40ffd0 100644 (file)
@@ -112,7 +112,7 @@ public class SocketCommunicator implements ICommunicator {
        private AtomicInteger heartbeatCount;
        private boolean isTerminated;
        private boolean isSensorDaemonStarted;
-       private boolean isRamdumpCompleted;
+       private boolean isRamdump;
        private ScheduledExecutorService heartbeatExecutor;
 
        private DataTranfer screenShotDataTransfer;
@@ -300,9 +300,7 @@ public class SocketCommunicator implements ICommunicator {
                                }
                                case RAMDUMP_COMPLETE: {
                                        logger.info("received RAMDUMP_COMPLETE from QEMU.");
-                                       synchronized ( this ) {
-                                               isRamdumpCompleted = true;
-                                       }
+                                       setRamdumpFlag(false);
                                        break;
                                }
                                case SENSOR_DAEMON_START: {
@@ -337,7 +335,7 @@ public class SocketCommunicator implements ICommunicator {
                
                synchronized ( dataTransfer ) {
                        
-                       if( null != dataTransfer.timer ) {
+                       if ( null != dataTransfer.timer ) {
                                dataTransfer.timer.cancel();
                        }
                        
@@ -345,7 +343,7 @@ public class SocketCommunicator implements ICommunicator {
                        
                        if( null != data ) {
                                logger.info( "finished receiving data from QEMU." );
-                       }else {
+                       } else {
                                logger.severe( "Fail to receiving data from QEMU." );
                        }
                        
@@ -563,8 +561,12 @@ public class SocketCommunicator implements ICommunicator {
                return isSensorDaemonStarted;
        }
 
-       public synchronized boolean isRamdumpCompleted() {
-               return isRamdumpCompleted;
+       public synchronized void setRamdumpFlag(boolean flag) {
+               isRamdump = flag;
+       }
+
+       public synchronized boolean getRamdumpFlag() {
+               return isRamdump;
        }
 
        private void increaseHeartbeatCount() {
diff --git a/tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/RamdumpDialog.java b/tizen/src/skin/client/src/org/tizen/emulator/skin/dialog/RamdumpDialog.java
new file mode 100644 (file)
index 0000000..8096c94
--- /dev/null
@@ -0,0 +1,149 @@
+package org.tizen.emulator.skin.dialog;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.ImageLoader;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.skin.comm.sock.SocketCommunicator;
+import org.tizen.emulator.skin.config.EmulatorConfig;
+import org.tizen.emulator.skin.log.SkinLogger;
+import org.tizen.emulator.skin.util.SkinUtil;
+
+public class RamdumpDialog extends SkinDialog {
+       private SocketCommunicator communicator;
+       private ImageData[] frames;
+
+       private Logger logger = SkinLogger.getSkinLogger(RamdumpDialog.class).getLogger();
+
+       public RamdumpDialog(Shell parent,
+                       SocketCommunicator communicator, EmulatorConfig config) throws IOException {
+               super(parent, SkinUtil.makeEmulatorName(config),
+                               SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+               this.communicator = communicator;
+       }
+
+       @Override
+       protected Composite createArea(Composite parent) {
+               Composite composite;
+
+               try {
+                       composite = createContents(parent);
+               } catch (IOException e) {
+                       logger.log(Level.SEVERE, e.getMessage(), e);
+                       return null;
+               }
+
+               RamdumpDialog.this.shell.addListener(SWT.Close, new Listener() {
+                       @Override
+                       public void handleEvent(Event event) {
+                               // do nothing
+                               logger.info("do nothing");
+
+                               if (communicator.getRamdumpFlag() == true) {
+                                       event.doit = false;
+                               }
+                       }
+               } );
+
+               return composite;
+       }
+
+       private Composite createContents(Composite parent) throws IOException {
+               Composite composite = new Composite(parent, SWT.NONE);
+
+               composite.setLayout(new GridLayout(2, false));
+
+               final Display display = Display.getDefault();
+
+               ImageLoader loader = new ImageLoader();
+
+               try {
+                       frames = loader.load("indicator.gif");
+               } catch (Exception e) {
+                       // TODO: register a indicator file
+                       frames = null;
+               }
+
+               final Label label = new Label(composite, SWT.NONE);
+               if (frames != null) {
+                       label.setImage(new Image(display, frames[0]));
+               }
+
+               Label waitMsg = new Label(composite, SWT.NONE);
+               waitMsg.setText("  Please wait...");
+
+               Thread animation = new Thread() {
+                       int currentFrame = 0;
+                       boolean isDisposed = false;
+
+                       @Override
+                       public void run() {
+                               while (!isDisposed) {
+                                       try {
+                                               if (frames != null) {
+                                                       sleep(frames[currentFrame].delayTime * 10);
+                                               } else {
+                                                       sleep(500);
+                                               }
+                                       } catch (InterruptedException e) {
+                                               logger.warning("InterruptedException");
+                                       }
+
+                                       if (frames != null) {
+                                               currentFrame = (currentFrame + 1) % frames.length;
+                                       }
+                                       if (display.isDisposed()) {
+                                               return;
+                                       }
+
+                                       if (frames != null) {
+                                               display.asyncExec(new Runnable() {
+                                                       @Override
+                                                       public void run() {
+                                                               try {
+                                                                       Image newImage = new Image(display, frames[currentFrame]);
+                                                                       label.getImage().dispose();
+                                                                       label.setImage(newImage);
+                                                               } catch (SWTException e) {
+                                                                       isDisposed = true;
+                                                               }
+                                                       }
+                                               }); //end of asyncExec
+                                       }
+
+                                       if (communicator.getRamdumpFlag() == false) {
+                                               isDisposed = true;
+                                       }
+                               }
+
+                               display.syncExec(new Runnable() {
+                                       @Override
+                                       public void run() {
+                                               logger.info("close the Ramdump dialog");
+                                               RamdumpDialog.this.shell.close();
+                                       }
+                               });
+                       }
+               };
+               animation.start();
+
+               return composite;
+       }
+
+       @Override
+       protected void setShellSize() {
+               shell.setSize(240, 120);
+       }
+}
index 063c595e17614bdae880a644a460e93c9aa7c394..16d142d0719fa58b8e4847e60f33849161115a48 100644 (file)
@@ -51,7 +51,6 @@ public abstract class SkinDialog extends Dialog {
        public static final String OK = "        " + "OK" + "        ";
        
        protected Shell shell;
-       private boolean isReady;
        private Composite buttonComposite;
        private Shell parent;
        private String title;
@@ -67,7 +66,6 @@ public abstract class SkinDialog extends Dialog {
        public void open() {
 
                shell = new Shell( parent, style );
-               shell.setLocation( parent.getLocation().x + 50, parent.getLocation().y + 50 );
                shell.setText( title );
                shell.setImage( parent.getImage() );
                
@@ -88,8 +86,6 @@ public abstract class SkinDialog extends Dialog {
                        return;
                }
 
-               isReady = true;
-
                buttonComposite = new Composite( parent, SWT.NONE );
                buttonComposite.setLayoutData( new GridData( SWT.FILL, SWT.CENTER, true, false ) );
                buttonComposite.setLayout( new FillLayout( SWT.HORIZONTAL ) );
@@ -99,10 +95,6 @@ public abstract class SkinDialog extends Dialog {
                shell.pack();
 
                setShellSize();
-               
-               if ( !isReady ) {
-                       return;
-               }
 
                if (this.parent != null) {
                        Point central = new Point(