1 11 12 package org.eclipse.jdt.internal.ui.text.correction; 13 14 import java.util.ArrayList ; 15 import java.util.Collection ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 19 import org.eclipse.ui.IWorkbench; 20 import org.eclipse.ui.LegacyHandlerSubmissionExpression; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.commands.ICommandService; 23 import org.eclipse.ui.handlers.IHandlerActivation; 24 import org.eclipse.ui.handlers.IHandlerService; 25 26 import org.eclipse.jdt.internal.ui.JavaPlugin; 27 import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; 28 29 public class CorrectionCommandInstaller { 30 31 34 public static final String COMMAND_PREFIX= "org.eclipse.jdt.ui.correction."; 36 39 public static final String ASSIST_SUFFIX= ".assist"; 41 private List fCorrectionHandlerActivations; 42 43 public CorrectionCommandInstaller() { 44 fCorrectionHandlerActivations= null; 45 } 46 47 public void registerCommands(CompilationUnitEditor editor) { 48 IWorkbench workbench= PlatformUI.getWorkbench(); 49 ICommandService commandService= (ICommandService) workbench.getAdapter(ICommandService.class); 50 IHandlerService handlerService= (IHandlerService) workbench.getAdapter(IHandlerService.class); 51 if (commandService == null || handlerService == null) { 52 return; 53 } 54 55 if (fCorrectionHandlerActivations != null) { 56 JavaPlugin.logErrorMessage("correction handler activations not released"); } 58 fCorrectionHandlerActivations= new ArrayList (); 59 60 Collection definedCommandIds= commandService.getDefinedCommandIds(); 61 for (Iterator iter= definedCommandIds.iterator(); iter.hasNext();) { 62 String id= (String ) iter.next(); 63 if (id.startsWith(COMMAND_PREFIX)) { 64 boolean isAssist= id.endsWith(ASSIST_SUFFIX); 65 CorrectionCommandHandler handler= new CorrectionCommandHandler(editor, id, isAssist); 66 IHandlerActivation activation= handlerService.activateHandler(id, handler, new LegacyHandlerSubmissionExpression(null, null, editor.getSite())); 67 fCorrectionHandlerActivations.add(activation); 68 } 69 } 70 } 71 72 public void deregisterCommands() { 73 IHandlerService handlerService= (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class); 74 if (handlerService != null && fCorrectionHandlerActivations != null) { 75 handlerService.deactivateHandlers(fCorrectionHandlerActivations); 76 fCorrectionHandlerActivations= null; 77 } 78 } 79 80 } 81 | Popular Tags |