View Javadoc

1   /*
2    * Copyright (c) 2003, Andreas Pataki 
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are
7    * met:
8    *
9    * Redistributions of source code must retain the above copyright notice,
10   * this list of conditions and the following disclaimer.
11   * 
12   * Redistributions in binary form must reproduce the above copyright notice,
13   * this list of conditions and the following disclaimer in the documentation
14   * and/or other materials provided with the distribution.
15   * 
16   * Neither the name of the author nor the names of its contributors
17   * may be used to endorse or promote products derived from this software
18   * without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS
21   * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22   * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   */
32  
33  package net.sf.tm.plugin;
34  
35  import net.sf.tm.WebContext;
36  import net.sf.tm.WebContextStatus;
37  import net.sf.tm.tomcat.TomcatServer;
38  
39  import org.eclipse.jface.viewers.LabelProvider;
40  import org.eclipse.swt.graphics.Image;
41  
42  /***
43   * Label provider for the Tomcat Manager tree view.
44   * 
45   * @author Andreas Pataki
46   * @version $Id: WebContextLabelProvider.java,v 1.6 2004/02/10 20:06:15 apataki Exp $
47   */
48  public class WebContextLabelProvider extends LabelProvider {
49  
50      /***
51       * Image for a Tomcat server
52       */
53      private Image serverImage;
54      /***
55       * Image for a started context
56       */
57      private Image startedContextImage;
58      /***
59       * Image for a stoped Context
60       */
61      private Image stopedContextImage;
62      /***
63       * Image for a pending Context
64       */
65      private Image pendingContextImage;
66  
67      /***
68       * Default Constructor
69       */
70      public WebContextLabelProvider() {
71          serverImage =
72              ContextManagerPlugin
73                  .getDefault()
74                  .getImageDescriptor("icons/server.gif")
75                  .createImage();
76  
77          startedContextImage =
78              ContextManagerPlugin
79                  .getDefault()
80                  .getImageDescriptor("icons/context_on.gif")
81                  .createImage();
82  
83          stopedContextImage =
84              ContextManagerPlugin
85                  .getDefault()
86                  .getImageDescriptor("icons/context_off.gif")
87                  .createImage();
88  
89          pendingContextImage =
90              ContextManagerPlugin
91                  .getDefault()
92                  .getImageDescriptor("icons/context_pending.gif")
93                  .createImage();
94  
95      }
96  
97      /***
98       * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
99       */
100     public String getText(Object obj) {
101         String text = null;
102         if (obj instanceof TreeNode) {
103             TreeNode node = (TreeNode) obj;
104 
105             if (node.getContent() instanceof TomcatServer) {
106 
107                 TomcatServer server = (TomcatServer) node.getContent();
108                 text = server.getName();
109 
110             } else if (node.getContent() instanceof WebContext) {
111 
112                 text = ((WebContext) node.getContent()).getPath();
113 
114             } else {
115 
116                 text = ((TreeNode) obj).getContent().toString();
117             }
118 
119         } else {
120             text = obj.toString();
121         }
122         return text;
123     }
124 
125     /***
126      * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
127      */
128     public Image getImage(Object obj) {
129         Image image = null;
130         if (obj instanceof TreeNode && ((TreeNode) obj).getParent() == null) {
131             image = serverImage;
132         } else {
133             WebContext context = (WebContext) ((TreeNode) obj).getContent();
134         
135             if (context.getStatus().equals(WebContextStatus.RUNNING)) {
136                 image = startedContextImage;
137             } else if (context.getStatus().equals(WebContextStatus.STOPPED)) {
138                 image = stopedContextImage;
139             } else if (context.getStatus().equals(WebContextStatus.PENDING)) {
140                 image = stopedContextImage;
141                 image = pendingContextImage;
142             } else {
143                 image = startedContextImage;
144             }
145 
146         }
147 
148         return image;
149     }
150 
151 }