summaryrefslogtreecommitdiff
path: root/src/plugins/preflighting.ui/src/com/motorolamobility/preflighting/ui/AppValidatorClearActionDelegate.java
blob: fef0c4e9f6e8316ebaf9a6f9e1effa6377268927 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.motorolamobility.preflighting.ui;

import java.net.URL;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;

import com.motorolamobility.preflighting.core.logging.PreflightingLogger;
import com.motorolamobility.preflighting.ui.handlers.AnalyzeApkHandler;
import com.motorolamobility.preflighting.ui.i18n.PreflightingUiNLS;

public class AppValidatorClearActionDelegate implements IViewActionDelegate
{
    public void run(IAction action)
    {
        //do nothing
    }

    public void selectionChanged(IAction action, ISelection selection)
    {
        //do nothing
    }

    public void init(IViewPart view)
    {
        IActionBars actionBar = view.getViewSite().getActionBars();
        IToolBarManager toolBar = actionBar.getToolBarManager();
        //defines action 
        Action action = new Action()
        {
            @Override
            public void run()
            {
                try
                {
                    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                    //clear app validator markers for every opened project and its subfiles
                    for (int i = 0; projects != null && i < projects.length; i++)
                    {
                        if (projects[i].isOpen())
                        {
                            projects[i].deleteMarkers(AnalyzeApkHandler.DEFAULT_APP_VALIDATOR_MARKER_TYPE,
                                    true, IResource.DEPTH_INFINITE);
                        }
                    }
                }
                catch (CoreException e)
                {
                    PreflightingLogger.error("Error removing markers from projects.");
                }

                super.run();
            }
        };
        //set icon
        URL imageUrl =
                PreflightingUIPlugin.getDefault().getBundle()
                        .getEntry("icons/MOTODEVAppValidator_16x16_clear.png");
        ImageDescriptor imageDesc = ImageDescriptor.createFromURL(imageUrl);
        action.setImageDescriptor(imageDesc);
        action.setEnabled(true);
        action.setToolTipText(PreflightingUiNLS.ProblemsView_ClearAppValidatorMarkers);
        //add to tool bar and update it
        toolBar.add(action);

        toolBar.add(new Separator());
        actionBar.updateActionBars();
    }
}