Author: snjeza
Date: 2012-03-14 13:03:19 -0400 (Wed, 14 Mar 2012)
New Revision: 39512
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java
Log:
JBIDE-11309 Runtime created from within wizard isn't in "Target Runtime"
combo box
Modified:
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java 2012-03-14
16:30:02 UTC (rev 39511)
+++
trunk/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/wizard/ArchetypeExamplesWizardFirstPage.java 2012-03-14
17:03:19 UTC (rev 39512)
@@ -46,6 +46,7 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
@@ -55,6 +56,8 @@
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager;
import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IRuntimeLifecycleListener;
+import org.eclipse.wst.server.core.ServerCore;
import org.eclipse.wst.server.core.internal.facets.FacetUtil;
import org.jboss.ide.eclipse.as.core.util.RuntimeUtils;
import org.jboss.tools.maven.project.examples.MavenProjectExamplesActivator;
@@ -87,6 +90,8 @@
private ProjectExample projectExample;
private WizardContext context;
+ private IRuntimeLifecycleListener listener;
+
public ArchetypeExamplesWizardFirstPage() {
super(new ProjectImportConfiguration(), "", "",new
ArrayList<IWorkingSet>());
}
@@ -102,6 +107,35 @@
@Override
protected void createAdditionalControls(Composite container) {
+ listener = new IRuntimeLifecycleListener() {
+
+ @Override
+ public void runtimeRemoved(IRuntime runtime) {
+ runInUIThread();
+ }
+
+ @Override
+ public void runtimeChanged(IRuntime runtime) {
+ runInUIThread();
+ }
+
+ @Override
+ public void runtimeAdded(IRuntime runtime) {
+ runInUIThread();
+ }
+
+ private void runInUIThread() {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ configureRuntimeCombo();
+ }
+ });
+ }
+
+ };
+ ServerCore.addRuntimeLifecycleListener(listener);
GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
projectNameLabel = new Label(container, SWT.NONE);
projectNameLabel.setText(Messages.ArchetypeExamplesWizardFirstPage_ProjectName_Label);
@@ -134,15 +168,7 @@
}
});
- //TODO read facet version from project example metadata
- IProjectFacetVersion facetVersion;
- try {
- facetVersion = ProjectFacetsManager.getProjectFacet(
- IJ2EEFacetConstants.DYNAMIC_WEB).getLatestVersion();
- createServerTargetComposite(container, facetVersion);
- } catch (CoreException e) {
- e.printStackTrace();
- }
+ createServerTargetComposite(container);
Label emptyLabel = new Label(container, SWT.NONE);
emptyLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false,
@@ -160,19 +186,49 @@
createMissingRepositoriesWarning(composite, gridData);
}
- protected void createServerTargetComposite(Composite parent,
- IProjectFacetVersion facetVersion) {
+ protected void createServerTargetComposite(Composite parent) {
Label serverTargetLabel = new Label(parent, SWT.NONE);
serverTargetLabel.setText(Messages.ArchetypeExamplesWizardFirstPage_Target_Runtime_Label);
GridData gridData = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
serverTargetCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
serverTargetCombo.setLayoutData(gridData);
- serverRuntimes = getServerRuntimes(facetVersion);
serverTargetCombo.add(Messages.ArchetypeExamplesWizardFirstPage_No_TargetRuntime);
+ serverTargetCombo.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ if (isCurrentPage()) {
+ context.setProperty(MavenProjectConstants.ENTERPRISE_TARGET,
isEnterpriseTargetRuntime());
+ }
+ validateEnterpriseRepo();
+ }
+ });
+
+ configureRuntimeCombo();
+
+ }
+
+ protected void configureRuntimeCombo() {
+ if (serverTargetCombo == null || serverTargetCombo.isDisposed()) {
+ return;
+ }
+ //TODO read facet version from project example metadata
+ IProjectFacetVersion facetVersion;
+ try {
+ facetVersion = ProjectFacetsManager.getProjectFacet(
+ IJ2EEFacetConstants.DYNAMIC_WEB).getLatestVersion();
+ } catch (CoreException e) {
+ MavenProjectExamplesActivator.log(e);
+ return;
+ }
+
int i =0, selectedRuntimeIdx = 0;
String lastUsedRuntime = dialogSettings.get(TARGET_RUNTIME);
+ serverRuntimes = getServerRuntimes(facetVersion);
+ serverTargetCombo.removeAll();
+ serverTargetCombo.add(Messages.ArchetypeExamplesWizardFirstPage_No_TargetRuntime);
for (Map.Entry<String, IRuntime> entry : serverRuntimes.entrySet()) {
serverTargetCombo.add(entry.getKey());
++i;
@@ -182,20 +238,9 @@
}
}
- serverTargetCombo.addModifyListener(new ModifyListener() {
-
- @Override
- public void modifyText(ModifyEvent e) {
- if (isCurrentPage()) {
- context.setProperty(MavenProjectConstants.ENTERPRISE_TARGET,
isEnterpriseTargetRuntime());
- }
- validateEnterpriseRepo();
- }
- });
if (selectedRuntimeIdx > 0) {
serverTargetCombo.select(selectedRuntimeIdx);
}
-
}
protected void validate() {
@@ -396,6 +441,10 @@
dialogSettings.put(TARGET_RUNTIME, lastUsedRuntime.getId());
}
}
+ if (listener != null) {
+ ServerCore.removeRuntimeLifecycleListener(listener);
+ listener = null;
+ }
super.dispose();
}