FXTableFormat.java
01 /*
02  * Copyright 2014-2016 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 griffon.plugins.glazedlists.javafx.gui;
17 
18 import ca.odell.glazedlists.gui.TableFormat;
19 import javafx.beans.value.ObservableValue;
20 
21 import javax.annotation.Nonnull;
22 
23 import static griffon.util.GriffonClassUtils.requireState;
24 import static griffon.util.GriffonNameUtils.requireNonBlank;
25 import static java.util.Objects.requireNonNull;
26 
27 /**
28  @author Andres Almiray
29  */
30 public interface FXTableFormat<E> extends TableFormat<E> {
31     /**
32      * Gets the observable value of the specified field for the specified object. This
33      * is the value that will be passed to the editor and renderer for the
34      * column.
35      */
36     ObservableValue<?> getColumnObservableValue(E baseObject, int column);
37 
38     @Nonnull
39     TableCellFactory getTableCellFactory(int column);
40 
41     @Nonnull
42     public static Option option(@Nonnull String name, @Nonnull Object value) {
43         return new Option(name, value);
44     }
45 
46     @Nonnull
47     public static Options options(@Nonnull Option... options) {
48         return new Options(options);
49     }
50 
51     class Option {
52         public final String name;
53         public final Object value;
54 
55         private Option(@Nonnull String name, @Nonnull Object value) {
56             this.name = requireNonBlank(name, "Argument 'name' must not be blank");
57             this.value = requireNonNull(value, "Argument 'value' must not be null");
58         }
59     }
60 
61     class Options {
62         public final Option[] options;
63 
64         private Options(@Nonnull Option... options) {
65             requireNonNull(options, "Argument 'value' must not be null");
66             requireState(options.length > 0"Argument 'options' must have at least one entry");
67             this.options = options;
68         }
69     }
70 }