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
This commit is contained in:
kohsuke committed 2008-12-31 14:11:59 +00:00
1 parent a9e309caa3
commit e666ecb18b
5 files changed
+147 -1

No files matched your search

@@ -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;
/**
*
* <h2>EXPERIMENTAL</h2>
* <p>
* The intention is to eventually merge this with the {@link ListView}.
* This class is here for experimentation.
*
* <p>
* 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<String> jobNames
= new TreeSet<String>(CaseInsensitiveComparator.INSTANCE);
/**
* Nested views.
*/
private final CopyOnWriteArrayList<View> views = new CopyOnWriteArrayList<View>();
@DataBoundConstructor
public TreeView(String name) {
super(name);
}
/**
* Returns a read-only view of all {@link Job}s in this view.
*
* <p>
* This method returns a separate copy each time to avoid
* concurrent modification issue.
*/
public synchronized List<TopLevelItem> getItems() {
return Hudson.getInstance().getItems();
// List<TopLevelItem> items = new ArrayList<TopLevelItem>(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<View> 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";
}
}
}
+3 -1
View File
@@ -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<View> SORTER = new Comparator<View>() {