Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 681a6799f0f0b9780d4a02a35b7f640c9dede9de (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*******************************************************************************
 * Copyright (c) 2016 Obeo.
 * 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
 *
 * Contributors:
 *    Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.eef.ide.ui.internal;

import java.util.List;

import org.eclipse.eef.common.ui.api.IEEFFormContainer;
import org.eclipse.eef.core.api.controllers.IConsumer;
import org.eclipse.eef.ide.ui.api.EEFTab;
import org.eclipse.emf.common.notify.Notification;

/**
 * A post-commit listener which refreshes the whole page when a significant change (an actual modification of a model
 * element) occurs in the current editing domain.
 *
 * @author pcdavid
 */
public class Updater implements IConsumer<List<Notification>> {

	/**
	 * The top-level page the section is part of.
	 */
	private final IEEFFormContainer formContainer;

	/**
	 * The section to refresh.
	 */
	private final EEFTab section;

	/**
	 * Creates a new updater.
	 *
	 * @param section
	 *            The section to refresh.
	 * @param formContainer
	 *            The container of the form.
	 */
	public Updater(EEFTab section, IEEFFormContainer formContainer) {
		this.section = section;
		this.formContainer = formContainer;
	}

	/**
	 * Start listening to changes from the current editing domain.
	 */
	public void enable() {
		disable();
		section.getEEFPage().getView().getContextAdapter().onModelChange(this);
	}

	/**
	 * Stop listening to changes from the editing domain.
	 */
	public void disable() {
		section.getEEFPage().getView().getContextAdapter().removeModelChangeConsumer();
	}

	@Override
	public void apply(List<Notification> value) {
		formContainer.refreshPage();
	}
}

Back to the top