1 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 33 public class EditAntHomeEntryAction extends RuntimeClasspathAction { 34 35 private AntClasspathTab fTab; 36 41 public EditAntHomeEntryAction(IClasspathViewer viewer, AntClasspathTab tab) { 42 super(AntLaunchConfigurationMessages.EditAntHomeEntryAction_1, viewer); 43 fTab = tab; 44 } 45 46 47 50 public void run() { 51 IDialogSettings dialogSettings = AntUIPlugin.getDefault().getDialogSettings(); 52 String 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 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 defaultHome = preferences.getAntHome(); 66 if (path.equalsIgnoreCase(defaultHome)) { 67 path = null; 68 } 69 fTab.setDirty(true); 70 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 getViewer().addEntries(new IRuntimeClasspathEntry[]{new AntHomeClasspathEntry(path)}); 86 } 87 88 91 protected boolean updateSelection(IStructuredSelection selection) { 92 return true; 93 } 94 } 95 | Popular Tags |