001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.hbtop.screen.top; 019 020import java.util.List; 021import java.util.stream.Collectors; 022import org.apache.hadoop.hbase.hbtop.RecordFilter; 023import org.apache.hadoop.hbase.hbtop.screen.AbstractScreenView; 024import org.apache.hadoop.hbase.hbtop.screen.Screen; 025import org.apache.hadoop.hbase.hbtop.screen.ScreenView; 026import org.apache.hadoop.hbase.hbtop.terminal.KeyPress; 027import org.apache.hadoop.hbase.hbtop.terminal.Terminal; 028import org.apache.yetus.audience.InterfaceAudience; 029 030/** 031 * The filter display mode in the top screen. Exit if Enter key is pressed. 032 */ 033@InterfaceAudience.Private 034public class FilterDisplayModeScreenView extends AbstractScreenView { 035 036 private final int row; 037 private final FilterDisplayModeScreenPresenter filterDisplayModeScreenPresenter; 038 039 public FilterDisplayModeScreenView(Screen screen, Terminal terminal, int row, 040 List<RecordFilter> filters, ScreenView nextScreenView) { 041 super(screen, terminal); 042 this.row = row; 043 this.filterDisplayModeScreenPresenter = 044 new FilterDisplayModeScreenPresenter(this, filters, nextScreenView); 045 } 046 047 @Override 048 public void init() { 049 filterDisplayModeScreenPresenter.init(); 050 } 051 052 @Override 053 public ScreenView handleKeyPress(KeyPress keyPress) { 054 if (keyPress.getType() == KeyPress.Type.Enter) { 055 return filterDisplayModeScreenPresenter.returnToNextScreen(); 056 } 057 return this; 058 } 059 060 public void showFilters(List<RecordFilter> filters) { 061 String filtersString = "none"; 062 if (!filters.isEmpty()) { 063 filtersString = String.join(" + ", 064 filters.stream().map(f -> String.format("'%s'", f)).collect(Collectors.toList())); 065 } 066 067 getTerminalPrinter(row).startBold().print("<Enter> to resume, filters: " + filtersString) 068 .stopBold().endOfLine(); 069 } 070}