• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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.hierarchyviewer;
18 
19 import com.android.ddmlib.IDevice;
20 import com.android.hierarchyviewerlib.HierarchyViewerDirector;
21 import com.android.hierarchyviewerlib.device.Window;
22 import com.android.ide.eclipse.hierarchyviewer.views.PixelPerfectTreeView;
23 import com.android.ide.eclipse.hierarchyviewer.views.PropertyView;
24 
25 import org.eclipse.core.runtime.IProgressMonitor;
26 import org.eclipse.core.runtime.IStatus;
27 import org.eclipse.core.runtime.Status;
28 import org.eclipse.core.runtime.jobs.ISchedulingRule;
29 import org.eclipse.core.runtime.jobs.Job;
30 import org.eclipse.ui.IWorkbenchPage;
31 import org.eclipse.ui.IWorkbenchPart;
32 import org.eclipse.ui.IWorkbenchWindow;
33 import org.eclipse.ui.PartInitException;
34 
35 public class HierarchyViewerPluginDirector extends HierarchyViewerDirector {
36 
createDirector()37     public static HierarchyViewerDirector createDirector() {
38         return sDirector = new HierarchyViewerPluginDirector();
39     }
40 
41     @Override
executeInBackground(final String taskName, final Runnable task)42     public void executeInBackground(final String taskName, final Runnable task) {
43         Job job = new Job(taskName) {
44             @Override
45             protected IStatus run(IProgressMonitor monitor) {
46                 task.run();
47                 return Status.OK_STATUS;
48             }
49         };
50         job.setPriority(Job.SHORT);
51         job.setRule(mSchedulingRule);
52         job.schedule();
53     }
54 
55     private ISchedulingRule mSchedulingRule = new ISchedulingRule() {
56         public boolean contains(ISchedulingRule rule) {
57             return rule == this;
58         }
59 
60         public boolean isConflicting(ISchedulingRule rule) {
61             return rule == this;
62         }
63 
64     };
65 
66     @Override
getAdbLocation()67     public String getAdbLocation() {
68         return HierarchyViewerPlugin.getPlugin().getPreferenceStore().getString(
69                 HierarchyViewerPlugin.ADB_LOCATION);
70     }
71 
72     @Override
loadViewTreeData(Window window)73     public void loadViewTreeData(Window window) {
74         super.loadViewTreeData(window);
75 
76         // The windows tab hides the property tab, so let's bring the property
77         // tab
78         // forward.
79 
80         IWorkbenchWindow[] windows =
81                 HierarchyViewerPlugin.getPlugin().getWorkbench().getWorkbenchWindows();
82         for (IWorkbenchWindow currentWindow : windows) {
83             IWorkbenchPage page = currentWindow.getActivePage();
84             if (page.getPerspective().getId().equals(TreeViewPerspective.ID)) {
85                 try {
86                     IWorkbenchPart part = page.findView(PropertyView.ID);
87                     if (part != null) {
88                         page.showView(PropertyView.ID);
89                     }
90                 } catch (PartInitException e) {
91 
92                 }
93             }
94         }
95     }
96 
97     @Override
loadPixelPerfectData(IDevice device)98     public void loadPixelPerfectData(IDevice device) {
99         super.loadPixelPerfectData(device);
100 
101         // The windows tab hides the tree tab, so let's bring the tree tab
102         // forward.
103 
104         IWorkbenchWindow[] windows =
105                 HierarchyViewerPlugin.getPlugin().getWorkbench().getWorkbenchWindows();
106         for (IWorkbenchWindow window : windows) {
107             IWorkbenchPage page = window.getActivePage();
108             if (page.getPerspective().getId().equals(PixelPerfectPespective.ID)) {
109                 try {
110                     IWorkbenchPart part = page.findView(PixelPerfectTreeView.ID);
111                     if (part != null) {
112                         page.showView(PixelPerfectTreeView.ID);
113                     }
114                 } catch (PartInitException e) {
115 
116                 }
117             }
118         }
119     }
120 }
121