1 /* 2 * Copyright (C) 2011 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 package com.android.ide.eclipse.ddms.views; 17 18 import com.android.ddmuilib.logcat.ILogCatMessageSelectionListener; 19 import com.android.ddmuilib.logcat.LogCatMessage; 20 import com.android.ddmuilib.logcat.LogCatPanel; 21 import com.android.ddmuilib.logcat.LogCatStackTraceParser; 22 import com.android.ide.eclipse.ddms.DdmsPlugin; 23 import com.android.ide.eclipse.ddms.JavaSourceRevealer; 24 import com.android.ide.eclipse.ddms.i18n.Messages; 25 import com.android.ide.eclipse.ddms.preferences.PreferenceInitializer; 26 27 import org.eclipse.jface.action.Action; 28 import org.eclipse.jface.preference.IPreferenceStore; 29 import org.eclipse.swt.dnd.Clipboard; 30 import org.eclipse.swt.layout.FillLayout; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.ui.IActionBars; 33 import org.eclipse.ui.actions.ActionFactory; 34 35 public class LogCatView extends SelectionDependentViewPart { 36 /** LogCatView ID as defined in plugin.xml. */ 37 public static final String ID = "com.android.ide.eclipse.ddms.views.LogCatView"; //$NON-NLS-1$ 38 39 /** Switch perspective when a Java file is opened from logcat view. */ 40 public static final boolean DEFAULT_SWITCH_PERSPECTIVE = true; 41 42 /** Target perspective to open when a Java file is opened from logcat view. */ 43 public static final String DEFAULT_PERSPECTIVE_ID = 44 "org.eclipse.jdt.ui.JavaPerspective"; //$NON-NLS-1$ 45 46 private LogCatPanel mLogCatPanel; 47 private LogCatStackTraceParser mStackTraceParser = new LogCatStackTraceParser(); 48 49 private Clipboard mClipboard; 50 51 @Override 52 public void createPartControl(Composite parent) { 53 parent.setLayout(new FillLayout()); 54 55 IPreferenceStore prefStore = DdmsPlugin.getDefault().getPreferenceStore(); 56 mLogCatPanel = new LogCatPanel(prefStore); 57 mLogCatPanel.createPanel(parent); 58 setSelectionDependentPanel(mLogCatPanel); 59 60 mLogCatPanel.addLogCatMessageSelectionListener(new ILogCatMessageSelectionListener() { 61 @Override 62 public void messageDoubleClicked(LogCatMessage m) { 63 onDoubleClick(m); 64 } 65 }); 66 67 mClipboard = new Clipboard(parent.getDisplay()); 68 IActionBars actionBars = getViewSite().getActionBars(); 69 actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), 70 new Action(Messages.LogCatView_Copy) { 71 @Override 72 public void run() { 73 mLogCatPanel.copySelectionToClipboard(mClipboard); 74 } 75 }); 76 77 actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), 78 new Action(Messages.LogCatView_Select_All) { 79 @Override 80 public void run() { 81 mLogCatPanel.selectAll(); 82 } 83 }); 84 } 85 86 @Override 87 public void setFocus() { 88 } 89 90 private void onDoubleClick(LogCatMessage m) { 91 String msg = m.getMessage(); 92 if (!mStackTraceParser.isValidExceptionTrace(msg)) { 93 return; 94 } 95 96 IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore(); 97 String perspectiveId = null; 98 if (store.getBoolean(PreferenceInitializer.ATTR_SWITCH_PERSPECTIVE)) { 99 perspectiveId = store.getString(PreferenceInitializer.ATTR_PERSPECTIVE_ID); 100 } 101 102 103 String fileName = mStackTraceParser.getFileName(msg); 104 int lineNumber = mStackTraceParser.getLineNumber(msg); 105 String methodName = mStackTraceParser.getMethodName(msg); 106 JavaSourceRevealer.revealMethod(methodName, fileName, lineNumber, perspectiveId); 107 } 108 109 public void selectTransientAppFilter(String appName) { 110 mLogCatPanel.selectTransientAppFilter(appName); 111 } 112 } 113