• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.views;
18 
19 import com.android.ddmlib.Client;
20 import com.android.ddmlib.IDevice;
21 import com.android.ddmuilib.SelectionDependentPanel;
22 import com.android.ide.eclipse.ddms.DdmsPlugin;
23 import com.android.ide.eclipse.ddms.DdmsPlugin.ISelectionListener;
24 
25 import org.eclipse.swt.graphics.Device;
26 import org.eclipse.ui.part.ViewPart;
27 
28 /**
29  * A Workbench {@link ViewPart} that requires {@link Device}/{@link Client} selection notifications
30  * from {@link DdmsPlugin} through the {@link ISelectionListener} interface.
31  */
32 public abstract class SelectionDependentViewPart extends ViewPart implements ISelectionListener {
33 
34     private SelectionDependentPanel mPanel;
35 
setSelectionDependentPanel(SelectionDependentPanel panel)36     protected final void setSelectionDependentPanel(SelectionDependentPanel panel) {
37         // remember the panel
38         mPanel = panel;
39 
40         // and add ourself as listener of selection events.
41         DdmsPlugin.getDefault().addSelectionListener(this);
42     }
43 
44     @Override
dispose()45     public void dispose() {
46         DdmsPlugin.getDefault().removeSelectionListener(this);
47         super.dispose();
48     }
49 
50     /**
51      * Sent when a new {@link Client} is selected.
52      * @param selectedClient The selected client.
53      *
54      * @see ISelectionListener
55      */
56     @Override
selectionChanged(Client selectedClient)57     public final void selectionChanged(Client selectedClient) {
58         mPanel.clientSelected(selectedClient);
59     }
60 
61     /**
62      * Sent when a new {@link Device} is selected.
63      * @param selectedDevice the selected device.
64      *
65      * @see ISelectionListener
66      */
67     @Override
selectionChanged(IDevice selectedDevice)68     public final void selectionChanged(IDevice selectedDevice) {
69         mPanel.deviceSelected(selectedDevice);
70     }
71 }
72