Author: snjeza
Date: 2008-11-18 17:15:49 -0500 (Tue, 18 Nov 2008)
New Revision: 11870
Added:
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/wizard/ProjectExamplesPatternFilter.java
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/Project.java
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java
Log:
JBIDE-2998 Add filter capability to project examples
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 2008-11-18
19:19:03 UTC (rev 11869)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Category.java 2008-11-18
22:15:49 UTC (rev 11870)
@@ -19,7 +19,7 @@
* @author snjeza
*
*/
-public class Category {
+public class Category implements ProjectModelElement {
private String name;
private List<Project> projects = new ArrayList<Project>();
@@ -71,4 +71,8 @@
return true;
}
+ public String getDescription() {
+ return getName();
+ }
+
}
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 2008-11-18
19:19:03 UTC (rev 11869)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/Project.java 2008-11-18
22:15:49 UTC (rev 11870)
@@ -13,13 +13,11 @@
import java.math.BigDecimal;
import java.util.List;
-import org.jboss.tools.project.examples.Messages;
-
/**
* @author snjeza
*
*/
-public class Project {
+public class Project implements ProjectModelElement {
private String name;
private String shortDescription;
Added:
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
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/model/ProjectModelElement.java 2008-11-18
22:15:49 UTC (rev 11870)
@@ -0,0 +1,21 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat 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, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.project.examples.model;
+
+/**
+ * @author snjeza
+ *
+ */
+public interface ProjectModelElement {
+
+ public String getName();
+ public String getDescription();
+}
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 2008-11-18
19:19:03 UTC (rev 11869)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesWizardPage.java 2008-11-18
22:15:49 UTC (rev 11870)
@@ -31,6 +31,9 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.dialogs.FilteredTree;
+import org.eclipse.ui.internal.dialogs.WizardPatternFilter;
+import org.eclipse.ui.model.AdaptableList;
import org.jboss.tools.project.examples.Messages;
import org.jboss.tools.project.examples.ProjectExamplesActivator;
import org.jboss.tools.project.examples.model.Category;
@@ -60,18 +63,28 @@
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint= 225;
+
composite.setLayoutData(gd);
new Label(composite,SWT.NONE).setText(Messages.NewProjectExamplesWizardPage_Projects);
- TreeViewer viewer = new TreeViewer(composite,SWT.MULTI);
+
+ ProjectExamplesPatternFilter filter = new ProjectExamplesPatternFilter();
+ int styleBits = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
+ FilteredTree filteredTree = new FilteredTree(composite, styleBits, filter);
+ filteredTree.setBackground(parent.getDisplay().getSystemColor(
+ SWT.COLOR_WIDGET_BACKGROUND));
+ TreeViewer viewer = filteredTree.getViewer();
Tree tree = viewer.getTree();
tree.setLayoutData(new GridData(GridData.FILL_BOTH));
tree.setFont(parent.getFont());
viewer.setLabelProvider(new ProjectLabelProvider());
viewer.setContentProvider(new ProjectContentProvider());
- viewer.setInput(ProjectUtil.getProjects());
+ AdaptableList input = new AdaptableList(ProjectUtil.getProjects());
+
+ viewer.setInput(input);
+
Label descriptionLabel = new Label(composite,SWT.NULL);
descriptionLabel.setText(Messages.NewProjectExamplesWizardPage_Description);
final Text text = new Text(composite,SWT.BORDER | SWT.MULTI | SWT.WRAP |
SWT.READ_ONLY);
@@ -171,9 +184,11 @@
private class ProjectContentProvider implements ITreeContentProvider {
public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof List) {
- List children = (List) parentElement;
- return children.toArray();
+ if (parentElement instanceof AdaptableList) {
+ Object[] childCollections = ((AdaptableList)parentElement).getChildren();
+ //List children = (List) parentElement;
+ //return children.toArray();
+ return childCollections;
}
if (parentElement instanceof Category) {
Category category = (Category) parentElement;
Added:
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/ProjectExamplesPatternFilter.java
===================================================================
---
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/ProjectExamplesPatternFilter.java
(rev 0)
+++
trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/ProjectExamplesPatternFilter.java 2008-11-18
22:15:49 UTC (rev 11870)
@@ -0,0 +1,47 @@
+/*************************************************************************************
+ * Copyright (c) 2008 JBoss, a division of Red Hat 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, a division of Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.project.examples.wizard;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.dialogs.PatternFilter;
+import org.jboss.tools.project.examples.model.ProjectModelElement;
+
+/**
+ * @author snjeza
+ *
+ */
+public class ProjectExamplesPatternFilter extends PatternFilter {
+
+ public ProjectExamplesPatternFilter() {
+ super();
+ }
+
+ public boolean isElementSelectable(Object element) {
+ return element instanceof ProjectModelElement;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.ui.internal.dialogs.PatternFilter#isElementMatch(org.eclipse.jface.viewers.Viewer,
java.lang.Object)
+ */
+ protected boolean isLeafMatch(Viewer viewer, Object element) {
+ if (! (element instanceof ProjectModelElement) ) {
+ return false;
+ }
+ ProjectModelElement model = (ProjectModelElement) element;
+
+ if (wordMatches(model.getName()) || wordMatches(model.getDescription())) {
+ return true;
+ }
+ return false;
+ }
+
+}