[Title] Shows warning message when connection explorer is closed
authorhyunsik.noh <hyunsik.noh@samsung.com>
Wed, 13 Mar 2013 06:07:47 +0000 (15:07 +0900)
committerhyunsik.noh <hyunsik.noh@samsung.com>
Fri, 15 Mar 2013 07:56:15 +0000 (16:56 +0900)
[Type]
[Module]common
[Priority]
[CQ#]
[Redmine#]8505
[Problem]
[Cause]
[Solution]

Change-Id: Id51fc6dcfbf398119ec984b2e60d54053d139f9b

org.tizen.common.connection/src/org/tizen/common/connection/ConnectionPlugin.java
org.tizen.common.connection/src/org/tizen/common/connection/ui/ConnectionExplorer.java
org.tizen.common.connection/src/org/tizen/common/connection/ui/ConnectionUIMessages.properties

index 6472d41..b059458 100755 (executable)
@@ -29,17 +29,14 @@ package org.tizen.common.connection;
 
 import java.util.ArrayList;
 
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 import org.tizen.common.connection.preference.TizenConnectionExplorerPreferencePage;
 import org.tizen.common.connection.preference.TizenLogPreferencePage;
-import org.tizen.common.connection.ui.ConnectionUIMessages;
 import org.tizen.common.util.OSChecker;
-import org.tizen.common.util.SWTUtil;
 import org.tizen.common.util.log.Logger;
 import org.tizen.sdblib.FileListingService.FileEntry;
 import org.tizen.sdblib.IDevice;
@@ -58,14 +55,14 @@ public class ConnectionPlugin extends AbstractUIPlugin {
     // The shared instance
     private static ConnectionPlugin plugin;
 
-    private static boolean isConnectionExplorerOpened = false;
-
-    private IDevice currentDevice;
+    private IDevice currentDevice = null;
     private final ArrayList<ISelectionListener> listeners = new ArrayList<ISelectionListener>();
 
     public int os;
     public static final int LINUX = 0;
     public static final int WINDOWS = 1;
+    
+    public static Job ideCheckJob;
 
     /**
      * Implements for FileEntry changed status.
@@ -121,6 +118,13 @@ public class ConnectionPlugin extends AbstractUIPlugin {
      */
     public void stop(BundleContext context) throws Exception {
         plugin = null;
+
+        if(ideCheckJob.sleep())
+        {
+            ideCheckJob.cancel();
+            Logger.info("IDE Check Job is cancelled");
+        }
+
         int deviceCnt = SmartDevelopmentBridge.getBridge().getDevices().length;
         if (deviceCnt==0)
         {
@@ -143,30 +147,9 @@ public class ConnectionPlugin extends AbstractUIPlugin {
     }
 
     public IDevice getCurrentDevice() {
-        if(!isConnectionExplorerOpened)
-        {
-            SWTUtil.syncExec(new Runnable()
-            {
-                @Override
-                public void run()
-                {
-                    MessageDialog.openError(new Shell(), ConnectionUIMessages.Explorer_Closed_Title, ConnectionUIMessages.Explorer_Closed_Message);
-                }
-            });
-            Logger.error("ConnectionExplorer is closed");
-            return null;
-        }
         return currentDevice;
     }
 
-    public void setConnectionExplorerOpened(boolean isOpend) {
-        isConnectionExplorerOpened = isOpend;
-    }
-
-    public boolean getConnectionExplorerOpened() {
-        return isConnectionExplorerOpened;
-    }
-
     public void addSelectionListener(ISelectionListener listener) {
         listeners.add(listener);
     }
@@ -188,6 +171,11 @@ public class ConnectionPlugin extends AbstractUIPlugin {
             }
         }
     }
+    
+    public static void setIDECheckJob(Job job)
+    {
+        ideCheckJob = job;
+    }
 
     /**
      * Returns an image descriptor for the image file at the given
index 96b3dca..0a05e7d 100755 (executable)
@@ -29,6 +29,10 @@ import java.io.File;
 import java.io.IOException;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IContributionItem;
 import org.eclipse.jface.action.IMenuListener;
@@ -46,6 +50,7 @@ import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.ToolBar;
 import org.eclipse.swt.widgets.ToolItem;
 import org.eclipse.swt.widgets.Tree;
@@ -62,6 +67,7 @@ import org.tizen.common.connection.explorer.ConnectionExplorerPanel;
 import org.tizen.common.connection.preference.TizenConnectionExplorerPreferencePage;
 import org.tizen.common.core.application.InstallPathConfig;
 import org.tizen.common.util.HostUtil;
+import org.tizen.common.util.SWTUtil;
 import org.tizen.common.util.log.Logger;
 import org.tizen.sdblib.FileListingService.FileEntry;
 import org.tizen.sdblib.IDevice;
@@ -511,7 +517,25 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2 {
 
     @Override
     public void partClosed(IWorkbenchPartReference partRef) {
-        setOpened(partRef, false);
+        if (ConnectionPlugin.ID_CONNECTION_VIEW.equals(partRef.getId())) {
+            ConnectionPlugin.getDefault().setCurrentDevice(null);
+            
+            Job job = new Job("Check IDE close"){
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
+                    SWTUtil.syncExec(new Runnable()
+                    {
+                        @Override
+                        public void run() {
+                            MessageDialog.openWarning(new Shell(), ConnectionUIMessages.Explorer_Closed_Title, ConnectionUIMessages.Explorer_Closed_Message);
+                        }
+                    });
+                    return Status.OK_STATUS;
+                }
+            };
+            ConnectionPlugin.getDefault().setIDECheckJob(job);
+            job.schedule(1000);
+        }
     }
 
     @Override
@@ -520,7 +544,6 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2 {
 
     @Override
     public void partOpened(IWorkbenchPartReference partRef) {
-        setOpened(partRef, true);
     }
 
     @Override
@@ -534,10 +557,4 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2 {
     @Override
     public void partInputChanged(IWorkbenchPartReference partRef) {
     }
-
-    private void setOpened(IWorkbenchPartReference partRef, boolean open) {
-        if (ConnectionPlugin.ID_CONNECTION_VIEW.equals(partRef.getId())) {
-            ConnectionPlugin.getDefault().setConnectionExplorerOpened(open);
-        }
-    }
 }
\ No newline at end of file
index b8859e8..3db284b 100644 (file)
@@ -1,5 +1,5 @@
-Explorer_Closed_Title = Failed to get device information
-Explorer_Closed_Message = The Connection Explorer is closed.\nPlease open it here:\n\tWindow > Show View > Other... > Tizen > Connection Explorer
+Explorer_Closed_Title = Connection Explorer is closed
+Explorer_Closed_Message = Connection Explorer is closed\nYou can open it by Window > Show View > Connection Explorer menu.
 
 Explorer_ConetextMenu_New = New
 Explorer_ConetextMenu_File = File