Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 143198 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/gmf/runtime/diagram/ui/internal/DiagramEventBrokerThreadSafe.java (-39 / +16 lines)
Lines 11-26 Link Here
11
package org.eclipse.gmf.runtime.diagram.ui.internal;
11
package org.eclipse.gmf.runtime.diagram.ui.internal;
12
12
13
import java.lang.ref.WeakReference;
13
import java.lang.ref.WeakReference;
14
import java.util.Iterator;
15
import java.util.Set;
16
14
17
import org.eclipse.emf.common.notify.Notification;
18
import org.eclipse.emf.transaction.ResourceSetChangeEvent;
15
import org.eclipse.emf.transaction.ResourceSetChangeEvent;
19
import org.eclipse.emf.transaction.TransactionalEditingDomain;
16
import org.eclipse.emf.transaction.TransactionalEditingDomain;
20
import org.eclipse.gef.EditPartViewer;
21
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
17
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
22
import org.eclipse.gmf.runtime.diagram.ui.internal.parts.NotificationForEditPartsListener;
23
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
24
import org.eclipse.swt.widgets.Display;
18
import org.eclipse.swt.widgets.Display;
25
import org.eclipse.ui.PlatformUI;
19
import org.eclipse.ui.PlatformUI;
26
20
Lines 34-41 Link Here
34
 * that has been exeucted with a progress meter, where the progress meter is displaying UI on the main
28
 * that has been exeucted with a progress meter, where the progress meter is displaying UI on the main
35
 * thread and there is a background thread that is being executed that the progress meter is monitoring.
29
 * thread and there is a background thread that is being executed that the progress meter is monitoring.
36
 * For this scenario, the UI updates on the diagram viewer have been disabled so as to avoid concurrency
30
 * For this scenario, the UI updates on the diagram viewer have been disabled so as to avoid concurrency
37
 * issues and it is desirable that the notifications continue to be handled on the worker thread so that
31
 * issues.  When notifications are handled, they are synchronized to the main thread to avoid
38
 * the progress meter doesn't lock up.
32
 * SWTExceptions when UI tries to access SWT resources when updating figures or other UI.
39
 * 
33
 * 
40
 * The second scenario is for when a job has been executed on a worker thread, but has not been executed
34
 * The second scenario is for when a job has been executed on a worker thread, but has not been executed
41
 * through the OperationHistory.  Consequently, there is no hook for turning off display updates.  This
35
 * through the OperationHistory.  Consequently, there is no hook for turning off display updates.  This
Lines 60-103 Link Here
60
     * @see org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker#resourceSetChanged(org.eclipse.emf.transaction.ResourceSetChangeEvent)
54
     * @see org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker#resourceSetChanged(org.eclipse.emf.transaction.ResourceSetChangeEvent)
61
     */
55
     */
62
    public void resourceSetChanged(ResourceSetChangeEvent event) {
56
    public void resourceSetChanged(ResourceSetChangeEvent event) {
63
        if (Display.getCurrent() == null) {
57
        if (shouldSynchronizeWithMainThread(event)) {
64
        	if (shouldSynchronizeWithMainThread(event)) {
58
           	// force synchronization with the main thread
65
            	// force synchronization with the main thread
59
            final ResourceSetChangeEvent eventToHandle = event;
66
                final ResourceSetChangeEvent eventToHandle = event;
60
            TransactionalEditingDomain editingDomain = (TransactionalEditingDomain)editingDomainRef.get();
67
                TransactionalEditingDomain editingDomain = (TransactionalEditingDomain)editingDomainRef.get();
61
            if (editingDomain != null) {
68
                if (editingDomain != null) {
62
	            PlatformUI.getWorkbench().getDisplay().syncExec(editingDomain.createPrivilegedRunnable(new Runnable() { 
69
	                PlatformUI.getWorkbench().getDisplay().syncExec(editingDomain.createPrivilegedRunnable(new Runnable() { 
63
	                public void run() {
70
	                    public void run() {
64
	                    internal_resourceSetChanged(eventToHandle);
71
	                        internal_resourceSetChanged(eventToHandle);
65
	                }
72
	                    }
66
	            }));
73
	                }));
74
	                
67
	                
75
	                return;
68
	            return;
76
                }
69
            }
77
        	}
78
        }
70
        }
79
        
71
        
80
        super.resourceSetChanged(event);
72
        super.resourceSetChanged(event);
81
    }
73
    }
82
    
74
    
83
    private boolean shouldSynchronizeWithMainThread(ResourceSetChangeEvent event) {
75
    private boolean shouldSynchronizeWithMainThread(ResourceSetChangeEvent event) {
84
    	
76
    	if (Display.getCurrent() == null)
85
    	for (Iterator i = event.getNotifications().iterator(); i.hasNext();) {
77
    		return true;
86
        	final Notification notification = (Notification) i.next();
87
        	Set nlSet = getInterestedNotificationListeners(notification, false);
88
        	Iterator iter = nlSet.iterator();
89
        	while (iter.hasNext()) {
90
        		Object listener = iter.next();
91
            	if (listener instanceof NotificationForEditPartsListener) {
92
            		EditPartViewer viewer = ((NotificationForEditPartsListener)listener).getViewer();
93
            		if (viewer instanceof DiagramGraphicalViewer) {
94
                        if (!((DiagramGraphicalViewer)viewer).areUpdatesDisabled()) {
95
                        	return true;
96
                        }
97
                    }
98
            	}
99
        	}
100
         }
101
        
78
        
102
        return false;
79
        return false;
103
    }
80
    }
(-)src/org/eclipse/gmf/runtime/diagram/ui/commands/DeferredLayoutCommand.java (-31 / +63 lines)
Lines 23-29 Link Here
23
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.runtime.IAdaptable;
24
import org.eclipse.core.runtime.IAdaptable;
25
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IStatus;
26
import org.eclipse.draw2d.IFigure;
27
import org.eclipse.draw2d.IFigure;
28
import org.eclipse.emf.transaction.RunnableWithResult;
27
import org.eclipse.emf.transaction.TransactionalEditingDomain;
29
import org.eclipse.emf.transaction.TransactionalEditingDomain;
28
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
30
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
29
import org.eclipse.gef.commands.Command;
31
import org.eclipse.gef.commands.Command;
Lines 33-38 Link Here
33
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
35
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
34
import org.eclipse.gmf.runtime.diagram.ui.requests.ArrangeRequest;
36
import org.eclipse.gmf.runtime.diagram.ui.requests.ArrangeRequest;
35
import org.eclipse.gmf.runtime.diagram.ui.services.layout.LayoutType;
37
import org.eclipse.gmf.runtime.diagram.ui.services.layout.LayoutType;
38
import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
36
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
39
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
37
import org.eclipse.gmf.runtime.notation.View;
40
import org.eclipse.gmf.runtime.notation.View;
38
41
Lines 121-159 Link Here
121
            IProgressMonitor progressMonitor, IAdaptable info)
124
            IProgressMonitor progressMonitor, IAdaptable info)
122
        throws ExecutionException {
125
        throws ExecutionException {
123
126
124
		containerEP.refresh();
127
		RunnableWithResult refreshRunnable = new RunnableWithResult() {
125
		
128
			
126
		// The layout command requires that the figure world is updated.
129
			private IStatus status;
127
		getContainerFigure().invalidate();
130
            private Object result;
128
		getContainerFigure().validate();
131
129
132
            public Object getResult() {
130
		List editParts = new ArrayList(viewAdapters.size());
133
                return result;
131
		Map epRegistry = containerEP.getRoot().getViewer()
134
            }
132
			.getEditPartRegistry();
135
133
		for (Iterator iter = viewAdapters.iterator(); iter.hasNext();) {
136
            public void setStatus(IStatus status) {
134
			IAdaptable ad = (IAdaptable) iter.next();
137
                this.status = status;
135
			View view = (View) ad.getAdapter(View.class);
138
            }
136
			Object ep = epRegistry.get(view);
139
137
			if (ep != null) {
140
            public IStatus getStatus() {
138
				editParts.add(ep);
141
                return status;
142
            }
143
            
144
			public void run() {
145
				containerEP.refresh();
146
				
147
				// The layout command requires that the figure world is updated.
148
				getContainerFigure().invalidate();
149
				getContainerFigure().validate();
150
151
				List editParts = new ArrayList(viewAdapters.size());
152
				Map epRegistry = containerEP.getRoot().getViewer()
153
					.getEditPartRegistry();
154
				for (Iterator iter = viewAdapters.iterator(); iter.hasNext();) {
155
					IAdaptable ad = (IAdaptable) iter.next();
156
					View view = (View) ad.getAdapter(View.class);
157
					Object ep = epRegistry.get(view);
158
					if (ep != null) {
159
						editParts.add(ep);
160
					}
161
				}
162
163
				if (editParts.isEmpty()) {
164
					result = editParts;
165
					return;
166
				}
167
168
				Set layoutSet = new HashSet(editParts.size());
169
				layoutSet.addAll(editParts);
170
				
171
				// refresh source and target connections of any shapes in the container not being considered for layout
172
				Iterator iter = containerEP.getChildren().iterator();
173
				while (iter.hasNext()) {
174
					Object obj = iter.next();
175
					if (!layoutSet.contains(obj) && obj instanceof IGraphicalEditPart) {
176
						IGraphicalEditPart ep = (IGraphicalEditPart)obj;
177
						ep.refresh();
178
					}
179
				}
180
				
181
				result = editParts;
139
			}
182
			}
140
		}
183
		};
141
142
		if (editParts.isEmpty()) {
143
			return CommandResult.newOKCommandResult();
144
		}
145
146
		Set layoutSet = new HashSet(editParts.size());
147
		layoutSet.addAll(editParts);
148
		
184
		
149
		// refresh source and target connections of any shapes in the container not being considered for layout
185
		EditPartUtil.synchronizeRunnableToMainThread(containerEP, refreshRunnable);
150
		Iterator iter = containerEP.getChildren().iterator();
186
		List editParts = (List)refreshRunnable.getResult();
151
		while (iter.hasNext()) {
187
		if (editParts == null || editParts.isEmpty()) {
152
			Object obj = iter.next();
188
			return CommandResult.newOKCommandResult();
153
			if (!layoutSet.contains(obj) && obj instanceof IGraphicalEditPart) {
154
				IGraphicalEditPart ep = (IGraphicalEditPart)obj;
155
				ep.refresh();
156
			}
157
		}
189
		}
158
		
190
		
159
		//	add an arrange command, to layout the related shapes
191
		//	add an arrange command, to layout the related shapes
(-)src/org/eclipse/gmf/runtime/diagram/ui/internal/parts/NotificationForEditPartsListener.java (-30 lines)
Removed Link Here
1
/******************************************************************************
2
 * Copyright (c) 2006 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
 * Contributors:
9
 *    IBM Corporation - initial API and implementation 
10
 ****************************************************************************/
11
12
package org.eclipse.gmf.runtime.diagram.ui.internal.parts;
13
14
import org.eclipse.gef.EditPartViewer;
15
import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
16
17
/**
18
 * This class is an extension of the <code>NotificationListener</code> interface to allow clients
19
 * handling the listener to determine which viewer the notification is relevant for.
20
 * 
21
 * @author sshaw
22
 *
23
 */
24
public interface NotificationForEditPartsListener extends NotificationListener {
25
	
26
	/**
27
	 * @return
28
	 */
29
	public EditPartViewer getViewer();
30
}
(-)src/org/eclipse/gmf/runtime/diagram/ui/util/EditPartUtil.java (-14 / +6 lines)
Lines 60-80 Link Here
60
	 */
60
	 */
61
	public static void synchronizeRunnableToMainThread(IGraphicalEditPart editPart, Runnable runThreadSafe) {
61
	public static void synchronizeRunnableToMainThread(IGraphicalEditPart editPart, Runnable runThreadSafe) {
62
		if (Display.getCurrent() == null) {
62
		if (Display.getCurrent() == null) {
63
			EditPartViewer viewer = editPart.getViewer();
63
			TransactionalEditingDomain editingDomain = (TransactionalEditingDomain)editPart.getEditingDomain();
64
			if (viewer instanceof DiagramGraphicalViewer) {
64
	        if (editingDomain != null) {
65
	            if (!((DiagramGraphicalViewer)viewer).areUpdatesDisabled()) {
65
	        	PlatformUI.getWorkbench().getDisplay().syncExec(editingDomain.createPrivilegedRunnable(runThreadSafe));
66
	            	TransactionalEditingDomain editingDomain = (TransactionalEditingDomain)editPart.getEditingDomain();
66
	            return;
67
	                if (editingDomain != null) {
68
	                    PlatformUI.getWorkbench().getDisplay().syncExec(editingDomain.createPrivilegedRunnable(runThreadSafe));
69
	                    return;
70
	                }
71
	            }
72
	            else {
73
					PlatformUI.getWorkbench().getDisplay().asyncExec(runThreadSafe);
74
				}
75
	        }
67
	        }
76
			else {
68
	        else {
77
				PlatformUI.getWorkbench().getDisplay().asyncExec(runThreadSafe);
69
	        	PlatformUI.getWorkbench().getDisplay().asyncExec(runThreadSafe);
78
			}
70
			}
79
		}
71
		}
80
		else {
72
		else {
(-)src/org/eclipse/gmf/runtime/diagram/ui/editpolicies/CanonicalEditPolicy.java (-2 / +1 lines)
Lines 63-69 Link Here
63
import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIDebugOptions;
63
import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIDebugOptions;
64
import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIPlugin;
64
import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIPlugin;
65
import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIStatusCodes;
65
import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIStatusCodes;
66
import org.eclipse.gmf.runtime.diagram.ui.internal.parts.NotificationForEditPartsListener;
67
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
66
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
68
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
67
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
69
import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
68
import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
Lines 98-104 Link Here
98
 * @author mhanner
97
 * @author mhanner
99
 */
98
 */
100
public abstract class CanonicalEditPolicy extends AbstractEditPolicy 
99
public abstract class CanonicalEditPolicy extends AbstractEditPolicy 
101
implements NotificationForEditPartsListener {
100
implements NotificationListener {
102
	
101
	
103
	/** Runs the supplied commands asyncronously. */
102
	/** Runs the supplied commands asyncronously. */
104
	private static class AsyncCommand extends Command {
103
	private static class AsyncCommand extends Command {
(-)src/org/eclipse/gmf/runtime/diagram/ui/editparts/GraphicalEditPart.java (-2 / +1 lines)
Lines 69-75 Link Here
69
import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.DummyEditPart;
69
import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.DummyEditPart;
70
import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.IEditableEditPart;
70
import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.IEditableEditPart;
71
import org.eclipse.gmf.runtime.diagram.ui.internal.l10n.DiagramFontRegistry;
71
import org.eclipse.gmf.runtime.diagram.ui.internal.l10n.DiagramFontRegistry;
72
import org.eclipse.gmf.runtime.diagram.ui.internal.parts.NotificationForEditPartsListener;
73
import org.eclipse.gmf.runtime.diagram.ui.internal.services.editpolicy.EditPolicyService;
72
import org.eclipse.gmf.runtime.diagram.ui.internal.services.editpolicy.EditPolicyService;
74
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
73
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
75
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain;
74
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain;
Lines 107-113 Link Here
107
 */
106
 */
108
public abstract class GraphicalEditPart
107
public abstract class GraphicalEditPart
109
	extends AbstractGraphicalEditPart
108
	extends AbstractGraphicalEditPart
110
	implements IGraphicalEditPart, IAdaptableSelection, NotificationForEditPartsListener {
109
	implements IGraphicalEditPart, IAdaptableSelection, NotificationListener {
111
  
110
  
112
    /** A map of listener filters ids to filter data */
111
    /** A map of listener filters ids to filter data */
113
	private Map listenerFilters;
112
	private Map listenerFilters;
(-)src/org/eclipse/gmf/runtime/diagram/ui/editparts/ConnectionEditPart.java (-2 / +1 lines)
Lines 76-82 Link Here
76
import org.eclipse.gmf.runtime.diagram.ui.internal.editpolicies.ConnectionLineSegEditPolicy;
76
import org.eclipse.gmf.runtime.diagram.ui.internal.editpolicies.ConnectionLineSegEditPolicy;
77
import org.eclipse.gmf.runtime.diagram.ui.internal.editpolicies.TreeConnectionBendpointEditPolicy;
77
import org.eclipse.gmf.runtime.diagram.ui.internal.editpolicies.TreeConnectionBendpointEditPolicy;
78
import org.eclipse.gmf.runtime.diagram.ui.internal.l10n.DiagramFontRegistry;
78
import org.eclipse.gmf.runtime.diagram.ui.internal.l10n.DiagramFontRegistry;
79
import org.eclipse.gmf.runtime.diagram.ui.internal.parts.NotificationForEditPartsListener;
80
import org.eclipse.gmf.runtime.diagram.ui.internal.properties.Properties;
79
import org.eclipse.gmf.runtime.diagram.ui.internal.properties.Properties;
81
import org.eclipse.gmf.runtime.diagram.ui.internal.services.editpolicy.EditPolicyService;
80
import org.eclipse.gmf.runtime.diagram.ui.internal.services.editpolicy.EditPolicyService;
82
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
81
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
Lines 125-131 Link Here
125
abstract public class ConnectionEditPart
124
abstract public class ConnectionEditPart
126
	extends AbstractConnectionEditPart
125
	extends AbstractConnectionEditPart
127
	implements IGraphicalEditPart, PropertyChangeListener, IContainedEditPart,
126
	implements IGraphicalEditPart, PropertyChangeListener, IContainedEditPart,
128
	IPrimaryEditPart, NotificationForEditPartsListener {
127
	IPrimaryEditPart, NotificationListener {
129
128
130
	/** A map of listener filters ids to filter data */
129
	/** A map of listener filters ids to filter data */
131
	private Map listenerFilters;
130
	private Map listenerFilters;

Return to bug 143198