Author: snjeza
Date: 2009-02-26 19:29:44 -0500 (Thu, 26 Feb 2009)
New Revision: 13855
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/SiteFilter.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/messages.properties
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/ProjectModelElement.java
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/wizard/NewProjectExamplesWizardPage.java
Log:
JBIDE-3849 Filter project examples per site to know the origins of the example
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 2009-02-27
00:17:13 UTC (rev 13854)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/Messages.java 2009-02-27
00:29:44 UTC (rev 13855)
@@ -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 NewProjectExamplesWizardPage_Site;
public static String Category_Other;
public static String ECFExamplesTransport_Downloading;
public static String ECFExamplesTransport_Internal_Error;
@@ -45,6 +46,10 @@
public static String NewProjectExamplesWizardPage_Projects;
public static String NewProjectExamplesWizardPage_Show_the_Quick_Fix_dialog;
public static String NewProjectExamplesWizardPage_URL;
+ public static String Project_JBoss_Tools_Team_from_jboss_org;
+ public static String Project_Local;
+ public static String Project_Unknown;
+ public static String ProjectExamplesActivator_All;
public static String ProjectExamplesActivator_Waiting;
public static String ProjectUtil_Invalid_URL;
public static String ProjectUtil_Invalid_welcome_element;
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 2009-02-27
00:17:13 UTC (rev 13854)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2009-02-27
00:29:44 UTC (rev 13855)
@@ -35,7 +35,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;
+
// The shared instance
private static ProjectExamplesActivator plugin;
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 2009-02-27
00:17:13 UTC (rev 13854)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/messages.properties 2009-02-27
00:29:44 UTC (rev 13855)
@@ -29,6 +29,11 @@
NewProjectExamplesWizardPage_Projects=Projects:
NewProjectExamplesWizardPage_Show_the_Quick_Fix_dialog=Show the Quick Fix dialog
NewProjectExamplesWizardPage_URL=URL:
+Project_JBoss_Tools_Team_from_jboss_org=JBoss Tools Team from
jboss.org
+Project_Local=Local
+Project_Unknown=Unknown
+ProjectExamplesActivator_All=All
ProjectExamplesActivator_Waiting=Waiting...
ProjectUtil_Invalid_URL=Invalid URL\: {0}
ProjectUtil_Invalid_welcome_element=The welcome element has invalid the url attribute
+NewProjectExamplesWizardPage_Site=Site\:
\ No newline at end of file
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 2009-02-27
00:17:13 UTC (rev 13854)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java 2009-02-27
00:29:44 UTC (rev 13855)
@@ -14,6 +14,7 @@
import java.util.List;
import org.jboss.tools.project.examples.Messages;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
/**
* @author snjeza
@@ -79,4 +80,8 @@
return getName();
}
+ public String getSite() {
+ return ProjectExamplesActivator.ALL_SITES;
+ }
+
}
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 2009-02-27
00:17:13 UTC (rev 13854)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2009-02-27
00:29:44 UTC (rev 13855)
@@ -13,6 +13,9 @@
import java.math.BigDecimal;
import java.util.List;
+import org.jboss.tools.project.examples.Messages;
+import org.jboss.tools.project.examples.ProjectExamplesActivator;
+
/**
* @author snjeza
*
@@ -29,6 +32,7 @@
private boolean welcome;
private String type;
private String welcomeURL;
+ private String site;
public Project() {
name=""; //$NON-NLS-1$
@@ -133,4 +137,21 @@
public void setWelcomeURL(String welcomeURL) {
this.welcomeURL = welcomeURL;
}
+
+ public String getSite() {
+ if (site == null) {
+ if (getUrl().startsWith("http://anonsvn.jboss.org")) { //$NON-NLS-1$
+ site = Messages.Project_JBoss_Tools_Team_from_jboss_org;
+ } else if (getUrl().startsWith("file:")) { //$NON-NLS-1$
+ site = Messages.Project_Local;
+ } else {
+ site = Messages.Project_Unknown;
+ }
+ }
+ return site;
+ }
+
+ public void setSite(String site) {
+ this.site = site;
+ }
}
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectModelElement.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectModelElement.java 2009-02-27
00:17:13 UTC (rev 13854)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectModelElement.java 2009-02-27
00:29:44 UTC (rev 13855)
@@ -19,4 +19,5 @@
public String getName();
public String getDescription();
public String getShortDescription();
+ public String getSite();
}
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 2009-02-27
00:17:13 UTC (rev 13854)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectUtil.java 2009-02-27
00:29:44 UTC (rev 13855)
@@ -150,6 +150,9 @@
if (nodeName.equals("name")) { //$NON-NLS-1$
project.setName(getContent(child));
}
+ if (nodeName.equals("site")) { //$NON-NLS-1$
+ project.setSite(getContent(child));
+ }
if (nodeName.equals("shortDescription")) { //$NON-NLS-1$
project
.setShortDescription(getContent(child));
Modified:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java 2009-02-27
00:17:13 UTC (rev 13854)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java 2009-02-27
00:29:44 UTC (rev 13855)
@@ -11,8 +11,11 @@
package org.jboss.tools.project.examples.wizard;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -23,10 +26,13 @@
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
@@ -58,22 +64,46 @@
}
public void createControl(Composite parent) {
- Composite composite = new Composite(parent,SWT.NULL);
+ Composite composite = new Composite(parent,SWT.NONE);
composite.setLayout(new GridLayout(1,false));
GridData gd = new GridData(GridData.FILL_BOTH);
- gd.widthHint= 225;
composite.setLayoutData(gd);
+ Composite siteComposite = new Composite(composite,SWT.NONE);
+ GridLayout gridLayout = new GridLayout(2,false);
+ gridLayout.marginHeight = 0;
+ gridLayout.marginWidth = 0;
+ siteComposite.setLayout(gridLayout);
+ gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
+ siteComposite.setLayoutData(gd);
+
+ new Label(siteComposite,SWT.NONE).setText(Messages.NewProjectExamplesWizardPage_Site);
+ final Combo siteCombo = new Combo(siteComposite,SWT.READ_ONLY);
+ siteCombo.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
+ List<Category> categories = ProjectUtil.getProjects();
+ Set<String> sites = new TreeSet<String>();
+ sites.add(ProjectExamplesActivator.ALL_SITES);
+ for (Category category:categories) {
+ List<Project> projects = category.getProjects();
+ for (Project project:projects) {
+ sites.add(project.getSite());
+ }
+ }
+ String[] items = sites.toArray(new String[0]);
+ siteCombo.setItems(items);
+ siteCombo.setText(ProjectExamplesActivator.ALL_SITES);
+
new Label(composite,SWT.NONE).setText(Messages.NewProjectExamplesWizardPage_Projects);
- ProjectExamplesPatternFilter filter = new ProjectExamplesPatternFilter();
+ final ProjectExamplesPatternFilter filter = new ProjectExamplesPatternFilter();
+
int styleBits = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
- FilteredTree filteredTree = new FilteredTree(composite, styleBits, filter);
+ final FilteredTree filteredTree = new FilteredTree(composite, styleBits, filter);
filteredTree.setBackground(parent.getDisplay().getSystemColor(
SWT.COLOR_WIDGET_BACKGROUND));
- TreeViewer viewer = filteredTree.getViewer();
+ final TreeViewer viewer = filteredTree.getViewer();
Tree tree = viewer.getTree();
tree.setLayoutData(new GridData(GridData.FILL_BOTH));
tree.setFont(parent.getFont());
@@ -81,8 +111,10 @@
viewer.setLabelProvider(new ProjectLabelProvider());
viewer.setContentProvider(new ProjectContentProvider());
- AdaptableList input = new AdaptableList(ProjectUtil.getProjects());
+ final AdaptableList input = new AdaptableList(categories);
+ final SiteFilter siteFilter = new SiteFilter();
+ viewer.addFilter(siteFilter);
viewer.setInput(input);
Label descriptionLabel = new Label(composite,SWT.NULL);
@@ -152,9 +184,17 @@
gd=new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan=2;
showQuickFixButton.setLayoutData(gd);
- //Label showQuickFixLabel = new Label(internal,SWT.NULL);
- //showQuickFixLabel.setText("Show the Quick Fix dialog:");
+ siteCombo.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ siteFilter.setSite(siteCombo.getText());
+ viewer.refresh();
+ }
+
+ });
+
setPageComplete(false);
setControl(composite);
Added:
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
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/SiteFilter.java 2009-02-27
00:29:44 UTC (rev 13855)
@@ -0,0 +1,52 @@
+package org.jboss.tools.project.examples.wizard;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+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.ProjectModelElement;
+
+public class SiteFilter extends ViewerFilter {
+
+ private String site;
+
+ public SiteFilter() {
+ super();
+ site = ProjectExamplesActivator.ALL_SITES;
+ }
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (! (element instanceof ProjectModelElement) ) {
+ return false;
+ }
+ if (element instanceof Category) {
+ Category category = (Category) element;
+ int size = 0;
+ if (site.equals(ProjectExamplesActivator.ALL_SITES)) {
+ size += category.getProjects().size();
+ } else {
+ List<Project> projects = category.getProjects();
+ for (Project project:projects) {
+ if (site.equals(project.getSite())) {
+ size++;
+ }
+ }
+ }
+ return size > 0;
+ }
+ ProjectModelElement model = (ProjectModelElement) element;
+ if ( site.equals(ProjectExamplesActivator.ALL_SITES) || site.equals(model.getSite()))
{
+ return true;
+ }
+ return false;
+ }
+
+ public void setSite(String site) {
+ this.site = site;
+ }
+
+}