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
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
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) {
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 {
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;
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;
private Repository existingRepo;
+ /* tizen */
+ // For ST Things SDK
+ private AbstractDeviceWizardPage devicePage;
+ private Map<IFile, Boolean> generatedFileMap;
+ /* ===== */
+
/**
* The default constructor
*/
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<CloneSourceProvider> getCloneSourceProviders() {
List<CloneSourceProvider> cloneSourceProvider = super.getCloneSourceProviders();
return createGeneralProjectPage;
}
else if (page == createGeneralProjectPage || page == projectsImportPage)
+ /* Tizen */
+ // return null;
+ return devicePage;
+ else if (page == devicePage) {
return null;
+ }
+ /* ===== */
return super.getNextPage(page);
}
/* 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 {
/* ===== */
}
});
+
+ /* 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;
return true;
}
+ protected IProject getCurrentProject(List<IProject> 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()) {
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();
}
}
}
+ /* 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<IFile, Boolean> 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();