1 /*******************************************************************************
2 * Copyright (c) 2003, 2004 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 Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.debug.core.logview;
13 import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin;
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.ModifyEvent;
19 import org.eclipse.swt.events.ModifyListener;
20 import org.eclipse.swt.events.SelectionAdapter;
21 import org.eclipse.swt.events.SelectionEvent;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Button;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Group;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.swt.widgets.Text;
31 import org.eclipse.ui.IMemento;
34 public class FilterDialog extends Dialog {
36 private Text limitText;
38 private Button okButton;
39 private Button errorButton;
40 private Button warningButton;
41 private Button infoButton;
42 private Button showAllButton;
43 private IMemento memento;
45 public FilterDialog(Shell parentShell, IMemento memento) {
47 this.memento = memento;
50 protected Control createDialogArea(Composite parent) {
51 Composite container = (Composite)super.createDialogArea(parent);
52 createEventTypesGroup(container);
53 createLimitSection(container);
54 createSessionSection(container);
56 Dialog.applyDialogFont(container);
60 private void createEventTypesGroup(Composite parent) {
61 Group group = new Group(parent, SWT.NONE);
62 group.setLayout(new GridLayout());
63 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
65 group.setLayoutData(gd);
66 group.setText(PHPDebugCorePlugin.getResourceString("LogView.FilterDialog.eventTypes")); //$NON-NLS-1$
68 infoButton = new Button(group, SWT.CHECK);
69 infoButton.setText(PHPDebugCorePlugin.getResourceString("LogView.FilterDialog.information")); //$NON-NLS-1$
70 infoButton.setSelection(memento.getString(LogView.P_LOG_INFO).equals("true")); //$NON-NLS-1$
72 warningButton = new Button(group, SWT.CHECK);
73 warningButton.setText(PHPDebugCorePlugin.getResourceString("LogView.FilterDialog.warning")); //$NON-NLS-1$
74 warningButton.setSelection(memento.getString(LogView.P_LOG_WARNING).equals("true")); //$NON-NLS-1$
76 errorButton = new Button(group, SWT.CHECK);
77 errorButton.setText(PHPDebugCorePlugin.getResourceString("LogView.FilterDialog.error")); //$NON-NLS-1$
78 errorButton.setSelection(memento.getString(LogView.P_LOG_ERROR).equals("true")); //$NON-NLS-1$
81 private void createLimitSection(Composite parent) {
82 Composite comp = new Composite(parent, SWT.NONE);
83 GridLayout layout = new GridLayout();
84 layout.numColumns = 2;
85 comp.setLayout(layout);
86 comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
88 limit = new Button(comp, SWT.CHECK);
89 limit.setText(PHPDebugCorePlugin.getResourceString("LogView.FilterDialog.limitTo")); //$NON-NLS-1$
90 limit.setSelection(memento.getString(LogView.P_USE_LIMIT).equals("true")); //$NON-NLS-1$
91 limit.addSelectionListener(new SelectionAdapter() {
92 public void widgetSelected(SelectionEvent e) {
93 limitText.setEnabled(((Button)e.getSource()).getSelection());
96 limitText = new Text(comp, SWT.BORDER);
97 limitText.addModifyListener(new ModifyListener(){
98 public void modifyText(ModifyEvent e) {
100 if (okButton == null)
102 Integer.parseInt(limitText.getText());
103 okButton.setEnabled(true);
104 } catch (NumberFormatException e1) {
105 okButton.setEnabled(false);
108 limitText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
109 limitText.setText(memento.getString(LogView.P_LOG_LIMIT));
110 limitText.setEnabled(limit.getSelection());
114 private void createSessionSection(Composite parent) {
115 Composite container = new Composite(parent, SWT.NONE);
116 container.setLayout(new GridLayout());
117 container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
119 Label label = new Label(container, SWT.NONE);
120 label.setText(PHPDebugCorePlugin.getResourceString("LogView.FilterDialog.eventsLogged")); //$NON-NLS-1$
122 showAllButton = new Button(container, SWT.RADIO);
123 showAllButton.setText(PHPDebugCorePlugin.getResourceString("LogView.FilterDialog.allSessions")); //$NON-NLS-1$
124 GridData gd = new GridData();
125 gd.horizontalIndent = 20;
126 showAllButton.setLayoutData(gd);
128 Button button = new Button(container, SWT.RADIO);
129 button.setText(PHPDebugCorePlugin.getResourceString("LogView.FilterDialog.recentSession")); //$NON-NLS-1$
131 gd.horizontalIndent = 20;
132 button.setLayoutData(gd);
134 if (memento.getString(LogView.P_SHOW_ALL_SESSIONS).equals("true")) { //$NON-NLS-1$
135 showAllButton.setSelection(true);
137 button.setSelection(true);
141 protected void createButtonsForButtonBar(Composite parent) {
142 okButton = createButton(
144 IDialogConstants.OK_ID,
145 IDialogConstants.OK_LABEL,
149 IDialogConstants.CANCEL_ID,
150 IDialogConstants.CANCEL_LABEL,
154 protected void okPressed() {
155 memento.putString(LogView.P_LOG_INFO, infoButton.getSelection() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
156 memento.putString(LogView.P_LOG_WARNING, warningButton.getSelection() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
157 memento.putString(LogView.P_LOG_ERROR, errorButton.getSelection() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
158 memento.putString(LogView.P_LOG_LIMIT, limitText.getText());
159 memento.putString(LogView.P_USE_LIMIT, limit.getSelection() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
160 memento.putString(LogView.P_SHOW_ALL_SESSIONS, showAllButton.getSelection() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$