From 82bc6b42ed0df1a828af21f73c8d93919052f974 Mon Sep 17 00:00:00 2001 From: "gyeongmin.ju" Date: Wed, 8 Mar 2017 16:43:37 +0900 Subject: [PATCH] RTSDK: improve current project find method Change-Id: Ia542d282d4f5915c344bbc449943ebebefa782bb Signed-off-by: gyeongmin.ju --- .../tizen/rt/ide/build/RtosBuildDialogPage.java | 9 ++- .../src/org/tizen/rt/ide/util/ResourceUtil.java | 60 ++++++++++++++----- .../src/org/tizen/rt/ide/util/WorkspaceUtil.java | 67 ---------------------- 3 files changed, 52 insertions(+), 84 deletions(-) delete mode 100644 rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/WorkspaceUtil.java diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildDialogPage.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildDialogPage.java index 1e2f9d1..adbd54b 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildDialogPage.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildDialogPage.java @@ -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; } } }); diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ResourceUtil.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ResourceUtil.java index 3b3dba1..3b82fe0 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ResourceUtil.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/ResourceUtil.java @@ -1,3 +1,28 @@ +/* +* Common +* +* Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* jm.jemin.kim +* HyeongSeok Heo +* +* 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 } (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 index 7470bc8..0000000 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/util/WorkspaceUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Common - * - * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * Daeryong Park - * - * 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; - } - -} -- 2.7.4