1 11 package org.eclipse.update.internal.ui.views; 12 13 import java.lang.reflect.*; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.action.*; 17 import org.eclipse.jface.dialogs.*; 18 import org.eclipse.osgi.util.NLS; 19 import org.eclipse.swt.widgets.*; 20 import org.eclipse.update.configuration.*; 21 import org.eclipse.update.internal.ui.*; 22 import org.eclipse.update.operations.*; 23 24 27 28 public class SiteStateAction extends Action { 29 private IConfiguredSite site; 30 private Shell shell; 31 32 public SiteStateAction(Shell shell) { 33 this.shell = shell; 34 } 35 36 public void setSite(IConfiguredSite site) { 37 this.site = site; 38 boolean state = site.isEnabled(); 39 setText(state ? UpdateUIMessages.SiteStateAction_disableLabel : UpdateUIMessages.SiteStateAction_enableLabel); 40 } 41 42 public void run() { 43 try { 44 if (site == null) 45 return; 46 47 IStatus status = OperationsManager.getValidator().validatePlatformConfigValid(); 48 if (status != null) { 49 ErrorDialog.openError(shell, null, null, status); 50 return; 51 } 52 53 boolean oldValue = site.isEnabled(); 54 if (!confirm(!oldValue)) 55 return; 56 57 IOperation toggleSiteOperation = OperationsManager.getOperationFactory().createToggleSiteOperation(site); 58 boolean restartNeeded = toggleSiteOperation.execute(null, null); 59 60 UpdateUI.requestRestart(restartNeeded); 61 62 } catch (CoreException e) { 63 ErrorDialog.openError(shell, null, null, e.getStatus()); 64 } catch (InvocationTargetException e) { 65 UpdateUI.logException(e); 66 } 67 } 68 69 private boolean confirm(boolean newState) { 70 String name = site.getSite().getURL().toString(); 71 String enableMessage = NLS.bind(UpdateUIMessages.SiteStateAction_enableMessage, name); 72 String disableMessage = NLS.bind(UpdateUIMessages.SiteStateAction_disableMessage, name); 73 74 String message = newState ? enableMessage : disableMessage; 75 return MessageDialog.openConfirm(shell, UpdateUIMessages.SiteStateAction_dialogTitle, message); 76 } 77 } 78 | Popular Tags |