Author: fbricon
Date: 2012-04-16 05:25:44 -0400 (Mon, 16 Apr 2012)
New Revision: 40199
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/runtimes/RuntimeUtils.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/RuntimeTypeFilter.java
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesMainPage.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/SiteFilter.java
Log:
JBIDE-10119: Filter project examples per compatible target runtime
https://issues.jboss.org/browse/JBIDE-10119
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java 2012-04-16
09:20:22 UTC (rev 40198)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java 2012-04-16
09:25:44 UTC (rev 40199)
@@ -14,6 +14,7 @@
public class Messages extends NLS {
private static final String BUNDLE_NAME =
"org.jboss.tools.project.examples.messages"; //$NON-NLS-1$
+ public static String NewProjectExamplesMainPage_TargetedRuntime;
public static String NewProjectExamplesWizardPage_Cannot_access_the_following_sites;
public static String NewProjectExamplesWizardPage_Site;
public static String Category_Other;
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2012-04-16
09:20:22 UTC (rev 40198)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2012-04-16
09:25:44 UTC (rev 40199)
@@ -146,6 +146,8 @@
// The plug-in ID
public static final String PLUGIN_ID = "org.jboss.tools.project.examples";
//$NON-NLS-1$
public static final String ALL_SITES = Messages.ProjectExamplesActivator_All;
+ public static final String ALL_RUNTIMES = Messages.ProjectExamplesActivator_All;
+
public static final String SHOW_EXPERIMENTAL_SITES = "showExperimentalSites";
//$NON-NLS-1$
public static final String USER_SITES = "userSites"; //$NON-NLS-1$
public static final boolean SHOW_EXPERIMENTAL_SITES_VALUE = false;
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java 2012-04-16
09:20:22 UTC (rev 40198)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/fixes/WTPRuntimeFix.java 2012-04-16
09:25:44 UTC (rev 40199)
@@ -12,7 +12,9 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IProject;
@@ -177,8 +179,7 @@
}
private IRuntime getBestRuntime(ProjectExample project, ProjectFix fix) {
- String allowedTypes = fix.getProperties().get(
- ProjectFix.ALLOWED_TYPES);
+ String allowedTypes = fix.getProperties().get(ProjectFix.ALLOWED_TYPES);
if (allowedTypes == null) {
ProjectExamplesActivator.log(NLS.bind(Messages.WTPRuntimeFix_Invalid_WTP_runtime_fix,
project.getName()));
return null;
@@ -365,4 +366,41 @@
return null;
}
+
+
+ public static Set<IRuntimeType> getTargetedServerRuntimes(ProjectExample example)
{
+ Set<IRuntimeType> targetedRuntimes = new HashSet<IRuntimeType>();
+ List<ProjectFix> fixes = example.getFixes();
+ if (fixes != null && !fixes.isEmpty()) {
+ IRuntime[] runtimes = ServerCore.getRuntimes();
+ if (runtimes.length > 0) {
+ for (ProjectFix fix : fixes) {
+ if (ProjectFix.WTP_RUNTIME.equals(fix.getType())) {
+
+ String allowedTypes = fix.getProperties().get(ProjectFix.ALLOWED_TYPES);
+ if (allowedTypes == null) {
+ continue;
+ }
+
+ StringTokenizer tokenizer = new StringTokenizer(allowedTypes, ",");
//$NON-NLS-1$
+ while (tokenizer.hasMoreTokens()) {
+ String allowedType = tokenizer.nextToken().trim();
+ if (allowedType.length() <= 0) {
+ continue;
+ }
+ for (IRuntime runtime:runtimes) {
+ IRuntimeType runtimeType = runtime.getRuntimeType();
+ if (runtimeType != null && (ProjectFix.ANY.equals(allowedType) ||
runtimeType.getId().equals(allowedType))) {
+ targetedRuntimes.add(runtimeType);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return targetedRuntimes;
+ }
+
+
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties 2012-04-16
09:20:22 UTC (rev 40198)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties 2012-04-16
09:25:44 UTC (rev 40199)
@@ -23,6 +23,7 @@
MarkerDialog_Resource=Resource
MarkerDialog_Select_a_marker_and_click_the_Quick_Fix_button=Select a marker and click the
Quick Fix button.
MarkerDialog_Type=Type
+NewProjectExamplesMainPage_TargetedRuntime=Targeted runtime
NewProjectExamplesWizard_Detail=Detail
NewProjectExamplesWizard_Downloading=Downloading...
NewProjectExamplesWizard_Error=Error
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/runtimes/RuntimeUtils.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/runtimes/RuntimeUtils.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/runtimes/RuntimeUtils.java 2012-04-16
09:25:44 UTC (rev 40199)
@@ -0,0 +1,40 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.project.examples.runtimes;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IRuntimeType;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
+
+public class RuntimeUtils {
+
+ /**
+ * Returns an unmodifiable {@link Set} of all {@link IRuntimeType} having at least one
corresponding {@link IServer} instance
+ * configured in this workspace.<br/>
+ *
+ * @return all configured {@link IRuntimeType}
+ */
+ public static Set<IRuntimeType> getInstalledRuntimeTypes() {
+ Set<IRuntimeType> runtimeTypes = new HashSet<IRuntimeType>();
+ for (IServer server : ServerCore.getServers()) {
+ IRuntime runtime = server.getRuntime();
+ if (runtime != null && runtime.getRuntimeType() != null) {
+ runtimeTypes.add(runtime.getRuntimeType());
+ }
+ }
+ return Collections.unmodifiableSet(runtimeTypes);
+ }
+}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesMainPage.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesMainPage.java 2012-04-16
09:20:22 UTC (rev 40198)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesMainPage.java 2012-04-16
09:25:44 UTC (rev 40199)
@@ -31,6 +31,7 @@
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
@@ -48,14 +49,17 @@
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.dialogs.FilteredTree;
import org.eclipse.ui.model.AdaptableList;
+import org.eclipse.wst.server.core.IRuntimeType;
import org.jboss.tools.project.examples.Messages;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.fixes.WTPRuntimeFix;
import org.jboss.tools.project.examples.model.IImportProjectExample;
import org.jboss.tools.project.examples.model.IProjectExampleSite;
import org.jboss.tools.project.examples.model.ProjectExample;
import org.jboss.tools.project.examples.model.ProjectExampleCategory;
import org.jboss.tools.project.examples.model.ProjectExampleUtil;
import org.jboss.tools.project.examples.model.ProjectFix;
+import org.jboss.tools.project.examples.runtimes.RuntimeUtils;
/**
* @author snjeza
@@ -73,6 +77,7 @@
//private NewProjectExamplesReadyPage readyPage;
private List<IProjectExamplesWizardPage> pages;
private ProjectExample selectedProject;
+ private Combo targetRuntimeTypesCombo;
public NewProjectExamplesMainPage(NewProjectExamplesRequirementsPage requirementsPage,
List<IProjectExamplesWizardPage> pages) {
super("org.jboss.tools.project.examples.main"); //$NON-NLS-1$
@@ -109,6 +114,10 @@
new Label(siteComposite,SWT.NONE).setText(Messages.NewProjectExamplesWizardPage_Site);
siteCombo = new Combo(siteComposite,SWT.READ_ONLY);
siteCombo.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
+
+ new
Label(siteComposite,SWT.NONE).setText(Messages.NewProjectExamplesMainPage_TargetedRuntime);
+ targetRuntimeTypesCombo = new Combo(siteComposite, SWT.READ_ONLY);
+ targetRuntimeTypesCombo .setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true,
false));
new Label(composite,SWT.NONE).setText(Messages.NewProjectExamplesWizardPage_Projects);
@@ -132,7 +141,8 @@
viewer.setContentProvider(new ProjectContentProvider());
final SiteFilter siteFilter = new SiteFilter();
- viewer.addFilter(siteFilter);
+ final RuntimeTypeFilter serverFilter = new RuntimeTypeFilter();
+ viewer.setFilters(new ViewerFilter[]{siteFilter, serverFilter});
Label descriptionLabel = new Label(composite,SWT.NONE);
descriptionLabel.setText(Messages.NewProjectExamplesWizardPage_Description);
@@ -225,29 +235,76 @@
public void widgetSelected(SelectionEvent e) {
IPreferenceStore store = ProjectExamplesActivator.getDefault().getPreferenceStore();
store.setValue(ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES,
button.getSelection());
+
+ //Store current combo selections
+ String selectedRuntime = targetRuntimeTypesCombo.getText();
+ String selectedSite = siteCombo.getText();
+
+ //Rebuild the combo lists
refresh(viewer, true);
- if (siteCombo != null) {
- String[] items = getItems();
- int index = siteCombo.getSelectionIndex();
- siteCombo.setItems(items);
- if (items.length > 0 && (index < 0 || index > items.length) ) {
- siteCombo.select(0);
- } else {
- siteCombo.select(index);
- }
- }
+
+ //Restore the combo selections with initial values if possible
+ restoreCombo(targetRuntimeTypesCombo, selectedRuntime);
+ restoreCombo(siteCombo, selectedSite);
+
siteFilter.setSite(siteCombo.getText());
viewer.refresh();
}
});
+
+
+ targetRuntimeTypesCombo.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ serverFilter.setRuntimeType(targetRuntimeTypesCombo.getText());
+ viewer.refresh();
+ }
+ });
+
+
setPageComplete(false);
setControl(composite);
-
+
refresh(viewer, true);
siteCombo.setText(ProjectExamplesActivator.ALL_SITES);
+
+ targetRuntimeTypesCombo.setText(ProjectExamplesActivator.ALL_RUNTIMES);
+
+
+
}
+
+ private void loadRuntimeTypes() {
+ if (targetRuntimeTypesCombo == null) {
+ return;
+ }
+ targetRuntimeTypesCombo.removeAll();
+ targetRuntimeTypesCombo.add(ProjectExamplesActivator.ALL_RUNTIMES);
+
+ Set<IRuntimeType> installedRuntimeTypes =
RuntimeUtils.getInstalledRuntimeTypes();
+ List<IRuntimeType> sortedTypes = new ArrayList<IRuntimeType>();
+
+ for (ProjectExampleCategory category : categories) {
+ for (ProjectExample project : category.getProjects()) {
+ for (IRuntimeType type : WTPRuntimeFix.getTargetedServerRuntimes(project)) {
+ if (!sortedTypes.contains(type)) {
+ //If runtime types have a server instance, display them first
+ if (installedRuntimeTypes.contains(type)) {
+ sortedTypes.add(0, type);
+ } else {
+ sortedTypes.add(type);
+ }
+ }
+ }
+ }
+ }
+
+ for (IRuntimeType type : sortedTypes) {
+ targetRuntimeTypesCombo.add(type.getName());
+ }
+ }
private void refresh(final TreeViewer viewer, boolean show) {
AdaptableList input = new AdaptableList(getCategories(show));
@@ -255,6 +312,7 @@
viewer.refresh();
String[] items = getItems();
siteCombo.setItems(items);
+ loadRuntimeTypes();
}
private List<ProjectExampleCategory> getCategories(boolean show) {
@@ -411,5 +469,16 @@
public ProjectExample getSelectedProject() {
return selectedProject;
}
+
+ private static void restoreCombo(Combo combo, String initialValue) {
+ //Look position of initial value
+ int selectedIdx = combo.indexOf(initialValue);
+ if (selectedIdx < 0) {
+ //If initial value not found, reset to first item
+ selectedIdx = 0;
+ }
+ //Reset position of combo to the appropriate item index
+ combo.select(selectedIdx);
+ }
}
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/RuntimeTypeFilter.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/RuntimeTypeFilter.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/RuntimeTypeFilter.java 2012-04-16
09:25:44 UTC (rev 40199)
@@ -0,0 +1,80 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2012 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.project.examples.wizard;
+
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.wst.server.core.IRuntimeType;
+import org.jboss.tools.project.examples.Messages;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.fixes.WTPRuntimeFix;
+import org.jboss.tools.project.examples.model.ProjectExample;
+import org.jboss.tools.project.examples.model.ProjectExampleCategory;
+import org.jboss.tools.project.examples.model.ProjectModelElement;
+
+/**
+ *
+ * @author Fred Bricon
+ *
+ */
+public class RuntimeTypeFilter extends ViewerFilter {
+
+ private String runtimeType;
+
+ public RuntimeTypeFilter() {
+ super();
+ runtimeType = Messages.ProjectExamplesActivator_All;
+ }
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (! (element instanceof ProjectModelElement) ) {
+ return false;
+ }
+ if (runtimeType.equals(ProjectExamplesActivator.ALL_RUNTIMES)) {
+ return true;
+ }
+
+ if (element instanceof ProjectExampleCategory) {
+ ProjectExampleCategory category = (ProjectExampleCategory) element;
+ List<ProjectExample> projects = category.getProjects();
+ for (ProjectExample project:projects) {
+ if (hasServer(project)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ boolean select = false;
+ if (element instanceof ProjectExample) {
+ select = hasServer((ProjectExample) element);
+ }
+ return select;
+ }
+
+ private boolean hasServer(ProjectExample project) {
+ Set<IRuntimeType> runtimes = WTPRuntimeFix.getTargetedServerRuntimes(project);
+ for (IRuntimeType r : runtimes) {
+ if (runtimeType.equals(r.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void setRuntimeType(String runtimeType) {
+ this.runtimeType = runtimeType;
+ }
+
+}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/SiteFilter.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/SiteFilter.java 2012-04-16
09:20:22 UTC (rev 40198)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/SiteFilter.java 2012-04-16
09:25:44 UTC (rev 40199)
@@ -39,38 +39,28 @@
if (! (element instanceof ProjectModelElement) ) {
return false;
}
+
+ if (site.equals(ProjectExamplesActivator.ALL_SITES)) {
+ return true;
+ }
+
if (element instanceof ProjectExampleCategory) {
ProjectExampleCategory category = (ProjectExampleCategory) element;
- int size = 0;
- if (site.equals(ProjectExamplesActivator.ALL_SITES)) {
- size += category.getProjects().size();
- } else {
- IProjectExampleSite categorySite = category.getSite();
- if (categorySite == null) {
- return false;
+ IProjectExampleSite categorySite = category.getSite();
+ if (categorySite == null || !site.equals(categorySite.getName())) {
+ return false;
+ }
+ List<ProjectExample> projects = category.getProjects();
+ for (ProjectExample project:projects) {
+ IProjectExampleSite projectSite = project.getSite();
+ if (projectSite != null && site.equals(projectSite.getName())) {
+ return true;
}
- if (!site.equals(categorySite.getName())) {
- return false;
- }
- List<ProjectExample> projects = category.getProjects();
- for (ProjectExample project:projects) {
- IProjectExampleSite projectSite = project.getSite();
- if (projectSite == null) {
- continue;
- }
-
- if (site.equals(projectSite.getName())) {
- size++;
- }
- }
}
- return size > 0;
- }
- ProjectModelElement model = (ProjectModelElement) element;
- if (model.getSite() == null) {
return false;
}
- if ( site.equals(ProjectExamplesActivator.ALL_SITES) ||
site.equals(model.getSite().getName())) {
+ ProjectModelElement model = (ProjectModelElement) element;
+ if (model.getSite() != null && site.equals(model.getSite().getName())) {
return true;
}
return false;