File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\TreeView.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.model;
25
26 import hudson.model.Descriptor.FormException;
27 import hudson.util.CaseInsensitiveComparator;
28 import hudson.Indenter;
29 import hudson.Extension;
30 import hudson.views.ViewsTabBar;
31 import jenkins.model.Jenkins;
32 import org.kohsuke.stapler.DataBoundConstructor;
33 import org.kohsuke.stapler.StaplerRequest;
34 import org.kohsuke.stapler.StaplerResponse;
35
36 import javax.servlet.ServletException;
37 import java.io.IOException;
38 import java.util.Collection;
39 import java.util.Collections;
40 import java.util.List;
41 import java.util.Set;
42 import java.util.TreeSet;
43 import java.util.concurrent.CopyOnWriteArrayList;
44
45 /**
46 *
47 * <h2>EXPERIMENTAL</h2>
48 * <p>
49 * The intention is to eventually merge this with the {@link ListView}.
50 * This class is here for experimentation.
51 *
52 * <p>
53 * Until this class is sufficiently stable, there's no need for l10n.
54 * TODO: use ViewGroupMixIn
55 *
56 * @author Kohsuke Kawaguchi
57 */
58 public class TreeView extends View implements ViewGroup {
59 /**
60 * List of job names. This is what gets serialized.
61 */
62 private final Set<String> jobNames
63 = new TreeSet<String>(CaseInsensitiveComparator.INSTANCE);
64
65 /**
66 * Nested views.
67 */
68 private final CopyOnWriteArrayList<View> views = new CopyOnWriteArrayList<View>();
69
70 @DataBoundConstructor
71 public TreeView(String name) {
72 super(name);
73 }
74
75 /**
76 * Returns {@link Indenter} that has the fixed indentation width.
77 * Used for assisting view rendering.
78 */
79 public Indenter createFixedIndenter(String d) {
80 final int depth = Integer.parseInt(d);
81 return new Indenter() {
82 protected int getNestLevel(Job job) { return depth; }
83 };
84 }
85
86 /**
87 * Returns a read-only view of all {@link Job}s in this view.
88 *
89 * <p>
90 * This method returns a separate copy each time to avoid
91 * concurrent modification issue.
92 */
93 public synchronized List<TopLevelItem> getItems() {
94 return Jenkins.getInstance().getItems();
95 // List<TopLevelItem> items = new ArrayList<TopLevelItem>(jobNames.size());
96 // for (String name : jobNames) {
97 // TopLevelItem item = Hudson.getInstance().getItem(name);
98 // if(item!=null)
99 // items.add(item);
100 // }
101 // return items;
102 }
103
104 public boolean contains(TopLevelItem item) {
105 return true;
106 // return jobNames.contains(item.getName());
107 }
108
109 public TopLevelItem doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
110 ItemGroup<? extends TopLevelItem> ig = getOwnerItemGroup();
111 if (ig instanceof ModifiableItemGroup) {
112 TopLevelItem item = ((ModifiableItemGroup<? extends TopLevelItem>)ig).doCreateItem(req, rsp);
113 if(item!=null) {
114 jobNames.add(item.getName());
115 owner.save();
116 }
117 return item;
118 }
119 return null;
120 }
121
122 @Override
123 public synchronized void onJobRenamed(Item item, String oldName, String newName) {
124 if(jobNames.remove(oldName) && newName!=null)
125 jobNames.add(newName);
126 // forward to children
127 for (View v : views)
128 v.onJobRenamed(item,oldName,newName);
129 }
130
131 protected void submit(StaplerRequest req) throws IOException, ServletException, FormException {
132 }
133
134 public boolean canDelete(View view) {
135 return true;
136 }
137
138 public void deleteView(View view) throws IOException {
139 views.remove(view);
140 }
141
142 public Collection<View> getViews() {
143 return Collections.unmodifiableList(views);
144 }
145
146 public View getView(String name) {
147 for (View v : views)
148 if(v.getViewName().equals(name))
149 return v;
150 return null;
151 }
152
153 public View getPrimaryView() {
154 return null;
155 }
156
157 public void onViewRenamed(View view, String oldName, String newName) {
158 // noop
159 }
160
161 public void doCreateView( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException {
162 checkPermission(View.CREATE);
163 views.add(View.create(req,rsp,this));
164 save();
165 }
166
167 // this feature is not public yet
168 @Extension
169 public static ViewDescriptor register() {
170 if(Boolean.getBoolean("hudson.TreeView"))
171 return new DescriptorImpl();
172 else
173 return null;
174 }
175
176 public static final class DescriptorImpl extends ViewDescriptor {
177 public String getDisplayName() {
178 return "Tree View";
179 }
180 }
181
182 public ViewsTabBar getViewsTabBar() {
183 return Jenkins.getInstance().getViewsTabBar();
184 }
185
186 public ItemGroup<? extends TopLevelItem> getItemGroup() {
187 return getOwnerItemGroup();
188 }
189
190 public List<Action> getViewActions() {
191 return owner.getViewActions();
192 }
193
194 }
195