~piastucki/bzr-eclipse/history-view-enhancements

« back to all changes in this revision

Viewing changes to org.vcs.bazaar.eclipse.ui/src/org/vcs/bazaar/eclipse/ui/team/BzrAction.java

  • Committer: Guillermo Gonzalez
  • Date: 2007-03-14 12:15:50 UTC
  • Revision ID: guillo.gonzo@gmail.com-20070314121550-tltk3b6f3zblf0dh
Initial commit with the new code layout.
Now starts the real work

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * LICENCSE + COPYRIGHT
 
3
 */
 
4
package org.vcs.bazaar.eclipse.ui.team;
 
5
 
 
6
import org.eclipse.core.resources.IProject;
 
7
import org.eclipse.jface.action.IAction;
 
8
import org.eclipse.jface.viewers.ISelection;
 
9
import org.eclipse.jface.viewers.IStructuredSelection;
 
10
import org.eclipse.swt.widgets.Shell;
 
11
import org.eclipse.ui.IWorkbench;
 
12
import org.eclipse.ui.IWorkbenchWindow;
 
13
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 
14
import org.eclipse.ui.PlatformUI;
 
15
 
 
16
/**
 
17
 * @author Guillermo Gonzalez <guillo.gonzo@gmail.com>
 
18
 * 
 
19
 * TODO
 
20
 * 
 
21
 * I'm the base class for all actions.
 
22
 */
 
23
public abstract class BzrAction implements IWorkbenchWindowActionDelegate {
 
24
 
 
25
        protected IWorkbenchWindow window;
 
26
 
 
27
        protected IStructuredSelection selection;
 
28
 
 
29
        /**
 
30
         * Find and return the repository for the selection
 
31
         * 
 
32
         * @param selection
 
33
         * @return
 
34
         */
 
35
        protected String getRepositoryFor(IStructuredSelection selection) {
 
36
                IProject proj = BazaarUtilities.getProject(selection);
 
37
                return BazaarUtilities.getRepositoryPath(proj);
 
38
        }
 
39
 
 
40
        /**
 
41
         * Find and return the shell of the parent "window"
 
42
         * 
 
43
         * @return the parent window Shell or a workbench Shell
 
44
         */
 
45
        protected Shell getParentShell() {
 
46
                Shell shell;
 
47
                if ((window != null) && (window.getShell() != null)) {
 
48
                        shell = window.getShell();
 
49
                } else {
 
50
                        IWorkbench workbench = PlatformUI.getWorkbench();
 
51
                        shell = workbench.getActiveWorkbenchWindow().getShell();
 
52
                }
 
53
                return shell;
 
54
        }
 
55
        
 
56
        /**
 
57
         * We will cache window object in order to be able to provide parent shell
 
58
         * for the message dialog.
 
59
         * 
 
60
         * @see IWorkbenchWindowActionDelegate#init
 
61
         */
 
62
        public void init(IWorkbenchWindow window) {
 
63
                // TODO: change System.out to BazaarEclipsePlugin.log()
 
64
                // TODO: test if this.getClass().getName() == "ActionXXXX" and != "BzrAction"
 
65
                System.out.println(this.getClass().getName() + ":init(window)");
 
66
                //this.window = window;
 
67
        }
 
68
        
 
69
        /**
 
70
         * We can use this method to dispose of any system resources we previously
 
71
         * allocated.
 
72
         * 
 
73
         * @see IWorkbenchWindowActionDelegate#dispose
 
74
         */
 
75
        public void dispose() {
 
76
 
 
77
        }
 
78
        
 
79
        /**
 
80
         * Selection in the workbench has been changed. We can change the state of
 
81
         * the 'real' action here if we want, but this can only happen after the
 
82
         * delegate has been created.
 
83
         * 
 
84
         * @see IWorkbenchWindowActionDelegate#selectionChanged
 
85
         */
 
86
        public void selectionChanged(IAction action, ISelection in_selection) {
 
87
                if (in_selection != null
 
88
                                && in_selection instanceof IStructuredSelection) {
 
89
                        selection = (IStructuredSelection) in_selection;
 
90
                }
 
91
        }
 
92
 
 
93
}