1 12 package org.eclipse.jdt.internal.ui.callhierarchy; 13 14 import java.util.Arrays ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.IStatus; 18 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.layout.GridData; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Control; 23 import org.eclipse.swt.widgets.Shell; 24 25 import org.eclipse.jface.action.Action; 26 import org.eclipse.jface.dialogs.StatusDialog; 27 import org.eclipse.jface.viewers.ISelection; 28 import org.eclipse.jface.viewers.StructuredSelection; 29 import org.eclipse.jface.window.Window; 30 31 import org.eclipse.ui.PlatformUI; 32 33 import org.eclipse.jdt.core.IMethod; 34 35 import org.eclipse.jdt.ui.JavaElementLabelProvider; 36 37 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 38 import org.eclipse.jdt.internal.ui.JavaPlugin; 39 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; 40 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; 41 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter; 42 import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil; 43 import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField; 44 45 public class HistoryListAction extends Action { 46 47 private class HistoryListDialog extends StatusDialog { 48 49 private ListDialogField fHistoryList; 50 private IStatus fHistoryStatus; 51 private IMethod fResult; 52 53 private HistoryListDialog(Shell shell, IMethod[] elements) { 54 super(shell); 55 setTitle(CallHierarchyMessages.HistoryListDialog_title); 56 57 String [] buttonLabels= new String [] { 58 CallHierarchyMessages.HistoryListDialog_remove_button, 59 }; 60 61 IListAdapter adapter= new IListAdapter() { 62 public void customButtonPressed(ListDialogField field, int index) { 63 doCustomButtonPressed(); 64 } 65 public void selectionChanged(ListDialogField field) { 66 doSelectionChanged(); 67 } 68 69 public void doubleClicked(ListDialogField field) { 70 doDoubleClicked(); 71 } 72 }; 73 74 JavaElementLabelProvider labelProvider= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_QUALIFIED | JavaElementLabelProvider.SHOW_ROOT); 75 76 fHistoryList= new ListDialogField(adapter, buttonLabels, labelProvider); 77 fHistoryList.setLabelText(CallHierarchyMessages.HistoryListDialog_label); 78 fHistoryList.setElements(Arrays.asList(elements)); 79 80 ISelection sel; 81 if (elements.length > 0) { 82 sel= new StructuredSelection(elements[0]); 83 } else { 84 sel= new StructuredSelection(); 85 } 86 87 fHistoryList.selectElements(sel); 88 } 89 90 91 94 protected Control createDialogArea(Composite parent) { 95 initializeDialogUnits(parent); 96 97 Composite composite= (Composite) super.createDialogArea(parent); 98 99 Composite inner= new Composite(composite, SWT.NONE); 100 inner.setLayoutData(new GridData(GridData.FILL_BOTH)); 101 inner.setFont(composite.getFont()); 102 103 LayoutUtil.doDefaultLayout(inner, new DialogField[] { fHistoryList }, true, 0, 0); 104 LayoutUtil.setHeightHint(fHistoryList.getListControl(null), convertHeightInCharsToPixels(12)); 105 LayoutUtil.setHorizontalGrabbing(fHistoryList.getListControl(null)); 106 107 applyDialogFont(composite); 108 return composite; 109 } 110 111 114 private void doCustomButtonPressed() { 115 fHistoryList.removeElements(fHistoryList.getSelectedElements()); 116 } 117 118 private void doDoubleClicked() { 119 if (fHistoryStatus.isOK()) { 120 okPressed(); 121 } 122 } 123 124 125 private void doSelectionChanged() { 126 StatusInfo status= new StatusInfo(); 127 List selected= fHistoryList.getSelectedElements(); 128 if (selected.size() != 1) { 129 status.setError(""); fResult= null; 131 } else { 132 fResult= (IMethod) selected.get(0); 133 } 134 fHistoryList.enableButton(0, fHistoryList.getSize() > selected.size() && selected.size() != 0); 135 fHistoryStatus= status; 136 updateStatus(status); 137 } 138 139 public IMethod getResult() { 140 return fResult; 141 } 142 143 public IMethod[] getRemaining() { 144 List elems= fHistoryList.getElements(); 145 return (IMethod[]) elems.toArray(new IMethod[elems.size()]); 146 } 147 148 151 protected void configureShell(Shell newShell) { 152 super.configureShell(newShell); 153 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.HISTORY_LIST_DIALOG); 154 } 155 156 159 public void create() { 160 setShellStyle(getShellStyle() | SWT.RESIZE); 161 super.create(); 162 } 163 164 } 165 166 private CallHierarchyViewPart fView; 167 168 public HistoryListAction(CallHierarchyViewPart view) { 169 fView= view; 170 setText(CallHierarchyMessages.HistoryListAction_label); 171 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.HISTORY_LIST_ACTION); 172 } 173 174 177 public void run() { 178 IMethod[] historyEntries= fView.getHistoryEntries(); 179 HistoryListDialog dialog= new HistoryListDialog(JavaPlugin.getActiveWorkbenchShell(), historyEntries); 180 if (dialog.open() == Window.OK) { 181 fView.setHistoryEntries(dialog.getRemaining()); 182 fView.setMethod(dialog.getResult()); 183 } 184 } 185 186 } 187 188 | Popular Tags |