1 11 package org.eclipse.jdt.internal.ui.workingsets; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.events.SelectionAdapter; 17 import org.eclipse.swt.events.SelectionEvent; 18 import org.eclipse.swt.graphics.Image; 19 import org.eclipse.swt.widgets.Menu; 20 import org.eclipse.swt.widgets.MenuItem; 21 22 import org.eclipse.jface.action.ContributionItem; 23 import org.eclipse.jface.resource.ImageDescriptor; 24 25 import org.eclipse.ui.IWorkingSet; 26 import org.eclipse.ui.IWorkingSetManager; 27 import org.eclipse.ui.PlatformUI; 28 29 34 public class WorkingSetMenuContributionItem extends ContributionItem { 35 36 private int fId; 37 private IWorkingSet fWorkingSet; 38 private WorkingSetFilterActionGroup fActionGroup; 39 private Image fImage; 40 41 48 public WorkingSetMenuContributionItem(int id, WorkingSetFilterActionGroup actionGroup, IWorkingSet workingSet) { 49 super(getId(id)); 50 Assert.isNotNull(actionGroup); 51 Assert.isNotNull(workingSet); 52 fId= id; 53 fActionGroup= actionGroup; 54 fWorkingSet= workingSet; 55 } 56 57 60 public void fill(Menu menu, int index) { 61 MenuItem mi= new MenuItem(menu, SWT.RADIO, index); 62 63 String name= fWorkingSet.getLabel(); 64 65 mi.setText("&" + fId + " " + name); if (fImage == null) { 67 ImageDescriptor imageDescriptor= fWorkingSet.getImage(); 68 if (imageDescriptor != null) 69 fImage= imageDescriptor.createImage(); 70 } 71 mi.setImage(fImage); 72 mi.setSelection(fWorkingSet.equals(fActionGroup.getWorkingSet())); 73 mi.addSelectionListener(new SelectionAdapter() { 74 public void widgetSelected(SelectionEvent e) { 75 IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager(); 76 fActionGroup.setWorkingSet(fWorkingSet, true); 77 manager.addRecentWorkingSet(fWorkingSet); 78 } 79 }); 80 } 81 82 86 public void dispose() { 87 if (fImage != null && !fImage.isDisposed()) 88 fImage.dispose(); 89 fImage= null; 90 91 super.dispose(); 92 } 93 94 97 public boolean isDynamic() { 98 return true; 99 } 100 101 static String getId(int id) { 102 return WorkingSetMenuContributionItem.class.getName() + "." + id; } 104 } 105 | Popular Tags |