View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.hbtop.screen.top;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.apache.commons.lang3.StringUtils;
24  import org.apache.hadoop.hbase.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.hbtop.RecordFilter;
26  import org.apache.hadoop.hbase.hbtop.screen.AbstractScreenView;
27  import org.apache.hadoop.hbase.hbtop.screen.Screen;
28  import org.apache.hadoop.hbase.hbtop.screen.ScreenView;
29  import org.apache.hadoop.hbase.hbtop.terminal.KeyPress;
30  import org.apache.hadoop.hbase.hbtop.terminal.Terminal;
31  
32  /**
33   * The filter display mode in the top screen.
34   *
35   * Exit if Enter key is pressed.
36   */
37  @InterfaceAudience.Private
38  public class FilterDisplayModeScreenView extends AbstractScreenView {
39  
40    private final int row;
41    private final FilterDisplayModeScreenPresenter filterDisplayModeScreenPresenter;
42  
43    public FilterDisplayModeScreenView(Screen screen, Terminal terminal, int row,
44      List<RecordFilter> filters, ScreenView nextScreenView) {
45      super(screen, terminal);
46      this.row = row;
47      this.filterDisplayModeScreenPresenter =
48        new FilterDisplayModeScreenPresenter(this, filters, nextScreenView);
49    }
50  
51    @Override
52    public void init() {
53      filterDisplayModeScreenPresenter.init();
54    }
55  
56    @Override
57    public ScreenView handleKeyPress(KeyPress keyPress) {
58      if (keyPress.getType() == KeyPress.Type.Enter) {
59        return filterDisplayModeScreenPresenter.returnToNextScreen();
60      }
61      return this;
62    }
63  
64    public void showFilters(List<RecordFilter> filters) {
65      String filtersString = "none";
66      if (!filters.isEmpty()) {
67        List<String> filterStrings = new ArrayList<>();
68        for (RecordFilter filter : filters) {
69          filterStrings.add(String.format("'%s'", filter));
70        }
71        filtersString = StringUtils.join(filterStrings, " + ");
72      }
73  
74      getTerminalPrinter(row).startBold().print("<Enter> to resume, filters: " + filtersString)
75        .stopBold().endOfLine();
76    }
77  }