| /** |
| * 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.ecview; |
| |
| import java.util.ArrayList; |
| import java.util.Collections; |
| import java.util.List; |
| |
| import org.eclipse.e4.core.contexts.IEclipseContext; |
| import org.eclipse.osbp.runtime.common.validation.Status; |
| import org.eclipse.osbp.vaaclipse.addons.common.api.explorer.AbstractExplorerInfo; |
| import org.eclipse.osbp.vaaclipse.addons.common.api.explorer.IExplorerCategory; |
| import org.eclipse.osbp.vaaclipse.addons.common.api.explorer.IExplorerInfo; |
| import org.eclipse.osbp.vaaclipse.addons.common.api.explorer.IExplorerInfoManager; |
| import org.eclipse.osbp.vaaclipse.addons.common.api.status.IStatusManager; |
| import org.osgi.framework.FrameworkUtil; |
| import org.osgi.util.tracker.ServiceTracker; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| /** |
| * The Class ExplorerCategory. |
| */ |
| public class ExplorerCategory extends AbstractExplorerInfo implements |
| IExplorerCategory { |
| |
| /** The Constant LOGGER. */ |
| private static final Logger LOGGER = LoggerFactory |
| .getLogger(ExplorerCategory.class); |
| |
| /** The eclipse context. */ |
| private final IEclipseContext eclipseContext; |
| |
| /** The parent category. */ |
| protected IExplorerCategory parentCategory; |
| |
| /** The children. */ |
| protected List<IExplorerInfo> children; |
| |
| /** The lazy has children. */ |
| protected boolean lazyHasChildren; |
| |
| /** |
| * Instantiates a new explorer category. |
| * |
| * @param eclipseContext |
| * the eclipse context |
| */ |
| public ExplorerCategory(IEclipseContext eclipseContext) { |
| this.eclipseContext = eclipseContext; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.vaaclipse.addons.common.api.explorer.IExplorerCategory#getParentCategory() |
| */ |
| @Override |
| public IExplorerCategory getParentCategory() { |
| return parentCategory; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.vaaclipse.addons.common.api.explorer.IExplorerCategory#getChildren() |
| */ |
| @Override |
| public List<IExplorerInfo> getChildren() { |
| if (children == null) { |
| loadChilds(); |
| } |
| return children != null ? Collections.unmodifiableList(children) |
| : Collections.<IExplorerInfo> emptyList(); |
| } |
| |
| /** |
| * Adds the child. |
| * |
| * @param info |
| * the info |
| * @return true, if successful |
| */ |
| private boolean addChild(IExplorerInfo info) { |
| return children.add(info); |
| } |
| |
| /** |
| * Returns the infos as an input for the tree. |
| */ |
| private void loadChilds() { |
| if (children == null) { |
| children = new ArrayList<IExplorerInfo>(); |
| } else { |
| return; |
| } |
| |
| ServiceTracker<IExplorerInfoManager, IExplorerInfoManager> tracker = new ServiceTracker<IExplorerInfoManager, IExplorerInfoManager>( |
| FrameworkUtil.getBundle(getClass()).getBundleContext(), |
| IExplorerInfoManager.class, null); |
| |
| try { |
| tracker.open(); |
| IExplorerInfoManager provider = tracker.waitForService(500); |
| for (IExplorerInfo info : provider.getExplorerInfo(this, |
| eclipseContext)) { |
| addChild(info); |
| } |
| } catch (InterruptedException e) { |
| LOGGER.error("{}", e); |
| eclipseContext.get(IStatusManager.class).getActiveScope() |
| .addStatus(Status.createErrorStatus(e)); |
| } finally { |
| tracker.close(); |
| } |
| } |
| } |