View | Details | Raw Unified | Return to bug 115905 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/gmf/runtime/diagram/ui/editpolicies/ResizableCompartmentEditPolicy.java (-9 / +127 lines)
Lines 13-19 Link Here
13
13
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.List;
15
import java.util.List;
16
import java.util.ListIterator;
16
17
18
import org.eclipse.draw2d.FigureListener;
17
import org.eclipse.draw2d.IFigure;
19
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.PositionConstants;
20
import org.eclipse.draw2d.PositionConstants;
19
import org.eclipse.draw2d.geometry.Dimension;
21
import org.eclipse.draw2d.geometry.Dimension;
Lines 22-27 Link Here
22
import org.eclipse.emf.transaction.TransactionalEditingDomain;
24
import org.eclipse.emf.transaction.TransactionalEditingDomain;
23
import org.eclipse.gef.EditPart;
25
import org.eclipse.gef.EditPart;
24
import org.eclipse.gef.EditPartListener;
26
import org.eclipse.gef.EditPartListener;
27
import org.eclipse.gef.LayerConstants;
25
import org.eclipse.gef.commands.Command;
28
import org.eclipse.gef.commands.Command;
26
import org.eclipse.gef.requests.ChangeBoundsRequest;
29
import org.eclipse.gef.requests.ChangeBoundsRequest;
27
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
30
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
Lines 29-39 Link Here
29
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
32
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
30
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
33
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
31
import org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart;
34
import org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart;
35
import org.eclipse.gmf.runtime.diagram.ui.editparts.TopGraphicEditPart;
32
import org.eclipse.gmf.runtime.diagram.ui.figures.BorderedNodeFigure;
36
import org.eclipse.gmf.runtime.diagram.ui.figures.BorderedNodeFigure;
33
import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
37
import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
34
import org.eclipse.gmf.runtime.diagram.ui.handles.CompartmentCollapseHandle;
38
import org.eclipse.gmf.runtime.diagram.ui.handles.CompartmentCollapseHandle;
35
import org.eclipse.gmf.runtime.diagram.ui.internal.handles.CompartmentResizeHandle;
39
import org.eclipse.gmf.runtime.diagram.ui.internal.handles.CompartmentResizeHandle;
36
import org.eclipse.gmf.runtime.notation.NotationPackage;
40
import org.eclipse.gmf.runtime.notation.NotationPackage;
41
import org.eclipse.jface.util.Assert;
37
42
38
/**
43
/**
39
 * A resizable editpolicy for resizable compartments. The editpolicy could be
44
 * A resizable editpolicy for resizable compartments. The editpolicy could be
Lines 45-50 Link Here
45
	extends ResizableEditPolicyEx {
50
	extends ResizableEditPolicyEx {
46
51
47
	private boolean horizontal;
52
	private boolean horizontal;
53
	
54
	/**
55
	 * Listener to determine bounds changes of compartment figure and/or its container
56
	 * to display or hide collapse handles accordingly (Bugzilla #115905)
57
	 */
58
	private FigureListener figureListener = new FigureListener() {
59
		public void figureMoved(IFigure source) {
60
			if (handles != null) {
61
				ResizableCompartmentFigure compartment = getCompartmentFigure();
62
				if (source.equals(compartment))
63
				{
64
					refreshCollapseHandles(getGraphicalEditPart()
65
							.getTopGraphicEditPart().getFigure().getBounds()
66
							.contains(source.getBounds()));
67
					Dimension minClientDimension = compartment.getMinClientDimension();
68
					
69
					/* If compartment size cannot become smaller, we'll be looking at its
70
					 * container figure bounds changes. If compartment can decrease its size
71
					 * we don't need to look at its container figure bounds changes */
72
					if (compartment.getBounds().width <= minClientDimension.width+1 
73
							|| compartment.getBounds().height <= minClientDimension.height+1)
74
						getGraphicalEditPart().getTopGraphicEditPart().getFigure().addFigureListener(this);
75
					else
76
						getGraphicalEditPart().getTopGraphicEditPart().getFigure().removeFigureListener(this);
77
				}
78
				else if (source.equals(getGraphicalEditPart().getTopGraphicEditPart().getFigure()))
79
					refreshCollapseHandles(source.getBounds().contains(compartment.getBounds()));
80
			}
81
		}
82
	};
48
83
49
	/**
84
	/**
50
	 * Creates a new vertical ResizableCompartmentEditPolicy
85
	 * Creates a new vertical ResizableCompartmentEditPolicy
Lines 79-88 Link Here
79
		IGraphicalEditPart part = (IGraphicalEditPart) getHost();
114
		IGraphicalEditPart part = (IGraphicalEditPart) getHost();
80
115
81
		List collapseHandles = new ArrayList();
116
		List collapseHandles = new ArrayList();
117
		
82
		collapseHandles.add(new CompartmentCollapseHandle(part));
118
		collapseHandles.add(new CompartmentCollapseHandle(part));
83
		return collapseHandles;
119
		return collapseHandles;
84
	}
120
	}
85
121
	
86
	/**
122
	/**
87
	 * @see org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#createSelectionHandles()
123
	 * @see org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#createSelectionHandles()
88
	 */
124
	 */
Lines 93-99 Link Here
93
		int d2 = isHorizontal() ? PositionConstants.EAST
129
		int d2 = isHorizontal() ? PositionConstants.EAST
94
			: PositionConstants.SOUTH;
130
			: PositionConstants.SOUTH;
95
		List selectionHandles = new ArrayList();
131
		List selectionHandles = new ArrayList();
96
		selectionHandles.addAll(createCollapseHandles());
132
		
133
		TopGraphicEditPart wrapper = part.getTopGraphicEditPart();
134
		if ( wrapper == null || wrapper.getFigure().getBounds().contains(getCompartmentFigure().getBounds()) )
135
			selectionHandles.addAll(createCollapseHandles());
136
		
97
		selectionHandles.add(new CompartmentResizeHandle(part, d1));
137
		selectionHandles.add(new CompartmentResizeHandle(part, d1));
98
		selectionHandles.add(new CompartmentResizeHandle(part, d2));
138
		selectionHandles.add(new CompartmentResizeHandle(part, d2));
99
		return selectionHandles;
139
		return selectionHandles;
Lines 133-141 Link Here
133
	 */
173
	 */
134
	protected void showSelection() {
174
	protected void showSelection() {
135
		super.showSelection();
175
		super.showSelection();
136
		if (getHost().getSelected() != EditPart.SELECTED_NONE) {
176
		if (getGraphicalEditPart().getTopGraphicEditPart() != null)
137
			ResizableCompartmentFigure compartmentFigure = getCompartmentFigure();
177
			getGraphicalEditPart().getTopGraphicEditPart().getFigure().addFigureListener(figureListener);
138
			if (compartmentFigure != null) {
178
		ResizableCompartmentFigure compartmentFigure = getCompartmentFigure();
179
		if (compartmentFigure != null) {
180
			compartmentFigure.addFigureListener(figureListener);
181
			if (getHost().getSelected() != EditPart.SELECTED_NONE) {
139
				compartmentFigure.setSelected(true);
182
				compartmentFigure.setSelected(true);
140
			}
183
			}
141
		}
184
		}
Lines 146-154 Link Here
146
	 */
189
	 */
147
	protected void hideSelection() {
190
	protected void hideSelection() {
148
		super.hideSelection();
191
		super.hideSelection();
149
		if (getHost().getSelected() == EditPart.SELECTED_NONE) {
192
		if (getGraphicalEditPart().getTopGraphicEditPart() != null)
150
			ResizableCompartmentFigure compartmentFigure = getCompartmentFigure();
193
			getGraphicalEditPart().getTopGraphicEditPart().getFigure().removeFigureListener(figureListener);
151
			if (compartmentFigure != null) {
194
		ResizableCompartmentFigure compartmentFigure = getCompartmentFigure();
195
		if (compartmentFigure != null) {
196
			compartmentFigure.removeFigureListener(figureListener);
197
			if (getHost().getSelected() == EditPart.SELECTED_NONE) {
152
				compartmentFigure.setSelected(false);
198
				compartmentFigure.setSelected(false);
153
			}
199
			}
154
		}
200
		}
Lines 185-194 Link Here
185
231
186
			public void notifyChanged(Notification notification) {
232
			public void notifyChanged(Notification notification) {
187
				if (NotationPackage.eINSTANCE.getView_Visible().equals(
233
				if (NotationPackage.eINSTANCE.getView_Visible().equals(
188
					notification.getFeature()))
234
						notification.getFeature()))
189
					setSelectedState();
235
					setSelectedState();
190
			}
236
			}
191
		};
237
		};
238
				
192
		getDiagramEventBroker().addNotificationListener(
239
		getDiagramEventBroker().addNotificationListener(
193
			getGraphicalEditPart().getNotationView(), propertyListener);
240
			getGraphicalEditPart().getNotationView(), propertyListener);
194
	}
241
	}
Lines 291-294 Link Here
291
        }
338
        }
292
        return null;
339
        return null;
293
    }
340
    }
341
    
342
    /**
343
     * Refreshes collapse handles - displays them if they need to be displayed but not displaying
344
     * and removes them if they shouldn't be displayed, but are displayed.
345
     * Method assumes that handles are not <code>null</code>, i.e. handles are being displayed
346
     *  
347
     * @param shouldHaveHandles <code>true</code> if collapse handles need to be displayed 
348
     */
349
    private void refreshCollapseHandles(boolean shouldHaveHandles)
350
    {
351
    	Assert.isTrue(handles!=null);
352
353
    	boolean hasHandles = dispalyingCollapseHandles();
354
    	
355
    	if (shouldHaveHandles && !hasHandles)
356
    		addCollapseHandles();
357
    	else if (!shouldHaveHandles && hasHandles)
358
    		removeCollapseHandles();
359
    }
360
    
361
    /**
362
     * Adds collapse handles to the list of handles and displays them
363
     * Method assumes that handles are not <code>null</code>, i.e. handles are being displayed 
364
     */
365
    private void addCollapseHandles()
366
    {
367
    	Assert.isTrue(handles!=null);
368
		List collapseHandles = createCollapseHandles();
369
		IFigure layer = getLayer(LayerConstants.HANDLE_LAYER);
370
		handles.addAll(collapseHandles);
371
		for (ListIterator handlesIterator = collapseHandles
372
				.listIterator(); handlesIterator.hasNext();)
373
			layer.add((IFigure) handlesIterator.next());    	
374
    }
375
    
376
    /**
377
     * Tries to remove collapse handles if any displayed
378
     * Method assumes that handles are not <code>null</code>, i.e. handles are being displayed 
379
     * 
380
     */
381
    private void removeCollapseHandles()
382
    {
383
    	Assert.isTrue(handles!=null);
384
		IFigure layer = getLayer(LayerConstants.HANDLE_LAYER);
385
		for (ListIterator handlesIterator = handles.listIterator(); handlesIterator.hasNext();)
386
		{
387
			IFigure handle = (IFigure) handlesIterator.next();
388
			if (handle instanceof CompartmentCollapseHandle) {
389
				layer.remove(handle);
390
				handlesIterator.remove();
391
			}
392
		}    	
393
    }
394
    
395
    /**
396
     * Checks whether connection handles are being displayed.
397
     * Method assumes that handles are not <code>null</code>, i.e. handles are being displayed 
398
     * 
399
     * @return <code>true</code> if collapse handles are being displayed
400
     */
401
    private boolean dispalyingCollapseHandles()
402
    {
403
    	Assert.isTrue(handles!=null);
404
    	for (ListIterator handlesIterator = handles.listIterator(); handlesIterator.hasNext();)
405
		{
406
			if (handlesIterator.next() instanceof CompartmentCollapseHandle)
407
				return true;
408
		}
409
		return false;
410
    }
411
    
294
}
412
}

Return to bug 115905