KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > launchConfigurations > EditAntHomeEntryAction


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.ant.internal.ui.launchConfigurations;
12
13 import org.eclipse.ant.core.AntCorePlugin;
14 import org.eclipse.ant.core.AntCorePreferences;
15 import org.eclipse.ant.internal.ui.AntUIPlugin;
16 import org.eclipse.ant.internal.ui.IAntUIConstants;
17 import org.eclipse.ant.internal.ui.preferences.AntPreferencesMessages;
18 import org.eclipse.core.resources.ResourcesPlugin;
19 import org.eclipse.jdt.internal.debug.ui.actions.RuntimeClasspathAction;
20 import org.eclipse.jdt.internal.debug.ui.classpath.ClasspathEntry;
21 import org.eclipse.jdt.internal.debug.ui.launcher.IClasspathViewer;
22 import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
23 import org.eclipse.jdt.launching.IRuntimeClasspathEntry2;
24 import org.eclipse.jface.dialogs.IDialogSettings;
25 import org.eclipse.jface.viewers.IStructuredSelection;
26 import org.eclipse.swt.widgets.DirectoryDialog;
27
28 /**
29  * Edits the Ant Home classpath entry.
30  *
31  * @since 3.0
32  */

33 public class EditAntHomeEntryAction extends RuntimeClasspathAction {
34     
35     private AntClasspathTab fTab;
36     /**
37      * Constructs an action to edit the Ant Home setting for a launch config.
38      *
39      * @param viewer classpath viewer
40      */

41     public EditAntHomeEntryAction(IClasspathViewer viewer, AntClasspathTab tab) {
42         super(AntLaunchConfigurationMessages.EditAntHomeEntryAction_1, viewer);
43         fTab = tab;
44     }
45     
46     
47     /* (non-Javadoc)
48      * @see org.eclipse.jface.action.IAction#run()
49      */

50     public void run() {
51         IDialogSettings dialogSettings = AntUIPlugin.getDefault().getDialogSettings();
52         String JavaDoc lastUsedPath= dialogSettings.get(IAntUIConstants.DIALOGSTORE_LASTANTHOME);
53         if (lastUsedPath == null) {
54             lastUsedPath= ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString();
55         }
56         DirectoryDialog dialog = new DirectoryDialog(getShell());
57         dialog.setMessage(AntPreferencesMessages.AntClasspathBlock_3);
58         dialog.setFilterPath(lastUsedPath);
59         String JavaDoc path = dialog.open();
60         if (path == null) {
61             return;
62         }
63         dialogSettings.put(IAntUIConstants.DIALOGSTORE_LASTANTHOME, path);
64         AntCorePreferences preferences = AntCorePlugin.getPlugin().getPreferences();
65         String JavaDoc defaultHome = preferences.getAntHome();
66         if (path.equalsIgnoreCase(defaultHome)) {
67             path = null;
68         }
69         fTab.setDirty(true);
70         // update existing entry or add a new one
71
IRuntimeClasspathEntry[] entries = getViewer().getEntries();
72         for (int i = 0; i < entries.length; i++) {
73             IRuntimeClasspathEntry entry = entries[i];
74             if (entry.getType() == IRuntimeClasspathEntry.OTHER) {
75                 IRuntimeClasspathEntry2 entry2 = (IRuntimeClasspathEntry2)((ClasspathEntry)entry).getDelegate();
76                 if (entry2.getTypeId().equals(AntHomeClasspathEntry.TYPE_ID)) {
77                     ((AntHomeClasspathEntry)entry2).setAntHome(path);
78                     getViewer().refresh(entry);
79                     getViewer().notifyChanged();
80                     return;
81                 }
82             }
83         }
84         // no entry found - add a new one
85
getViewer().addEntries(new IRuntimeClasspathEntry[]{new AntHomeClasspathEntry(path)});
86     }
87     
88     /**
89      * @see SelectionListenerAction#updateSelection(IStructuredSelection)
90      */

91     protected boolean updateSelection(IStructuredSelection selection) {
92         return true;
93     }
94 }
95
Popular Tags