Lines 22-27
Link Here
|
22 |
import org.eclipse.jface.viewers.IStructuredSelection; |
22 |
import org.eclipse.jface.viewers.IStructuredSelection; |
23 |
import org.eclipse.jface.viewers.StructuredSelection; |
23 |
import org.eclipse.jface.viewers.StructuredSelection; |
24 |
|
24 |
|
|
|
25 |
import org.eclipse.draw2d.IFigure; |
26 |
import org.eclipse.draw2d.geometry.Rectangle; |
27 |
|
25 |
/** |
28 |
/** |
26 |
* Manages a viewer's selection model. Selection management includes representing a form |
29 |
* Manages a viewer's selection model. Selection management includes representing a form |
27 |
* of selection which is available to clients of a viewer as an ISelection. It also |
30 |
* of selection which is available to clients of a viewer as an ISelection. It also |
Lines 62-79
Link Here
|
62 |
* @since 3.2 |
65 |
* @since 3.2 |
63 |
*/ |
66 |
*/ |
64 |
public void appendSelection(EditPart editpart) { |
67 |
public void appendSelection(EditPart editpart) { |
65 |
if (editpart != getFocus()) |
68 |
if (canSelectEditPart(editpart)) { |
66 |
viewer.setFocus(null); |
69 |
if (editpart != getFocus()) |
67 |
if (!selection.isEmpty()) { |
70 |
viewer.setFocus(null); |
68 |
EditPart primary = (EditPart)selection.get(selection.size() - 1); |
71 |
if (!selection.isEmpty()) { |
69 |
primary.setSelected(EditPart.SELECTED); |
72 |
EditPart primary = (EditPart)selection.get(selection.size() - 1); |
70 |
} |
73 |
primary.setSelected(EditPart.SELECTED); |
71 |
// if the editpart is already in the list, re-order it to be the last one |
74 |
} |
72 |
selection.remove(editpart); |
75 |
// if the editpart is already in the list, re-order it to be the last one |
73 |
selection.add(editpart); |
76 |
selection.remove(editpart); |
74 |
editpart.setSelected(EditPart.SELECTED_PRIMARY); |
77 |
selection.add(editpart); |
75 |
|
78 |
editpart.setSelected(EditPart.SELECTED_PRIMARY); |
76 |
fireSelectionChanged(); |
79 |
|
|
|
80 |
fireSelectionChanged(); |
81 |
} |
77 |
} |
82 |
} |
78 |
|
83 |
|
79 |
/** |
84 |
/** |
Lines 219-233
Link Here
|
219 |
Iterator itr = orderedSelection.iterator(); |
224 |
Iterator itr = orderedSelection.iterator(); |
220 |
while (true) { |
225 |
while (true) { |
221 |
EditPart part = (EditPart)itr.next(); |
226 |
EditPart part = (EditPart)itr.next(); |
222 |
selection.add(part); |
227 |
if (canSelectEditPart(part)) { |
223 |
if (!itr.hasNext()) { |
228 |
selection.add(part); |
224 |
part.setSelected(EditPart.SELECTED_PRIMARY); |
229 |
if (!itr.hasNext()) { |
225 |
break; |
230 |
part.setSelected(EditPart.SELECTED_PRIMARY); |
226 |
} |
231 |
break; |
227 |
part.setSelected(EditPart.SELECTED); |
232 |
} |
|
|
233 |
part.setSelected(EditPart.SELECTED); |
234 |
} |
228 |
} |
235 |
} |
229 |
} |
236 |
} |
230 |
fireSelectionChanged(); |
237 |
fireSelectionChanged(); |
231 |
} |
238 |
} |
232 |
|
239 |
|
|
|
240 |
private boolean isFigureVisible(IFigure fig) { |
241 |
Rectangle figBounds = fig.getBounds().getCopy(); |
242 |
IFigure walker = fig.getParent(); |
243 |
while (!figBounds.isEmpty() && walker != null) { |
244 |
walker.translateToParent(figBounds); |
245 |
figBounds.intersect(walker.getBounds()); |
246 |
walker = walker.getParent(); |
247 |
} |
248 |
return !figBounds.isEmpty(); |
249 |
} |
250 |
|
251 |
public boolean canSelectEditPart(EditPart ep) { |
252 |
if (ep.isSelectable()) { |
253 |
if (ep instanceof GraphicalEditPart) { |
254 |
GraphicalEditPart gep = (GraphicalEditPart)ep; |
255 |
IFigure fig = gep.getFigure(); |
256 |
return gep.getTargetEditPart(new Request(RequestConstants.REQ_SELECTION))==gep |
257 |
&& isFigureVisible(fig) |
258 |
&& fig.isShowing(); |
259 |
} |
260 |
else { |
261 |
return true; |
262 |
} |
263 |
} |
264 |
return false; |
265 |
} |
266 |
|
233 |
} |
267 |
} |