1 /**********************************************************************
2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM - Initial API and implementation
10 **********************************************************************/
11 package net.sourceforge.phpdt.monitor.ui.internal.viewers;
13 import net.sourceforge.phpdt.monitor.core.IRequest;
14 import net.sourceforge.phpdt.monitor.core.MonitorCore;
15 import net.sourceforge.phpdt.monitor.ui.internal.ContextIds;
16 import net.sourceforge.phpdt.monitor.ui.internal.MonitorUIPlugin;
18 import org.eclipse.jface.resource.JFaceResources;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Display;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Text;
26 import org.eclipse.ui.help.WorkbenchHelp;
29 * An transport (header) viewer.
31 public class HeaderViewer {
32 protected boolean displayHeader;
34 protected Composite headerComp;
35 protected Composite innerComp;
36 protected Composite rootComp;
38 protected Label headerLabel;
39 protected Text headerText;
40 protected IRequest rr;
42 protected GridLayout layout;
43 protected GridData data;
45 protected boolean hidden;
47 protected static int HEADER_LABEL_SIZE = 15;
48 protected static int HEADER_TEXT_SIZE = 110;
49 public static byte REQUEST_HEADER = 0;
50 public static byte RESPONSE_HEADER = 1;
52 public HeaderViewer(Composite parent, byte message) {
57 headerComp = new Composite(parent, SWT.NONE);
58 layout = new GridLayout();
59 layout.numColumns = 1;
60 layout.marginHeight = 0;
61 layout.marginWidth = 0;
62 headerComp.setLayout(layout);
63 data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
64 headerComp.setLayoutData(data);
66 innerComp = new Composite(headerComp, SWT.NONE);
67 layout = new GridLayout();
68 layout.numColumns = 1;
69 layout.marginHeight = 0;
70 layout.marginWidth = 2;
71 innerComp.setLayout(layout);
72 data = new GridData(GridData.FILL_BOTH);
73 data.heightHint = HEADER_LABEL_SIZE;
74 innerComp.setLayoutData(data);
79 setDisplayHeader(false);
82 /*public boolean isHidden() {
86 /*public void hideViewer() {
89 data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
91 headerComp.setLayoutData(data);
92 rootComp.layout(true);
95 public void showViewer() {
98 innerComp = new Composite(headerComp, SWT.NONE);
99 layout = new GridLayout();
100 layout.numColumns = 1;
101 layout.marginHeight = 0;
102 layout.marginWidth = 2;
103 innerComp.setLayout(layout);
104 data = new GridData(GridData.FILL_BOTH);
105 data.heightHint = HEADER_LABEL_SIZE;
106 innerComp.setLayoutData(data);
108 displayHeader = true;
109 setDisplayHeader(false);
112 public void setRequestResponse(IRequest reqresp) {
118 public void setDisplayHeader(boolean b) {
119 if (displayHeader != b) {
124 data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
125 data.heightHint = HEADER_TEXT_SIZE;
126 headerComp.setLayoutData(data);
128 innerComp = new Composite(headerComp, SWT.NONE);
129 layout = new GridLayout();
130 layout.numColumns = 1;
131 layout.marginHeight = 0;
132 layout.marginWidth = 0;
133 innerComp.setLayout(layout);
134 data = new GridData(GridData.FILL_BOTH);
135 data.heightHint = HEADER_TEXT_SIZE;
136 innerComp.setLayoutData(data);
138 headerText = new Text(innerComp, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
139 Display display = innerComp.getDisplay();
140 headerText.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
141 headerText.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
142 headerText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
143 headerText.setFont(JFaceResources.getTextFont());
144 WorkbenchHelp.setHelp(headerText, ContextIds.VIEW_RESPONSE);
146 rootComp.layout(true);
150 data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
151 data.heightHint = HEADER_LABEL_SIZE;
152 headerComp.setLayoutData(data);
154 innerComp = new Composite(headerComp, SWT.NONE);
155 layout = new GridLayout();
156 layout.numColumns = 1;
157 layout.marginHeight = 0;
158 layout.marginWidth = 2;
159 innerComp.setLayout(layout);
160 data = new GridData(GridData.FILL_BOTH);
161 data.heightHint = HEADER_LABEL_SIZE;
162 innerComp.setLayoutData(data);
164 headerLabel = new Label(innerComp, SWT.NONE);
165 headerLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
167 rootComp.layout(true);
173 /*public boolean getDisplayHeader() {
174 return displayHeader;
177 private void getView() {
180 if (msg == REQUEST_HEADER) {
181 out = MonitorCore.parse(rr.getRequest(IRequest.TRANSPORT));
182 } else if (msg == RESPONSE_HEADER) {
183 out = MonitorCore.parse(rr.getResponse(IRequest.TRANSPORT));
188 headerText.setText(out);
190 String lineSeparator = System.getProperty("line.separator");
191 int index = out.indexOf(lineSeparator);
193 headerLabel.setText(MonitorUIPlugin.getResource("%headerLabel") + ": " + out.substring(0, index));
195 headerLabel.setText(MonitorUIPlugin.getResource("%headerLabel") + ": " + out);
199 public void dispose() {
200 headerComp.dispose();