2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.ide.eclipse.ddms.views;
19 import com.android.ddmuilib.ITableFocusListener;
20 import com.android.ddmuilib.TablePanel;
21 import com.android.ddmuilib.ITableFocusListener.IFocusedTableActivator;
23 import org.eclipse.jface.action.Action;
24 import org.eclipse.swt.dnd.Clipboard;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.ui.IActionBars;
27 import org.eclipse.ui.actions.ActionFactory;
30 * Base class for view containing Table that needs to support copy, and select all.
32 public abstract class TableView extends SelectionDependentViewPart {
34 /** Activator for the current Table that has the focus */
35 IFocusedTableActivator mActivator = null;
37 private Clipboard mClipboard;
39 private Action mCopyAction;
40 private Action mSelectAllAction;
43 * Setup the listener for the Table objects of <code>Panel</code>, and setup
44 * the copy and select all actions.
45 * @param panel The panel to setup
46 * @param parent The parent composite of the Panel's content.
48 void setupTableFocusListener(TablePanel panel, Composite parent) {
49 panel.setTableFocusListener(new ITableFocusListener() {
50 public void focusGained(IFocusedTableActivator activator) {
51 mActivator = activator;
52 mCopyAction.setEnabled(true);
53 mSelectAllAction.setEnabled(true);
56 public void focusLost(IFocusedTableActivator activator) {
57 if (activator == mActivator) {
59 mCopyAction.setEnabled(false);
60 mSelectAllAction.setEnabled(false);
65 // setup the copy action
66 mClipboard = new Clipboard(parent.getDisplay());
67 IActionBars actionBars = getViewSite().getActionBars();
68 actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
69 mCopyAction = new Action("Copy") {
72 if (mActivator != null) {
73 mActivator.copy(mClipboard);
78 // setup the select all action
79 actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(),
80 mSelectAllAction = new Action("Select All") {
83 if (mActivator != null) {
84 mActivator.selectAll();
92 public void dispose() {