1 /* 2 * Copyright (C) 2019 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 package com.android.atest; 17 18 import com.android.atest.widget.AtestNotification; 19 import com.intellij.notification.Notifications; 20 import com.intellij.openapi.actionSystem.AnActionEvent; 21 import com.intellij.openapi.diagnostic.Logger; 22 import com.intellij.openapi.wm.ToolWindow; 23 import com.intellij.openapi.wm.ToolWindowManager; 24 import org.jetbrains.annotations.NotNull; 25 26 /** An Action to launch Atest tool window. */ 27 public class AtestToolWindowAction extends com.intellij.openapi.actionSystem.AnAction { 28 29 private static final Logger LOG = Logger.getInstance(AtestToolWindowAction.class); 30 31 /** 32 * Launches the atest tool window. 33 * 34 * @param event carries information on the invocation place. 35 */ 36 @Override actionPerformed(@otNull AnActionEvent event)37 public void actionPerformed(@NotNull AnActionEvent event) { 38 ToolWindow AtestTW = 39 ToolWindowManager.getInstance(event.getProject()) 40 .getToolWindow(Constants.ATEST_TOOL_WINDOW); 41 if (AtestTW == null) { 42 Notifications.Bus.notify(new AtestNotification(Constants.ATEST_WINDOW_FAIL)); 43 LOG.error("Can't get Atest tool window."); 44 return; 45 } 46 47 if (AtestTW.isVisible()) { 48 AtestTW.hide(null); 49 } else { 50 AtestTW.show(null); 51 } 52 } 53 } 54