/********************************************************************** * Copyright (c) 2003 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html  * * Contributors: * IBM - Initial API and implementation **********************************************************************/ package net.sourceforge.phpdt.monitor.ui.internal.viewers; import net.sourceforge.phpdt.monitor.core.IRequest; import net.sourceforge.phpdt.monitor.core.MonitorCore; import net.sourceforge.phpdt.monitor.ui.internal.ContextIds; import net.sourceforge.phpdt.monitor.ui.internal.MonitorUIPlugin; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.help.WorkbenchHelp; /** * An transport (header) viewer. */ public class HeaderViewer { protected boolean displayHeader; protected Composite headerComp; protected Composite innerComp; protected Composite rootComp; protected Label headerLabel; protected Text headerText; protected IRequest rr; protected byte msg; protected GridLayout layout; protected GridData data; protected boolean hidden; protected static int HEADER_LABEL_SIZE = 15; protected static int HEADER_TEXT_SIZE = 110; public static byte REQUEST_HEADER = 0; public static byte RESPONSE_HEADER = 1; public HeaderViewer(Composite parent, byte message) { rootComp = parent; displayHeader = true; hidden = false; headerComp = new Composite(parent, SWT.NONE); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 0; layout.marginWidth = 0; headerComp.setLayout(layout); data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); headerComp.setLayoutData(data); innerComp = new Composite(headerComp, SWT.NONE); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 0; layout.marginWidth = 2; innerComp.setLayout(layout); data = new GridData(GridData.FILL_BOTH); data.heightHint = HEADER_LABEL_SIZE; innerComp.setLayoutData(data); rr = null; msg = message; setDisplayHeader(false); } /*public boolean isHidden() { return hidden; }*/ /*public void hideViewer() { hidden = true; innerComp.dispose(); data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); data.heightHint = 0; headerComp.setLayoutData(data); rootComp.layout(true); } public void showViewer() { hidden = false; innerComp = new Composite(headerComp, SWT.NONE); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 0; layout.marginWidth = 2; innerComp.setLayout(layout); data = new GridData(GridData.FILL_BOTH); data.heightHint = HEADER_LABEL_SIZE; innerComp.setLayoutData(data); displayHeader = true; setDisplayHeader(false); }*/ public void setRequestResponse(IRequest reqresp) { rr = reqresp; if (!hidden) getView(); } public void setDisplayHeader(boolean b) { if (displayHeader != b) { displayHeader = b; if (displayHeader) { innerComp.dispose(); data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); data.heightHint = HEADER_TEXT_SIZE; headerComp.setLayoutData(data); innerComp = new Composite(headerComp, SWT.NONE); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 0; layout.marginWidth = 0; innerComp.setLayout(layout); data = new GridData(GridData.FILL_BOTH); data.heightHint = HEADER_TEXT_SIZE; innerComp.setLayoutData(data); headerText = new Text(innerComp, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL); Display display = innerComp.getDisplay(); headerText.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); headerText.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND)); headerText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); headerText.setFont(JFaceResources.getTextFont()); WorkbenchHelp.setHelp(headerText, ContextIds.VIEW_RESPONSE); rootComp.layout(true); } else { innerComp.dispose(); data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING); data.heightHint = HEADER_LABEL_SIZE; headerComp.setLayoutData(data); innerComp = new Composite(headerComp, SWT.NONE); layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 0; layout.marginWidth = 2; innerComp.setLayout(layout); data = new GridData(GridData.FILL_BOTH); data.heightHint = HEADER_LABEL_SIZE; innerComp.setLayoutData(data); headerLabel = new Label(innerComp, SWT.NONE); headerLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); rootComp.layout(true); } } getView(); } /*public boolean getDisplayHeader() { return displayHeader; }*/ private void getView() { String out = ""; if (rr != null) { if (msg == REQUEST_HEADER) { out = MonitorCore.parse(rr.getRequest(IRequest.TRANSPORT)); } else if (msg == RESPONSE_HEADER) { out = MonitorCore.parse(rr.getResponse(IRequest.TRANSPORT)); } } if (displayHeader) { headerText.setText(out); } else { String lineSeparator = System.getProperty("line.separator"); int index = out.indexOf(lineSeparator); if(index > 0) headerLabel.setText(MonitorUIPlugin.getResource("%headerLabel") + ": " + out.substring(0, index)); else headerLabel.setText(MonitorUIPlugin.getResource("%headerLabel") + ": " + out); } } public void dispose() { headerComp.dispose(); } }