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 griffon.pivot.support;
17
18 import griffon.core.CallableWithArgs;
19 import griffon.core.RunnableWithArgs;
20 import org.apache.pivot.wtk.Action;
21 import org.apache.pivot.wtk.Component;
22
23 import javax.annotation.Nonnull;
24 import javax.annotation.Nullable;
25
26 import static java.util.Objects.requireNonNull;
27
28 /**
29 * @author Andres Almiray
30 */
31 public class PivotAction extends Action {
32 private static final String ERROR_CALLABLE_NULL = "Argument 'callable' must not be null";
33 private static final String ERROR_RUNNABLE_NULL = "Argument 'runnable' must not be null";
34 private String name;
35 private String description;
36 private RunnableWithArgs runnable;
37
38 public PivotAction() {
39
40 }
41
42 public PivotAction(@Nonnull RunnableWithArgs runnable) {
43 this.runnable = requireNonNull(runnable, ERROR_RUNNABLE_NULL);
44 }
45
46 @Deprecated
47 public PivotAction(@Nonnull CallableWithArgs<Void> callable) {
48 setCallable(callable);
49 }
50
51 public String getName() {
52 return name;
53 }
54
55 public void setName(String name) {
56 this.name = name;
57 }
58
59 public String getDescription() {
60 return description;
61 }
62
63 public void setDescription(String description) {
64 this.description = description;
65 }
66
67 @Deprecated
68 public void setCallable(final @Nonnull CallableWithArgs<Void> callable) {
69 requireNonNull(callable, ERROR_CALLABLE_NULL);
70 this.runnable = new RunnableWithArgs() {
71 @Override
72 public void run(@Nullable Object... args) {
73 callable.call(args);
74 }
75 };
76 }
77
78 public RunnableWithArgs getRunnable() {
79 return runnable;
80 }
81
82 public void setRunnable(RunnableWithArgs runnable) {
83 this.runnable = runnable;
84 }
85
86 public String toString() {
87 return "Action[" + name + ", " + description + "]";
88 }
89
90 @Override
91 public void perform(Component component) {
92 requireNonNull(runnable, "Argument 'runnable' must not be null for " + this);
93 runnable.run(component);
94 }
95 }
|