KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > webapp > data > ToolbarData


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.webapp.data;
12
13 import java.util.*;
14
15 import javax.servlet.*;
16 import javax.servlet.http.*;
17
18 /**
19  * Control for a toolbar.
20  */

21 public class ToolbarData extends RequestData {
22
23     ToolbarButton[] buttons;
24
25     public ToolbarData(ServletContext context, HttpServletRequest request,
26             HttpServletResponse response) {
27         super(context, request, response);
28         loadButtons();
29     }
30
31     /*
32      * Returns whether or not this toolbar has a menu button (has an arrow with drop
33      * down menu).
34      */

35     public boolean hasMenu() {
36         for (int i=0;i<buttons.length;++i) {
37             if ("menu".equals(buttons[i].getAction())) { //$NON-NLS-1$
38
return true;
39             }
40         }
41         return false;
42     }
43     
44     private void loadButtons() {
45         String JavaDoc[] names = request.getParameterValues("name"); //$NON-NLS-1$
46
String JavaDoc[] tooltips = request.getParameterValues("tooltip"); //$NON-NLS-1$
47
String JavaDoc[] images = request.getParameterValues("image"); //$NON-NLS-1$
48
String JavaDoc[] actions = request.getParameterValues("action"); //$NON-NLS-1$
49
String JavaDoc[] params = request.getParameterValues("param"); //$NON-NLS-1$
50
String JavaDoc[] states = request.getParameterValues("state"); //$NON-NLS-1$
51

52         if (names == null || tooltips == null || images == null
53                 || actions == null || params == null || states == null
54                 || names.length != tooltips.length
55                 || names.length != images.length
56                 || names.length != actions.length
57                 || names.length != params.length
58                 || names.length != states.length) {
59             buttons = new ToolbarButton[0];
60             return;
61         }
62
63         List buttonList = new ArrayList();
64         for (int i = 0; i < names.length; i++) {
65             if ("".equals(names[i])) //$NON-NLS-1$
66
buttonList.add(new ToolbarButton());
67             else
68                 buttonList.add(new ToolbarButton(names[i], ServletResources
69                         .getString(tooltips[i], request), preferences
70                         .getImagesDirectory()
71                         + "/" + images[i], //$NON-NLS-1$
72
actions[i], params[i], states[i]));
73         }
74         // add implicit maximize/restore button on all toolbars
75
if (isIE() || isMozilla()
76                 && "1.2.1".compareTo(getMozillaVersion()) <= 0 //$NON-NLS-1$
77
|| (isSafari() && "120".compareTo(getSafariVersion()) <= 0)) { //$NON-NLS-1$
78
buttonList.add(new ToolbarButton("maximize_restore", //$NON-NLS-1$
79
getMaximizeTooltip(), preferences.getImagesDirectory()
80                             + "/" + "maximize.gif", //$NON-NLS-1$ //$NON-NLS-2$
81
"restore_maximize", null, "off")); //$NON-NLS-1$ //$NON-NLS-2$
82
}
83         buttons = (ToolbarButton[]) buttonList
84                 .toArray(new ToolbarButton[buttonList.size()]);
85     }
86
87     public ToolbarButton[] getButtons() {
88         return buttons;
89     }
90
91     public String JavaDoc getName() {
92         if (request.getParameter("view") == null) //$NON-NLS-1$
93
return ""; //$NON-NLS-1$
94
return request.getParameter("view"); //$NON-NLS-1$
95
}
96
97     public String JavaDoc getTitle() {
98         if (request.getParameter("view") == null) //$NON-NLS-1$
99
return ""; //$NON-NLS-1$
100
return ServletResources.getString(request.getParameter("view"), //$NON-NLS-1$
101
request);
102     }
103
104     public String JavaDoc getScript() {
105         return request.getParameter("script"); //$NON-NLS-1$
106
}
107     public String JavaDoc getMaximizeImage() {
108         return preferences.getImagesDirectory() + "/e_maximize.gif"; //$NON-NLS-1$
109
}
110     public String JavaDoc getRestoreImage() {
111         return preferences.getImagesDirectory() + "/e_restore.gif"; //$NON-NLS-1$
112
}
113     public String JavaDoc getMaximizeTooltip() {
114         return ServletResources.getString("maximize", request); //$NON-NLS-1$
115
}
116     public String JavaDoc getRestoreTooltip() {
117         return ServletResources.getString("restore", request); //$NON-NLS-1$
118
}
119 }
120
Popular Tags