]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 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 | *******************************************************************************/ | |
9 | package org.eclipse.jdt.internal.ui.callhierarchy; | |
10 | ||
11 | import java.util.Iterator; | |
12 | ||
13 | import org.eclipse.jface.action.Action; | |
14 | import org.eclipse.jface.action.IMenuManager; | |
15 | import org.eclipse.jface.viewers.ISelection; | |
16 | import org.eclipse.jface.viewers.IStructuredSelection; | |
17 | ||
18 | import org.eclipse.ui.PlatformUI; | |
19 | ||
20 | import org.eclipse.jdt.internal.corext.callhierarchy.CallerMethodWrapper; | |
21 | import org.eclipse.jdt.internal.corext.callhierarchy.RealCallers; | |
22 | ||
23 | import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; | |
24 | ||
25 | /** | |
26 | * The action to expand the selected member hierarchy with constructor calls. | |
27 | * | |
28 | * @since 3.5 | |
29 | */ | |
30 | public class ExpandWithConstructorsAction extends Action { | |
31 | ||
32 | /** | |
33 | * The call hierarchy view part. | |
34 | */ | |
35 | private CallHierarchyViewPart fPart; | |
36 | ||
37 | /** | |
38 | * The call hierarchy viewer. | |
39 | */ | |
40 | public CallHierarchyViewer fCallHierarchyViewer; | |
41 | ||
42 | /** | |
43 | * Creates the action for expanding the hierarchy with constructor calls. | |
44 | * | |
45 | * @param callHierarchyViewPart the call hierarchy view part | |
46 | * @param callHierarchyViewer the call hierarchy viewer | |
47 | */ | |
48 | public ExpandWithConstructorsAction(CallHierarchyViewPart callHierarchyViewPart, CallHierarchyViewer callHierarchyViewer) { | |
49 | super(CallHierarchyMessages.ExpandWithConstructorsAction_expandWithConstructors_text, AS_CHECK_BOX); | |
50 | fPart= callHierarchyViewPart; | |
51 | fCallHierarchyViewer= callHierarchyViewer; | |
52 | setDescription(CallHierarchyMessages.ExpandWithConstructorsAction_expandWithConstructors_description); | |
53 | setToolTipText(CallHierarchyMessages.ExpandWithConstructorsAction_expandWithConstructors_tooltip); | |
54 | PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.CALL_HIERARCHY_EXPAND_WITH_CONSTRUCTORS_ACTION); | |
55 | ||
56 | } | |
57 | ||
58 | ||
59 | /* | |
60 | * @see Action#run | |
61 | */ | |
62 | @Override | |
63 | public void run() { | |
64 | boolean isChecked= isChecked(); | |
65 | fCallHierarchyViewer.cancelJobs(); | |
66 | ||
67 | IStructuredSelection selection= (IStructuredSelection)getSelection(); | |
68 | for (Iterator<?> iter= selection.iterator(); iter.hasNext();) { | |
69 | CallerMethodWrapper member= (CallerMethodWrapper)iter.next(); | |
70 | member.generated_2297222693293678322(isChecked, this); | |
71 | fCallHierarchyViewer.refresh(member); | |
72 | if (isChecked) { // expand only after refresh | |
73 | fCallHierarchyViewer.setExpandedState(member, true); | |
74 | fCallHierarchyViewer.expandConstructorNode(); | |
75 | } | |
76 | } | |
77 | } | |
78 | ||
79 | ||
80 | /** | |
81 | * Gets the selection from the call hierarchy view part. | |
82 | * | |
83 | * @return the current selection | |
84 | */ | |
85 | private ISelection getSelection() { | |
86 | return fPart.getSelection(); | |
87 | } | |
88 | ||
89 | /** | |
90 | * Checks whether this action can be added for the selected element in the call hierarchy. | |
91 | * | |
92 | * @return <code> true</code> if the action can be added, <code>false</code> otherwise | |
93 | */ | |
94 | public boolean canActionBeAdded() { | |
95 | if (fPart.getCallMode() == CallHierarchyViewPart.CALL_MODE_CALLEES) | |
96 | return false; | |
97 | ISelection selection= getSelection(); | |
98 | if (selection.isEmpty()) | |
99 | return false; | |
100 | ||
101 | boolean allElementsChecked= true; | |
102 | IStructuredSelection structuredSelection= (IStructuredSelection)selection; | |
103 | CallerMethodWrapper[] wrappers= new CallerMethodWrapper[structuredSelection.size()]; | |
104 | int i= 0; | |
105 | for (Iterator<?> iter= structuredSelection.iterator(); iter.hasNext(); i++) { | |
106 | Object element= iter.next(); | |
107 | if (!(element instanceof CallerMethodWrapper) || element instanceof RealCallers) | |
108 | return false; | |
109 | ||
110 | wrappers[i]= (CallerMethodWrapper)element; | |
111 | if (!CallHierarchyContentProvider.canExpandWithConstructors(wrappers[i])) | |
112 | return false; | |
113 | ||
114 | for (int j= 0; j < i; j++) { | |
115 | CallerMethodWrapper parent= (CallerMethodWrapper)wrappers[j].getParent(); | |
116 | while (parent != null) { | |
117 | if (wrappers[i] == parent) { | |
118 | return false;// disable if element is a parent of other selected elements | |
119 | } | |
120 | parent= (CallerMethodWrapper)parent.getParent(); | |
121 | } | |
122 | CallerMethodWrapper parentElement= (CallerMethodWrapper)wrappers[i].getParent(); | |
123 | while (parentElement != null) { | |
124 | if (parentElement == wrappers[j]) { | |
125 | return false;// disable if element is a child of other selected elements | |
126 | } | |
127 | parentElement= (CallerMethodWrapper)parentElement.getParent(); | |
128 | } | |
129 | ||
130 | } | |
131 | CallHierarchyContentProvider.ensureDefaultExpandWithConstructors(wrappers[i]); | |
132 | if (!wrappers[i].getExpandWithConstructors()) { | |
133 | allElementsChecked= false; | |
134 | } | |
135 | } | |
136 | if (allElementsChecked) { | |
137 | setChecked(true); | |
138 | } else { | |
139 | setChecked(false); | |
140 | } | |
141 | return true; | |
142 | } | |
143 | ||
144 | ||
145 | public void generated_5114698458974857780(IMenuManager menu) { | |
146 | if (canActionBeAdded()) { | |
147 | menu.appendToGroup(CallHierarchyViewPart.GROUP_FOCUS, this); | |
148 | } | |
149 | } | |
150 | } |