Home | History | Annotate | Download | only in preferences
      1 /*
      2  * Copyright (C) 2007 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.preferences;
     18 
     19 import com.android.ddmlib.Log.LogLevel;
     20 import com.android.ddmuilib.logcat.LogCatMessageList;
     21 import com.android.ddmuilib.logcat.LogCatPanel;
     22 import com.android.ide.eclipse.base.InstallDetails;
     23 import com.android.ide.eclipse.ddms.DdmsPlugin;
     24 import com.android.ide.eclipse.ddms.LogCatMonitor;
     25 import com.android.ide.eclipse.ddms.i18n.Messages;
     26 
     27 import org.eclipse.jface.preference.BooleanFieldEditor;
     28 import org.eclipse.jface.preference.ComboFieldEditor;
     29 import org.eclipse.jface.preference.FieldEditorPreferencePage;
     30 import org.eclipse.jface.preference.FontFieldEditor;
     31 import org.eclipse.jface.preference.IntegerFieldEditor;
     32 import org.eclipse.jface.util.PropertyChangeEvent;
     33 import org.eclipse.swt.SWT;
     34 import org.eclipse.swt.layout.GridData;
     35 import org.eclipse.swt.widgets.Label;
     36 import org.eclipse.ui.IPerspectiveDescriptor;
     37 import org.eclipse.ui.IWorkbench;
     38 import org.eclipse.ui.IWorkbenchPreferencePage;
     39 import org.eclipse.ui.PlatformUI;
     40 
     41 /**
     42  * Preference Pane for LogCat.
     43  */
     44 public class LogCatPreferencePage extends FieldEditorPreferencePage implements
     45         IWorkbenchPreferencePage {
     46     private BooleanFieldEditor mSwitchPerspective;
     47     private ComboFieldEditor mWhichPerspective;
     48     private IntegerFieldEditor mMaxMessages;
     49     private BooleanFieldEditor mAutoMonitorLogcat;
     50     private ComboFieldEditor mAutoMonitorLogcatLevel;
     51     private BooleanFieldEditor mAutoScrollLock;
     52 
     53     public LogCatPreferencePage() {
     54         super(GRID);
     55         setPreferenceStore(DdmsPlugin.getDefault().getPreferenceStore());
     56     }
     57 
     58     @Override
     59     protected void createFieldEditors() {
     60         FontFieldEditor ffe = new FontFieldEditor(LogCatPanel.LOGCAT_VIEW_FONT_PREFKEY,
     61                 Messages.LogCatPreferencePage_Display_Font, getFieldEditorParent());
     62         addField(ffe);
     63 
     64         mMaxMessages = new IntegerFieldEditor(
     65                 LogCatMessageList.MAX_MESSAGES_PREFKEY,
     66                 Messages.LogCatPreferencePage_MaxMessages, getFieldEditorParent());
     67         addField(mMaxMessages);
     68 
     69         mAutoScrollLock = new BooleanFieldEditor(LogCatPanel.AUTO_SCROLL_LOCK_PREFKEY,
     70                 "Automatically enable/disable scroll lock based on the scrollbar position",
     71                 getFieldEditorParent());
     72         addField(mAutoScrollLock);
     73 
     74         createHorizontalSeparator();
     75 
     76         if (InstallDetails.isAdtInstalled()) {
     77             createAdtSpecificFieldEditors();
     78         }
     79     }
     80 
     81     private void createHorizontalSeparator() {
     82         Label l = new Label(getFieldEditorParent(), SWT.SEPARATOR | SWT.HORIZONTAL);
     83         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
     84         gd.horizontalSpan = 3;
     85         l.setLayoutData(gd);
     86     }
     87 
     88     private void createAdtSpecificFieldEditors() {
     89         mSwitchPerspective = new BooleanFieldEditor(PreferenceInitializer.ATTR_SWITCH_PERSPECTIVE,
     90                 Messages.LogCatPreferencePage_Switch_Perspective, getFieldEditorParent());
     91         addField(mSwitchPerspective);
     92         IPerspectiveDescriptor[] perspectiveDescriptors =
     93                 PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives();
     94         String[][] perspectives = new String[0][0];
     95         if (perspectiveDescriptors.length > 0) {
     96             perspectives = new String[perspectiveDescriptors.length][2];
     97             for (int i = 0; i < perspectiveDescriptors.length; i++) {
     98                 IPerspectiveDescriptor perspective = perspectiveDescriptors[i];
     99                 perspectives[i][0] = perspective.getLabel();
    100                 perspectives[i][1] = perspective.getId();
    101             }
    102         }
    103         mWhichPerspective = new ComboFieldEditor(PreferenceInitializer.ATTR_PERSPECTIVE_ID,
    104                 Messages.LogCatPreferencePage_Switch_To, perspectives, getFieldEditorParent());
    105         mWhichPerspective.setEnabled(getPreferenceStore()
    106                 .getBoolean(PreferenceInitializer.ATTR_SWITCH_PERSPECTIVE), getFieldEditorParent());
    107         addField(mWhichPerspective);
    108 
    109         createHorizontalSeparator();
    110 
    111         mAutoMonitorLogcat = new BooleanFieldEditor(LogCatMonitor.AUTO_MONITOR_PREFKEY,
    112                 Messages.LogCatPreferencePage_AutoMonitorLogcat,
    113                 getFieldEditorParent());
    114         addField(mAutoMonitorLogcat);
    115 
    116         mAutoMonitorLogcatLevel = new ComboFieldEditor(LogCatMonitor.AUTO_MONITOR_LOGLEVEL,
    117                 Messages.LogCatPreferencePage_SessionFilterLogLevel,
    118                 new String[][] {
    119                     { LogLevel.VERBOSE.toString(), LogLevel.VERBOSE.getStringValue() },
    120                     { LogLevel.DEBUG.toString(), LogLevel.DEBUG.getStringValue() },
    121                     { LogLevel.INFO.toString(), LogLevel.INFO.getStringValue() },
    122                     { LogLevel.WARN.toString(), LogLevel.WARN.getStringValue() },
    123                     { LogLevel.ERROR.toString(), LogLevel.ERROR.getStringValue() },
    124                     { LogLevel.ASSERT.toString(), LogLevel.ASSERT.getStringValue() },
    125                 },
    126                 getFieldEditorParent());
    127         mAutoMonitorLogcatLevel.setEnabled(
    128                 getPreferenceStore().getBoolean(LogCatMonitor.AUTO_MONITOR_PREFKEY),
    129                 getFieldEditorParent());
    130         addField(mAutoMonitorLogcatLevel);
    131     }
    132 
    133     @Override
    134     public void init(IWorkbench workbench) {
    135     }
    136 
    137     @Override
    138     public void propertyChange(PropertyChangeEvent event) {
    139         if (event.getSource().equals(mSwitchPerspective)) {
    140             mWhichPerspective.setEnabled(mSwitchPerspective.getBooleanValue(),
    141                     getFieldEditorParent());
    142         } else if (event.getSource().equals(mAutoMonitorLogcat)) {
    143             mAutoMonitorLogcatLevel.setEnabled(mAutoMonitorLogcat.getBooleanValue(),
    144                     getFieldEditorParent());
    145         }
    146     }
    147 
    148     @Override
    149     protected void performDefaults() {
    150         super.performDefaults();
    151         mWhichPerspective.setEnabled(mSwitchPerspective.getBooleanValue(), getFieldEditorParent());
    152 
    153         mMaxMessages.setStringValue(
    154                 Integer.toString(LogCatMessageList.MAX_MESSAGES_DEFAULT));
    155 
    156         mAutoMonitorLogcatLevel.setEnabled(mAutoMonitorLogcat.getBooleanValue(),
    157                 getFieldEditorParent());
    158     }
    159 }
    160