1 11 package org.eclipse.update.internal.ui.views; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.jface.dialogs.ErrorDialog; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.swt.widgets.Shell; 20 import org.eclipse.update.internal.operations.UpdateUtils; 21 import org.eclipse.update.internal.ui.UpdateUI; 22 import org.eclipse.update.internal.ui.UpdateUIMessages; 23 import org.eclipse.update.internal.ui.model.ConfiguredFeatureAdapter; 24 import org.eclipse.update.operations.IOperation; 25 import org.eclipse.update.operations.OperationsManager; 26 27 public class FeatureStateAction extends FeatureAction { 28 29 private ConfiguredFeatureAdapter adapter; 30 31 public FeatureStateAction(Shell shell, String text) { 32 super(shell, text); 33 setWindowTitle(UpdateUIMessages.FeatureStateAction_dialogTitle); 34 } 35 36 public void setSelection(IStructuredSelection selection) { 37 38 this.adapter = (ConfiguredFeatureAdapter) selection.getFirstElement(); 39 if (adapter.isConfigured()) { 40 setText(UpdateUIMessages.FeatureStateAction_disable); 41 } else { 42 setText(UpdateUIMessages.FeatureStateAction_enable); 43 } 44 } 45 46 public void run() { 47 try { 48 if (adapter == null) 49 return; 50 51 IStatus status = OperationsManager.getValidator().validatePlatformConfigValid(); 52 if (status != null) 53 throw new CoreException(status); 54 55 boolean isConfigured = adapter.isConfigured(); 56 String message = 58 isConfigured 59 ? UpdateUIMessages.FeatureStateAction_disableQuestion 60 : UpdateUIMessages.FeatureStateAction_EnableQuestion; 61 62 if (!confirm(message)) 63 return; 64 65 if (OperationsManager.getValidator().validateCurrentState() != null && 67 !confirm(UpdateUIMessages.Actions_brokenConfigQuestion)) 68 return; 69 70 IOperation toggleOperation = 71 isConfigured 72 ? (IOperation)OperationsManager 73 .getOperationFactory() 74 .createUnconfigOperation( 75 adapter.getConfiguredSite(), 76 adapter.getFeature(null)) 77 : OperationsManager 78 .getOperationFactory() 79 .createConfigOperation( 80 adapter.getConfiguredSite(), 81 adapter.getFeature(null)); 82 83 boolean restartNeeded = toggleOperation.execute(null, null); 84 UpdateUI.requestRestart(restartNeeded); 85 86 } catch (CoreException e) { 87 ErrorDialog.openError(shell, 88 null, null, e.getStatus()); 89 } catch (InvocationTargetException e) { 90 UpdateUtils.logException(e.getTargetException()); 92 } 93 } 94 95 public boolean canExecuteAction() { 96 return true; 97 } 98 99 } 100 | Popular Tags |