1 11 package org.eclipse.compare.internal; 12 13 import org.eclipse.swt.widgets.Composite; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.compare.*; 18 19 import org.eclipse.jface.viewers.Viewer; 20 21 24 public class ViewerDescriptor implements IViewerDescriptor { 25 26 private final static String CLASS_ATTRIBUTE= "class"; private final static String EXTENSIONS_ATTRIBUTE= "extensions"; 29 private IConfigurationElement fConfiguration; 30 private IViewerCreator fViewerCreator; 31 private Class fViewerClass; 32 33 public ViewerDescriptor(IConfigurationElement config) { 34 fConfiguration= config; 35 } 36 37 public Viewer createViewer(Viewer currentViewer, Composite parent, CompareConfiguration mp) { 38 39 if (currentViewer != null && currentViewer.getClass() == fViewerClass) { 40 return currentViewer; 42 } 43 44 if (fViewerCreator == null) { 45 try { 46 fViewerCreator= (IViewerCreator) fConfiguration.createExecutableExtension(CLASS_ATTRIBUTE); 47 } catch (CoreException e) { 48 CompareUIPlugin.log(e); 49 } 50 } 51 52 if (fViewerCreator != null) { 53 if (currentViewer != null) { 56 CompareHandlerService compareHandlerService = (CompareHandlerService)Utilities.getAdapter(currentViewer, CompareHandlerService.class); 57 if (compareHandlerService != null) 58 compareHandlerService.dispose(); 59 } 60 Viewer viewer= fViewerCreator.createViewer(parent, mp); 61 if (viewer != null) 62 fViewerClass= viewer.getClass(); 63 return viewer; 64 } 65 66 return null; 67 } 68 69 public String getExtension() { 70 return fConfiguration.getAttribute(EXTENSIONS_ATTRIBUTE); 71 } 72 } 73 | Popular Tags |