[Title] Add for checking view id to identify opened/closed state of connection explorer
authorhyunsik.noh <hyunsik.noh@samsung.com>
Thu, 21 Feb 2013 12:02:56 +0000 (21:02 +0900)
committerhyunsik.noh <hyunsik.noh@samsung.com>
Fri, 22 Feb 2013 03:03:53 +0000 (12:03 +0900)
[Type]
[Module]common
[Priority]
[CQ#]
[Redmine#]8505
[Problem]
[Cause]
[Solution]

Change-Id: Ibaa0bfe862af21b3baab9186ca1365c109ab717a

org.tizen.common.connection/src/org/tizen/common/connection/ui/ConnectionExplorer.java

index 8968713..96b3dca 100755 (executable)
@@ -68,8 +68,7 @@ import org.tizen.sdblib.IDevice;
 import org.tizen.sdblib.MultiLineReceiver;
 import org.tizen.sdblib.SmartDevelopmentBridge;
 
-public class ConnectionExplorer extends ViewPart implements IPartListener2
-{
+public class ConnectionExplorer extends ViewPart implements IPartListener2 {
 
     private ConnectionExplorerPanel panel;
     private Composite parent;
@@ -94,14 +93,12 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
 
     private MenuManager menuMgr;
     private static ConnectionExplorer explorer;
-    
+
     public static String PLATFORMLOG_ON = "1";
     public static String PLATFORMLOG_OFF = "0";
 
-    synchronized public static ConnectionExplorer gerDefault()
-    {
-        if (explorer == null)
-        {
+    synchronized public static ConnectionExplorer gerDefault() {
+        if (explorer == null) {
             explorer = new ConnectionExplorer();
         }
         return explorer;
@@ -112,15 +109,13 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
     }
 
     @Override
-    public void dispose()
-    {
+    public void dispose() {
         IWorkbenchWindow workbenchWindow = getSite().getWorkbenchWindow();
         workbenchWindow.getPartService().removePartListener(this);
     }
 
     @Override
-    public void createPartControl(Composite p)
-    {
+    public void createPartControl(Composite p) {
         IWorkbenchWindow workbenchWindow = getSite().getWorkbenchWindow();
         workbenchWindow.getPartService().addPartListener(this);
 
@@ -155,166 +150,135 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
 
         panel.setToolItems(pushToolItem, pullToolItem, emulManagerToolItem);
 
-        panel.setActions(subNewMenu, actionPush, actionPull, actionRefresh, actionRename, actionProperty, actionDelete, subLogMenu);
+        panel.setActions(subNewMenu, actionPush, actionPull, actionRefresh, actionRename, actionProperty, actionDelete,
+                subLogMenu);
     }
 
-    private void createFileExplorerView(Composite parent)
-    {
+    private void createFileExplorerView(Composite parent) {
 
         // device explorer
         panel = new ConnectionExplorerPanel();
         panel.createPanel(parent);
-        panel.getTreeViewer().getTree().addKeyListener(new KeyAdapter()
-        {
+        panel.getTreeViewer().getTree().addKeyListener(new KeyAdapter() {
             @Override
-            public void keyPressed(KeyEvent e)
-            {
+            public void keyPressed(KeyEvent e) {
                 handleKeyPressed(e);
             }
 
             @Override
-            public void keyReleased(KeyEvent e)
-            {
+            public void keyReleased(KeyEvent e) {
             }
         });
 
     }
 
-    private void handleKeyPressed(KeyEvent event)
-    {
+    private void handleKeyPressed(KeyEvent event) {
 
         Tree tree = (Tree) event.widget;
         int length = tree.getSelectionCount();
-        if (event.keyCode == SWT.F5)
-        {
-            if (length == 1)
-            {
+        if (event.keyCode == SWT.F5) {
+            if (length == 1) {
                 actionRefresh();
             }
-        } else if (event.keyCode == SWT.F2)
-        {
-            if (length == 1)
-            {
+        } else if (event.keyCode == SWT.F2) {
+            if (length == 1) {
                 actionRename();
             }
-        } else if (event.keyCode == SWT.DEL)
-        {
+        } else if (event.keyCode == SWT.DEL) {
             actionDelete();
         }
-        if ((event.stateMask == SWT.ALT) && (event.keyCode == SWT.CR))
-        {
+        if ((event.stateMask == SWT.ALT) && (event.keyCode == SWT.CR)) {
             actionShowProperty();
         }
     }
 
-    private void actionAddFile()
-    {
+    private void actionAddFile() {
         panel.addNewFileSelection();
     }
 
-    private void actionAddFolder()
-    {
+    private void actionAddFolder() {
         panel.addNewFolderSelection();
     }
 
-    private void actionPush()
-    {
+    private void actionPush() {
         panel.pushIntoSelection();
     }
 
-    private void actionPull()
-    {
+    private void actionPull() {
         panel.pullSelection();
     }
 
-    private void actionRefresh()
-    {
+    private void actionRefresh() {
         panel.refreshSelection();
     }
 
-    private void actionDelete()
-    {
+    private void actionDelete() {
         panel.deleteSelection();
     }
 
-    private void actionRename()
-    {
+    private void actionRename() {
         panel.renameSelection();
     }
 
-    private void actionShowProperty()
-    {
+    private void actionShowProperty() {
         panel.showPropertySelection(getSite());
     }
 
-    private void actionSetPlatformLog(boolean setON)
-    {
+    private void actionSetPlatformLog(boolean setON) {
         panel.setPlatformLogOnOff(setON);
     }
+
     /*
      * make actions
      */
-    private void makeActions()
-    {
+    private void makeActions() {
         subNewMenu = new MenuManager(ConnectionUIMessages.Explorer_ConetextMenu_New, null);
 
-        actionAddFile = new Action()
-        {
+        actionAddFile = new Action() {
             @Override
-            public void run()
-            {
+            public void run() {
                 actionAddFile();
             }
         };
         actionAddFile.setText(ConnectionUIMessages.Explorer_ConetextMenu_File);
 
-        actionAddFolder = new Action()
-        {
+        actionAddFolder = new Action() {
             @Override
-            public void run()
-            {
+            public void run() {
                 actionAddFolder();
             }
         };
         actionAddFolder.setText(ConnectionUIMessages.Explorer_ConetextMenu_Folder);
 
-        actionPush = new Action()
-        {
+        actionPush = new Action() {
             @Override
-            public void run()
-            {
+            public void run() {
                 actionPush();
             }
         };
         actionPush.setText(ConnectionUIMessages.Explorer_ConetextMenu_Push);
 
-        actionPull = new Action()
-        {
+        actionPull = new Action() {
             @Override
-            public void run()
-            {
+            public void run() {
                 actionPull();
             }
         };
         actionPull.setText(ConnectionUIMessages.Explorer_ConetextMenu_Pull);
 
         // Add refresh action
-        actionRefresh = new Action()
-        {
+        actionRefresh = new Action() {
             @Override
-            public void run()
-            {
+            public void run() {
                 actionRefresh();
             }
         };
         actionRefresh.setText(ConnectionUIMessages.Explorer_ConetextMenu_Refresh);
         actionRefresh.setActionDefinitionId("org.tizen.common.connection.refresh");
 
-        actionRename = new Action()
-        {
+        actionRename = new Action() {
             @Override
-            public void run()
-            {
+            public void run() {
                 actionRename();
             }
         };
@@ -322,22 +286,18 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
         actionRename.setText(ConnectionUIMessages.Explorer_ConetextMenu_Rename);
         actionRename.setActionDefinitionId("org.tizen.common.connection.rename");
 
-        actionDelete = new Action()
-        {
+        actionDelete = new Action() {
             @Override
-            public void run()
-            {
+            public void run() {
                 actionDelete();
             }
         };
         actionDelete.setText(ConnectionUIMessages.Explorer_ConetextMenu_Delete);
         actionDelete.setActionDefinitionId("org.tizen.common.connection.delete");
 
-        actionProperty = new Action()
-        {
+        actionProperty = new Action() {
             @Override
-            public void run()
-            {
+            public void run() {
                 panel.showPropertySelection(getSite());
             }
         };
@@ -346,37 +306,30 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
 
         subLogMenu = new MenuManager(ConnectionUIMessages.Explorer_ConetextMenu_Log, null);
 
-        actionPlatformLogOn = new Action()
-        {
+        actionPlatformLogOn = new Action() {
             @Override
-            public void run()
-            {
+            public void run() {
                 actionSetPlatformLog(true);
             }
         };
         actionPlatformLogOn.setText(ConnectionUIMessages.Explorer_ConetextMenu_Log_On);
-        
-        actionPlatformLogOff = new Action()
-        {
+
+        actionPlatformLogOff = new Action() {
             @Override
-            public void run()
-            {
+            public void run() {
                 actionSetPlatformLog(false);
             }
         };
         actionPlatformLogOff.setText(ConnectionUIMessages.Explorer_ConetextMenu_Log_Off);
     }
 
-    private void initContextMenu()
-    {
-        // initalize the context menu
+    private void initContextMenu() {
+        // initialize the context menu
         menuMgr = new MenuManager("Connection Explorer MenuMgr"); //$NON-NLS-1$
         menuMgr.setRemoveAllWhenShown(true);
-        menuMgr.addMenuListener(new IMenuListener()
-        {
+        menuMgr.addMenuListener(new IMenuListener() {
             @Override
-            public void menuAboutToShow(IMenuManager manager)
-            {
+            public void menuAboutToShow(IMenuManager manager) {
                 fillContextMenu(manager);
             }
         });
@@ -385,19 +338,14 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
         panel.getTreeViewer().getTree().setMenu(menu);
         getSite().registerContextMenu(menuMgr, panel.getTreeViewer());
 
-        menuMgr.addMenuListener(new IMenuListener()
-        {
+        menuMgr.addMenuListener(new IMenuListener() {
             @Override
-            public void menuAboutToShow(IMenuManager manager)
-            {
+            public void menuAboutToShow(IMenuManager manager) {
                 // Remove team menu from our menu
                 IContributionItem[] items = manager.getItems();
-                if (items != null)
-                {
-                    for (IContributionItem item : items)
-                    {
-                        if (("team.main").equals(item.getId()))
-                        {
+                if (items != null) {
+                    for (IContributionItem item : items) {
+                        if (("team.main").equals(item.getId())) {
                             manager.remove(item);
                             break;
                         }
@@ -407,8 +355,7 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
         });
     }
 
-    private void activateContext()
-    {
+    private void activateContext() {
         IContextService contextService = (IContextService) getSite().getService(IContextService.class);
         contextService.activateContext("org.tizen.common.connection.delete.context");
         contextService.activateContext("org.tizen.common.connection.rename.context");
@@ -417,8 +364,7 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
 
     }
 
-    private void fillContextMenu(IMenuManager manager)
-    {
+    private void fillContextMenu(IMenuManager manager) {
         subNewMenu.add(actionAddFile);
         subNewMenu.add(actionAddFolder);
         manager.add(subNewMenu);
@@ -440,41 +386,32 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
         actionPlatformLogOn.setChecked(isOn);
         actionPlatformLogOff.setChecked(!isOn);
     }
-    
-    private boolean isPlatformLogOn()
-    {
+
+    private boolean isPlatformLogOn() {
         TreeItem[] items = panel.getTreeViewer().getTree().getSelection();
-        FileEntry file = (FileEntry)items[0].getData();
+        FileEntry file = (FileEntry) items[0].getData();
         IDevice[] devices = SmartDevelopmentBridge.getBridge().getDevices();
         final AtomicBoolean result = new AtomicBoolean(false);
-        for(IDevice device : devices)
-        {
-            if(file.getName().equals(device.getDeviceName()))
-            {
+        for (IDevice device : devices) {
+            if (file.getName().equals(device.getDeviceName())) {
                 String command = "dlogctrl get platformlog";
                 try {
-                    device.executeShellCommand(command, new MultiLineReceiver()
-                    {
+                    device.executeShellCommand(command, new MultiLineReceiver() {
 
                         @Override
-                        public void processNewLines(String[] lines)
-                        {
+                        public void processNewLines(String[] lines) {
                             boolean isOn = lines[0].equals(PLATFORMLOG_ON);
                             boolean isOff = lines[0].equals(PLATFORMLOG_OFF);
-                            if(isOn || isOff)
-                            {
-                                if(isOn)
-                                {
+                            if (isOn || isOff) {
+                                if (isOn) {
                                     result.set(true);
                                 }
-                                if(!subLogMenu.isVisible())
-                                {
+                                if (!subLogMenu.isVisible()) {
                                     subLogMenu.setVisible(true);
                                 }
-                            }
-                            else
-                            {
-                                MessageDialog.openError(parent.getShell(), ConnectionUIMessages.Explorer_Message_PlatformLogError, lines[0] ); //$NON-NLS-1$
+                            } else {
+                                MessageDialog.openError(parent.getShell(),
+                                        ConnectionUIMessages.Explorer_Message_PlatformLogError, lines[0]); //$NON-NLS-1$
                                 subLogMenu.setVisible(false);
                             }
                         }
@@ -487,8 +424,7 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
         return result.get();
     }
 
-    private void createToolBar(Composite shell, Object layoutData)
-    {
+    private void createToolBar(Composite shell, Object layoutData) {
         toolBar = new ToolBar(shell, SWT.NULL);
         toolBar.setLayoutData(layoutData);
 
@@ -497,16 +433,12 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
         emulManagerToolItem = new ToolItem(toolBar, SWT.PUSH);
         emulManagerToolItem.setImage(ConnectionPlugin.getImageDescriptorFromPlugin("icons/emulator_manager.gif").createImage());
         emulManagerToolItem.setToolTipText(ConnectionUIMessages.Explorer_Tooltip_EmulatorManager);
-        emulManagerToolItem.addSelectionListener(new SelectionAdapter()
-        {
+        emulManagerToolItem.addSelectionListener(new SelectionAdapter() {
             @Override
-            public void widgetSelected(SelectionEvent e)
-            {
-                try
-                {
+            public void widgetSelected(SelectionEvent e) {
+                try {
                     startEmulatorManager();
-                } catch (Exception e1)
-                {
+                } catch (Exception e1) {
                     Logger.error("Fail to start Emulator Manager", e1.getMessage());
                 }
             }
@@ -518,11 +450,9 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
         pushToolItem = new ToolItem(toolBar, SWT.PUSH);
         pushToolItem.setImage(ConnectionPlugin.getImageDescriptorFromPlugin("icons/push.gif").createImage());
         pushToolItem.setToolTipText(ConnectionUIMessages.Explorer_Tooltip_Push);
-        pushToolItem.addSelectionListener(new SelectionAdapter()
-        {
+        pushToolItem.addSelectionListener(new SelectionAdapter() {
             @Override
-            public void widgetSelected(SelectionEvent e)
-            {
+            public void widgetSelected(SelectionEvent e) {
                 panel.pushIntoSelection();
             }
         });
@@ -533,47 +463,40 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
         pullToolItem = new ToolItem(toolBar, SWT.PUSH);
         pullToolItem.setImage(ConnectionPlugin.getImageDescriptorFromPlugin("icons/pull.gif").createImage());
         pullToolItem.setToolTipText(ConnectionUIMessages.Explorer_Tooltip_Pull);
-        pullToolItem.addSelectionListener(new SelectionAdapter()
-        {
+        pullToolItem.addSelectionListener(new SelectionAdapter() {
             @Override
-            public void widgetSelected(SelectionEvent e)
-            {
+            public void widgetSelected(SelectionEvent e) {
                 panel.pullSelection();
             }
         });
         pullToolItem.setEnabled(false);
-        new ToolItem(toolBar, SWT.SEPARATOR);   // Separator
+        new ToolItem(toolBar, SWT.SEPARATOR); // Separator
     }
 
     @Override
-    public void setFocus()
-    {
-        if(parent != null)
-        {
+    public void setFocus() {
+        if (parent != null) {
             parent.setFocus();
         }
     }
 
-    public static void startEmulatorManager() throws Exception
-    {
+    public static void startEmulatorManager() throws Exception {
         int osType = ConnectionPlugin.getDefault().os;
         int linuxType = ConnectionPlugin.LINUX;
 
-        String exePath = ConnectionPlugin.getDefault().getPreferenceStore().getString(TizenConnectionExplorerPreferencePage.KEY_EMULATOR_MANAGER_PATH);
-        if (exePath.equals("") || (!exePath.equals("") && !HostUtil.exists(exePath)))
-        {
+        String exePath = ConnectionPlugin.getDefault().getPreferenceStore()
+                .getString(TizenConnectionExplorerPreferencePage.KEY_EMULATOR_MANAGER_PATH);
+        if (exePath.equals("") || (!exePath.equals("") && !HostUtil.exists(exePath))) {
             throw new Exception(ConnectionUIMessages.Explorer_Message_EmulatorError);
         }
 
         // FIXME : should implement the lines below based on windows system.
         String command = exePath;
-        if (osType == linuxType)
-        {
+        if (osType == linuxType) {
             command = command + " 1>/dev/null 2>/dev/null &";
 
             HostUtil.execute(command);
-        } else
-        {
+        } else {
             HostUtil.batchExecute(command, null, new File(InstallPathConfig.getEmulatorPath()));
         }
     }
@@ -588,7 +511,7 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
 
     @Override
     public void partClosed(IWorkbenchPartReference partRef) {
-        ConnectionPlugin.getDefault().setConnectionExplorerOpened(false);
+        setOpened(partRef, false);
     }
 
     @Override
@@ -597,7 +520,7 @@ public class ConnectionExplorer extends ViewPart implements IPartListener2
 
     @Override
     public void partOpened(IWorkbenchPartReference partRef) {
-        ConnectionPlugin.getDefault().setConnectionExplorerOpened(true);
+        setOpened(partRef, true);
     }
 
     @Override
@@ -611,4 +534,10 @@ 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