Source Code Cross Referenced for PushDownWizard.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » refactoring » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » jdt » org.eclipse.jdt.internal.ui.refactoring 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.ui.refactoring;
011:
012:        import java.lang.reflect.InvocationTargetException;
013:        import java.util.ArrayList;
014:        import java.util.Arrays;
015:        import java.util.HashMap;
016:        import java.util.Iterator;
017:        import java.util.List;
018:        import java.util.Map;
019:
020:        import org.eclipse.core.runtime.Assert;
021:        import org.eclipse.core.runtime.IProgressMonitor;
022:
023:        import org.eclipse.swt.SWT;
024:        import org.eclipse.swt.events.SelectionAdapter;
025:        import org.eclipse.swt.events.SelectionEvent;
026:        import org.eclipse.swt.graphics.Image;
027:        import org.eclipse.swt.layout.GridData;
028:        import org.eclipse.swt.layout.GridLayout;
029:        import org.eclipse.swt.widgets.Button;
030:        import org.eclipse.swt.widgets.Composite;
031:        import org.eclipse.swt.widgets.Item;
032:        import org.eclipse.swt.widgets.Label;
033:        import org.eclipse.swt.widgets.Table;
034:        import org.eclipse.swt.widgets.TableColumn;
035:
036:        import org.eclipse.jface.dialogs.Dialog;
037:        import org.eclipse.jface.dialogs.IDialogConstants;
038:        import org.eclipse.jface.operation.IRunnableWithProgress;
039:        import org.eclipse.jface.viewers.ArrayContentProvider;
040:        import org.eclipse.jface.viewers.CellEditor;
041:        import org.eclipse.jface.viewers.CheckStateChangedEvent;
042:        import org.eclipse.jface.viewers.ColumnWeightData;
043:        import org.eclipse.jface.viewers.ComboBoxCellEditor;
044:        import org.eclipse.jface.viewers.DoubleClickEvent;
045:        import org.eclipse.jface.viewers.ICellModifier;
046:        import org.eclipse.jface.viewers.ICheckStateListener;
047:        import org.eclipse.jface.viewers.IDoubleClickListener;
048:        import org.eclipse.jface.viewers.ILabelProvider;
049:        import org.eclipse.jface.viewers.ISelection;
050:        import org.eclipse.jface.viewers.ISelectionChangedListener;
051:        import org.eclipse.jface.viewers.IStructuredSelection;
052:        import org.eclipse.jface.viewers.ITableLabelProvider;
053:        import org.eclipse.jface.viewers.LabelProvider;
054:        import org.eclipse.jface.viewers.SelectionChangedEvent;
055:        import org.eclipse.jface.viewers.StructuredSelection;
056:        import org.eclipse.jface.viewers.TableLayout;
057:        import org.eclipse.jface.window.Window;
058:
059:        import org.eclipse.ui.PlatformUI;
060:
061:        import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
062:        import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
063:
064:        import org.eclipse.jdt.core.IMember;
065:        import org.eclipse.jdt.core.JavaModelException;
066:
067:        import org.eclipse.jdt.internal.corext.refactoring.structure.PushDownRefactoring;
068:        import org.eclipse.jdt.internal.corext.refactoring.structure.PushDownRefactoringProcessor.MemberActionInfo;
069:        import org.eclipse.jdt.internal.corext.util.Messages;
070:
071:        import org.eclipse.jdt.ui.JavaElementLabelProvider;
072:
073:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
074:        import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
075:        import org.eclipse.jdt.internal.ui.util.PixelConverter;
076:        import org.eclipse.jdt.internal.ui.util.SWTUtil;
077:        import org.eclipse.jdt.internal.ui.util.TableLayoutComposite;
078:
079:        public final class PushDownWizard extends RefactoringWizard {
080:
081:            private static class PushDownInputPage extends UserInputWizardPage {
082:
083:                private static class MemberActionInfoLabelProvider extends
084:                        LabelProvider implements  ITableLabelProvider {
085:
086:                    private static String getActionLabel(final int action) {
087:                        switch (action) {
088:                        case MemberActionInfo.NO_ACTION:
089:                            return ""; //$NON-NLS-1$
090:                        case MemberActionInfo.PUSH_ABSTRACT_ACTION:
091:                            return RefactoringMessages.PushDownInputPage_leave_abstract;
092:                        case MemberActionInfo.PUSH_DOWN_ACTION:
093:                            return RefactoringMessages.PushDownInputPage_push_down;
094:                        default:
095:                            Assert.isTrue(false);
096:                            return null;
097:                        }
098:                    }
099:
100:                    private static String[] getAvailableActionLabels(
101:                            final MemberActionInfo info) {
102:                        final int[] actions = info.getAvailableActions();
103:                        final String[] result = new String[actions.length];
104:                        for (int index = 0; index < actions.length; index++) {
105:                            result[index] = getActionLabel(actions[index]);
106:                        }
107:                        return result;
108:                    }
109:
110:                    private final ILabelProvider fLabelProvider = new JavaElementLabelProvider(
111:                            JavaElementLabelProvider.SHOW_DEFAULT
112:                                    | JavaElementLabelProvider.SHOW_SMALL_ICONS);
113:
114:                    public void dispose() {
115:                        fLabelProvider.dispose();
116:                        super .dispose();
117:                    }
118:
119:                    public Image getColumnImage(final Object element,
120:                            final int index) {
121:                        final MemberActionInfo info = (MemberActionInfo) element;
122:                        switch (index) {
123:                        case MEMBER_COLUMN:
124:                            return fLabelProvider.getImage(info.getMember());
125:                        case ACTION_COLUMN:
126:                            return null;
127:                        default:
128:                            Assert.isTrue(false);
129:                            return null;
130:                        }
131:                    }
132:
133:                    public String getColumnText(final Object element,
134:                            final int index) {
135:                        final MemberActionInfo info = (MemberActionInfo) element;
136:                        switch (index) {
137:                        case MEMBER_COLUMN:
138:                            return fLabelProvider.getText(info.getMember());
139:                        case ACTION_COLUMN:
140:                            return getActionLabel(info.getAction());
141:                        default:
142:                            Assert.isTrue(false);
143:                            return null;
144:                        }
145:                    }
146:                }
147:
148:                private class PushDownCellModifier implements  ICellModifier {
149:
150:                    public boolean canModify(final Object element,
151:                            final String property) {
152:                        if (!ACTION_PROPERTY.equals(property))
153:                            return false;
154:                        return ((MemberActionInfo) element).isEditable();
155:                    }
156:
157:                    public Object getValue(final Object element,
158:                            final String property) {
159:                        if (!ACTION_PROPERTY.equals(property))
160:                            return null;
161:
162:                        final MemberActionInfo info = (MemberActionInfo) element;
163:                        return new Integer(info.getAction());
164:                    }
165:
166:                    public void modify(final Object element,
167:                            final String property, final Object value) {
168:                        if (!ACTION_PROPERTY.equals(property))
169:                            return;
170:
171:                        final int action = ((Integer) value).intValue();
172:                        MemberActionInfo info;
173:                        if (element instanceof  Item) {
174:                            info = (MemberActionInfo) ((Item) element)
175:                                    .getData();
176:                        } else
177:                            info = (MemberActionInfo) element;
178:                        if (!canModify(info, property))
179:                            return;
180:                        info.setAction(action);
181:                        PushDownInputPage.this .updateWizardPage(null, true);
182:                    }
183:                }
184:
185:                private static final int ACTION_COLUMN = 1;
186:
187:                private final static String ACTION_PROPERTY = "action"; //$NON-NLS-1$	
188:
189:                private static final int MEMBER_COLUMN = 0;
190:
191:                private final static String MEMBER_PROPERTY = "member"; //$NON-NLS-1$	
192:
193:                private static final String PAGE_NAME = "PushDownInputPage"; //$NON-NLS-1$
194:
195:                private static final int ROW_COUNT = 10;
196:
197:                private static int countEditableInfos(
198:                        final MemberActionInfo[] infos) {
199:                    int result = 0;
200:                    for (int index = 0; index < infos.length; index++) {
201:                        if (infos[index].isEditable())
202:                            result++;
203:                    }
204:                    return result;
205:                }
206:
207:                private static void setInfoAction(
208:                        final MemberActionInfo[] infos, final int action) {
209:                    for (int index = 0; index < infos.length; index++) {
210:                        infos[index].setAction(action);
211:                    }
212:                }
213:
214:                private Button fDeselectAllButton;
215:
216:                private Button fEditButton;
217:
218:                private Button fSelectAllButton;
219:
220:                private Label fStatusLine;
221:
222:                private PullPushCheckboxTableViewer fTableViewer;
223:
224:                public PushDownInputPage() {
225:                    super (PAGE_NAME);
226:                }
227:
228:                private boolean areAllElementsMarkedAsNoAction() {
229:                    return countInfosForAction(MemberActionInfo.NO_ACTION) == ((MemberActionInfo[]) fTableViewer
230:                            .getInput()).length;
231:                }
232:
233:                private boolean areAllElementsMarkedAsPushDownAction() {
234:                    return countInfosForAction(MemberActionInfo.PUSH_DOWN_ACTION) == ((MemberActionInfo[]) fTableViewer
235:                            .getInput()).length;
236:                }
237:
238:                private void checkPageCompletionStatus(
239:                        final boolean displayErrorMessage) {
240:                    if (areAllElementsMarkedAsNoAction()) {
241:                        if (displayErrorMessage)
242:                            setErrorMessage(RefactoringMessages.PushDownInputPage_Select_members_to_push_down);
243:                        setPageComplete(false);
244:                    } else {
245:                        setErrorMessage(null);
246:                        setPageComplete(true);
247:                    }
248:                }
249:
250:                private int countInfosForAction(final int action) {
251:                    final MemberActionInfo[] infos = (MemberActionInfo[]) fTableViewer
252:                            .getInput();
253:                    int count = 0;
254:                    for (int index = 0; index < infos.length; index++) {
255:                        final MemberActionInfo info = infos[index];
256:                        if (info.getAction() == action)
257:                            count++;
258:                    }
259:                    return count;
260:                }
261:
262:                private void createButtonComposite(final Composite parent) {
263:                    final Composite composite = new Composite(parent, SWT.NONE);
264:                    composite
265:                            .setLayoutData(new GridData(GridData.FILL_VERTICAL));
266:                    final GridLayout layout = new GridLayout();
267:                    layout.marginHeight = 0;
268:                    layout.marginWidth = 0;
269:                    composite.setLayout(layout);
270:
271:                    fSelectAllButton = new Button(composite, SWT.PUSH);
272:                    fSelectAllButton
273:                            .setText(RefactoringMessages.PullUpWizard_select_all_label);
274:                    fSelectAllButton.setLayoutData(new GridData(
275:                            GridData.FILL_HORIZONTAL));
276:                    fSelectAllButton.setEnabled(true);
277:                    SWTUtil.setButtonDimensionHint(fSelectAllButton);
278:                    fSelectAllButton
279:                            .addSelectionListener(new SelectionAdapter() {
280:
281:                                public void widgetSelected(
282:                                        final SelectionEvent event) {
283:                                    final IMember[] members = getMembers();
284:                                    setActionForMembers(members,
285:                                            MemberActionInfo.PUSH_DOWN_ACTION);
286:                                    updateWizardPage(null, true);
287:                                }
288:                            });
289:
290:                    fDeselectAllButton = new Button(composite, SWT.PUSH);
291:                    fDeselectAllButton
292:                            .setText(RefactoringMessages.PullUpWizard_deselect_all_label);
293:                    fDeselectAllButton.setLayoutData(new GridData(
294:                            GridData.FILL_HORIZONTAL));
295:                    fDeselectAllButton.setEnabled(false);
296:                    SWTUtil.setButtonDimensionHint(fDeselectAllButton);
297:                    fDeselectAllButton
298:                            .addSelectionListener(new SelectionAdapter() {
299:
300:                                public void widgetSelected(
301:                                        final SelectionEvent event) {
302:                                    final IMember[] members = getMembers();
303:                                    setActionForMembers(members,
304:                                            MemberActionInfo.NO_ACTION);
305:                                    updateWizardPage(null, true);
306:                                }
307:                            });
308:
309:                    fEditButton = new Button(composite, SWT.PUSH);
310:                    fEditButton
311:                            .setText(RefactoringMessages.PushDownInputPage_Edit);
312:                    final GridData data = new GridData(GridData.FILL_HORIZONTAL);
313:                    data.verticalIndent = new PixelConverter(parent)
314:                            .convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
315:                    fEditButton.setLayoutData(data);
316:                    fEditButton.setEnabled(false);
317:                    SWTUtil.setButtonDimensionHint(fEditButton);
318:                    fEditButton.addSelectionListener(new SelectionAdapter() {
319:
320:                        public void widgetSelected(final SelectionEvent event) {
321:                            PushDownInputPage.this .editSelectedMembers();
322:                        }
323:                    });
324:
325:                    final Button addButton = new Button(composite, SWT.PUSH);
326:                    addButton
327:                            .setText(RefactoringMessages.PushDownInputPage_Add_Required);
328:                    addButton.setLayoutData(new GridData(
329:                            GridData.FILL_HORIZONTAL));
330:                    SWTUtil.setButtonDimensionHint(addButton);
331:                    addButton.addSelectionListener(new SelectionAdapter() {
332:
333:                        public void widgetSelected(final SelectionEvent event) {
334:                            PushDownInputPage.this 
335:                                    .markAdditionalRequiredMembersAsMembersToPushDown();
336:                        }
337:                    });
338:                }
339:
340:                public void createControl(final Composite parent) {
341:                    final Composite composite = new Composite(parent, SWT.NONE);
342:                    composite.setLayout(new GridLayout());
343:
344:                    createMemberTableLabel(composite);
345:                    createMemberTableComposite(composite);
346:                    createStatusLine(composite);
347:
348:                    setControl(composite);
349:                    Dialog.applyDialogFont(composite);
350:                    PlatformUI.getWorkbench().getHelpSystem().setHelp(
351:                            getControl(),
352:                            IJavaHelpContextIds.PUSH_DOWN_WIZARD_PAGE);
353:                }
354:
355:                private void createMemberTable(final Composite parent) {
356:                    final TableLayoutComposite layouter = new TableLayoutComposite(
357:                            parent, SWT.NONE);
358:                    layouter.addColumnData(new ColumnWeightData(60, true));
359:                    layouter.addColumnData(new ColumnWeightData(40, true));
360:
361:                    final Table table = new Table(layouter, SWT.H_SCROLL
362:                            | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER
363:                            | SWT.FULL_SELECTION | SWT.CHECK);
364:                    table.setHeaderVisible(true);
365:                    table.setLinesVisible(true);
366:
367:                    final GridData data = new GridData(GridData.FILL_BOTH);
368:                    data.heightHint = SWTUtil.getTableHeightHint(table,
369:                            ROW_COUNT);
370:                    data.widthHint = convertWidthInCharsToPixels(30);
371:                    layouter.setLayoutData(data);
372:
373:                    final TableLayout layout = new TableLayout();
374:                    table.setLayout(layout);
375:
376:                    final TableColumn first = new TableColumn(table, SWT.NONE);
377:                    first.setText(RefactoringMessages.PushDownInputPage_Member);
378:
379:                    final TableColumn second = new TableColumn(table, SWT.NONE);
380:                    second
381:                            .setText(RefactoringMessages.PushDownInputPage_Action);
382:
383:                    fTableViewer = new PullPushCheckboxTableViewer(table);
384:                    fTableViewer.setUseHashlookup(true);
385:                    fTableViewer.setContentProvider(new ArrayContentProvider());
386:                    fTableViewer
387:                            .setLabelProvider(new MemberActionInfoLabelProvider());
388:                    fTableViewer
389:                            .addSelectionChangedListener(new ISelectionChangedListener() {
390:
391:                                public void selectionChanged(
392:                                        final SelectionChangedEvent event) {
393:                                    PushDownInputPage.this 
394:                                            .updateButtonEnablementState((IStructuredSelection) event
395:                                                    .getSelection());
396:                                }
397:                            });
398:                    fTableViewer
399:                            .addCheckStateListener(new ICheckStateListener() {
400:
401:                                public void checkStateChanged(
402:                                        final CheckStateChangedEvent event) {
403:                                    final boolean checked = event.getChecked();
404:                                    final MemberActionInfo info = (MemberActionInfo) event
405:                                            .getElement();
406:                                    if (checked)
407:                                        info
408:                                                .setAction(MemberActionInfo.PUSH_DOWN_ACTION);
409:                                    else
410:                                        info
411:                                                .setAction(MemberActionInfo.NO_ACTION);
412:                                    updateWizardPage(null, true);
413:                                }
414:                            });
415:                    fTableViewer
416:                            .addDoubleClickListener(new IDoubleClickListener() {
417:
418:                                public void doubleClick(
419:                                        final DoubleClickEvent event) {
420:                                    PushDownInputPage.this 
421:                                            .editSelectedMembers();
422:                                }
423:                            });
424:
425:                    fTableViewer.setInput(getPushDownRefactoring()
426:                            .getPushDownProcessor().getMemberActionInfos());
427:                    updateWizardPage(null, false);
428:                    setupCellEditors(table);
429:                }
430:
431:                private void createMemberTableComposite(final Composite parent) {
432:                    final Composite composite = new Composite(parent, SWT.NONE);
433:                    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
434:                    final GridLayout layout = new GridLayout();
435:                    layout.numColumns = 2;
436:                    layout.marginWidth = 0;
437:                    layout.marginHeight = 0;
438:                    composite.setLayout(layout);
439:
440:                    createMemberTable(composite);
441:                    createButtonComposite(composite);
442:                }
443:
444:                private void createMemberTableLabel(final Composite parent) {
445:                    final Label label = new Label(parent, SWT.NONE);
446:                    label
447:                            .setText(RefactoringMessages.PushDownInputPage_Specify_actions);
448:                    label.setLayoutData(new GridData());
449:                }
450:
451:                private void createStatusLine(final Composite composite) {
452:                    fStatusLine = new Label(composite, SWT.NONE);
453:                    final GridData data = new GridData();
454:                    data.horizontalSpan = 2;
455:                    updateStatusLine();
456:                    fStatusLine.setLayoutData(data);
457:                }
458:
459:                // String -> Integer
460:                private Map createStringMappingForSelectedElements() {
461:                    final Map result = new HashMap();
462:                    int action = MemberActionInfo.PUSH_DOWN_ACTION;
463:                    result.put(MemberActionInfoLabelProvider
464:                            .getActionLabel(action), new Integer(action));
465:                    int action1 = MemberActionInfo.PUSH_ABSTRACT_ACTION;
466:                    result.put(MemberActionInfoLabelProvider
467:                            .getActionLabel(action1), new Integer(action1));
468:                    return result;
469:                }
470:
471:                private void editSelectedMembers() {
472:                    if (!fEditButton.isEnabled())
473:                        return;
474:                    final ISelection preserved = fTableViewer.getSelection();
475:                    try {
476:                        final Map stringMapping = createStringMappingForSelectedElements();
477:                        final String[] keys = (String[]) stringMapping.keySet()
478:                                .toArray(
479:                                        new String[stringMapping.keySet()
480:                                                .size()]);
481:                        Arrays.sort(keys);
482:                        final int initialSelectionIndex = getInitialSelectionIndexForEditDialog(
483:                                stringMapping, keys);
484:
485:                        final ComboSelectionDialog dialog = new ComboSelectionDialog(
486:                                getShell(),
487:                                RefactoringMessages.PushDownInputPage_Edit_members,
488:                                RefactoringMessages.PushDownInputPage_Mark_selected_members,
489:                                keys, initialSelectionIndex);
490:                        dialog.setBlockOnOpen(true);
491:                        if (dialog.open() == Window.CANCEL)
492:                            return;
493:                        final int action = ((Integer) stringMapping.get(dialog
494:                                .getSelectedString())).intValue();
495:                        setInfoAction(getSelectedMemberActionInfos(), action);
496:                    } finally {
497:                        updateWizardPage(preserved, true);
498:                    }
499:                }
500:
501:                private boolean enableEditButton(
502:                        final IStructuredSelection selection) {
503:                    if (selection.isEmpty() || selection.size() == 0)
504:                        return false;
505:                    return selection.size() == countEditableInfos(getSelectedMemberActionInfos());
506:                }
507:
508:                private MemberActionInfo[] getActiveInfos() {
509:                    final MemberActionInfo[] infos = getPushDownRefactoring()
510:                            .getPushDownProcessor().getMemberActionInfos();
511:                    final List result = new ArrayList(infos.length);
512:                    for (int index = 0; index < infos.length; index++) {
513:                        final MemberActionInfo info = infos[index];
514:                        if (info.isActive())
515:                            result.add(info);
516:                    }
517:                    return (MemberActionInfo[]) result
518:                            .toArray(new MemberActionInfo[result.size()]);
519:                }
520:
521:                private int getCommonActionCodeForSelectedInfos() {
522:                    final MemberActionInfo[] infos = getSelectedMemberActionInfos();
523:                    if (infos.length == 0)
524:                        return -1;
525:
526:                    final int code = infos[0].getAction();
527:                    for (int index = 0; index < infos.length; index++) {
528:                        if (code != infos[index].getAction())
529:                            return -1;
530:                    }
531:                    return code;
532:                }
533:
534:                private int getInitialSelectionIndexForEditDialog(
535:                        final Map mapping, final String[] keys) {
536:                    final int commonActionCode = getCommonActionCodeForSelectedInfos();
537:                    if (commonActionCode == -1)
538:                        return 0;
539:                    for (final Iterator iterator = mapping.keySet().iterator(); iterator
540:                            .hasNext();) {
541:                        final String key = (String) iterator.next();
542:                        final int action = ((Integer) mapping.get(key))
543:                                .intValue();
544:                        if (commonActionCode == action) {
545:                            for (int index = 0; index < keys.length; index++) {
546:                                if (key.equals(keys[index]))
547:                                    return index;
548:                            }
549:                            Assert.isTrue(false);// there's no way
550:                        }
551:                    }
552:                    return 0;
553:                }
554:
555:                private IMember[] getMembers() {
556:                    final MemberActionInfo[] infos = (MemberActionInfo[]) fTableViewer
557:                            .getInput();
558:                    final List result = new ArrayList(infos.length);
559:                    for (int index = 0; index < infos.length; index++) {
560:                        result.add(infos[index].getMember());
561:                    }
562:                    return (IMember[]) result
563:                            .toArray(new IMember[result.size()]);
564:                }
565:
566:                private PushDownRefactoring getPushDownRefactoring() {
567:                    return (PushDownRefactoring) getRefactoring();
568:                }
569:
570:                private MemberActionInfo[] getSelectedMemberActionInfos() {
571:                    Assert
572:                            .isTrue(fTableViewer.getSelection() instanceof  IStructuredSelection);
573:                    final List result = ((IStructuredSelection) fTableViewer
574:                            .getSelection()).toList();
575:                    return (MemberActionInfo[]) result
576:                            .toArray(new MemberActionInfo[result.size()]);
577:                }
578:
579:                public void markAdditionalRequiredMembersAsMembersToPushDown() {
580:                    try {
581:                        PlatformUI.getWorkbench().getActiveWorkbenchWindow()
582:                                .run(false, false, new IRunnableWithProgress() {
583:
584:                                    public void run(final IProgressMonitor pm)
585:                                            throws InvocationTargetException {
586:                                        try {
587:                                            getPushDownRefactoring()
588:                                                    .getPushDownProcessor()
589:                                                    .computeAdditionalRequiredMembersToPushDown(
590:                                                            pm);
591:                                            updateWizardPage(null, true);
592:                                        } catch (final JavaModelException e) {
593:                                            throw new InvocationTargetException(
594:                                                    e);
595:                                        } finally {
596:                                            pm.done();
597:                                        }
598:                                    }
599:                                });
600:                    } catch (final InvocationTargetException e) {
601:                        ExceptionHandler
602:                                .handle(
603:                                        e,
604:                                        getShell(),
605:                                        RefactoringMessages.PushDownInputPage_Push_Down,
606:                                        RefactoringMessages.PushDownInputPage_Internal_Error);
607:                    } catch (final InterruptedException e) {
608:                        Assert.isTrue(false);// not cancelable
609:                    }
610:                }
611:
612:                private void setActionForMembers(final IMember[] members,
613:                        final int action) {
614:                    final MemberActionInfo[] infos = (MemberActionInfo[]) fTableViewer
615:                            .getInput();
616:                    for (int offset = 0; offset < members.length; offset++) {
617:                        for (int index = 0; index < infos.length; index++) {
618:                            if (infos[index].getMember()
619:                                    .equals(members[offset]))
620:                                infos[index].setAction(action);
621:                        }
622:                    }
623:                }
624:
625:                private void setupCellEditors(final Table table) {
626:                    final ComboBoxCellEditor comboBoxCellEditor = new ComboBoxCellEditor();
627:                    comboBoxCellEditor.setStyle(SWT.READ_ONLY);
628:                    fTableViewer.setCellEditors(new CellEditor[] { null,
629:                            comboBoxCellEditor });
630:                    fTableViewer
631:                            .addSelectionChangedListener(new ISelectionChangedListener() {
632:
633:                                public void selectionChanged(
634:                                        final SelectionChangedEvent event) {
635:                                    if (comboBoxCellEditor.getControl() == null
636:                                            & !table.isDisposed())
637:                                        comboBoxCellEditor.create(table);
638:                                    Assert
639:                                            .isTrue(event.getSelection() instanceof  IStructuredSelection);
640:                                    final IStructuredSelection ss = (IStructuredSelection) event
641:                                            .getSelection();
642:                                    if (ss.size() != 1)
643:                                        return;
644:                                    final MemberActionInfo mac = (MemberActionInfo) ss
645:                                            .getFirstElement();
646:                                    comboBoxCellEditor
647:                                            .setItems(MemberActionInfoLabelProvider
648:                                                    .getAvailableActionLabels(mac));
649:                                    comboBoxCellEditor.setValue(new Integer(mac
650:                                            .getAction()));
651:                                }
652:                            });
653:
654:                    final ICellModifier cellModifier = new PushDownCellModifier();
655:                    fTableViewer.setCellModifier(cellModifier);
656:                    fTableViewer.setColumnProperties(new String[] {
657:                            MEMBER_PROPERTY, ACTION_PROPERTY });
658:                }
659:
660:                public void setVisible(final boolean visible) {
661:                    super .setVisible(visible);
662:                    if (visible) {
663:                        fTableViewer.setSelection(new StructuredSelection(
664:                                getActiveInfos()), true);
665:                        fTableViewer.getControl().setFocus();
666:                    }
667:                }
668:
669:                private void updateButtonEnablementState(
670:                        final IStructuredSelection tableSelection) {
671:                    if (tableSelection == null || fEditButton == null)
672:                        return;
673:                    fEditButton.setEnabled(enableEditButton(tableSelection));
674:                    if (fSelectAllButton != null)
675:                        fSelectAllButton
676:                                .setEnabled(!areAllElementsMarkedAsPushDownAction());
677:                    if (fDeselectAllButton != null)
678:                        fDeselectAllButton
679:                                .setEnabled(!areAllElementsMarkedAsNoAction());
680:                }
681:
682:                private void updateStatusLine() {
683:                    if (fStatusLine == null)
684:                        return;
685:                    final int selected = fTableViewer.getCheckedElements().length;
686:                    final String[] keys = { String.valueOf(selected) };
687:                    final String msg = Messages.format(
688:                            RefactoringMessages.PushDownInputPage_status_line,
689:                            keys);
690:                    fStatusLine.setText(msg);
691:                }
692:
693:                private void updateWizardPage(final ISelection preserved,
694:                        final boolean displayErrorMessage) {
695:                    fTableViewer.refresh();
696:                    if (preserved != null) {
697:                        fTableViewer.getControl().setFocus();
698:                        fTableViewer.setSelection(preserved);
699:                    }
700:                    checkPageCompletionStatus(displayErrorMessage);
701:                    updateButtonEnablementState(((IStructuredSelection) fTableViewer
702:                            .getSelection()));
703:                    updateStatusLine();
704:                }
705:            }
706:
707:            public PushDownWizard(final PushDownRefactoring ref) {
708:                super (ref, DIALOG_BASED_USER_INTERFACE);
709:                setDefaultPageTitle(RefactoringMessages.PushDownWizard_defaultPageTitle);
710:            }
711:
712:            protected void addUserInputPages() {
713:                addPage(new PushDownInputPage());
714:            }
715:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.