View Javadoc

1   /* ======================================
2    * Copyright (c) 2004-2005 Achim Nierbeck
3    * All rights reserved.
4    *
5    * You may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *       http://www.gnu.org/licenses/lgpl.html
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   * ======================================
16   */
17  
18  /*
19   * DeleteAction.java
20   * $Revision: 1.3 $
21   * Date 14.12.2005
22   * 
23   * $Author: nierbeck $ 
24   * $Date: 2006/02/02 21:29:37 $ 
25   * 
26   */
27  
28  package de.nierbeck.timeTrack.actions;
29  
30  import org.eclipse.jface.action.Action;
31  import org.eclipse.jface.action.IAction;
32  import org.eclipse.jface.dialogs.MessageDialog;
33  import org.eclipse.jface.viewers.ISelection;
34  import org.eclipse.jface.viewers.IStructuredSelection;
35  import org.eclipse.jface.viewers.TableViewer;
36  import org.eclipse.swt.widgets.Shell;
37  import org.eclipse.ui.IObjectActionDelegate;
38  import org.eclipse.ui.IWorkbenchPart;
39  
40  import de.nierbeck.timeTrack.model.Entries;
41  
42  /***
43   * Action Class for Deleting entries from the Table
44   * 
45   * @author Achim
46   * 
47   */
48  public class DeleteAction extends Action implements IObjectActionDelegate {
49  
50  	private TableViewer tableView;
51  
52  	private Entries entries;
53  
54  	/***
55  	 * Constructor for DeleteAction.
56  	 * 
57  	 * @param tableView - Table View on wich it acts
58  	 * @param entries - the Entries on which it acts
59  	 */
60  	public DeleteAction(TableViewer tableView, Entries entries) {
61  		super();
62  		this.tableView = tableView;
63  		this.entries = entries;
64  	}
65  
66  	/***
67  	 * Does nothing
68  	 * 
69  	 * @param action - given action
70  	 * @param targetPart - targetPart 
71  	 * 
72  	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
73  	 */
74  	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
75  	}
76  
77  	/***
78  	 * @see IActionDelegate#run(IAction)
79  	 * 
80  	 * @param action - run on the given action
81  	 */
82  	public final void run(IAction action) {
83  		Shell shell = new Shell();
84  		MessageDialog.openInformation(shell, "TimeTrack Plug-in",
85  				"New Action was executed.");
86  	}
87  
88  	/***
89  	 * @see Action#run()
90  	 */
91  	public final void run() {
92  		Object obj = ((IStructuredSelection) tableView.getSelection())
93  				.getFirstElement();
94  		tableView.remove(obj);
95  		entries.getEntry().remove(obj);
96  	}
97  
98  	/***
99  	 * @param action - does nothing
100 	 * @param selection - does nothing
101 	 * 
102 	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
103 	 */
104 	public void selectionChanged(IAction action, ISelection selection) {
105 	}
106 
107 }