/*
* Created on Dec 20, 2008
*
* Copyright 2005 CafeSip.org
*
* 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.
*
*/
package org.cafesip.jiplet.console.client;
import java.util.HashMap;
import org.cafesip.gwtcomp.client.ui.PropertyViewer;
import org.cafesip.gwtcomp.client.ui.TitleBar;
import com.google.gwt.user.client.ui.DecoratedTabPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* @author Becky McElroy
*
*/
public class DetailsView extends VerticalPanel
{
private DecoratedTabPanel panel;
private PropertyViewer general;
protected Widget detail;
protected DetailsView(String title)
{
this(title, "Properties");
}
protected DetailsView(String title, String detailPanelLabel)
{
this(title, detailPanelLabel, new PropertyViewer(true, true));
}
/**
* A constructor for the case where the detail tab needs to show something
* other than a standard PropertyViewer.
*
* @param title
* @param detailPanelLabel
* @param detail
* The widget that the detail tab needs to have.
*/
protected DetailsView(String title, String detailPanelLabel, Widget detail)
{
super();
this.detail = detail;
setWidth("100%");
init(title, detailPanelLabel);
}
private void init(String title, String detailPanelLabel)
{
TitleBar titleBar = new TitleBar(title, null, 1);
add(titleBar);
add(new HTML("<p>"));
panel = new DecoratedTabPanel();
add(panel);
panel.setWidth("100%");
setCellHorizontalAlignment(panel, HasHorizontalAlignment.ALIGN_LEFT);
setCellVerticalAlignment(panel, HasVerticalAlignment.ALIGN_TOP);
FlowPanel generalPanel = new FlowPanel();
panel.add(generalPanel, "General");
generalPanel.setWidth("100%");
general = new PropertyViewer(false, false);
general.setWidth("100%");
generalPanel.add(general);
FlowPanel detailPanel = new FlowPanel();
panel.add(detailPanel, detailPanelLabel);
detailPanel.setWidth("100%");
detail.setWidth("100%");
detailPanel.add(detail);
panel.selectTab(0);
}
/**
* Call this when using the standard PropertyViewer in the detail tab
* (default case).
*
* @param generalProperties
* @param detailProperties
*/
protected void display(HashMap<String, String> generalProperties,
HashMap<String, String> detailProperties)
{
general.setProperties(generalProperties);
((PropertyViewer) detail).setProperties(detailProperties);
panel.selectTab(0);
}
/**
* Call this to display everything but the widget in the detail tab.
*
* @param generalProperties
*/
protected void displayGeneral(HashMap<String, String> generalProperties)
{
general.setProperties(generalProperties);
panel.selectTab(0);
}
protected String format(String property)
{
return property == null ? "" : property;
}
protected String formatYesNo(boolean property)
{
return property == true ? "Yes" : "No";
}
protected FlowPanel addTab(String label, Widget w)
{
FlowPanel detailPanel = new FlowPanel();
panel.add(detailPanel, label);
detailPanel.setWidth("100%");
w.setWidth("100%");
detailPanel.add(w);
return detailPanel;
}
/**
* @return Returns the panel.
*/
public DecoratedTabPanel getPanel()
{
return panel;
}
}