1 11 package org.eclipse.update.internal.ui.views; 12 13 import java.io.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.action.*; 17 import org.eclipse.jface.dialogs.*; 18 import org.eclipse.jface.resource.*; 19 import org.eclipse.swt.*; 20 import org.eclipse.swt.widgets.*; 21 import org.eclipse.update.configuration.*; 22 import org.eclipse.update.core.*; 23 import org.eclipse.update.internal.ui.*; 24 import org.eclipse.update.operations.*; 25 26 public class NewExtensionLocationAction extends Action { 27 private Shell shell; 28 29 public NewExtensionLocationAction(Shell shell, String text, ImageDescriptor desc) { 30 super(text, desc); 31 this.shell = shell; 32 } 33 34 public void run() { 35 36 IStatus status = OperationsManager.getValidator().validatePlatformConfigValid(); 37 if (status != null) { 38 ErrorDialog.openError(shell, null, null, status); 39 return; 40 } 41 42 DirectoryDialog dialog = 43 new DirectoryDialog(shell, SWT.APPLICATION_MODAL); 44 dialog.setMessage(UpdateUIMessages.NewExtensionLocationAction_selectExtLocation); 45 46 String dir = dialog.open(); 47 while (dir != null) { 48 File dirFile = getExtensionSite(new File(dir)); 49 if (dirFile != null) { 50 if (addExtensionLocation(dirFile)) 51 return; 52 else { 53 dialog.setFilterPath(dir); 55 dir = dialog.open(); 56 } 57 } else { 58 MessageDialog.openInformation( 59 shell, 60 UpdateUIMessages.NewExtensionLocationAction_extInfoTitle, 61 UpdateUIMessages.NewExtensionLocationAction_extInfoMessage); 62 dialog.setFilterPath(dir); 64 dir = dialog.open(); 65 } 66 } 67 } 68 69 73 static File getExtensionSite(File directory) { 74 if (directory.getName().equals("eclipse")) { File site = getExtensionSite(directory.getParentFile()); 78 if (site != null) 79 return directory; 80 } 82 83 File eclipse = new File(directory, "eclipse"); if (!eclipse.exists() || !eclipse.isDirectory()) 85 return null; 86 87 File marker = new File(eclipse, ".eclipseextension"); if (!marker.exists() || marker.isDirectory()) 90 return null; 91 return eclipse; 92 } 93 94 private boolean addExtensionLocation(File dir) { 95 try { 96 IInstallConfiguration config = SiteManager.getLocalSite().getCurrentConfiguration(); 97 IConfiguredSite csite = config.createLinkedConfiguredSite(dir); 98 csite.verifyUpdatableStatus(); 99 config.addConfiguredSite(csite); 100 boolean restartNeeded = SiteManager.getLocalSite().save(); 101 UpdateUI.requestRestart(restartNeeded); 102 return true; 103 } catch (CoreException e) { 104 String title = UpdateUIMessages.InstallWizard_TargetPage_location_error_title; 105 ErrorDialog.openError(shell, title, null, e.getStatus()); 106 UpdateUI.logException(e,false); 107 return false; 108 } 109 } 110 111 } 112 | Popular Tags |