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/** 032 * The filter display mode in the top screen. 033 * 034 * Exit if Enter key is pressed. 035 */ 036@InterfaceAudience.Private 037public class FilterDisplayModeScreenView extends AbstractScreenView { 038 039 private final int row; 040 private final FilterDisplayModeScreenPresenter filterDisplayModeScreenPresenter; 041 042 public FilterDisplayModeScreenView(Screen screen, Terminal terminal, int row, 043 List<RecordFilter> filters, ScreenView nextScreenView) { 044 super(screen, terminal); 045 this.row = row; 046 this.filterDisplayModeScreenPresenter = 047 new FilterDisplayModeScreenPresenter(this, filters, nextScreenView); 048 } 049 050 @Override 051 public void init() { 052 filterDisplayModeScreenPresenter.init(); 053 } 054 055 @Override 056 public ScreenView handleKeyPress(KeyPress keyPress) { 057 if (keyPress.getType() == KeyPress.Type.Enter) { 058 return filterDisplayModeScreenPresenter.returnToNextScreen(); 059 } 060 return this; 061 } 062 063 public void showFilters(List<RecordFilter> filters) { 064 String filtersString = "none"; 065 if (!filters.isEmpty()) { 066 filtersString = String.join(" + ", 067 filters.stream().map(f -> String.format("'%s'", f)).collect(Collectors.toList())); 068 } 069 070 getTerminalPrinter(row).startBold().print("<Enter> to resume, filters: " + filtersString) 071 .stopBold().endOfLine(); 072 } 073}