1 9 package de.loskutov.bco.views; 10 11 import org.eclipse.core.filebuffers.IFileBuffer; 12 import org.eclipse.core.filebuffers.IFileBufferListener; 13 import org.eclipse.core.runtime.IPath; 14 import org.eclipse.jdt.core.IJavaElement; 15 import org.eclipse.jface.text.ITextSelection; 16 import org.eclipse.jface.viewers.ISelection; 17 import org.eclipse.jface.viewers.IStructuredSelection; 18 import org.eclipse.swt.widgets.Display; 19 import org.eclipse.ui.IPartListener2; 20 import org.eclipse.ui.ISelectionListener; 21 import org.eclipse.ui.IWorkbenchPart; 22 import org.eclipse.ui.IWorkbenchPartReference; 23 24 27 public class EditorListener implements ISelectionListener, IFileBufferListener, 28 IPartListener2 { 29 protected BytecodeOutlineView view; 30 31 EditorListener(BytecodeOutlineView view){ 32 this.view = view; 33 } 34 35 38 public void dispose(){ 39 this.view = null; 40 } 41 42 47 public void selectionChanged(IWorkbenchPart part, ISelection selection) { 48 if(!(selection instanceof ITextSelection)){ 49 if(selection instanceof IStructuredSelection){ 50 IStructuredSelection ssel = (IStructuredSelection) selection; 51 if(ssel.isEmpty()){ 52 return; 53 } 54 if(ssel.getFirstElement() instanceof IJavaElement){ 55 60 Display display = Display.getDefault(); 61 display.asyncExec(new Runnable () { 63 public void run() { 64 view.checkOpenEditors(true); 65 } 66 }); 67 } 68 } 69 return; 70 } 71 view.handleSelectionChanged(part, selection); 72 } 73 74 77 public void dirtyStateChanged(IFileBuffer buffer, final boolean isDirty) { 78 if(!view.isLinkedWithEditor()){ 79 return; 80 } 81 if(isSupportedBuffer(buffer)){ view.handleBufferIsDirty(isDirty); 84 85 if(!isDirty){ 87 final Runnable runnable2 = new Runnable () { 90 public void run() { 91 view.handleBufferIsDirty(isDirty); 92 } 93 }; 94 Runnable runnable1 = new Runnable () { 97 public void run() { 98 Display display = Display.getCurrent(); 99 display.timerExec(1000, runnable2); 100 } 101 }; 102 Display display = Display.getDefault(); 103 display.asyncExec(runnable1); 105 } 106 } 107 } 108 109 private boolean isSupportedBuffer(IFileBuffer buffer) { 110 String fileExtension = buffer.getLocation().getFileExtension(); 111 return "java".equals(fileExtension); } 114 115 118 public void partClosed(IWorkbenchPartReference partRef) { 119 view.handlePartHidden(partRef.getPart(false)); 120 } 121 122 125 public void partHidden(IWorkbenchPartReference partRef) { 126 view.handlePartHidden(partRef.getPart(false)); 127 } 128 129 132 public void partOpened(IWorkbenchPartReference partRef) { 133 view.handlePartVisible(partRef.getPart(false)); 134 } 135 136 139 public void partVisible(IWorkbenchPartReference partRef) { 140 view.handlePartVisible(partRef.getPart(false)); 141 } 142 143 144 147 public void bufferDisposed(IFileBuffer buffer) { 148 } 150 151 154 public void bufferCreated(IFileBuffer buffer) { 155 } 157 158 161 public void bufferContentAboutToBeReplaced(IFileBuffer buffer) { 162 } 164 165 168 public void bufferContentReplaced(IFileBuffer buffer) { 169 } 171 172 175 public void stateChanging(IFileBuffer buffer) { 176 } 178 179 182 public void stateValidationChanged(IFileBuffer buffer, boolean isStateValidated) { 183 } 185 186 189 public void underlyingFileMoved(IFileBuffer buffer, IPath path) { 190 } 192 193 196 public void underlyingFileDeleted(IFileBuffer buffer) { 197 } 199 200 203 public void stateChangeFailed(IFileBuffer buffer) { 204 } 206 207 210 public void partInputChanged(IWorkbenchPartReference partRef) { 211 } 213 214 217 public void partActivated(IWorkbenchPartReference partRef) { 218 } 220 221 224 public void partBroughtToTop(IWorkbenchPartReference partRef) { 225 } 227 228 231 public void partDeactivated(IWorkbenchPartReference partRef) { 232 } 234 235 236 237 238 239 } 240 | Popular Tags |