close sync service
authoryoonki.park <yoonki.park@samsung.com>
Wed, 10 Apr 2013 02:34:10 +0000 (11:34 +0900)
committeryoonki.park <yoonki.park@samsung.com>
Wed, 10 Apr 2013 02:34:10 +0000 (11:34 +0900)
Signed-off-by: yoonki.park <yoonki.park@samsung.com>
org.tizen.common.connection/src/org/tizen/common/connection/sdblib/dnd/FileEntryDropAdapter.java

index d116656..1940858 100755 (executable)
@@ -1,28 +1,28 @@
 /*
-*  Common
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact:
-* Hoon Kang <h245.kang@samsung.com>
-* Yoonki Park <yoonki.park@samsung.com>
-*
+ *  Common
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Hoon Kang <h245.kang@samsung.com>
+ * Yoonki Park <yoonki.park@samsung.com>
+ *
  * 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.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
+ * 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
 package org.tizen.common.connection.sdblib.dnd;
 
 import java.io.File;
@@ -37,6 +37,7 @@ import org.eclipse.ui.part.IDropActionDelegate;
 import org.tizen.common.connection.ConnectionPlugin;
 import org.tizen.common.connection.ddmuilib.FileDialogUtils;
 import org.tizen.common.connection.ddmuilib.console.DdmConsole;
+import org.tizen.common.util.IOUtil;
 import org.tizen.sdblib.SdbCommandRejectedException;
 import org.tizen.sdblib.SyncService;
 import org.tizen.sdblib.SyncService.ISyncProgressMonitor;
@@ -45,91 +46,89 @@ import org.tizen.sdblib.TimeoutException;
 
 public class FileEntryDropAdapter implements IDropActionDelegate {
 
-       @Override
-       public boolean run(Object source, Object target) {
-               IResource resource = null;
+    @Override
+    public boolean run(Object source, Object target) {
+        IResource resource = null;
 
-               if (target instanceof IAdaptable) {
-                       target = ((IAdaptable) target).getAdapter(IResource.class);
-                       if (target != null && target instanceof IResource) {
-                               resource = (IResource) target;
-                               if (resource.getType() == IResource.FILE && resource.getParent() != null)
-                               {
-                                       resource = resource.getParent();
-                               }
-                       }
-               }
+        if (target instanceof IAdaptable) {
+            target = ((IAdaptable) target).getAdapter(IResource.class);
+            if (target != null && target instanceof IResource) {
+                resource = (IResource) target;
+                if (resource.getType() == IResource.FILE && resource.getParent() != null) {
+                    resource = resource.getParent();
+                }
+            }
+        }
 
-               String[] entries = FileEntryTransfer.getInstance().fromByteArray( (byte[]) source);
+        String[] entries = FileEntryTransfer.getInstance().fromByteArray((byte[]) source);
 
-               if (entries.length < 1)
-               {
-                       return false;
-               }
+        if (entries.length < 1) {
+            return false;
+        }
 
-               SyncService sync = null;
-               try {
-                       sync = ConnectionPlugin.getDefault().getCurrentDevice().getSyncService();
-               } catch (TimeoutException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } catch (SdbCommandRejectedException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } catch (IOException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }
-               if (sync != null) {
-                       ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor();
-                       boolean isAlwayCopy = false;
+        SyncService sync = null;
+        try {
+            sync = ConnectionPlugin.getDefault().getCurrentDevice().getSyncService();
+        } catch (TimeoutException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (SdbCommandRejectedException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        if (sync != null) {
+            ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor();
+            boolean isAlwayCopy = false;
 
-                       for (int i = 0; i < entries.length; i++) {
-                               File f = new File(entries[i]);
-                               if (resource == null )
-                               {
-                                       return false;
-                               }
-                               IPath localPath = resource.getFullPath().append(f.getName());
-                               IResource newRes = resource.getWorkspace().getRoot().findMember(localPath);
+            for (int i = 0; i < entries.length; i++) {
+                File f = new File(entries[i]);
+                if (resource == null) {
+                    return false;
+                }
+                IPath localPath = resource.getFullPath().append(f.getName());
+                IResource newRes = resource.getWorkspace().getRoot().findMember(localPath);
 
-                               String localFilePath = resource.getLocation().append(f.getName()).toOSString();
+                String localFilePath = resource.getLocation().append(f.getName()).toOSString();
 
-               if (newRes != null) {
-                                       if (isAlwayCopy == false) {
-                                               int ret = FileDialogUtils.checkOverwrite(f.getName());
-                                               switch (ret) {
-                                                       case FileDialogUtils.CANCEL_ID :
-                                                               return false;
-                                                       case FileDialogUtils.YES_TO_ALL_ID :
-                                                               isAlwayCopy = true;
-                                                               break;
-                                                       case FileDialogUtils.NO_ID :
-                                                               continue;
-                                                       default:
-                                               }
-                                       }
-                               }
-                               SyncResult result = sync.pullFile(entries[i], localFilePath     , monitor);
+                if (newRes != null) {
+                    if (isAlwayCopy == false) {
+                        int ret = FileDialogUtils.checkOverwrite(f.getName());
+                        switch (ret) {
+                        case FileDialogUtils.CANCEL_ID:
+                            return false;
+                        case FileDialogUtils.YES_TO_ALL_ID:
+                            isAlwayCopy = true;
+                            break;
+                        case FileDialogUtils.NO_ID:
+                            continue;
+                        default:
+                        }
+                    }
+                }
+                SyncResult result = sync.pullFile(entries[i], localFilePath, monitor);
 
-                               if (result.getCode() != SyncService.RESULT_OK) {
-                                       DdmConsole.printErrorToConsole(String.format(
-                                                       "Failed to pull %1$s: %2$s",
-                                                       localFilePath, result.getMessage()));
-                                       continue;
-                               } else {
-                                       if (ResourcesPlugin.getWorkspace().isTreeLocked() == false) {
-                                               try {
-                                                       resource.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
-                                               } catch (CoreException e) {
-                                                       e.printStackTrace();
-                                               }
-                                       }
-                               }
-                       }
-               }
+                if (result.getCode() != SyncService.RESULT_OK) {
+                    DdmConsole.printErrorToConsole(String.format("Failed to pull %1$s: %2$s", localFilePath, result.getMessage()));
+                    continue;
+                } else {
+                    if (ResourcesPlugin.getWorkspace().isTreeLocked() == false) {
+                        try {
+                            resource.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
+                        } catch (CoreException e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
+            }
+        }
+        if (sync != null) {
+            IOUtil.tryClose(sync);
+        }
 
-       return false;
-       }
+        return false;
+    }
 
-}
+}
\ No newline at end of file