Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fb13cae6ca7f4fe69d7e6fa933f883c115b10075 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*****************************************************************************
 * Copyright (c) 2012 CEA LIST.
 *
 *    
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.timing.custom.edit.commands;

import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.RootEditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper;
import org.eclipse.swt.widgets.Display;

/**
 * Refresh the {@link IFigure} of a given {@link GraphicalEditPart}.
 */
public abstract class AbstractRefreshCommand extends Command {

	private final GraphicalEditPart editPartToRefresh;

	private final RootEditPart rootEditPart;

	public AbstractRefreshCommand(final GraphicalEditPart editPartToRefresh) {
		this.editPartToRefresh = editPartToRefresh;
		this.rootEditPart = editPartToRefresh.getRoot();
	}

	public GraphicalEditPart getEditPartToRefresh() {
		return this.editPartToRefresh;
	}

	protected void refresh() {
		Display.getDefault().asyncExec(new Runnable() {

			public void run() {
				if(AbstractRefreshCommand.this.editPartToRefresh.isActive()) {
					DiagramHelper.refresh(AbstractRefreshCommand.this.editPartToRefresh, true);
					// this is needed in order to update the bounds of the Figures from their layout manager constraints
					AbstractRefreshCommand.this.editPartToRefresh.getFigure().invalidateTree();
				} else if(AbstractRefreshCommand.this.rootEditPart.isActive()) {
					/*
					 * If the EditPart we needed to refresh is not active anymore, then it probably means that we undid its
					 * creation, and re-created the object as part of a redo, with a different EditPart. In this case, just
					 * refresh everything.
					 */
					DiagramHelper.refresh(AbstractRefreshCommand.this.rootEditPart, true);
				}
			}
		});
	}
}

Back to the top