/*******************************************************************************
* Copyright (c) 2012 Pivotal Software, Inc.
* 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:
* Pivotal Software, Inc. - initial API and implementation
*******************************************************************************/
package com.vmware.vfabric.ide.eclipse.tcserver.insight.internal.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import org.eclipse.wst.server.ui.editor.ServerEditorSection;
import com.vmware.vfabric.ide.eclipse.tcserver.insight.internal.ui.actions.OpenDashboardAction;
/**
* A section for running Insight related actions.
* @author Steffen Pingel
*/
public class InsightActionSection extends ServerEditorSection {
public InsightActionSection() {
}
@Override
public void createSection(Composite parent) {
super.createSection(parent);
FormToolkit toolkit = getFormToolkit(parent.getDisplay());
Section section = toolkit.createSection(parent, ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR
| Section.DESCRIPTION | ExpandableComposite.FOCUS_TITLE | ExpandableComposite.EXPANDED);
section.setText("Dashboard");
section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
Composite composite = toolkit.createComposite(section);
TableWrapLayout layout = new TableWrapLayout();
layout.topMargin = 0;
layout.leftMargin = 8;
layout.bottomMargin = 8;
layout.rightMargin = 8;
composite.setLayout(layout);
toolkit.paintBordersFor(composite);
section.setClient(composite);
final OpenDashboardAction action = new OpenDashboardAction();
Link link = new Link(composite, SWT.NONE);
link.setText("<a>Open Insight Dashboard</a> to view metrics. Requires server to be running with Insight enabled.");
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
action.run(server.getOriginal());
}
});
link.setEnabled(server.getOriginal() != null && action.isEnabled(server.getOriginal()));
}
@Override
public void init(IEditorSite site, IEditorInput input) {
super.init(site, input);
}
}