KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.debug.core.DebugPlugin;
16 import org.eclipse.debug.core.ILaunchConfiguration;
17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
18 import org.eclipse.debug.internal.ui.DebugUIPlugin;
19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
20 import org.eclipse.debug.ui.DebugUITools;
21 import org.eclipse.jface.resource.ImageDescriptor;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23 import org.eclipse.jface.viewers.Viewer;
24
25 /**
26  * Duplicates the selected launch configuration.
27  */

28 public class DuplicateLaunchConfigurationAction extends AbstractLaunchConfigurationAction {
29     
30     /**
31      * Action identifier for IDebugView#getAction(String)
32      */

33     public static final String JavaDoc ID_DUPLICATE_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_DUPLICATE_ACTION"; //$NON-NLS-1$
34

35     /**
36      * Constructs an action to duplicate a launch configuration
37      */

38     public DuplicateLaunchConfigurationAction(Viewer viewer, String JavaDoc mode) {
39         super(LaunchConfigurationsMessages.DuplicateLaunchConfigurationAction__Duplicate_1, viewer, mode);
40     }
41
42     /**
43      * @see AbstractLaunchConfigurationAction#performAction()
44      */

45     protected void performAction() {
46         ILaunchConfiguration original = (ILaunchConfiguration)getStructuredSelection().getFirstElement();
47         String JavaDoc newName = DebugPlugin.getDefault().getLaunchManager().generateUniqueLaunchConfigurationNameFrom(original.getName());
48         try {
49             ILaunchConfigurationWorkingCopy newWorkingCopy = original.copy(newName);
50             newWorkingCopy.doSave();
51         } catch (CoreException e) {
52             errorDialog(e);
53         }
54     }
55
56     /**
57      * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
58      */

59     protected boolean updateSelection(IStructuredSelection selection) {
60         return selection.size() == 1 && selection.getFirstElement() instanceof ILaunchConfiguration;
61     }
62     
63     /* (non-Javadoc)
64      * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor()
65      */

66     public ImageDescriptor getDisabledImageDescriptor() {
67         return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_DUPLICATE_CONFIG);
68     }
69
70     /* (non-Javadoc)
71      * @see org.eclipse.jface.action.Action#getImageDescriptor()
72      */

73     public ImageDescriptor getImageDescriptor() {
74         return DebugUITools.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_DUPLICATE_CONFIG);
75     }
76
77     /* (non-Javadoc)
78      * @see org.eclipse.jface.action.Action#getToolTipText()
79      */

80     public String JavaDoc getToolTipText() {
81         return LaunchConfigurationsMessages.LaunchConfigurationsDialog_5;
82     }
83
84 }
85
Popular Tags