KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mountainminds > eclemma > internal > ui > actions > MergeSessionsAction


1 /*******************************************************************************
2  * Copyright (c) 2006 Mountainminds GmbH & Co. KG
3  * This software is provided under the terms of the Eclipse Public License v1.0
4  * See http://www.eclipse.org/legal/epl-v10.html.
5  *
6  * $Id: MergeSessionsAction.java 97 2006-09-18 17:14:42Z mho $
7  ******************************************************************************/

8 package com.mountainminds.eclemma.internal.ui.actions;
9
10 import java.text.MessageFormat JavaDoc;
11 import java.util.Date JavaDoc;
12
13 import org.eclipse.jface.action.Action;
14 import org.eclipse.jface.dialogs.IDialogConstants;
15 import org.eclipse.ui.IWorkbenchWindow;
16
17 import com.mountainminds.eclemma.core.CoverageTools;
18 import com.mountainminds.eclemma.core.ICoverageSession;
19 import com.mountainminds.eclemma.core.ISessionManager;
20 import com.mountainminds.eclemma.internal.ui.EclEmmaUIPlugin;
21 import com.mountainminds.eclemma.internal.ui.UIMessages;
22 import com.mountainminds.eclemma.internal.ui.dialogs.MergeSessionsDialog;
23
24 /**
25  * This action launches the merge sessions dialog.
26  *
27  * @author Marc R. Hoffmann
28  * @version $Revision: 97 $
29  */

30 public class MergeSessionsAction extends Action {
31   
32   private final IWorkbenchWindow window;
33   
34   public MergeSessionsAction(IWorkbenchWindow window) {
35     this.window = window;
36     setText(UIMessages.MergeSessionsAction_label);
37     setToolTipText(UIMessages.MergeSessionsAction_tooltip);
38     setImageDescriptor(EclEmmaUIPlugin.getImageDescriptor(EclEmmaUIPlugin.ELCL_MERGESESSIONS));
39     setDisabledImageDescriptor(EclEmmaUIPlugin.getImageDescriptor(EclEmmaUIPlugin.DLCL_MERGESESSIONS));
40   }
41   
42   public void run() {
43     ISessionManager sm = CoverageTools.getSessionManager();
44     ICoverageSession[] sessions = sm.getSessions();
45     String JavaDoc descr = UIMessages.MergeSessionsDialogDescriptionDefault_value;
46     descr = MessageFormat.format(descr, new Object JavaDoc[] { new Date JavaDoc() });
47     MergeSessionsDialog d = new MergeSessionsDialog(window.getShell(), sessions, descr);
48     if (d.open() == IDialogConstants.OK_ID) {
49       Object JavaDoc[] result = d.getResult();
50       ICoverageSession merged = (ICoverageSession) result[0];
51       for (int i = 1; i < result.length; i++) {
52         merged = merged.merge((ICoverageSession) result[i], d.getDescription());
53       }
54       sm.addSession(merged, true, null);
55       for (int i = 0; i < result.length; i++) {
56         sm.removeSession((ICoverageSession) result[i]);
57       }
58     }
59   }
60
61 }
62
Popular Tags