From b87773b26157f2b4d70de2ccd38544d4facaf43f Mon Sep 17 00:00:00 2001 From: "daeryong.park" Date: Mon, 3 Apr 2017 13:44:49 +0900 Subject: [PATCH] RTSDK : Remove unnecessary cr(\r) characters - Remove cr(\r) characters Change-Id: Iac3f4412c22fed572218e53ae9bf871c5a2b0f51 Signed-off-by: daeryong.park --- .../src/org/tizen/rt/ide/Messages.java | 160 ++--- .../tizen/rt/ide/build/RtosBuildDialogPage.java | 724 ++++++++++----------- .../org/tizen/rt/ide/build/RtosBuildWizard.java | 230 +++---- .../org/tizen/rt/ide/wizards/NewRtAppWizard.java | 444 ++++++------- 4 files changed, 779 insertions(+), 779 deletions(-) diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/Messages.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/Messages.java index 46bef9a..8894894 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/Messages.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/Messages.java @@ -1,80 +1,80 @@ -/** - * Common - * - * @since 2017. 2. 7. - * - * Copyright (c) 2000 - 2015 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; - -import org.eclipse.osgi.util.NLS; - -public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.tizen.rt.ide.messages"; //$NON-NLS-1$ - - public static String NewArtikProjectWizard_CreateOperationLabel; - public static String NewArtikProjectWizard_WindowTitle; - - public static String NewArtikProjectWizardPage_Description; - public static String NewArtikProjectWizardPage_Title; - - public static String NewArtikProjectWizardPage2_Description; - public static String NewArtikProjectWizardPage2_Title; - public static String NewArtikProjectWizardPage2_LabelBoard; - public static String NewArtikProjectWizardPage2_LabelBoardName; - public static String NewArtikProjectWizardPage2_NameColumn; - - public static String RtosBuildDialogPage_BoardNameColumn; - public static String RtosBuildDialogPage_Description; - public static String RtosBuildDialogPage_KconfigErrorMessage; - public static String RtosBuildDialogPage_KernelConfigButtonText; - public static String RtosBuildDialogPage_OptionNameColumn; - public static String RtosBuildDialogPage_Title; - public static String RtosBuildDialogPage_ToolchainButtonText; - public static String RtosBuildDialogPage_ToolchainDialogMessage; - - public static String RtosBuildWizard_WindowTitle; - - public static String RtosFlashDialogPage_Description; - public static String RtosFlashDialogPage_OptionNameColumn; - public static String RtosFlashDialogPage_Title; - - public static String RtosFlashWizard_WindowTitle; - - public static String FlashHandler_NotFoundBuildInfo; - - public static String LaunchShortcut_NotFoundBuildInfo; - public static String RtosBuildDialogPage_text_text; - public static String RtosBuildDialogPage_lblNewLabel_text; - public static String RtosBuildDialogPage_clearToolchainBtn_text; - - public static String RtosNewRtAppWizard_WindowTitle; - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} +/** + * Common + * + * @since 2017. 2. 7. + * + * Copyright (c) 2000 - 2015 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; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.tizen.rt.ide.messages"; //$NON-NLS-1$ + + public static String NewArtikProjectWizard_CreateOperationLabel; + public static String NewArtikProjectWizard_WindowTitle; + + public static String NewArtikProjectWizardPage_Description; + public static String NewArtikProjectWizardPage_Title; + + public static String NewArtikProjectWizardPage2_Description; + public static String NewArtikProjectWizardPage2_Title; + public static String NewArtikProjectWizardPage2_LabelBoard; + public static String NewArtikProjectWizardPage2_LabelBoardName; + public static String NewArtikProjectWizardPage2_NameColumn; + + public static String RtosBuildDialogPage_BoardNameColumn; + public static String RtosBuildDialogPage_Description; + public static String RtosBuildDialogPage_KconfigErrorMessage; + public static String RtosBuildDialogPage_KernelConfigButtonText; + public static String RtosBuildDialogPage_OptionNameColumn; + public static String RtosBuildDialogPage_Title; + public static String RtosBuildDialogPage_ToolchainButtonText; + public static String RtosBuildDialogPage_ToolchainDialogMessage; + + public static String RtosBuildWizard_WindowTitle; + + public static String RtosFlashDialogPage_Description; + public static String RtosFlashDialogPage_OptionNameColumn; + public static String RtosFlashDialogPage_Title; + + public static String RtosFlashWizard_WindowTitle; + + public static String FlashHandler_NotFoundBuildInfo; + + public static String LaunchShortcut_NotFoundBuildInfo; + public static String RtosBuildDialogPage_text_text; + public static String RtosBuildDialogPage_lblNewLabel_text; + public static String RtosBuildDialogPage_clearToolchainBtn_text; + + public static String RtosNewRtAppWizard_WindowTitle; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} 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 431340f..65967f7 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 @@ -1,362 +1,362 @@ -/* -* Common -* -* Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: -* Jaemin Kim -* Gyeongmin Ju -* Daeryong Park -* 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.build; - -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; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.browser.Browser; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.DirectoryDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.Text; -import org.tizen.rt.ide.Messages; -import org.tizen.rt.ide.RtosCommandManager; -import org.tizen.rt.ide.util.ResourceUtil; - -/** - * DeviceGuideDialogPage Select Emulator Wizard Feature - * @author jm.jaemin.kim{@literal } (S-Core) - */ -public class RtosBuildDialogPage extends WizardPage { - - public final static String DEFAULT_DESC_FILE = "index.html"; //$NON-NLS-1$ - public final static String DEFAULT_DESC_HTML_FORMAT = "

%s

App : %s"; //$NON-NLS-1$ - public final static String[] KERNEL_CONFIG_CMD = new String[] { "gnome-terminal", "--command", "make menuconfig" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - private Shell shell; - private Table buildOptionTable; - private Table boardTable; - private TableViewer boardTableViewer; - private TableViewer buildOptionTableViewer; - private Button selectToolchainBtn; - private Button kernelConfigBtn; - private Browser browser; - private Text toolchainText; - private Composite composite; - private Label lblNewLabel; - private Button clearToolchainBtn; - - protected RtosBuildDialogPage(String pageName, Shell shell) { - super(pageName); - this.shell = shell; - setTitle(Messages.RtosBuildDialogPage_Title); - setDescription(Messages.RtosBuildDialogPage_Description); - setErrorMessage(null); - } - - @Override - public void createControl(Composite parentComposite) { - - List boardList = RtosCommandManager.getBuildBoards(); - - Composite container = new Composite(parentComposite, SWT.NONE); - container.setLayoutData(new GridData(GridData.FILL_BOTH)); - container.setLayout(new GridLayout(1, true)); - - Composite tableComposite = new Composite(container, SWT.NONE); - tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); - GridLayout layout = new GridLayout(2, true); - layout.marginWidth = 0; - layout.horizontalSpacing = 5; - tableComposite.setLayout(layout); - - // Boards select table - boardTableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION); - - boardTable = boardTableViewer.getTable(); - boardTable.setLinesVisible(true); - boardTable.setHeaderVisible(true); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.minimumHeight = 180; - boardTable.setLayoutData(gd); - - TableColumn boardNameColumn = new TableColumn(boardTable, SWT.NONE); - boardNameColumn.setWidth(300); - boardNameColumn.setText(Messages.RtosBuildDialogPage_BoardNameColumn); - - boardTableViewer.setLabelProvider(new TableViewerProvider_1()); - boardTableViewer.setContentProvider(new ArrayContentProvider()); - boardTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent event) { - selectToolchainBtn.setEnabled(false); - clearToolchainBtn.setEnabled(false); - IStructuredSelection selection = (IStructuredSelection) event.getSelection(); - for (Object o : selection.toArray()) { - String board = (String) o; - RtosBuildWizardDialog.selectionBoard(board); - // input buildOption list - List testList = RtosCommandManager.getBuildOptions(board); - buildOptionTableViewer.setInput(testList); - if (testList != null && !testList.isEmpty()) { - boolean isActive = testList.get(0).getSetEnv(); - selectToolchainBtn.setEnabled(isActive); - clearToolchainBtn.setEnabled(isActive); - } - } - } - }); - boardTableViewer.setInput(boardList); - - // Build option select table - buildOptionTableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION); - - buildOptionTable = buildOptionTableViewer.getTable(); - buildOptionTable.setHeaderVisible(true); - buildOptionTable.setLinesVisible(true); - gd = new GridData(GridData.FILL_BOTH); - gd.minimumHeight = 180; - buildOptionTable.setLayoutData(gd); - - TableColumn optionNameColumn = new TableColumn(buildOptionTable, SWT.NONE); - optionNameColumn.setWidth(300); - optionNameColumn.setText(Messages.RtosBuildDialogPage_OptionNameColumn); - - buildOptionTableViewer.setLabelProvider(new TableViewerProvider()); - buildOptionTableViewer.setContentProvider(new ArrayContentProvider()); - buildOptionTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection) event.getSelection(); - if (selection.isEmpty()) { - browser.setText(""); //$NON-NLS-1$ - kernelConfigBtn.setEnabled(false); - setPageComplete(false); - } else { - for (Object o : selection.toArray()) { - BuildOption bOption = (BuildOption) o; - RtosBuildWizardDialog.selectionOption(bOption); - File desc = new File(bOption.getPath(), DEFAULT_DESC_FILE); - if (desc.exists()) { - browser.setUrl(desc.toURI().toString()); - } else { - browser.setText(String.format(DEFAULT_DESC_HTML_FORMAT, bOption.getBoard(), bOption.getBuildOption())); - } - kernelConfigBtn.setEnabled(true); - setPageComplete(true); - } - } - } - }); - buildOptionTableViewer.addDoubleClickListener(new IDoubleClickListener() { - @Override - public void doubleClick(DoubleClickEvent arg0) { - RtosBuildWizard wizard = (RtosBuildWizard) getWizard(); - RtosBuildWizardDialog dialog = (RtosBuildWizardDialog) wizard.getContainer(); - dialog.PressedFinished(); - } - }); - - // Description area - Composite descComposite = new Composite(container, SWT.BORDER); - descComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 2)); - GridLayout browserLayout = new GridLayout(1, true); - browserLayout.marginHeight = 0; - browserLayout.marginWidth = 0; - descComposite.setLayout(browserLayout); - - browser = new Browser(descComposite, SWT.NONE); - browser.setJavascriptEnabled(false); - browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - - composite = new Composite(container, SWT.NONE); - composite.setLayout(new GridLayout(4, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - - lblNewLabel = new Label(composite, SWT.NONE); - lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - lblNewLabel.setText(Messages.RtosBuildDialogPage_lblNewLabel_text); - - toolchainText = new Text(composite, SWT.BORDER); - toolchainText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - toolchainText.setEditable(false); - - selectToolchainBtn = new Button(composite, SWT.NONE); - selectToolchainBtn.setText(Messages.RtosBuildDialogPage_ToolchainButtonText); - selectToolchainBtn.setEnabled(false); - - clearToolchainBtn = new Button(composite, SWT.NONE); - clearToolchainBtn.setText(Messages.RtosBuildDialogPage_clearToolchainBtn_text); - clearToolchainBtn.setEnabled(false); - - selectToolchainBtn.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent arg0) { - DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SHEET); - dialog.setMessage(Messages.RtosBuildDialogPage_ToolchainDialogMessage); - String toolchainPath = dialog.open(); - if (toolchainPath != null) { - toolchainText.setText(toolchainPath); - RtosBuildWizardDialog.selectionToolchain(toolchainPath); - } - } - }); - - clearToolchainBtn.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - toolchainText.setText(""); - RtosBuildWizardDialog.selectionToolchain(null); - } - }); - - // Button group area - Composite btnGroupComposite = new Composite(container, SWT.NONE); - btnGroupComposite.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, true, false, 2, 1)); - RowLayout btnLayout = new RowLayout(SWT.HORIZONTAL); - btnLayout.marginLeft = 0; - btnLayout.spacing = 5; - btnLayout.pack = false; - btnGroupComposite.setLayout(btnLayout); - - kernelConfigBtn = new Button(btnGroupComposite, SWT.NONE); - kernelConfigBtn.setText(Messages.RtosBuildDialogPage_KernelConfigButtonText); - kernelConfigBtn.setEnabled(false); - kernelConfigBtn.addSelectionListener(new SelectionListener() { - @Override - public void widgetDefaultSelected(SelectionEvent arg0) { - } - - @Override - public void widgetSelected(SelectionEvent arg0) { - try { - Runtime.getRuntime().exec(KERNEL_CONFIG_CMD, null, - new File(ResourceUtil.getCurrentProject().getLocation().toString() + File.separator + "os")); //$NON-NLS-1$ - } catch (IOException e) { - MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosBuildDialogPage_KconfigErrorMessage); //$NON-NLS-1$ - return; - } - } - }); - - initialize(); - dialogChanged(); - - setControl(parentComposite); - } - - /** - * Tests if the current workbench selection is a suitable container to use. - */ - private void initialize() { - String toolchainPath = RtosBuildWizardDialog.getSelectionToolchain(); - if (toolchainPath != null) { - toolchainText.setText(RtosBuildWizardDialog.getSelectionToolchain()); - } else { - toolchainText.setText(""); - } - setPageComplete(false); - } - - private void dialogChanged() { - - } - - /** - * @return the shell - */ - public Shell getShell() { - return shell; - } - - private class TableViewerProvider_1 extends LabelProvider implements ITableLabelProvider { - - @Override - public Image getColumnImage(Object arg0, int columnIndex) { - return null; - } - - @Override - public String getColumnText(Object element, int columnIndex) { - // TODO: create object in associated with Device EntryList - if (element instanceof String) { - String bOption = (String) element; - switch (columnIndex) { - case 0: - return bOption; - default: - break; - } - } - return null; - } - - } - - private class TableViewerProvider extends LabelProvider implements ITableLabelProvider { - - @Override - public Image getColumnImage(Object arg0, int columnIndex) { - return null; - } - - @Override - public String getColumnText(Object element, int columnIndex) { - // TODO: create object in associated with Device EntryList - if (element instanceof BuildOption) { - BuildOption bOption = (BuildOption) element; - switch (columnIndex) { - case 0: - return bOption.getBuildOption(); - default: - break; - } - } - return null; - } - - } - -} +/* +* Common +* +* Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Jaemin Kim +* Gyeongmin Ju +* Daeryong Park +* 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.build; + +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; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.browser.Browser; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.Text; +import org.tizen.rt.ide.Messages; +import org.tizen.rt.ide.RtosCommandManager; +import org.tizen.rt.ide.util.ResourceUtil; + +/** + * DeviceGuideDialogPage Select Emulator Wizard Feature + * @author jm.jaemin.kim{@literal } (S-Core) + */ +public class RtosBuildDialogPage extends WizardPage { + + public final static String DEFAULT_DESC_FILE = "index.html"; //$NON-NLS-1$ + public final static String DEFAULT_DESC_HTML_FORMAT = "

%s

App : %s"; //$NON-NLS-1$ + public final static String[] KERNEL_CONFIG_CMD = new String[] { "gnome-terminal", "--command", "make menuconfig" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + private Shell shell; + private Table buildOptionTable; + private Table boardTable; + private TableViewer boardTableViewer; + private TableViewer buildOptionTableViewer; + private Button selectToolchainBtn; + private Button kernelConfigBtn; + private Browser browser; + private Text toolchainText; + private Composite composite; + private Label lblNewLabel; + private Button clearToolchainBtn; + + protected RtosBuildDialogPage(String pageName, Shell shell) { + super(pageName); + this.shell = shell; + setTitle(Messages.RtosBuildDialogPage_Title); + setDescription(Messages.RtosBuildDialogPage_Description); + setErrorMessage(null); + } + + @Override + public void createControl(Composite parentComposite) { + + List boardList = RtosCommandManager.getBuildBoards(); + + Composite container = new Composite(parentComposite, SWT.NONE); + container.setLayoutData(new GridData(GridData.FILL_BOTH)); + container.setLayout(new GridLayout(1, true)); + + Composite tableComposite = new Composite(container, SWT.NONE); + tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + GridLayout layout = new GridLayout(2, true); + layout.marginWidth = 0; + layout.horizontalSpacing = 5; + tableComposite.setLayout(layout); + + // Boards select table + boardTableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION); + + boardTable = boardTableViewer.getTable(); + boardTable.setLinesVisible(true); + boardTable.setHeaderVisible(true); + GridData gd = new GridData(GridData.FILL_BOTH); + gd.minimumHeight = 180; + boardTable.setLayoutData(gd); + + TableColumn boardNameColumn = new TableColumn(boardTable, SWT.NONE); + boardNameColumn.setWidth(300); + boardNameColumn.setText(Messages.RtosBuildDialogPage_BoardNameColumn); + + boardTableViewer.setLabelProvider(new TableViewerProvider_1()); + boardTableViewer.setContentProvider(new ArrayContentProvider()); + boardTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + selectToolchainBtn.setEnabled(false); + clearToolchainBtn.setEnabled(false); + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + for (Object o : selection.toArray()) { + String board = (String) o; + RtosBuildWizardDialog.selectionBoard(board); + // input buildOption list + List testList = RtosCommandManager.getBuildOptions(board); + buildOptionTableViewer.setInput(testList); + if (testList != null && !testList.isEmpty()) { + boolean isActive = testList.get(0).getSetEnv(); + selectToolchainBtn.setEnabled(isActive); + clearToolchainBtn.setEnabled(isActive); + } + } + } + }); + boardTableViewer.setInput(boardList); + + // Build option select table + buildOptionTableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION); + + buildOptionTable = buildOptionTableViewer.getTable(); + buildOptionTable.setHeaderVisible(true); + buildOptionTable.setLinesVisible(true); + gd = new GridData(GridData.FILL_BOTH); + gd.minimumHeight = 180; + buildOptionTable.setLayoutData(gd); + + TableColumn optionNameColumn = new TableColumn(buildOptionTable, SWT.NONE); + optionNameColumn.setWidth(300); + optionNameColumn.setText(Messages.RtosBuildDialogPage_OptionNameColumn); + + buildOptionTableViewer.setLabelProvider(new TableViewerProvider()); + buildOptionTableViewer.setContentProvider(new ArrayContentProvider()); + buildOptionTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + if (selection.isEmpty()) { + browser.setText(""); //$NON-NLS-1$ + kernelConfigBtn.setEnabled(false); + setPageComplete(false); + } else { + for (Object o : selection.toArray()) { + BuildOption bOption = (BuildOption) o; + RtosBuildWizardDialog.selectionOption(bOption); + File desc = new File(bOption.getPath(), DEFAULT_DESC_FILE); + if (desc.exists()) { + browser.setUrl(desc.toURI().toString()); + } else { + browser.setText(String.format(DEFAULT_DESC_HTML_FORMAT, bOption.getBoard(), bOption.getBuildOption())); + } + kernelConfigBtn.setEnabled(true); + setPageComplete(true); + } + } + } + }); + buildOptionTableViewer.addDoubleClickListener(new IDoubleClickListener() { + @Override + public void doubleClick(DoubleClickEvent arg0) { + RtosBuildWizard wizard = (RtosBuildWizard) getWizard(); + RtosBuildWizardDialog dialog = (RtosBuildWizardDialog) wizard.getContainer(); + dialog.PressedFinished(); + } + }); + + // Description area + Composite descComposite = new Composite(container, SWT.BORDER); + descComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 2)); + GridLayout browserLayout = new GridLayout(1, true); + browserLayout.marginHeight = 0; + browserLayout.marginWidth = 0; + descComposite.setLayout(browserLayout); + + browser = new Browser(descComposite, SWT.NONE); + browser.setJavascriptEnabled(false); + browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + composite = new Composite(container, SWT.NONE); + composite.setLayout(new GridLayout(4, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + lblNewLabel = new Label(composite, SWT.NONE); + lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + lblNewLabel.setText(Messages.RtosBuildDialogPage_lblNewLabel_text); + + toolchainText = new Text(composite, SWT.BORDER); + toolchainText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + toolchainText.setEditable(false); + + selectToolchainBtn = new Button(composite, SWT.NONE); + selectToolchainBtn.setText(Messages.RtosBuildDialogPage_ToolchainButtonText); + selectToolchainBtn.setEnabled(false); + + clearToolchainBtn = new Button(composite, SWT.NONE); + clearToolchainBtn.setText(Messages.RtosBuildDialogPage_clearToolchainBtn_text); + clearToolchainBtn.setEnabled(false); + + selectToolchainBtn.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent arg0) { + DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SHEET); + dialog.setMessage(Messages.RtosBuildDialogPage_ToolchainDialogMessage); + String toolchainPath = dialog.open(); + if (toolchainPath != null) { + toolchainText.setText(toolchainPath); + RtosBuildWizardDialog.selectionToolchain(toolchainPath); + } + } + }); + + clearToolchainBtn.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + toolchainText.setText(""); + RtosBuildWizardDialog.selectionToolchain(null); + } + }); + + // Button group area + Composite btnGroupComposite = new Composite(container, SWT.NONE); + btnGroupComposite.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, true, false, 2, 1)); + RowLayout btnLayout = new RowLayout(SWT.HORIZONTAL); + btnLayout.marginLeft = 0; + btnLayout.spacing = 5; + btnLayout.pack = false; + btnGroupComposite.setLayout(btnLayout); + + kernelConfigBtn = new Button(btnGroupComposite, SWT.NONE); + kernelConfigBtn.setText(Messages.RtosBuildDialogPage_KernelConfigButtonText); + kernelConfigBtn.setEnabled(false); + kernelConfigBtn.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + try { + Runtime.getRuntime().exec(KERNEL_CONFIG_CMD, null, + new File(ResourceUtil.getCurrentProject().getLocation().toString() + File.separator + "os")); //$NON-NLS-1$ + } catch (IOException e) { + MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", Messages.RtosBuildDialogPage_KconfigErrorMessage); //$NON-NLS-1$ + return; + } + } + }); + + initialize(); + dialogChanged(); + + setControl(parentComposite); + } + + /** + * Tests if the current workbench selection is a suitable container to use. + */ + private void initialize() { + String toolchainPath = RtosBuildWizardDialog.getSelectionToolchain(); + if (toolchainPath != null) { + toolchainText.setText(RtosBuildWizardDialog.getSelectionToolchain()); + } else { + toolchainText.setText(""); + } + setPageComplete(false); + } + + private void dialogChanged() { + + } + + /** + * @return the shell + */ + public Shell getShell() { + return shell; + } + + private class TableViewerProvider_1 extends LabelProvider implements ITableLabelProvider { + + @Override + public Image getColumnImage(Object arg0, int columnIndex) { + return null; + } + + @Override + public String getColumnText(Object element, int columnIndex) { + // TODO: create object in associated with Device EntryList + if (element instanceof String) { + String bOption = (String) element; + switch (columnIndex) { + case 0: + return bOption; + default: + break; + } + } + return null; + } + + } + + private class TableViewerProvider extends LabelProvider implements ITableLabelProvider { + + @Override + public Image getColumnImage(Object arg0, int columnIndex) { + return null; + } + + @Override + public String getColumnText(Object element, int columnIndex) { + // TODO: create object in associated with Device EntryList + if (element instanceof BuildOption) { + BuildOption bOption = (BuildOption) element; + switch (columnIndex) { + case 0: + return bOption.getBuildOption(); + default: + break; + } + } + return null; + } + + } + +} diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildWizard.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildWizard.java index 65f8e04..b2f9673 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildWizard.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/build/RtosBuildWizard.java @@ -1,115 +1,115 @@ -/* -* Common -* -* Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: -* jm.jemin.kim -* -* 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.build; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.IPageChangedListener; -import org.eclipse.jface.dialogs.PageChangedEvent; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.wizard.IWizardContainer; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.swt.widgets.Shell; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.tizen.rt.ide.Messages; -import org.tizen.rt.ide.RtosCommandManager; -import org.tizen.rt.ide.console.ConsoleManager; - -/** - * RtosWizard - * @author jm.jaemin.kim{@literal } (S-Core) - */ -public class RtosBuildWizard extends Wizard implements IPageChangedListener { - - private ConsoleManager consoleManager; - private Shell shell; - private IProject project; - private final String GUIDE_DIALOG_NAME = "Build Option Selection"; //$NON-NLS-1$ - private RtosBuildDialogPage rtosDialogPage = null; - private final Logger logger = LoggerFactory.getLogger(RtosBuildWizard.class); - - public RtosBuildWizard(Shell shell, IProject project) { - super(); - this.setWindowTitle(Messages.RtosBuildWizard_WindowTitle); - this.setNeedsProgressMonitor(true); - this.shell = shell; - this.project = project; - this.consoleManager = new ConsoleManager(true); - } - - @Override - public boolean performFinish() { - IWizardContainer container = getContainer(); - try { - container.run(true, false, new IRunnableWithProgress() { - @Override - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - // String selectedDeviceName = - monitor.beginTask("Build", 4); //$NON-NLS-1$ - BuildOption buildOption = RtosBuildWizardDialog.getSelectionOption(); - consoleManager.println("Build Option : " + buildOption.getBuildOption()); //$NON-NLS-1$ - monitor.worked(1); - - String toolchainPath = RtosBuildWizardDialog.getSelectionToolchain(); - monitor.worked(1); - - RtosCommandManager.runBuild(buildOption, toolchainPath, consoleManager, monitor); - try { - project.refreshLocal(IResource.DEPTH_INFINITE, monitor); - } catch (CoreException e) { - logger.error(e.getMessage(), e); - } - - monitor.done(); - } - }); - } catch (InvocationTargetException e) { - logger.error(e.getMessage(), e); - } catch (InterruptedException e) { - logger.error(e.getMessage(), e); - } - return true; - } - - @Override - public void addPages() { - rtosDialogPage = new RtosBuildDialogPage(GUIDE_DIALOG_NAME, shell); - addPage(rtosDialogPage); - WizardDialog dialog = (WizardDialog) getContainer(); - dialog.addPageChangedListener(this); - } - - @Override - public void pageChanged(PageChangedEvent arg0) { - - } -} +/* +* Common +* +* Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* jm.jemin.kim +* +* 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.build; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.IPageChangedListener; +import org.eclipse.jface.dialogs.PageChangedEvent; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.wizard.IWizardContainer; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Shell; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.rt.ide.Messages; +import org.tizen.rt.ide.RtosCommandManager; +import org.tizen.rt.ide.console.ConsoleManager; + +/** + * RtosWizard + * @author jm.jaemin.kim{@literal } (S-Core) + */ +public class RtosBuildWizard extends Wizard implements IPageChangedListener { + + private ConsoleManager consoleManager; + private Shell shell; + private IProject project; + private final String GUIDE_DIALOG_NAME = "Build Option Selection"; //$NON-NLS-1$ + private RtosBuildDialogPage rtosDialogPage = null; + private final Logger logger = LoggerFactory.getLogger(RtosBuildWizard.class); + + public RtosBuildWizard(Shell shell, IProject project) { + super(); + this.setWindowTitle(Messages.RtosBuildWizard_WindowTitle); + this.setNeedsProgressMonitor(true); + this.shell = shell; + this.project = project; + this.consoleManager = new ConsoleManager(true); + } + + @Override + public boolean performFinish() { + IWizardContainer container = getContainer(); + try { + container.run(true, false, new IRunnableWithProgress() { + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + // String selectedDeviceName = + monitor.beginTask("Build", 4); //$NON-NLS-1$ + BuildOption buildOption = RtosBuildWizardDialog.getSelectionOption(); + consoleManager.println("Build Option : " + buildOption.getBuildOption()); //$NON-NLS-1$ + monitor.worked(1); + + String toolchainPath = RtosBuildWizardDialog.getSelectionToolchain(); + monitor.worked(1); + + RtosCommandManager.runBuild(buildOption, toolchainPath, consoleManager, monitor); + try { + project.refreshLocal(IResource.DEPTH_INFINITE, monitor); + } catch (CoreException e) { + logger.error(e.getMessage(), e); + } + + monitor.done(); + } + }); + } catch (InvocationTargetException e) { + logger.error(e.getMessage(), e); + } catch (InterruptedException e) { + logger.error(e.getMessage(), e); + } + return true; + } + + @Override + public void addPages() { + rtosDialogPage = new RtosBuildDialogPage(GUIDE_DIALOG_NAME, shell); + addPage(rtosDialogPage); + WizardDialog dialog = (WizardDialog) getContainer(); + dialog.addPageChangedListener(this); + } + + @Override + public void pageChanged(PageChangedEvent arg0) { + + } +} diff --git a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/wizards/NewRtAppWizard.java b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/wizards/NewRtAppWizard.java index 378105c..b453ad3 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/wizards/NewRtAppWizard.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/tizen/rt/ide/wizards/NewRtAppWizard.java @@ -1,222 +1,222 @@ -/* - * NewRtAppWizard - * - * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * Gyeongmin Ju - * 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.wizards; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.lang.reflect.InvocationTargetException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.tizen.rt.ide.Messages; -import org.tizen.rt.ide.util.MacroUtil; -import org.tizen.rt.ide.util.ZipUtil; -import org.tizen.rt.ide.util.ZipUtil.AbstractRunner; - -public class NewRtAppWizard extends BasicNewResourceWizard { - private final Logger logger = LoggerFactory.getLogger(NewRtAppWizard.class); - - private NewRtAppWizardPage page; - - /** - * Constructor for NewRtAppWizard. - */ - public NewRtAppWizard() { - super(); - setWindowTitle(Messages.RtosNewRtAppWizard_WindowTitle); - setNeedsProgressMonitor(true); - } - - /** - * Adding the page to the wizard. - */ - public void addPages() { - page = new NewRtAppWizardPage(selection); - addPage(page); - } - - /** - * This method is called when 'Finish' button is pressed in the wizard. We will create an operation and run it using wizard as execution context. - */ - @Override - public boolean performFinish() { - final String appName = page.getAppName(); - final String localtion = page.getFileName(); - final IProject project = page.getProject(); - final String tempFileName = page.getTemplateFileName(); - IRunnableWithProgress op = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException { - try { - doFinish(appName, localtion, tempFileName, project, monitor); - } catch (CoreException e) { - throw new InvocationTargetException(e); - } finally { - monitor.done(); - } - } - }; - try { - getContainer().run(true, false, op); - - // select and reveal created app folder - IFolder folder = project.getFolder(localtion); - if (folder != null && folder.exists()) { - selectAndReveal(folder); - } - } catch (InterruptedException e) { - return false; - } catch (InvocationTargetException e) { - Throwable realException = e.getTargetException(); - MessageDialog.openError(getShell(), "Error", realException.getMessage()); - return false; - } - return true; - } - - /** - * The worker method. It will find the container, create the file if missing or just replace its contents, and open the editor on the newly created file. - */ - private void copys(File srcFile, File desFile, IProgressMonitor monitor) throws IOException { - java.nio.file.Path srcPath = Paths.get(srcFile.toString()); - java.nio.file.Path desPath = Paths.get(desFile.toString()); - - File[] tempFiles = srcFile.listFiles(); - if (tempFiles != null) { - for (File file : tempFiles) { - String name = file.getName(); - java.nio.file.Path srcPath2 = srcPath.resolve(name); - if (Files.isSymbolicLink(srcPath2)) { - continue; - } - - java.nio.file.Path desPath2 = desPath.resolve(name); - Files.copy(srcPath2, desPath2, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); - if (monitor != null) { - monitor.subTask(name); - monitor.worked(1); - } - - if (file.isDirectory()) { - copys(file, desPath2.toFile(), monitor); - } - } - } - } - - private class MacroFileRunner extends AbstractRunner { - private Map macros; - private String targetDir; - - public MacroFileRunner(Map macros, String targetDir) { - this.macros = macros; - this.targetDir = targetDir; - } - - @Override - public boolean run(boolean isDirectory, InputStream ios, String filename, int extra) { - File targetFile = new File(targetDir, filename); - - if (isDirectory) { - String path = MacroUtil.processMacro(targetFile.getAbsolutePath(), "TIZEN", macros); - File targetFileObj = new File(path); - targetFileObj.mkdirs(); - } else { - String path = MacroUtil.processMacro(targetFile.toString(), macros); - targetFile = new File(path); - File targetFileHome = targetFile.getParentFile(); - targetFileHome.mkdirs(); - - OutputStream fs = null; - try { - fs = new FileOutputStream(targetFile); - MacroUtil.processMacro(ios, fs, "TIZEN", macros); - } catch (Exception e) { - logger.error(e.getMessage()); - return false; - } finally { - if (fs != null) { - try { - fs.close(); - } catch (IOException e) { - return false; - } - } - } - } - - return true; - } - } - - private void doFinish(String appName, String appPathName, String templateFileName, IProject project, - IProgressMonitor monitor) throws CoreException { - monitor.beginTask("Creating " + appPathName, 4); //$NON-NLS-1$ - - Map macros = new HashMap(); - macros.put("TIZEN.newapp", appName); - macros.put("TIZEN.NEWAPP", appName.toUpperCase()); - - File appPathFile = new File(project.getLocation().toString(), appPathName); - appPathFile.mkdirs(); - - File tempFile = new File(templateFileName); - - if (tempFile.isDirectory()) { - File projFile = project.getFullPath().toFile(); - - try { - copys(tempFile, projFile, monitor); - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - } else if (tempFile.getName().endsWith(".zip")) { //$NON-NLS-1$ - try { - ZipUtil.unzip(tempFile.toString(), new MacroFileRunner(macros, appPathFile.toString()), monitor); - } catch (Exception e) { - logger.error(e.getMessage(), e); - } - } - - project.getFolder(appPathName).refreshLocal(IResource.DEPTH_INFINITE, monitor); - - monitor.worked(1); - } -} +/* + * NewRtAppWizard + * + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Gyeongmin Ju + * 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.wizards; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.reflect.InvocationTargetException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.tizen.rt.ide.Messages; +import org.tizen.rt.ide.util.MacroUtil; +import org.tizen.rt.ide.util.ZipUtil; +import org.tizen.rt.ide.util.ZipUtil.AbstractRunner; + +public class NewRtAppWizard extends BasicNewResourceWizard { + private final Logger logger = LoggerFactory.getLogger(NewRtAppWizard.class); + + private NewRtAppWizardPage page; + + /** + * Constructor for NewRtAppWizard. + */ + public NewRtAppWizard() { + super(); + setWindowTitle(Messages.RtosNewRtAppWizard_WindowTitle); + setNeedsProgressMonitor(true); + } + + /** + * Adding the page to the wizard. + */ + public void addPages() { + page = new NewRtAppWizardPage(selection); + addPage(page); + } + + /** + * This method is called when 'Finish' button is pressed in the wizard. We will create an operation and run it using wizard as execution context. + */ + @Override + public boolean performFinish() { + final String appName = page.getAppName(); + final String localtion = page.getFileName(); + final IProject project = page.getProject(); + final String tempFileName = page.getTemplateFileName(); + IRunnableWithProgress op = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException { + try { + doFinish(appName, localtion, tempFileName, project, monitor); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } finally { + monitor.done(); + } + } + }; + try { + getContainer().run(true, false, op); + + // select and reveal created app folder + IFolder folder = project.getFolder(localtion); + if (folder != null && folder.exists()) { + selectAndReveal(folder); + } + } catch (InterruptedException e) { + return false; + } catch (InvocationTargetException e) { + Throwable realException = e.getTargetException(); + MessageDialog.openError(getShell(), "Error", realException.getMessage()); + return false; + } + return true; + } + + /** + * The worker method. It will find the container, create the file if missing or just replace its contents, and open the editor on the newly created file. + */ + private void copys(File srcFile, File desFile, IProgressMonitor monitor) throws IOException { + java.nio.file.Path srcPath = Paths.get(srcFile.toString()); + java.nio.file.Path desPath = Paths.get(desFile.toString()); + + File[] tempFiles = srcFile.listFiles(); + if (tempFiles != null) { + for (File file : tempFiles) { + String name = file.getName(); + java.nio.file.Path srcPath2 = srcPath.resolve(name); + if (Files.isSymbolicLink(srcPath2)) { + continue; + } + + java.nio.file.Path desPath2 = desPath.resolve(name); + Files.copy(srcPath2, desPath2, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); + if (monitor != null) { + monitor.subTask(name); + monitor.worked(1); + } + + if (file.isDirectory()) { + copys(file, desPath2.toFile(), monitor); + } + } + } + } + + private class MacroFileRunner extends AbstractRunner { + private Map macros; + private String targetDir; + + public MacroFileRunner(Map macros, String targetDir) { + this.macros = macros; + this.targetDir = targetDir; + } + + @Override + public boolean run(boolean isDirectory, InputStream ios, String filename, int extra) { + File targetFile = new File(targetDir, filename); + + if (isDirectory) { + String path = MacroUtil.processMacro(targetFile.getAbsolutePath(), "TIZEN", macros); + File targetFileObj = new File(path); + targetFileObj.mkdirs(); + } else { + String path = MacroUtil.processMacro(targetFile.toString(), macros); + targetFile = new File(path); + File targetFileHome = targetFile.getParentFile(); + targetFileHome.mkdirs(); + + OutputStream fs = null; + try { + fs = new FileOutputStream(targetFile); + MacroUtil.processMacro(ios, fs, "TIZEN", macros); + } catch (Exception e) { + logger.error(e.getMessage()); + return false; + } finally { + if (fs != null) { + try { + fs.close(); + } catch (IOException e) { + return false; + } + } + } + } + + return true; + } + } + + private void doFinish(String appName, String appPathName, String templateFileName, IProject project, + IProgressMonitor monitor) throws CoreException { + monitor.beginTask("Creating " + appPathName, 4); //$NON-NLS-1$ + + Map macros = new HashMap(); + macros.put("TIZEN.newapp", appName); + macros.put("TIZEN.NEWAPP", appName.toUpperCase()); + + File appPathFile = new File(project.getLocation().toString(), appPathName); + appPathFile.mkdirs(); + + File tempFile = new File(templateFileName); + + if (tempFile.isDirectory()) { + File projFile = project.getFullPath().toFile(); + + try { + copys(tempFile, projFile, monitor); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } else if (tempFile.getName().endsWith(".zip")) { //$NON-NLS-1$ + try { + ZipUtil.unzip(tempFile.toString(), new MacroFileRunner(macros, appPathFile.toString()), monitor); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + } + + project.getFolder(appPathName).refreshLocal(IResource.DEPTH_INFINITE, monitor); + + monitor.worked(1); + } +} -- 2.7.4