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.builder.javafx.factory
17
18 import griffon.plugins.glazedlists.javafx.gui.DefaultFXTableFormat
19 import griffon.plugins.glazedlists.javafx.gui.FXTableFormat
20
21 /**
22 * @author Andres Almiray
23 */
24 class DefaultFXTableFormatFactory extends AbstractFactory {
25 Object newInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes)
26 throws InstantiationException, IllegalAccessException {
27 if (FactoryBuilderSupport.checkValueIsTypeNotString(value, name, DefaultFXTableFormat)) {
28 return value
29 }
30
31 if (attributes.containsKey('columns')) {
32 def columns = attributes.remove('columns')
33 if (columns instanceof List) {
34 return new DefaultFXTableFormat(columns)
35 } else if (columns instanceof FXTableFormat.Options[]) {
36 return new DefaultFXTableFormat(columns)
37 }
38 throw new IllegalArgumentException("In $name the value of columns: must be a List")
39 }
40
41 if (!attributes.containsKey('columnNames')) {
42 throw new IllegalArgumentException("In $name you must define a value for columnNames:, i.e, ['columnA', 'columnB']")
43 }
44
45 def columnNames = attributes.remove('columnNames')
46 new DefaultFXTableFormat(columnNames as String[])
47 }
48
49 boolean isLeaf() {
50 true
51 }
52 }
|