1 11 package org.eclipse.pde.internal.ui.commands; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 16 import org.eclipse.pde.internal.ui.PDEUIMessages; 17 18 public abstract class CommandCopyFilter { 19 20 private static final ArrayList fFilters = new ArrayList (); 21 22 23 private CommandCopyFilter() { 24 fFilters.add(this); 25 } 26 27 public final String filter(String serializedCommand, boolean surroundWithMarkup, String markupLabel) { 28 if (surroundWithMarkup) 29 return markup(escape(serializedCommand), markupLabel); 30 return escape(serializedCommand); 31 } 32 33 protected abstract String escape(String serializedCommand); 34 protected abstract String markup(String escapedSerializedCommand, String markupLabel); 35 public abstract String getLabelText(); 36 public abstract String 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 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 getLabelText() { 59 return PDEUIMessages.CommandCopyFilter_noFilter; 60 } 61 62 public String getToolTipText() { 63 return PDEUIMessages.CommandCopyFilter_noFilterDesc; 64 } 65 66 protected String escape(String serializedCommand) { 67 return serializedCommand; 68 } 69 70 protected String markup(String escapedSerializedCommand, String markupLabel) { 71 return escapedSerializedCommand; 72 } 73 74 }; 75 76 public static final CommandCopyFilter HELP = new CommandCopyFilter() { 77 public String getLabelText() { 78 return PDEUIMessages.CommandCopyFilter_help; 79 } 80 81 public String getToolTipText() { 82 return PDEUIMessages.CommandCopyFilter_helpDesc; 83 } 84 85 protected String escape(String serializedCommand) { 86 return serializedCommand; 88 } 89 protected String markup(String escapedSerializedCommand, String markupLabel) { 90 StringBuffer sb = new StringBuffer (); 91 92 sb.append("<a HREF='javascript:executeCommand(\""); sb.append(escapedSerializedCommand); 94 sb.append("\")'>"); if (markupLabel != null) sb.append(markupLabel); 96 sb.append("</a>"); 98 return sb.toString(); 99 } 100 101 }; 102 103 public static final CommandCopyFilter CHEATSHEET = new CommandCopyFilter() { 104 public String getLabelText() { 105 return PDEUIMessages.CommandCopyFilter_cheatsheet; 106 } 107 108 public String getToolTipText() { 109 return PDEUIMessages.CommandCopyFilter_cheatsheetDesc; 110 } 111 112 protected String escape(String serializedCommand) { 113 return serializedCommand; 115 } 116 protected String markup(String escapedSerializedCommand, String markupLabel) { 117 StringBuffer sb = new StringBuffer (); 118 119 sb.append("<command serialization=\""); sb.append(escapedSerializedCommand); 121 sb.append("\"/>"); 123 return sb.toString(); 124 } 125 126 }; 127 128 public static final CommandCopyFilter INTRO = new CommandCopyFilter() { 129 public String getLabelText() { 130 return PDEUIMessages.CommandCopyFilter_intro; 131 } 132 133 public String getToolTipText() { 134 return PDEUIMessages.CommandCopyFilter_introDesc; 135 } 136 137 protected String escape(String serializedCommand) { 138 return serializedCommand; 140 } 141 protected String markup(String escapedSerializedCommand, String markupLabel) { 142 StringBuffer sb = new StringBuffer (); 143 144 sb.append("<link\n"); if (markupLabel != null) { 146 sb.append("label=\""); sb.append(markupLabel); 148 sb.append("\"\n"); } 150 151 sb.append("id=\"TODO\"\n"); 153 sb.append("url=\""); sb.append(escapedSerializedCommand); 155 sb.append("\"\n"); 157 sb.append("<text>TODO</text>\n"); 159 sb.append("</link>"); 161 return sb.toString(); 162 } 163 164 }; 165 166 } 167 | Popular Tags |