1 11 package org.eclipse.team.internal.ui.wizards; 12 13 import java.util.*; 14 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.jface.dialogs.IDialogConstants; 17 import org.eclipse.jface.dialogs.TitleAreaDialog; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.viewers.*; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.events.ModifyEvent; 22 import org.eclipse.swt.events.ModifyListener; 23 import org.eclipse.swt.graphics.Image; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.layout.GridLayout; 26 import org.eclipse.swt.widgets.*; 27 import org.eclipse.team.internal.ui.TeamUIMessages; 28 import org.eclipse.team.internal.ui.TeamUIPlugin; 29 import org.eclipse.ui.IWorkingSet; 30 31 public class WorkingSetsDialog extends TitleAreaDialog { 32 33 protected TableViewer wsTableViewer; 34 protected Text wsNameText; 35 protected Image dlgTitleImage; 36 37 private String selectedWorkingSet; 38 39 public static final String resourceWorkingSetId = "org.eclipse.ui.resourceWorkingSetPage"; 41 public WorkingSetsDialog(Shell shell) { 42 super(shell); 43 setShellStyle(getShellStyle() | SWT.RESIZE); 44 } 45 46 protected Control createDialogArea(Composite parent) { 47 setTitle(TeamUIMessages.WorkingSetsDialog_Title); 48 setMessage(TeamUIMessages.WorkingSetsDialog_Message); 49 Composite composite = (Composite) super.createDialogArea(parent); 50 getShell().setText(TeamUIMessages.WorkingSetsDialog_TitleBar); 51 52 final Composite group = new Composite(composite, SWT.NONE); 53 GridLayout layout = new GridLayout(2, false); 54 layout.marginWidth = 0; 55 group.setLayout(layout); 56 group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); 57 58 final Label label = new Label(group, SWT.NONE); 59 label.setLayoutData(new GridData()); 60 label.setText(TeamUIMessages.WorkingSetsDialog_Label); 61 62 wsNameText = new Text(group, SWT.BORDER); 63 wsNameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); 64 65 layout = new GridLayout(); 66 layout.numColumns = 1; 67 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 68 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 69 composite.setLayout(layout); 70 final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); 71 composite.setLayoutData(data); 72 73 wsTableViewer = new TableViewer(composite, SWT.BORDER); 74 final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); 75 gd.widthHint = 450; 76 gd.heightHint = 250; 77 wsTableViewer.getTable().setLayoutData(gd); 78 79 wsTableViewer.setContentProvider(new ArrayContentProvider()); 80 wsTableViewer.setLabelProvider(new WorkingSetLabelProvider()); 81 wsTableViewer.setInput(TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager().getWorkingSets()); 82 83 setupListeners(); 84 85 return parent; 86 } 87 88 protected void okPressed() { 89 selectedWorkingSet = wsNameText.getText(); 90 91 if (selectedWorkingSet.equals("")) { setErrorMessage(TeamUIMessages.WorkingSetsDialog_ErrorMessage); 93 return; 94 } 95 96 super.okPressed(); 97 } 98 99 protected void cancelPressed() { 100 super.cancelPressed(); 101 } 102 103 public boolean close() { 104 if (dlgTitleImage != null) 105 dlgTitleImage.dispose(); 106 return super.close(); 107 } 108 109 void setupListeners() { 110 wsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { 111 public void selectionChanged(SelectionChangedEvent event) { 112 IStructuredSelection s = (IStructuredSelection) event.getSelection(); 113 Object obj = s.getFirstElement(); 114 if (obj instanceof IWorkingSet) 115 wsNameText.setText(((IWorkingSet) obj).getName()); 116 } 117 }); 118 119 wsNameText.addModifyListener(new ModifyListener() { 120 public void modifyText(ModifyEvent e) { 121 setErrorMessage(null); 122 } 123 }); 124 } 125 126 class WorkingSetLabelProvider extends LabelProvider { 127 private Map icons; 128 129 public WorkingSetLabelProvider() { 130 icons = new Hashtable(); 131 } 132 133 public void dispose() { 134 Iterator iterator = icons.values().iterator(); 135 136 while (iterator.hasNext()) { 137 Image icon = (Image) iterator.next(); 138 icon.dispose(); 139 } 140 super.dispose(); 141 } 142 143 public Image getImage(Object object) { 144 Assert.isTrue(object instanceof IWorkingSet); 145 IWorkingSet workingSet = (IWorkingSet) object; 146 ImageDescriptor imageDescriptor = workingSet.getImage(); 147 148 if (imageDescriptor == null) { 149 return null; 150 } 151 152 Image icon = (Image) icons.get(imageDescriptor); 153 if (icon == null) { 154 icon = imageDescriptor.createImage(); 155 icons.put(imageDescriptor, icon); 156 } 157 return icon; 158 } 159 160 public String getText(Object object) { 161 Assert.isTrue(object instanceof IWorkingSet); 162 IWorkingSet workingSet = (IWorkingSet) object; 163 return workingSet.getLabel(); 164 } 165 } 166 167 public String getSelectedWorkingSet(){ 168 return selectedWorkingSet; 169 } 170 } 171 | Popular Tags |