| /** |
| * Copyright (c) 2011, 2014 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * 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: |
| * Florian Pirchner - Initial implementation |
| */ |
| package org.eclipse.osbp.vaaclipse.addons.common.status; |
| |
| import java.util.ArrayList; |
| import java.util.Collections; |
| import java.util.HashMap; |
| import java.util.List; |
| import java.util.Map; |
| |
| import javax.annotation.PreDestroy; |
| import javax.inject.Inject; |
| |
| import org.eclipse.e4.core.contexts.Active; |
| import org.eclipse.e4.core.di.annotations.Optional; |
| import org.eclipse.e4.core.services.events.IEventBroker; |
| import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
| import org.eclipse.e4.ui.workbench.modeling.EPartService; |
| import org.eclipse.osbp.runtime.common.validation.IStatus; |
| import org.eclipse.osbp.vaaclipse.addons.common.api.IE4Topics; |
| import org.eclipse.osbp.vaaclipse.addons.common.api.status.IStatusManager; |
| import org.eclipse.osbp.vaaclipse.addons.common.api.status.IStatusScope; |
| |
| /** |
| * The Class StatusManager. |
| */ |
| public class StatusManager implements IStatusManager { |
| |
| /** The scopes. */ |
| private final Map<MPart, IStatusScope> scopes = new HashMap<MPart, IStatusScope>(); |
| |
| /** The event broker. */ |
| @Inject |
| private IEventBroker eventBroker; |
| |
| /** The part service. */ |
| @Inject |
| private EPartService partService; |
| |
| /** The active part. */ |
| private MPart activePart; |
| |
| /** |
| * Instantiates a new status manager. |
| */ |
| public StatusManager() { |
| |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.vaaclipse.addons.common.api.status.IStatusManager#getAllStatus() |
| */ |
| @Override |
| public List<IStatus> getAllStatus() { |
| IStatusScope scope = getActiveScope(); |
| if (scope == null) { |
| return Collections.emptyList(); |
| } |
| |
| return scope.getAllStatus(); |
| } |
| |
| /** |
| * Returns the scope of the currently active MPart. |
| * |
| * @return the active scope |
| */ |
| public IStatusScope getActiveScope() { |
| return scopes.get(activePart); |
| } |
| |
| /** |
| * Sets the active view. |
| * |
| * @param activePart |
| * the new active view |
| */ |
| @Inject |
| public void setActiveView(@Active @Optional MPart activePart) { |
| |
| this.activePart = activePart; |
| if (activePart == null) { |
| return; |
| } |
| ensureScope(this.activePart); |
| |
| Map<String, Object> props = new HashMap<String, Object>(); |
| props.put(IE4Topics.StatusManagerEvents.PROP_SCOPE, getActiveScope()); |
| eventBroker |
| .post(IE4Topics.StatusManagerEvents.ACTIVE_SCOPE_CHANGED_TOPIC, |
| props); |
| } |
| |
| /** |
| * Ensure scope. |
| * |
| * @param mPart |
| * the m part |
| */ |
| protected void ensureScope(MPart mPart) { |
| if (mPart == null) { |
| return; |
| } |
| |
| if (!scopes.containsKey(mPart)) { |
| IStatusScope scope = new StatusScope(mPart, eventBroker); |
| scopes.put(mPart, scope); |
| } |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.vaaclipse.addons.common.api.status.IStatusManager#getAllScopes() |
| */ |
| @Override |
| public List<IStatusScope> getAllScopes() { |
| return Collections.unmodifiableList(new ArrayList<IStatusScope>(scopes |
| .values())); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.vaaclipse.addons.common.api.status.IStatusManager#getScopeFor(org.eclipse.e4.ui.model.application.ui.basic.MPart) |
| */ |
| @Override |
| public IStatusScope getScopeFor(MPart mPart) { |
| ensureScope(mPart); |
| return scopes.get(mPart); |
| } |
| |
| /** |
| * Dispose. |
| */ |
| @PreDestroy |
| protected void dispose() { |
| scopes.clear(); |
| activePart = null; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.vaaclipse.addons.common.api.status.IStatusManager#getAllScopeStatus() |
| */ |
| @Override |
| public List<IStatus> getAllScopeStatus() { |
| List<IStatus> result = new ArrayList<>(); |
| for(IStatusScope scope : getAllScopes()) { |
| result.addAll(scope.getAllStatus()); |
| } |
| return result; |
| } |
| } |