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
17package com.android.hierarchyviewerlib.actions;
18
19import com.android.ddmuilib.ImageLoader;
20import com.android.hierarchyviewerlib.HierarchyViewerDirector;
21
22import org.eclipse.jface.action.Action;
23import org.eclipse.jface.resource.ImageDescriptor;
24import org.eclipse.swt.SWT;
25import org.eclipse.swt.graphics.Image;
26import org.eclipse.swt.widgets.Display;
27
28public class RefreshWindowsAction extends Action implements ImageAction {
29
30    private static RefreshWindowsAction sAction;
31
32    private Image mImage;
33
34    private RefreshWindowsAction() {
35        super("&Refresh");
36        setAccelerator(SWT.F5);
37        ImageLoader imageLoader = ImageLoader.getLoader(HierarchyViewerDirector.class);
38        mImage = imageLoader.loadImage("refresh-windows.png", Display.getDefault()); //$NON-NLS-1$
39        setImageDescriptor(ImageDescriptor.createFromImage(mImage));
40        setToolTipText("Refresh the list of devices");
41    }
42
43    public static RefreshWindowsAction getAction() {
44        if (sAction == null) {
45            sAction = new RefreshWindowsAction();
46        }
47        return sAction;
48    }
49
50    @Override
51    public void run() {
52        HierarchyViewerDirector.getDirector().refreshWindows();
53    }
54
55    @Override
56    public Image getImage() {
57        return mImage;
58    }
59}
60