summaryrefslogtreecommitdiff
path: root/src/plugins/emulator/src/com/motorola/studio/android/emulator/ui/handlers/ShowViewHandler.java
blob: a2a15e2d66952269bdb9135a92eac1b4a5d5a906 (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
/*
* 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.emulator.ui.handlers;

import static com.motorola.studio.android.common.log.StudioLogger.error;
import static com.motorola.studio.android.common.log.StudioLogger.info;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.PartInitException;

import com.motorola.studio.android.common.utilities.EclipseUtils;
import com.motorola.studio.android.emulator.i18n.EmulatorNLS;
import com.motorola.studio.android.emulator.ui.view.AndroidView;
import com.motorola.studio.android.emulator.ui.view.MainDisplayView;

/**
 * DESCRIPTION:
 * This class is a handler for the show view actions
 *
 * RESPONSIBILITY:
 * Execute the show view operations on demand
 *
 * COLABORATORS:
 * None.
 *
 * USAGE:
 * This class is intended to be used by Eclipse only
 */
public class ShowViewHandler extends AbstractHandler implements IHandlerConstants
{
    /**
     * @see org.eclipse.core.commands.IHandler#execute(ExecutionEvent)
     */
    public Object execute(ExecutionEvent event) throws ExecutionException
    {
        String viewId = event.getParameter(IHandlerConstants.ACTIVE_VIEW_PARAMETER);

        try
        {
            if (viewId.equals(AndroidView.ANDROID_VIEW_ID))
            {
                info("Showing Main Display View by command execution");
                EclipseUtils.showView(MainDisplayView.EMULATOR_MAIN_DISPLAY_VIEW_ID);
            }
            else if (viewId.equals(MainDisplayView.EMULATOR_MAIN_DISPLAY_VIEW_ID))
            {
                info("Showing Android View by command execution");
                EclipseUtils.showView(AndroidView.ANDROID_VIEW_ID);
            }
            else
            {
                info("User tried to open an unknown view. Ignoring the action.");
            }
        }
        catch (PartInitException e)
        {
            error("The views that were requested to be opened are not accessible programatically");
            EclipseUtils.showErrorDialog(EmulatorNLS.GEN_Error,
                    EmulatorNLS.EXC_AndroidView_ViewNotFound);
        }

        return null;
    }
}