1 11 12 package org.eclipse.ui.internal.cheatsheets.composite.views; 13 14 import org.eclipse.jface.resource.JFaceResources; 15 import org.eclipse.osgi.util.NLS; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.layout.GridData; 18 import org.eclipse.swt.layout.GridLayout; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Control; 21 import org.eclipse.ui.forms.IFormColors; 22 import org.eclipse.ui.forms.ManagedForm; 23 import org.eclipse.ui.forms.events.IHyperlinkListener; 24 import org.eclipse.ui.forms.widgets.FormText; 25 import org.eclipse.ui.forms.widgets.FormToolkit; 26 import org.eclipse.ui.forms.widgets.ScrolledForm; 27 import org.eclipse.ui.forms.widgets.TableWrapData; 28 import org.eclipse.ui.forms.widgets.TableWrapLayout; 29 import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin; 30 import org.eclipse.ui.internal.cheatsheets.ICheatSheetResource; 31 import org.eclipse.ui.internal.cheatsheets.Messages; 32 import org.eclipse.ui.internal.cheatsheets.composite.model.AbstractTask; 33 import org.eclipse.ui.internal.cheatsheets.composite.model.SuccesorTaskFinder; 34 import org.eclipse.ui.internal.cheatsheets.composite.model.TaskStateUtilities; 35 import org.eclipse.ui.internal.cheatsheets.composite.parser.ICompositeCheatsheetTags; 36 import org.eclipse.ui.internal.cheatsheets.composite.parser.MarkupParser; 37 import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask; 38 import org.eclipse.ui.internal.provisional.cheatsheets.IEditableTask; 39 import org.eclipse.ui.internal.provisional.cheatsheets.ITaskGroup; 40 41 52 53 public class DescriptionPanel { 54 55 public static final String REVIEW_IMAGE = "review"; private static final String GOTO_IMAGE = "goto"; private static final String SKIP_IMAGE = "skip"; private static final String START_IMAGE = "start"; private static final String WARNING_IMAGE = "warning"; private static final String INFORMATION_IMAGE = "info"; private Composite panel; 62 private Composite control; 63 private FormText upperText; 64 private FormText lowerText; 65 private ScrolledForm form; 66 protected DescriptionPanel() {} 67 68 public DescriptionPanel(ManagedForm mform, Composite parent) { 69 70 FormToolkit toolkit = mform.getToolkit(); 71 control = new Composite(parent, SWT.NULL); 72 final GridLayout controlLayout = new GridLayout(); 73 controlLayout.marginHeight = 0; 74 controlLayout.marginWidth = 0; 75 control.setLayout(controlLayout); 76 form = toolkit.createScrolledForm(control); 77 panel = form.getBody(); 78 form.setLayoutData(new GridData(GridData.FILL_BOTH)); 79 toolkit.adapt(panel); 80 81 TableWrapLayout layout = new TableWrapLayout(); 82 panel.setLayout(layout); 83 84 upperText = mform.getToolkit().createFormText(panel, false); 85 mform.getToolkit().adapt(upperText, false, false); 86 87 Composite separator = toolkit.createCompositeSeparator(panel); 88 89 TableWrapData data = new TableWrapData(); 90 data.align = TableWrapData.FILL; 91 data.grabHorizontal = true; 92 data.maxHeight = 1; 93 separator.setLayoutData(data); 94 95 lowerText = mform.getToolkit().createFormText(panel, false); 96 mform.getToolkit().adapt(lowerText, false, false); 97 98 upperText.marginWidth = 5; 99 upperText.marginHeight = 5; 100 upperText.setFont("header", JFaceResources.getHeaderFont()); upperText.setColor("title", toolkit.getColors().getColor(IFormColors.TITLE)); lowerText.marginWidth = 5; 103 lowerText.marginHeight = 5; 104 lowerText.setImage(START_IMAGE, CheatSheetPlugin.getPlugin().getImage(ICheatSheetResource.COMPOSITE_TASK_START)); 105 lowerText.setImage(SKIP_IMAGE, CheatSheetPlugin.getPlugin().getImage(ICheatSheetResource.COMPOSITE_TASK_SKIP)); 106 lowerText.setImage(GOTO_IMAGE, CheatSheetPlugin.getPlugin().getImage(ICheatSheetResource.COMPOSITE_GOTO_TASK)); 107 lowerText.setImage(REVIEW_IMAGE, CheatSheetPlugin.getPlugin().getImage(ICheatSheetResource.COMPOSITE_TASK_REVIEW)); 108 lowerText.setImage(WARNING_IMAGE, CheatSheetPlugin.getPlugin().getImage(ICheatSheetResource.WARNING)); 109 lowerText.setImage(INFORMATION_IMAGE, CheatSheetPlugin.getPlugin().getImage(ICheatSheetResource.INFORMATION)); 110 } 111 112 public Control getControl() { 113 return control; 114 } 115 116 public void addHyperlinkListener(IHyperlinkListener listener) { 117 lowerText.addHyperlinkListener(listener); 118 } 119 120 public void showDescription(final ICompositeCheatSheetTask task) { 121 StringBuffer upperMessage = new StringBuffer (); 122 upperMessage.append("<form>"); upperMessage.append("<p><span color=\"title\" font=\"header\">"); upperMessage.append(MarkupParser.escapeText(task.getName())); 125 upperMessage.append("</span></p>"); upperMessage.append(MarkupParser.createParagraph(task.getDescription(), null)); 127 upperMessage.append("</form>"); upperText.setText(upperMessage.toString(), true, false); 129 130 StringBuffer buf = new StringBuffer (); 131 buf.append("<form>"); 133 boolean startable = false; 134 boolean isBlocked = false; 135 boolean isSkippable = ((AbstractTask)task).isSkippable(); 136 137 if (task.getState() == ICompositeCheatSheetTask.COMPLETED) { 138 buf.append(MarkupParser.createParagraph(task.getCompletionMessage(), null)); 139 isSkippable = false; 140 } else if (task.getState() == ICompositeCheatSheetTask.SKIPPED) { 141 buf.append(MarkupParser.createParagraph(Messages.THIS_TASK_SKIPPED, INFORMATION_IMAGE)); 142 isSkippable = false; 143 } else if (TaskStateUtilities.findSkippedAncestor(task) != null) { 144 ICompositeCheatSheetTask skipped = TaskStateUtilities.findSkippedAncestor(task); 145 String skipParentMsg = NLS.bind(Messages.PARENT_SKIPPED, 146 (new Object [] {MarkupParser.escapeText((skipped.getName()))})); 147 buf.append(MarkupParser.createParagraph(skipParentMsg, WARNING_IMAGE)); 148 isSkippable = false; 149 } else if (TaskStateUtilities.findCompletedAncestor(task) != null) { 150 ICompositeCheatSheetTask completed = TaskStateUtilities.findCompletedAncestor(task); 151 String completedParentMsg = NLS.bind(Messages.PARENT_COMPLETED, 152 (new Object [] {MarkupParser.escapeText(completed.getName())})); 153 buf.append(MarkupParser.createParagraph(completedParentMsg, WARNING_IMAGE)); 154 isSkippable = false; 155 } else if (!task.requiredTasksCompleted()) { 156 isBlocked = true; 157 showBlockingTasks(Messages.COMPOSITE_PAGE_BLOCKED, task, buf); 158 } else if (TaskStateUtilities.findBlockedAncestor(task) != null) { 159 isBlocked = true; 160 ICompositeCheatSheetTask blockedAncestor = TaskStateUtilities.findBlockedAncestor(task); 161 String blockingAncestorMsg = NLS.bind(Messages.PARENT_BLOCKED, 162 (new Object [] {MarkupParser.escapeText(blockedAncestor.getName())})); 163 showBlockingTasks(blockingAncestorMsg , blockedAncestor, buf); 164 } else { 165 startable = task instanceof IEditableTask && task.getState() == ICompositeCheatSheetTask.NOT_STARTED; 166 } 167 168 if (startable) { 169 addHyperlink(buf, CompositeCheatSheetPage.START_HREF, START_IMAGE, Messages.COMPOSITE_PAGE_START_TASK); 170 } 171 172 if (task instanceof IEditableTask && task.getState() == ICompositeCheatSheetTask.COMPLETED ) { 173 addHyperlink(buf, CompositeCheatSheetPage.REVIEW_TAG, REVIEW_IMAGE, Messages.COMPOSITE_PAGE_REVIEW_TASK); 174 } 175 176 if (isSkippable) { 177 String skipMessage; 178 if (task instanceof ITaskGroup) { 179 skipMessage = Messages.COMPOSITE_PAGE_SKIP_TASK_GROUP; 180 } else { 181 skipMessage = Messages.COMPOSITE_PAGE_SKIP_TASK; 182 } 183 addHyperlink(buf, CompositeCheatSheetPage.SKIP_HREF, SKIP_IMAGE, skipMessage); 184 } 185 186 if (!startable && !isBlocked) { 187 showSuccesorTaskLinks(task, buf); 188 } 189 190 buf.append("</form>"); 192 lowerText.setText(buf.toString(), true, false); 193 getControl().setData(ICompositeCheatsheetTags.TASK, task); 194 form.reflow(true); 195 } 196 197 private void showBlockingTasks(String message, final ICompositeCheatSheetTask task, StringBuffer buf) { 198 buf.append("<p/>"); buf.append("<p>"); buf.append("<img HREF=\""); buf.append(WARNING_IMAGE); 202 buf.append("\"/> "); buf.append(message); 204 buf.append("</p>"); 206 ICompositeCheatSheetTask[] requiredTasks = task.getRequiredTasks(); 207 for (int i = 0; i < requiredTasks.length; i++) { 208 warnOfIncompleteTask(buf, requiredTasks[i]); 209 } 210 buf.append("<p>"); buf.append("</p>"); } 213 214 private void addHyperlink(StringBuffer buf, String href, String imageRef, String message) { 215 buf.append("<p><a HREF=\""); buf.append(href); 217 buf.append("\">"); buf.append("<img HREF=\""); buf.append(imageRef); 220 buf.append("\"/> "); buf.append(message); 222 buf.append("</a></p>"); } 224 225 228 private void warnOfIncompleteTask(StringBuffer buf, ICompositeCheatSheetTask task) { 229 if (task.getState() != ICompositeCheatSheetTask.COMPLETED && 230 task.getState() != ICompositeCheatSheetTask.SKIPPED ) { 231 buf.append("<li>"); buf.append("<a HREF=\""); buf.append(CompositeCheatSheetPage.GOTO_TASK_TAG); 234 buf.append(task.getId()); 235 buf.append("\">"); buf.append(NLS.bind(Messages.COMPOSITE_PAGE_TASK_NOT_COMPLETE, (new Object [] 237 {MarkupParser.escapeText(task.getName())}))); 238 buf.append("</a>"); buf.append("</li>"); } 241 } 242 243 private void showSuccesorTaskLinks(ICompositeCheatSheetTask task, StringBuffer buf) { 244 ICompositeCheatSheetTask[] successorTasks = new SuccesorTaskFinder(task).getRecommendedSuccessors(); 246 for (int i = 0; i < successorTasks.length; i++) { 247 ICompositeCheatSheetTask successor = successorTasks[i]; 248 String message = NLS.bind(Messages.COMPOSITE_PAGE_GOTO_TASK, (new Object [] 249 {MarkupParser.escapeText(successor.getName())})); 250 addHyperlink(buf, CompositeCheatSheetPage.GOTO_TASK_TAG + successor.getId(), GOTO_IMAGE, message); 251 } 252 } 253 254 } 255 | Popular Tags |