Source Code Cross Referenced for PullUpMethodPage.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) 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.HashSet;
017:        import java.util.Iterator;
018:        import java.util.List;
019:        import java.util.Map;
020:        import java.util.Set;
021:
022:        import org.eclipse.core.runtime.Assert;
023:        import org.eclipse.core.runtime.IProgressMonitor;
024:        import org.eclipse.core.runtime.SubProgressMonitor;
025:
026:        import org.eclipse.swt.SWT;
027:        import org.eclipse.swt.custom.SashForm;
028:        import org.eclipse.swt.events.SelectionAdapter;
029:        import org.eclipse.swt.events.SelectionEvent;
030:        import org.eclipse.swt.layout.GridData;
031:        import org.eclipse.swt.layout.GridLayout;
032:        import org.eclipse.swt.widgets.Button;
033:        import org.eclipse.swt.widgets.Composite;
034:        import org.eclipse.swt.widgets.Label;
035:        import org.eclipse.swt.widgets.Tree;
036:
037:        import org.eclipse.jface.dialogs.Dialog;
038:        import org.eclipse.jface.operation.IRunnableWithProgress;
039:        import org.eclipse.jface.preference.IPreferenceStore;
040:        import org.eclipse.jface.resource.JFaceResources;
041:        import org.eclipse.jface.viewers.CheckStateChangedEvent;
042:        import org.eclipse.jface.viewers.ICheckStateListener;
043:        import org.eclipse.jface.viewers.ISelection;
044:        import org.eclipse.jface.viewers.ISelectionChangedListener;
045:        import org.eclipse.jface.viewers.IStructuredSelection;
046:        import org.eclipse.jface.viewers.ITreeContentProvider;
047:        import org.eclipse.jface.viewers.SelectionChangedEvent;
048:        import org.eclipse.jface.viewers.Viewer;
049:        import org.eclipse.jface.viewers.ViewerFilter;
050:        import org.eclipse.jface.wizard.IWizardPage;
051:
052:        import org.eclipse.jface.text.Document;
053:        import org.eclipse.jface.text.IDocument;
054:        import org.eclipse.jface.text.source.SourceViewer;
055:
056:        import org.eclipse.ui.PlatformUI;
057:        import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
058:
059:        import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
060:
061:        import org.eclipse.jdt.core.IJavaProject;
062:        import org.eclipse.jdt.core.IMember;
063:        import org.eclipse.jdt.core.IMethod;
064:        import org.eclipse.jdt.core.ISourceReference;
065:        import org.eclipse.jdt.core.IType;
066:        import org.eclipse.jdt.core.ITypeHierarchy;
067:        import org.eclipse.jdt.core.JavaModelException;
068:
069:        import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
070:        import org.eclipse.jdt.internal.corext.refactoring.structure.HierarchyProcessor;
071:        import org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoring;
072:        import org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor;
073:        import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
074:        import org.eclipse.jdt.internal.corext.util.Messages;
075:        import org.eclipse.jdt.internal.corext.util.Strings;
076:
077:        import org.eclipse.jdt.ui.JavaElementComparator;
078:        import org.eclipse.jdt.ui.JavaElementLabelProvider;
079:        import org.eclipse.jdt.ui.PreferenceConstants;
080:        import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration;
081:
082:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
083:        import org.eclipse.jdt.internal.ui.JavaPlugin;
084:        import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer;
085:        import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
086:        import org.eclipse.jdt.internal.ui.util.SWTUtil;
087:
088:        /**
089:         * Wizard page for pull up refactoring wizards which allows to specify the
090:         * methods to be deleted in subtypes after pull up.
091:         * 
092:         * @since 3.2
093:         */
094:        public class PullUpMethodPage extends UserInputWizardPage {
095:
096:            private static class PullUpFilter extends ViewerFilter {
097:
098:                private static boolean anySubtypeCanBeShown(final IType type,
099:                        final Map typeToMemberArray,
100:                        final ITypeHierarchy hierarchy) {
101:                    final IType[] subTypes = hierarchy.getSubtypes(type);
102:                    for (int i = 0; i < subTypes.length; i++) {
103:                        if (canBeShown(subTypes[i], typeToMemberArray,
104:                                hierarchy))
105:                            return true;
106:                    }
107:                    return false;
108:                }
109:
110:                private static boolean canBeShown(final IType type,
111:                        final Map typeToMemberArray,
112:                        final ITypeHierarchy hierarchy) {
113:                    if (typeToMemberArray.containsKey(type))
114:                        return true;
115:                    return anySubtypeCanBeShown(type, typeToMemberArray,
116:                            hierarchy);
117:                }
118:
119:                private static Set computeShowableSubtypesOfMainType(
120:                        final ITypeHierarchy hierarchy,
121:                        final Map typeToMemberArray) {
122:                    final Set result = new HashSet();
123:                    final IType[] subtypes = hierarchy.getAllSubtypes(hierarchy
124:                            .getType());
125:                    for (int i = 0; i < subtypes.length; i++) {
126:                        final IType subtype = subtypes[i];
127:                        if (canBeShown(subtype, typeToMemberArray, hierarchy))
128:                            result.add(subtype);
129:                    }
130:                    return result;
131:                }
132:
133:                private static Set computeTypesToShow(
134:                        final ITypeHierarchy hierarchy,
135:                        final Map typeToMemberArray) {
136:                    final Set typesToShow = new HashSet();
137:                    typesToShow.add(hierarchy.getType());
138:                    typesToShow.addAll(computeShowableSubtypesOfMainType(
139:                            hierarchy, typeToMemberArray));
140:                    return typesToShow;
141:                }
142:
143:                private final Set fTypesToShow;
144:
145:                public PullUpFilter(final ITypeHierarchy hierarchy,
146:                        final IMember[] members) {
147:                    // IType -> IMember[]
148:                    final Map map = PullUpMethodPage
149:                            .createTypeToMemberArrayMapping(members);
150:                    fTypesToShow = computeTypesToShow(hierarchy, map);
151:                }
152:
153:                public boolean select(final Viewer viewer,
154:                        final Object parentElement, final Object element) {
155:                    if (element instanceof  IMethod)
156:                        return true;
157:                    return fTypesToShow.contains(element);
158:                }
159:            }
160:
161:            private static class PullUpHierarchyContentProvider implements 
162:                    ITreeContentProvider {
163:
164:                private IType fDeclaringType;
165:
166:                private ITypeHierarchy fHierarchy;
167:
168:                private Map fTypeToMemberArray; // IType -> IMember[]
169:
170:                public PullUpHierarchyContentProvider(
171:                        final IType declaringType, final IMember[] members) {
172:                    fDeclaringType = declaringType;
173:                    fTypeToMemberArray = PullUpMethodPage
174:                            .createTypeToMemberArrayMapping(members);
175:                }
176:
177:                public void dispose() {
178:                    fHierarchy = null;
179:                    fTypeToMemberArray.clear();
180:                    fTypeToMemberArray = null;
181:                    fDeclaringType = null;
182:                }
183:
184:                public Object[] getChildren(final Object parentElement) {
185:                    if (parentElement instanceof  IType)
186:                        return getSubclassesAndMembers((IType) parentElement);
187:                    else
188:                        return new Object[0];
189:                }
190:
191:                public Object[] getElements(final Object inputElement) {
192:                    Assert.isTrue(inputElement == null
193:                            || inputElement instanceof  ITypeHierarchy);
194:                    return new IType[] { fHierarchy.getType() };
195:                }
196:
197:                private IMember[] getMembers(final IType type) {
198:                    if (fTypeToMemberArray.containsKey(type))
199:                        return (IMember[]) (fTypeToMemberArray.get(type));
200:                    else
201:                        return new IMember[0];
202:                }
203:
204:                public Object getParent(final Object element) {
205:                    if (element instanceof  IType)
206:                        return fHierarchy.getSuperclass((IType) element);
207:                    if (element instanceof  IMember)
208:                        return ((IMember) element).getDeclaringType();
209:                    Assert.isTrue(false, "Should not get here"); //$NON-NLS-1$
210:                    return null;
211:                }
212:
213:                private IType[] getSubclasses(final IType type) {
214:                    if (type.equals(fDeclaringType))
215:                        return new IType[0];
216:                    return fHierarchy.getSubclasses(type);
217:                }
218:
219:                private Object[] getSubclassesAndMembers(final IType type) {
220:                    final Set set = new HashSet();
221:                    set.addAll(Arrays.asList(getSubclasses(type)));
222:                    set.addAll(Arrays.asList(getMembers(type)));
223:                    return set.toArray();
224:                }
225:
226:                public boolean hasChildren(final Object element) {
227:                    if (!(element instanceof  IType))
228:                        return false;
229:                    final IType type = (IType) element;
230:                    return (fHierarchy.getAllSubtypes(type).length > 0)
231:                            || fTypeToMemberArray.containsKey(type);
232:                }
233:
234:                public void inputChanged(final Viewer viewer,
235:                        final Object oldInput, final Object newInput) {
236:                    Assert.isTrue(newInput == null
237:                            || newInput instanceof  ITypeHierarchy);
238:                    fHierarchy = (ITypeHierarchy) newInput;
239:                }
240:            }
241:
242:            private static final String PAGE_NAME = "PullUpMethodPage"; //$NON-NLS-1$
243:
244:            // IType -> IMember[]
245:            private static Map createTypeToMemberArrayMapping(
246:                    final IMember[] members) {
247:                final Map typeToMemberSet = createTypeToMemberSetMapping(members);
248:
249:                final Map typeToMemberArray = new HashMap();
250:                for (final Iterator iter = typeToMemberSet.keySet().iterator(); iter
251:                        .hasNext();) {
252:                    final IType type = (IType) iter.next();
253:                    final Set memberSet = (Set) typeToMemberSet.get(type);
254:                    final IMember[] memberArray = (IMember[]) memberSet
255:                            .toArray(new IMember[memberSet.size()]);
256:                    typeToMemberArray.put(type, memberArray);
257:                }
258:                return typeToMemberArray;
259:            }
260:
261:            // IType -> Set of IMember
262:            private static Map createTypeToMemberSetMapping(
263:                    final IMember[] members) {
264:                final Map typeToMemberSet = new HashMap();
265:                for (int i = 0; i < members.length; i++) {
266:                    final IMember member = members[i];
267:                    final IType type = member.getDeclaringType();
268:                    if (!typeToMemberSet.containsKey(type))
269:                        typeToMemberSet.put(type, new HashSet());
270:                    ((Set) typeToMemberSet.get(type)).add(member);
271:                }
272:                return typeToMemberSet;
273:            }
274:
275:            private boolean fChangedSettings = true;
276:
277:            private Label fSelectionLabel;
278:
279:            private SourceViewer fSourceViewer;
280:
281:            private ContainerCheckedTreeViewer fTreeViewer;
282:
283:            private Label fTypeHierarchyLabel;
284:
285:            public PullUpMethodPage() {
286:                super (PAGE_NAME);
287:                setMessage(RefactoringMessages.PullUpInputPage_select_methods);
288:            }
289:
290:            private void checkAllParents(final IType parent) {
291:                final ITypeHierarchy th = getTreeInput();
292:                final IType root = getTreeInput().getType();
293:                IType type = parent;
294:                while (!root.equals(type)) {
295:                    fTreeViewer.setChecked(type, true);
296:                    type = th.getSuperclass(type);
297:                }
298:                fTreeViewer.setChecked(root, true);
299:            }
300:
301:            public void checkPulledUp() {
302:                uncheckAll();
303:                final HierarchyProcessor processor = getPullUpRefactoring()
304:                        .getPullUpProcessor();
305:                fTreeViewer.setCheckedElements(processor.getMembersToMove());
306:                final IType parent = processor.getDeclaringType();
307:                fTreeViewer.setChecked(parent, true);
308:                checkAllParents(parent);
309:            }
310:
311:            private void createButtonComposite(final Composite super Composite) {
312:                final Composite buttonComposite = new Composite(super Composite,
313:                        SWT.NONE);
314:                buttonComposite.setLayoutData(new GridData(GridData.FILL,
315:                        GridData.BEGINNING, true, false));
316:                final GridLayout layout = new GridLayout(2, false);
317:                layout.marginWidth = 0;
318:                buttonComposite.setLayout(layout);
319:
320:                fSelectionLabel = new Label(buttonComposite, SWT.LEFT
321:                        | SWT.WRAP | SWT.HORIZONTAL);
322:                GridData data = new GridData(GridData.BEGINNING,
323:                        GridData.BEGINNING, true, false);
324:                data.widthHint = convertWidthInCharsToPixels(32);
325:                fSelectionLabel.setLayoutData(data);
326:
327:                final Button button = new Button(buttonComposite, SWT.PUSH);
328:                button.setText(RefactoringMessages.PullUpInputPage2_Select);
329:                button.setLayoutData(new GridData());
330:                SWTUtil.setButtonDimensionHint(button);
331:                button.addSelectionListener(new SelectionAdapter() {
332:
333:                    public void widgetSelected(final SelectionEvent e) {
334:                        checkPulledUp();
335:                        updateSelectionLabel();
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:                createTreeAndSourceViewer(composite);
345:                createButtonComposite(composite);
346:                setControl(composite);
347:
348:                Dialog.applyDialogFont(composite);
349:                PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
350:                        IJavaHelpContextIds.PULL_UP_WIZARD_PAGE);
351:            }
352:
353:            private void createHierarchyTreeComposite(final Composite parent) {
354:                final Composite composite = new Composite(parent, SWT.NONE);
355:                composite.setLayoutData(new GridData(GridData.FILL_BOTH));
356:                final GridLayout layout = new GridLayout();
357:                layout.marginWidth = 0;
358:                layout.marginHeight = 0;
359:                layout.horizontalSpacing = 1;
360:                layout.verticalSpacing = 1;
361:                composite.setLayout(layout);
362:
363:                createTypeHierarchyLabel(composite);
364:                createTreeViewer(composite);
365:            }
366:
367:            private void createSourceViewer(final Composite c) {
368:                final IPreferenceStore store = JavaPlugin.getDefault()
369:                        .getCombinedPreferenceStore();
370:                fSourceViewer = new JavaSourceViewer(c, null, null, false,
371:                        SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER
372:                                | SWT.FULL_SELECTION, store);
373:                fSourceViewer.configure(new JavaSourceViewerConfiguration(
374:                        JavaPlugin.getDefault().getJavaTextTools()
375:                                .getColorManager(), store, null, null));
376:                fSourceViewer.setEditable(false);
377:                fSourceViewer.getControl().setLayoutData(
378:                        new GridData(GridData.FILL_BOTH));
379:                fSourceViewer.getControl().setFont(
380:                        JFaceResources
381:                                .getFont(PreferenceConstants.EDITOR_TEXT_FONT));
382:            }
383:
384:            private void createSourceViewerComposite(final Composite parent) {
385:                final Composite c = new Composite(parent, SWT.NONE);
386:                c.setLayoutData(new GridData(GridData.FILL_BOTH));
387:                final GridLayout layout = new GridLayout();
388:                layout.marginWidth = 0;
389:                layout.marginHeight = 0;
390:                layout.horizontalSpacing = 1;
391:                layout.verticalSpacing = 1;
392:                c.setLayout(layout);
393:
394:                createSourceViewerLabel(c);
395:                createSourceViewer(c);
396:            }
397:
398:            private void createSourceViewerLabel(final Composite c) {
399:                final Label label = new Label(c, SWT.WRAP);
400:                final GridData gd = new GridData(GridData.FILL_HORIZONTAL);
401:                label.setText(RefactoringMessages.PullUpInputPage2_Source);
402:                label.setLayoutData(gd);
403:            }
404:
405:            private void createTreeAndSourceViewer(
406:                    final Composite super Composite) {
407:                final SashForm composite = new SashForm(super Composite,
408:                        SWT.HORIZONTAL);
409:                initializeDialogUnits(super Composite);
410:                final GridData gd = new GridData(GridData.FILL_BOTH);
411:                gd.heightHint = convertHeightInCharsToPixels(20);
412:                gd.widthHint = convertWidthInCharsToPixels(10);
413:                composite.setLayoutData(gd);
414:                final GridLayout layout = new GridLayout();
415:                layout.numColumns = 2;
416:                layout.marginWidth = 0;
417:                layout.marginHeight = 0;
418:                layout.horizontalSpacing = 1;
419:                layout.verticalSpacing = 1;
420:                composite.setLayout(layout);
421:
422:                createHierarchyTreeComposite(composite);
423:                createSourceViewerComposite(composite);
424:                composite.setWeights(new int[] { 50, 50 });
425:            }
426:
427:            private void createTreeViewer(final Composite composite) {
428:                final Tree tree = new Tree(composite, SWT.CHECK | SWT.BORDER
429:                        | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
430:                tree.setLayoutData(new GridData(GridData.FILL_BOTH));
431:                fTreeViewer = new ContainerCheckedTreeViewer(tree);
432:                fTreeViewer.setLabelProvider(new JavaElementLabelProvider(
433:                        JavaElementLabelProvider.SHOW_DEFAULT
434:                                | JavaElementLabelProvider.SHOW_SMALL_ICONS));
435:                fTreeViewer.setUseHashlookup(true);
436:                fTreeViewer.setComparator(new JavaElementComparator());
437:                fTreeViewer
438:                        .addSelectionChangedListener(new ISelectionChangedListener() {
439:
440:                            public void selectionChanged(
441:                                    final SelectionChangedEvent event) {
442:                                treeViewerSelectionChanged(event);
443:                            }
444:                        });
445:                fTreeViewer.addCheckStateListener(new ICheckStateListener() {
446:
447:                    public void checkStateChanged(
448:                            final CheckStateChangedEvent event) {
449:                        updateSelectionLabel();
450:                    }
451:                });
452:            }
453:
454:            private void createTypeHierarchyLabel(final Composite composite) {
455:                fTypeHierarchyLabel = new Label(composite, SWT.WRAP);
456:                final GridData gd = new GridData(GridData.FILL_HORIZONTAL);
457:                fTypeHierarchyLabel.setLayoutData(gd);
458:            }
459:
460:            public void fireSettingsChanged() {
461:                fChangedSettings = true;
462:            }
463:
464:            private IMethod[] getCheckedMethods() {
465:                final Object[] checked = fTreeViewer.getCheckedElements();
466:                final List members = new ArrayList(checked.length);
467:                for (int i = 0; i < checked.length; i++) {
468:                    if (checked[i] instanceof  IMethod)
469:                        members.add(checked[i]);
470:                }
471:                return (IMethod[]) members.toArray(new IMethod[members.size()]);
472:            }
473:
474:            private ISourceReference getFirstSelectedSourceReference(
475:                    final SelectionChangedEvent event) {
476:                final ISelection s = event.getSelection();
477:                if (!(s instanceof  IStructuredSelection))
478:                    return null;
479:                final IStructuredSelection ss = (IStructuredSelection) s;
480:                if (ss.size() != 1)
481:                    return null;
482:                final Object first = ss.getFirstElement();
483:                if (!(first instanceof  ISourceReference))
484:                    return null;
485:                return (ISourceReference) first;
486:            }
487:
488:            public IWizardPage getNextPage() {
489:                initializeRefactoring();
490:                return super .getNextPage();
491:            }
492:
493:            private PullUpRefactoring getPullUpRefactoring() {
494:                return (PullUpRefactoring) getRefactoring();
495:            }
496:
497:            private String getSupertypeSignature() {
498:                return JavaElementUtil.createSignature(getPullUpRefactoring()
499:                        .getPullUpProcessor().getDestinationType());
500:            }
501:
502:            private ITypeHierarchy getTreeInput() {
503:                return (ITypeHierarchy) fTreeViewer.getInput();
504:            }
505:
506:            private void initializeRefactoring() {
507:                getPullUpRefactoring().getPullUpProcessor().setDeletedMethods(
508:                        getCheckedMethods());
509:            }
510:
511:            private void initializeTreeViewer() {
512:                try {
513:                    getContainer().run(false, false,
514:                            new IRunnableWithProgress() {
515:
516:                                public void run(final IProgressMonitor pm) {
517:                                    try {
518:                                        initializeTreeViewer(pm);
519:                                    } finally {
520:                                        pm.done();
521:                                    }
522:                                }
523:                            });
524:                } catch (InvocationTargetException e) {
525:                    ExceptionHandler.handle(e, getShell(),
526:                            RefactoringMessages.PullUpInputPage_pull_Up,
527:                            RefactoringMessages.PullUpInputPage_exception);
528:                } catch (InterruptedException e) {
529:                    Assert.isTrue(false);
530:                }
531:            }
532:
533:            private void initializeTreeViewer(final IProgressMonitor pm) {
534:                try {
535:                    pm.beginTask(
536:                            RefactoringCoreMessages.PullUpRefactoring_checking,
537:                            2);
538:                    final PullUpRefactoringProcessor processor = getPullUpRefactoring()
539:                            .getPullUpProcessor();
540:                    final IMember[] matchingMethods = processor
541:                            .getMatchingElements(new SubProgressMonitor(pm, 1),
542:                                    false);
543:                    final ITypeHierarchy hierarchy = processor
544:                            .getDestinationTypeHierarchy(new SubProgressMonitor(
545:                                    pm, 1));
546:                    removeAllTreeViewFilters();
547:                    fTreeViewer.addFilter(new PullUpFilter(hierarchy,
548:                            matchingMethods));
549:                    fTreeViewer
550:                            .setContentProvider(new PullUpHierarchyContentProvider(
551:                                    processor.getDeclaringType(),
552:                                    matchingMethods));
553:                    fTreeViewer.setInput(hierarchy);
554:                    precheckElements(fTreeViewer);
555:                    fTreeViewer.expandAll();
556:                    updateSelectionLabel();
557:                } catch (JavaModelException e) {
558:                    ExceptionHandler.handle(e,
559:                            RefactoringMessages.PullUpInputPage_pull_up1,
560:                            RefactoringMessages.PullUpInputPage_exception);
561:                    fTreeViewer.setInput(null);
562:                } finally {
563:                    pm.done();
564:                }
565:            }
566:
567:            protected boolean performFinish() {
568:                initializeRefactoring();
569:                return super .performFinish();
570:            }
571:
572:            private void precheckElements(
573:                    final ContainerCheckedTreeViewer treeViewer) {
574:                final IMember[] members = getPullUpRefactoring()
575:                        .getPullUpProcessor().getMembersToMove();
576:                for (int i = 0; i < members.length; i++) {
577:                    treeViewer.setChecked(members[i], true);
578:                }
579:            }
580:
581:            private void removeAllTreeViewFilters() {
582:                final ViewerFilter[] filters = fTreeViewer.getFilters();
583:                for (int i = 0; i < filters.length; i++) {
584:                    fTreeViewer.removeFilter(filters[i]);
585:                }
586:            }
587:
588:            private void setHierarchyLabelText() {
589:                final String message = Messages.format(
590:                        RefactoringMessages.PullUpInputPage_subtypes,
591:                        getSupertypeSignature());
592:                fTypeHierarchyLabel.setText(message);
593:            }
594:
595:            private void setSourceViewerContents(String contents) {
596:                if (contents != null) {
597:                    final IJavaProject project = getPullUpRefactoring()
598:                            .getPullUpProcessor().getDestinationType()
599:                            .getJavaProject();
600:                    final String[] lines = Strings.convertIntoLines(contents);
601:                    if (lines.length > 0) {
602:                        final int indent = Strings.computeIndentUnits(
603:                                lines[lines.length - 1], project);
604:                        contents = Strings.changeIndent(contents, indent,
605:                                project, "", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
606:                    }
607:                }
608:                final IDocument document = (contents == null) ? new Document()
609:                        : new Document(contents);
610:                JavaPlugin.getDefault().getJavaTextTools()
611:                        .setupJavaDocumentPartitioner(document);
612:                fSourceViewer.setDocument(document);
613:            }
614:
615:            public void setVisible(final boolean visible) {
616:                if (visible && fChangedSettings) {
617:                    fChangedSettings = false;
618:                    initializeTreeViewer();
619:                    setHierarchyLabelText();
620:                }
621:                super .setVisible(visible);
622:            }
623:
624:            private void showInSourceViewer(final ISourceReference selected)
625:                    throws JavaModelException {
626:                if (selected == null)
627:                    setSourceViewerContents(null);
628:                else
629:                    setSourceViewerContents(selected.getSource());
630:            }
631:
632:            private void treeViewerSelectionChanged(
633:                    final SelectionChangedEvent event) {
634:                try {
635:                    showInSourceViewer(getFirstSelectedSourceReference(event));
636:                } catch (JavaModelException e) {
637:                    ExceptionHandler.handle(e,
638:                            RefactoringMessages.PullUpInputPage_pull_up1,
639:                            RefactoringMessages.PullUpInputPage_see_log);
640:                }
641:            }
642:
643:            private void uncheckAll() {
644:                final IType root = getTreeInput().getType();
645:                fTreeViewer.setChecked(root, false);
646:            }
647:
648:            private void updateSelectionLabel() {
649:                fSelectionLabel.setText(Messages.format(
650:                        RefactoringMessages.PullUpInputPage_hierarchyLabal,
651:                        String.valueOf(getCheckedMethods().length)));
652:            }
653:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.