/*******************************************************************************
 * Mission Control Technologies, Copyright (c) 2009-2012, United States Government
 * as represented by the Administrator of the National Aeronautics and Space 
 * Administration. All rights reserved.
 *
 * The MCT platform is licensed under the Apache License, Version 2.0 (the 
 * "License"); you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
 * License for the specific language governing permissions and limitations under 
 * the License.
 *
 * MCT includes source code licensed under additional open source licenses. See 
 * the MCT Open Source Licenses file included with this distribution or the About 
 * MCT Licenses dialog available at runtime from the MCT Help menu for additional 
 * information. 
 *******************************************************************************/
package gov.nasa.arc.mct.scenario.component;

import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.gui.CustomVisualControl;
import gov.nasa.arc.mct.platform.spi.PlatformAccess;
import gov.nasa.arc.mct.scenario.view.LabelView;

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.JPanel;

public class ActivityVisualControl extends CustomVisualControl {
	private static final long serialVersionUID = 260628819696786275L;
	private List<AbstractComponent> tags = new ArrayList<AbstractComponent>();
	private JPanel tagPanel = new JPanel();
	private JComboBox comboBox;
	
	public ActivityVisualControl() {
		setLayout(new BorderLayout());
		comboBox = makeComboBox();
		add(comboBox, BorderLayout.NORTH);
		add(tagPanel, BorderLayout.CENTER);
	}
	
	@Override
	public void setValue(Object value) {
		tagPanel.removeAll();
		tags.clear();
		if (value instanceof List) {
			for (Object element : (List<?>) value) {
				if (element instanceof AbstractComponent) {
					add(LabelView.VIEW_INFO.createView((AbstractComponent) element));
					tags.add((AbstractComponent) element);
				}
			}
		}
	}

	@Override
	public Object getValue() {
		return tags;
	}

	@Override
	public void setMutable(boolean mutable) {
	}
	
	private JComboBox makeComboBox() {
		List<Object> listItems = new ArrayList<Object>();
		for (AbstractComponent comp : 
			PlatformAccess.getPlatform().getBootstrapComponents()) {
			RepositoryCapability repo = comp.getCapability(RepositoryCapability.class);
			if (repo != null && 
				TagCapability.class.isAssignableFrom(repo.getCapabilityClass())) {
				// First, add repo as a section heading
				listItems.add(comp);
				// Add all tags underneath
				for (AbstractComponent child : comp.getComponents()) {					
					listItems.addAll(child.getCapabilities(TagCapability.class));
				}
			}
		}
		
		JComboBox comboBox = new JComboBox(listItems.toArray());
		
		return comboBox;
	}
	
	
}

@@ -1485,16 +1485,88 @@
 Layout;%0A
+import java.awt.Color;%0Aimport java.awt.Component;%0Aimport java.awt.Font;%0A
 import j
@@ -1605,24 +1605,54 @@
 util.List;%0A%0A
+import javax.swing.ImageIcon;%0A
 import javax
@@ -1689,21 +1689,111 @@
 .swing.J
-Panel
+Label;%0Aimport javax.swing.JList;%0Aimport javax.swing.JPanel;%0Aimport javax.swing.ListCellRenderer
 ;%0A%0Apubli
@@ -3371,16 +3371,823 @@
 y());%0A%09%09
+comboBox.setRenderer(new ListCellRenderer() %7B%0A%09%09%09private JLabel label = new JLabel(); // Re-use%0A%09%09%09private Color c = label.getForeground();%0A%09%09%09@Override%0A%09%09%09public Component getListCellRendererComponent(JList list,%0A%09%09%09%09%09Object item, int index, boolean isSelected, boolean hasFocus) %7B%0A%09%09%09%09label.setFont(label.getFont().deriveFont(%0A%09%09%09%09%09item instanceof TagCapability ? Font.PLAIN : %0A%09%09%09%09%09item instanceof AbstractComponent ? Font.ITALIC :%0A%09%09%09%09%09Font.BOLD));%0A%09%09%09%09%09%09%0A%09%09%09%09label.setIcon(item instanceof TagCapability ?%0A%09%09%09%09%09((TagCapability)item).getComponentRepresentation().getAsset(ImageIcon.class) :%0A%09%09%09%09%09null);%0A%09%09%09%09%0A%09%09%09%09label.setText(item instanceof AbstractComponent ?%0A%09%09%09%09%09((AbstractComponent)item).getDisplayName() :%0A%09%09%09%09%09item.toString());%0A%09%09%09%09%0A%09%09%09%09label.setForeground(c);%0A%09%09%09%09%0A%09%09%09%09return label;%0A%09%09%09%7D%09%09%09%0A%09%09%7D);
 %0A%09%09retur

Add component renderer to tag combo box