1 11 package org.eclipse.compare.structuremergeviewer; 12 13 import org.eclipse.compare.*; 14 import org.eclipse.core.runtime.IAdaptable; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.jface.text.IDocument; 17 import org.eclipse.swt.graphics.Image; 18 import org.eclipse.swt.widgets.Shell; 19 import org.eclipse.ui.services.IDisposable; 20 21 37 public class StructureRootNode extends DocumentRangeNode implements IDisposable, ITypedElement { 38 39 43 public static final int ROOT_TYPE = 0; 44 45 49 public static final String ROOT_ID = "root"; 51 private final Object fInput; 52 private final StructureCreator fCreator; 53 private ISharedDocumentAdapter fAdapter; 54 55 63 public StructureRootNode(IDocument document, Object input, StructureCreator creator, ISharedDocumentAdapter adapter) { 64 super(null, ROOT_TYPE, ROOT_ID, document, 0, document.getLength()); 65 fInput = input; 66 fCreator = creator; 67 fAdapter = adapter; 68 } 69 70 73 public void dispose() { 74 if (fAdapter != null) { 75 fAdapter.disconnect(fInput); 76 } 77 } 78 79 87 public Object getAdapter(Class adapter) { 88 if (adapter == ISharedDocumentAdapter.class) { 89 return fAdapter; 90 } 91 return super.getAdapter(adapter); 92 } 93 94 99 protected void nodeChanged(DocumentRangeNode node) { 100 fCreator.save(this, fInput); 101 } 102 103 106 public ITypedElement replace(ITypedElement child, ITypedElement other) { 107 nodeChanged(this); 110 return child; 111 } 112 113 116 public Image getImage() { 117 return null; 118 } 119 120 123 public String getName() { 124 return getId(); 125 } 126 127 130 public String getType() { 131 return FOLDER_TYPE; 132 } 133 134 137 public boolean isReadOnly() { 138 if (fInput instanceof IEditableContentExtension) { 139 IEditableContentExtension ext = (IEditableContentExtension) fInput; 140 return ext.isReadOnly(); 141 } 142 return super.isReadOnly(); 143 } 144 145 148 public IStatus validateEdit(Shell shell) { 149 if (fInput instanceof IEditableContentExtension) { 150 IEditableContentExtension ext = (IEditableContentExtension) fInput; 151 return ext.validateEdit(shell); 152 } 153 return super.validateEdit(shell); 154 } 155 156 } 157 | Popular Tags |