01 /*
02 * Copyright 2010-2013 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
17 package griffon.core.resources.editors;
18
19 import java.io.File;
20
21 import static griffon.util.GriffonNameUtils.isBlank;
22
23 /**
24 * @author Andres Almiray
25 * @since 1.1.0
26 */
27 public class FilePropertyEditor extends AbstractPropertyEditor {
28 public void setAsText(String value) throws IllegalArgumentException {
29 setValue(value);
30 }
31
32 public void setValue(Object value) {
33 if (null == value) return;
34 if (value instanceof CharSequence) {
35 handleAsString(String.valueOf(value));
36 } else if (value instanceof File) {
37 super.setValue(value);
38 } else {
39 throw illegalValue(value, File.class);
40 }
41 }
42
43 private void handleAsString(String str) {
44 if (isBlank(str)) {
45 throw illegalValue(str, File.class);
46 }
47 super.setValue(new File(str));
48 }
49 }
|