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.printing.ui.internal.editor;
16:
17: import net.refractions.udig.printing.ui.internal.PrintingPlugin;
18:
19: import org.eclipse.core.runtime.CoreException;
20: import org.eclipse.core.runtime.IConfigurationElement;
21: import org.eclipse.gef.ui.actions.SelectionAction;
22: import org.eclipse.jface.action.IAction;
23: import org.eclipse.ui.IActionDelegate;
24: import org.eclipse.ui.IWorkbenchPart;
25:
26: /**
27: * Permits the lazy loading of edit actions. The name of the edit action is loaded from the extension point
28: * but the class is not created until the action is clicked.
29: *
30: * @author Jesse
31: * @since 1.1.0
32: */
33: public class DelegatingDirectAction extends SelectionAction implements
34: IAction {
35:
36: private IConfigurationElement element;
37: private IActionDelegate action;
38:
39: public DelegatingDirectAction(IWorkbenchPart part,
40: IConfigurationElement element) {
41: super (part);
42: this .element = element;
43: setText(element.getAttribute("name")); //$NON-NLS-1$
44: setId(element.getAttribute("id")); //$NON-NLS-1$
45: }
46:
47: @Override
48: public void run() {
49: if (action == null) {
50: try {
51: action = (IActionDelegate) element
52: .createExecutableExtension("action");//$NON-NLS-1$
53: } catch (CoreException e) {
54: PrintingPlugin.log("", e); //$NON-NLS-1$
55: }
56: }
57: if (action != null)
58: action.run(this );
59: }
60:
61: @Override
62: protected boolean calculateEnabled() {
63: return false;
64: }
65:
66: }
|