From e666ecb18ba7066b5aefea9f0fe4f24afb626d55 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Wed, 31 Dec 2008 14:11:59 +0000 Subject: [PATCH] started working on experimental tree view. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14025 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/TreeView.java | 134 ++++++++++++++++++ core/src/main/java/hudson/model/View.java | 4 +- .../hudson/model/TreeView/newView.jelly | 1 + .../hudson/model/TreeView/newViewDetail.jelly | 3 + .../hudson/model/TreeView/sidepanel2.jelly | 6 + 5 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/hudson/model/TreeView.java create mode 100644 core/src/main/resources/hudson/model/TreeView/newView.jelly create mode 100644 core/src/main/resources/hudson/model/TreeView/newViewDetail.jelly create mode 100644 core/src/main/resources/hudson/model/TreeView/sidepanel2.jelly diff --git a/core/src/main/java/hudson/model/TreeView.java b/core/src/main/java/hudson/model/TreeView.java new file mode 100644 index 0000000000..16f256fcfc --- /dev/null +++ b/core/src/main/java/hudson/model/TreeView.java @@ -0,0 +1,134 @@ +package hudson.model; + +import hudson.model.Descriptor.FormException; +import hudson.util.CaseInsensitiveComparator; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerResponse; + +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * + *

EXPERIMENTAL

+ *

+ * The intention is to eventually merge this with the {@link ListView}. + * This class is here for experimentation. + * + *

+ * Until this class is sufficiently stable, there's no need for l10n. + * + * @author Kohsuke Kawaguchi + */ +public class TreeView extends View implements ViewGroup { + /** + * List of job names. This is what gets serialized. + */ + private final Set jobNames + = new TreeSet(CaseInsensitiveComparator.INSTANCE); + + /** + * Nested views. + */ + private final CopyOnWriteArrayList views = new CopyOnWriteArrayList(); + + @DataBoundConstructor + public TreeView(String name) { + super(name); + } + + /** + * Returns a read-only view of all {@link Job}s in this view. + * + *

+ * This method returns a separate copy each time to avoid + * concurrent modification issue. + */ + public synchronized List getItems() { + return Hudson.getInstance().getItems(); +// List items = new ArrayList(jobNames.size()); +// for (String name : jobNames) { +// TopLevelItem item = Hudson.getInstance().getItem(name); +// if(item!=null) +// items.add(item); +// } +// return items; + } + + public boolean contains(TopLevelItem item) { + return true; +// return jobNames.contains(item.getName()); + } + + public Item doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { + Item item = Hudson.getInstance().doCreateItem(req, rsp); + if(item!=null) { + jobNames.add(item.getName()); + owner.save(); + } + return item; + } + + @Override + public synchronized void onJobRenamed(Item item, String oldName, String newName) { + if(jobNames.remove(oldName) && newName!=null) + jobNames.add(newName); + // forward to children + for (View v : views) + v.onJobRenamed(item,oldName,newName); + } + + protected void submit(StaplerRequest req) throws IOException, ServletException, FormException { + } + + public void deleteView(View view) throws IOException { + views.remove(view); + } + + public Collection getViews() { + return Collections.unmodifiableList(views); + } + + public View getView(String name) { + for (View v : views) + if(v.getViewName().equals(name)) + return v; + return null; + } + + public void onViewRenamed(View view, String oldName, String newName) { + // noop + } + + public void save() throws IOException { + owner.save(); + } + + public ViewDescriptor getDescriptor() { + return DESCRIPTOR; + } + + public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl(); + + static { + LIST.add(DESCRIPTOR); + } + + public static final class DescriptorImpl extends ViewDescriptor { + private DescriptorImpl() { + super(TreeView.class); + } + + public String getDisplayName() { + return "Tree View"; + } + } +} diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java index d3c3256851..a3ecc477e4 100644 --- a/core/src/main/java/hudson/model/View.java +++ b/core/src/main/java/hudson/model/View.java @@ -408,7 +408,7 @@ public abstract class View extends AbstractModelObject implements AccessControll /** * Accepts submission from the configuration page. * - * Subtypes should override the {@link #submit()} method. + * Subtypes should override the {@link #submit(StaplerRequest)} method. */ public final synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException { try { @@ -504,6 +504,8 @@ public abstract class View extends AbstractModelObject implements AccessControll LIST.load(ListView.class); LIST.load(AllView.class); LIST.load(MyView.class); + if(Boolean.getBoolean("hudson.TreeView")) + LIST.load(TreeView.class); } public static final Comparator SORTER = new Comparator() { diff --git a/core/src/main/resources/hudson/model/TreeView/newView.jelly b/core/src/main/resources/hudson/model/TreeView/newView.jelly new file mode 100644 index 0000000000..1a65f90297 --- /dev/null +++ b/core/src/main/resources/hudson/model/TreeView/newView.jelly @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/core/src/main/resources/hudson/model/TreeView/newViewDetail.jelly b/core/src/main/resources/hudson/model/TreeView/newViewDetail.jelly new file mode 100644 index 0000000000..019b48b57b --- /dev/null +++ b/core/src/main/resources/hudson/model/TreeView/newViewDetail.jelly @@ -0,0 +1,3 @@ +

+ Experimental: show hierarchical views +
\ No newline at end of file diff --git a/core/src/main/resources/hudson/model/TreeView/sidepanel2.jelly b/core/src/main/resources/hudson/model/TreeView/sidepanel2.jelly new file mode 100644 index 0000000000..f1da931c48 --- /dev/null +++ b/core/src/main/resources/hudson/model/TreeView/sidepanel2.jelly @@ -0,0 +1,6 @@ + + + + \ No newline at end of file