1 /*******************************************************************************
2 * Copyright (c) 2000, 2012 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package org.eclipse.jdt.internal.ui.text.correction;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.List;
18 import org.eclipse.ui.IWorkbench;
19 import org.eclipse.ui.PlatformUI;
20 import org.eclipse.ui.commands.ICommandService;
21 import org.eclipse.ui.handlers.IHandlerActivation;
22 import org.eclipse.ui.handlers.IHandlerService;
24 import org.eclipse.jdt.internal.ui.JavaPlugin;
25 import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
27 public class CorrectionCommandInstaller {
29 public List<IHandlerActivation> fCorrectionHandlerActivations;
31 public CorrectionCommandInstaller() {
32 fCorrectionHandlerActivations= null;
35 public void registerCommands(CompilationUnitEditor editor) {
36 IWorkbench workbench= PlatformUI.getWorkbench();
37 ICommandService commandService= (ICommandService) workbench.getAdapter(ICommandService.class);
38 IHandlerService handlerService= (IHandlerService) workbench.getAdapter(IHandlerService.class);
39 if (commandService == null || handlerService == null) {
43 if (fCorrectionHandlerActivations != null) {
44 JavaPlugin.logErrorMessage("correction handler activations not released"); //$NON-NLS-1$
46 fCorrectionHandlerActivations= new ArrayList<IHandlerActivation>();
48 Collection<String> definedCommandIds= commandService.getDefinedCommandIds();
49 editor.generated_7415811112593806754(this, handlerService, definedCommandIds);
52 public void deregisterCommands() {
53 IHandlerService handlerService= (IHandlerService) PlatformUI.getWorkbench().getAdapter(IHandlerService.class);
54 if (handlerService != null && fCorrectionHandlerActivations != null) {
55 handlerService.deactivateHandlers(fCorrectionHandlerActivations);
56 fCorrectionHandlerActivations= null;