01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.tools.edit.activator;
16:
17: import net.refractions.udig.project.ui.tool.IToolContext;
18: import net.refractions.udig.tools.edit.Activator;
19: import net.refractions.udig.tools.edit.EditPlugin;
20: import net.refractions.udig.tools.edit.EditToolHandler;
21: import net.refractions.udig.tools.edit.handler.SnapBehaviourCommandHandler;
22:
23: import org.eclipse.core.commands.Command;
24: import org.eclipse.core.commands.IHandler;
25: import org.eclipse.ui.PlatformUI;
26: import org.eclipse.ui.commands.ICommandService;
27:
28: /**
29: * Enables the {@link net.refractions.udig.tools.edit.handler.SnapBehaviourCommandHandler} on the CycleSnapBehaviour command.
30: * @author Jesse
31: * @since 1.1.0
32: */
33: public class SetSnapBehaviourCommandHandlerActivator implements
34: Activator {
35: private static final String COMMAND_ID = "net.refractions.udig.tool.edit.cycle.snap.behaviour"; //$NON-NLS-1$
36: ICommandService service = (ICommandService) PlatformUI
37: .getWorkbench().getAdapter(ICommandService.class);
38: private IHandler commandHandler;
39:
40: public void activate(EditToolHandler handler) {
41: Command command = service.getCommand(COMMAND_ID);
42: IToolContext context = handler.getContext();
43: commandHandler = new SnapBehaviourCommandHandler(context
44: .getMapDisplay(), context.getMap());
45: if (command != null)
46: command.setHandler(commandHandler);
47: }
48:
49: public void deactivate(EditToolHandler handler) {
50: commandHandler = null;
51: Command command = service.getCommand(COMMAND_ID);
52: if (command != null)
53: command.setHandler(null);
54: }
55:
56: public void handleActivateError(EditToolHandler handler,
57: Throwable error) {
58: EditPlugin.log("", error); //$NON-NLS-1$
59: }
60:
61: public void handleDeactivateError(EditToolHandler handler,
62: Throwable error) {
63: EditPlugin.log("", error); //$NON-NLS-1$
64: }
65:
66: }
|