summaryrefslogtreecommitdiff
path: root/src/plugins/android/src/com/motorola/studio/android/wizards/monkey/MonkeyConfigurationTabTable.java
blob: 81359bbdb252c88fa953e4ef977cbb83006416f0 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * 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.motorola.studio.android.wizards.monkey;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

import com.motorola.studio.android.adt.DDMSUtils;
import com.motorola.studio.android.i18n.AndroidNLS;
import com.motorola.studio.android.wizards.elements.TableWithLoadingInfo;

/**
 * Table with loading info for monkey.
 */
public class MonkeyConfigurationTabTable extends
        TableWithLoadingInfo<MonkeyConfigurationTab, Map<String, String>, String>
{

    /**
     * @see TableWithLoadingInfo#TableWithLoadingInfo(Composite, int, String, Object)
     */
    public MonkeyConfigurationTabTable(Composite parent, int style, String animatedTextLabel,
            MonkeyConfigurationTab callingPage)
    {
        super(parent, style, animatedTextLabel, callingPage);
    }

    /**
     * Populates the table with available packages.
     *  
     * @see com.motorola.studio.android.wizards.elements.TableWithLoadingInfo#addTableData(Object)
     */
    @Override
    protected void addTableData(Map<String, String> elementList)
    {
        // retrieve the available packages
        Map<String, String> availablePackages = elementList;
        // retrieve the monkey wizard page
        MonkeyConfigurationTab monkeyWizardPage = getCallingPage();
        // get the list of selected packages preference
        List<?> selectedPackagesPreference = monkeyWizardPage.getSelectedPackagesPreference();
        // get the table to be populated
        Table table = getTable();
        // iterate through the available packages
        String packageName = null;
        String packagePath = null;
        Iterator<String> it = availablePackages.keySet().iterator();
        while (it.hasNext())
        {
            // the the package name and path
            packageName = it.next();
            packagePath = availablePackages.get(packageName);
            if (!monkeyWizardPage.isFilterSystem() || !packagePath.toLowerCase().contains("system"))
            {
                // add data
                TableItem item = new TableItem(table, SWT.NONE);
                item.setText(0, packageName);
                item.setText(1, packagePath.contains("system")
                        ? AndroidNLS.UninstallAppWizardPage_SystemLabel
                        : AndroidNLS.UninstallAppWizardPage_UserLabel);
                if (selectedPackagesPreference != null)
                {
                    if (selectedPackagesPreference.contains(packageName))
                    {
                        item.setChecked(true);
                        getTable().select(table.getItemCount() - 1);
                    }
                }

            }
        }
    }

    /**
     * Get the List of installed packages from the device based on its serial number.
     *  
     * @see com.motorola.studio.android.wizards.elements.TableWithLoadingInfo#callServiceForRetrievingDataToPopulateTable(java.lang.Object)
     */
    @Override
    protected Map<String, String> callServiceForRetrievingDataToPopulateTable(String serialNumber)
    {
        // installed packages to be returned
        Map<String, String> installedPackages = null;
        // based on the serial number, the the installed packages
        if (serialNumber != null)
        {
            try
            {
                installedPackages = DDMSUtils.listInstalledPackages(serialNumber);
            }
            catch (IOException e)
            {
                installedPackages = new HashMap<String, String>(0);
            }
        }
        return installedPackages;
    }

    /** 
     * Update the Launching configuration dialog.
     * 
     * @see com.motorola.studio.android.wizards.elements.TableWithLoadingInfo#executeOperationsAfterTableIsPopulated()
     */
    @Override
    protected void executeOperationsAfterTableIsPopulated()
    {
        // update the launching configuration dialog
        MonkeyConfigurationTab monkeyWizardPage = getCallingPage();
        monkeyWizardPage.callUpdateLaunchConfigurationDialog();
    }

}