RTSDK: improve current project find method
authorgyeongmin.ju <gyeongmin.ju@samsung.com>
Wed, 8 Mar 2017 07:43:37 +0000 (16:43 +0900)
committergyeongmin.ju <gyeongmin.ju@samsung.com>
Wed, 8 Mar 2017 10:29:00 +0000 (19:29 +0900)
Change-Id: Ia542d282d4f5915c344bbc449943ebebefa782bb
Signed-off-by: gyeongmin.ju <gyeongmin.ju@samsung.com>
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildDialogPage.java
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ResourceUtil.java
rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/WorkspaceUtil.java [deleted file]

index 1e2f9d1..adbd54b 100644 (file)
@@ -29,6 +29,7 @@ import java.io.File;
 import java.io.IOException;
 import java.util.List;
 
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
@@ -48,12 +49,13 @@ import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.ui.PlatformUI;
 import org.tizen.rt.ide.RtosCommandManager;
-import org.tizen.rt.ide.util.WorkspaceUtil;
+import org.tizen.rt.ide.util.ResourceUtil;
 
 /**
  * DeviceGuideDialogPage Select Emulator Wizard Feature
@@ -175,9 +177,10 @@ public class RtosBuildDialogPage extends WizardPage {
             public void widgetSelected(SelectionEvent arg0) {
                 try {
                     Runtime.getRuntime().exec(new String[] { "gnome-terminal", "--command", "make menuconfig" }, null,
-                            new File(WorkspaceUtil.getCurrentProjectPath() + File.separator + "os"));
+                            new File(ResourceUtil.getCurrentProject().getLocation().toString() + File.separator + "os"));
                 } catch (IOException e) {
-                    e.printStackTrace();
+                    MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", "Could not execute kconfig");
+                    return;
                 }
             }
         });
index 3b3dba1..3b82fe0 100644 (file)
@@ -1,3 +1,28 @@
+/*
+*  Common
+*
+* Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* jm.jemin.kim <jm.jemin.kim@samsung.com>
+* HyeongSeok Heo <harry.heo@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
+*
+*/
 package org.tizen.rt.ide.util;
 
 import org.eclipse.core.resources.IProject;
@@ -10,29 +35,36 @@ import org.eclipse.ui.ISelectionService;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
 
+/**
+ * Workspace Resource Utility Functions
+ * @author gyeongmin.ju{@literal <gyeongmin.ju>} (S-Core)
+ */
 public class ResourceUtil {
     public static IResource getCurrentResource() {
         IResource res = null;
 
         IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        IEditorPart editorPart = window.getActivePage().getActiveEditor();
-
-        if (editorPart != null) {
-            IFileEditorInput input = (IFileEditorInput) editorPart.getEditorInput();
-            res = input.getFile();
-        } else {
-            ISelectionService selectionService = window.getSelectionService();
-            if (selectionService != null) {
-                ISelection selection = selectionService.getSelection();
-                if (selection instanceof IStructuredSelection) {
-                    Object firstElement = ((IStructuredSelection) selection).getFirstElement();
-                    if (firstElement instanceof IResource) {
-                        res = (IResource) firstElement;
-                    }
+
+        ISelectionService selectionService = window.getSelectionService();
+        if (selectionService != null) {
+            ISelection selection = selectionService.getSelection();
+            if (selection instanceof IStructuredSelection) {
+                Object firstElement = ((IStructuredSelection) selection).getFirstElement();
+                if (firstElement instanceof IResource) {
+                    res = (IResource) firstElement;
                 }
             }
         }
 
+        if (res == null) {
+            IEditorPart editorPart = window.getActivePage().getActiveEditor();
+
+            if (editorPart != null) {
+                IFileEditorInput input = (IFileEditorInput) editorPart.getEditorInput();
+                res = input.getFile();
+            }
+        }
+
         return res;
     }
 
diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/WorkspaceUtil.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/WorkspaceUtil.java
deleted file mode 100644 (file)
index 7470bc8..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * Common
- *
- * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:
- * Daeryong Park <bdragon.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
- *
- */
-package org.tizen.rt.ide.util;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.ISelectionService;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-
-public class WorkspaceUtil {
-
-    public static String getCurrentProjectPath() {
-        String projPath = null;
-
-        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-        IEditorPart editorPart = window.getActivePage().getActiveEditor();
-        if (editorPart != null) {
-            IFileEditorInput input = (IFileEditorInput) editorPart.getEditorInput();
-            IFile file = input.getFile();
-            IProject activeProject = file.getProject();
-            projPath = activeProject.getLocation().toString();
-        } else {
-            ISelectionService selectionService = window.getSelectionService();
-            if (selectionService != null) {
-                ISelection selection = selectionService.getSelection();
-                if (selection instanceof IStructuredSelection) {
-                    Object firstElement = ((IStructuredSelection) selection).getFirstElement();
-                    if (firstElement instanceof IResource) {
-                        IProject activeProject = ((IResource) firstElement).getProject();
-                        projPath = activeProject.getLocation().toString();
-                    }
-                }
-            }
-        }
-
-        return projPath;
-    }
-
-}