1 11 package org.eclipse.pde.internal.runtime.logview; 12 13 import org.eclipse.jface.dialogs.Dialog; 14 import org.eclipse.jface.dialogs.IDialogConstants; 15 import org.eclipse.jface.dialogs.TrayDialog; 16 import org.eclipse.pde.internal.runtime.PDERuntimeMessages; 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; 32 33 34 public class FilterDialog extends TrayDialog { 35 private Button limit; 36 private Text limitText; 37 38 private Button okButton; 39 private Button errorButton; 40 private Button warningButton; 41 private Button infoButton; 42 private Button showAllButton; 43 private IMemento memento; 44 45 public FilterDialog(Shell parentShell, IMemento memento) { 46 super(parentShell); 47 this.memento = memento; 48 } 49 50 protected Control createDialogArea(Composite parent) { 51 Composite container = (Composite)super.createDialogArea(parent); 52 createEventTypesGroup(container); 53 createLimitSection(container); 54 createSessionSection(container); 55 56 Dialog.applyDialogFont(container); 57 return container; 58 } 59 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); 64 gd.widthHint = 275; 65 group.setLayoutData(gd); 66 group.setText(PDERuntimeMessages.LogView_FilterDialog_eventTypes); 67 68 infoButton = new Button(group, SWT.CHECK); 69 infoButton.setText(PDERuntimeMessages.LogView_FilterDialog_information); 70 infoButton.setSelection(memento.getString(LogView.P_LOG_INFO).equals("true")); 72 warningButton = new Button(group, SWT.CHECK); 73 warningButton.setText(PDERuntimeMessages.LogView_FilterDialog_warning); 74 warningButton.setSelection(memento.getString(LogView.P_LOG_WARNING).equals("true")); 76 errorButton = new Button(group, SWT.CHECK); 77 errorButton.setText(PDERuntimeMessages.LogView_FilterDialog_error); 78 errorButton.setSelection(memento.getString(LogView.P_LOG_ERROR).equals("true")); } 80 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)); 87 88 limit = new Button(comp, SWT.CHECK); 89 limit.setText(PDERuntimeMessages.LogView_FilterDialog_limitTo); 90 limit.setSelection(memento.getString(LogView.P_USE_LIMIT).equals("true")); limit.addSelectionListener(new SelectionAdapter() { 92 public void widgetSelected(SelectionEvent e) { 93 limitText.setEnabled(((Button)e.getSource()).getSelection()); 94 }}); 95 96 limitText = new Text(comp, SWT.BORDER); 97 limitText.addModifyListener(new ModifyListener(){ 98 public void modifyText(ModifyEvent e) { 99 try { 100 if (okButton == null) 101 return; 102 Integer.parseInt(limitText.getText()); 103 okButton.setEnabled(true); 104 } catch (NumberFormatException e1) { 105 okButton.setEnabled(false); 106 } 107 }}); 108 limitText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 109 limitText.setText(memento.getString(LogView.P_LOG_LIMIT)); 110 limitText.setEnabled(limit.getSelection()); 111 112 } 113 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)); 118 119 Label label = new Label(container, SWT.NONE); 120 label.setText(PDERuntimeMessages.LogView_FilterDialog_eventsLogged); 121 122 showAllButton = new Button(container, SWT.RADIO); 123 showAllButton.setText(PDERuntimeMessages.LogView_FilterDialog_allSessions); 124 GridData gd = new GridData(); 125 gd.horizontalIndent = 20; 126 showAllButton.setLayoutData(gd); 127 128 Button button = new Button(container, SWT.RADIO); 129 button.setText(PDERuntimeMessages.LogView_FilterDialog_recentSession); 130 gd = new GridData(); 131 gd.horizontalIndent = 20; 132 button.setLayoutData(gd); 133 134 if (memento.getString(LogView.P_SHOW_ALL_SESSIONS).equals("true")) { showAllButton.setSelection(true); 136 } else { 137 button.setSelection(true); 138 } 139 } 140 141 protected void createButtonsForButtonBar(Composite parent) { 142 okButton = createButton( 143 parent, 144 IDialogConstants.OK_ID, 145 IDialogConstants.OK_LABEL, 146 true); 147 createButton( 148 parent, 149 IDialogConstants.CANCEL_ID, 150 IDialogConstants.CANCEL_LABEL, 151 false); 152 } 153 154 protected void okPressed() { 155 memento.putString(LogView.P_LOG_INFO, infoButton.getSelection() ? "true" : "false"); memento.putString(LogView.P_LOG_WARNING, warningButton.getSelection() ? "true" : "false"); memento.putString(LogView.P_LOG_ERROR, errorButton.getSelection() ? "true" : "false"); memento.putString(LogView.P_LOG_LIMIT, limitText.getText()); 159 memento.putString(LogView.P_USE_LIMIT, limit.getSelection() ? "true" : "false"); memento.putString(LogView.P_SHOW_ALL_SESSIONS, showAllButton.getSelection() ? "true" : "false"); super.okPressed(); 162 } 163 164 } 165 | Popular Tags |