Author: fbricon
Date: 2012-01-18 04:24:06 -0500 (Wed, 18 Jan 2012)
New Revision: 37935
Removed:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/model/Tutorial.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/model/TutorialCategory.java
Modified:
trunk/central/plugins/org.jboss.tools.central/plugin.xml
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/JBossCentralActivator.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTutorialsHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/dialogs/ProjectExamplesDialog.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/JBossCentralEditor.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshTutorialsJob.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
Log:
JBIDE-10641 : Replace hard coded tutorials in central with a tag-based search
Modified: trunk/central/plugins/org.jboss.tools.central/plugin.xml
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/plugin.xml 2012-01-18 09:20:13 UTC (rev
37934)
+++ trunk/central/plugins/org.jboss.tools.central/plugin.xml 2012-01-18 09:24:06 UTC (rev
37935)
@@ -221,58 +221,5 @@
commandId="org.jboss.tools.central.newProjectExamplesWizard"
icon="icons/examples_wiz.gif">
</image>
- </extension>
-
- <extension
- point="org.jboss.tools.central.tutorials">
- <category
- id="org.jboss.tools.central.javaee6.quickstart"
- name="Java EE Archetypes"
- priority="1" />
- <tutorial
- id="org.jboss.tools.central.jbossas.quickstart.jbossJavaee6Webapp"
- categoryId="org.jboss.tools.central.javaee6.quickstart"
- name="Java EE Web Project"
- type="projectExample"
- priority="1"
- icon="icons/newwebprj_wiz.gif"
- reference="Java EE 6 Quickstarts::jboss-javaee6-webapp"/>
-
- <tutorial
- id="org.jboss.tools.central.jbossas.quickstart.jbossJavaee6Ear"
- categoryId="org.jboss.tools.central.javaee6.quickstart"
- name="Java EE Project"
- type="projectExample"
- priority="2"
- icon="icons/ear-wiz-icon.gif"
- reference="Java EE 6 Quickstarts::multi-javaee6-archetype"/>
-
- <tutorial
- id="org.jboss.tools.central.jbossas.quickstart.jbossJavaee6Poh5"
- categoryId="org.jboss.tools.central.javaee6.quickstart"
- name="HTML5 Project"
- type="projectExample"
- priority="3"
- icon="icons/html5.png"
- reference="Java EE 6
Quickstarts::jboss-javaee6-poh5-archetype"/>
-
- <tutorial
-
id="org.jboss.tools.central.jbossas.quickstart.jbossJavaee6SpringMvc"
- categoryId="org.jboss.tools.central.javaee6.quickstart"
- name="Spring MVC Project"
- type="projectExample"
- priority="4"
- icon="icons/spring_wiz.gif"
- reference="Java EE 6 Quickstarts::spring-mvc-webapp"/>
-
- <tutorial
-
id="org.jboss.tools.central.jbossas.quickstart.jbossJavaee6Richfaces"
- categoryId="org.jboss.tools.central.javaee6.quickstart"
- name="RichFaces Project"
- type="projectExample"
- priority="5"
- icon="icons/rf_logo.png"
- reference="Java EE 6
Quickstarts::richfaces-archetype-simpleapp"/>
- </extension>
-
+ </extension>
</plugin>
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/JBossCentralActivator.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/JBossCentralActivator.java 2012-01-18
09:20:13 UTC (rev 37934)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/JBossCentralActivator.java 2012-01-18
09:24:06 UTC (rev 37935)
@@ -12,9 +12,7 @@
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
import java.util.Dictionary;
-import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
@@ -59,8 +57,7 @@
import org.jboss.tools.central.configurators.IJBossCentralConfigurator;
import org.jboss.tools.central.editors.JBossCentralEditor;
import org.jboss.tools.central.editors.JBossCentralEditorInput;
-import org.jboss.tools.central.model.Tutorial;
-import org.jboss.tools.central.model.TutorialCategory;
+import org.jboss.tools.project.examples.model.Category;
import org.jboss.tools.project.examples.model.Project;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -133,10 +130,10 @@
public static final String SEARCH_RED_HAT_CUSTOMER_PORTAL = "Search Red Hat
Customer Portal ";
- public Map<String, TutorialCategory> tutorialCategories;
-
private BundleContext bundleContext;
+ private Map<Category, List<Project>> tutorialCategories;
+
public static final int MAX_FEEDS = 100;
private static final Object CONFIGURATOR = "configurator";
@@ -180,7 +177,6 @@
plugin = null;
bundleContext = null;
- tutorialCategories = null;
super.stop(context);
}
@@ -405,92 +401,6 @@
return configurator;
}
- public Map<String, TutorialCategory> getTutorialCategories() {
- if (tutorialCategories == null) {
- tutorialCategories = new HashMap<String, TutorialCategory>();
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint extensionPoint = registry
- .getExtensionPoint(TUTORIALS_EXTENSION_ID);
- IExtension[] extensions = extensionPoint.getExtensions();
- for (int i = 0; i < extensions.length; i++) {
- IExtension extension = extensions[i];
- IConfigurationElement[] configurationElements = extension
- .getConfigurationElements();
- for (int j = 0; j < configurationElements.length; j++) {
- IConfigurationElement configurationElement = configurationElements[j];
- if (CATEGORY.equals(configurationElement.getName())) {
- String name = configurationElement.getAttribute(NAME);
- String id = configurationElement.getAttribute(ID);
- String description = configurationElement
- .getAttribute(DESCRIPTION);
- String priorityString = configurationElement
- .getAttribute(PRIORITY);
- int priority = Integer.MAX_VALUE;
- if (priorityString != null) {
- try {
- priority = new Integer(priorityString)
- .intValue();
- } catch (NumberFormatException e) {
- log(e);
- }
- }
- TutorialCategory category = new TutorialCategory(id,
- name, priority, description);
- tutorialCategories.put(id, category);
- }
- }
- for (int j = 0; j < configurationElements.length; j++) {
- IConfigurationElement configurationElement = configurationElements[j];
- if (TUTORIAL.equals(configurationElement.getName())) {
- String name = configurationElement.getAttribute(NAME);
- String id = configurationElement.getAttribute(ID);
- String type = configurationElement.getAttribute(TYPE);
- String reference = configurationElement
- .getAttribute(REFERENCE);
- String priorityString = configurationElement
- .getAttribute(PRIORITY);
- String description = configurationElement
- .getAttribute(DESCRIPTION);
- String iconPath = configurationElement
- .getAttribute(ICON);
- int priority = Integer.MAX_VALUE;
- if (priorityString != null) {
- try {
- priority = new Integer(priorityString)
- .intValue();
- } catch (NumberFormatException e) {
- log(e);
- }
- }
- String categoryId = configurationElement
- .getAttribute(CATEGORY_ID);
- TutorialCategory category = tutorialCategories
- .get(categoryId);
- if (category == null) {
- log("Invalid tutorial: id=" + id);
- continue;
- }
- Tutorial tutorial = new Tutorial(id, name, type,
- reference, priority, category, description,
- iconPath);
- category.getTutorials().add(tutorial);
- }
- }
- }
- List<TutorialCategory> emptyCategories = new
ArrayList<TutorialCategory>();
- for (TutorialCategory category : tutorialCategories.values()) {
- if (category.getTutorials().size() == 0) {
- emptyCategories.add(category);
- }
- }
- for (TutorialCategory category : emptyCategories) {
- tutorialCategories.remove(category.getId());
- }
- }
-
- return tutorialCategories;
- }
-
public Image getImage(String imagePath) {
ImageRegistry registry = getImageRegistry();
Image image = registry.get(imagePath);
@@ -503,23 +413,15 @@
return image;
}
- public void setTutorialCategories(
- Map<String, TutorialCategory> tutorialCategories) {
- this.tutorialCategories = tutorialCategories;
- }
-
- public String getDescription(Tutorial tutorial) {
- String description = tutorial.getDescription();
- Project project = tutorial.getProjectExamples();
- if (project.getDescription() != null) {
- description = project.getDescription();
- }
- StringBuffer buffer = new StringBuffer();
- buffer.append(description);
+ public String getDescription(Project project) {
+ StringBuilder buffer = new StringBuilder();
+ if (project.getDescription() != null) {
+ buffer.append(project.getDescription());
+ }
buffer.append("\n\n");
buffer.append("Size: ");
buffer.append(project.getSizeAsText());
- if (project.getUnsatisfiedFixes().size() > 0) {
+ if (project.getUnsatisfiedFixes() != null &&
project.getUnsatisfiedFixes().size() > 0) {
buffer.append("\n\n");
}
return buffer.toString();
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTutorialsHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTutorialsHandler.java 2012-01-18
09:20:13 UTC (rev 37934)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTutorialsHandler.java 2012-01-18
09:24:06 UTC (rev 37935)
@@ -15,7 +15,6 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.jobs.Job;
-import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.central.jobs.RefreshTutorialsJob;
/**
@@ -28,7 +27,6 @@
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (RefreshTutorialsJob.INSTANCE.getState() == Job.NONE) {
- JBossCentralActivator.getDefault().setTutorialCategories(null);
RefreshTutorialsJob.INSTANCE.schedule();
}
return null;
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/dialogs/ProjectExamplesDialog.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/dialogs/ProjectExamplesDialog.java 2012-01-18
09:20:13 UTC (rev 37934)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/dialogs/ProjectExamplesDialog.java 2012-01-18
09:24:06 UTC (rev 37935)
@@ -12,6 +12,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -62,7 +63,6 @@
import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.central.actions.JBossRuntimeDetectionPreferencesHandler;
import org.jboss.tools.central.editors.DescriptionToolTip;
-import org.jboss.tools.central.model.Tutorial;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.model.Project;
import org.jboss.tools.project.examples.model.ProjectFix;
@@ -76,7 +76,7 @@
*/
public class ProjectExamplesDialog extends FormDialog implements IRunnableContext {
- private Tutorial tutorial;
+ private Project tutorial;
private FormToolkit toolkit;
private ScrolledForm form;
private Composite fixesComposite;
@@ -85,11 +85,11 @@
private Control fLastControl;
private Set<Button> controls = new HashSet<Button>();
- public ProjectExamplesDialog(Shell parentShell, Tutorial tutorial) {
+ public ProjectExamplesDialog(Shell parentShell, Project project) {
super(parentShell);
setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER
| SWT.RESIZE | getDefaultOrientation());
- this.tutorial = tutorial;
+ this.tutorial = project;
//setHelpAvailable(false);
}
@@ -100,7 +100,7 @@
toolkit = mform.getToolkit();
toolkit.getHyperlinkGroup().setHyperlinkUnderlineMode(HyperlinkSettings.UNDERLINE_HOVER);
form.getBody().setLayout(new GridLayout());
- form.setText(tutorial.getName());
+ form.setText(tutorial.getShortDescription());
Section descSection = toolkit.createSection(form.getBody(),
ExpandableComposite.TITLE_BAR|ExpandableComposite.EXPANDED);
descSection.setText("Description");
descSection.setLayout(new GridLayout());
@@ -140,16 +140,15 @@
controls.clear();
addButtons();
- Project project = tutorial.getProjectExamples();
- List<ProjectFix> fixes = project.getFixes();
+ List<ProjectFix> fixes = tutorial.getFixes();
List<ProjectFix> unsatisfiedFixes = new ArrayList<ProjectFix>();
- project.setUnsatisfiedFixes(unsatisfiedFixes);
+ tutorial.setUnsatisfiedFixes(unsatisfiedFixes);
for (ProjectFix fix:fixes) {
- if (!ProjectExamplesActivator.canFix(project, fix)) {
+ if (!ProjectExamplesActivator.canFix(tutorial, fix)) {
unsatisfiedFixes.add(fix);
}
}
- fixes = project.getUnsatisfiedFixes();
+ fixes = tutorial.getUnsatisfiedFixes();
disposeChildren(fixesComposite);
reqSection.setVisible(fixes.size() > 0);
if (fixes.size() > 0) {
@@ -511,9 +510,7 @@
@Override
protected void okPressed() {
super.okPressed();
- List<Project> selectedProjects = new ArrayList<Project>();
- selectedProjects.add(tutorial.getProjectExamples());
- ProjectExamplesActivator.importProjectExamples(selectedProjects, true);
+ ProjectExamplesActivator.importProjectExamples(Arrays.asList(tutorial), true);
}
}
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java 2012-01-18
09:20:13 UTC (rev 37934)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java 2012-01-18
09:24:06 UTC (rev 37935)
@@ -99,11 +99,8 @@
import org.jboss.tools.central.jobs.RefreshNewsJob;
import org.jboss.tools.central.jobs.RefreshTutorialsJob;
import org.jboss.tools.central.model.FeedsEntry;
-import org.jboss.tools.central.model.Tutorial;
-import org.jboss.tools.central.model.TutorialCategory;
-import org.jboss.tools.project.examples.ProjectExamplesActivator;
+import org.jboss.tools.project.examples.model.Category;
import org.jboss.tools.project.examples.model.Project;
-import org.jboss.tools.project.examples.model.ProjectFix;
import org.osgi.framework.Bundle;
/**
@@ -113,7 +110,6 @@
*/
public class GettingStartedPage extends AbstractJBossCentralPage {
- private static final String ORG_JBOSS_TOOLS_CENTRAL_JAVAEE6_QUICKSTART =
"org.jboss.tools.central.javaee6.quickstart";
private static final String NEWS_WARNING_ID =
"org.jboss.tools.central.newsWarning";
private static final String BLOGS_WARNING_ID =
"org.jboss.tools.central.blogsWarning";
@@ -145,7 +141,7 @@
private Composite projectsComposite;
private Composite documentationComposite;
- private Set<TutorialCategory> expandedCategories = new
HashSet<TutorialCategory>();
+ private Set<Category> expandedCategories = new HashSet<Category>();
private Section newsSection;
private ScrolledComposite newsScrollComposite;
private PageBook newsPageBook;
@@ -656,13 +652,8 @@
}
}
- private void displayTutorialLinks(final TutorialCategory category, final Composite
composite, boolean addTooltips) {
- for (final Tutorial tutorial:category.getTutorials()) {
- Project project = tutorial.getProjectExamples();
- if (project == null) {
- continue;
- }
-
+ private void displayTutorialLinks(final Collection<Project> tutorials, final
Composite composite, boolean addTooltips) {
+ for (final Project tutorial : tutorials) {
FormText tutorialText = toolkit.createFormText(composite, true);
configureTutorialText(tutorialText, tutorial);
if (addTooltips) {
@@ -879,7 +870,7 @@
showException(tutorialPageBook, tutorialsExceptionText, job.getException());
return;
}
- Map<String, TutorialCategory> categories = job.getTutorialCategories();
+ Map<Category, List<Project>> categories = job.getTutorialCategories();
if (categories == null || categories.size() == 0) {
showNote(tutorialPageBook, tutorialsNoteText, tutorialScrollComposite);
return;
@@ -889,26 +880,21 @@
@Deprecated
//This method should be removed once the EE6 archetypes are wizardified
- private void updateNewProjects(TutorialCategory tutorialCategory) {
+ private void updateNewProjects(List<Project> wizardProjects) {
if (!newProjectsInitialized) {
- if (tutorialCategory != null) {
+ if (wizardProjects != null) {
newProjectsInitialized = true;
- displayTutorialLinks(tutorialCategory, projectsComposite, false);
+ displayTutorialLinks(wizardProjects, projectsComposite, false);
resize(true);
}
}
}
- private void showTutorials(Map<String, TutorialCategory> categories) {
+ private void showTutorials(Map<Category, List<Project>> categories) {
disposeChildren(tutorialsComposite);
- List<TutorialCategory> sortedCategories = getSortedCategories(categories);
- for (final TutorialCategory category:sortedCategories) {
- //TEMPORARY HACK FOR JBIDE-10053 (Java EE6 archetypes in the project section)
- //Should be removed once these archetype tutorials are changed to use wizards as per
JBIDE-10264
- if (ORG_JBOSS_TOOLS_CENTRAL_JAVAEE6_QUICKSTART.equals(category.getId())) {
- //bail
- continue;
- }
+ List<Category> sortedCategories = new
ArrayList<Category>(categories.keySet());
+ Collections.sort(sortedCategories);
+ for (final Category category : sortedCategories) {
int style = ExpandableComposite.TITLE_BAR|ExpandableComposite.TWISTIE;
if (expandedCategories.contains(category)) {
style|=ExpandableComposite.EXPANDED;
@@ -941,7 +927,7 @@
}
});
- displayTutorialLinks(category, composite, true);
+ displayTutorialLinks(categories.get(category), composite, true);
categoryComposite.setClient(composite);
String description = category.getDescription();
if (description != null && !description.isEmpty() &&
categoryComposite.getControl() != null) {
@@ -958,16 +944,7 @@
//recomputeScrollComposite(tutorialScrollComposite, tutorialPageBook);
}
- private List<TutorialCategory> getSortedCategories(
- Map<String, TutorialCategory> categories) {
- Collection<TutorialCategory> tempCategories = categories.values();
- List<TutorialCategory> sortedCategories = new
ArrayList<TutorialCategory>();
- sortedCategories.addAll(tempCategories);
- Collections.sort(sortedCategories);
- return sortedCategories;
- }
-
- private Font getBoldFont(Font font) {
+ private Font getBoldFont(Font font) {
if (categoryFont != null) {
return categoryFont;
}
@@ -979,7 +956,7 @@
return categoryFont;
}
- private void hookTooltip(FormText tutorialText, Tutorial tutorial) {
+ private void hookTooltip(FormText tutorialText, Project tutorial) {
final String description =
JBossCentralActivator.getDefault().getDescription(tutorial);
if (description != null && !description.isEmpty()) {
ToolTip toolTip = new DescriptionToolTip(tutorialText, description);
@@ -987,33 +964,26 @@
}
}
- protected void configureTutorialText(FormText tutorialText, final Tutorial tutorial) {
+ protected void configureTutorialText(FormText tutorialText, final Project tutorial) {
StringBuilder buffer = new StringBuilder();
buffer.append(JBossCentralActivator.FORM_START_TAG);
buffer.append("<img href=\"image\"/> ");
buffer.append("<a href=\"link\">");
- buffer.append(tutorial.getName());
+ buffer.append(tutorial.getShortDescription());
buffer.append("</a> ");
buffer.append(JBossCentralActivator.FORM_END_TAG);
- String text = buffer.toString();
- tutorialText.setText(text , true, false);
- Image image;
- Project project = tutorial.getProjectExamples();
- List<ProjectFix> fixes = project.getFixes();
- List<ProjectFix> unsatisfiedFixes = new ArrayList<ProjectFix>();
- project.setUnsatisfiedFixes(unsatisfiedFixes);
- for (ProjectFix fix:fixes) {
- if (!ProjectExamplesActivator.canFix(project, fix)) {
- unsatisfiedFixes.add(fix);
- }
+ tutorialText.setText(buffer.toString() , true, false);
+
+ String iconPath = tutorial.getIconPath();
+ if (iconPath != null) {
+ Image image = JBossCentralActivator.getDefault().getImage(tutorial.getIconPath());
+ if (image != null) {
+ tutorialText.setImage("image", image);
+ }
}
- //JBIDE-10303 : never display a warning image
- image = JBossCentralActivator.getDefault().getImage(tutorial.getIconPath());
- tutorialText.setImage("image", image);
tutorialText.addHyperlinkListener(new HyperlinkAdapter() {
-
@Override
public void linkActivated(HyperlinkEvent e) {
Object object = e.data;
@@ -1288,9 +1258,9 @@
//TEMPORARY HACK FOR JBIDE-10053 (Java EE6 archetypes in the project section)
//Should be removed once these archetype tutorials are changed to use wizards as per
JBIDE-10264
RefreshTutorialsJob job = RefreshTutorialsJob.INSTANCE;
- Map<String, TutorialCategory> categories = job.getTutorialCategories();
- if (categories != null){
- updateNewProjects(categories.get(ORG_JBOSS_TOOLS_CENTRAL_JAVAEE6_QUICKSTART));
+ List<Project> wizardProjects = job.getWizardProjects();
+ if (wizardProjects != null){
+ updateNewProjects(wizardProjects);
}
}
});
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/JBossCentralEditor.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/JBossCentralEditor.java 2012-01-18
09:20:13 UTC (rev 37934)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/JBossCentralEditor.java 2012-01-18
09:24:06 UTC (rev 37935)
@@ -47,10 +47,6 @@
import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.central.actions.OpenJBossBlogsHandler;
import org.jboss.tools.central.editors.xpl.TextSearchControl;
-import org.jboss.tools.central.jobs.RefreshBlogsJob;
-import org.jboss.tools.central.jobs.RefreshDiscoveryJob;
-import org.jboss.tools.central.jobs.RefreshNewsJob;
-import org.jboss.tools.central.jobs.RefreshTutorialsJob;
/**
*
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshTutorialsJob.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshTutorialsJob.java 2012-01-18
09:20:13 UTC (rev 37934)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/jobs/RefreshTutorialsJob.java 2012-01-18
09:24:06 UTC (rev 37935)
@@ -11,18 +11,15 @@
package org.jboss.tools.central.jobs;
import java.util.ArrayList;
-import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.jboss.tools.central.JBossCentralActivator;
-import org.jboss.tools.central.model.Tutorial;
-import org.jboss.tools.central.model.TutorialCategory;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.model.Category;
import org.jboss.tools.project.examples.model.Project;
@@ -37,7 +34,10 @@
public class RefreshTutorialsJob extends Job {
private Exception exception;
- private Map<String, TutorialCategory> tutorialCategories;
+ private Map<Category,List<Project>> tutorialCategories;
+
+ private List<Project> wizardProjects;
+
public static RefreshTutorialsJob INSTANCE = new RefreshTutorialsJob();
private RefreshTutorialsJob() {
@@ -50,52 +50,32 @@
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
- tutorialCategories = JBossCentralActivator.getDefault().getTutorialCategories();
List<Category> categories = ProjectUtil.getProjects(monitor);
- Collection<TutorialCategory> values = tutorialCategories.values();
- for (TutorialCategory category:values) {
- for (Tutorial tutorial:category.getTutorials()) {
- if (JBossCentralActivator.PROJECT_EXAMPLE_TYPE.equals(tutorial.getType())) {
- String reference = tutorial.getReference();
- String[] projectExamples = reference.split("::");
- Assert.isNotNull(projectExamples);
- Assert.isTrue(projectExamples.length == 2);
- String projectExampleCategory = projectExamples[0];
- String projectExampleName = projectExamples[1];
- Project projectTutorial = null;
- for (Category peCategory : categories) {
- if (projectExampleCategory.equals(peCategory.getName())) {
- for (Project project : peCategory.getProjects()) {
- if (projectExampleName.equals(project.getName())
- && canBeImported(project)){
- projectTutorial = project;
- break;
- }
- }
- }
- if (projectTutorial != null) {
- List<ProjectFix> unsatisfiedFixes = new ArrayList<ProjectFix>();
- if (projectTutorial != null) {
- List<ProjectFix> fixes = projectTutorial.getFixes();
- projectTutorial.setUnsatisfiedFixes(unsatisfiedFixes);
- for (ProjectFix fix : fixes) {
- if (!ProjectExamplesActivator.canFix(projectTutorial, fix)) {
- unsatisfiedFixes.add(fix);
- }
- }
- }
-
- break;
- }
+ wizardProjects = ProjectUtil.getProjectsByTags(categories, "wizard");
+ List<Project> tutorials = ProjectUtil.getProjectsByTags(categories,
"central");
+ if (tutorialCategories == null) {
+ tutorialCategories = new HashMap<Category, List<Project>>();
+ } else {
+ tutorialCategories.clear();
+ }
+
+ for (Project project : tutorials) {
+ if (canBeImported(project)){
+ List<ProjectFix> unsatisfiedFixes = new ArrayList<ProjectFix>();
+ List<ProjectFix> fixes = project.getFixes();
+ project.setUnsatisfiedFixes(unsatisfiedFixes);
+ for (ProjectFix fix : fixes) {
+ if (!ProjectExamplesActivator.canFix(project, fix)) {
+ unsatisfiedFixes.add(fix);
}
- if (projectTutorial != null) {
- tutorial.setProjectExamples(projectTutorial);
- } else {
- JBossCentralActivator.logWarning("The " + tutorial.getId() + "
project example not found");
- }
- } else {
- // FIXME
}
+ Category category = project.getCategory();
+ List<Project> projects = tutorialCategories.get(category);
+ if (projects == null) {
+ projects = new ArrayList<Project>();
+ tutorialCategories.put(category, projects);
+ }
+ projects.add(project);
}
}
@@ -115,10 +95,14 @@
this.exception = exception;
}
- public Map<String, TutorialCategory> getTutorialCategories() {
+ public Map<Category,List<Project>> getTutorialCategories() {
return tutorialCategories;
}
+ public List<Project> getWizardProjects() {
+ return wizardProjects;
+ }
+
@Override
public boolean belongsTo(Object family) {
return family == JBossCentralActivator.JBOSS_CENTRAL_FAMILY;
Deleted:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/model/Tutorial.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/model/Tutorial.java 2012-01-18
09:20:13 UTC (rev 37934)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/model/Tutorial.java 2012-01-18
09:24:06 UTC (rev 37935)
@@ -1,172 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2008-2011 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.central.model;
-
-import org.jboss.tools.project.examples.model.Project;
-
-/**
- *
- * @author snjeza
- *
- */
-public class Tutorial implements Comparable<Tutorial> {
- private String id;
- private String name;
- private String type;
- private String reference;
- private int priority;
- private TutorialCategory category;
- private Project projectExamples;
- private String description;
- private String iconPath;
-
- public Tutorial(String id, String name, String type, String reference,
- int priority, TutorialCategory category, String description, String iconPath) {
- this.id = id;
- this.name = name;
- this.type = type;
- this.reference = reference;
- this.priority = priority;
- this.category = category;
- this.description = description;
- this.iconPath = iconPath;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getReference() {
- return reference;
- }
-
- public void setReference(String reference) {
- this.reference = reference;
- }
-
- public int getPriority() {
- return priority;
- }
-
- public void setPriority(int priority) {
- this.priority = priority;
- }
-
- public TutorialCategory getCategory() {
- return category;
- }
-
- public void setCategory(TutorialCategory category) {
- this.category = category;
- }
-
- public Project getProjectExamples() {
- return projectExamples;
- }
-
- public void setProjectExamples(Project projectExamples) {
- this.projectExamples = projectExamples;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getIconPath() {
- return iconPath;
- }
-
- public void setIconPath(String iconPath) {
- this.iconPath = iconPath;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Tutorial other = (Tutorial) obj;
- if (id == null) {
- if (other.id != null)
- return false;
- } else if (!id.equals(other.id))
- return false;
- return true;
- }
-
- @Override
- public int compareTo(Tutorial o) {
- if (o == null) {
- return -1;
- }
- TutorialCategory otherCategory = o.getCategory();
- if (otherCategory == null && this.category == null) {
- return 0;
- }
- if (this.category != null) {
- if (this.category.compareTo(otherCategory) != 0) {
- return this.category.compareTo(otherCategory);
- }
- int other = o.getPriority();
- if (other < this.priority)
- return 1;
- else if (other > this.priority)
- return -1;
- return this.getId().compareTo(o.getId());
- }
- return -1;
- }
-
- @Override
- public String toString() {
- return "Tutorial [id=" + id + ", name=" + name + ",
type=" + type
- + ", reference=" + reference + ", priority=" + priority
- + ", category=" + category + ", projectExamples="
- + projectExamples + ", description=" + description
- + ", iconPath=" + iconPath + "]";
- }
-
-}
Deleted:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/model/TutorialCategory.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/model/TutorialCategory.java 2012-01-18
09:20:13 UTC (rev 37934)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/model/TutorialCategory.java 2012-01-18
09:24:06 UTC (rev 37935)
@@ -1,118 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2008-2011 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.central.model;
-
-import java.util.Set;
-import java.util.TreeSet;
-
-/**
- *
- * @author snjeza
- *
- */
-public class TutorialCategory implements Comparable<TutorialCategory> {
-
- private String id;
- private String name;
- private int priority;
- private String description;
- private Set<Tutorial> tutorials = new TreeSet<Tutorial>();
-
- public TutorialCategory() {
- }
-
- public TutorialCategory(String id, String name, int priority, String description) {
- this.id = id;
- this.name = name;
- this.priority = priority;
- this.description = description;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public int getPriority() {
- return priority;
- }
-
- public void setPriority(int priority) {
- this.priority = priority;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- TutorialCategory other = (TutorialCategory) obj;
- if (id == null) {
- if (other.id != null)
- return false;
- } else if (!id.equals(other.id))
- return false;
- return true;
- }
-
- @Override
- public int compareTo(TutorialCategory o) {
- if (o == null)
- return 1;
- int other = o.getPriority();
- if (other < this.priority)
- return 1;
- else if (other > this.priority)
- return -1;
- return id.compareTo(o.getId());
- }
-
- public Set<Tutorial> getTutorials() {
- return tutorials;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- @Override
- public String toString() {
- return "TutorialCategory [id=" + id + ", name=" + name + ",
priority="
- + priority + ", description=" + description + "]";
- }
-
-}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java 2012-01-18
09:20:13 UTC (rev 37934)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java 2012-01-18
09:24:06 UTC (rev 37935)
@@ -19,7 +19,7 @@
* @author snjeza
*
*/
-public class Category implements ProjectModelElement {
+public class Category implements ProjectModelElement, Comparable<Category> {
private String name;
private List<Project> projects = new ArrayList<Project>();
@@ -99,4 +99,23 @@
public String toString() {
return getName();
}
+
+ @Override
+ public int compareTo(Category o) {
+ if (o == null) {
+ return 1;
+ }
+ //TODO use priorities
+ String otherName = o.getName();
+ if (name == otherName) {
+ return 0;
+ }
+ if (name == null) {
+ return -1;
+ }
+ if (otherName == null) {
+ return 1;
+ }
+ return name.compareTo(otherName);
+ }
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2012-01-18
09:20:13 UTC (rev 37934)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2012-01-18
09:24:06 UTC (rev 37935)
@@ -48,6 +48,7 @@
private IProjectExampleSite site;
private String defaultProfiles =""; //$NON-NLS-1$
private Set<String> tags;
+ private String iconPath;
public Project() {
name=""; //$NON-NLS-1$
@@ -273,11 +274,31 @@
this.tags = tags;
}
- public Set<String> setTags() {
+ public Set<String> getTags() {
if (tags == null) {
tags = new HashSet<String>();
}
return tags;
}
+ public boolean hasTags(String ... tags) {
+ if (!getTags().isEmpty()
+ && tags != null && tags.length > 0) {
+ for (String tag : tags) {
+ if (!getTags().contains(tag)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public void setIconPath(String path) {
+ this.iconPath = path;
+ }
+
+ public String getIconPath() {
+ return iconPath;
+ }
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2012-01-18
09:20:13 UTC (rev 37934)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2012-01-18
09:24:06 UTC (rev 37935)
@@ -23,8 +23,11 @@
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
@@ -221,8 +224,8 @@
invalidSites.clear();
Category other = Category.OTHER;
try {
+ boolean showExperimentalSites =
ProjectExamplesActivator.getDefault().getPreferenceStore().getBoolean(ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES);
for (IProjectExampleSite site : sites) {
- boolean showExperimentalSites =
ProjectExamplesActivator.getDefault().getPreferenceStore().getBoolean(ProjectExamplesActivator.SHOW_EXPERIMENTAL_SITES);
if (!showExperimentalSites && site.isExperimental()) {
continue;
}
@@ -242,8 +245,7 @@
continue;
}
- DocumentBuilderFactory dbf = DocumentBuilderFactory
- .newInstance();
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
NodeList projects = doc.getElementsByTagName("project"); //$NON-NLS-1$
@@ -356,6 +358,12 @@
else if (nodeName.equals("tags")) { //$NON-NLS-1$
parseTags(project, child);
}
+ else if (nodeName.equals("icon")) { //$NON-NLS-1$
+ String path = child.getAttribute("path");
+ if (path != null) {
+ project.setIconPath(path);
+ }
+ }
}
}
}
@@ -368,7 +376,7 @@
return list;
}
- private static void parseTags(Project project, Element tagElement) {
+ private static void parseTags(Project project, Element tagElement) {
String tagsValue = tagElement.getTextContent();
if (tagsValue != null) {
StringTokenizer tokenizer = new StringTokenizer(tagsValue.trim(),
",");//$NON-NLS-1$
@@ -646,4 +654,19 @@
public static HashSet<IProjectExampleSite> getInvalidSites() {
return invalidSites;
}
+
+ public static List<Project> getProjectsByTags(Collection<Category>
categories, String ... tags) {
+ if (categories == null) {
+ return null;
+ }
+ List<Project> selection = new ArrayList<Project>();
+ for (Category c : categories) {
+ for (Project p : c.getProjects()) {
+ if (p.hasTags(tags) && !selection.contains(p)) {
+ selection.add(p);
+ }
+ }
+ }
+ return selection;
+ }
}