1 11 package org.eclipse.pde.internal.ui.views.dependencies; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.jface.dialogs.StatusDialog; 19 import org.eclipse.jface.viewers.ISelection; 20 import org.eclipse.jface.viewers.ISelectionChangedListener; 21 import org.eclipse.jface.viewers.IStructuredContentProvider; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 import org.eclipse.jface.viewers.SelectionChangedEvent; 24 import org.eclipse.jface.viewers.StructuredSelection; 25 import org.eclipse.jface.viewers.TableViewer; 26 import org.eclipse.pde.internal.core.PDECore; 27 import org.eclipse.pde.internal.ui.IHelpContextIds; 28 import org.eclipse.pde.internal.ui.PDEUIMessages; 29 import org.eclipse.pde.internal.ui.elements.DefaultContentProvider; 30 import org.eclipse.pde.internal.ui.parts.StatusInfo; 31 import org.eclipse.pde.internal.ui.util.SWTUtil; 32 import org.eclipse.pde.internal.ui.wizards.ListUtil; 33 import org.eclipse.swt.SWT; 34 import org.eclipse.swt.events.DisposeEvent; 35 import org.eclipse.swt.events.DisposeListener; 36 import org.eclipse.swt.events.SelectionAdapter; 37 import org.eclipse.swt.events.SelectionEvent; 38 import org.eclipse.swt.layout.GridData; 39 import org.eclipse.swt.layout.GridLayout; 40 import org.eclipse.swt.widgets.Button; 41 import org.eclipse.swt.widgets.Composite; 42 import org.eclipse.swt.widgets.Control; 43 import org.eclipse.swt.widgets.Label; 44 import org.eclipse.swt.widgets.Shell; 45 import org.eclipse.swt.widgets.Table; 46 import org.eclipse.ui.PlatformUI; 47 48 public class HistoryListDialog extends StatusDialog { 49 class ContentProvider extends DefaultContentProvider implements 50 IStructuredContentProvider { 51 public Object [] getElements(Object element) { 52 return fHistoryList.toArray(); 53 } 54 } 55 56 private List fHistoryList = new ArrayList (); 57 58 private IStatus fHistoryStatus; 59 60 private TableViewer fHistoryViewer; 61 62 private Button fRemoveButton; 63 64 private String fResult; 65 66 public HistoryListDialog(Shell shell, String [] elements) { 67 super(shell); 68 setTitle(PDEUIMessages.HistoryListDialog_title); 69 fHistoryList.addAll(Arrays.asList(elements)); 70 } 71 72 75 protected void configureShell(Shell newShell) { 76 super.configureShell(newShell); 77 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IHelpContextIds.HISTORY_LIST_DIALOG); 78 } 79 80 85 public void create() { 86 setShellStyle(getShellStyle() | SWT.RESIZE); 87 super.create(); 88 } 89 90 93 protected Control createDialogArea(Composite parent) { 94 initializeDialogUnits(parent); 95 96 Composite composite = (Composite) super.createDialogArea(parent); 97 98 Composite inner = new Composite(composite, SWT.NONE); 99 GridLayout layout = new GridLayout(); 100 layout.marginWidth = 0; 101 layout.marginHeight = 0; 102 inner.setLayout(layout); 103 inner.setLayoutData(new GridData(GridData.FILL_BOTH)); 104 105 Label label = new Label(inner, SWT.NONE); 106 label.setText(PDEUIMessages.HistoryListDialog_label); 107 108 Composite container = createListArea(inner); 109 110 container.setLayoutData(new GridData(GridData.FILL_BOTH)); 111 112 applyDialogFont(composite); 113 return composite; 114 } 115 116 120 private Composite createListArea(Composite parent) { 121 Composite container = new Composite(parent, SWT.NONE); 122 GridLayout layout1 = new GridLayout(); 123 layout1.marginWidth = 0; 124 layout1.marginHeight = 0; 125 layout1.numColumns = 2; 126 container.setLayout(layout1); 127 container.setLayoutData(new GridData(GridData.FILL_BOTH)); 128 129 createTableArea(container); 130 createListButtons(container); 131 return container; 132 } 133 134 137 private void createListButtons(Composite parent) { 138 fRemoveButton = new Button(parent, SWT.PUSH); 139 fRemoveButton.setText(PDEUIMessages.HistoryListDialog_remove_button); 140 fRemoveButton.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, 141 false)); 142 SWTUtil.setButtonDimensionHint(fRemoveButton); 143 fRemoveButton.addSelectionListener(new SelectionAdapter() { 144 149 public void widgetSelected(SelectionEvent e) { 150 ISelection selection = fHistoryViewer.getSelection(); 151 if (!selection.isEmpty() 152 && selection instanceof IStructuredSelection) { 153 Object removalCandiate = ((IStructuredSelection) selection) 154 .getFirstElement(); 155 fHistoryList.remove(removalCandiate); 156 fHistoryViewer.remove(removalCandiate); 157 } 158 } 159 }); 160 } 161 162 166 private Control createTableArea(Composite parent) { 167 Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); 168 GridData gd = new GridData(GridData.FILL_BOTH); 169 gd.widthHint = 225; 170 gd.heightHint = 200; 171 table.setLayoutData(gd); 172 173 table.addSelectionListener(new SelectionAdapter() { 174 179 public void widgetDefaultSelected(SelectionEvent e) { 180 if (fHistoryStatus.isOK()) { 181 okPressed(); 182 } 183 } 184 }); 185 186 fHistoryViewer = new TableViewer(table); 187 final DependenciesLabelProvider labelProvider = new DependenciesLabelProvider( 188 false); 189 fHistoryViewer.setLabelProvider(labelProvider); 190 fHistoryViewer.getControl().addDisposeListener(new DisposeListener() { 191 public void widgetDisposed(DisposeEvent e) { 192 labelProvider.dispose(); 193 } 194 }); 195 fHistoryViewer.setContentProvider(new ContentProvider()); 196 fHistoryViewer.setInput(PDECore.getDefault().getModelManager()); 197 fHistoryViewer.setComparator(ListUtil.PLUGIN_COMPARATOR); 198 199 ISelection sel; 200 if (fHistoryList.size() > 0) { 201 sel = new StructuredSelection(fHistoryList.get(0)); 202 } else { 203 sel = new StructuredSelection(); 204 } 205 fHistoryViewer.setSelection(sel); 206 207 fHistoryViewer 208 .addSelectionChangedListener(new ISelectionChangedListener() { 209 214 public void selectionChanged(SelectionChangedEvent event) { 215 StatusInfo status = new StatusInfo(); 216 ISelection selection = fHistoryViewer.getSelection(); 217 if (selection instanceof IStructuredSelection) { 218 List selected = ((IStructuredSelection) selection) 219 .toList(); 220 if (selected.size() != 1) { 221 status.setError(""); fResult = null; 223 } else { 224 fResult = (String ) selected.get(0); 225 } 226 fRemoveButton 227 .setEnabled(fHistoryList.size() > selected 228 .size() 229 && selected.size() != 0); 230 fHistoryStatus = status; 231 updateStatus(status); 232 } 233 } 234 }); 235 return fHistoryViewer.getControl(); 236 } 237 238 public String [] getRemaining() { 239 return (String []) fHistoryList.toArray(new String [fHistoryList.size()]); 240 } 241 242 public String getResult() { 243 return fResult; 244 } 245 246 } 247 | Popular Tags |