1 11 package org.eclipse.jdt.internal.ui.compare; 12 13 import org.eclipse.core.runtime.CoreException; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.graphics.Font; 17 import org.eclipse.swt.widgets.Composite; 18 import org.eclipse.swt.widgets.Control; 19 20 import org.eclipse.jface.preference.IPreferenceStore; 21 import org.eclipse.jface.resource.JFaceResources; 22 import org.eclipse.jface.viewers.ISelection; 23 import org.eclipse.jface.viewers.Viewer; 24 25 import org.eclipse.jface.text.Document; 26 import org.eclipse.jface.text.source.SourceViewer; 27 28 import org.eclipse.compare.IStreamContentAccessor; 29 30 import org.eclipse.jdt.ui.text.JavaTextTools; 31 32 import org.eclipse.jdt.internal.ui.JavaPlugin; 33 import org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions; 34 import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileSourceViewerConfiguration; 35 36 41 public class PropertiesFileViewer extends Viewer { 42 43 private SourceViewer fSourceViewer; 44 private Object fInput; 45 46 47 PropertiesFileViewer(Composite parent) { 48 fSourceViewer= new SourceViewer(parent, null, SWT.LEFT_TO_RIGHT | SWT.H_SCROLL | SWT.V_SCROLL); 49 JavaTextTools tools= JavaCompareUtilities.getJavaTextTools(); 50 if (tools != null) { 51 IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore(); 52 fSourceViewer.configure(new PropertiesFileSourceViewerConfiguration(tools.getColorManager(), store, null, IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING)); 53 } 54 55 fSourceViewer.setEditable(false); 56 57 String symbolicFontName= PropertiesFileMergeViewer.class.getName(); 58 Font font= JFaceResources.getFont(symbolicFontName); 59 if (font != null) 60 fSourceViewer.getTextWidget().setFont(font); 61 } 62 63 public Control getControl() { 64 return fSourceViewer.getControl(); 65 } 66 67 public void setInput(Object input) { 68 if (input instanceof IStreamContentAccessor) { 69 Document document= new Document(getString(input)); 70 JavaCompareUtilities.setupPropertiesFileDocument(document); 71 fSourceViewer.setDocument(document); 72 } 73 fInput= input; 74 } 75 76 public Object getInput() { 77 return fInput; 78 } 79 80 public ISelection getSelection() { 81 return null; 82 } 83 84 public void setSelection(ISelection s, boolean reveal) { 85 } 86 87 public void refresh() { 88 } 89 90 94 private static String getString(Object input) { 95 96 if (input instanceof IStreamContentAccessor) { 97 IStreamContentAccessor sca= (IStreamContentAccessor) input; 98 try { 99 return JavaCompareUtilities.readString(sca); 100 } catch (CoreException ex) { 101 JavaPlugin.log(ex); 102 } 103 } 104 return ""; } 106 } 107 | Popular Tags |