KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > DuplicateLaunchDelegatesStatusHandler


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.launchConfigurations;
12
13 import java.util.HashSet JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.debug.core.ILaunchConfiguration;
19 import org.eclipse.debug.core.ILaunchDelegate;
20 import org.eclipse.debug.core.IStatusHandler;
21 import org.eclipse.debug.internal.ui.DebugUIPlugin;
22 import org.eclipse.jface.dialogs.IDialogConstants;
23 import org.eclipse.swt.widgets.Shell;
24
25 /**
26  * This class provides a mechanism to prompt users in the UI thread from debug.core in the case where
27  * duplicate launch delegates have been detected and a preferred delegate needs to be selected.
28  *
29  * As this handler is used once a launch has been started, and only prompts in the event that the launch <i>can</i>
30  * continue with further input, it must be a blocking operation.
31  *
32  * @since 3.3
33  */

34 public class DuplicateLaunchDelegatesStatusHandler implements IStatusHandler {
35     
36     /**
37      * @see org.eclipse.debug.core.IStatusHandler#handleStatus(org.eclipse.core.runtime.IStatus, java.lang.Object)
38      */

39     public Object JavaDoc handleStatus(IStatus status, Object JavaDoc source) throws CoreException {
40         if(source instanceof Object JavaDoc[]) {
41             Object JavaDoc[] infos = (Object JavaDoc[]) source;
42             if(infos.length == 2) {
43                 ILaunchConfiguration config = (ILaunchConfiguration) infos[0];
44                 String JavaDoc mode = (String JavaDoc) infos[1];
45                 Shell shell = DebugUIPlugin.getShell();
46                 HashSet JavaDoc modes = new HashSet JavaDoc();
47                 modes.add(mode);
48                 modes.addAll(config.getModes());
49                 SelectLaunchersDialog sldd = new SelectLaunchersDialog(shell,
50                         config.getType().getDelegates(modes),
51                         config.getWorkingCopy(),
52                         mode);
53                 if(sldd.open() != IDialogConstants.OK_ID) {
54                     return Status.CANCEL_STATUS;
55                 }
56                 //check that the delegate has been set
57
ILaunchDelegate delegate = config.getPreferredDelegate(modes);
58                 if(delegate == null) {
59                     delegate = config.getType().getPreferredDelegate(modes);
60                 }
61                 return (delegate == null ? Status.CANCEL_STATUS : Status.OK_STATUS);
62             }
63         }
64         return Status.CANCEL_STATUS;
65     }
66 }
67
Popular Tags