DefaultPivotWindowDisplayHandler.java
01 /*
02  * Copyright 2008-2015 the original author or authors.
03  *
04  * Licensed under the Apache License, Version 2.0 (the "License");
05  * you may not use this file except in compliance with the License.
06  * You may obtain a copy of the License at
07  *
08  *     http://www.apache.org/licenses/LICENSE-2.0
09  *
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 org.codehaus.griffon.runtime.pivot;
17 
18 import griffon.pivot.PivotWindowDisplayHandler;
19 import org.apache.pivot.wtk.Display;
20 import org.apache.pivot.wtk.Window;
21 
22 import javax.annotation.Nonnull;
23 import javax.inject.Inject;
24 
25 import static griffon.util.GriffonNameUtils.requireNonBlank;
26 import static java.util.Objects.requireNonNull;
27 
28 /**
29  @author Andres Almiray
30  @since 2.0.0
31  */
32 public class DefaultPivotWindowDisplayHandler implements PivotWindowDisplayHandler {
33     private static final String ERROR_NAME_BLANK = "Argument 'name' must not be null";
34     private static final String ERROR_WINDOW_NULL = "Argument 'window' must not be null";
35 
36     private final Display display;
37 
38     @Inject
39     public DefaultPivotWindowDisplayHandler(@Nonnull Display display) {
40         this.display = requireNonNull(display, "Argument 'display' must not be null");
41     }
42 
43     public void show(@Nonnull String name, @Nonnull Window window) {
44         requireNonBlank(name, ERROR_NAME_BLANK);
45         requireNonNull(window, ERROR_WINDOW_NULL);
46         window.open(display);
47     }
48 
49     public void hide(@Nonnull String name, @Nonnull Window window) {
50         requireNonBlank(name, ERROR_NAME_BLANK);
51         requireNonNull(window, ERROR_WINDOW_NULL);
52         window.close();
53     }
54 }