1 11 package org.eclipse.jdt.internal.ui.workingsets; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.swt.widgets.Shell; 16 17 import org.eclipse.jface.action.Action; 18 import org.eclipse.jface.dialogs.MessageDialog; 19 import org.eclipse.jface.window.Window; 20 import org.eclipse.jface.wizard.WizardDialog; 21 22 import org.eclipse.ui.IWorkbenchPartSite; 23 import org.eclipse.ui.IWorkingSet; 24 import org.eclipse.ui.IWorkingSetManager; 25 import org.eclipse.ui.PlatformUI; 26 import org.eclipse.ui.dialogs.IWorkingSetEditWizard; 27 28 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 29 import org.eclipse.jdt.internal.ui.JavaPlugin; 30 31 36 public class EditWorkingSetAction extends Action { 37 private IWorkbenchPartSite fSite; 38 private Shell fShell; 39 private WorkingSetFilterActionGroup fActionGroup; 40 41 public EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup, IWorkbenchPartSite site) { 42 this(actionGroup); 43 fSite= site; 44 } 45 46 public EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup, Shell shell) { 47 this(actionGroup); 48 fShell= shell; 49 } 50 51 private EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup) { 52 super(WorkingSetMessages.EditWorkingSetAction_text); 53 Assert.isNotNull(actionGroup); 54 setToolTipText(WorkingSetMessages.EditWorkingSetAction_toolTip); 55 setEnabled(actionGroup.getWorkingSet() != null); 56 fActionGroup= actionGroup; 57 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.EDIT_WORKING_SET_ACTION); 58 } 59 60 63 public void run() { 64 Shell shell= getShell(); 65 IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager(); 66 IWorkingSet workingSet= fActionGroup.getWorkingSet(); 67 if (workingSet == null || workingSet.isAggregateWorkingSet()) { 68 setEnabled(false); 69 return; 70 } 71 IWorkingSetEditWizard wizard= manager.createWorkingSetEditWizard(workingSet); 72 if (wizard == null) { 73 String title= WorkingSetMessages.EditWorkingSetAction_error_nowizard_title; 74 String message= WorkingSetMessages.EditWorkingSetAction_error_nowizard_message; 75 MessageDialog.openError(shell, title, message); 76 return; 77 } 78 WizardDialog dialog= new WizardDialog(shell, wizard); 79 dialog.create(); 80 if (dialog.open() == Window.OK) 81 fActionGroup.setWorkingSet(wizard.getSelection(), true); 82 } 83 84 private Shell getShell() { 85 if (fSite != null) { 86 return fSite.getShell(); 87 } else if (fShell != null) { 88 return fShell; 89 } else { 90 return JavaPlugin.getActiveWorkbenchShell(); 91 } 92 } 93 } 94 | Popular Tags |