blob: 5cc5a1d663325dec56a32fd3768c1777f18f2778 (
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
|
/*******************************************************************************
* Copyright (c) 2019 protos software gmbh (http://www.protos.de).
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* CONTRIBUTORS:
* Jan Belle (initial contribution)
*
*******************************************************************************/
package org.eclipse.etrice.core.common.ui.modelpath;
import java.util.Collection;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.etrice.core.common.ui.modelpath.ModelPathManager.IModelPathListener;
import org.eclipse.xtext.builder.impl.BuildScheduler;
import org.eclipse.xtext.builder.impl.IBuildFlag;
import org.eclipse.xtext.resource.impl.CoarseGrainedChangeEvent;
import org.eclipse.xtext.ui.editor.IDirtyStateManager;
import org.eclipse.xtext.ui.shared.contribution.IEagerContribution;
import com.google.inject.Inject;
/**
* Listens for modelpath changes and triggers a rebuild if necessary.
*/
@SuppressWarnings("restriction")
public class ModelPathChangeListener implements IEagerContribution, IModelPathListener {
private BuildScheduler buildScheduler;
private IDirtyStateManager dirtyStateManager;
@Inject
public ModelPathChangeListener(BuildScheduler buildScheduler, IDirtyStateManager dirtyStateManager) {
this.buildScheduler = buildScheduler;
this.dirtyStateManager = dirtyStateManager;
}
@Override
public void onChange(Collection<IProject> projects) {
// Notify xtext of modelpath changes
dirtyStateManager.notifyListeners(new CoarseGrainedChangeEvent());
// Trigger build for all projects if auto build is enabled
if(ResourcesPlugin.getWorkspace().isAutoBuilding()) {
buildScheduler.scheduleBuildIfNecessary(projects, IBuildFlag.FORGET_BUILD_STATE_ONLY);
}
}
@Override
public void initialize() {
ModelPathManager.INSTANCE.addListener(this);
ModelPathManager.INSTANCE.startListening();
}
@Override
public void discard() {
ModelPathManager.INSTANCE.stopListening();
ModelPathManager.INSTANCE.removeListener(this);
}
}
|