From: bdragon.park Date: Tue, 26 Sep 2017 07:14:49 +0000 (+0900) Subject: OCF : Add ST Things SDK functionality to new project from git wizard X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9bca5ca1061479b9f4c5897f04994b73b929df14;p=sdk%2Fide%2Frt-ide-product.git OCF : Add ST Things SDK functionality to new project from git wizard Signed-off-by: bdragon.park --- diff --git a/rt-ide/tizen.rt.product.plugin/src/org/eclipse/egit/ui/internal/clone/RtGitCreateGeneralProjectPage.java b/rt-ide/tizen.rt.product.plugin/src/org/eclipse/egit/ui/internal/clone/RtGitCreateGeneralProjectPage.java index df11a25..94f8890 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/eclipse/egit/ui/internal/clone/RtGitCreateGeneralProjectPage.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/eclipse/egit/ui/internal/clone/RtGitCreateGeneralProjectPage.java @@ -26,11 +26,16 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; 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.Label; import org.eclipse.swt.widgets.Text; +import org.tizen.ocf.bridge.OcfBridgePlugin; +import org.tizen.rt.ide.Messages; /** * Allows to import a directory in the local file system as "General" project @@ -52,6 +57,12 @@ public class RtGitCreateGeneralProjectPage extends WizardPage { private boolean defaultLocation; + /* Tizen */ + // For ST Things SDK + private Button useIotCheckButton; + private boolean useIot = false; + /* ===== */ + /** * Creates a new project creation wizard page. * @param path the path to a directory in the local file system @@ -123,10 +134,47 @@ public class RtGitCreateGeneralProjectPage extends WizardPage { directoryText.setEnabled(false); GridDataFactory.fillDefaults().grab(true, false).applyTo(directoryText); + /* Tizen */ + // For ST Things SDK + // create OCF specific widgets if ocf extension plug-in included + createOcfWidget(workArea); + Dialog.applyDialogFont(workArea); } + /* Tizen */ + // For ST Things SDK + private void createOcfWidget(Composite container) { + if (OcfBridgePlugin.isOcfExtensionExist()) { + Composite c = new Composite(container, SWT.NONE); + GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_END); + gridData.horizontalSpan = 2; + c.setLayoutData(gridData); + GridLayout layout = new GridLayout(1, true); + layout.marginRight = 10; + layout.marginBottom = 0; + layout.verticalSpacing = 0; + c.setLayout(layout); + + useIotCheckButton = new Button(c, SWT.CHECK); + gridData = new GridData(GridData.HORIZONTAL_ALIGN_END); + useIotCheckButton.setLayoutData(gridData); + useIotCheckButton.setText(Messages.NewArtikProjectWizardPage2_LabelCheckButton); + useIotCheckButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + checkPage(); + } + }); + } + } + + public boolean useIotService() { + return useIot; + } + /* ===== */ + @Override public void setVisible(boolean visible) { if (visible) { @@ -151,7 +199,18 @@ public class RtGitCreateGeneralProjectPage extends WizardPage { return defaultLocation; } + public boolean canFlipToNextPage() { + return super.canFlipToNextPage() && useIot; + } + private void checkPage() { + /* Tizen */ + // For ST Things SDK + if (OcfBridgePlugin.isOcfExtensionExist() && useIotCheckButton != null) { + useIot = useIotCheckButton.getSelection(); + } + /* ===== */ + String projectName = projectText.getText(); setErrorMessage(null); try { diff --git a/rt-ide/tizen.rt.product.plugin/src/org/eclipse/egit/ui/internal/clone/RtGitImportWizard.java b/rt-ide/tizen.rt.product.plugin/src/org/eclipse/egit/ui/internal/clone/RtGitImportWizard.java index a60d880..3e71e6c 100644 --- a/rt-ide/tizen.rt.product.plugin/src/org/eclipse/egit/ui/internal/clone/RtGitImportWizard.java +++ b/rt-ide/tizen.rt.product.plugin/src/org/eclipse/egit/ui/internal/clone/RtGitImportWizard.java @@ -23,9 +23,13 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.Set; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; @@ -45,18 +49,32 @@ import org.eclipse.egit.ui.internal.provisional.wizards.IRepositorySearchResult; import org.eclipse.egit.ui.internal.provisional.wizards.NoRepositoryInfoException; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; import org.eclipse.ui.IImportWizard; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartReference; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.NewProjectAction; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.internal.ide.DialogUtil; +import org.eclipse.ui.internal.wizards.newresource.ResourceMessages; +import org.eclipse.ui.part.ISetSelectionTarget; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.tizen.ocf.bridge.OcfBridgePlugin; +import org.tizen.ocf.bridge.ui.AbstractDeviceWizardPage; +import org.tizen.ocf.bridge.ui.OcfWizardPageLoader; import org.tizen.rt.ide.Messages; import org.tizen.rt.product.RtProjectNature; @@ -122,6 +140,12 @@ public class RtGitImportWizard extends AbstractRtGitCloneWizard implements IImpo private Repository existingRepo; + /* tizen */ + // For ST Things SDK + private AbstractDeviceWizardPage devicePage; + private Map generatedFileMap; + /* ===== */ + /** * The default constructor */ @@ -151,8 +175,28 @@ public class RtGitImportWizard extends AbstractRtGitCloneWizard implements IImpo addPage(importWithDirectoriesPage); addPage(projectsImportPage); addPage(createGeneralProjectPage); + + /* tizen */ + // Add OCF pages for working with IoT cloud service + addOcfPages(); + /* ===== */ } + /* tizen */ + private void addOcfPages() { + if (OcfBridgePlugin.isOcfExtensionExist()) { + try { + devicePage = OcfWizardPageLoader.loadDeviceWizardPage(); + if (devicePage != null) { + addPage(devicePage); + } + } catch (CoreException e) { + logger.error(e.getLocalizedMessage(), e); + } + } + } + /* ===== */ + @Override protected List getCloneSourceProviders() { List cloneSourceProvider = super.getCloneSourceProviders(); @@ -185,7 +229,13 @@ public class RtGitImportWizard extends AbstractRtGitCloneWizard implements IImpo return createGeneralProjectPage; } else if (page == createGeneralProjectPage || page == projectsImportPage) + /* Tizen */ + // return null; + return devicePage; + else if (page == devicePage) { return null; + } + /* ===== */ return super.getNextPage(page); } @@ -214,14 +264,7 @@ public class RtGitImportWizard extends AbstractRtGitCloneWizard implements IImpo /* Tizen */ // Add CDT nature to current project - IProject[] currentProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - IProject project = null; - for (IProject current : currentProjects) { - if (!previousProjects.contains(current)) { - project = current; - break; - } - } + IProject project = getCurrentProject(previousProjects); if (project != null) { try { @@ -234,6 +277,20 @@ public class RtGitImportWizard extends AbstractRtGitCloneWizard implements IImpo /* ===== */ } }); + + /* Tizen */ + // post processing : perform OCF pages work + if (OcfBridgePlugin.isOcfExtensionExist() && createGeneralProjectPage.useIotService()) { + IProject project = getCurrentProject(previousProjects); + + if (project != null) { + generatedFileMap = devicePage.performFinish(project, new NullProgressMonitor()); + + // Additional work for OCF : Open files with editor + openWithEditor(project); + } + } + /* ===== */ } catch (InvocationTargetException e) { Activator.handleError(e.getCause().getMessage(), e.getCause(), true); return false; @@ -244,6 +301,18 @@ public class RtGitImportWizard extends AbstractRtGitCloneWizard implements IImpo return true; } + protected IProject getCurrentProject(List previousProjects) { + IProject[] currentProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); + IProject project = null; + for (IProject current : currentProjects) { + if (!previousProjects.contains(current)) { + project = current; + break; + } + } + return project; + } + @Override public boolean canFinish() { switch (importWithDirectoriesPage.getWizardSelection()) { @@ -252,8 +321,19 @@ public class RtGitImportWizard extends AbstractRtGitCloneWizard implements IImpo case RtGitSelectWizardPage.NEW_WIZARD: return true; case RtGitSelectWizardPage.GENERAL_WIZARD: - return createGeneralProjectPage.isPageComplete(); + /* Tizen */ + if (OcfBridgePlugin.isOcfExtensionExist()) { + if (createGeneralProjectPage.useIotService()) { + return createGeneralProjectPage.isPageComplete() && devicePage.isPageComplete(); + } else { + return createGeneralProjectPage.isPageComplete(); + } + } else { + return createGeneralProjectPage.isPageComplete(); + } + /* ===== */ } + return super.canFinish(); } @@ -352,6 +432,91 @@ public class RtGitImportWizard extends AbstractRtGitCloneWizard implements IImpo } } + /* Tizen */ + private void openWithEditor(IProject newProjectHandle) { + if (OcfBridgePlugin.isOcfExtensionExist() && createGeneralProjectPage.useIotService()) { + final IWorkbench workbench = PlatformUI.getWorkbench(); + if (workbench != null) { + IWorkbenchWindow dw = workbench.getActiveWorkbenchWindow(); + try { + if (dw != null) { + IWorkbenchPage page = dw.getActivePage(); + if (page != null && generatedFileMap != null && generatedFileMap.size() > 0) { + for (Entry item : generatedFileMap.entrySet()) { + IFile file = item.getKey(); + boolean toBeOpened = item.getValue(); + if (toBeOpened && file != null && file.exists()) { + selectAndReveal(file, dw); + + // Open editor on new file. + IDE.openEditor(page, file, true); + } + } + } + } + } catch (PartInitException e) { + DialogUtil.openError(dw.getShell(), ResourceMessages.FileResource_errorMessage, + e.getMessage(), e); + } + } + } + } + + @SuppressWarnings("unchecked") + public static void selectAndReveal(IResource resource, + IWorkbenchWindow window) { + // validate the input + if (window == null || resource == null) { + return; + } + IWorkbenchPage page = window.getActivePage(); + if (page == null) { + return; + } + + // get all the view and editor parts + List parts = new ArrayList(); + IWorkbenchPartReference refs[] = page.getViewReferences(); + for (int i = 0; i < refs.length; i++) { + IWorkbenchPart part = refs[i].getPart(false); + if (part != null) { + parts.add(part); + } + } + refs = page.getEditorReferences(); + for (int i = 0; i < refs.length; i++) { + if (refs[i].getPart(false) != null) { + parts.add(refs[i].getPart(false)); + } + } + + final ISelection selection = new StructuredSelection(resource); + Iterator itr = parts.iterator(); + while (itr.hasNext()) { + IWorkbenchPart part = (IWorkbenchPart) itr.next(); + + // get the part's ISetSelectionTarget implementation + ISetSelectionTarget target = null; + if (part instanceof ISetSelectionTarget) { + target = (ISetSelectionTarget) part; + } else { + target = part.getAdapter(ISetSelectionTarget.class); + } + + if (target != null) { + // select and reveal resource + final ISetSelectionTarget finalTarget = target; + window.getShell().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + finalTarget.selectReveal(selection); + } + }); + } + } + } + /* ===== */ + static IDialogSettings getImportWizardDialogSettings() { IDialogSettings settings = Activator.getDefault().getDialogSettings();