| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * 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: |
| * Pierre Allard - initial API and implementation |
| * Regent L'Archeveque, |
| * Sebastien Gemme |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************/ |
| package org.eclipse.apogy.common.topology.ui.composites; |
| |
| import java.util.Collection; |
| import java.util.HashSet; |
| import java.util.Set; |
| |
| import org.eclipse.apogy.common.topology.AbstractNodeVisitor; |
| import org.eclipse.apogy.common.topology.INodeVisitor; |
| import org.eclipse.apogy.common.topology.Node; |
| import org.eclipse.emf.common.notify.AdapterFactory; |
| import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; |
| import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; |
| import org.eclipse.swt.graphics.Image; |
| import org.eclipse.swt.widgets.Composite; |
| |
| public class NodeSearchComposite extends AbstractNodeSearchComposite { |
| // The root of the topology. |
| protected Node topologyRoot = null; |
| |
| public NodeSearchComposite(Composite parent, int style) { |
| super(parent, style); |
| } |
| |
| public NodeSearchComposite(Composite parent, int style, Node topologyRoot) { |
| super(parent, style); |
| setTopologyRoot(topologyRoot); |
| } |
| |
| @Override |
| protected AdapterFactoryContentProvider createContentProvider() { |
| return new NodeContentProvider(this.adapterFactory); |
| } |
| |
| @Override |
| protected AdapterFactoryLabelProvider createLabelProvider() { |
| return new NodeLabelProvider(this.adapterFactory); |
| } |
| |
| /** |
| * Sets the root of the topology for which to display and filter available |
| * Nodes. |
| * |
| * @param root The root of the topology. |
| */ |
| public void setTopologyRoot(Node root) { |
| this.topologyRoot = root; |
| |
| // Clears the selected Node(s) |
| this.selectedNode = null; |
| nodeSelectedChanged(null); |
| |
| // Forces the filters to be applied and the displays updated. |
| applyFilters(); |
| } |
| |
| @Override |
| protected Set<Node> getUnfilteredNodes() { |
| Set<Node> nodes = new HashSet<Node>(); |
| |
| if (this.topologyRoot != null) { |
| INodeVisitor visitor = new AbstractNodeVisitor() { |
| @Override |
| public void visit(Node node) { |
| nodes.add(node); |
| } |
| }; |
| |
| this.topologyRoot.accept(visitor); |
| } |
| return nodes; |
| } |
| |
| /** |
| * Content provider for the arguments. |
| * |
| */ |
| private class NodeContentProvider extends AdapterFactoryContentProvider { |
| |
| public NodeContentProvider(AdapterFactory adapterFactory) { |
| super(adapterFactory); |
| } |
| |
| @Override |
| public Object[] getElements(Object object) { |
| if (object instanceof Collection) { |
| return ((Collection<?>) object).toArray(); |
| } |
| return null; |
| } |
| |
| @Override |
| public Object[] getChildren(Object object) { |
| return null; |
| } |
| |
| @Override |
| public boolean hasChildren(Object object) { |
| return false; |
| } |
| } |
| |
| /** |
| * Label provider for the arguments. |
| * |
| */ |
| private class NodeLabelProvider extends AdapterFactoryLabelProvider { |
| public NodeLabelProvider(AdapterFactory adapterFactory) { |
| super(adapterFactory); |
| } |
| |
| @Override |
| public String getColumnText(Object object, int columnIndex) { |
| String str = "<undefined>"; |
| |
| switch (columnIndex) { |
| case ID_COLUMN_INDEX: |
| if (object instanceof Node) { |
| str = ((Node) object).getNodeId(); |
| } |
| break; |
| |
| case DESCRIPTION_COLUMN_INDEX: |
| if (object instanceof Node) { |
| str = ((Node) object).getDescription(); |
| } |
| break; |
| default: |
| break; |
| } |
| return str; |
| } |
| |
| @Override |
| public Image getColumnImage(Object object, int columnIndex) { |
| if (columnIndex == ID_COLUMN_INDEX) { |
| return super.getColumnImage(object, columnIndex); |
| } else { |
| return null; |
| } |
| } |
| } |
| } |