]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 IBM Corporation and others. | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * IBM Corporation - initial API and implementation | |
10 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.ui.refactoring; | |
12 | ||
13 | import java.lang.reflect.InvocationTargetException; | |
14 | import java.util.ArrayList; | |
15 | import java.util.Arrays; | |
16 | import java.util.HashMap; | |
17 | import java.util.Iterator; | |
18 | import java.util.List; | |
19 | import java.util.Map; | |
20 | ||
21 | import org.eclipse.swt.SWT; | |
22 | import org.eclipse.swt.events.SelectionAdapter; | |
23 | import org.eclipse.swt.events.SelectionEvent; | |
24 | import org.eclipse.swt.graphics.Image; | |
25 | import org.eclipse.swt.layout.GridData; | |
26 | import org.eclipse.swt.layout.GridLayout; | |
27 | import org.eclipse.swt.widgets.Button; | |
28 | import org.eclipse.swt.widgets.Composite; | |
29 | import org.eclipse.swt.widgets.Item; | |
30 | import org.eclipse.swt.widgets.Label; | |
31 | import org.eclipse.swt.widgets.Table; | |
32 | import org.eclipse.swt.widgets.TableColumn; | |
33 | ||
34 | import org.eclipse.core.runtime.Assert; | |
35 | import org.eclipse.core.runtime.IProgressMonitor; | |
36 | ||
37 | import org.eclipse.jface.dialogs.Dialog; | |
38 | import org.eclipse.jface.dialogs.IDialogConstants; | |
39 | import org.eclipse.jface.layout.PixelConverter; | |
40 | import org.eclipse.jface.operation.IRunnableWithProgress; | |
41 | import org.eclipse.jface.viewers.CellEditor; | |
42 | import org.eclipse.jface.viewers.CheckStateChangedEvent; | |
43 | import org.eclipse.jface.viewers.ColumnWeightData; | |
44 | import org.eclipse.jface.viewers.ComboBoxCellEditor; | |
45 | import org.eclipse.jface.viewers.DoubleClickEvent; | |
46 | import org.eclipse.jface.viewers.ICellModifier; | |
47 | import org.eclipse.jface.viewers.ICheckStateListener; | |
48 | import org.eclipse.jface.viewers.IDoubleClickListener; | |
49 | import org.eclipse.jface.viewers.ILabelProvider; | |
50 | import org.eclipse.jface.viewers.ISelection; | |
51 | import org.eclipse.jface.viewers.ISelectionChangedListener; | |
52 | import org.eclipse.jface.viewers.IStructuredSelection; | |
53 | import org.eclipse.jface.viewers.ITableLabelProvider; | |
54 | import org.eclipse.jface.viewers.LabelProvider; | |
55 | import org.eclipse.jface.viewers.SelectionChangedEvent; | |
56 | import org.eclipse.jface.viewers.TableLayout; | |
57 | import org.eclipse.jface.window.Window; | |
58 | ||
59 | import org.eclipse.ui.PlatformUI; | |
60 | ||
61 | import org.eclipse.ltk.core.refactoring.Refactoring; | |
62 | import org.eclipse.ltk.ui.refactoring.RefactoringWizard; | |
63 | import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; | |
64 | ||
65 | import org.eclipse.jdt.core.IMember; | |
66 | import org.eclipse.jdt.core.JavaModelException; | |
67 | ||
68 | import org.eclipse.jdt.internal.corext.refactoring.structure.PushDownRefactoringProcessor; | |
69 | import org.eclipse.jdt.internal.corext.refactoring.structure.PushDownRefactoringProcessor.MemberActionInfo; | |
70 | import org.eclipse.jdt.internal.corext.util.Messages; | |
71 | ||
72 | import org.eclipse.jdt.ui.JavaElementLabelProvider; | |
73 | import org.eclipse.jdt.ui.JavaElementLabels; | |
74 | ||
75 | import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; | |
76 | import org.eclipse.jdt.internal.ui.util.ExceptionHandler; | |
77 | import org.eclipse.jdt.internal.ui.util.SWTUtil; | |
78 | import org.eclipse.jdt.internal.ui.util.TableLayoutComposite; | |
79 | ||
80 | public final class PushDownWizard extends RefactoringWizard { | |
81 | ||
82 | private final PushDownRefactoringProcessor fProcessor; | |
83 | ||
84 | public static class PushDownInputPage extends UserInputWizardPage { | |
85 | ||
86 | public static class MemberActionInfoLabelProvider extends LabelProvider implements ITableLabelProvider { | |
87 | ||
88 | public static String getActionLabel(final int action) { | |
89 | switch (action) { | |
90 | case MemberActionInfo.NO_ACTION: | |
91 | return ""; //$NON-NLS-1$ | |
92 | case MemberActionInfo.PUSH_ABSTRACT_ACTION: | |
93 | return RefactoringMessages.PushDownInputPage_leave_abstract; | |
94 | case MemberActionInfo.PUSH_DOWN_ACTION: | |
95 | return RefactoringMessages.PushDownInputPage_push_down; | |
96 | default: | |
97 | Assert.isTrue(false); | |
98 | return null; | |
99 | } | |
100 | } | |
101 | ||
102 | public static String[] getAvailableActionLabels(final MemberActionInfo info) { | |
103 | final int[] actions= info.getAvailableActions(); | |
104 | final String[] result= new String[actions.length]; | |
105 | for (int index= 0; index < actions.length; index++) { | |
106 | result[index]= getActionLabel(actions[index]); | |
107 | } | |
108 | return result; | |
109 | } | |
110 | ||
111 | public final ILabelProvider fLabelProvider= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT | JavaElementLabelProvider.SHOW_SMALL_ICONS); | |
112 | ||
113 | @Override | |
114 | public void dispose() { | |
115 | fLabelProvider.dispose(); | |
116 | super.dispose(); | |
117 | } | |
118 | ||
119 | public Image getColumnImage(final Object element, final int index) { | |
120 | final MemberActionInfo info= (MemberActionInfo) element; | |
121 | switch (index) { | |
122 | case MEMBER_COLUMN: | |
123 | return fLabelProvider.getImage(info.getMember()); | |
124 | case ACTION_COLUMN: | |
125 | return null; | |
126 | default: | |
127 | Assert.isTrue(false); | |
128 | return null; | |
129 | } | |
130 | } | |
131 | ||
132 | public String getColumnText(final Object element, final int index) { | |
133 | final MemberActionInfo info= (MemberActionInfo) element; | |
134 | return info.generated_8560446215034864378(index, MemberActionInfoLabelProvider.this); | |
135 | } | |
136 | } | |
137 | ||
138 | private class PushDownCellModifier implements ICellModifier { | |
139 | ||
140 | public boolean canModify(final Object element, final String property) { | |
141 | if (!ACTION_PROPERTY.equals(property)) | |
142 | return false; | |
143 | return ((MemberActionInfo) element).isEditable(); | |
144 | } | |
145 | ||
146 | public Object getValue(final Object element, final String property) { | |
147 | if (!ACTION_PROPERTY.equals(property)) | |
148 | return null; | |
149 | ||
150 | final MemberActionInfo info= (MemberActionInfo) element; | |
151 | return new Integer(info.getAction()); | |
152 | } | |
153 | ||
154 | public void modify(final Object element, final String property, final Object value) { | |
155 | if (!ACTION_PROPERTY.equals(property)) | |
156 | return; | |
157 | ||
158 | final int action= ((Integer) value).intValue(); | |
159 | MemberActionInfo info; | |
160 | if (element instanceof Item) { | |
161 | info= (MemberActionInfo) ((Item) element).getData(); | |
162 | } else | |
163 | info= (MemberActionInfo) element; | |
164 | if (!canModify(info, property)) | |
165 | return; | |
166 | info.setAction(action); | |
167 | PushDownInputPage.this.updateWizardPage(null, true); | |
168 | } | |
169 | } | |
170 | ||
171 | public static final int ACTION_COLUMN= 1; | |
172 | ||
173 | private final static String ACTION_PROPERTY= "action"; //$NON-NLS-1$ | |
174 | ||
175 | public static final int MEMBER_COLUMN= 0; | |
176 | ||
177 | private final static String MEMBER_PROPERTY= "member"; //$NON-NLS-1$ | |
178 | ||
179 | private static final String PAGE_NAME= "PushDownInputPage"; //$NON-NLS-1$ | |
180 | ||
181 | private static final int ROW_COUNT= 10; | |
182 | ||
183 | private static int countEditableInfos(final MemberActionInfo[] infos) { | |
184 | int result= 0; | |
185 | for (int index= 0; index < infos.length; index++) { | |
186 | if (infos[index].isEditable()) | |
187 | result++; | |
188 | } | |
189 | return result; | |
190 | } | |
191 | ||
192 | private static void setInfoAction(final MemberActionInfo[] infos, final int action) { | |
193 | for (int index= 0; index < infos.length; index++) { | |
194 | infos[index].setAction(action); | |
195 | } | |
196 | } | |
197 | ||
198 | private Button fDeselectAllButton; | |
199 | ||
200 | private Button fEditButton; | |
201 | ||
202 | private Button fSelectAllButton; | |
203 | ||
204 | private Label fStatusLine; | |
205 | ||
206 | PullPushCheckboxTableViewer fTableViewer; | |
207 | ||
208 | private final PushDownRefactoringProcessor fProcessor; | |
209 | ||
210 | public PushDownInputPage(PushDownRefactoringProcessor processor) { | |
211 | super(PAGE_NAME); | |
212 | fProcessor= processor; | |
213 | } | |
214 | ||
215 | private boolean areAllElementsMarkedAsNoAction() { | |
216 | return countInfosForAction(MemberActionInfo.NO_ACTION) == ((MemberActionInfo[]) fTableViewer.getInput()).length; | |
217 | } | |
218 | ||
219 | private boolean areAllElementsMarkedAsPushDownAction() { | |
220 | return countInfosForAction(MemberActionInfo.PUSH_DOWN_ACTION) == ((MemberActionInfo[]) fTableViewer.getInput()).length; | |
221 | } | |
222 | ||
223 | void checkPageCompletionStatus(final boolean displayErrorMessage) { | |
224 | if (areAllElementsMarkedAsNoAction()) { | |
225 | if (displayErrorMessage) | |
226 | setErrorMessage(RefactoringMessages.PushDownInputPage_Select_members_to_push_down); | |
227 | setPageComplete(false); | |
228 | } else { | |
229 | setErrorMessage(null); | |
230 | setPageComplete(true); | |
231 | } | |
232 | } | |
233 | ||
234 | private int countInfosForAction(final int action) { | |
235 | final MemberActionInfo[] infos= (MemberActionInfo[]) fTableViewer.getInput(); | |
236 | int count= 0; | |
237 | for (int index= 0; index < infos.length; index++) { | |
238 | final MemberActionInfo info= infos[index]; | |
239 | if (info.getAction() == action) | |
240 | count++; | |
241 | } | |
242 | return count; | |
243 | } | |
244 | ||
245 | private void createButtonComposite(final Composite parent) { | |
246 | final Composite composite= new Composite(parent, SWT.NONE); | |
247 | composite.setLayoutData(new GridData(GridData.FILL_VERTICAL)); | |
248 | final GridLayout layout= new GridLayout(); | |
249 | layout.marginHeight= 0; | |
250 | layout.marginWidth= 0; | |
251 | composite.setLayout(layout); | |
252 | ||
253 | fSelectAllButton= new Button(composite, SWT.PUSH); | |
254 | fSelectAllButton.setText(RefactoringMessages.PullUpWizard_select_all_label); | |
255 | fSelectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
256 | fSelectAllButton.setEnabled(true); | |
257 | SWTUtil.setButtonDimensionHint(fSelectAllButton); | |
258 | fSelectAllButton.addSelectionListener(new SelectionAdapter() { | |
259 | ||
260 | @Override | |
261 | public void widgetSelected(final SelectionEvent event) { | |
262 | final IMember[] members= getMembers(); | |
263 | setActionForMembers(members, MemberActionInfo.PUSH_DOWN_ACTION); | |
264 | updateWizardPage(null, true); | |
265 | } | |
266 | }); | |
267 | ||
268 | fDeselectAllButton= new Button(composite, SWT.PUSH); | |
269 | fDeselectAllButton.setText(RefactoringMessages.PullUpWizard_deselect_all_label); | |
270 | fDeselectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
271 | fDeselectAllButton.setEnabled(false); | |
272 | SWTUtil.setButtonDimensionHint(fDeselectAllButton); | |
273 | fDeselectAllButton.addSelectionListener(new SelectionAdapter() { | |
274 | ||
275 | @Override | |
276 | public void widgetSelected(final SelectionEvent event) { | |
277 | final IMember[] members= getMembers(); | |
278 | setActionForMembers(members, MemberActionInfo.NO_ACTION); | |
279 | updateWizardPage(null, true); | |
280 | } | |
281 | }); | |
282 | ||
283 | fEditButton= new Button(composite, SWT.PUSH); | |
284 | fEditButton.setText(RefactoringMessages.PushDownInputPage_Edit); | |
285 | final GridData data= new GridData(GridData.FILL_HORIZONTAL); | |
286 | data.verticalIndent= new PixelConverter(parent).convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); | |
287 | fEditButton.setLayoutData(data); | |
288 | fEditButton.setEnabled(false); | |
289 | SWTUtil.setButtonDimensionHint(fEditButton); | |
290 | fEditButton.addSelectionListener(new SelectionAdapter() { | |
291 | ||
292 | @Override | |
293 | public void widgetSelected(final SelectionEvent event) { | |
294 | PushDownInputPage.this.editSelectedMembers(); | |
295 | } | |
296 | }); | |
297 | ||
298 | final Button addButton= new Button(composite, SWT.PUSH); | |
299 | addButton.setText(RefactoringMessages.PushDownInputPage_Add_Required); | |
300 | addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
301 | SWTUtil.setButtonDimensionHint(addButton); | |
302 | addButton.addSelectionListener(new SelectionAdapter() { | |
303 | ||
304 | @Override | |
305 | public void widgetSelected(final SelectionEvent event) { | |
306 | PushDownInputPage.this.markAdditionalRequiredMembersAsMembersToPushDown(); | |
307 | } | |
308 | }); | |
309 | } | |
310 | ||
311 | public void createControl(final Composite parent) { | |
312 | final Composite composite= new Composite(parent, SWT.NONE); | |
313 | composite.setLayout(new GridLayout()); | |
314 | ||
315 | createMemberTableLabel(composite); | |
316 | createMemberTableComposite(composite); | |
317 | createStatusLine(composite); | |
318 | ||
319 | setControl(composite); | |
320 | Dialog.applyDialogFont(composite); | |
321 | PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.PUSH_DOWN_WIZARD_PAGE); | |
322 | } | |
323 | ||
324 | private void createMemberTable(final Composite parent) { | |
325 | final TableLayoutComposite layouter= new TableLayoutComposite(parent, SWT.NONE); | |
326 | layouter.addColumnData(new ColumnWeightData(60, true)); | |
327 | layouter.addColumnData(new ColumnWeightData(40, true)); | |
328 | ||
329 | final Table table= new Table(layouter, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.CHECK); | |
330 | table.setHeaderVisible(true); | |
331 | table.setLinesVisible(true); | |
332 | ||
333 | final GridData data= new GridData(GridData.FILL_BOTH); | |
334 | data.heightHint= SWTUtil.getTableHeightHint(table, ROW_COUNT); | |
335 | data.widthHint= convertWidthInCharsToPixels(30); | |
336 | layouter.setLayoutData(data); | |
337 | ||
338 | final TableLayout layout= new TableLayout(); | |
339 | table.setLayout(layout); | |
340 | ||
341 | final TableColumn first= new TableColumn(table, SWT.NONE); | |
342 | first.setText(RefactoringMessages.PushDownInputPage_Member); | |
343 | ||
344 | final TableColumn second= new TableColumn(table, SWT.NONE); | |
345 | second.setText(RefactoringMessages.PushDownInputPage_Action); | |
346 | ||
347 | fTableViewer= new PullPushCheckboxTableViewer(table); | |
348 | fTableViewer.generated_1634911259932250120(); | |
349 | fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { | |
350 | ||
351 | public void selectionChanged(final SelectionChangedEvent event) { | |
352 | PushDownInputPage.this.updateButtonEnablementState((IStructuredSelection) event.getSelection()); | |
353 | } | |
354 | }); | |
355 | fTableViewer.addCheckStateListener(new ICheckStateListener() { | |
356 | ||
357 | public void checkStateChanged(final CheckStateChangedEvent event) { | |
358 | final boolean checked= event.getChecked(); | |
359 | final MemberActionInfo info= (MemberActionInfo) event.getElement(); | |
360 | if (checked) | |
361 | info.setAction(MemberActionInfo.PUSH_DOWN_ACTION); | |
362 | else | |
363 | info.setAction(MemberActionInfo.NO_ACTION); | |
364 | updateWizardPage(null, true); | |
365 | } | |
366 | }); | |
367 | fTableViewer.addDoubleClickListener(new IDoubleClickListener() { | |
368 | ||
369 | public void doubleClick(final DoubleClickEvent event) { | |
370 | PushDownInputPage.this.editSelectedMembers(); | |
371 | } | |
372 | }); | |
373 | ||
374 | fTableViewer.setInput(fProcessor.getMemberActionInfos()); | |
375 | updateWizardPage(null, false); | |
376 | setupCellEditors(table); | |
377 | } | |
378 | ||
379 | private void createMemberTableComposite(final Composite parent) { | |
380 | final Composite composite= new Composite(parent, SWT.NONE); | |
381 | composite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
382 | final GridLayout layout= new GridLayout(); | |
383 | layout.numColumns= 2; | |
384 | layout.marginWidth= 0; | |
385 | layout.marginHeight= 0; | |
386 | composite.setLayout(layout); | |
387 | ||
388 | createMemberTable(composite); | |
389 | createButtonComposite(composite); | |
390 | } | |
391 | ||
392 | private void createMemberTableLabel(final Composite parent) { | |
393 | final Label label= new Label(parent, SWT.NONE); | |
394 | label.setText(RefactoringMessages.PushDownInputPage_Specify_actions); | |
395 | label.setLayoutData(new GridData()); | |
396 | } | |
397 | ||
398 | private void createStatusLine(final Composite composite) { | |
399 | fStatusLine= new Label(composite, SWT.NONE); | |
400 | final GridData data= new GridData(SWT.FILL, SWT.CENTER, false, false); | |
401 | data.horizontalSpan= 2; | |
402 | updateStatusLine(); | |
403 | fStatusLine.setLayoutData(data); | |
404 | } | |
405 | ||
406 | // String -> Integer | |
407 | private Map<String, Integer> createStringMappingForSelectedElements() { | |
408 | final Map<String, Integer> result= new HashMap<String, Integer>(); | |
409 | int action= MemberActionInfo.PUSH_DOWN_ACTION; | |
410 | result.put(MemberActionInfoLabelProvider.getActionLabel(action), new Integer(action)); | |
411 | int action1= MemberActionInfo.PUSH_ABSTRACT_ACTION; | |
412 | result.put(MemberActionInfoLabelProvider.getActionLabel(action1), new Integer(action1)); | |
413 | return result; | |
414 | } | |
415 | ||
416 | private void editSelectedMembers() { | |
417 | if (!fEditButton.isEnabled()) | |
418 | return; | |
419 | final ISelection preserved= fTableViewer.getSelection(); | |
420 | try { | |
421 | MemberActionInfo[] selectedMembers= getSelectedMemberActionInfos(); | |
422 | final String labelText= selectedMembers.length == 1 ? Messages.format(RefactoringMessages.PushDownInputPage_Mark_selected_members_singular, JavaElementLabels.getElementLabel( | |
423 | selectedMembers[0].getMember(), JavaElementLabels.M_PARAMETER_TYPES)) : Messages.format(RefactoringMessages.PushDownInputPage_Mark_selected_members_plural, String | |
424 | .valueOf(selectedMembers.length)); | |
425 | final Map<String, Integer> stringMapping= createStringMappingForSelectedElements(); | |
426 | final String[] keys= stringMapping.keySet().toArray(new String[stringMapping.keySet().size()]); | |
427 | Arrays.sort(keys); | |
428 | final int initialSelectionIndex= getInitialSelectionIndexForEditDialog(stringMapping, keys); | |
429 | ||
430 | final ComboSelectionDialog dialog= new ComboSelectionDialog(getShell(), RefactoringMessages.PushDownInputPage_Edit_members, labelText, keys, initialSelectionIndex); | |
431 | dialog.setBlockOnOpen(true); | |
432 | if (dialog.open() == Window.CANCEL) | |
433 | return; | |
434 | final int action= stringMapping.get(dialog.getSelectedString()).intValue(); | |
435 | setInfoAction(selectedMembers, action); | |
436 | } finally { | |
437 | updateWizardPage(preserved, true); | |
438 | } | |
439 | } | |
440 | ||
441 | private boolean enableEditButton(final IStructuredSelection selection) { | |
442 | if (selection.isEmpty() || selection.size() == 0) | |
443 | return false; | |
444 | return selection.size() == countEditableInfos(getSelectedMemberActionInfos()); | |
445 | } | |
446 | ||
447 | MemberActionInfo[] getActiveInfos() { | |
448 | final MemberActionInfo[] infos= fProcessor.getMemberActionInfos(); | |
449 | final List<MemberActionInfo> result= new ArrayList<MemberActionInfo>(infos.length); | |
450 | for (int index= 0; index < infos.length; index++) { | |
451 | final MemberActionInfo info= infos[index]; | |
452 | info.generated_1100016762981330739(result); | |
453 | } | |
454 | return result.toArray(new MemberActionInfo[result.size()]); | |
455 | } | |
456 | ||
457 | private int getCommonActionCodeForSelectedInfos() { | |
458 | final MemberActionInfo[] infos= getSelectedMemberActionInfos(); | |
459 | if (infos.length == 0) | |
460 | return -1; | |
461 | ||
462 | final int code= infos[0].getAction(); | |
463 | for (int index= 0; index < infos.length; index++) { | |
464 | if (code != infos[index].getAction()) | |
465 | return -1; | |
466 | } | |
467 | return code; | |
468 | } | |
469 | ||
470 | private int getInitialSelectionIndexForEditDialog(final Map<String, Integer> mapping, final String[] keys) { | |
471 | final int commonActionCode= getCommonActionCodeForSelectedInfos(); | |
472 | if (commonActionCode == -1) | |
473 | return 0; | |
474 | for (final Iterator<String> iterator= mapping.keySet().iterator(); iterator.hasNext();) { | |
475 | final String key= iterator.next(); | |
476 | final int action= mapping.get(key).intValue(); | |
477 | if (commonActionCode == action) { | |
478 | for (int index= 0; index < keys.length; index++) { | |
479 | if (key.equals(keys[index])) | |
480 | return index; | |
481 | } | |
482 | Assert.isTrue(false);// there's no way | |
483 | } | |
484 | } | |
485 | return 0; | |
486 | } | |
487 | ||
488 | private IMember[] getMembers() { | |
489 | final MemberActionInfo[] infos= (MemberActionInfo[]) fTableViewer.getInput(); | |
490 | final List<IMember> result= new ArrayList<IMember>(infos.length); | |
491 | for (int index= 0; index < infos.length; index++) { | |
492 | result.add(infos[index].getMember()); | |
493 | } | |
494 | return result.toArray(new IMember[result.size()]); | |
495 | } | |
496 | ||
497 | private MemberActionInfo[] getSelectedMemberActionInfos() { | |
498 | final List<?> result= fTableViewer.generated_958426737991695877(); | |
499 | return result.toArray(new MemberActionInfo[result.size()]); | |
500 | } | |
501 | ||
502 | public void markAdditionalRequiredMembersAsMembersToPushDown() { | |
503 | try { | |
504 | PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(false, false, new IRunnableWithProgress() { | |
505 | ||
506 | public void run(final IProgressMonitor pm) throws InvocationTargetException { | |
507 | try { | |
508 | fProcessor.computeAdditionalRequiredMembersToPushDown(pm); | |
509 | updateWizardPage(null, true); | |
510 | } catch (final JavaModelException e) { | |
511 | throw new InvocationTargetException(e); | |
512 | } finally { | |
513 | pm.done(); | |
514 | } | |
515 | } | |
516 | }); | |
517 | } catch (final InvocationTargetException e) { | |
518 | ExceptionHandler.handle(e, getShell(), RefactoringMessages.PushDownInputPage_Push_Down, RefactoringMessages.PushDownInputPage_Internal_Error); | |
519 | } catch (final InterruptedException e) { | |
520 | Assert.isTrue(false);// not cancelable | |
521 | } | |
522 | } | |
523 | ||
524 | private void setActionForMembers(final IMember[] members, final int action) { | |
525 | final MemberActionInfo[] infos= (MemberActionInfo[]) fTableViewer.getInput(); | |
526 | for (int offset= 0; offset < members.length; offset++) { | |
527 | for (int index= 0; index < infos.length; index++) { | |
528 | if (infos[index].getMember().equals(members[offset])) | |
529 | infos[index].setAction(action); | |
530 | } | |
531 | } | |
532 | } | |
533 | ||
534 | private void setupCellEditors(final Table table) { | |
535 | final ComboBoxCellEditor comboBoxCellEditor= new ComboBoxCellEditor(); | |
536 | comboBoxCellEditor.setStyle(SWT.READ_ONLY); | |
537 | fTableViewer.setCellEditors(new CellEditor[] { null, comboBoxCellEditor}); | |
538 | fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { | |
539 | ||
540 | public void selectionChanged(final SelectionChangedEvent event) { | |
541 | if (comboBoxCellEditor.getControl() == null & !table.isDisposed()) | |
542 | comboBoxCellEditor.create(table); | |
543 | Assert.isTrue(event.getSelection() instanceof IStructuredSelection); | |
544 | final IStructuredSelection ss= (IStructuredSelection) event.getSelection(); | |
545 | if (ss.size() != 1) | |
546 | return; | |
547 | final MemberActionInfo mac= (MemberActionInfo) ss.getFirstElement(); | |
548 | mac.generated_5439817953403860788(comboBoxCellEditor); | |
549 | } | |
550 | }); | |
551 | ||
552 | final ICellModifier cellModifier= new PushDownCellModifier(); | |
553 | fTableViewer.setCellModifier(cellModifier); | |
554 | fTableViewer.setColumnProperties(new String[] { MEMBER_PROPERTY, ACTION_PROPERTY}); | |
555 | } | |
556 | ||
557 | @Override | |
558 | public void setVisible(final boolean visible) { | |
559 | super.setVisible(visible); | |
560 | if (visible) { | |
561 | fTableViewer.generated_7905926537400450197(this); | |
562 | } | |
563 | } | |
564 | ||
565 | void updateButtonEnablementState(final IStructuredSelection tableSelection) { | |
566 | if (tableSelection == null || fEditButton == null) | |
567 | return; | |
568 | fEditButton.setEnabled(enableEditButton(tableSelection)); | |
569 | if (fSelectAllButton != null) | |
570 | fSelectAllButton.setEnabled(!areAllElementsMarkedAsPushDownAction()); | |
571 | if (fDeselectAllButton != null) | |
572 | fDeselectAllButton.setEnabled(!areAllElementsMarkedAsNoAction()); | |
573 | } | |
574 | ||
575 | private void updateStatusLine() { | |
576 | if (fStatusLine == null) | |
577 | return; | |
578 | Object[] selectedMembers= fTableViewer.getCheckedElements(); | |
579 | final int selected= selectedMembers.length; | |
580 | final String msg= selected == 1 ? Messages.format(RefactoringMessages.PushDownInputPage_status_line_singular, JavaElementLabels.getElementLabel( | |
581 | ((MemberActionInfo)selectedMembers[0]).getMember(), JavaElementLabels.M_PARAMETER_TYPES)) : Messages.format(RefactoringMessages.PushDownInputPage_status_line_plural, String | |
582 | .valueOf(selected)); | |
583 | fStatusLine.setText(msg); | |
584 | } | |
585 | ||
586 | private void updateWizardPage(final ISelection preserved, final boolean displayErrorMessage) { | |
587 | fTableViewer.generated_6676435898273622646(this, preserved, displayErrorMessage); | |
588 | updateStatusLine(); | |
589 | } | |
590 | } | |
591 | ||
592 | public PushDownWizard(PushDownRefactoringProcessor processor, Refactoring ref) { | |
593 | super(ref, DIALOG_BASED_USER_INTERFACE); | |
594 | fProcessor= processor; | |
595 | setDefaultPageTitle(RefactoringMessages.PushDownWizard_defaultPageTitle); | |
596 | } | |
597 | ||
598 | @Override | |
599 | protected void addUserInputPages() { | |
600 | addPage(new PushDownInputPage(fProcessor)); | |
601 | } | |
602 | } |