1 11 package org.eclipse.ltk.internal.ui.refactoring.model; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.NullProgressMonitor; 15 16 import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; 17 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; 18 19 import org.eclipse.ltk.internal.ui.refactoring.util.HTMLPrinter; 20 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.browser.Browser; 23 import org.eclipse.swt.graphics.Font; 24 import org.eclipse.swt.graphics.FontData; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Control; 27 import org.eclipse.swt.widgets.Display; 28 29 import org.eclipse.jface.resource.JFaceResources; 30 import org.eclipse.jface.text.TextSelection; 31 import org.eclipse.jface.viewers.ISelection; 32 import org.eclipse.jface.viewers.Viewer; 33 34 39 public class RefactoringDescriptorViewer extends Viewer { 40 41 42 protected final Browser fBrowser; 43 44 45 private RefactoringDescriptorProxy fDescriptor= null; 46 47 55 public RefactoringDescriptorViewer(final Composite parent, final int style) { 56 Assert.isNotNull(parent); 57 fBrowser= new Browser(parent, style); 58 final Display display= parent.getDisplay(); 59 fBrowser.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND)); 60 fBrowser.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); 61 } 62 63 66 public Control getControl() { 67 return fBrowser; 68 } 69 70 73 public Object getInput() { 74 return fDescriptor; 75 } 76 77 84 protected String getInputText(final RefactoringDescriptorProxy proxy) { 85 final StringBuffer buffer= new StringBuffer (); 86 final Font font= JFaceResources.getDialogFont(); 87 final FontData[] data= font.getFontData(); 88 String face= data[0].getName(); 89 int index= face.indexOf('-'); 90 if (index >= 0 && index < face.length() - 1) 91 face= face.substring(index + 1); 92 final int size= data[0].getHeight(); 93 HTMLPrinter.insertPageProlog(buffer, face, size, 0, fBrowser.getBackground().getRGB()); 94 if (proxy != null) { 95 HTMLPrinter.addSmallHeader(buffer, face, size, HTMLPrinter.convertToHTMLContent(proxy.getDescription())); 96 final RefactoringDescriptor descriptor= proxy.requestDescriptor(new NullProgressMonitor()); 97 if (descriptor != null) { 98 final String comment= descriptor.getComment(); 99 if (comment != null && !"".equals(comment)) HTMLPrinter.addParagraph(buffer, face, size, HTMLPrinter.convertToHTMLContent(comment)); 101 HTMLPrinter.startBulletList(buffer); 102 final int flags= descriptor.getFlags(); 103 if ((flags & RefactoringDescriptor.BREAKING_CHANGE) > 0) 104 HTMLPrinter.addBullet(buffer, face, size, ModelMessages.RefactoringDescriptorViewer_breaking_change_message); 105 if ((flags & RefactoringDescriptor.STRUCTURAL_CHANGE) > 0) 106 HTMLPrinter.addBullet(buffer, face, size, ModelMessages.RefactoringDescriptorViewer_structural_change_message); 107 if ((flags & RefactoringDescriptor.MULTI_CHANGE) > 0) 108 HTMLPrinter.addBullet(buffer, face, size, ModelMessages.RefactoringDescriptorViewer_closure_change_message); 109 HTMLPrinter.endBulletList(buffer); 110 } 111 } 112 HTMLPrinter.addPageEpilog(buffer); 113 return buffer.toString(); 114 } 115 116 119 public ISelection getSelection() { 120 return new TextSelection(0, 0); 121 } 122 123 126 public void refresh() { 127 String text= getInputText(fDescriptor); 128 if (text != null && text.length() > 0) { 129 if ((fBrowser.getShell().getStyle() & SWT.RIGHT_TO_LEFT) != 0) { 130 final StringBuffer buffer= new StringBuffer (text); 131 HTMLPrinter.insertStyles(buffer, new String [] { "direction:rtl", "overflow:hidden"}); text= buffer.toString(); 133 } 134 } 135 fBrowser.setText(text); 136 } 137 138 141 public void setInput(final Object input) { 142 if (input instanceof RefactoringDescriptorProxy) { 143 fDescriptor= (RefactoringDescriptorProxy) input; 144 refresh(); 145 } else 146 fDescriptor= null; 147 } 148 149 152 public void setSelection(final ISelection selection, final boolean reveal) { 153 } 155 } 156 | Popular Tags |