1 11 package org.eclipse.jdt.internal.ui.navigator; 12 13 import org.eclipse.swt.events.HelpListener; 14 import org.eclipse.swt.widgets.Event; 15 import org.eclipse.swt.widgets.Shell; 16 17 import org.eclipse.jface.action.IAction; 18 import org.eclipse.jface.action.IMenuCreator; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.jface.util.IPropertyChangeListener; 21 import org.eclipse.jface.viewers.ISelection; 22 import org.eclipse.jface.viewers.ISelectionProvider; 23 import org.eclipse.jface.viewers.IStructuredSelection; 24 import org.eclipse.jface.viewers.SelectionChangedEvent; 25 import org.eclipse.jface.viewers.TreeViewer; 26 27 import org.eclipse.jface.text.ITextSelection; 28 29 import org.eclipse.ui.IWorkbenchSite; 30 31 import org.eclipse.jdt.core.JavaModelException; 32 33 import org.eclipse.jdt.ui.actions.OpenAction; 34 import org.eclipse.jdt.ui.actions.SelectionDispatchAction; 35 36 import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection; 37 38 public class OpenAndExpand extends SelectionDispatchAction implements IAction { 39 40 private OpenAction fOpenAction; 41 private TreeViewer fViewer; 42 43 public OpenAndExpand(IWorkbenchSite site, OpenAction openAction, TreeViewer viewer) { 44 super(site); 45 fOpenAction = openAction; 46 fViewer = viewer; 47 } 48 49 public void run() { 50 fOpenAction.run(); 51 if(getSelection() != null && getSelection() instanceof IStructuredSelection) 52 expand(((IStructuredSelection)getSelection()).getFirstElement()); 53 54 } 55 56 public void run(ISelection selection) { 57 fOpenAction.run(selection); 58 if(selection != null && selection instanceof IStructuredSelection) 59 expand(((IStructuredSelection)selection).getFirstElement()); 60 } 61 62 public void run(IStructuredSelection selection) { 63 fOpenAction.run(selection); 64 if(selection != null) 65 expand(selection.getFirstElement()); 66 } 67 68 public void run(ITextSelection selection) { 69 fOpenAction.run(selection); 70 } 71 72 public void run(JavaTextSelection selection) { 73 fOpenAction.run(selection); 74 } 75 76 public void run(Object [] elements) { 77 fOpenAction.run(elements); 78 } 79 80 public void runWithEvent(Event event) { 81 fOpenAction.runWithEvent(event); 82 } 83 84 public void addPropertyChangeListener(IPropertyChangeListener listener) { 85 fOpenAction.addPropertyChangeListener(listener); 86 } 87 88 public boolean equals(Object obj) { 89 return fOpenAction.equals(obj); 90 } 91 92 public int getAccelerator() { 93 return fOpenAction.getAccelerator(); 94 } 95 96 public String getActionDefinitionId() { 97 return fOpenAction.getActionDefinitionId(); 98 } 99 100 public String getDescription() { 101 return fOpenAction.getDescription(); 102 } 103 104 public ImageDescriptor getDisabledImageDescriptor() { 105 return fOpenAction.getDisabledImageDescriptor(); 106 } 107 108 public Object getElementToOpen(Object object) throws JavaModelException { 109 return fOpenAction.getElementToOpen(object); 110 } 111 112 public HelpListener getHelpListener() { 113 return fOpenAction.getHelpListener(); 114 } 115 116 public ImageDescriptor getHoverImageDescriptor() { 117 return fOpenAction.getHoverImageDescriptor(); 118 } 119 120 public String getId() { 121 return fOpenAction.getId(); 122 } 123 124 public ImageDescriptor getImageDescriptor() { 125 return fOpenAction.getImageDescriptor(); 126 } 127 128 public IMenuCreator getMenuCreator() { 129 return fOpenAction.getMenuCreator(); 130 } 131 132 public ISelection getSelection() { 133 return fOpenAction.getSelection(); 134 } 135 136 public ISelectionProvider getSelectionProvider() { 137 return fOpenAction.getSelectionProvider(); 138 } 139 140 public Shell getShell() { 141 return fOpenAction.getShell(); 142 } 143 144 public IWorkbenchSite getSite() { 145 return fOpenAction.getSite(); 146 } 147 148 public int getStyle() { 149 return fOpenAction.getStyle(); 150 } 151 152 public String getText() { 153 return fOpenAction.getText(); 154 } 155 156 public String getToolTipText() { 157 return fOpenAction.getToolTipText(); 158 } 159 160 public int hashCode() { 161 return fOpenAction.hashCode(); 162 } 163 164 public boolean isChecked() { 165 return fOpenAction.isChecked(); 166 } 167 168 public boolean isEnabled() { 169 return fOpenAction.isEnabled(); 170 } 171 172 public boolean isHandled() { 173 return fOpenAction.isHandled(); 174 } 175 176 public void removePropertyChangeListener(IPropertyChangeListener listener) { 177 fOpenAction.removePropertyChangeListener(listener); 178 } 179 180 public void selectionChanged(ISelection selection) { 181 fOpenAction.selectionChanged(selection); 182 } 183 184 public void selectionChanged(IStructuredSelection selection) { 185 fOpenAction.selectionChanged(selection); 186 } 187 188 public void selectionChanged(ITextSelection selection) { 189 fOpenAction.selectionChanged(selection); 190 } 191 192 public void selectionChanged(JavaTextSelection selection) { 193 fOpenAction.selectionChanged(selection); 194 } 195 196 public void selectionChanged(SelectionChangedEvent event) { 197 fOpenAction.selectionChanged(event); 198 } 199 200 public void setAccelerator(int keycode) { 201 fOpenAction.setAccelerator(keycode); 202 } 203 204 public void setActionDefinitionId(String id) { 205 fOpenAction.setActionDefinitionId(id); 206 } 207 208 public void setChecked(boolean checked) { 209 fOpenAction.setChecked(checked); 210 } 211 212 public void setDescription(String text) { 213 fOpenAction.setDescription(text); 214 } 215 216 public void setDisabledImageDescriptor(ImageDescriptor newImage) { 217 fOpenAction.setDisabledImageDescriptor(newImage); 218 } 219 220 public void setEnabled(boolean enabled) { 221 fOpenAction.setEnabled(enabled); 222 } 223 224 public void setHelpListener(HelpListener listener) { 225 fOpenAction.setHelpListener(listener); 226 } 227 228 public void setHoverImageDescriptor(ImageDescriptor newImage) { 229 fOpenAction.setHoverImageDescriptor(newImage); 230 } 231 232 public void setId(String id) { 233 fOpenAction.setId(id); 234 } 235 236 public void setImageDescriptor(ImageDescriptor newImage) { 237 fOpenAction.setImageDescriptor(newImage); 238 } 239 240 public void setMenuCreator(IMenuCreator creator) { 241 fOpenAction.setMenuCreator(creator); 242 } 243 244 public void setSpecialSelectionProvider(ISelectionProvider provider) { 245 fOpenAction.setSpecialSelectionProvider(provider); 246 } 247 248 public void setText(String text) { 249 fOpenAction.setText(text); 250 } 251 252 public void setToolTipText(String toolTipText) { 253 fOpenAction.setToolTipText(toolTipText); 254 } 255 256 public String toString() { 257 return fOpenAction.toString(); 258 } 259 260 public void update(ISelection selection) { 261 fOpenAction.update(selection); 262 } 263 264 private void expand(Object target) { 265 if (! fOpenAction.isEnabled()) 266 fViewer.setExpandedState(target, !fViewer.getExpandedState(target)); 267 } 268 269 270 } 271 | Popular Tags |