changeset 73:226f4abc7528

Auto-completion for selecting project When creating a new thermostat-plugin.xml file, provide auto-completion for selecting the project to place the thermostat-plugin.xml file in.
author Omair Majid <omajid@redhat.com>
date Mon, 06 Jan 2014 17:58:17 -0500
parents ceb9e092236a
children 12bf566f08e5
files src/com/redhat/thermostat/plugin/eclipse/wizards/PluginXmlProjectSelectionPage.java
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/redhat/thermostat/plugin/eclipse/wizards/PluginXmlProjectSelectionPage.java	Mon Jan 06 17:35:30 2014 -0500
+++ b/src/com/redhat/thermostat/plugin/eclipse/wizards/PluginXmlProjectSelectionPage.java	Mon Jan 06 17:58:17 2014 -0500
@@ -1,10 +1,17 @@
 package com.redhat.thermostat.plugin.eclipse.wizards;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IAdaptable;
 import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.bindings.keys.KeyStroke;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
+import org.eclipse.jface.fieldassist.TextContentAdapter;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.WizardPage;
@@ -51,6 +58,12 @@
             }
         });
 
+        String[] proposals = getOpenProjectNames().toArray(new String[0]);
+        SimpleContentProposalProvider projectProposalProvider = new SimpleContentProposalProvider(proposals);
+        TextContentAdapter contentAdapter = new TextContentAdapter();
+        ContentProposalAdapter proposalAdapter = new ContentProposalAdapter(containerText, contentAdapter, projectProposalProvider, null, null);
+        proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
+
         Button button = new Button(container, SWT.PUSH);
         button.setText("Browse...");
         button.addSelectionListener(new SelectionAdapter() {
@@ -123,4 +136,17 @@
     public String getContainerName() {
         return containerText.getText();
     }
+
+    private List<String> getOpenProjectNames() {
+        List<String> result = new ArrayList<>();
+
+        IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+        for (IProject project : projects) {
+           if (project.isOpen()) {
+               result.add(project.getName());
+           }
+        }
+
+        return result;
+    }
 }