KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > AttachSourceAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.internal.debug.ui.actions;
12
13
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.jdt.core.IClasspathEntry;
17 import org.eclipse.jdt.internal.debug.ui.launcher.RuntimeClasspathViewer;
18 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
19 import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.swt.SWT;
22
23 /**
24  * Attach source to an archive or variable.
25  */

26 public class AttachSourceAction extends RuntimeClasspathAction {
27     
28     private IRuntimeClasspathEntry[] fEntries;
29     
30     /**
31      * Creates an action to open a source attachment dialog.
32      *
33      * @param viewer the viewer the action is associated with or <code>null</code>
34      * @param style a button or radio button
35      */

36     public AttachSourceAction(RuntimeClasspathViewer viewer, int style) {
37         super((style == SWT.RADIO) ? ActionMessages.AttachSourceAction_2 : ActionMessages.AttachSourceAction_3, viewer); //
38
}
39
40     /**
41      * Prompts source attachment.
42      *
43      * @see org.eclipse.jface.action.IAction#run()
44      */

45     public void run() {
46         IClasspathEntry classpathEntry = BuildPathDialogAccess.configureSourceAttachment(getShell(), fEntries[0].getClasspathEntry());
47         if (classpathEntry != null) {
48             for (int i = 0; i < fEntries.length; i++) {
49                 IRuntimeClasspathEntry entry = fEntries[i];
50                 entry.setSourceAttachmentPath(classpathEntry.getSourceAttachmentPath());
51                 entry.setSourceAttachmentRootPath(classpathEntry.getSourceAttachmentRootPath());
52                 getViewer().refresh(entry);
53             }
54             getViewer().notifyChanged();
55         }
56     }
57
58     /* (non-Javadoc)
59      * @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
60      */

61     protected boolean updateSelection(IStructuredSelection selection) {
62         fEntries = new IRuntimeClasspathEntry[selection.size()];
63         Iterator JavaDoc iterator = selection.iterator();
64         int i = 0;
65         while (iterator.hasNext()) {
66             Object JavaDoc selected= iterator.next();
67             if (selected instanceof IRuntimeClasspathEntry) {
68                 IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry)selected;
69                 int type = entry.getType();
70                 switch (type) {
71                     case IRuntimeClasspathEntry.VARIABLE:
72                     case IRuntimeClasspathEntry.ARCHIVE:
73                         fEntries[i] = entry;
74                         i++;
75                         break;
76                     default:
77                         return false;
78                 }
79             } else {
80                 return false;
81             }
82         }
83         return selection.size() > 0;
84     }
85 }
86
Popular Tags