1 11 12 package org.eclipse.ui.internal.actions; 13 14 import org.eclipse.core.runtime.Assert; 15 import org.eclipse.jface.action.Action; 16 import org.eclipse.jface.window.Window; 17 import org.eclipse.swt.widgets.Shell; 18 import org.eclipse.ui.IWorkingSet; 19 import org.eclipse.ui.IWorkingSetManager; 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.actions.WorkingSetFilterActionGroup; 22 import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog; 23 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 24 import org.eclipse.ui.internal.WorkbenchMessages; 25 26 32 public class SelectWorkingSetAction extends Action { 33 private Shell shell; 34 35 private WorkingSetFilterActionGroup actionGroup; 36 37 43 public SelectWorkingSetAction(WorkingSetFilterActionGroup actionGroup, 44 Shell shell) { 45 super(WorkbenchMessages.SelectWorkingSetAction_text); 46 Assert.isNotNull(actionGroup); 47 setToolTipText(WorkbenchMessages.SelectWorkingSetAction_toolTip); 48 49 this.shell = shell; 50 this.actionGroup = actionGroup; 51 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 52 IWorkbenchHelpContextIds.SELECT_WORKING_SET_ACTION); 53 } 54 55 60 public void run() { 61 IWorkingSetManager manager = PlatformUI.getWorkbench() 62 .getWorkingSetManager(); 63 IWorkingSetSelectionDialog dialog = manager 64 .createWorkingSetSelectionDialog(shell, false); 65 IWorkingSet workingSet = actionGroup.getWorkingSet(); 66 67 if (workingSet != null) { 68 dialog.setSelection(new IWorkingSet[] { workingSet }); 69 } 70 71 if (dialog.open() == Window.OK) { 72 IWorkingSet[] result = dialog.getSelection(); 73 if (result != null && result.length > 0) { 74 actionGroup.setWorkingSet(result[0]); 75 manager.addRecentWorkingSet(result[0]); 76 } else { 77 actionGroup.setWorkingSet(null); 78 } 79 } else { 80 actionGroup.setWorkingSet(workingSet); 81 } 82 } 83 } 84 | Popular Tags |