package org.opennms.features.vaadin.topology;


import org.opennms.features.vaadin.topology.gwt.client.Graph;
import org.opennms.features.vaadin.topology.gwt.client.Vertex;

import com.vaadin.Application;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.event.Action;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Slider;
import com.vaadin.ui.Slider.ValueOutOfBoundsException;
import com.vaadin.ui.Tree;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class TopologyWidgetTestApplication extends Application implements Action.Handler {

    private Window m_window;
    private TopologyComponent m_topologyComponent;
	private Action[] m_actions = new Action[] {new Action("Group")};
    
    @Override
    public void init() {
        VerticalLayout layout = new VerticalLayout();
        layout.setSizeFull();
        
        m_window = new Window("Topology Widget Test");
        m_window.setContent(layout);
        setMainWindow(m_window);
        
        m_topologyComponent = new TopologyComponent();
        m_topologyComponent.addActionHandler(this);
        m_topologyComponent.setSizeFull();
        
        
        
        final Slider slider = new Slider(0, 3);
        slider.setResolution(2);
        slider.setWidth("300px");
        slider.setOrientation(Slider.ORIENTATION_HORIZONTAL);
        slider.addListener(new ValueChangeListener(){

			public void valueChange(ValueChangeEvent event) {
				double scale = (Double) slider.getValue();
				
				m_topologyComponent.setScale(scale);
			}
		});
        slider.setImmediate(true);
        try {
			slider.setValue(m_topologyComponent.getScale());
		} catch (ValueOutOfBoundsException e) {
			e.printStackTrace();
		}
        
        
        Button addButton = new Button("Add a Vertex");
        addButton.setDescription("Use this button to add a new Vertex");
        addButton.addListener(new ClickListener() {

			public void buttonClick(ClickEvent event) {
				m_topologyComponent.addRandomNode();
			}
        });
        
        Button resetButton = new Button("Reset");
        resetButton.addListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {
                m_topologyComponent.resetGraph();
            }
        });
        
        Button removeVertexButton = new Button("Remove Vertex");
        removeVertexButton.addListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {
                m_topologyComponent.removeVertex();
            }
            
        });
        
        HorizontalLayout topLayoutBar = new HorizontalLayout();
        topLayoutBar.addComponent(addButton);
        topLayoutBar.addComponent(resetButton);
        topLayoutBar.addComponent(removeVertexButton);
        topLayoutBar.addComponent(slider);
        
        VerticalLayout vLayout = new VerticalLayout();
        vLayout.setWidth("100px");
        vLayout.setHeight("100%");
        vLayout.addComponent(createTree());
        
        layout.addComponent(topLayoutBar);
        layout.addComponent(vLayout);
        layout.addComponent(m_topologyComponent);
        layout.setExpandRatio(m_topologyComponent, 1.0f);
        
    }

	private Component createTree() {
	    Tree tree = new Tree();
	    tree.setWidth("100%");
	    tree.setHeight("100%");
	    
	    Graph graph = m_topologyComponent.getGraph();
	    for(Vertex vertex : graph.getVertices()) {
	        tree.addItem(vertex);
	    }
	    
        return tree;
    }

    public Action[] getActions(Object target, Object sender) {
		return m_actions;
	}

	public void handleAction(Action action, Object sender, Object target) {
		if(action.getCaption().equals("Group")) {
			//Do Something here
		}
		
	}

}

@@ -3039,32 +3039,172 @@
 ider);%0A        %0A
+        HorizontalLayout bottomLayoutBar = new HorizontalLayout();%0A        bottomLayoutBar.addComponent(new Button(%22Bottom bar%22));%0A        %0A
         Vertical
@@ -3345,72 +3345,103 @@
 ent(
-createTree());%0A        %0A        layout.addComponent(top
+new Button(%22Hello There%22));%0A        %0A        HorizontalLayout mapLayout = new Horizontal
 Layout
-Bar
+(
 );%0A 
@@ -3439,33 +3439,45 @@
 yout();%0A        
-l
+%0A        mapL
 ayout.addCompone
@@ -3493,25 +3493,28 @@
 t);%0A        
-l
+mapL
 ayout.addCom
@@ -3542,33 +3542,69 @@
 onent);%0A        
-l
+mapLayout.setSizeFull();%0A        mapL
 ayout.setExpandR
@@ -3641,24 +3641,237 @@
 );%0A        %0A
+        %0A        %0A        layout.addComponent(topLayoutBar);%0A        layout.addComponent(mapLayout);%0A        layout.addComponent(bottomLayoutBar);%0A        layout.setExpandRatio(mapLayout, 1.0f);%0A        %0A        %0A
     %7D%0A%0A%09priv

Fix up layout for the topology map Application Frame