KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > commands > CommandCopyFilter


1 /*******************************************************************************
2  * Copyright (c) 2006 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.pde.internal.ui.commands;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.pde.internal.ui.PDEUIMessages;
17
18 public abstract class CommandCopyFilter {
19
20     private static final ArrayList JavaDoc fFilters = new ArrayList JavaDoc();
21     
22     
23     private CommandCopyFilter() {
24         fFilters.add(this);
25     }
26     
27     public final String JavaDoc filter(String JavaDoc serializedCommand, boolean surroundWithMarkup, String JavaDoc markupLabel) {
28         if (surroundWithMarkup)
29             return markup(escape(serializedCommand), markupLabel);
30         return escape(serializedCommand);
31     }
32     
33     protected abstract String JavaDoc escape(String JavaDoc serializedCommand);
34     protected abstract String JavaDoc markup(String JavaDoc escapedSerializedCommand, String JavaDoc markupLabel);
35     public abstract String JavaDoc getLabelText();
36     public abstract String JavaDoc getToolTipText();
37     
38     public static CommandCopyFilter[] getFilters() {
39         return (CommandCopyFilter[]) fFilters.toArray(new CommandCopyFilter[fFilters.size()]);
40     }
41     
42     public static CommandCopyFilter getFilter(int index) {
43         return (CommandCopyFilter)fFilters.get(index);
44     }
45     
46     public static int indexOf(CommandCopyFilter filter) {
47         
48         int index = 0;
49         for (Iterator JavaDoc i = fFilters.iterator(); i.hasNext(); ) {
50             CommandCopyFilter f = (CommandCopyFilter)i.next();
51             if (f == filter) return index;
52             index++;
53         }
54         return -1;
55     }
56     
57     public static final CommandCopyFilter NONE = new CommandCopyFilter() {
58         public String JavaDoc getLabelText() {
59             return PDEUIMessages.CommandCopyFilter_noFilter;
60         }
61         
62         public String JavaDoc getToolTipText() {
63             return PDEUIMessages.CommandCopyFilter_noFilterDesc;
64         }
65         
66         protected String JavaDoc escape(String JavaDoc serializedCommand) {
67             return serializedCommand;
68         }
69         
70         protected String JavaDoc markup(String JavaDoc escapedSerializedCommand, String JavaDoc markupLabel) {
71             return escapedSerializedCommand;
72         }
73
74     };
75     
76     public static final CommandCopyFilter HELP = new CommandCopyFilter() {
77         public String JavaDoc getLabelText() {
78             return PDEUIMessages.CommandCopyFilter_help;
79         }
80         
81         public String JavaDoc getToolTipText() {
82             return PDEUIMessages.CommandCopyFilter_helpDesc;
83         }
84         
85         protected String JavaDoc escape(String JavaDoc serializedCommand) {
86             // TODO: escape for Help
87
return serializedCommand;
88         }
89         protected String JavaDoc markup(String JavaDoc escapedSerializedCommand, String JavaDoc markupLabel) {
90             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
91             
92             sb.append("<a HREF='javascript:executeCommand(\""); //$NON-NLS-1$
93
sb.append(escapedSerializedCommand);
94             sb.append("\")'>"); //$NON-NLS-1$
95
if (markupLabel != null) sb.append(markupLabel);
96             sb.append("</a>"); //$NON-NLS-1$
97

98             return sb.toString();
99         }
100         
101     };
102     
103     public static final CommandCopyFilter CHEATSHEET = new CommandCopyFilter() {
104         public String JavaDoc getLabelText() {
105             return PDEUIMessages.CommandCopyFilter_cheatsheet;
106         }
107         
108         public String JavaDoc getToolTipText() {
109             return PDEUIMessages.CommandCopyFilter_cheatsheetDesc;
110         }
111         
112         protected String JavaDoc escape(String JavaDoc serializedCommand) {
113             // TODO: escape for Cheatsheets
114
return serializedCommand;
115         }
116         protected String JavaDoc markup(String JavaDoc escapedSerializedCommand, String JavaDoc markupLabel) {
117             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
118             
119             sb.append("<command serialization=\""); //$NON-NLS-1$
120
sb.append(escapedSerializedCommand);
121             sb.append("\"/>"); //$NON-NLS-1$
122

123             return sb.toString();
124         }
125         
126     };
127     
128     public static final CommandCopyFilter INTRO = new CommandCopyFilter() {
129         public String JavaDoc getLabelText() {
130             return PDEUIMessages.CommandCopyFilter_intro;
131         }
132         
133         public String JavaDoc getToolTipText() {
134             return PDEUIMessages.CommandCopyFilter_introDesc;
135         }
136         
137         protected String JavaDoc escape(String JavaDoc serializedCommand) {
138             // TODO: escape for Intro
139
return serializedCommand;
140         }
141         protected String JavaDoc markup(String JavaDoc escapedSerializedCommand, String JavaDoc markupLabel) {
142             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
143             
144             sb.append("<link\n"); //$NON-NLS-1$
145
if (markupLabel != null) {
146                 sb.append("label=\""); //$NON-NLS-1$
147
sb.append(markupLabel);
148                 sb.append("\"\n"); //$NON-NLS-1$
149
}
150             
151             sb.append("id=\"TODO\"\n"); //$NON-NLS-1$
152

153             sb.append("url=\""); //$NON-NLS-1$
154
sb.append(escapedSerializedCommand);
155             sb.append("\"\n"); //$NON-NLS-1$
156

157             sb.append("<text>TODO</text>\n"); //$NON-NLS-1$
158

159             sb.append("</link>"); //$NON-NLS-1$
160

161             return sb.toString();
162         }
163         
164     };
165     
166 }
167
Popular Tags