Home | History | Annotate | Download | only in ddms
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.ddms;
     18 
     19 import com.android.ddmlib.Log.LogLevel;
     20 
     21 import org.eclipse.jface.dialogs.IDialogConstants;
     22 import org.eclipse.jface.dialogs.TitleAreaDialog;
     23 import org.eclipse.swt.SWT;
     24 import org.eclipse.swt.events.SelectionAdapter;
     25 import org.eclipse.swt.events.SelectionEvent;
     26 import org.eclipse.swt.events.SelectionListener;
     27 import org.eclipse.swt.layout.GridData;
     28 import org.eclipse.swt.layout.GridLayout;
     29 import org.eclipse.swt.widgets.Button;
     30 import org.eclipse.swt.widgets.Combo;
     31 import org.eclipse.swt.widgets.Composite;
     32 import org.eclipse.swt.widgets.Control;
     33 import org.eclipse.swt.widgets.Shell;
     34 
     35 public class LogCatMonitorDialog extends TitleAreaDialog {
     36     private static final String TITLE = "Auto Monitor Logcat";
     37     private static final String DEFAULT_MESSAGE =
     38             "Would you like ADT to automatically monitor logcat \n" +
     39             "output for messages from applications in the workspace?";
     40 
     41     private boolean mShouldMonitor = true;
     42 
     43     private static final String[] LOG_PRIORITIES = new String[] {
     44         LogLevel.VERBOSE.getStringValue(),
     45         LogLevel.DEBUG.getStringValue(),
     46         LogLevel.INFO.getStringValue(),
     47         LogLevel.WARN.getStringValue(),
     48         LogLevel.ERROR.getStringValue(),
     49         LogLevel.ASSERT.getStringValue(),
     50     };
     51     private static final int ERROR_PRIORITY_INDEX = 4;
     52 
     53     private String mMinimumLogPriority = LOG_PRIORITIES[ERROR_PRIORITY_INDEX];
     54 
     55     public LogCatMonitorDialog(Shell parentShell) {
     56         super(parentShell);
     57         setHelpAvailable(false);
     58     }
     59 
     60     @Override
     61     protected Control createDialogArea(Composite parent) {
     62         setTitle(TITLE);
     63         setMessage(DEFAULT_MESSAGE);
     64 
     65         parent = (Composite) super.createDialogArea(parent);
     66         Composite c = new Composite(parent, SWT.BORDER);
     67         c.setLayout(new GridLayout(2, false));
     68         GridData gd_c = new GridData(GridData.FILL_BOTH);
     69         gd_c.grabExcessVerticalSpace = false;
     70         gd_c.grabExcessHorizontalSpace = false;
     71         c.setLayoutData(gd_c);
     72 
     73         final Button disableButton = new Button(c, SWT.RADIO);
     74         disableButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
     75         disableButton.setText("No, do not monitor logcat output.");
     76 
     77         final Button enableButton = new Button(c, SWT.RADIO);
     78         enableButton.setText("Yes, monitor logcat and display logcat view if there are\n" +
     79                 "messages with priority higher than:");
     80         enableButton.setSelection(true);
     81 
     82         final Combo levelCombo = new Combo(c, SWT.READ_ONLY | SWT.DROP_DOWN);
     83         levelCombo.setItems(LOG_PRIORITIES);
     84         levelCombo.select(ERROR_PRIORITY_INDEX);
     85 
     86         SelectionListener s = new SelectionAdapter() {
     87             @Override
     88             public void widgetSelected(SelectionEvent e) {
     89                 if (e.getSource() == enableButton) {
     90                     mShouldMonitor = enableButton.getSelection();
     91                     levelCombo.setEnabled(mShouldMonitor);
     92                 } else if (e.getSource() == levelCombo) {
     93                     mMinimumLogPriority = LOG_PRIORITIES[levelCombo.getSelectionIndex()];
     94                 }
     95             }
     96         };
     97 
     98         levelCombo.addSelectionListener(s);
     99         enableButton.addSelectionListener(s);
    100 
    101         return parent;
    102     }
    103 
    104     @Override
    105     protected void createButtonsForButtonBar(Composite parent) {
    106         // Only need OK button
    107         createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
    108                 true);
    109     }
    110 
    111     public boolean shouldMonitor() {
    112         return mShouldMonitor;
    113     }
    114 
    115     public String getMinimumPriority() {
    116         return mMinimumLogPriority;
    117     }
    118 }
    119