View Javadoc

1   /*
2    * Copyright 2007-2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.gwe.utils.web;
18  
19  
20  /**
21   * @author Marco Ruiz
22   * @since Dec 21, 2008
23   */
24  public enum WebIcon {
25  
26  	// Status
27  	STATUS_OK(   "ok", "icon_success_sml.gif"),
28  	STATUS_WARN( "warn", "icon_warning_sml.gif"),
29  	STATUS_INFO( "info", "icon_info_sml.gif"),
30  	STATUS_HELP( "help", "icon_help_sml.gif"),
31  	STATUS_ERROR("error", "icon_error_sml.gif"),
32  	
33  	// Operations 
34  	OPER_PREVIEW("preview", "report_magnify.png"),
35  	OPER_QUEUE(  "queue", "report_go.png"),
36  
37  	OPER_UP(     "up", "arrow_up.png"),
38  	OPER_DOWN(   "down", "arrow_down.png"),
39  	
40  	OPER_PAUSE(  "pause", "pause.gif"),
41  	OPER_RESUME( "resume", "resume_co.gif"),
42  	OPER_DELETE( "delete", "trash.gif"),
43  	
44  	// Entities
45  	ENT_GRID("grid", ""),
46  	ENT_CLUSTER("cluster", "server.png"),
47  	ENT_ORDER("order", "report.png"),
48  	ENT_JOB("job", "page.png"),
49  	ENT_EXEC("execution", ""),
50  	ENT_PERM("permutation", ""),
51  	ENT_STMT("statement", "");
52  	
53  	public static WebIcon getImageById(String id) {
54  		if (id != null) {
55  			id = id.toLowerCase();
56  			for (WebIcon icon : WebIcon.values())
57  		        if (icon.toString().equals(id)) 
58  		        	return icon;
59  		}
60  		
61  		return null;
62  	}
63  	
64  	public static WebIcon getImageFor(Object value) {
65  		if (value == null) return STATUS_ERROR;
66  		if (value instanceof Boolean)
67  			return ((Boolean)value) ? STATUS_OK : STATUS_ERROR;
68  		return STATUS_OK;
69  	}
70  	
71  	private String id;
72  	private String fileName;
73  	
74  	WebIcon(String id, String fileName) {
75  		this.id = id;
76  		this.fileName = "img/" + fileName; 
77  	}
78  	
79  	public String toString() {
80  		return fileName;
81  	}
82  }
83