• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.views;
18 
19 import com.android.ddmuilib.ImageLoader;
20 import com.android.ddmuilib.log.event.EventLogPanel;
21 import com.android.ide.eclipse.ddms.CommonAction;
22 import com.android.ide.eclipse.ddms.i18n.Messages;
23 
24 import org.eclipse.jface.action.IAction;
25 import org.eclipse.jface.action.IMenuManager;
26 import org.eclipse.jface.action.IToolBarManager;
27 import org.eclipse.jface.action.Separator;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.ui.IActionBars;
30 
31 public class EventLogView extends SelectionDependentViewPart {
32 
33     private EventLogPanel mLogPanel;
34 
35     @Override
createPartControl(Composite parent)36     public void createPartControl(Composite parent) {
37         ImageLoader loader = ImageLoader.getDdmUiLibLoader();
38 
39         // create the external actions
40         CommonAction optionsAction = new CommonAction(Messages.EventLogView_Options);
41         optionsAction.setToolTipText(Messages.EventLogView_Opens_Options_Panel);
42         optionsAction.setImageDescriptor(loader.loadDescriptor("edit.png")); //$NON-NLS-1$
43 
44         CommonAction clearLogAction = new CommonAction(Messages.EventLogView_Clear_Log);
45         clearLogAction.setToolTipText(Messages.EventLogView_Clears_Event_Log);
46         clearLogAction.setImageDescriptor(loader.loadDescriptor("clear.png")); //$NON-NLS-1$
47 
48         CommonAction saveAction = new CommonAction(Messages.EventLogView_Save_Log);
49         saveAction.setToolTipText(Messages.EventLogView_Saves_Event_Log);
50         saveAction.setImageDescriptor(loader.loadDescriptor("save.png")); //$NON-NLS-1$
51 
52         CommonAction loadAction = new CommonAction(Messages.EventLogView_Load_Log);
53         loadAction.setToolTipText(Messages.EventLogView_Loads_Event_Log);
54         loadAction.setImageDescriptor(loader.loadDescriptor("load.png")); //$NON-NLS-1$
55 
56         CommonAction importBugAction = new CommonAction(Messages.EventLogView_Import_Bug_Report_Log);
57         importBugAction.setToolTipText(Messages.EventLogView_Imports_Bug_Report);
58         importBugAction.setImageDescriptor(loader.loadDescriptor("importBug.png")); //$NON-NLS-1$
59 
60         placeActions(optionsAction, clearLogAction, saveAction, loadAction, importBugAction);
61 
62         mLogPanel = new EventLogPanel();
63         mLogPanel
64                 .setActions(optionsAction, clearLogAction, saveAction, loadAction, importBugAction);
65         mLogPanel.createPanel(parent);
66         setSelectionDependentPanel(mLogPanel);
67     }
68 
69     @Override
setFocus()70     public void setFocus() {
71         mLogPanel.setFocus();
72     }
73 
74     @Override
dispose()75     public void dispose() {
76         if (mLogPanel != null) {
77             mLogPanel.stopEventLog(true);
78         }
79     }
80 
81     /**
82      * Places the actions in the toolbar and in the menu.
83      *
84      * @param importBugAction
85      */
placeActions(IAction optionAction, IAction clearAction, IAction saveAction, IAction loadAction, CommonAction importBugAction)86     private void placeActions(IAction optionAction, IAction clearAction, IAction saveAction,
87             IAction loadAction, CommonAction importBugAction) {
88         IActionBars actionBars = getViewSite().getActionBars();
89 
90         // first in the menu
91         IMenuManager menuManager = actionBars.getMenuManager();
92         menuManager.add(clearAction);
93         menuManager.add(new Separator());
94         menuManager.add(saveAction);
95         menuManager.add(loadAction);
96         menuManager.add(importBugAction);
97         menuManager.add(new Separator());
98         menuManager.add(optionAction);
99 
100         // and then in the toolbar
101         IToolBarManager toolBarManager = actionBars.getToolBarManager();
102         toolBarManager.add(clearAction);
103         toolBarManager.add(new Separator());
104         toolBarManager.add(saveAction);
105         toolBarManager.add(loadAction);
106         toolBarManager.add(importBugAction);
107         toolBarManager.add(new Separator());
108         toolBarManager.add(optionAction);
109     }
110 
111 }
112